petsc-3.12.1 2019-10-22
Report Typos and Errors

# 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 on Mat

### Input Parameters

| mat | - the matrix
| type | - type of assembly, either MAT_FLUSH_ASSEMBLY or MAT_FINAL_ASSEMBLY

### Notes

MatSetValues() generally caches the values. 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 requring 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.

### See Also

MatAssemblyEnd(), MatSetValues(), MatAssembled()

### Level

beginner

### Location

src/mat/interface/matrix.c

### Examples

src/mat/examples/tutorials/ex2.c.html
src/mat/examples/tutorials/ex4.c.html
src/mat/examples/tutorials/ex8.c.html
src/mat/examples/tutorials/ex9.c.html
src/mat/examples/tutorials/ex12.c.html
src/mat/examples/tutorials/ex15.c.html
src/mat/examples/tutorials/ex16.c.html
src/mat/examples/tutorials/ex17.c.html
src/mat/examples/tutorials/ex4f.F90.html
src/mat/examples/tutorials/ex15f.F90.html
src/mat/examples/tutorials/ex17f.F90.html

### Implementations

MatAssemblyBegin_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c
MatAssemblyBegin_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c
MatAssemblyBegin_MPIDense in src/mat/impls/dense/mpi/mpidense.c
MatAssemblyBegin_SeqDense in src/mat/impls/dense/seq/dense.c
MatAssemblyBegin_Elemental in src/mat/impls/elemental/matelem.cxx
MatAssemblyBegin_HYPRE in src/mat/impls/hypre/mhypre.c
MatAssemblyBegin_IS in src/mat/impls/is/matis.c
MatAssemblyBegin_Nest in src/mat/impls/nest/matnest.c
MatAssemblyBegin_Preallocator in src/mat/impls/preallocator/matpreallocator.c
MatAssemblyBegin_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c
MatAssemblyBegin_MPISELL in src/mat/impls/sell/mpi/mpisell.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages