[petsc-users] matload and petsc4py

Barry Smith bsmith at petsc.dev
Thu Jun 6 08:31:18 CDT 2024


  When I attempt to read the "np_2" data into Matlab (the reading process doesn't use any PETSc code) I get the same failure. It does look like the file is corrupted.

  Barry


> On Jun 6, 2024, at 8:52 AM, Klaij, Christiaan <C.Klaij at marin.nl> wrote:
> 
> This Message Is From an External Sender
> This message came from outside your organization.
> 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
> 
> 
> <image337700.png>
> dr. ir.​​​​ 	Christiaan	 Klaij
>  | 	Senior Researcher	 | 	Research & Development	
> T +31 317 49 33 44 <tel:+31%20317%2049%2033%2044>	 | 	 C.Klaij at marin.nl <mailto:C.Klaij at marin.nl> 	| https://urldefense.us/v3/__http://www.marin.nl__;!!G_uCfscf7eWS!a1xtGgs31Xt_6pJ-UUpqz9O6jfNb7GDOBoRRBZiCsTwsrgfsArGejlWuyqulRp-L3Q1cvQfBgn2XWeWbC9vB554$  <https://urldefense.us/v3/__https://www.marin.nl/__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWBYeP9zg$>
> <image563921.png> <https://urldefense.us/v3/__https://www.facebook.com/marin.wageningen__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWzqK6wKw$>	
> <image268336.png> <https://urldefense.us/v3/__https://www.linkedin.com/company/marin__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWIUyfXbM$>	
> <image799923.png> <https://urldefense.us/v3/__https://www.youtube.com/marinmultimedia__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWjtUkoeg$><a_mat_np_1.dat><a_mat_np_1.dat.info><a_mat_np_2.dat><a_mat_np_2.dat.info>

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


More information about the petsc-users mailing list