petsc-3.7.1 2016-05-15
Report Typos and Errors

# MatCreateShell

Creates a new matrix class for use with a user-defined private data storage format.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode  MatCreateShell(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,void *ctx,Mat *A)

Collective on MPI_Comm Many br

### Input Parameters

| comm | - MPI communicator Many br
| m | - number of local rows (must be given) Many br
| n | - number of local columns (must be given) Many br
| M | - number of global rows (may be PETSC_DETERMINE) Many br
| N | - number of global columns (may be PETSC_DETERMINE) Many br
| ctx | - pointer to data needed by the shell matrix routines Many br

### Output Parameter

A -the matrix Many br

Many br

### Usage

       extern int mult(Mat,Vec,Vec);

       MatCreateShell(comm,m,n,M,N,ctx,&mat);

       MatShellSetOperation(mat,MATOP_MULT,(void(*)(void))mult);

       [ Use matrix for operations that have been set ]

       MatDestroy(mat);

### Notes

The shell matrix type is intended to provide a simple class to use Many brwith KSP (such as, for use with matrix-free methods). You should not Many bruse the shell type if you plan to define a complete matrix class. Many br

Fortran Notes: To use this from Fortran with a ctx you must write an interface definition for this Many brfunction and for MatShellGetContext() that tells Fortran the Fortran derived data type you are passing Many brin as the ctx argument. Many br

PETSc requires that matrices and vectors being used for certain Many broperations are partitioned accordingly. For example, when Many brcreating a shell matrix, A, that supports parallel matrix-vector Many brproducts using MatMult(A,x,y) the user should set the number Many brof local matrix rows to be the number of local elements of the Many brcorresponding result vector, y. Note that this is information is Many brrequired for use of the matrix interface routines, even though Many brthe shell matrix may not actually be physically partitioned. Many brFor example, Many br

        Vec x, y

        extern int mult(Mat,Vec,Vec);

        Mat A

        VecCreateMPI(comm,PETSC_DECIDE,M,&y);

        VecCreateMPI(comm,PETSC_DECIDE,N,&x);

        VecGetLocalSize(y,&m);

        VecGetLocalSize(x,&n);

        MatCreateShell(comm,m,n,M,N,ctx,&A);

        MatShellSetOperation(mat,MATOP_MULT,(void(*)(void))mult);

        MatMult(A,x,y);

        MatDestroy(A);

        VecDestroy(y); VecDestroy(x);

### Keywords

matrix, shell, create

### See Also

MatShellSetOperation(), MatHasOperation(), MatShellGetContext(), MatShellSetContext()

Level:advanced
Location:src/mat/impls/shell/shell.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/ksp/ksp/examples/tutorials/ex14f.F.html
src/ts/examples/tutorials/ex22f_mf.F90.html
src/tao/unconstrained/examples/tutorials/eptorsion1.c.html
src/tao/bound/examples/tutorials/plate2.c.html
src/tao/pde_constrained/examples/tutorials/elliptic.c.html
src/tao/pde_constrained/examples/tutorials/parabolic.c.html
src/tao/pde_constrained/examples/tutorials/hyperbolic.c.html