[petsc-users] RAW binary write

Matthew Knepley knepley at gmail.com
Tue Dec 4 10:53:18 CST 2018


On Tue, Dec 4, 2018 at 11:11 AM Lisandro Dalcin via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> PetscByteSwap ? But be careful, you should (1) vec get array, byteswap,
> vec restore array, (2) view, (3) vec get array, byteswap, vec restore
> array. Of course, if you do not care about the final Vec contents, you can
> just omit step (3) and let it be, let it be...
>
> PS: Eventually, PETSc binary viewers should gain an API like
> PetscViewerBinarySetByteOrder(viewer, PETSC_LITTLE_ENDIAN) ...
>

Note that this enables exactly what we wanted to avoid, namely binary files
that an incompatible with some installations.

   Matt


> On Tue, 4 Dec 2018 at 12:33, Sal Am <tempohoper at gmail.com> wrote:
>
>> Thank you so much Lisandro!
>>
>> That was very helpful actually and what I was looking for, but now it
>> still requires an intermediate step of a short python script where I have
>> to use byteswap() on the data to get it to work on other platforms.
>> Would you happen to know any way of byteswapping in petsc? I was reading
>> and it seems PetscBinaryWrite does byteswapping but I am not sure it would
>> work in my case as there are no examples with it writing a petsc vector.
>>
>> Thanks and all the best
>>
>> On Sun, Dec 2, 2018 at 10:01 AM Lisandro Dalcin <dalcinl at gmail.com>
>> wrote:
>>
>>> Use PetscViewerBinarySetSkipHeader(viewer, PETSC_TRUE) before VecView().
>>>
>>> On Thu, 29 Nov 2018 at 18:50, 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?
>>>>
>>>> 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,
>>>>
>>>
>>>
>>> --
>>> Lisandro Dalcin
>>> ============
>>> Research Scientist
>>> Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
>>> Extreme Computing Research Center (ECRC)
>>> King Abdullah University of Science and Technology (KAUST)
>>> http://ecrc.kaust.edu.sa/
>>>
>>> 4700 King Abdullah University of Science and Technology
>>> al-Khawarizmi Bldg (Bldg 1), Office # 0109
>>> Thuwal 23955-6900, Kingdom of Saudi Arabia
>>> http://www.kaust.edu.sa
>>>
>>> Office Phone: +966 12 808-0459
>>>
>>
>
> --
> Lisandro Dalcin
> ============
> Research Scientist
> Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
> Extreme Computing Research Center (ECRC)
> King Abdullah University of Science and Technology (KAUST)
> http://ecrc.kaust.edu.sa/
>
> 4700 King Abdullah University of Science and Technology
> al-Khawarizmi Bldg (Bldg 1), Office # 0109
> Thuwal 23955-6900, Kingdom of Saudi Arabia
> http://www.kaust.edu.sa
>
> Office Phone: +966 12 808-0459
>


-- 
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/20181204/56bba8ff/attachment.html>


More information about the petsc-users mailing list