[petsc-users] Better way to pre-allocate memory for matrix being read in ???

Gaurish Telang gaurish108 at gmail.com
Sun Feb 13 16:37:11 CST 2011


I have a text file containing the non-zero entries of a sparse matrix of
dimension 2683x1274, stored in the form (row, column, element) i.e. [i, j,
element] format.

That is ALL the information I have regarding the matrix.

However when pre-allocating memory with  MatSeqAIJSetPreallocation(Mat
B,PetscInt nz,const PetscInt nnz[]),  the parameters nz and nnz need to be

nz=number of nonzeros per row (same for all rows)
nnz=array containing the number of nonzeros in the various rows (possibly
different for each row) or

which i do not know for my matrix, ( unless I resort to using MATLAB. ).

Does that mean I have to set nz= 1274 (the length of a row) and
nnz=PETSC_NULL ?  Though,  I guess this setting would consume a lot of
memory for higher order matrices.

How then, should I go about memory pre-allocation more efficiently?

Gaurish Telang

There is a code in the PETSc folder (/src/mat/examples/tests/ex78.c ) which
reads in a matrix of this format.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110213/72d7080a/attachment.htm>

More information about the petsc-users mailing list