My program loads a parallel PETSc matrix $A$ on several MPI processes, each holding a block submatrix $A_i$.
I would like to retrieve the local submatrix $A_i$, the one corresponding to the current rank.
I am not trying to alter the matrix $A_i$, I only need to read it and compute some information (determinant, eigenvalues, etc).
int main(int argc, char **args) {
PetscErrorCode ierr;
PetscViewer fd;
Mat A;
ierr = SlepcInitialize(&argc, &args, (char *) nullptr, nullptr);
if (ierr) return ierr;
// Open file
PetscViewerBinaryOpen(PETSC_COMM_WORLD, "matrix.mat", FILE_MODE_READ, &fd);
// Load into Petsc object
MatCreate(PETSC_COMM_WORLD, &A);
MatSetType(A, MATMPIBAIJ);
MatLoad(A, fd);
PetscViewerDestroy(&fd);
// Here I would like to manipulate the local submatrix of A
// For example to show information with MatView
// Clear workspace
MatDestroy(&A);
SlepcFinalize();
return 0;
}
What would be the right way to retrieve the local submatrix for the current rank?
Note: I am using SlepcInitialize
in order to use SLEPc for eigenvalues afterwards.
Edit :
I have pointers towards VecGetArray
, I think I need an equivalent for matrices, but MatGetArray
is not supposed to be used according to the documentation (and another post)