:orphan:
# 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 (starts with zero)
- ***j -*** the column indices for each row (starts with zero) these must be sorted for each row
- ***v -*** optional values in the matrix





## 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
 [](ch_matrices), `Mat`, `MatCreate()`, `MatCreateSeqAIJ()`, `MatSetValues()`, `MatSeqAIJSetPreallocation()`, `MatCreateSeqAIJ()`, `MATSEQAIJ`, `MatResetPreallocation()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatSeqAIJSetPreallocationCSR">src/mat/impls/aij/seq/aij.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatSeqAIJSetPreallocationCSR_SeqAIJ">MatSeqAIJSetPreallocationCSR_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/aij/seq/aij.c)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
