[petsc-users] PETSc Error when writing a vector object to a binary file

amrit poudel amrit_pou at hotmail.com
Wed Sep 7 22:15:10 CDT 2011





Thanks. That worked out okay!


Date: Wed, 7 Sep 2011 21:43:17 -0500
From: abhyshr at hawk.iit.edu
To: petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] PETSc Error when writing a vector object to a binary file

Use VecView(), http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecView.html, to write the vector to a binary file and then use PetscBinaryRead() in Matlab


ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, filesol, FILE_MODE_WRITE, &binviewersol) ; CHKERRQ(ierr) ; ierr = VecView(b,binviewersol);CHKERRQ(ierr);
In Matlab,
b = PetscBinaryRead(binviewersol,'complex', true);
See the function PetscBinaryRead() in $PETSC_DIR/bin/matlab
On Wed, Sep 7, 2011 at 9:17 PM, amrit poudel <amrit_pou at hotmail.com> wrote:






I am using the following sequence of commands to write a Vec b to a binary file  and then eventually read it in MATLAB, but I get an error when I try writing this vector to a file in PETSc.

ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, filesol, FILE_MODE_WRITE, &binviewersol) ; CHKERRQ(ierr) ;    

ierr = PetscViewerBinaryGetDescriptor(binviewersol, &fd); CHKERRQ(ierr) ;
ierr = PetscBinaryWrite(fd, b, 5, PETSC_SCALAR, PETSC_FALSE);    CHKERRQ(ierr) ;



Here is the error :


[1]PETSC ERROR: Write to file failed!

[1]PETSC ERROR: Error writing to file.!



NOTE : Petsc is configured with complex option and Vec b has complex entries. Length of Vec b is 5 .
 		 	   		  

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110908/f82cf6af/attachment.htm>


More information about the petsc-users mailing list