:orphan:
# 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; No Fortran Support
## 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**);
extern PetscErrorCode usernumeric(Mat,Mat,Mat,void*);
extern PetscErrorCode userdestroy(void*);
MatCreateShell(comm,m,n,M,N,ctx,&A);
MatShellSetMatProductOperation(A,MATPRODUCT_AB,usersymbolic,usernumeric,userdestroy,MATSEQAIJ,MATDENSE);
[ create B of type SEQAIJ etc..]
MatProductCreate(A,B,NULL,&C);
MatProductSetType(C,MATPRODUCT_AB);
MatProductSetFromOptions(C);
MatProductSymbolic(C); -> actually runs the user defined symbolic operation
MatProductNumeric(C); -> actually runs the user defined numeric operation
[ use C = A*B ]
```
## Notes
`MATPRODUCT_ABC` is not supported yet.
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
[](ch_matrices), `Mat`, `MATSHELL`, `MatCreateShell()`, `MatShellGetContext()`, `MatShellGetOperation()`, `MatShellSetContext()`, `MatSetOperation()`, `MatProductType`, `MatType`, `MatSetUp()`
## Level
advanced
## Location
src/mat/impls/shell/shell.c
## Implementations
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
---
[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](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)