[petsc-users] petsc binary matrix file for dense matrices

Jed Brown jedbrown at mcs.anl.gov
Tue Apr 10 06:55:37 CDT 2012


On Tue, Apr 10, 2012 at 04:27, Umut Tabak <u.tabak at tudelft.nl> wrote:

> I first had a look at the MATLAB routines to read and write the matrices
> as examples and MatLoad function manual. I got the idea however I have a
> question regarding the write operation for dense matrices, in MATLAB code,
> it is given as
>
>    [m,n] = size(A);
>    write(fd,[1211214,m*n],'int32'**);
>    write(fd,A,'double');
>

I suggest just using

PetscBinaryWrite('filename',sparse(A))

The scripts are in $PETSC_DIR/bin/matlab.

PETSc binary format does not contain information for storing dense matrices
as dense. Note that you can still read the "sparse" matrix on disk as a
dense matrix. Also, if you compress the binary (e.g. gzip), it will be
essentially the same size (because the column indices are so regular). For
example, writing a 1000x1000 random matrix (the entries essentially don't
compress for a random matrix), I have

-rw-r--r-- 1 jed users  8000008 Apr 10 06:52 densematrix
-rw-r--r-- 1 jed users 12004016 Apr 10 06:52 sparsematrix
-rw-r--r-- 1 jed users 7539706 Apr 10 06:52 densematrix.gz
-rw-r--r-- 1 jed users 7568387 Apr 10 06:52 sparsematrix.gz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120410/c2bda468/attachment.htm>


More information about the petsc-users mailing list