:orphan: # MatCopy Copies a matrix to another matrix. ## Synopsis ``` #include "petscmat.h" PetscErrorCode MatCopy(Mat A, Mat B, MatStructure str) ``` Collective ## Input Parameters - ***A -*** the matrix - ***str -*** `SAME_NONZERO_PATTERN` or `DIFFERENT_NONZERO_PATTERN` ## Output Parameter - ***B -*** where the copy is put ## Notes If you use `SAME_NONZERO_PATTERN` then the two matrices must have the same nonzero pattern or the routine will crash. `MatCopy()` copies the matrix entries of a matrix to another existing matrix (after first zeroing the second matrix). A related routine is `MatConvert()`, which first creates a new matrix and then copies the data. ## See Also [](ch_matrices), `Mat`, `MatConvert()`, `MatDuplicate()` ## Level intermediate ## Location src/mat/interface/matrix.c ## Examples src/ksp/ksp/tutorials/ex79.c
src/tao/pde_constrained/tutorials/elliptic.c
src/tao/pde_constrained/tutorials/hyperbolic.c
src/tao/pde_constrained/tutorials/parabolic.c
src/tao/tutorials/ex4.c
src/tao/unconstrained/tutorials/burgers_spectral.c
src/tao/unconstrained/tutorials/spectraladjointassimilation.c
src/ts/tutorials/ex3.c
src/ts/tutorials/ex50.c
## Implementations MatCopy_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c
MatCopy_SeqAIJ in src/mat/impls/aij/seq/aij.c
MatCopy_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c
MatCopy_SeqBAIJ in src/mat/impls/baij/seq/baij.c
MatCopy_MPIDense in src/mat/impls/dense/mpi/mpidense.c
MatCopy_SeqDense in src/mat/impls/dense/seq/dense.c
MatCopy_Elemental in src/mat/impls/elemental/matelem.cxx
MatCopy_HYPRE in src/mat/impls/hypre/mhypre.c
MatCopy_IS in src/mat/impls/is/matis.c
MatCopy_Nest in src/mat/impls/nest/matnest.c
MatCopy_Normal in src/mat/impls/normal/normm.c
MatCopy_NormalHermitian in src/mat/impls/normal/normmh.c
MatCopy_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c
MatCopy_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c
MatCopy_ScaLAPACK in src/mat/impls/scalapack/matscalapack.c
MatCopy_MPISELL in src/mat/impls/sell/mpi/mpisell.c
MatCopy_SeqSELL in src/mat/impls/sell/seq/sell.c
MatCopy_Shell in src/mat/impls/shell/shell.c
--- [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](/manualpages/index.md) [Index of all manual pages](/manualpages/singleindex.md)