petsc-3.14.5 2021-03-03
Report Typos and Errors

# MatCopy

Copies a matrix to another matrix.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode MatCopy(Mat A,Mat B,MatStructure str)

Collective on Mat

### 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 had better 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

MatConvert(), MatDuplicate()

### Level

intermediate

### Location

src/mat/interface/matrix.c

### Examples

src/ksp/ksp/tutorials/ex79.c.html
src/ts/tutorials/ex3.c.html
src/ts/tutorials/ex50.c.html
src/tao/unconstrained/tutorials/spectraladjointassimilation.c.html
src/tao/pde_constrained/tutorials/elliptic.c.html
src/tao/pde_constrained/tutorials/parabolic.c.html
src/tao/pde_constrained/tutorials/hyperbolic.c.html
src/tao/tutorials/ex4.c.html

### Implementations

MatCopy_seqaij_seqaij_MKL_CPARDISO in src/mat/impls/aij/mpi/mkl_cpardiso/mkl_cpardiso.c
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_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_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
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages