MatAssemblyBegin#

Begins assembling the matrix. This routine should be called after completing all calls to MatSetValues().

Synopsis#

#include "petscmat.h"
PetscErrorCode MatAssemblyBegin(Mat mat, MatAssemblyType type)


Collective

Input Parameters#

• mat - the matrix

• type - type of assembly, either MAT_FLUSH_ASSEMBLY or MAT_FINAL_ASSEMBLY

Notes#

MatSetValues() generally caches the values that belong to other MPI ranks. The matrix is ready to use only after MatAssemblyBegin() and MatAssemblyEnd() have been called.

Use MAT_FLUSH_ASSEMBLY when switching between ADD_VALUES and INSERT_VALUES in MatSetValues(); use MAT_FINAL_ASSEMBLY for the final assembly before using the matrix.

ALL processes that share a matrix MUST call MatAssemblyBegin() and MatAssemblyEnd() the SAME NUMBER of times, and each time with the same flag of MAT_FLUSH_ASSEMBLY or MAT_FINAL_ASSEMBLY for all processes. Thus you CANNOT locally change from ADD_VALUES to INSERT_VALUES, that is a global collective operation requiring all processes that share the matrix.

Space for preallocated nonzeros that is not filled by a call to MatSetValues() or a related routine are compressed out by assembly. If you intend to use that extra space on a subsequent assembly, be sure to insert explicit zeros before MAT_FINAL_ASSEMBLY so the space is not compressed out.

Mat, MatAssemblyEnd(), MatSetValues(), MatAssembled()

beginner

Location#

src/mat/interface/matrix.c

Edit on GitLab