<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div><span>Jed,</span></div><div><span></span> </div><div><span>Thanks a lot for your nice suggestions. The CRS matrix has already been created by the program and I don't want to change that, do you mean I should read the arrays (i, j, a) and set coefficients row by row using MatSetValues? Will it be much slower than passing the arrays directly to MatCreateSeqAIJWithArrays or MatCreateMPIAIJWithArrays, especially when the matrix is big?</span></div><div><span></span> </div><div><span>Thanks,</span></div><div><span>Qin</span></div><div style="display: block;" class="yahoo_quoted"> <br> <br> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica,
 Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Thursday, October 31, 2013 3:07 PM, Jed Brown <jedbrown@mcs.anl.gov> wrote:<br> </font> </div>  <div class="y_msg_container">Qin Lu <<a href="mailto:lu_qin_2000@yahoo.com" shape="rect" ymailto="mailto:lu_qin_2000@yahoo.com">lu_qin_2000@yahoo.com</a>> writes:<br clear="none"><br clear="none">> Hello,<br clear="none">><br clear="none">> I have successfully installed a sequential PETSc's linear solver in a sequential program. The matrix has been created in CSR format and it was passed to  MatCreateSeqAIJWithArrays (instead of using MatSetValues). <br clear="none">><br clear="none">> Now I want to use a parallel PETSc solver in the same sequential program, and use the same CRS matrix mentioned above. I intend to use MatCreateMPIAIJWithArrays, since I hope to pass the array direct to PETSc, instead of using
 MatSetValues. There a few questions:<br clear="none"><br clear="none">Use MatSetValues.  It uses less memory and is more flexible.<br clear="none"><br clear="none">> 1. Is there a sample code for using MatCreateMPIAIJWithArrays?<br clear="none"><br clear="none">Please don't use this function.  It only exists to support legacy users<br clear="none">that were already using it.  The implementation calls MatSetValues<br clear="none">because the input format is not suitable to actually compute with.<br clear="none"><br clear="none">> 2. There seems to be a subroutine MatDistribute_MPIAIJ, but it is not<br clear="none">> in the PETSc manual. Where can I get the instruction how to use it? It<br clear="none">> would be nice if there is a sample code available.<br clear="none"><br clear="none">That is a private function.  Use MatSetValues.<br clear="none"><br clear="none">> 3. Manual says the matrix will be copied by
 MatCreateMPIAIJWithArrays<br clear="none">> into internal format (while it is not when using<br clear="none">> MatCreateSeqAIJWithArrays), does this mean I have to call<br clear="none">> MatMPIAIJSetPreallocation first?<br clear="none"><br clear="none">Not if you call MatCreateMPIAIJWithArrays, but to avoid using the extra<br clear="none">memory (and to simplify your code), you should compute preallocation and<br clear="none">then call MatSetValues once per row, per element, or whatever.<div id="yqtfd46909" class="yqt6138906792"><br clear="none"><br clear="none">> 4. In sample code ex2.c in the manual, both MatMPIAIJSetPreallocation<br clear="none">> and MatSeqAIJSetPreallocation are called to preallocate the matrix<br clear="none">> A. Is not the first subroutine sufficient?</div><br clear="none"><br clear="none">The example can run in serial or parallel.  Only the matching<br clear="none">preallocation is used, any others will
 be ignored.<br><br></div>  </div> </div>  </div> </div></body></html>