Skip to main content
`Ctrl`+`K`

# MatBlockMatSetPreallocation

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 MatBlockMatSetPreallocation(Mat B, PetscInt bs, PetscInt nz, const PetscInt nnz[])

Collective

## Input Parameters

- B - The matrix

- bs - size of each block in matrix

- nz - number of nonzeros per block row (same for all rows)

- nnz - array containing the number of nonzeros in the various block rows (possibly different for each row) or `NULL`

## Notes

If `nnz` is given then `nz` is ignored

Specify the preallocated storage with either `nz` or `nnz` (not both). Set `nz` = `PETSC_DEFAULT` and `nnz` = `NULL` for PETSc to control dynamic memory allocation.

## See Also

Matrices, `Mat`, `MatCreate()`, `MatCreateBlockMat()`, `MatSetValues()`

## Level

intermediate

## Location

src/mat/impls/blockmat/seq/blockmat.c

## Implementations

MatBlockMatSetPreallocation_BlockMat() in src/mat/impls/blockmat/seq/blockmat.c

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