[petsc-users] Loading Binary file problem

Jin, Shuangshuang Shuangshuang.Jin at pnnl.gov
Tue Jun 26 18:31:27 CDT 2012


Jed, thanks for pointing out that the program expects a matrix followed by a vector in the file.

I created a new binary file “myAb.dat” in matlab by adding the b vector.
A = [1     2     0;
     2     0     5;
     0     3     0;
     1     4     1]
b = [1 2 3]'
PetscBinaryWrite('myAb.dat',sparse(A),b)
[AA bb] = PetscBinaryRead('myAb.dat')

The PETSc program works with this input file now:
$ ./ex12 -f0 myAb.dat
Matrix Object: 1 MPI processes
  type: seqaij
row 0: (0, 1)  (1, 2)
row 1: (0, 2)  (2, 5)
row 2: (1, 3)
row 3: (0, 1)  (1, 4)  (2, 1)
Matrix Object: 1 MPI processes
  type: seqaij
row 0: (0, 1)  (1, 2)  (4, 1)
row 1: (0, 2)  (2, 5)  (4, 2)
row 2: (1, 3)  (4, 3)
row 3: (0, 1)  (1, 4)  (2, 1)  (4, 2.22295e-319)
row 4: (0, 1)  (1, 2)  (2, 3)  (3, 2.22295e-319)  (4, 3)

Thanks,
Shuangshuang


From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Jed Brown
Sent: Tuesday, June 26, 2012 4:02 PM
To: PETSc users list
Subject: Re: [petsc-users] Loading Binary file problem

On Tue, Jun 26, 2012 at 1:09 PM, Jin, Shuangshuang <Shuangshuang.Jin at pnnl.gov<mailto:Shuangshuang.Jin at pnnl.gov>> wrote:
Hello everyone,

     I created a 4*3 matrix A in matlab, saved it to binary file “myA.dat” using PetscBinaryWrite(‘myA.dat’,sparse(A)). Everything seems fine to me because I can read the binary file ‘myA.dat’ by PetscBinaryRead('myA.dat')correctly.

A = [1     2     0;
     2     0     5;
     0     3     0;
     1     4     1]
PetscBinaryWrite('myA.dat',sparse(A))
PetscBinaryRead('myA.dat')

However, when I tried to load the binary file “myA.dat” in PETSc using the example code “ex12.c” under “petsc-3.3-p0/src/mat/examples/tutorials”, I got error message below:

[d3m956 at olympus tutorials]$ ./ex12 -f0 myA.dat

This program expects a matrix followed by a vector in the file. You can use -rhs 0 to skip reading the right hand side vector from the file, it will use a vector of all ones.

[0]PETSC ERROR: --------------------- Error Message ------------------------------------
[0]PETSC ERROR: Read from file failed!
[0]PETSC ERROR: Read past end of file!
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Petsc Release Version 3.3.0, Patch 0, Tue Jun  5 14:20:42 CDT 2012
[0]PETSC ERROR: See docs/changes/index.html for recent updates.
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
[0]PETSC ERROR: See docs/index.html for manual pages.
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: ./ex12 on a arch-linu named olympus.local by d3m956 Tue Jun 26 13:51:28 2012
[0]PETSC ERROR: Libraries linked from /pic/projects/mca/ss/PETSC/petsc-3.3-p0/arch-linux2-c-debug/lib
[0]PETSC ERROR: Configure run at Thu Jun 14 17:00:19 2012
[0]PETSC ERROR: Configure options --with-cc=gcc --with-fc=gfortran --download-f-blas-lapack --download-mpich
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: PetscBinaryRead() line 271 in src/sys/fileio/sysio.c
[0]PETSC ERROR: PetscBinarySynchronizedRead() line 558 in src/sys/fileio/sysio.c
[0]PETSC ERROR: PetscViewerBinaryRead() line 764 in src/sys/viewer/impls/binary/binv.c
[0]PETSC ERROR: PetscViewerBinaryReadVecHeader_Private() line 24 in src/vec/vec/utils/vecio.c
[0]PETSC ERROR: VecLoad_Binary() line 97 in src/vec/vec/utils/vecio.c
[0]PETSC ERROR: VecLoad_Default() line 348 in src/vec/vec/utils/vecio.c
[0]PETSC ERROR: VecLoad() line 1111 in src/vec/vec/interface/vector.c
[0]PETSC ERROR: main() line 92 in src/mat/examples/tutorials/ex12.c

It said “Read from file failed! Read past end of file!” Anything wrong? I was using the example code without changing anything. Please help me to figure out the problem.

Thanks,
Shuangshuang



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


More information about the petsc-users mailing list