[petsc-users] output vec

Likun Tan likunt at caltech.edu
Thu May 22 13:55:16 CDT 2014


Hi Matt,

I am not using PetscBinaryRead. I wrote a binary file from Petsc and use Matlab's function to read it, I.e.

fileID = fopen('result.bin', 'w');
data = fread(fileID, 'double');

But this gives me unreasonable values of data. I checked this example

http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex54f.F.html

which is exactly what I need for my problem. Do you have a C version of it ? Many thanks.

> On May 22, 2014, at 12:26 PM, Matthew Knepley <knepley at gmail.com> wrote:
> 
>> On Thu, May 22, 2014 at 11:20 AM, Likun Tan <likunt at caltech.edu> wrote:
>> 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
> 
> Are you using PetscBinaryRead.m in Matlab? If so, send the code snippet for a small vector, all the output, and the binary file.
> 
>   Matt
>  
>> ========================================
>> 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.
> 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
> -- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140522/adabe746/attachment.html>


More information about the petsc-users mailing list