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/20110907/bf0ce940/attachment.htm>
