Hello, > MatGetOwnershipRangesColumn
Thanks! That's what I was looking for. I have set a MatSetLocalToGlobalMapping on the matrix and I use MatMPIAIJSetPreallocation(_matrixA.matrix, 0, d_nnz, 0, o_nnz) to set the preallocation. Am I right to assume that nnz is to in the the PETSc ordering of rows and not application ordering? Best Thanks, Florian Am Mittwoch, 6. April 2016, 10:19:23 CEST schrieben Sie: > On Wed, Apr 6, 2016 at 10:12 AM, Florian Lindner <mailingli...@xgm.de> > wrote: > > > Hello, > > > > in order to preallocate I have to know whether a non-zero will be in the > > local diagonal submatrix or not. > > > > > > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html > > > > says: > > > > The DIAGONAL portion of the local submatrix of a processor can be defined > > as the submatrix which is obtained by extraction the part corresponding to > > the rows r1-r2 and columns c1-c2 of the global matrix, where r1 is the > > first row that belongs to the processor, r2 is the last row belonging to > > the this processor, and c1-c2 is range of indices of the local part of a > > vector suitable for applying the matrix to. This is an mxn matrix. In the > > common case of a square matrix, the row and column ranges are the same and > > the DIAGONAL part is also square. The remaining portion of the local > > submatrix (mxN) constitute the OFF-DIAGONAL portion. > > > > Therefore I compute the begin and end rows and cols like that: > > > > int ownerRangeBeginA = _matrixA.ownerRange().first; > > int ownerRangeEndA = _matrixA.ownerRange().second; > > > > // Uses: MatGetVecs(_matrixA.matrix, &vector, nullptr); > > petsc::Vector diagTest{_matrixA, "test", petsc::Vector::RIGHT}; > > > > int localDiagColBegin = diagTest.ownerRange().first; > > int localDiagColEnd = diagTest.ownerRange().second; > > > > Debug("Local Submatrix Rows = " << ownerRangeBeginA << " / " << > > ownerRangeEndA << > > ", Local Submatrix Cols = " << localDiagColBegin << " / " << > > localDiagColEnd); > > > > > > It's a little bit tainted by my PETSc C++ helper function, but I think you > > get the code. > > > > Is there a way to do it more elegantly? Without instantiating a vector > > just for the purpose of gettings its owner range? And then testing a if an > > index is inside the local diagonal submatrix? > > > > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetOwnershipRangesColumn.html > > Thanks, > > Matt > > > > Thanks, > > Florian > > > > > >