[petsc-users] output vec

Likun Tan likunt at caltech.edu
Thu May 22 11:20:13 CDT 2014


I am using VecView to output the vec in a binary file and tried to open it in Matlab. I define the precision to be double, but Matlab does not give reasonable values of my vec (almost extremely large or small or NaN values). Here is my code

========================================
PetscViewerBinaryOpen(PETSC_COMM_WORLD, NAME, FILE_MODE_WRITE, & view);
for(step=0; step<STEP; step++)
{
       //compute M at current step
       VecView(M, view);
}
PetscViewerDestroy(&view);
=======================================

I am not sure if there is any problem of my Petsc code. Your comment is well appreciated.

> On May 22, 2014, at 11:07 AM, Jed Brown <jed at jedbrown.org> wrote:
> 
> Likun Tan <likunt at caltech.edu> writes:
> 
>> Thanks for your suggestion.  
>> Using VecView or PetscViewerBinaryWrite will print the vec vertically, i.e.
>> m1
>> m2
>> m3
>> m4
>> m5
>> m6
> 
> The binary viewer writes a *binary* file.  No formatting or line breaks.
> 
>> But I prefer the form
>> 
>> m1 m2 m3
>> m4 m5 m6
>> 
>> Since in the end I will have about 1e+7 elements in the vec. If there is no way to output the vec in the second form, I will simply use VecView. Thanks.
> 
> Use VecView to write a binary (not ASCII) file.  See
> PetscViewerBinaryOpen().  You can look at it with python, matlab/octave,
> etc.


More information about the petsc-users mailing list