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 | [email protected] |
https://urldefense.us/v3/__http://www.marin.nl__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWm7XFthU$
a_mat_np_1.dat
Description: a_mat_np_1.dat
a_mat_np_1.dat.info
Description: a_mat_np_1.dat.info
a_mat_np_2.dat
Description: a_mat_np_2.dat
a_mat_np_2.dat.info
Description: a_mat_np_2.dat.info
