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?

Thanks,
Florian

Reply via email to