# MatCreateComposite
Creates a matrix as the sum or product of one or more matrices 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatCreateComposite(MPI_Comm comm, PetscInt nmat, const Mat *mats, Mat *mat)
```
Collective


## Input Parameters

- ***comm -*** MPI communicator
- ***nmat -*** number of matrices to put in
- ***mats -*** the matrices



## Output Parameter

- ***mat -*** the matrix



## Options Database Keys

- ***-mat_composite_merge         -*** merge in `MatAssemblyEnd()`
- ***-mat_composite_merge_mvctx   -*** merge Mvctx of component matrices to optimize communication in `MatMult()` for ADDITIVE matrices
- ***-mat_composite_merge_type    -*** set merge direction





## Note
Alternative construction
```none
MatCreate(comm,&mat);
```
```none
MatSetSizes(mat,m,n,M,N);
```
```none
MatSetType(mat,MATCOMPOSITE);
```
```none
MatCompositeAddMat(mat,mats[0]);
```
```none
....
```
```none
MatCompositeAddMat(mat,mats[nmat-1]);
```
```none
MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY);
```
```none
MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY);
```

For the multiplicative form the product is mat[nmat-1]*mat[nmat-2]*....*mat[0]


## See Also
 `MatDestroy()`, `MatMult()`, `MatCompositeAddMat()`, `MatCompositeGetMat()`, `MatCompositeMerge()`, `MatCompositeSetType()`, `MATCOMPOSITE`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/composite/mcomposite.c.html#MatCreateComposite">src/mat/impls/composite/mcomposite.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex9.c.html">src/mat/tutorials/ex9.c.html</A><BR>


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