# MatSeqBDiagSetPreallocation

Sets the nonzero structure and (optionally) arrays.

### Synopsis

    PetscErrorCode PETSCMAT_DLLEXPORT MatSeqBDiagSetPreallocation(Mat B,PetscInt nd,PetscInt bs,const PetscInt diag[],PetscScalar *diagv[])

Collective on MPI_Comm

### Input Parameters

| B | - the matrix
| nd | - number of block diagonals (optional)
| bs | - each element of a diagonal is an bs x bs dense matrix
| diag | - optional array of block diagonal numbers (length nd). For a matrix element A[i,j], where i=row and j=column, the diagonal number is

        diag = i/bs - j/bs  (integer division)

Set diag=PETSC_NULL on input for PETSc to dynamically allocate memory as needed (expensive).
| diagv | - pointer to actual diagonals (in same order as diag array), if allocated by user. Otherwise, set diagv=PETSC_NULL on input for PETSc to control memory allocation.

### Options Database Keys

-mat_block_size <bs> -Sets blocksize
-mat_bdiag_diags <s1,s2,s3,...> -Sets diagonal numbers

### Notes

See the users manual for further details regarding this storage format.

### Fortran Note

Fortran programmers cannot set diagv; this value is ignored.

### Keywords

matrix, block, diagonal, sparse

### See Also

MatCreate(), MatCreateMPIBDiag(), MatSetValues()

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

### Examples

src/ksp/examples/tutorials/ex4.c.html