<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Jan 8, 2024, at 4:31 AM, Deuse, Mathieu via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">Hello,<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">I have a piece of code which generates a matrix in CSR format, but the without sorting the column indexes in increasing order within each row. This seems not to be 100% compatible with the MATMPIAIJ format: the documentation of MatCreateMPIAIJWithArrays indeed mentions 'row-major ordering'.<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">For example, consider the 2x2 matrix (1 2; 3 4), which in my code could be stored as i=[0, 2, 4], j=[1, 0, 0, 1], v=[2, 1, 3, 4]. I can generate the matrix as follows (on 1 proc): MatCreateMPIAIJWithArrays(PETSC_COMM_SELF, 2, 2, 2, 2, i, j, v, &matrix). This appears to work fine, and I can then use the matrix in a KSP for example. However, if I try to update the entry values (same order and values v=[2, 1, 3, 4]) with MatUpdateMPIAIJWithArray(matrix, v), it seems that PETSc does not memorize the order of the column indexes and the matrix that I get now is (2 1; 3 4). I get the same result with MatUpdateMPIAIJWithArrays(matrix, 2, 2, 2, 2, i, j, v). On the other hand, if the column indexes are sorted within each row (i=[0, 2, 4], j=[0, 1, 0, 1], v=[1, 2, 3, 4]), then it works fine. I have attached a minimal working example (C++).<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">Can I safely rely on MatCreateMPIAIJWithArrays working fine with unsorted column indexes as long as I do not use MatUpdateMPIAIJWithArray(s)?</span></div></div></div></blockquote><div><br></div><div> Yes, this is correct. The column indices do not need to be sorted if you never call <span style="font-family: Arial, sans-serif; font-size: 10pt;">MatUpdateMPIAIJWithArray().</span></div><div><span style="font-family: Arial, sans-serif; font-size: 10pt;"><br></span></div><div><span style="font-family: Arial, sans-serif; font-size: 10pt;"><br></span></div><br><blockquote type="cite"><div><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"> Or should I do the sorting myself before calling MatCreateMPIAIJWithArrays? (or alternatively use another matrix format).<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">Thanks in advance for the help.<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">Kind regards,<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span style="font-size: 10pt; font-family: Arial, sans-serif;">Mathieu Deuse<o:p></o:p></span></div></div><span id="cid:11A284EE-9AEE-431C-964A-D9B3EFAEE9E0"><main.cpp></span></div></blockquote></div><br></body></html>