petsc-3.7.1 2016-05-15
Report Typos and Errors

MatSeqAIJSetPreallocation

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.

Synopsis

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

Input Parameters

B - The matrix Many br
nz - number of nonzeros per row (same for all rows) Many br
nnz - array containing the number of nonzeros in the various rows Many br(possibly different for each row) or NULL Many br

Notes

If nnz is given then nz is ignored Many br

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

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

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

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

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

Options Database Keys

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

Many br

See Also

MatCreate(), MatCreateAIJ(), MatSetValues(), MatSeqAIJSetColumnIndices(), MatCreateSeqAIJWithArrays(), MatGetInfo()

Level:intermediate
Location:
src/mat/impls/aij/seq/aij.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/mat/examples/tutorials/ex15.c.html
src/mat/examples/tutorials/ex16.c.html
src/mat/examples/tutorials/ex17.c.html
src/ksp/ksp/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex3.c.html
src/ksp/ksp/examples/tutorials/ex4.c.html
src/ksp/ksp/examples/tutorials/ex7.c.html
src/ksp/ksp/examples/tutorials/ex18.c.html
src/ksp/ksp/examples/tutorials/ex52.c.html
src/ksp/ksp/examples/tutorials/ex55.c.html
src/ksp/ksp/examples/tutorials/ex56.c.html