MatCopy — PETSc 3.25.2 documentation

Skip to main content
`Ctrl`+`K`

# 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

Matrices, `Mat`, `MatConvert()`, `MatDuplicate()`

## Level

intermediate

## Location

src/mat/interface/matrix.c

## Examples

src/tao/unconstrained/tutorials/burgers_spectral.c
src/ts/tutorials/ex50.c
src/tao/tutorials/ex4.c
src/tao/unconstrained/tutorials/rosenbrock1_taoterm.c
src/ts/tutorials/ex3.c
src/tao/pde_constrained/tutorials/elliptic.c
src/tao/pde_constrained/tutorials/hyperbolic.c
src/tao/unconstrained/tutorials/spectraladjointassimilation.c
src/tao/pde_constrained/tutorials/parabolic.c
src/ksp/ksp/tutorials/ex79.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
MatCopy_HT() in src/mat/impls/transpose/htransm.c
MatCopy_Transpose() in src/mat/impls/transpose/transm.c

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages