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

# MatSeqBAIJSetPreallocation

Sets the block size and expected nonzeros per row in the matrix. 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  MatSeqBAIJSetPreallocation(Mat B,PetscInt bs,PetscInt nz,const PetscInt nnz[])

Collective on MPI_Comm Many br

### Input Parameters

| B | - the matrix Many br
| bs | - size of block, the blocks are ALWAYS square. One can use MatSetBlockSizes() to set a different row and column blocksize but the row Many brblocksize always defines the size of the blocks. The column blocksize sets the blocksize of the vectors obtained with MatCreateVecs() Many br
| nz | - number of block nonzeros per block row (same for all rows) Many br
| nnz | - array containing the number of block nonzeros in the various block rows Many br(possibly different for each block row) or NULL Many br

### Options Database Keys

-mat_no_unroll -uses code that does not unroll the loops in the Many brblock calculations (much slower) Many br
-mat_block_size -size of the blocks to use Many br

Many br

### Notes

If the nnz parameter is given then the nz parameter is ignored 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

The block AIJ format 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. See Users-Manual: ch_mat for details. Many br

### See Also

MatCreate(), MatCreateSeqAIJ(), MatSetValues(), MatCreateBAIJ(), MatGetInfo()

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

### Examples

src/mat/examples/tutorials/ex17.c.html
src/snes/examples/tutorials/ex48.c.html