:orphan:
# MatPreallocatorPreallocate
Preallocates the A matrix, using information from a `MATPREALLOCATOR` mat, optionally filling A with zeros 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatPreallocatorPreallocate(Mat mat, PetscBool fill, Mat A)
```

## Input Parameters

- ***mat  -*** the `MATPREALLOCATOR` preallocator matrix
- ***fill -*** fill the matrix with zeros
- ***A    -*** the matrix to be preallocated



## Notes
This `MatType` implementation provides a helper utility to define the correct
preallocation data for a given nonzero structure. Use this object like a
regular matrix, e.g. loop over the nonzero structure of the matrix and
call `MatSetValues()` or `MatSetValuesBlocked()` to indicate the nonzero locations.
The matrix entries provided to `MatSetValues()` will be ignored, it only uses
the row / col indices provided to determine the information required to be
passed to `MatXAIJSetPreallocation()`. Once you have looped over the nonzero
structure, you must call `MatAssemblyBegin()`, `MatAssemblyEnd()` on mat.

After you have assembled the preallocator matrix (mat), call `MatPreallocatorPreallocate()`
to define the preallocation information on the matrix (A). Setting the parameter
fill = PETSC_TRUE will insert zeros into the matrix A. Internally `MatPreallocatorPreallocate()`
will call `MatSetOption`(A, `MAT_NEW_NONZERO_ALLOCATION_ERR`, `PETSC_TRUE`);

This function may only be called once for a given `MATPREALLOCATOR` object. If
multiple `Mat`s need to be preallocated, consider using `MatDuplicate()` after
this function.




## See Also
 `MATPREALLOCATOR`, `MatXAIJSetPreallocation()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/preallocator/matpreallocator.c.html#MatPreallocatorPreallocate">src/mat/impls/preallocator/matpreallocator.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/preallocator/matpreallocator.c.html#MatPreallocatorPreallocate_Preallocator">MatPreallocatorPreallocate_Preallocator in src/mat/impls/preallocator/matpreallocator.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/preallocator/matpreallocator.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)  
