Use VecView(), <a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecView.html">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecView.html</a>, to write the vector to a binary file and then use PetscBinaryRead() in Matlab<br>
<div><br></div><div>ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, filesol, FILE_MODE_WRITE, &binviewersol) ; CHKERRQ(ierr) ; </div><div>ierr = VecView(b,binviewersol);CHKERRQ(ierr);</div><div><br></div><div>In Matlab,</div>
<div>b = PetscBinaryRead(binviewersol,'complex', true);</div><div><br></div><div>See the function PetscBinaryRead() in $PETSC_DIR/bin/matlab</div><div><br><div class="gmail_quote">On Wed, Sep 7, 2011 at 9:17 PM, amrit poudel <span dir="ltr"><<a href="mailto:amrit_pou@hotmail.com">amrit_pou@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div dir="ltr">
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.<br><br>ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, filesol, FILE_MODE_WRITE, &binviewersol) ; CHKERRQ(ierr) ; <br>
ierr = PetscViewerBinaryGetDescriptor(binviewersol, &fd); CHKERRQ(ierr) ;<br>ierr = PetscBinaryWrite(fd, b, 5, PETSC_SCALAR, PETSC_FALSE); CHKERRQ(ierr) ;<br><br><br><br>Here is the error :<br><br><br>[1]PETSC ERROR: Write to file failed!<br>
[1]PETSC ERROR: Error writing to file.!<br><br><br><br>NOTE : Petsc is configured with complex option and Vec b has complex entries. Length of Vec b is 5 .<br>                                            </div></div>
</blockquote></div><br></div>