[petsc-users] output vec

likunt at caltech.edu likunt at caltech.edu
Thu May 22 18:01:06 CDT 2014


Thanks for your suggestion.
I've successfully read some binary files from petsc examples using
PetscBinaryRead, but I still have problem when reading the binary file
from my code. The issue is that only the first 8 elements are read
correctly and the rest are either extremely large or small numbers. I am
using the following commands for data output:

PetscViewerBinaryOpen(PETSC_COMM_WORLD, 'result.txt', FILE_MODE_WRITE,
&view);
VecView(field.M, view);
PetscViewerDestroy(&view);

Would you please give comments on the possible reason for this? Thank you.

> On Thu, May 22, 2014 at 1:55 PM, Likun Tan <likunt at caltech.edu> wrote:
>
>> 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.
>
> Why would you rewrite this?
>
>
> https://bitbucket.org/petsc/petsc/src/2c43c009db31f079231059c9efed501d4deca8bf/bin/matlab/PetscBinaryRead.m?at=master
>
>    Matt
>
>
>> 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
>
>
> --
> 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
>






More information about the petsc-users mailing list