For good matrix assembly performance the user should preallocate the matrix storage by setting the parameter nz (or the array nnz). By setting these parameters accurately, performance during matrix assembly can be increased by more than a factor of 50.


#include "petscmat.h" 
PetscErrorCode PETSCMAT_DLLEXPORT MatSeqAIJSetPreallocation(Mat B,PetscInt nz,const PetscInt nnz[])
Collective on MPI_Comm

Input Parameters

B - The matrix
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 PETSC_NULL

C++ variants

  MatSeqAIJSetPreallocation(Mat A,const PetscInt nnz[])->MatSeqAIJSetPreallocation(A,0,nnz)


If nnz is given then nz is ignored

The AIJ format (also called the Yale sparse matrix format or compressed row storage), is fully compatible with standard Fortran 77 storage. That is, the stored row and column indices can begin at either one (as in Fortran) or zero. See the users' manual for details.

Specify the preallocated storage with either nz or nnz (not both). Set nz=PETSC_DEFAULT and nnz=PETSC_NULL for PETSc to control dynamic memory allocation. For large problems you MUST preallocate memory or you will get TERRIBLE performance, see the users' manual chapter on matrices.

Developers: Use nz of MAT_SKIP_ALLOCATION to not allocate any space for the matrix entries or columns indices

By default, this format uses inodes (identical nodes) when possible, to improve numerical efficiency of matrix-vector products and solves. We search for consecutive rows with the same nonzero structure, thereby reusing matrix information to achieve increased efficiency.

Options Database Keys

-mat_no_inode - Do not use inodes
-mat_inode_limit <limit> - Sets inode limit (max limit=5)
-mat_aij_oneindex - Internally use indexing starting at 1 rather than 0. Note that when calling MatSetValues(), the user still MUST index entries starting at 0!

See Also

MatCreate(), MatCreateMPIAIJ(), MatSetValues(), MatSeqAIJSetColumnIndices(), MatCreateSeqAIJWithArrays()

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages