# MatMult
Computes the matrix-vector product, y = Ax. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatMult(Mat mat, Vec x, Vec y)
```
Neighbor-wise Collective


## Input Parameters

- ***mat -*** the matrix
- ***x   -*** the vector to be multiplied



## Output Parameters

- ***y -*** the result





## Note
The vectors `x` and `y` cannot be the same.  I.e., one cannot
call `MatMult`(A,y,y).


## See Also
 `Mat`, `MatMultTranspose()`, `MatMultAdd()`, `MatMultTransposeAdd()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matrix.c.html#MatMult">src/mat/interface/matrix.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex2.c.html">src/mat/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex3.c.html">src/mat/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5cu.cu.html">src/mat/tutorials/ex5cu.cu.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5k.kokkos.cxx.html">src/mat/tutorials/ex5k.kokkos.cxx.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex9.c.html">src/mat/tutorials/ex9.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/swarm/tutorials/ex1f90.F90.html">src/dm/impls/swarm/tutorials/ex1f90.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/tutorials/ex3.c.html">src/ksp/pc/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/bench_pcsetup.c.html">src/ksp/ksp/tutorials/bench_pcsetup.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex1.c.html">src/ksp/ksp/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex100.c.html">src/ksp/ksp/tutorials/ex100.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex100f.F90.html">src/ksp/ksp/tutorials/ex100f.F90.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/hypre/mhyp.c.html#MatMult_HYPREStruct">MatMult_HYPREStruct in src/dm/impls/da/hypre/mhyp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/hypre/mhyp.c.html#MatMult_HYPRESStruct">MatMult_HYPRESStruct in src/dm/impls/da/hypre/mhyp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/usfft/matusfft.c.html#MatMult_SeqUSFFT">MatMult_SeqUSFFT in src/dm/impls/da/usfft/matusfft.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/impls/h2opus/pch2opus.c.html#MatMult_AAt">MatMult_AAt in src/ksp/pc/impls/h2opus/pch2opus.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/impls/h2opus/pch2opus.c.html#MatMult_MAmI">MatMult_MAmI in src/ksp/pc/impls/h2opus/pch2opus.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/impls/h2opus/pch2opus.c.html#MatMult_Hyper">MatMult_Hyper in src/ksp/pc/impls/h2opus/pch2opus.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/impls/h2opus/pch2opus.c.html#MatMult_NS">MatMult_NS in src/ksp/pc/impls/h2opus/pch2opus.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/impls/ml/ml.c.html#MatMult_ML">MatMult_ML in src/ksp/pc/impls/ml/ml.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/kokkos/mpiaijkok.kokkos.cxx.html#MatMult_MPIAIJKokkos">MatMult_MPIAIJKokkos in src/mat/impls/aij/mpi/kokkos/mpiaijkok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatMult_MPIAIJ">MatMult_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu.html#MatMult_MPIAIJCUSPARSE">MatMult_MPIAIJCUSPARSE in src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c.html#MatMult_MPIAIJHIPSPARSE">MatMult_MPIAIJHIPSPARSE in src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatMult_SeqAIJ">MatMult_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijmkl/aijmkl.c.html#MatMult_SeqAIJMKL">MatMult_SeqAIJMKL in src/mat/impls/aij/seq/aijmkl/aijmkl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijperm/aijperm.c.html#MatMult_SeqAIJPERM">MatMult_SeqAIJPERM in src/mat/impls/aij/seq/aijperm/aijperm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijsell/aijsell.c.html#MatMult_SeqAIJSELL">MatMult_SeqAIJSELL in src/mat/impls/aij/seq/aijsell/aijsell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/crl/crl.c.html#MatMult_AIJCRL">MatMult_AIJCRL in src/mat/impls/aij/seq/crl/crl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx.html#MatMult_SeqAIJKokkos">MatMult_SeqAIJKokkos in src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu.html#MatMult_SeqAIJCUSPARSE">MatMult_SeqAIJCUSPARSE in src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c.html#MatMult_SeqAIJHIPSPARSE">MatMult_SeqAIJHIPSPARSE in src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx.html#MatMult_SeqAIJViennaCL">MatMult_SeqAIJViennaCL in src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatMult_MPIBAIJ">MatMult_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/blockmat/seq/blockmat.c.html#MatMult_BlockMat">MatMult_BlockMat in src/mat/impls/blockmat/seq/blockmat.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/cdiagonal/cdiagonal.c.html#MatMult_ConstantDiagonal">MatMult_ConstantDiagonal in src/mat/impls/cdiagonal/cdiagonal.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/centering/centering.c.html#MatMult_Centering">MatMult_Centering in src/mat/impls/centering/centering.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/composite/mcomposite.c.html#MatMult_Composite">MatMult_Composite in src/mat/impls/composite/mcomposite.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/cufft/cufft.cu.html#MatMult_SeqCUFFT">MatMult_SeqCUFFT in src/mat/impls/cufft/cufft.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatMult_MPIDense">MatMult_MPIDense in src/mat/impls/dense/mpi/mpidense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/cuda/densecuda.cu.html#MatMult_SeqDenseCUDA">MatMult_SeqDenseCUDA in src/mat/impls/dense/seq/cuda/densecuda.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/dense.c.html#MatMult_SeqDense">MatMult_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/hip/densehip.hip.c.html#MatMult_SeqDenseHIP">MatMult_SeqDenseHIP in src/mat/impls/dense/seq/hip/densehip.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/elemental/matelem.cxx.html#MatMult_Elemental">MatMult_Elemental in src/mat/impls/elemental/matelem.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/fft/fftw/fftw.c.html#MatMult_SeqFFTW">MatMult_SeqFFTW in src/mat/impls/fft/fftw/fftw.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/fft/fftw/fftw.c.html#MatMult_MPIFFTW">MatMult_MPIFFTW in src/mat/impls/fft/fftw/fftw.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/h2opus/cuda/math2opus.cu.html#MatMult_H2OPUS">MatMult_H2OPUS in src/mat/impls/h2opus/cuda/math2opus.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/htool/htool.cxx.html#MatMult_Htool">MatMult_Htool in src/mat/impls/htool/htool.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatMult_HYPRE">MatMult_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/is/matis.c.html#MatMult_IS">MatMult_IS in src/mat/impls/is/matis.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/kaij/kaij.c.html#MatMult_SeqKAIJ">MatMult_SeqKAIJ in src/mat/impls/kaij/kaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/kaij/kaij.c.html#MatMult_MPIKAIJ">MatMult_MPIKAIJ in src/mat/impls/kaij/kaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/lrc/lrc.c.html#MatMult_LRC">MatMult_LRC in src/mat/impls/lrc/lrc.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/mffd/mffd.c.html#MatMult_MFFD">MatMult_MFFD in src/mat/impls/mffd/mffd.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/nest/matnest.c.html#MatMult_Nest">MatMult_Nest in src/mat/impls/nest/matnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/normal/normm.c.html#MatMult_Normal">MatMult_Normal in src/mat/impls/normal/normm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/normal/normmh.c.html#MatMult_NormalHermitian">MatMult_NormalHermitian in src/mat/impls/normal/normmh.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatMult_MPISBAIJ">MatMult_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/scalapack/matscalapack.c.html#MatMult_ScaLAPACK">MatMult_ScaLAPACK in src/mat/impls/scalapack/matscalapack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/scatter/mscatter.c.html#MatMult_Scatter">MatMult_Scatter in src/mat/impls/scatter/mscatter.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatMult_MPISELL">MatMult_MPISELL in src/mat/impls/sell/mpi/mpisell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/seq/sell.c.html#MatMult_SeqSELL">MatMult_SeqSELL in src/mat/impls/sell/seq/sell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/shell/shell.c.html#MatMult_Shell">MatMult_Shell in src/mat/impls/shell/shell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/shell/shellcnv.c.html#MatMult_CF">MatMult_CF in src/mat/impls/shell/shellcnv.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/submat/submat.c.html#MatMult_SubMatrix">MatMult_SubMatrix in src/mat/impls/submat/submat.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/transpose/htransm.c.html#MatMult_HT">MatMult_HT in src/mat/impls/transpose/htransm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/transpose/transm.c.html#MatMult_Transpose">MatMult_Transpose in src/mat/impls/transpose/transm.c</A><BR>


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