<div class="gmail_quote">On Tue, Apr 10, 2012 at 04:27, Umut Tabak <span dir="ltr"><<a href="mailto:u.tabak@tudelft.nl">u.tabak@tudelft.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":1k7">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<br>
<br>
[m,n] = size(A);<br>
write(fd,[1211214,m*n],'int32'<u></u>);<br>
write(fd,A,'double');<br></div></blockquote><div><br></div><div>I suggest just using</div><div><br></div><div>PetscBinaryWrite('filename',sparse(A))</div><div><br></div><div>The scripts are in $PETSC_DIR/bin/matlab.</div>
<div><br></div><div>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</div>
<div><br></div><div>-rw-r--r-- 1 jed users 8000008 Apr 10 06:52 densematrix</div><div>-rw-r--r-- 1 jed users 12004016 Apr 10 06:52 sparsematrix</div><div><div>-rw-r--r-- 1 jed users 7539706 Apr 10 06:52 densematrix.gz</div>
<div>-rw-r--r-- 1 jed users 7568387 Apr 10 06:52 sparsematrix.gz</div></div></div>