Skip to main content
`Ctrl`+`K`

# MatTranspose

Computes an in-place or out-of-place transpose of a matrix.

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatTranspose(Mat mat, MatReuse reuse, Mat *B)

Collective

## Input Parameters

- mat - the matrix to transpose

- reuse - either `MAT_INITIAL_MATRIX`, `MAT_REUSE_MATRIX`, or `MAT_INPLACE_MATRIX`

## Output Parameter

- B - the transpose

## Notes

If you use `MAT_INPLACE_MATRIX` then you must pass in `&mat` for `B`

`MAT_REUSE_MATRIX` uses the `B` matrix obtained from a previous call to this function with `MAT_INITIAL_MATRIX`. If you already have a matrix to contain the transpose, call `MatTransposeSetPrecursor(mat, B)` before calling this routine.

If the nonzero structure of mat changed from the previous call to this function with the same matrices an error will be generated for some matrix types.

Consider using `MatCreateTranspose()` instead if you only need a matrix that behaves like the transpose, but don’t need the storage to be changed.

If mat is unchanged from the last call this function returns immediately without recomputing the result

If you only need the symbolic transpose, and not the numerical values, use `MatTransposeSymbolic()`

## See Also

Matrices, `Mat`, `MatTransposeSetPrecursor()`, `MatMultTranspose()`, `MatMultTransposeAdd()`, `MatIsTranspose()`, `MatReuse`, `MAT_INITIAL_MATRIX`, `MAT_REUSE_MATRIX`, `MAT_INPLACE_MATRIX`, `MatTransposeSymbolic()`, `MatCreateTranspose()`

## Level

intermediate

## Location

src/mat/interface/matrix.c

## Examples

src/tao/pde_constrained/tutorials/hyperbolic.c
src/ksp/ksp/tutorials/ex74.c
src/ksp/ksp/tutorials/ex65.c
src/tao/pde_constrained/tutorials/parabolic.c
src/ksp/ksp/tutorials/ex87.c
src/ksp/ksp/tutorials/ex43.c
src/ksp/ksp/tutorials/ex79.c
src/snes/tutorials/ex70.c

## Implementations

MatTranspose_MPIAIJ() in src/mat/impls/aij/mpi/mpiaij.c
MatTranspose_SeqAIJKokkos() in src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx
MatTranspose_SeqAIJ() in src/mat/impls/aij/seq/symtranspose.c
MatTranspose_MPIBAIJ() in src/mat/impls/baij/mpi/mpibaij.c
MatTranspose_SeqBAIJ() in src/mat/impls/baij/seq/baij.c
MatTranspose_MPIDense() in src/mat/impls/dense/mpi/mpidense.c
MatTranspose_SeqDense() in src/mat/impls/dense/seq/dense.c
MatTranspose_Elemental() in src/mat/impls/elemental/matelem.cxx
MatTranspose_Htool() in src/mat/impls/htool/htool.cxx
MatTranspose_IS() in src/mat/impls/is/matis.c
MatTranspose_Nest() in src/mat/impls/nest/matnest.c
MatTranspose_MPISBAIJ() in src/mat/impls/sbaij/mpi/mpisbaij.c
MatTranspose_SeqSBAIJ() in src/mat/impls/sbaij/seq/sbaij.c
MatTranspose_ScaLAPACK() in src/mat/impls/scalapack/matscalapack.c

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