# MatShellSetMatProductOperation
Allows user to set a matrix matrix operation for a `MATSHELL` shell matrix. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatShellSetMatProductOperation(Mat A, MatProductType ptype, PetscErrorCode (*symbolic)(Mat, Mat, Mat, void **), PetscErrorCode (*numeric)(Mat, Mat, Mat, void *), PetscErrorCode (*destroy)(void *), MatType Btype, MatType Ctype)
```
Logically Collective on A


## Input Parameters

- ***A -*** the `MATSHELL` shell matrix
- ***ptype -*** the product type
- ***symbolic -*** the function for the symbolic phase (can be NULL)
- ***numeric -*** the function for the numerical phase
- ***destroy -*** the function for the destruction of the needed data generated during the symbolic phase (can be NULL)
- ***Btype -*** the matrix type for the matrix to be multiplied against
- ***Ctype -*** the matrix type for the result (can be NULL)





## Usage
```none
extern PetscErrorCode usersymbolic(Mat,Mat,Mat,void**);
```
```none
extern PetscErrorCode usernumeric(Mat,Mat,Mat,void*);
```
```none
extern PetscErrorCode userdestroy(void*);
```
```none
MatCreateShell(comm,m,n,M,N,ctx,&A);
```
```none
MatShellSetMatProductOperation(A,MATPRODUCT_AB,usersymbolic,usernumeric,userdestroy,MATSEQAIJ,MATDENSE);
```
```none
[ create B of type SEQAIJ etc..]
```
```none
MatProductCreate(A,B,NULL,&C);
```
```none
MatProductSetType(C,MATPRODUCT_AB);
```
```none
MatProductSetFromOptions(C);
```
```none
MatProductSymbolic(C); -> actually runs the user defined symbolic operation
```
```none
MatProductNumeric(C); -> actually runs the user defined numeric operation
```
```none
[ use C = A*B ]
```


## Notes
`MATPRODUCT_ABC` is not supported yet. Not supported in Fortran.

If the symbolic phase is not specified, `MatSetUp()` is called on the result matrix that must have its type set if Ctype is NULL.

Any additional data needed by the matrix product needs to be returned during the symbolic phase and destroyed with the destroy callback.
PETSc will take care of calling the user-defined callbacks.
It is allowed to specify the same callbacks for different Btype matrix types.
The couple (Btype,ptype) uniquely identifies the operation: the last specified callbacks takes precedence.


## See Also
 `MATSHELL`, `MatCreateShell()`, `MatShellGetContext()`, `MatShellGetOperation()`, `MatShellSetContext()`, `MatSetOperation()`, `MatProductType`, `MatType`, `MatSetUp()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/shell/shell.c.html#MatShellSetMatProductOperation">src/mat/impls/shell/shell.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/shell/shell.c.html#MatShellSetMatProductOperation_Shell(Mat A, MatProductType ptype, PetscErrorCode (*symbolic)(Mat, Mat, Mat, void **), PetscErrorCode (*numeric)(Mat, Mat, Mat, void *), PetscErrorCode (*destroy)">MatShellSetMatProductOperation_Shell(Mat A, MatProductType ptype, PetscErrorCode (*symbolic)(Mat, Mat, Mat, void **), PetscErrorCode (*numeric)(Mat, Mat, Mat, void *), PetscErrorCode (*destroy) in src/mat/impls/shell/shell.c</A><BR>


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