[petsc-users] PETSc Matrix to MatLab

Zhang, Hong hzhang at mcs.anl.gov
Fri May 17 10:49:22 CDT 2019

Check your petsc matrix before dumping the data by adding
immediately after calling MatAssemblyEnd().
Do you see a correct parallel matrix?

On Fri, May 17, 2019 at 10:24 AM Emmanuel Ayala via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:

I am a newby with PETSc. I want to check some matrices generated in PETSc, using MatLab.

I created a matrix A (MATMPIAIJ), the partition is defined by PETSc and I defined the global size.

Then, I used the next code to save in binary format the matrix from PETSc:

PetscViewer    viewer;
PetscViewerBinaryOpen(PETSC_COMM_WORLD, "matrix", FILE_MODE_WRITE, &viewer);

After that (I think) MatView writes in the viewer:


Then I laod the matrix in MatLab with PetscBinaryRead().

For one process everything is Ok, I can see the full pattern of the sparse matrix (spy(A)). But when I generate the matrix A with more than one process, the resultant matrix only contains the data from the process 0.

What is the mistake in my procedure?

1. I just want to export the PETSc matrix to MatLab, for any number of process.

Thanks in advance, for your time.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190517/d2027fdc/attachment.html>

More information about the petsc-users mailing list