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

Barry Smith bsmith at mcs.anl.gov
Wed Sep 7 21:51:44 CDT 2011


On Sep 7, 2011, at 9:17 PM, amrit poudel 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) ;

   This is not how you would write a Vec to a binary file. PetscBinaryWrite() is for writing raw bytes to a binary file (a low level operation).  Use VecView(b, binviewersol); to write a vector.

   Barry

> 
> 
> 
> 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 .



More information about the petsc-users mailing list