Skip to main content
`Ctrl`+`K`

# MatSeqAIJSetPreallocationCSR

Allocates memory for a sparse sequential matrix in `MATSEQAIJ` format.

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat B, const PetscInt i[], const PetscInt j[], const PetscScalar v[])

## Input Parameters

- B - the matrix

- i - the indices into `j` for the start of each row (indices start with zero)

- j - the column indices for each row (indices start with zero) these must be sorted for each row

- v - optional values in the matrix, use `NULL` if not provided

## Notes

The `i`,`j`,`v` values are COPIED with this routine; to avoid the copy use `MatCreateSeqAIJWithArrays()`

This routine may be called multiple times with different nonzero patterns (or the same nonzero pattern). The nonzero structure will be the union of all the previous nonzero structures.

## Developer Notes

An optimization could be added to the implementation where it checks if the `i`, and `j` are identical to the current `i` and `j` and then just copies the `v` values directly with `PetscMemcpy()`.

This routine could also take a `PetscCopyMode` argument to allow sharing the values instead of always copying them.

## See Also

Matrices, `Mat`, `MatCreate()`, `MatCreateSeqAIJ()`, `MatSetValues()`, `MatSeqAIJSetPreallocation()`, `MATSEQAIJ`, `MatResetPreallocation()`

## Level

developer

## Location

src/mat/impls/aij/seq/aij.c

## Implementations

MatSeqAIJSetPreallocationCSR_SeqAIJ() in src/mat/impls/aij/seq/aij.c

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