[petsc-users] RAW binary write

Matthew Knepley knepley at gmail.com
Fri Nov 30 07:20:38 CST 2018


On Fri, Nov 30, 2018 at 4:03 AM Sal Am <tempohoper at gmail.com> wrote:

> Hi Matthew,
>
> by raw I mean something the equivalent of pure C++ like
>
> std::fstream fout("Vector_b.bin",std::ios::out | std::ios::binary);
> fout.write((char*)&b[i],sizeof(std::complex<double>));
> fout.close();  //std::vector< std::complex<double> > b
>
> i.e. without the PETSc format information, so I can use the resulting data
> in other software.
>

That format would not let the user know how big the vector was. Moreover,
other people would
want other slightly different formats. The PETSc binary viewer is built
from lower level PETSc
functions which you could use to build whatever output you want.

  Thanks,

     Matt


> Thanks
>
>
>
> On Thu, Nov 29, 2018 at 4:39 PM Matthew Knepley <knepley at gmail.com> wrote:
>
>> On Thu, Nov 29, 2018 at 10:50 AM Sal Am via petsc-users <
>> petsc-users at mcs.anl.gov> wrote:
>>
>>> Is there a way to write the solution from the system Ax=b in raw binary
>>> instead of PETSc binary format?
>>>
>>
>> What is "raw binary". You have to have some format.
>>
>>    Matt
>>
>>
>>> Currently I am doing:
>>>   ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,
>>> "../../python/petscpy/Vector_x_petsc.dat", FILE_MODE_WRITE,
>>> &viewer);CHKERRQ(ierr);
>>>   ierr = VecView(x,viewer);CHKERRQ(ierr);CHKERRQ(ierr);
>>>   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>>>
>>> And then use PetscBinaryIO to read it back and save it using
>>> write('newformat', 'wb') to get to raw... however this approach is not good
>>> it seems as there are some troubles with little/big endian when using the
>>> resulting converted file on other systems for post-processing.
>>>
>>> Thanks,
>>>
>>
>>
>> --
>> 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
>>
>> https://www.cse.buffalo.edu/~knepley/
>> <http://www.cse.buffalo.edu/~knepley/>
>>
>

-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181130/99d7e2da/attachment.html>


More information about the petsc-users mailing list