<div dir="ltr">Dear PETSc developers
<div><br></div><div>I got an error with MatZeroRowsColumns, which said there was one missing diagonal entries</div><div><br></div><div>This is the full log message that I got:</div><div><br></div><div><div>Mat Object: 2 MPI processes</div><div> type: mpiaij</div><div> rows=41064, cols=41064, bs=4</div><div> total: nonzeros=5.66069e+06, allocated nonzeros=1.28112e+07</div><div> total number of mallocs used during MatSetValues calls =0</div><div> using I-node (on process 0) routines: found 5647 nodes, limit used is 5</div><div>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</div><div>[0]PETSC ERROR: Object is in wrong state</div><div>[0]PETSC ERROR: Matrix is missing diagonal entry in row 7</div><div>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</div><div>[0]PETSC ERROR: Petsc Release Version 3.6.3, Dec, 03, 2015 </div><div>[0]PETSC ERROR: python on a arch-linux2-cxx-opt named bermuda by hbui2 Wed Jan 13 10:27:42 2016</div><div>[0]PETSC ERROR: Configure options --with-shared-libraries --with-debugging=0 --with-pic --with-clanguage=cxx --download-fblas-lapack=yes --download-ptscotch=yes --download-metis=yes --download-parmetis=yes --download-scalapack=yes --download-mumps=yes --download-hypre=yes --download-ml=yes --download-klu=yes --download-pastix=yes --with-mpi-dir=/opt/openmpi-1.10.1_thread-multiple --prefix=/home/hbui/opt/petsc-3.6.3</div><div>[0]PETSC ERROR: #1 MatZeroRowsColumns_SeqAIJ() line 1901 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/impls/aij/seq/aij.c</div><div>[0]PETSC ERROR: #2 MatZeroRowsColumns() line 5476 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: #3 MatZeroRowsColumns_MPIAIJ() line 908 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/impls/aij/mpi/mpiaij.c</div><div>[0]PETSC ERROR: #4 MatZeroRowsColumns() line 5476 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/interface/matrix.c</div><div>[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</div><div>[1]PETSC ERROR: Object is in wrong state</div><div>[1]PETSC ERROR: Matrix is missing diagonal entry in row 7</div><div>[1]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</div><div>[1]PETSC ERROR: Petsc Release Version 3.6.3, Dec, 03, 2015 </div><div>[1]PETSC ERROR: python on a arch-linux2-cxx-opt named bermuda by hbui2 Wed Jan 13 10:27:42 2016</div><div>[1]PETSC ERROR: Configure options --with-shared-libraries --with-debugging=0 --with-pic --with-clanguage=cxx --download-fblas-lapack=yes --download-ptscotch=yes --download-metis=yes --download-parmetis=yes --download-scalapack=yes --download-mumps=yes --download-hypre=yes --download-ml=yes --download-klu=yes --download-pastix=yes --with-mpi-dir=/opt/openmpi-1.10.1_thread-multiple --prefix=/home/hbui/opt/petsc-3.6.3</div><div>[1]PETSC ERROR: #1 MatZeroRowsColumns_SeqAIJ() line 1901 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/impls/aij/seq/aij.c</div><div>[1]PETSC ERROR: #2 MatZeroRowsColumns() line 5476 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/interface/matrix.c</div><div>[1]PETSC ERROR: #3 MatZeroRowsColumns_MPIAIJ() line 908 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/impls/aij/mpi/mpiaij.c</div><div>[1]PETSC ERROR: #4 MatZeroRowsColumns() line 5476 in /media/NEW_HOME/sw2/petsc-3.6.3/src/mat/interface/matrix.c</div></div><div><br></div><div><br></div><div>The problem is, before calling MatZeroRowsColumns, I searched for zero rows and set the respective diagonal:</div><div><div><br></div><div> PetscInt Istart, Iend;</div><div> MatGetOwnershipRange(rA.Get(), &Istart, &Iend);</div><div><br></div><div> // loop through each row in the current partition</div><div> for(PetscInt row = Istart; row < Iend; ++row)</div><div> {</div><div> int ncols;</div><div> const PetscInt* cols;</div><div> const PetscScalar* vals;</div><div> MatGetRow(rA.Get(), row, &ncols, &cols, &vals);</div><div><br></div><div> PetscScalar row_norm = 0.0;</div><div> for(int i = 0; i < ncols; ++i)</div><div> {</div><div> PetscScalar val = vals[i];</div><div> row_norm += pow(val, 2);</div><div> }</div><div> row_norm = sqrt(row_norm);</div><div><br></div><div> if(row_norm == 0.0)</div><div> {</div><div> for(int i = 0; i < ncols; ++i)</div><div> {</div><div> PetscInt col = cols[i];</div><div> if(col == row)</div><div> {</div><div> MatSetValue(rA.Get(), row, col, 1.0, INSERT_VALUES);</div><div> }</div><div> }</div><div> }</div><div><br></div><div> MatRestoreRow(rA.Get(), row, &ncols, &cols, &vals);</div><div> }</div><div><br></div><div> // cached the modification</div><div> MatAssemblyBegin(rA.Get(), MAT_FINAL_ASSEMBLY);</div><div> MatAssemblyEnd(rA.Get(), MAT_FINAL_ASSEMBLY);</div></div><div><br></div><div>This should set all the missing diagonal for missing rows. But I could not figure out why the error message above happen. Any ideas?</div><div><br></div><div>Regards</div><div>Giang</div><div><br></div></div>