[petsc-users] Output portability, binary, HDF5, ascii

Lisandro Dalcin dalcinl at gmail.com
Thu Feb 18 15:36:33 CST 2010

On 18 February 2010 18:10, Barry Smith <bsmith at mcs.anl.gov> wrote:
> On Feb 18, 2010, at 2:35 PM, Arturo Fountain wrote:
>> Greetings:
>> I've been using the PETSc libraries for a few weeks now and am very
>> impressed with the software. Great work folks!
>> I'm writing with an issue I've been unable to work around. I'd like to
>> save output and import it into an external program (hdfview or matlab,
>> for example). Vectors are no problem to output but as mentioned at
>> https://lists.mcs.anl.gov/mailman/htdig/petsc-users/2010-January/005796.html,
>> this is not possible in PETSc for matrices.
>    This is an indirect way of doing but since PETSc can dump vectors and
> sparse matrices in PETSc format rapidly and they can be read into Matlab
> rapidly, could you then use Matlab's HDF5 capability to write then into any
> HDF5 format you like? I realize this is not ideal, but it is just a single
> extra postprocessing step.
>    You could also write your own PETSc object viewers that wrote to HDF5,
> for sparse matrices, but I think it is easy just to dump to Matlab and have
> it save it in the format you want.
>    ASCII is just SO slow for large data sets I think it is impractical.
>   Barry
>> Furthermore: "It won't buy
>> you any speed, disk space, or portability."
>> Certainly the PETSc binary format works fine for PETSc I/O but I am
>> unable to find anything to convert between this format and any other.
>> I'm most concerned with portability; I would like to utilize external
>> visualization packages. Is it standard practice to simply use ASCII
>> output? I can certainly do that but for larger problems size will
>> certainly become an impending issue....
>> Thanks in advance for any help you can offer,
>> Arturo

OTOH, PETSc binary format is extremely easy to read... for example,
feed the attached Python script with a PETSc binary file, and you will
see the sparse matrix line by line in your console:

$ python matio.py matrix.dat

try this with a small matrix, as printing a big matrix can take
forever. However, the readmat() function should perform extremely
well, all the actual IO is done in C, thanks to numpy,

Of course, you can do anything you want with the I, J, V numpy arrays,
like using any HDF5 Python wrapper to generate an hdf5 file...

Lisandro Dalcin
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
-------------- next part --------------
A non-text attachment was scrubbed...
Name: matio.py
Type: text/x-python
Size: 991 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100218/cc29a146/attachment.py>

More information about the petsc-users mailing list