# MatMPIAIJSetPreallocationCSR
Allocates memory for a sparse parallel matrix in `MATAIJ` format (the default parallel PETSc format). 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat B, const PetscInt i[], const PetscInt j[], const PetscScalar v[])
```
Collective


## Input Parameters

- ***B -*** the matrix
- ***i -*** the indices into j for the start of each local row (starts with zero)
- ***j -*** the column indices for each local row (starts with zero)
- ***v -*** optional values in the matrix





## Notes
The i, j, and v arrays ARE copied by this routine into the internal format used by PETSc;
thus you CANNOT change the matrix entries by changing the values of v[] after you have
called this routine. Use `MatCreateMPIAIJWithSplitArrays()` to avoid needing to copy the arrays.

The i and j indices are 0 based, and i indices are indices corresponding to the local j array.

The format which is used for the sparse matrix input, is equivalent to a
row-major ordering.. i.e for the following matrix, the input data expected is
as shown

```none
1 0 0
```
```none
2 0 3     P0
```
```none
-------
```
```none
4 5 6     P1
```
```none
```
```none
Process0 [P0]: rows_owned=[0,1]
```
```none
i =  {0,1,3}  [size = nrow+1  = 2+1]
```
```none
j =  {0,0,2}  [size = 3]
```
```none
v =  {1,2,3}  [size = 3]
```
```none
```
```none
Process1 [P1]: rows_owned=[2]
```
```none
i =  {0,3}    [size = nrow+1  = 1+1]
```
```none
j =  {0,1,2}  [size = 3]
```
```none
v =  {4,5,6}  [size = 3]
```


## See Also
 `MATMPIAIJ`, `MatCreate()`, `MatCreateSeqAIJ()`, `MatSetValues()`, `MatMPIAIJSetPreallocation()`, `MatCreateAIJ()`, `MATMPIAIJ`,
`MatCreateSeqAIJWithArrays()`, `MatCreateMPIAIJWithSplitArrays()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatMPIAIJSetPreallocationCSR">src/mat/impls/aij/mpi/mpiaij.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatMPIAIJSetPreallocationCSR_MPIAIJ">MatMPIAIJSetPreallocationCSR_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>


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


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