[petsc-users] matload and petsc4py

Klaij, Christiaan C.Klaij at marin.nl
Thu Jun 6 07:52:28 CDT 2024


I'm writing a matrix to file from my fortran code (that uses petsc-3.19.4) with -mat_view binary. Then, I'm trying to load this mat into python (that uses petsc-3.21.0). This works fine using single or multiple procs when the marix was written using a single proc (attached file a_mat_np_1.dat). However, when the matrix was written using mulitple procs (attached file a_mat_n_2.dat) I get the error below. Is this supposed to work? If so, what I'm I doing wrong?

$ cat test_matrixImport_binary.py
import sys
import petsc4py
from petsc4py import PETSc
from mpi4py import MPI

# mat files
#filename = "./a_mat_np_1.dat"  # Works
filename = "./a_mat_np_2.dat"   # Doesn't work

# Initialize PETSc
petsc4py.init(sys.argv)

# Create a viewer for reading the binary file
viewer = PETSc.Viewer().createBinary(filename, mode='r', comm=PETSc.COMM_WORLD)

# Create a matrix and load data from the binary file
A = PETSc.Mat().create(comm=PETSc.COMM_WORLD)
A.load(viewer)

$ python test_matrixImport_binary.py 
Traceback (most recent call last):
  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module>
    A.load(viewer)
  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load
petsc4py.PETSc.Error: error code 79
[0] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344
[0] MatLoad_SeqAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/seq/aij.c:5091
[0] MatLoad_SeqAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/seq/aij.c:5142
[0] Unexpected data in file
[0] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761

$ mpirun -n 2 python test_matrixImport_binary.py 
Traceback (most recent call last):
  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module>
Traceback (most recent call last):
  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module>
    A.load(viewer)
  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load
    A.load(viewer)
  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load
petsc4py.PETSc.Error: error code 79
[0] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344
[0] MatLoad_MPIAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3035
[0] MatLoad_MPIAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3087
[0] Unexpected data in file
[0] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761
petsc4py.PETSc.Error: error code 79
[1] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344
[1] MatLoad_MPIAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3035
[1] MatLoad_MPIAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3087
[1] Unexpected data in file
[1] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761



dr. ir. Christiaan Klaij
 | Senior Researcher | Research & Development
T +31 317 49 33 44 |  C.Klaij at marin.nl | https://urldefense.us/v3/__http://www.marin.nl__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWm7XFthU$ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image337700.png
Type: image/png
Size: 5004 bytes
Desc: image337700.png
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image563921.png
Type: image/png
Size: 487 bytes
Desc: image563921.png
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image268336.png
Type: image/png
Size: 504 bytes
Desc: image268336.png
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image799923.png
Type: image/png
Size: 482 bytes
Desc: image799923.png
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_mat_np_1.dat
Type: application/octet-stream
Size: 5936 bytes
Desc: a_mat_np_1.dat
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_mat_np_1.dat.info
Type: application/octet-stream
Size: 22 bytes
Desc: a_mat_np_1.dat.info
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_mat_np_2.dat
Type: application/octet-stream
Size: 2976 bytes
Desc: a_mat_np_2.dat
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_mat_np_2.dat.info
Type: application/octet-stream
Size: 22 bytes
Desc: a_mat_np_2.dat.info
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240606/90f7657b/attachment-0007.obj>


More information about the petsc-users mailing list