MatCreateShell

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

Synopsis

int MatCreateShell(MPI_Comm comm,int m,int n,int M,int N,void *ctx,Mat *A)

Input Parameters

comm -MPI communicator
m -number of local rows
n -number of local columns
M -number of global rows
N -number of global columns
ctx -pointer to data needed by the shell matrix routines

Output Parameter

A -the matrix

Collective on MPI_Comm

Usage

   MatCreateShell(comm,m,n,M,N,ctx,&mat);
   MatShellSetOperation(mat,MATOP_MULT,mult);
   [ Use matrix for operations that have been set ]
   MatDestroy(mat);

Notes

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

PETSc requires that matrices and vectors being used for certainoperations are partitioned accordingly. For example, whencreating a shell matrix, A, that supports parallel matrix- vectorproducts using MatMult(A,x,y) the user should set the numberof local matrix rows to be the number of local elements of thecorresponding result vector, y. Note that this is information isrequired for use of the matrix interface routines, even thoughthe shell matrix may not actually be physically partitioned. For example,


    Vec x, y
    Mat A

    VecCreate(comm,PETSC_DECIDE,M,&y);
    VecCreate(comm,PETSC_DECIDE,N,&x);
    VecGetLocalSize(y,&m);
    MatCreateShell(comm,m,N,M,N,ctx,&A);
    MatShellSetOperation(mat,MATOP_MULT,mult);
    MatMult(A,x,y);
    MatDestroy(A);
    VecDestroy(y); VecDestroy(x);

Keywords

matrix, shell, create

See Also

MatShellSetOperation(), MatHasOperation(), MatShellGetContext()

Location: src/mat/impls/shell/shell.c
Matrix Index
Table of Contents