Preallocates the A matrix, using information from mat, optionally filling A with zeros


#include "petscmat.h" 
PetscErrorCode MatPreallocatorPreallocate(Mat mat, PetscBool fill, Mat A)

Input Parameter

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


This Mat 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 entires 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);

Level: advanced

See Also