<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 14, 2017 at 6:41 AM, Andrew Ho <span dir="ltr"><<a href="mailto:andrewh0@uw.edu" target="_blank">andrewh0@uw.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I have a 3x6 matrix, and I want to set it to (just as an example):</div><div><br></div><div>0 0 0 1 1 1</div><div>0 0 0 1 1 1</div><div>0 0 0 1 1 1<br><br>From what I can tell, according to the documentation the MPIAIJ sparsity of this matrix is:</div></div></blockquote><div><br></div><div>I believe this is an inconsistency in PETSc for rectangular matrices. We divide matrices into diagonal and</div><div>off-diagonal parts mainly to separate communication from computation. Thus on 1 proc, we never divide</div><div>them, even if the matrix is rectangular. Therefore we misinterpret your preallocation.</div><div><br></div><div>Barry, do you think we want to try and change this?</div><div><br></div><div>  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>d_nnz = [0, 0, 0]</div><div>o_nnz = [3, 3, 3]</div><div><br></div><div>However, when I do this, I get the following error:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[0]PETSC ERROR: --------------------- Error Message ------------------------------<wbr>------------------------------<wbr>--                                                                           <br>[0]PETSC ERROR: Argument out of range<br>[0]PETSC ERROR: New nonzero at (0,3) caused a malloc<br>Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_<wbr>ERR, PETSC_FALSE) to turn off this check<br>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/faq.html</a> for trouble shooting.<br>[0]PETSC ERROR: Petsc Release Version 3.7.5, unknown <br>[0]PETSC ERROR: ./ex3 on a arch-linux2-c-opt Tue Feb 14 04:23:56 2017<br>[0]PETSC ERROR: Configure options --with-debugging=0 --COPTFLAGS="-O3 -march=native" --CXXOPTFLAGS="-O3 -march=native" --FOPTFLAGS="-O3 -march=native"                           <br>[0]PETSC ERROR: #1 MatSetValues_MPIAIJ() line 582 in petsc/src/mat/impls/aij/mpi/<wbr>mpiaij.c<br>[0]PETSC ERROR: #2 MatSetValues() line 1190 in petsc/src/mat/interface/<wbr>matrix.c                    <br>[0]PETSC ERROR: #3 main() line 36 in ex3.c<br>[0]PETSC ERROR: No PETSc Option Table entries<br>[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov-------<wbr>---</blockquote><div><br></div><div>Here's a working test code:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">#include <petsc.h><br>#include <mpi.h><br>int main(int argc, char** argv)<br>{<br>  PetscErrorCode err;<br>  err = PetscInitialize(&argc, &argv, NULL, "help");<br>  CHKERRQ(err);<br>  // create a sparse AIJ matrix distributed across MPI<br>  PetscInt global_width = 6;<br>  PetscInt global_height = 3;<br>  Mat A;<br>  err = MatCreate(MPI_COMM_WORLD, &A);<br>  CHKERRQ(err);<br>  err = MatSetType(A, MATMPIAIJ);<br>  CHKERRQ(err);<br>  // setup pre-allocation for matrix space<br>  {<br>    err =<br>      MatSetSizes(A, global_height, PETSC_DECIDE, global_height, global_width);<br>    CHKERRQ(err);<br>    PetscInt d_nnz[] = {0, 0, 0};<br>    PetscInt o_nnz[] = {3, 3, 3};<br>    err = MatMPIAIJSetPreallocation(A, 0, d_nnz, 0, o_nnz);<br>    CHKERRQ(err);<br>  }<br>  err = MatSetUp(A);<br>  CHKERRQ(err);<br>  // set values inside the matrix<br>  for (PetscInt row = 0; row < global_height; ++row)<br>  {<br>    for (PetscInt col = global_height; col < global_width; ++col)<br>    {<br>      err = MatSetValue(A, row, col, 1, INSERT_VALUES);<br>      CHKERRQ(err);<br>    }<br>  }<br>  err = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);<br>  CHKERRQ(err);<br>  err = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);<br>  CHKERRQ(err);<br>  err = MatView(A, PETSC_VIEWER_STDOUT_WORLD);<br>  CHKERRQ(err);<br>  // free memory<br>  err = MatDestroy(&A);<br>  CHKERRQ(err);<br>  // cleanup any internal PETSc data at end of program<br>  err = PetscFinalize();<br>  CHKERRQ(err);<br>}</blockquote></div><div><br></div><div>Am I mis-understanding what the d_nnz and o_nnz parameter are supposed to mean?</div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_3224953740535681211gmail_signature"><div dir="ltr">Andrew Ho</div></div></font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>