Preallocates memory for a sparse parallel matrix in AIJ format (the default parallel PETSc format). For good matrix assembly performance the user should preallocate the matrix storage by setting the parameters d_nz (or d_nnz) and o_nz (or o_nnz). By setting these parameters accurately, performance can be increased by more than a factor of 50.

Synopsis

Input Parameters

B

- the matrix

d_nz

- number of nonzeros per row in DIAGONAL portion of local submatrix
(same value is used for all local rows)

d_nnz

- array containing the number of nonzeros in the various rows of the
DIAGONAL portion of the local submatrix (possibly different for each row)
or NULL (PETSC_NULL_INTEGER in Fortran), if d_nz is used to specify the nonzero structure.
The size of this array is equal to the number of local rows, i.e 'm'.
For matrices that will be factored, you must leave room for (and set)
the diagonal entry even if it is zero.

o_nz

- number of nonzeros per row in the OFF-DIAGONAL portion of local
submatrix (same value is used for all local rows).

o_nnz

- array containing the number of nonzeros in the various rows of the
OFF-DIAGONAL portion of the local submatrix (possibly different for
each row) or NULL (PETSC_NULL_INTEGER in Fortran), if o_nz is used to specify the nonzero
structure. The size of this array is equal to the number
of local rows, i.e 'm'.

The parallel matrix is partitioned such that the first m0 rows belong to
process 0, the next m1 rows belong to process 1, the next m2 rows belong
to process 2 etc.. where m0,m1,m2... are the input parameter 'm'.

The DIAGONAL portion of the local submatrix of a processor can be defined
as the submatrix which is obtained by extraction the part corresponding to
the rows r1-r2 and columns c1-c2 of the global matrix, where r1 is the
first row that belongs to the processor, r2 is the last row belonging to
the this processor, and c1-c2 is range of indices of the local part of a
vector suitable for applying the matrix to. This is an mxn matrix. In the
common case of a square matrix, the row and column ranges are the same and
the DIAGONAL part is also square. The remaining portion of the local
submatrix (mxN) constitute the OFF-DIAGONAL portion.

If o_nnz, d_nnz are specified, then o_nz, and d_nz are ignored.

You can call MatGetInfo() to get information on how effective the preallocation was;
for example the fields mallocs,nz_allocated,nz_used,nz_unneeded;
You can also run with the option -info and look for messages with the string
malloc in them to see if additional memory allocation was needed.

This can be represented as a collection of submatrices as

Where the submatrices A,B,C are owned by proc0, D,E,F are
owned by proc1, G,H,I are owned by proc2.

The 'm' parameters for proc0,proc1,proc2 are 3,3,2 respectively.
The 'n' parameters for proc0,proc1,proc2 are 3,3,2 respectively.
The 'M','N' parameters are 8,8, and have the same values on all procs.

The DIAGONAL submatrices corresponding to proc0,proc1,proc2 are
submatrices [A], [E], [I] respectively. The OFF-DIAGONAL submatrices
corresponding to proc0,proc1,proc2 are [BC], [DF], [GH] respectively.
Internally, each processor stores the DIAGONAL part, and the OFF-DIAGONAL
part as SeqAIJ matrices. for eg: proc1 will store [E] as a SeqAIJ
matrix, ans [DF] as another SeqAIJ matrix.

When d_nz, o_nz parameters are specified, d_nz storage elements are
allocated for every row of the local diagonal submatrix, and o_nz
storage locations are allocated for every row of the OFF-DIAGONAL submat.
One way to choose d_nz and o_nz is to use the max nonzerors per local
rows for each of the local DIAGONAL, and the OFF-DIAGONAL submatrices.

In this case, the values of d_nz,o_nz are

We are allocating m*(d_nz+o_nz) storage locations for every proc. This
translates to 3*(2+2)=12 for proc0, 3*(3+2)=15 for proc1, 2*(1+4)=10
for proc3. i.e we are using 12+15+10=37 storage locations to store
34 values.

When d_nnz, o_nnz parameters are specified, the storage is specified
for every row, coresponding to both DIAGONAL and OFF-DIAGONAL submatrices.