xref: /petsc/include/petscmat.h (revision 713ccfa99f17df39acafad0bca83af4e03287b7f)
12eac72dbSBarry Smith /*
22eac72dbSBarry Smith      Include file for the matrix component of PETSc
32eac72dbSBarry Smith */
40a835dfdSSatish Balay #ifndef __PETSCMAT_H
50a835dfdSSatish Balay #define __PETSCMAT_H
60a835dfdSSatish Balay #include "petscvec.h"
72eac72dbSBarry Smith 
8d9274352SBarry Smith /*S
9d9274352SBarry Smith      Mat - Abstract PETSc matrix object
102eac72dbSBarry Smith 
11d91e6319SBarry Smith    Level: beginner
12d91e6319SBarry Smith 
13d9274352SBarry Smith   Concepts: matrix; linear operator
14d9274352SBarry Smith 
15d9274352SBarry Smith .seealso:  MatCreate(), MatType, MatSetType()
16d9274352SBarry Smith S*/
17d9274352SBarry Smith typedef struct _p_Mat*           Mat;
18d9274352SBarry Smith 
1976bdecfbSBarry Smith /*J
20d9274352SBarry Smith     MatType - String with the name of a PETSc matrix or the creation function
21d9274352SBarry Smith        with an optional dynamic library name, for example
22d9274352SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:mymatcreate()
23d9274352SBarry Smith 
24d9274352SBarry Smith    Level: beginner
25d9274352SBarry Smith 
26c7393fdbSBarry Smith .seealso: MatSetType(), Mat, MatSolverPackage
2776bdecfbSBarry Smith J*/
28a313700dSBarry Smith #define MatType char*
29273d9f13SBarry Smith #define MATSAME            "same"
305a11e1b2SBarry Smith #define MATMAIJ            "maij"
31273d9f13SBarry Smith #define MATSEQMAIJ         "seqmaij"
32273d9f13SBarry Smith #define MATMPIMAIJ         "mpimaij"
33273d9f13SBarry Smith #define MATIS              "is"
345a11e1b2SBarry Smith #define MATAIJ             "aij"
35273d9f13SBarry Smith #define MATSEQAIJ          "seqaij"
367d6a0e61SBarry Smith #define MATSEQAIJPTHREAD   "seqaijpthread"
37bf2c1783SBarry Smith #define MATAIJPTHREAD      "aijpthread"
38273d9f13SBarry Smith #define MATMPIAIJ          "mpiaij"
395a11e1b2SBarry Smith #define MATAIJCRL          "aijcrl"
405a11e1b2SBarry Smith #define MATSEQAIJCRL       "seqaijcrl"
415a11e1b2SBarry Smith #define MATMPIAIJCRL       "mpiaijcrl"
428154be41SBarry Smith #define MATAIJCUSP         "aijcusp"
438154be41SBarry Smith #define MATSEQAIJCUSP      "seqaijcusp"
448154be41SBarry Smith #define MATMPIAIJCUSP      "mpiaijcusp"
455a11e1b2SBarry Smith #define MATAIJPERM         "aijperm"
465a11e1b2SBarry Smith #define MATSEQAIJPERM      "seqaijperm"
475a11e1b2SBarry Smith #define MATMPIAIJPERM      "mpiaijperm"
48273d9f13SBarry Smith #define MATSHELL           "shell"
495a11e1b2SBarry Smith #define MATDENSE           "dense"
50209238afSKris Buschelman #define MATSEQDENSE        "seqdense"
51273d9f13SBarry Smith #define MATMPIDENSE        "mpidense"
525a11e1b2SBarry Smith #define MATBAIJ            "baij"
53273d9f13SBarry Smith #define MATSEQBAIJ         "seqbaij"
54273d9f13SBarry Smith #define MATMPIBAIJ         "mpibaij"
55273d9f13SBarry Smith #define MATMPIADJ          "mpiadj"
565a11e1b2SBarry Smith #define MATSBAIJ           "sbaij"
57273d9f13SBarry Smith #define MATSEQSBAIJ        "seqsbaij"
58273d9f13SBarry Smith #define MATMPISBAIJ        "mpisbaij"
59c0cdd4a1SDahai Guo #define MATSEQBSTRM        "seqbstrm"
60c0cdd4a1SDahai Guo #define MATMPIBSTRM        "mpibstrm"
61c0cdd4a1SDahai Guo #define MATBSTRM           "bstrm"
62aa5a9175SDahai Guo #define MATSEQSBSTRM       "seqsbstrm"
63aa5a9175SDahai Guo #define MATMPISBSTRM       "mpisbstrm"
64aa5a9175SDahai Guo #define MATSBSTRM          "sbstrm"
65cebc7f6cSBarry Smith #define MATDAAD            "daad"
66cebc7f6cSBarry Smith #define MATMFFD            "mffd"
67c8a8475eSBarry Smith #define MATNORMAL          "normal"
68ab92ecdeSBarry Smith #define MATLRC             "lrc"
692a6744ebSBarry Smith #define MATSCATTER         "scatter"
70421e10b8SBarry Smith #define MATBLOCKMAT        "blockmat"
71793850ffSBarry Smith #define MATCOMPOSITE       "composite"
721f8c7532SHong Zhang #define MATFFT             "fft"
731f8c7532SHong Zhang #define MATFFTW            "fftw"
74e133240eSMatthew G Knepley #define MATSEQCUFFT        "seqcufft"
75557cca28SSatish Balay #define MATTRANSPOSEMAT    "transpose"
7672ca8751SBarry Smith #define MATSCHURCOMPLEMENT "schurcomplement"
771d6018f0SLisandro Dalcin #define MATPYTHON          "python"
78f91d8e95SBarry Smith #define MATHYPRESTRUCT     "hyprestruct"
79a9e6138eSGlenn Hammond #define MATHYPRESSTRUCT    "hypresstruct"
80ee1cef2cSJed Brown #define MATSUBMATRIX       "submatrix"
812c0dbf93SJed Brown #define MATLOCALREF        "localref"
82d8588912SDave May #define MATNEST            "nest"
8315c1f1baSDmitry Karpeev #define MATIJ              "ij"
84773941d6SBarry Smith 
8576bdecfbSBarry Smith /*J
86c7393fdbSBarry Smith     MatSolverPackage - String with the name of a PETSc matrix solver type.
879989ab13SBarry Smith 
889989ab13SBarry Smith     For example: "petsc" indicates what PETSc provides, "superlu" indicates either
899989ab13SBarry Smith        SuperLU or SuperLU_Dist etc.
909989ab13SBarry Smith 
919989ab13SBarry Smith 
929989ab13SBarry Smith    Level: beginner
939989ab13SBarry Smith 
945c9eb25fSBarry Smith .seealso: MatGetFactor(), Mat, MatSetType(), MatType
9576bdecfbSBarry Smith J*/
96c7393fdbSBarry Smith #define MatSolverPackage char*
972692d6eeSBarry Smith #define MATSOLVERSPOOLES      "spooles"
982692d6eeSBarry Smith #define MATSOLVERSUPERLU      "superlu"
992692d6eeSBarry Smith #define MATSOLVERSUPERLU_DIST "superlu_dist"
1002692d6eeSBarry Smith #define MATSOLVERUMFPACK      "umfpack"
10120db9a53SJed Brown #define MATSOLVERCHOLMOD      "cholmod"
1022692d6eeSBarry Smith #define MATSOLVERESSL         "essl"
1032692d6eeSBarry Smith #define MATSOLVERLUSOL        "lusol"
1042692d6eeSBarry Smith #define MATSOLVERMUMPS        "mumps"
1052692d6eeSBarry Smith #define MATSOLVERPASTIX       "pastix"
1062692d6eeSBarry Smith #define MATSOLVERMATLAB       "matlab"
1072692d6eeSBarry Smith #define MATSOLVERPETSC        "petsc"
1082692d6eeSBarry Smith #define MATSOLVERPLAPACK      "plapack"
1092692d6eeSBarry Smith #define MATSOLVERBAS          "bas"
110773941d6SBarry Smith 
111aa5a9175SDahai Guo #define MATSOLVERBSTRM        "bstrm"
112aa5a9175SDahai Guo #define MATSOLVERSBSTRM       "sbstrm"
113c0cdd4a1SDahai Guo 
114b24902e0SBarry Smith /*E
115b24902e0SBarry Smith     MatFactorType - indicates what type of factorization is requested
116b24902e0SBarry Smith 
117b24902e0SBarry Smith     Level: beginner
118b24902e0SBarry Smith 
119b24902e0SBarry Smith    Any additions/changes here MUST also be made in include/finclude/petscmat.h
120b24902e0SBarry Smith 
121c7393fdbSBarry Smith .seealso: MatSolverPackage, MatGetFactor()
122b24902e0SBarry Smith E*/
123599ef60dSHong Zhang typedef enum {MAT_FACTOR_NONE, MAT_FACTOR_LU, MAT_FACTOR_CHOLESKY, MAT_FACTOR_ILU, MAT_FACTOR_ICC,MAT_FACTOR_ILUDT} MatFactorType;
124014dd563SJed Brown PETSC_EXTERN const char *const MatFactorTypes[];
125e92e720dSBarry Smith 
126014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactor(Mat,const MatSolverPackage,MatFactorType,Mat*);
127014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat,const MatSolverPackage,MatFactorType,PetscBool *);
128014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFactorGetSolverPackage(Mat,const MatSolverPackage*);
129014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat,MatFactorType*);
1309989ab13SBarry Smith 
131c06d978dSMatthew Knepley /* Logging support */
1320700a824SBarry Smith #define    MAT_FILE_CLASSID 1211216    /* used to indicate matrices in binary files */
133014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_CLASSID;
134014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_FDCOLORING_CLASSID;
135014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_TRANSPOSECOLORING_CLASSID;
136014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_PARTITIONING_CLASSID;
137014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_COARSEN_CLASSID;
138014dd563SJed Brown PETSC_EXTERN PetscClassId MAT_NULLSPACE_CLASSID;
139014dd563SJed Brown PETSC_EXTERN PetscClassId MATMFFD_CLASSID;
140c06d978dSMatthew Knepley 
141ceb03754SKris Buschelman /*E
142ceb03754SKris Buschelman     MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices()
143d6eff37eSBarry Smith      or MatGetSubMatrix() are to be reused to store the new matrix values. For MatConvert() is used to indicate
144d6eff37eSBarry Smith      that the input matrix is to be replaced with the converted matrix.
145ceb03754SKris Buschelman 
146ceb03754SKris Buschelman     Level: beginner
147ceb03754SKris Buschelman 
148ceb03754SKris Buschelman    Any additions/changes here MUST also be made in include/finclude/petscmat.h
149ceb03754SKris Buschelman 
1500c451bc4SBarry Smith .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices(), MatConvert()
151ceb03754SKris Buschelman E*/
152dfe085dbSJed Brown typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX,MAT_IGNORE_MATRIX} MatReuse;
153ceb03754SKris Buschelman 
1545494a064SHong Zhang /*E
1555494a064SHong Zhang     MatGetSubMatrixOption - Indicates if matrices obtained from a call to MatGetSubMatrices()
156829201f2SHong Zhang      include the matrix values. Currently it is only used by MatGetSeqNonzerostructure().
1575494a064SHong Zhang 
1585494a064SHong Zhang     Level: beginner
1595494a064SHong Zhang 
160829201f2SHong Zhang .seealso: MatGetSeqNonzerostructure()
1615494a064SHong Zhang E*/
1625494a064SHong Zhang typedef enum {MAT_DO_NOT_GET_VALUES,MAT_GET_VALUES} MatGetSubMatrixOption;
1635494a064SHong Zhang 
164014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatInitializePackage(const char[]);
165c06d978dSMatthew Knepley 
166014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreate(MPI_Comm,Mat*);
167014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetSizes(Mat,PetscInt,PetscInt,PetscInt,PetscInt);
168014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetType(Mat,const MatType);
169014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat);
170014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRegisterAll(const char[]);
171014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat));
172014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRegisterBaseName(const char[],const char[],const char[]);
173014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetOptionsPrefix(Mat,const char[]);
174014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefix(Mat,const char[]);
175014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOptionsPrefix(Mat,const char*[]);
176f69a0ea3SMatthew Knepley 
17730de9b25SBarry Smith /*MC
17830de9b25SBarry Smith    MatRegisterDynamic - Adds a new matrix type
17930de9b25SBarry Smith 
18030de9b25SBarry Smith    Synopsis:
1811890ba74SBarry Smith    PetscErrorCode MatRegisterDynamic(const char *name,const char *path,const char *name_create,PetscErrorCode (*routine_create)(Mat))
18230de9b25SBarry Smith 
18330de9b25SBarry Smith    Not Collective
18430de9b25SBarry Smith 
18530de9b25SBarry Smith    Input Parameters:
18630de9b25SBarry Smith +  name - name of a new user-defined matrix type
18730de9b25SBarry Smith .  path - path (either absolute or relative) the library containing this solver
18830de9b25SBarry Smith .  name_create - name of routine to create method context
18930de9b25SBarry Smith -  routine_create - routine to create method context
19030de9b25SBarry Smith 
19130de9b25SBarry Smith    Notes:
19230de9b25SBarry Smith    MatRegisterDynamic() may be called multiple times to add several user-defined solvers.
19330de9b25SBarry Smith 
19430de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (routine_create)
19530de9b25SBarry Smith    is ignored.
19630de9b25SBarry Smith 
19730de9b25SBarry Smith    Sample usage:
19830de9b25SBarry Smith .vb
19930de9b25SBarry Smith    MatRegisterDynamic("my_mat",/home/username/my_lib/lib/libO/solaris/mylib.a,
20030de9b25SBarry Smith                "MyMatCreate",MyMatCreate);
20130de9b25SBarry Smith .ve
20230de9b25SBarry Smith 
20330de9b25SBarry Smith    Then, your solver can be chosen with the procedural interface via
20430de9b25SBarry Smith $     MatSetType(Mat,"my_mat")
20530de9b25SBarry Smith    or at runtime via the option
20630de9b25SBarry Smith $     -mat_type my_mat
20730de9b25SBarry Smith 
20830de9b25SBarry Smith    Level: advanced
20930de9b25SBarry Smith 
210ab901514SBarry Smith    Notes: ${PETSC_ARCH} occuring in pathname will be replaced with appropriate values.
21130de9b25SBarry Smith          If your function is not being put into a shared library then use VecRegister() instead
21230de9b25SBarry Smith 
21330de9b25SBarry Smith .keywords: Mat, register
21430de9b25SBarry Smith 
21530de9b25SBarry Smith .seealso: MatRegisterAll(), MatRegisterDestroy()
21630de9b25SBarry Smith 
21730de9b25SBarry Smith M*/
218273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
219273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0)
220273d9f13SBarry Smith #else
221273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d)
22230de9b25SBarry Smith #endif
22330de9b25SBarry Smith 
224014dd563SJed Brown PETSC_EXTERN PetscBool MatRegisterAllCalled;
225014dd563SJed Brown PETSC_EXTERN PetscFList MatList;
226014dd563SJed Brown PETSC_EXTERN PetscFList MatColoringList;
227014dd563SJed Brown PETSC_EXTERN PetscFList MatPartitioningList;
228014dd563SJed Brown PETSC_EXTERN PetscFList MatCoarsenList;
22928988994SBarry Smith 
2303b224e63SBarry Smith /*E
2313b224e63SBarry Smith     MatStructure - Indicates if the matrix has the same nonzero structure
2323b224e63SBarry Smith 
2333b224e63SBarry Smith     Level: beginner
2343b224e63SBarry Smith 
2353b224e63SBarry Smith    Any additions/changes here MUST also be made in include/finclude/petscmat.h
2363b224e63SBarry Smith 
2373b224e63SBarry Smith .seealso: MatCopy(), KSPSetOperators(), PCSetOperators()
2383b224e63SBarry Smith E*/
239214bc6a2SJed Brown typedef enum {DIFFERENT_NONZERO_PATTERN,SUBSET_NONZERO_PATTERN,SAME_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure;
2403b224e63SBarry Smith 
241014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm,PetscInt,PetscInt,PetscScalar[],Mat*);
242014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateDense(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar[],Mat*);
243014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
244014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
245014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat *);
246014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSplitArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],PetscInt[],PetscInt[],PetscScalar[],Mat*);
2478d7a6e47SBarry Smith 
248014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
249014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
250014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat*);
251d21a29f3SJed Brown 
252014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAdj(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscInt[],Mat*);
253014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
254d21a29f3SJed Brown 
255014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
256014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat *);
257014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
258014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat,PetscInt,const PetscInt*,const PetscInt*,const PetscInt*,const PetscInt*);
259dfb205c3SBarry Smith 
260014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateShell(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,void *,Mat*);
261014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateAdic(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,void (*)(void),Mat*);
262014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateNormal(Mat,Mat*);
263014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateLRC(Mat,Mat,Mat,Mat*);
264014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateIS(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,ISLocalToGlobalMapping,Mat*);
265014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCRL(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
266014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
267c0cdd4a1SDahai Guo 
268014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
269014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
270014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqSBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
271014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPISBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
272c0cdd4a1SDahai Guo 
273014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateScatter(MPI_Comm,VecScatter,Mat*);
274014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatScatterSetVecScatter(Mat,VecScatter);
275014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatScatterGetVecScatter(Mat,VecScatter*);
276014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateBlockMat(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,Mat*);
277014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCompositeAddMat(Mat,Mat);
278014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCompositeMerge(Mat);
279014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateComposite(MPI_Comm,PetscInt,const Mat*,Mat*);
2806d7c1e57SBarry Smith typedef enum {MAT_COMPOSITE_ADDITIVE,MAT_COMPOSITE_MULTIPLICATIVE} MatCompositeType;
281014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCompositeSetType(Mat,MatCompositeType);
2826d7c1e57SBarry Smith 
283014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateFFT(MPI_Comm,PetscInt,const PetscInt[],const MatType,Mat*);
284014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqCUFFT(MPI_Comm,PetscInt,const PetscInt[],Mat*);
285dedccee8SHong Zhang 
286014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateTranspose(Mat,Mat*);
287014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSubMatrix(Mat,IS,IS,Mat*);
288014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSubMatrixUpdate(Mat,Mat,IS,IS);
289014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateLocalRef(Mat,IS,IS,Mat*);
2901472f72bSBarry Smith 
291014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat,const char[]);
2921d6018f0SLisandro Dalcin 
293014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetUp(Mat);
294014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDestroy(Mat*);
29521c89e3eSBarry Smith 
296014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatConjugate(Mat);
297014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRealPart(Mat);
298014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatImaginaryPart(Mat);
299014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetDiagonalBlock(Mat,Mat*);
300014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetTrace(Mat,PetscScalar*);
301*713ccfa9SJed Brown PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonal(Mat,const PetscScalar **);
30299cafbc1SBarry Smith 
3038ed539a5SBarry Smith /* ------------------------------------------------------------*/
304014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValues(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
305014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesBlocked(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
306014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesRow(Mat,PetscInt,const PetscScalar[]);
307014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesRowLocal(Mat,PetscInt,const PetscScalar[]);
308014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesBatch(Mat,PetscInt,PetscInt,PetscInt[],const PetscScalar[]);
30984cb2905SBarry Smith 
3102ef4de8bSBarry Smith /*S
3112ef4de8bSBarry Smith      MatStencil - Data structure (C struct) for storing information about a single row or
312be479b30SJed Brown         column of a matrix as indexed on an associated grid.
313be479b30SJed Brown 
314be479b30SJed Brown    Fortran usage is different, see MatSetValuesStencil() for details.
3152ef4de8bSBarry Smith 
3162ef4de8bSBarry Smith    Level: beginner
3172ef4de8bSBarry Smith 
3182ef4de8bSBarry Smith   Concepts: matrix; linear operator
3192ef4de8bSBarry Smith 
320be479b30SJed Brown .seealso:  MatSetValuesStencil(), MatSetStencil(), MatSetValuesBlockedStencil()
3212ef4de8bSBarry Smith S*/
322435da068SBarry Smith typedef struct {
323c1ac3661SBarry Smith   PetscInt k,j,i,c;
324435da068SBarry Smith } MatStencil;
3252ef4de8bSBarry Smith 
326014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat,PetscInt,const MatStencil[],PetscInt,const MatStencil[],const PetscScalar[],InsertMode);
327014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat,PetscInt,const MatStencil[],PetscInt,const MatStencil[],const PetscScalar[],InsertMode);
328014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetStencil(Mat,PetscInt,const PetscInt[],const PetscInt[],PetscInt);
329435da068SBarry Smith 
330014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetColoring(Mat,ISColoring);
331014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesAdic(Mat,void*);
332014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesAdifor(Mat,PetscInt,void*);
3333a7fca6bSBarry Smith 
334d91e6319SBarry Smith /*E
335d91e6319SBarry Smith     MatAssemblyType - Indicates if the matrix is now to be used, or if you plan
336d91e6319SBarry Smith      to continue to add values to it
337d91e6319SBarry Smith 
338d91e6319SBarry Smith     Level: beginner
339d91e6319SBarry Smith 
340d91e6319SBarry Smith .seealso: MatAssemblyBegin(), MatAssemblyEnd()
341d91e6319SBarry Smith E*/
3426d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
343014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat,MatAssemblyType);
344014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat,MatAssemblyType);
345014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAssembled(Mat,PetscBool *);
3464f9c727eSBarry Smith 
3471d73ed98SBarry Smith 
34830de9b25SBarry Smith 
349d91e6319SBarry Smith /*E
350d91e6319SBarry Smith     MatOption - Options that may be set for a matrix and its behavior or storage
351d91e6319SBarry Smith 
352d91e6319SBarry Smith     Level: beginner
353d91e6319SBarry Smith 
3540a835dfdSSatish Balay    Any additions/changes here MUST also be made in include/finclude/petscmat.h
355d91e6319SBarry Smith 
356d91e6319SBarry Smith .seealso: MatSetOption()
357d91e6319SBarry Smith E*/
358512a5fc5SBarry Smith typedef enum {MAT_ROW_ORIENTED,MAT_NEW_NONZERO_LOCATIONS,
3594e0d8c25SBarry Smith               MAT_SYMMETRIC,
3604e0d8c25SBarry Smith               MAT_STRUCTURALLY_SYMMETRIC,
3618047e77bSBarry Smith               MAT_NEW_DIAGONALS,MAT_IGNORE_OFF_PROC_ENTRIES,
3624e0d8c25SBarry Smith               MAT_NEW_NONZERO_LOCATION_ERR,
3634e0d8c25SBarry Smith               MAT_NEW_NONZERO_ALLOCATION_ERR,MAT_USE_HASH_TABLE,
364a9817697SBarry Smith               MAT_KEEP_NONZERO_PATTERN,MAT_IGNORE_ZERO_ENTRIES,
3654e0d8c25SBarry Smith               MAT_USE_INODES,
3664e0d8c25SBarry Smith               MAT_HERMITIAN,
3674e0d8c25SBarry Smith               MAT_SYMMETRY_ETERNAL,
368cd6b891eSBarry Smith               MAT_CHECK_COMPRESSED_ROW,
3694e0d8c25SBarry Smith               MAT_IGNORE_LOWER_TRIANGULAR,MAT_ERROR_LOWER_TRIANGULAR,
37028b2fa4aSMatthew Knepley               MAT_GETROW_UPPERTRIANGULAR,MAT_UNUSED_NONZERO_LOCATION_ERR,
3714cb17eb5SBarry Smith               MAT_SPD,MAT_NO_OFF_PROC_ENTRIES,MAT_NO_OFF_PROC_ZERO_ROWS,
37228b2fa4aSMatthew Knepley               NUM_MAT_OPTIONS} MatOption;
373014dd563SJed Brown PETSC_EXTERN const char *MatOptions[];
374014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetOption(Mat,MatOption,PetscBool );
375014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetType(Mat,const MatType*);
37684cb2905SBarry Smith 
377014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetValues(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscScalar[]);
378014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRow(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
379014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreRow(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
380014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowUpperTriangular(Mat);
381014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreRowUpperTriangular(Mat);
382014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetColumn(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
383014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreColumn(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
384014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetColumnVector(Mat,Vec,PetscInt);
385014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetArray(Mat,PetscScalar *[]);
386014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreArray(Mat,PetscScalar *[]);
387014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetBlockSize(Mat,PetscInt *);
388014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetBlockSize(Mat,PetscInt);
389014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetBlockSizes(Mat,PetscInt *,PetscInt *);
390014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetBlockSizes(Mat,PetscInt,PetscInt);
391014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetNThreads(Mat,PetscInt);
392014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetNThreads(Mat,PetscInt*);
3931620fd73SBarry Smith 
394014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMult(Mat,Vec,Vec);
395014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultDiagonalBlock(Mat,Vec,Vec);
396014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultAdd(Mat,Vec,Vec,Vec);
397014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultTranspose(Mat,Vec,Vec);
398014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultHermitianTranspose(Mat,Vec,Vec);
399014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsTranspose(Mat,Mat,PetscReal,PetscBool *);
400014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsHermitianTranspose(Mat,Mat,PetscReal,PetscBool *);
401014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultTransposeAdd(Mat,Vec,Vec,Vec);
402014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAdd(Mat,Vec,Vec,Vec);
403014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultConstrained(Mat,Vec,Vec);
404014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultTransposeConstrained(Mat,Vec,Vec);
405014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatSolve(Mat,Mat,Mat);
406f5edf698SHong Zhang 
407d91e6319SBarry Smith /*E
408d91e6319SBarry Smith     MatDuplicateOption - Indicates if a duplicated sparse matrix should have
409d91e6319SBarry Smith   its numerical values copied over or just its nonzero structure.
410d91e6319SBarry Smith 
411d91e6319SBarry Smith     Level: beginner
412d91e6319SBarry Smith 
413d91e6319SBarry Smith    Any additions/changes here MUST also be made in include/finclude/petscmat.h
414d91e6319SBarry Smith 
41570dcbbb9SBarry Smith $   MAT_SHARE_NONZERO_PATTERN - the i and j arrays in the new matrix will be shared with the original matrix
41670dcbbb9SBarry Smith $                               this also triggers the MAT_DO_NOT_COPY_VALUES option. This is used when you
41770dcbbb9SBarry Smith $                               have several matrices with the same nonzero pattern.
41870dcbbb9SBarry Smith 
419d91e6319SBarry Smith .seealso: MatDuplicate()
420d91e6319SBarry Smith E*/
42170dcbbb9SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES,MAT_SHARE_NONZERO_PATTERN} MatDuplicateOption;
4222e8a6d31SBarry Smith 
423014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatConvert(Mat,const MatType,MatReuse,Mat*);
424014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDuplicate(Mat,MatDuplicateOption,Mat*);
42594a9d846SBarry Smith 
426cb5b572fSBarry Smith 
427014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCopy(Mat,Mat,MatStructure);
428014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatView(Mat,PetscViewer);
429014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsSymmetric(Mat,PetscReal,PetscBool *);
430014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetric(Mat,PetscBool *);
431014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsHermitian(Mat,PetscReal,PetscBool *);
432014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsSymmetricKnown(Mat,PetscBool *,PetscBool *);
433014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIsHermitianKnown(Mat,PetscBool *,PetscBool *);
434014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMissingDiagonal(Mat,PetscBool  *,PetscInt *);
435014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatLoad(Mat, PetscViewer);
4367b80b807SBarry Smith 
437014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,PetscInt *[],PetscInt *[],PetscBool  *);
438014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,PetscInt *[],PetscInt *[],PetscBool  *);
439014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,PetscInt *[],PetscInt *[],PetscBool  *);
440014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,PetscInt *[],PetscInt *[],PetscBool  *);
441d4fbbf0eSBarry Smith 
442d91e6319SBarry Smith /*S
443d91e6319SBarry Smith      MatInfo - Context of matrix information, used with MatGetInfo()
444d91e6319SBarry Smith 
445d91e6319SBarry Smith    In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE
446d91e6319SBarry Smith 
447d91e6319SBarry Smith    Level: intermediate
448d91e6319SBarry Smith 
449d91e6319SBarry Smith   Concepts: matrix^nonzero information
450d91e6319SBarry Smith 
451d9274352SBarry Smith .seealso:  MatGetInfo(), MatInfoType
452d91e6319SBarry Smith S*/
4534e220ebcSLois Curfman McInnes typedef struct {
454b0a32e0cSBarry Smith   PetscLogDouble block_size;                         /* block size */
455b0a32e0cSBarry Smith   PetscLogDouble nz_allocated,nz_used,nz_unneeded;   /* number of nonzeros */
456b0a32e0cSBarry Smith   PetscLogDouble memory;                             /* memory allocated */
457b0a32e0cSBarry Smith   PetscLogDouble assemblies;                         /* number of matrix assemblies called */
458b0a32e0cSBarry Smith   PetscLogDouble mallocs;                            /* number of mallocs during MatSetValues() */
459b0a32e0cSBarry Smith   PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
460b0a32e0cSBarry Smith   PetscLogDouble factor_mallocs;                     /* number of mallocs during factorization */
4614e220ebcSLois Curfman McInnes } MatInfo;
4624e220ebcSLois Curfman McInnes 
463d9274352SBarry Smith /*E
464d9274352SBarry Smith     MatInfoType - Indicates if you want information about the local part of the matrix,
465d9274352SBarry Smith      the entire parallel matrix or the maximum over all the local parts.
466d9274352SBarry Smith 
467d9274352SBarry Smith     Level: beginner
468d9274352SBarry Smith 
469d9274352SBarry Smith    Any additions/changes here MUST also be made in include/finclude/petscmat.h
470d9274352SBarry Smith 
471d9274352SBarry Smith .seealso: MatGetInfo(), MatInfo
472d9274352SBarry Smith E*/
4737b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
474014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetInfo(Mat,MatInfoType,MatInfo*);
475014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetDiagonal(Mat,Vec);
476014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowMax(Mat,Vec,PetscInt[]);
477014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowMin(Mat,Vec,PetscInt[]);
478014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowMaxAbs(Mat,Vec,PetscInt[]);
479014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowMinAbs(Mat,Vec,PetscInt[]);
480014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRowSum(Mat,Vec);
481014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTranspose(Mat,MatReuse,Mat*);
482014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatHermitianTranspose(Mat,MatReuse,Mat*);
483014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPermute(Mat,IS,IS,Mat *);
484014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDiagonalScale(Mat,Vec,Vec);
485014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDiagonalSet(Mat,Vec,InsertMode);
486014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatEqual(Mat,Mat,PetscBool *);
487014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultEqual(Mat,Mat,PetscInt,PetscBool *);
488014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultAddEqual(Mat,Mat,PetscInt,PetscBool *);
489014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultTransposeEqual(Mat,Mat,PetscInt,PetscBool *);
490014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMultTransposeAddEqual(Mat,Mat,PetscInt,PetscBool *);
4917b80b807SBarry Smith 
492014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNorm(Mat,NormType,PetscReal *);
493014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetColumnNorms(Mat,NormType,PetscReal *);
494014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroEntries(Mat);
495014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRows(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
496014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsIS(Mat,IS,PetscScalar,Vec,Vec);
497014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsStencil(Mat,PetscInt,const MatStencil [],PetscScalar,Vec,Vec);
498014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsStencil(Mat,PetscInt,const MatStencil[],PetscScalar,Vec,Vec);
499014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsColumns(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
500014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsIS(Mat,IS,PetscScalar,Vec,Vec);
5017b80b807SBarry Smith 
502014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetSize(Mat,PetscInt*,PetscInt*);
503014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat,PetscInt*,PetscInt*);
504014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat,PetscInt*,PetscInt*);
505014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat,const PetscInt**);
506014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat,PetscInt*,PetscInt*);
507014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat,const PetscInt**);
5087b80b807SBarry Smith 
509014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetSubMatrices(Mat,PetscInt,const IS[],const IS[],MatReuse,Mat *[]);
510014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetSubMatricesParallel(Mat,PetscInt,const IS[],const IS[],MatReuse,Mat *[]);
511014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDestroyMatrices(PetscInt,Mat *[]);
512014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetSubMatrix(Mat,IS,IS,MatReuse,Mat *);
513014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetLocalSubMatrix(Mat,IS,IS,Mat*);
514014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestoreLocalSubMatrix(Mat,IS,IS,Mat*);
515014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetSeqNonzeroStructure(Mat,Mat*);
516014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDestroySeqNonzeroStructure(Mat*);
5175494a064SHong Zhang 
518014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJConcatenateSeqAIJ(MPI_Comm,Mat,PetscInt,MatReuse,Mat*);
519014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJConcatenateSeqAIJSymbolic(MPI_Comm,Mat,PetscInt,Mat*);
520014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJConcatenateSeqAIJNumeric(MPI_Comm,Mat,PetscInt,Mat);
521014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJ(MPI_Comm,Mat,PetscInt,PetscInt,MatReuse,Mat*);
522014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJSymbolic(MPI_Comm,Mat,PetscInt,PetscInt,Mat*);
523014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJNumeric(Mat,Mat);
524014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMat(Mat,MatReuse,Mat*);
525014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatCondensed(Mat,MatReuse,IS*,IS*,Mat*);
526014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetBrowsOfAcols(Mat,Mat,MatReuse,IS*,IS*,Mat*);
52743eb5e2fSMatthew Knepley #if defined (PETSC_USE_CTABLE)
528014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetCommunicationStructs(Mat, Vec *, PetscTable *, VecScatter *);
52943eb5e2fSMatthew Knepley #else
530014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetCommunicationStructs(Mat, Vec *, PetscInt *[], VecScatter *);
53143eb5e2fSMatthew Knepley #endif
532014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetGhosts(Mat, PetscInt *,const PetscInt *[]);
5338efafbd8SBarry Smith 
534014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat,PetscInt,IS[],PetscInt);
5357b80b807SBarry Smith 
536014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatMult(Mat,Mat,MatReuse,PetscReal,Mat*);
537014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatMultSymbolic(Mat,Mat,PetscReal,Mat*);
538014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatMultNumeric(Mat,Mat,Mat);
53922440eb1SKris Buschelman 
540014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPtAP(Mat,Mat,MatReuse,PetscReal,Mat*);
541014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPtAPSymbolic(Mat,Mat,PetscReal,Mat*);
542014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPtAPNumeric(Mat,Mat,Mat);
543014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRARt(Mat,Mat,MatReuse,PetscReal,Mat*);
544014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRARtSymbolic(Mat,Mat,PetscReal,Mat*);
545014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRARtNumeric(Mat,Mat,Mat);
54622440eb1SKris Buschelman 
547014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat,Mat,MatReuse,PetscReal,Mat*);
548014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransposetMatMultSymbolic(Mat,Mat,PetscReal,Mat*);
549014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransposetMatMultNumeric(Mat,Mat,Mat);
550014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat,Mat,MatReuse,PetscReal,Mat*);
551014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatTransposeMultSymbolic(Mat,Mat,PetscReal,Mat*);
552014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMatTransposeMultNumeric(Mat,Mat,Mat);
553bc011b1eSHong Zhang 
554014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAXPY(Mat,PetscScalar,Mat,MatStructure);
555014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAYPX(Mat,PetscScalar,Mat,MatStructure);
5561c741599SHong Zhang 
557014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatScale(Mat,PetscScalar);
558014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatShift(Mat,PetscScalar);
5597b80b807SBarry Smith 
560014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping,ISLocalToGlobalMapping);
561014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping,ISLocalToGlobalMapping);
562014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping*,ISLocalToGlobalMapping*);
563014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping*,ISLocalToGlobalMapping*);
564014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsLocal(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
565014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsLocalIS(Mat,IS,PetscScalar,Vec,Vec);
566014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocal(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
567014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocalIS(Mat,IS,PetscScalar,Vec,Vec);
568014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesLocal(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
569014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
570052efed2SBarry Smith 
571014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat,PetscInt,PetscInt);
572014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
57390f02eecSBarry Smith 
574014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatInterpolate(Mat,Vec,Vec);
575014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatInterpolateAdd(Mat,Vec,Vec,Vec);
576014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRestrict(Mat,Vec,Vec);
577014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetVecs(Mat,Vec*,Vec*);
578014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetRedundantMatrix(Mat,PetscInt,MPI_Comm,PetscInt,MatReuse,Mat*);
579014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetMultiProcBlock(Mat,MPI_Comm,MatReuse,Mat*);
580014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFindZeroDiagonals(Mat,IS*);
581bd481603SBarry Smith 
582bd481603SBarry Smith /*MC
5831620fd73SBarry Smith    MatSetValue - Set a single entry into a matrix.
5841620fd73SBarry Smith 
5851620fd73SBarry Smith    Not collective
5861620fd73SBarry Smith 
5871620fd73SBarry Smith    Input Parameters:
5881620fd73SBarry Smith +  m - the matrix
5891620fd73SBarry Smith .  row - the row location of the entry
5901620fd73SBarry Smith .  col - the column location of the entry
5911620fd73SBarry Smith .  value - the value to insert
5921620fd73SBarry Smith -  mode - either INSERT_VALUES or ADD_VALUES
5931620fd73SBarry Smith 
5941620fd73SBarry Smith    Notes:
5951620fd73SBarry Smith    For efficiency one should use MatSetValues() and set several or many
5961620fd73SBarry Smith    values simultaneously if possible.
5971620fd73SBarry Smith 
5981620fd73SBarry Smith    Level: beginner
5991620fd73SBarry Smith 
6001620fd73SBarry Smith .seealso: MatSetValues(), MatSetValueLocal()
6011620fd73SBarry Smith M*/
6021620fd73SBarry Smith PETSC_STATIC_INLINE PetscErrorCode MatSetValue(Mat v,PetscInt i,PetscInt j,PetscScalar va,InsertMode mode) {return MatSetValues(v,1,&i,1,&j,&va,mode);}
6031620fd73SBarry Smith 
6041620fd73SBarry Smith PETSC_STATIC_INLINE PetscErrorCode MatGetValue(Mat v,PetscInt i,PetscInt j,PetscScalar *va) {return MatGetValues(v,1,&i,1,&j,va);}
6051620fd73SBarry Smith 
6061620fd73SBarry Smith PETSC_STATIC_INLINE PetscErrorCode MatSetValueLocal(Mat v,PetscInt i,PetscInt j,PetscScalar va,InsertMode mode) {return MatSetValuesLocal(v,1,&i,1,&j,&va,mode);}
6071620fd73SBarry Smith 
6081620fd73SBarry Smith /*MC
6090d2a7ff2SSatish Balay    MatPreallocateInitialize - Begins the block of code that will count the number of nonzeros per
610bd481603SBarry Smith        row in a matrix providing the data that one can use to correctly preallocate the matrix.
611bd481603SBarry Smith 
612bd481603SBarry Smith    Synopsis:
613c1ac3661SBarry Smith    PetscErrorCode MatPreallocateInitialize(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)
614bd481603SBarry Smith 
615bd481603SBarry Smith    Collective on MPI_Comm
616bd481603SBarry Smith 
617bd481603SBarry Smith    Input Parameters:
618bd481603SBarry Smith +  comm - the communicator that will share the eventually allocated matrix
619859fcb39SBarry Smith .  nrows - the number of LOCAL rows in the matrix
620859fcb39SBarry Smith -  ncols - the number of LOCAL columns in the matrix
621bd481603SBarry Smith 
622bd481603SBarry Smith    Output Parameters:
623bd481603SBarry Smith +  dnz - the array that will be passed to the matrix preallocation routines
624bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
625bd481603SBarry Smith 
626bd481603SBarry Smith 
627bd481603SBarry Smith    Level: intermediate
628bd481603SBarry Smith 
629bd481603SBarry Smith    Notes:
6300598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
631bd481603SBarry Smith 
6321d73ed98SBarry Smith    Do not malloc or free dnz and onz, that is handled internally by these routines
633bd481603SBarry Smith 
634bd481603SBarry Smith    Use MatPreallocateInitializeSymmetric() for symmetric matrices (MPISBAIJ matrices)
635bd481603SBarry Smith 
6361620fd73SBarry Smith    This is a MACRO not a function because it has a leading { that is closed by PetscPreallocateFinalize().
6371620fd73SBarry Smith 
638bd481603SBarry Smith   Concepts: preallocation^Matrix
639bd481603SBarry Smith 
640bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
641bd481603SBarry Smith           MatPreallocateInitializeSymmetric(), MatPreallocateSymmetricSetLocal()
642bd481603SBarry Smith M*/
643c4f061fbSSatish Balay #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \
6447c922b88SBarry Smith { \
645a89bc211SBarry Smith   PetscErrorCode _4_ierr; PetscInt __nrows = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
646a89bc211SBarry Smith   _4_ierr = PetscMalloc2(__nrows,PetscInt,&dnz,__nrows,PetscInt,&onz);CHKERRQ(_4_ierr); \
647a89bc211SBarry Smith   _4_ierr = PetscMemzero(dnz,__nrows*sizeof(PetscInt));CHKERRQ(_4_ierr);\
648eabe889fSLisandro Dalcin   _4_ierr = PetscMemzero(onz,__nrows*sizeof(PetscInt));CHKERRQ(_4_ierr); __start = 0; __end = __start; \
649c1ac3661SBarry Smith   _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPIU_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\
650a89bc211SBarry Smith   _4_ierr = MPI_Scan(&__nrows,&__rstart,1,MPIU_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __nrows;
6517c922b88SBarry Smith 
652bd481603SBarry Smith /*MC
653bd481603SBarry Smith    MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
654bd481603SBarry Smith        inserted using a local number of the rows and columns
655bd481603SBarry Smith 
656bd481603SBarry Smith    Synopsis:
657c1ac3661SBarry Smith    PetscErrorCode MatPreallocateSetLocal(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
658bd481603SBarry Smith 
659bd481603SBarry Smith    Not Collective
660bd481603SBarry Smith 
661bd481603SBarry Smith    Input Parameters:
662784ac674SJed Brown +  map - the row mapping from local numbering to global numbering
663bd481603SBarry Smith .  nrows - the number of rows indicated
6641d73ed98SBarry Smith .  rows - the indices of the rows
665784ac674SJed Brown .  cmap - the column mapping from local to global numbering
666bd481603SBarry Smith .  ncols - the number of columns in the matrix
667bd481603SBarry Smith .  cols - the columns indicated
668bd481603SBarry Smith .  dnz - the array that will be passed to the matrix preallocation routines
669bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
670bd481603SBarry Smith 
671bd481603SBarry Smith 
672bd481603SBarry Smith    Level: intermediate
673bd481603SBarry Smith 
674bd481603SBarry Smith    Notes:
6750598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
676bd481603SBarry Smith 
6771d73ed98SBarry Smith    Do not malloc or free dnz and onz, that is handled internally by these routines
678bd481603SBarry Smith 
679bd481603SBarry Smith   Concepts: preallocation^Matrix
680bd481603SBarry Smith 
681bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
682bd481603SBarry Smith           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal()
683bd481603SBarry Smith M*/
684784ac674SJed Brown #define MatPreallocateSetLocal(rmap,nrows,rows,cmap,ncols,cols,dnz,onz) 0; \
685c4f061fbSSatish Balay {\
686c1ac3661SBarry Smith   PetscInt __l;\
687784ac674SJed Brown   _4_ierr = ISLocalToGlobalMappingApply(rmap,nrows,rows,rows);CHKERRQ(_4_ierr);\
688784ac674SJed Brown   _4_ierr = ISLocalToGlobalMappingApply(cmap,ncols,cols,cols);CHKERRQ(_4_ierr);\
689c4f061fbSSatish Balay   for (__l=0;__l<nrows;__l++) {\
690ef66eb69SBarry Smith     _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
691c4f061fbSSatish Balay   }\
692c4f061fbSSatish Balay }
693c4f061fbSSatish Balay 
694bd481603SBarry Smith /*MC
695bd481603SBarry Smith    MatPreallocateSymmetricSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
696bd481603SBarry Smith        inserted using a local number of the rows and columns
697bd481603SBarry Smith 
698bd481603SBarry Smith    Synopsis:
699c1ac3661SBarry Smith    PetscErrorCode MatPreallocateSymmetricSetLocal(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
700bd481603SBarry Smith 
701bd481603SBarry Smith    Not Collective
702bd481603SBarry Smith 
703bd481603SBarry Smith    Input Parameters:
704bd481603SBarry Smith +  map - the mapping between local numbering and global numbering
705bd481603SBarry Smith .  nrows - the number of rows indicated
7061d73ed98SBarry Smith .  rows - the indices of the rows
707bd481603SBarry Smith .  ncols - the number of columns in the matrix
708bd481603SBarry Smith .  cols - the columns indicated
709bd481603SBarry Smith .  dnz - the array that will be passed to the matrix preallocation routines
710bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
711bd481603SBarry Smith 
712bd481603SBarry Smith 
713bd481603SBarry Smith    Level: intermediate
714bd481603SBarry Smith 
715bd481603SBarry Smith    Notes:
7160598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
717bd481603SBarry Smith 
718bd481603SBarry Smith    Do not malloc or free dnz and onz that is handled internally by these routines
719bd481603SBarry Smith 
720bd481603SBarry Smith   Concepts: preallocation^Matrix
721bd481603SBarry Smith 
722bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
723bd481603SBarry Smith           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
724bd481603SBarry Smith M*/
725d3d32019SBarry Smith #define MatPreallocateSymmetricSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\
726d3d32019SBarry Smith {\
727c1ac3661SBarry Smith   PetscInt __l;\
728d3d32019SBarry Smith   _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\
729d3d32019SBarry Smith   _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\
730d3d32019SBarry Smith   for (__l=0;__l<nrows;__l++) {\
731d3d32019SBarry Smith     _4_ierr = MatPreallocateSymmetricSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
732d3d32019SBarry Smith   }\
733d3d32019SBarry Smith }
734d3d32019SBarry Smith 
735bd481603SBarry Smith /*MC
736bd481603SBarry Smith    MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
737bd481603SBarry Smith        inserted using a local number of the rows and columns
738bd481603SBarry Smith 
739bd481603SBarry Smith    Synopsis:
740c1ac3661SBarry Smith    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
741bd481603SBarry Smith 
742bd481603SBarry Smith    Not Collective
743bd481603SBarry Smith 
744bd481603SBarry Smith    Input Parameters:
74564075487SBarry Smith +  row - the row
746bd481603SBarry Smith .  ncols - the number of columns in the matrix
747a50f8bf6SHong Zhang -  cols - the columns indicated
748a50f8bf6SHong Zhang 
749a50f8bf6SHong Zhang    Output Parameters:
750a50f8bf6SHong Zhang +  dnz - the array that will be passed to the matrix preallocation routines
751bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
752bd481603SBarry Smith 
753bd481603SBarry Smith 
754bd481603SBarry Smith    Level: intermediate
755bd481603SBarry Smith 
756bd481603SBarry Smith    Notes:
7570598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
758bd481603SBarry Smith 
759bd481603SBarry Smith    Do not malloc or free dnz and onz that is handled internally by these routines
760bd481603SBarry Smith 
7611620fd73SBarry Smith    This is a MACRO not a function because it uses variables declared in MatPreallocateInitialize().
7621620fd73SBarry Smith 
763bd481603SBarry Smith   Concepts: preallocation^Matrix
764bd481603SBarry Smith 
765bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
766bd481603SBarry Smith           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
767bd481603SBarry Smith M*/
768c4f061fbSSatish Balay #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\
769c1ac3661SBarry Smith { PetscInt __i; \
770e32f2f54SBarry Smith   if (row < __rstart) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Trying to set preallocation for row %D less than first local row %D",row,__rstart);\
771e32f2f54SBarry Smith   if (row >= __rstart+__nrows) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Trying to set preallocation for row %D greater than last local row %D",row,__rstart+__nrows-1);\
7727c922b88SBarry Smith   for (__i=0; __i<nc; __i++) {\
77364075487SBarry Smith     if ((cols)[__i] < __start || (cols)[__i] >= __end) onz[row - __rstart]++; \
7747cc688d7SBarry Smith     else dnz[row - __rstart]++;\
7757c922b88SBarry Smith   }\
7767c922b88SBarry Smith }
7777c922b88SBarry Smith 
778bd481603SBarry Smith /*MC
779bd481603SBarry Smith    MatPreallocateSymmetricSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
780bd481603SBarry Smith        inserted using a local number of the rows and columns
781bd481603SBarry Smith 
782bd481603SBarry Smith    Synopsis:
783c1ac3661SBarry Smith    PetscErrorCode MatPreallocateSymmetricSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
784bd481603SBarry Smith 
785bd481603SBarry Smith    Not Collective
786bd481603SBarry Smith 
787bd481603SBarry Smith    Input Parameters:
788bd481603SBarry Smith +  nrows - the number of rows indicated
7891d73ed98SBarry Smith .  rows - the indices of the rows
790bd481603SBarry Smith .  ncols - the number of columns in the matrix
791bd481603SBarry Smith .  cols - the columns indicated
792bd481603SBarry Smith .  dnz - the array that will be passed to the matrix preallocation routines
793bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
794bd481603SBarry Smith 
795bd481603SBarry Smith 
796bd481603SBarry Smith    Level: intermediate
797bd481603SBarry Smith 
798bd481603SBarry Smith    Notes:
7990598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
800bd481603SBarry Smith 
801bd481603SBarry Smith    Do not malloc or free dnz and onz that is handled internally by these routines
802bd481603SBarry Smith 
8031620fd73SBarry Smith    This is a MACRO not a function because it uses variables declared in MatPreallocateInitialize().
8041620fd73SBarry Smith 
805bd481603SBarry Smith   Concepts: preallocation^Matrix
806bd481603SBarry Smith 
807bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
808bd481603SBarry Smith           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
809bd481603SBarry Smith M*/
810d3d32019SBarry Smith #define MatPreallocateSymmetricSet(row,nc,cols,dnz,onz) 0;\
811c1ac3661SBarry Smith { PetscInt __i; \
812d3d32019SBarry Smith   for (__i=0; __i<nc; __i++) {\
813d3d32019SBarry Smith     if (cols[__i] >= __end) onz[row - __rstart]++; \
814d3d32019SBarry Smith     else if (cols[__i] >= row) dnz[row - __rstart]++;\
815d3d32019SBarry Smith   }\
816d3d32019SBarry Smith }
817d3d32019SBarry Smith 
818bd481603SBarry Smith /*MC
81916371a99SBarry Smith    MatPreallocateLocation -  An alternative to MatPreallocationSet() that puts the nonzero locations into the matrix if it exists
82016371a99SBarry Smith 
82116371a99SBarry Smith    Synopsis:
82216371a99SBarry Smith    PetscErrorCode MatPreallocateLocations(Mat A,PetscInt row,PetscInt ncols,PetscInt *cols,PetscInt *dnz,PetscInt *onz)
82316371a99SBarry Smith 
82416371a99SBarry Smith    Not Collective
82516371a99SBarry Smith 
82616371a99SBarry Smith    Input Parameters:
82716371a99SBarry Smith .  A - matrix
82816371a99SBarry Smith .  row - row where values exist (must be local to this process)
82916371a99SBarry Smith .  ncols - number of columns
83016371a99SBarry Smith .  cols - columns with nonzeros
83116371a99SBarry Smith .  dnz - the array that will be passed to the matrix preallocation routines
83216371a99SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
83316371a99SBarry Smith 
83416371a99SBarry Smith 
83516371a99SBarry Smith    Level: intermediate
83616371a99SBarry Smith 
83716371a99SBarry Smith    Notes:
8380598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
83916371a99SBarry Smith 
84016371a99SBarry Smith    Do not malloc or free dnz and onz that is handled internally by these routines
84116371a99SBarry Smith 
84216371a99SBarry Smith    This is a MACRO not a function because it uses a bunch of variables private to the MatPreallocation.... routines.
84316371a99SBarry Smith 
84416371a99SBarry Smith   Concepts: preallocation^Matrix
84516371a99SBarry Smith 
84616371a99SBarry Smith .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
847eabe889fSLisandro Dalcin           MatPreallocateSymmetricSetLocal()
84816371a99SBarry Smith M*/
84916371a99SBarry Smith #define MatPreallocateLocation(A,row,ncols,cols,dnz,onz) 0;if (A) {ierr = MatSetValues(A,1,&row,ncols,cols,PETSC_NULL,INSERT_VALUES);CHKERRQ(ierr);} else {ierr =  MatPreallocateSet(row,ncols,cols,dnz,onz);CHKERRQ(ierr);}
85016371a99SBarry Smith 
85116371a99SBarry Smith 
85216371a99SBarry Smith /*MC
8530d2a7ff2SSatish Balay    MatPreallocateFinalize - Ends the block of code that will count the number of nonzeros per
854bd481603SBarry Smith        row in a matrix providing the data that one can use to correctly preallocate the matrix.
855bd481603SBarry Smith 
856bd481603SBarry Smith    Synopsis:
857c1ac3661SBarry Smith    PetscErrorCode MatPreallocateFinalize(PetscInt *dnz, PetscInt *onz)
858bd481603SBarry Smith 
859bd481603SBarry Smith    Collective on MPI_Comm
860bd481603SBarry Smith 
861bd481603SBarry Smith    Input Parameters:
86216371a99SBarry Smith +  dnz - the array that was be passed to the matrix preallocation routines
863bd481603SBarry Smith -  ozn - the other array passed to the matrix preallocation routines
864bd481603SBarry Smith 
865bd481603SBarry Smith 
866bd481603SBarry Smith    Level: intermediate
867bd481603SBarry Smith 
868bd481603SBarry Smith    Notes:
8690598bfebSBarry Smith     See the <A href="../../docs/manual.pdf#nameddest=ch_performance">Hints for Performance Improvment</A> chapter in the users manual for more details.
870bd481603SBarry Smith 
871bd481603SBarry Smith    Do not malloc or free dnz and onz that is handled internally by these routines
872bd481603SBarry Smith 
8731620fd73SBarry Smith    This is a MACRO not a function because it closes the { started in MatPreallocateInitialize().
8741620fd73SBarry Smith 
875bd481603SBarry Smith   Concepts: preallocation^Matrix
876bd481603SBarry Smith 
877bd481603SBarry Smith .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
878eabe889fSLisandro Dalcin           MatPreallocateSymmetricSetLocal()
879bd481603SBarry Smith M*/
880a89bc211SBarry Smith #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree2(dnz,onz);CHKERRQ(_4_ierr);}
8817c922b88SBarry Smith 
882bd481603SBarry Smith 
883bd481603SBarry Smith 
8847b80b807SBarry Smith /* Routines unique to particular data structures */
885014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatShellGetContext(Mat,void *);
886698d4c6aSKris Buschelman 
887014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat,IS*,IS*);
888014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat,PetscInt *,PetscInt *[],PetscInt *);
889698d4c6aSKris Buschelman 
890014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat,PetscInt[]);
891014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat,PetscInt[]);
892014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
893014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
894014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
895014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqAIJFromTriple(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*,PetscInt,PetscBool);
8967b80b807SBarry Smith 
897a96a251dSBarry Smith #define MAT_SKIP_ALLOCATION -4
898a96a251dSBarry Smith 
899014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[]);
900014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[]);
901014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat,PetscInt,const PetscInt[]);
902273d9f13SBarry Smith 
903014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
904014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
905014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
906014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat,const PetscInt [],const PetscInt [],const PetscScalar []);
907014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
908014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat,const PetscInt[],const PetscInt[],const PetscScalar[]);
909014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
910014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat,PetscInt[],PetscInt[],PetscInt[]);
911014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat,PetscScalar[]);
912014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat,PetscScalar[]);
913014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,PetscInt*[]);
914014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,PetscInt*[]);
915014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatAdicSetLocalFunction(Mat,void (*)(void));
916014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIAdjCreateNonemptySubcommMat(Mat,Mat*);
917273d9f13SBarry Smith 
918014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqDenseSetLDA(Mat,PetscInt);
919014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDenseGetLocalMatrix(Mat,Mat*);
9201b807ce4Svictorle 
921014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
922014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);
9232e8a6d31SBarry Smith 
924014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDAADSetCtx(Mat,void*);
9253a7fca6bSBarry Smith 
926014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFindNonzeroRows(Mat,IS*);
9277b80b807SBarry Smith /*
9287b80b807SBarry Smith   These routines are not usually accessed directly, rather solving is
92994b7f48cSBarry Smith   done through the KSP and PC interfaces.
9307b80b807SBarry Smith */
9317b80b807SBarry Smith 
93276bdecfbSBarry Smith /*J
933d9274352SBarry Smith     MatOrderingType - String with the name of a PETSc matrix ordering or the creation function
934d9274352SBarry Smith        with an optional dynamic library name, for example
935d9274352SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:orderingcreate()
936d9274352SBarry Smith 
937d9274352SBarry Smith    Level: beginner
938d9274352SBarry Smith 
939e5a9bf91SBarry Smith    Cannot use const because the PC objects manipulate the string
940e5a9bf91SBarry Smith 
941d9274352SBarry Smith .seealso: MatGetOrdering()
94276bdecfbSBarry Smith J*/
9433eaad2caSSatish Balay #define MatOrderingType char*
9442692d6eeSBarry Smith #define MATORDERINGNATURAL     "natural"
9452692d6eeSBarry Smith #define MATORDERINGND          "nd"
9462692d6eeSBarry Smith #define MATORDERING1WD         "1wd"
9472692d6eeSBarry Smith #define MATORDERINGRCM         "rcm"
9482692d6eeSBarry Smith #define MATORDERINGQMD         "qmd"
9492692d6eeSBarry Smith #define MATORDERINGROWLENGTH   "rowlength"
950312e372aSBarry Smith #define MATORDERINGAMD         "amd"            /* only works if UMFPACK is installed with PETSc */
951b12f92e5SBarry Smith 
952014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOrdering(Mat,const MatOrderingType,IS*,IS*);
953014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetOrderingList(PetscFList *list);
954014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatOrderingRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,const MatOrderingType,IS*,IS*));
95530de9b25SBarry Smith 
95630de9b25SBarry Smith /*MC
9571890ba74SBarry Smith    MatOrderingRegisterDynamic - Adds a new sparse matrix ordering to the matrix package.
95830de9b25SBarry Smith 
95930de9b25SBarry Smith    Synopsis:
9601890ba74SBarry Smith    PetscErrorCode MatOrderingRegisterDynamic(const char *name_ordering,const char *path,const char *name_create,PetscErrorCode (*routine_create)(MatOrdering))
96130de9b25SBarry Smith 
96230de9b25SBarry Smith    Not Collective
96330de9b25SBarry Smith 
96430de9b25SBarry Smith    Input Parameters:
9652692d6eeSBarry Smith +  sname - name of ordering (for example MATORDERINGND)
96630de9b25SBarry Smith .  path - location of library where creation routine is
96730de9b25SBarry Smith .  name - name of function that creates the ordering type,a string
96830de9b25SBarry Smith -  function - function pointer that creates the ordering
96930de9b25SBarry Smith 
97030de9b25SBarry Smith    Level: developer
97130de9b25SBarry Smith 
97230de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (function)
97330de9b25SBarry Smith    is ignored.
97430de9b25SBarry Smith 
97530de9b25SBarry Smith    Sample usage:
97630de9b25SBarry Smith .vb
97730de9b25SBarry Smith    MatOrderingRegisterDynamic("my_order",/home/username/my_lib/lib/libO/solaris/mylib.a,
97830de9b25SBarry Smith                "MyOrder",MyOrder);
97930de9b25SBarry Smith .ve
98030de9b25SBarry Smith 
98130de9b25SBarry Smith    Then, your partitioner can be chosen with the procedural interface via
98230de9b25SBarry Smith $     MatOrderingSetType(part,"my_order)
98330de9b25SBarry Smith    or at runtime via the option
9842401956bSBarry Smith $     -pc_factor_mat_ordering_type my_order
98530de9b25SBarry Smith 
986ab901514SBarry Smith    ${PETSC_ARCH} occuring in pathname will be replaced with appropriate values.
98730de9b25SBarry Smith 
98830de9b25SBarry Smith .keywords: matrix, ordering, register
98930de9b25SBarry Smith 
99030de9b25SBarry Smith .seealso: MatOrderingRegisterDestroy(), MatOrderingRegisterAll()
99130de9b25SBarry Smith M*/
992aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
993f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0)
994b12f92e5SBarry Smith #else
995f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d)
996b12f92e5SBarry Smith #endif
99730de9b25SBarry Smith 
998014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatOrderingRegisterDestroy(void);
999014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatOrderingRegisterAll(const char[]);
1000014dd563SJed Brown PETSC_EXTERN PetscBool MatOrderingRegisterAllCalled;
1001014dd563SJed Brown PETSC_EXTERN PetscFList MatOrderingList;
1002d4fbbf0eSBarry Smith 
1003014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS);
1004a2ce50c7SBarry Smith 
1005d91e6319SBarry Smith /*S
1006d90ac83dSHong Zhang     MatFactorShiftType - Numeric Shift.
1007d90ac83dSHong Zhang 
1008d90ac83dSHong Zhang    Level: beginner
1009d90ac83dSHong Zhang 
1010d90ac83dSHong Zhang S*/
1011d90ac83dSHong Zhang typedef enum {MAT_SHIFT_NONE,MAT_SHIFT_NONZERO,MAT_SHIFT_POSITIVE_DEFINITE,MAT_SHIFT_INBLOCKS} MatFactorShiftType;
1012014dd563SJed Brown PETSC_EXTERN const char *MatFactorShiftTypes[];
1013d90ac83dSHong Zhang 
1014d90ac83dSHong Zhang /*S
10152401956bSBarry Smith    MatFactorInfo - Data passed into the matrix factorization routines
1016b00f7748SHong Zhang 
101761cad860SBarry Smith    In Fortran these are simply double precision arrays of size MAT_FACTORINFO_SIZE, that is use
101861cad860SBarry Smith $     MatFactorInfo  info(MAT_FACTORINFO_SIZE)
1019b00f7748SHong Zhang 
102015e8a5b3SHong Zhang    Notes: These are not usually directly used by users, instead use PC type of LU, ILU, CHOLESKY or ICC.
1021b00f7748SHong Zhang 
102261cad860SBarry Smith       You can use MatFactorInfoInitialize() to set default values.
102361cad860SBarry Smith 
1024b00f7748SHong Zhang    Level: developer
1025b00f7748SHong Zhang 
1026d7d82daaSBarry Smith .seealso: MatLUFactorSymbolic(), MatILUFactorSymbolic(), MatCholeskyFactorSymbolic(), MatICCFactorSymbolic(), MatICCFactor(),
1027d7d82daaSBarry Smith           MatFactorInfoInitialize()
1028b00f7748SHong Zhang 
1029b00f7748SHong Zhang S*/
1030b00f7748SHong Zhang typedef struct {
103115e8a5b3SHong Zhang   PetscReal     diagonal_fill;  /* force diagonal to fill in if initially not filled */
103285317021SBarry Smith   PetscReal     usedt;
103315e8a5b3SHong Zhang   PetscReal     dt;             /* drop tolerance */
1034b00f7748SHong Zhang   PetscReal     dtcol;          /* tolerance for pivoting */
103515e8a5b3SHong Zhang   PetscReal     dtcount;        /* maximum nonzeros to be allowed per row */
103667e28bfeSBarry Smith   PetscReal     fill;           /* expected fill, nonzeros in factored matrix/nonzeros in original matrix */
1037348344bbSBarry Smith   PetscReal     levels;         /* ICC/ILU(levels) */
1038bcd9e38bSBarry Smith   PetscReal     pivotinblocks;  /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0
1039bcd9e38bSBarry Smith                                    factorization may be faster if do not pivot */
104015e8a5b3SHong Zhang   PetscReal     zeropivot;      /* pivot is called zero if less than this */
1041f4db908eSBarry Smith   PetscReal     shifttype;      /* type of shift added to matrix factor to prevent zero pivots */
1042f4db908eSBarry Smith   PetscReal     shiftamount;     /* how large the shift is */
104315e8a5b3SHong Zhang } MatFactorInfo;
1044ffa6d0a5SLois Curfman McInnes 
1045014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFactorInfoInitialize(MatFactorInfo*);
1046014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCholeskyFactor(Mat,IS,const MatFactorInfo*);
1047014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat,Mat,IS,const MatFactorInfo*);
1048014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat,Mat,const MatFactorInfo*);
1049014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatLUFactor(Mat,IS,IS,const MatFactorInfo*);
1050014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatILUFactor(Mat,IS,IS,const MatFactorInfo*);
1051014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatLUFactorSymbolic(Mat,Mat,IS,IS,const MatFactorInfo*);
1052014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatILUFactorSymbolic(Mat,Mat,IS,IS,const MatFactorInfo*);
1053014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatICCFactorSymbolic(Mat,Mat,IS,const MatFactorInfo*);
1054014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatICCFactor(Mat,IS,const MatFactorInfo*);
1055014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatLUFactorNumeric(Mat,Mat,const MatFactorInfo*);
1056014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetInertia(Mat,PetscInt*,PetscInt*,PetscInt*);
1057014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSolve(Mat,Vec,Vec);
1058014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatForwardSolve(Mat,Vec,Vec);
1059014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatBackwardSolve(Mat,Vec,Vec);
1060014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSolveAdd(Mat,Vec,Vec,Vec);
1061014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSolveTranspose(Mat,Vec,Vec);
1062014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
1063014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSolves(Mat,Vecs,Vecs);
10648ed539a5SBarry Smith 
1065014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetUnfactored(Mat);
1066bb5a7306SBarry Smith 
1067d91e6319SBarry Smith /*E
1068d91e6319SBarry Smith     MatSORType - What type of (S)SOR to perform
1069bb1eb677SSatish Balay 
1070d91e6319SBarry Smith     Level: beginner
1071d91e6319SBarry Smith 
1072d9274352SBarry Smith    May be bitwise ORd together
1073d9274352SBarry Smith 
1074d91e6319SBarry Smith    Any additions/changes here MUST also be made in include/finclude/petscmat.h
1075d91e6319SBarry Smith 
10764e7234bfSBarry Smith    MatSORType may be bitwise ORd together, so do not change the numbers
10774e7234bfSBarry Smith 
107841f059aeSBarry Smith .seealso: MatSOR()
1079d91e6319SBarry Smith E*/
1080ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
1081ee50ffe9SBarry Smith               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
1082ee50ffe9SBarry Smith               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
108384cb2905SBarry Smith               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
1084014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSOR(Mat,Vec,PetscReal,MatSORType,PetscReal,PetscInt,PetscInt,Vec);
10858ed539a5SBarry Smith 
1086d4fbbf0eSBarry Smith /*
1087639f9d9dSBarry Smith     These routines are for efficiently computing Jacobians via finite differences.
1088639f9d9dSBarry Smith */
1089b12f92e5SBarry Smith 
109076bdecfbSBarry Smith /*J
1091d9274352SBarry Smith     MatColoringType - String with the name of a PETSc matrix coloring or the creation function
1092d9274352SBarry Smith        with an optional dynamic library name, for example
1093d9274352SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:coloringcreate()
1094d9274352SBarry Smith 
1095d9274352SBarry Smith    Level: beginner
1096d9274352SBarry Smith 
1097d9274352SBarry Smith .seealso: MatGetColoring()
109876bdecfbSBarry Smith J*/
1099a313700dSBarry Smith #define MatColoringType char*
11002692d6eeSBarry Smith #define MATCOLORINGNATURAL "natural"
11012692d6eeSBarry Smith #define MATCOLORINGSL      "sl"
11022692d6eeSBarry Smith #define MATCOLORINGLF      "lf"
11032692d6eeSBarry Smith #define MATCOLORINGID      "id"
1104b12f92e5SBarry Smith 
1105014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetColoring(Mat,const MatColoringType,ISColoring*);
1106014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatColoringRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,MatColoringType,ISColoring *));
110730de9b25SBarry Smith 
110830de9b25SBarry Smith /*MC
110930de9b25SBarry Smith    MatColoringRegisterDynamic - Adds a new sparse matrix coloring to the
111030de9b25SBarry Smith                                matrix package.
111130de9b25SBarry Smith 
111230de9b25SBarry Smith    Synopsis:
11131890ba74SBarry Smith    PetscErrorCode MatColoringRegisterDynamic(const char *name_coloring,const char *path,const char *name_create,PetscErrorCode (*routine_create)(MatColoring))
111430de9b25SBarry Smith 
111530de9b25SBarry Smith    Not Collective
111630de9b25SBarry Smith 
111730de9b25SBarry Smith    Input Parameters:
11182692d6eeSBarry Smith +  sname - name of Coloring (for example MATCOLORINGSL)
111930de9b25SBarry Smith .  path - location of library where creation routine is
112030de9b25SBarry Smith .  name - name of function that creates the Coloring type, a string
112130de9b25SBarry Smith -  function - function pointer that creates the coloring
112230de9b25SBarry Smith 
112330de9b25SBarry Smith    Level: developer
112430de9b25SBarry Smith 
112530de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (function)
112630de9b25SBarry Smith    is ignored.
112730de9b25SBarry Smith 
112830de9b25SBarry Smith    Sample usage:
112930de9b25SBarry Smith .vb
113030de9b25SBarry Smith    MatColoringRegisterDynamic("my_color",/home/username/my_lib/lib/libO/solaris/mylib.a,
113130de9b25SBarry Smith                "MyColor",MyColor);
113230de9b25SBarry Smith .ve
113330de9b25SBarry Smith 
113430de9b25SBarry Smith    Then, your partitioner can be chosen with the procedural interface via
113530de9b25SBarry Smith $     MatColoringSetType(part,"my_color")
113630de9b25SBarry Smith    or at runtime via the option
113730de9b25SBarry Smith $     -mat_coloring_type my_color
113830de9b25SBarry Smith 
1139ab901514SBarry Smith    $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
114030de9b25SBarry Smith 
114130de9b25SBarry Smith .keywords: matrix, Coloring, register
114230de9b25SBarry Smith 
114330de9b25SBarry Smith .seealso: MatColoringRegisterDestroy(), MatColoringRegisterAll()
114430de9b25SBarry Smith M*/
1145aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1146f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0)
1147b12f92e5SBarry Smith #else
1148f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d)
1149b12f92e5SBarry Smith #endif
115030de9b25SBarry Smith 
1151014dd563SJed Brown PETSC_EXTERN PetscBool MatColoringRegisterAllCalled;
1152f1144a30SSatish Balay 
1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatColoringRegisterAll(const char[]);
1154014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatColoringRegisterDestroy(void);
1155014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatColoringPatch(Mat,PetscInt,PetscInt,ISColoringValue[],ISColoring*);
1156639f9d9dSBarry Smith 
1157d9274352SBarry Smith /*S
1158d9274352SBarry Smith      MatFDColoring - Object for computing a sparse Jacobian via finite differences
1159d9274352SBarry Smith         and coloring
1160639f9d9dSBarry Smith 
1161d9274352SBarry Smith    Level: beginner
1162d9274352SBarry Smith 
1163d9274352SBarry Smith   Concepts: coloring, sparse Jacobian, finite differences
1164d9274352SBarry Smith 
1165d9274352SBarry Smith .seealso:  MatFDColoringCreate()
1166d9274352SBarry Smith S*/
1167e2a1c21fSSatish Balay typedef struct _p_MatFDColoring* MatFDColoring;
1168639f9d9dSBarry Smith 
1169014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
1170014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring*);
1171014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringView(MatFDColoring,PetscViewer);
1172014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring,PetscErrorCode (*)(void),void*);
1173014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringGetFunction(MatFDColoring,PetscErrorCode (**)(void),void**);
1174014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal);
1175014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring);
1176014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *);
1177014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring,Vec);
1178014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring,PetscInt*,PetscInt*[]);
1179b1683b59SHong Zhang 
1180b1683b59SHong Zhang /*S
1181b9af6bddSHong Zhang      MatTransposeColoring - Object for computing a sparse matrix product C=A*B^T via coloring
1182b1683b59SHong Zhang 
1183b1683b59SHong Zhang    Level: beginner
1184b1683b59SHong Zhang 
1185b1683b59SHong Zhang   Concepts: coloring, sparse matrix product
1186b1683b59SHong Zhang 
1187b9af6bddSHong Zhang .seealso:  MatTransposeColoringCreate()
1188b1683b59SHong Zhang S*/
1189b9af6bddSHong Zhang typedef struct _p_MatTransposeColoring* MatTransposeColoring;
1190b1683b59SHong Zhang 
1191014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat,ISColoring,MatTransposeColoring *);
1192014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring,Mat,Mat);
1193014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring,Mat,Mat);
1194014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring*);
1195b1683b59SHong Zhang 
1196639f9d9dSBarry Smith /*
11970752156aSBarry Smith     These routines are for partitioning matrices: currently used only
11983eda8832SBarry Smith   for adjacency matrix, MatCreateMPIAdj().
11990752156aSBarry Smith */
1200ca161407SBarry Smith 
1201d9274352SBarry Smith /*S
1202d9274352SBarry Smith      MatPartitioning - Object for managing the partitioning of a matrix or graph
1203d9274352SBarry Smith 
1204d9274352SBarry Smith    Level: beginner
1205d9274352SBarry Smith 
1206d9274352SBarry Smith   Concepts: partitioning
1207d9274352SBarry Smith 
1208743a1026Svictorle .seealso:  MatPartitioningCreate(), MatPartitioningType
1209d9274352SBarry Smith S*/
121091e9ee9fSBarry Smith typedef struct _p_MatPartitioning* MatPartitioning;
1211d9274352SBarry Smith 
121276bdecfbSBarry Smith /*J
12135bc6e7ccSvictorle     MatPartitioningType - String with the name of a PETSc matrix partitioning or the creation function
1214d9274352SBarry Smith        with an optional dynamic library name, for example
1215d9274352SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate()
1216d9274352SBarry Smith 
1217d9274352SBarry Smith    Level: beginner
12180d04baf8SBarry Smith dm
1219b547a13bSvictorle .seealso: MatPartitioningCreate(), MatPartitioning
122076bdecfbSBarry Smith J*/
1221a313700dSBarry Smith #define MatPartitioningType char*
12222692d6eeSBarry Smith #define MATPARTITIONINGCURRENT  "current"
12232692d6eeSBarry Smith #define MATPARTITIONINGSQUARE   "square"
12242692d6eeSBarry Smith #define MATPARTITIONINGPARMETIS "parmetis"
12252692d6eeSBarry Smith #define MATPARTITIONINGCHACO    "chaco"
12262692d6eeSBarry Smith #define MATPARTITIONINGPARTY    "party"
122750d91057SBarry Smith #define MATPARTITIONINGPTSCOTCH "ptscotch"
122871306c60Sjroman 
1229ca161407SBarry Smith 
1230014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm,MatPartitioning*);
1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning,const MatPartitioningType);
1232014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning,PetscInt);
1233014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning,Mat);
1234014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning,const PetscInt[]);
1235014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning,const PetscReal []);
1236014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning,IS*);
1237014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning*);
12382aabb6bbSBarry Smith 
1239014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningRegister(const char[],const char[],const char[],PetscErrorCode (*)(MatPartitioning));
124030de9b25SBarry Smith 
124130de9b25SBarry Smith /*MC
124230de9b25SBarry Smith    MatPartitioningRegisterDynamic - Adds a new sparse matrix partitioning to the
124330de9b25SBarry Smith    matrix package.
124430de9b25SBarry Smith 
124530de9b25SBarry Smith    Synopsis:
12461890ba74SBarry Smith    PetscErrorCode MatPartitioningRegisterDynamic(const char *name_partitioning,const char *path,const char *name_create,PetscErrorCode (*routine_create)(MatPartitioning))
124730de9b25SBarry Smith 
124830de9b25SBarry Smith    Not Collective
124930de9b25SBarry Smith 
125030de9b25SBarry Smith    Input Parameters:
12512692d6eeSBarry Smith +  sname - name of partitioning (for example MATPARTITIONINGCURRENT) or parmetis
125230de9b25SBarry Smith .  path - location of library where creation routine is
125330de9b25SBarry Smith .  name - name of function that creates the partitioning type, a string
125430de9b25SBarry Smith -  function - function pointer that creates the partitioning type
125530de9b25SBarry Smith 
125630de9b25SBarry Smith    Level: developer
125730de9b25SBarry Smith 
125830de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (function)
125930de9b25SBarry Smith    is ignored.
126030de9b25SBarry Smith 
126130de9b25SBarry Smith    Sample usage:
126230de9b25SBarry Smith .vb
126330de9b25SBarry Smith    MatPartitioningRegisterDynamic("my_part",/home/username/my_lib/lib/libO/solaris/mylib.a,
126430de9b25SBarry Smith                "MyPartCreate",MyPartCreate);
126530de9b25SBarry Smith .ve
126630de9b25SBarry Smith 
126730de9b25SBarry Smith    Then, your partitioner can be chosen with the procedural interface via
126830de9b25SBarry Smith $     MatPartitioningSetType(part,"my_part")
126930de9b25SBarry Smith    or at runtime via the option
127030de9b25SBarry Smith $     -mat_partitioning_type my_part
127130de9b25SBarry Smith 
1272ab901514SBarry Smith    $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
127330de9b25SBarry Smith 
127430de9b25SBarry Smith .keywords: matrix, partitioning, register
127530de9b25SBarry Smith 
127630de9b25SBarry Smith .seealso: MatPartitioningRegisterDestroy(), MatPartitioningRegisterAll()
127730de9b25SBarry Smith M*/
1278aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1279f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0)
12802aabb6bbSBarry Smith #else
1281f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d)
12822aabb6bbSBarry Smith #endif
12832aabb6bbSBarry Smith 
1284014dd563SJed Brown PETSC_EXTERN PetscBool MatPartitioningRegisterAllCalled;
1285f1144a30SSatish Balay 
1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningRegisterAll(const char[]);
1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningRegisterDestroy(void);
12882bad1931SBarry Smith 
1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningView(MatPartitioning,PetscViewer);
1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning);
1291014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning,const MatPartitioningType*);
1292ca161407SBarry Smith 
1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1294014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *);
12950752156aSBarry Smith 
1296b6956c12SJose Roman typedef enum { MP_CHACO_MULTILEVEL=1,MP_CHACO_SPECTRAL=2,MP_CHACO_LINEAR=4,MP_CHACO_RANDOM=5,MP_CHACO_SCATTERED=6 } MPChacoGlobalType;
1297014dd563SJed Brown PETSC_EXTERN const char *MPChacoGlobalTypes[];
1298b6956c12SJose Roman typedef enum { MP_CHACO_KERNIGHAN=1,MP_CHACO_NONE=2 } MPChacoLocalType;
1299014dd563SJed Brown PETSC_EXTERN const char *MPChacoLocalTypes[];
1300b6956c12SJose Roman typedef enum { MP_CHACO_LANCZOS=0,MP_CHACO_RQI=1 } MPChacoEigenType;
1301014dd563SJed Brown PETSC_EXTERN const char *MPChacoEigenTypes[];
1302b6956c12SJose Roman 
1303014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning,MPChacoGlobalType);
1304014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning,MPChacoGlobalType*);
1305014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning,MPChacoLocalType);
1306014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning,MPChacoLocalType*);
1307014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning,PetscReal);
1308014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning,MPChacoEigenType);
1309014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning,MPChacoEigenType*);
1310014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning,PetscReal);
1311014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning,PetscReal*);
1312014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning,PetscInt);
1313014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning,PetscInt*);
131471306c60Sjroman 
131571306c60Sjroman #define MP_PARTY_OPT "opt"
131671306c60Sjroman #define MP_PARTY_LIN "lin"
131771306c60Sjroman #define MP_PARTY_SCA "sca"
131871306c60Sjroman #define MP_PARTY_RAN "ran"
131971306c60Sjroman #define MP_PARTY_GBF "gbf"
132071306c60Sjroman #define MP_PARTY_GCF "gcf"
132171306c60Sjroman #define MP_PARTY_BUB "bub"
132271306c60Sjroman #define MP_PARTY_DEF "def"
1323014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning,const char*);
132471306c60Sjroman #define MP_PARTY_HELPFUL_SETS "hs"
132571306c60Sjroman #define MP_PARTY_KERNIGHAN_LIN "kl"
132671306c60Sjroman #define MP_PARTY_NONE "no"
1327014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning,const char*);
1328014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning,PetscReal);
1329014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning,PetscBool);
1330014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning,PetscBool);
133171306c60Sjroman 
133250d91057SBarry Smith typedef enum { MP_PTSCOTCH_QUALITY,MP_PTSCOTCH_SPEED,MP_PTSCOTCH_BALANCE,MP_PTSCOTCH_SAFETY,MP_PTSCOTCH_SCALABILITY } MPPTScotchStrategyType;
1333014dd563SJed Brown PETSC_EXTERN const char *MPPTScotchStrategyTypes[];
1334e0f1cffaSJose Roman 
1335014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning,PetscReal);
1336014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning,PetscReal*);
1337014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning,MPPTScotchStrategyType);
1338014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning,MPPTScotchStrategyType*);
133971306c60Sjroman 
1340b43b03e9SMark F. Adams /*
1341b43b03e9SMark F. Adams     These routines are for coarsening matrices:
1342b43b03e9SMark F. Adams */
1343b43b03e9SMark F. Adams 
1344b43b03e9SMark F. Adams /*S
1345b43b03e9SMark F. Adams      MatCoarsen - Object for managing the coarsening of a graph (symmetric matrix)
1346b43b03e9SMark F. Adams 
1347b43b03e9SMark F. Adams    Level: beginner
1348b43b03e9SMark F. Adams 
1349b43b03e9SMark F. Adams   Concepts: coarsen
1350b43b03e9SMark F. Adams 
1351b43b03e9SMark F. Adams .seealso:  MatCoarsenCreate), MatCoarsenType
1352b43b03e9SMark F. Adams S*/
1353b43b03e9SMark F. Adams typedef struct _p_MatCoarsen* MatCoarsen;
1354b43b03e9SMark F. Adams 
1355b43b03e9SMark F. Adams /*J
1356b43b03e9SMark F. Adams     MatCoarsenType - String with the name of a PETSc matrix coarsen or the creation function
1357b43b03e9SMark F. Adams        with an optional dynamic library name, for example
1358b43b03e9SMark F. Adams        http://www.mcs.anl.gov/petsc/lib.a:coarsencreate()
1359b43b03e9SMark F. Adams 
1360b43b03e9SMark F. Adams    Level: beginner
1361b43b03e9SMark F. Adams dm
1362b43b03e9SMark F. Adams .seealso: MatCoarsenCreate(), MatCoarsen
1363b43b03e9SMark F. Adams J*/
1364b43b03e9SMark F. Adams #define MatCoarsenType char*
1365b43b03e9SMark F. Adams #define MATCOARSENMIS  "mis"
13669057884aSMark F. Adams #define MATCOARSENHEM  "hem"
1367b43b03e9SMark F. Adams 
13680cbbd2e1SMark F. Adams /* linked list for aggregates */
136941b27cdeSMark F. Adams typedef struct _PetscCDIntNd{
137041b27cdeSMark F. Adams   struct _PetscCDIntNd *next;
13710cbbd2e1SMark F. Adams   PetscInt   gid;
137241b27cdeSMark F. Adams }PetscCDIntNd;
13730cbbd2e1SMark F. Adams 
13740cbbd2e1SMark F. Adams /* only used by node pool */
137541b27cdeSMark F. Adams typedef struct _PetscCDArrNd{
137641b27cdeSMark F. Adams   struct _PetscCDArrNd *next;
137741b27cdeSMark F. Adams   struct _PetscCDIntNd *array;
137841b27cdeSMark F. Adams }PetscCDArrNd;
13790cbbd2e1SMark F. Adams 
13800cbbd2e1SMark F. Adams typedef struct _PetscCoarsenData{
13810cbbd2e1SMark F. Adams   /* node pool */
138241b27cdeSMark F. Adams   PetscCDArrNd  pool_list;
138341b27cdeSMark F. Adams   PetscCDIntNd *new_node;
13840cbbd2e1SMark F. Adams   PetscInt   new_left;
13850cbbd2e1SMark F. Adams   PetscInt   chk_sz;
138641b27cdeSMark F. Adams   PetscCDIntNd *extra_nodes;
13870cbbd2e1SMark F. Adams   /* Array of lists */
138841b27cdeSMark F. Adams   PetscCDIntNd **array;
13890cbbd2e1SMark F. Adams   PetscInt size;
13900cbbd2e1SMark F. Adams   /* cache a Mat for communication data */
13910cbbd2e1SMark F. Adams   Mat mat;
1392a94c3b12SMark F. Adams   /* cache IS of removed equations */
1393a94c3b12SMark F. Adams   IS removedIS;
13940cbbd2e1SMark F. Adams }PetscCoarsenData;
13950cbbd2e1SMark F. Adams 
1396014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenCreate(MPI_Comm,MatCoarsen*);
1397014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetType(MatCoarsen,const MatCoarsenType);
1398014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetAdjacency(MatCoarsen,Mat);
1399014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetGreedyOrdering(MatCoarsen,const IS);
1400014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetStrictAggs(MatCoarsen,PetscBool);
1401014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetVerbose(MatCoarsen,PetscInt);
1402014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenGetData( MatCoarsen, PetscCoarsenData ** );
1403014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenApply(MatCoarsen);
1404014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenDestroy(MatCoarsen*);
1405b43b03e9SMark F. Adams 
1406014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenRegister(const char[],const char[],const char[],PetscErrorCode (*)(MatCoarsen));
1407b43b03e9SMark F. Adams 
1408b43b03e9SMark F. Adams /*MC
1409b43b03e9SMark F. Adams    MatCoarsenRegisterDynamic - Adds a new sparse matrix coarsen to the
1410b43b03e9SMark F. Adams    matrix package.
1411b43b03e9SMark F. Adams 
1412b43b03e9SMark F. Adams    Synopsis:
1413b43b03e9SMark F. Adams    PetscErrorCode MatCoarsenRegisterDynamic(const char *name_coarsen,const char *path,const char *name_create,PetscErrorCode (*routine_create)(MatCoarsen))
1414b43b03e9SMark F. Adams 
1415b43b03e9SMark F. Adams    Not Collective
1416b43b03e9SMark F. Adams 
1417b43b03e9SMark F. Adams    Input Parameters:
1418b43b03e9SMark F. Adams +  sname - name of coarsen (for example MATCOARSENMIS)
1419b43b03e9SMark F. Adams .  path - location of library where creation routine is
1420b43b03e9SMark F. Adams .  name - name of function that creates the coarsen type, a string
1421b43b03e9SMark F. Adams -  function - function pointer that creates the coarsen type
1422b43b03e9SMark F. Adams 
1423b43b03e9SMark F. Adams    Level: developer
1424b43b03e9SMark F. Adams 
1425b43b03e9SMark F. Adams    If dynamic libraries are used, then the fourth input argument (function)
1426b43b03e9SMark F. Adams    is ignored.
1427b43b03e9SMark F. Adams 
1428b43b03e9SMark F. Adams    Sample usage:
1429b43b03e9SMark F. Adams .vb
1430b43b03e9SMark F. Adams    MatCoarsenRegisterDynamic("my_agg",/home/username/my_lib/lib/libO/solaris/mylib.a,
1431b43b03e9SMark F. Adams                "MyAggCreate",MyAggCreate);
1432b43b03e9SMark F. Adams .ve
1433b43b03e9SMark F. Adams 
1434b43b03e9SMark F. Adams    Then, your aggregator can be chosen with the procedural interface via
1435b43b03e9SMark F. Adams $     MatCoarsenSetType(agg,"my_agg")
1436b43b03e9SMark F. Adams    or at runtime via the option
1437b43b03e9SMark F. Adams $     -mat_coarsen_type my_agg
1438b43b03e9SMark F. Adams 
1439b43b03e9SMark F. Adams    $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
1440b43b03e9SMark F. Adams 
1441b43b03e9SMark F. Adams .keywords: matrix, coarsen, register
1442b43b03e9SMark F. Adams 
1443b43b03e9SMark F. Adams .seealso: MatCoarsenRegisterDestroy(), MatCoarsenRegisterAll()
1444b43b03e9SMark F. Adams M*/
1445b43b03e9SMark F. Adams #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1446b43b03e9SMark F. Adams #define MatCoarsenRegisterDynamic(a,b,c,d) MatCoarsenRegister(a,b,c,0)
1447b43b03e9SMark F. Adams #else
1448b43b03e9SMark F. Adams #define MatCoarsenRegisterDynamic(a,b,c,d) MatCoarsenRegister(a,b,c,d)
1449b43b03e9SMark F. Adams #endif
1450b43b03e9SMark F. Adams 
1451014dd563SJed Brown PETSC_EXTERN PetscBool MatCoarsenRegisterAllCalled;
1452b43b03e9SMark F. Adams 
1453014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenRegisterAll(const char[]);
1454014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenRegisterDestroy(void);
1455b43b03e9SMark F. Adams 
1456014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenView(MatCoarsen,PetscViewer);
1457014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenSetFromOptions(MatCoarsen);
1458014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCoarsenGetType(MatCoarsen,const MatCoarsenType*);
1459b43b03e9SMark F. Adams 
1460b43b03e9SMark F. Adams 
1461014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMeshToVertexGraph(Mat,PetscInt,Mat*);
1462014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMeshToCellGraph(Mat,PetscInt,Mat*);
1463591294e4SBarry Smith 
14640752156aSBarry Smith /*
14650a835dfdSSatish Balay     If you add entries here you must also add them to finclude/petscmat.h
1466d4fbbf0eSBarry Smith */
14671c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0,
14681c1c02c0SLois Curfman McInnes                MATOP_GET_ROW=1,
14691c1c02c0SLois Curfman McInnes                MATOP_RESTORE_ROW=2,
14701c1c02c0SLois Curfman McInnes                MATOP_MULT=3,
14711c1c02c0SLois Curfman McInnes                MATOP_MULT_ADD=4,
14727c922b88SBarry Smith                MATOP_MULT_TRANSPOSE=5,
14737c922b88SBarry Smith                MATOP_MULT_TRANSPOSE_ADD=6,
14741c1c02c0SLois Curfman McInnes                MATOP_SOLVE=7,
14751c1c02c0SLois Curfman McInnes                MATOP_SOLVE_ADD=8,
14767c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE=9,
14777c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE_ADD=10,
14781c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR=11,
14791c1c02c0SLois Curfman McInnes                MATOP_CHOLESKYFACTOR=12,
1480a714c06dSBarry Smith                MATOP_SOR=13,
14811c1c02c0SLois Curfman McInnes                MATOP_TRANSPOSE=14,
14821c1c02c0SLois Curfman McInnes                MATOP_GETINFO=15,
14831c1c02c0SLois Curfman McInnes                MATOP_EQUAL=16,
14841c1c02c0SLois Curfman McInnes                MATOP_GET_DIAGONAL=17,
14851c1c02c0SLois Curfman McInnes                MATOP_DIAGONAL_SCALE=18,
14861c1c02c0SLois Curfman McInnes                MATOP_NORM=19,
14871c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_BEGIN=20,
14881c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_END=21,
1489d519adbfSMatthew Knepley                MATOP_SET_OPTION=22,
1490d519adbfSMatthew Knepley                MATOP_ZERO_ENTRIES=23,
1491d519adbfSMatthew Knepley                MATOP_ZERO_ROWS=24,
1492d519adbfSMatthew Knepley                MATOP_LUFACTOR_SYMBOLIC=25,
1493d519adbfSMatthew Knepley                MATOP_LUFACTOR_NUMERIC=26,
1494d519adbfSMatthew Knepley                MATOP_CHOLESKY_FACTOR_SYMBOLIC=27,
1495d519adbfSMatthew Knepley                MATOP_CHOLESKY_FACTOR_NUMERIC=28,
1496d519adbfSMatthew Knepley                MATOP_SETUP_PREALLOCATION=29,
1497d519adbfSMatthew Knepley                MATOP_ILUFACTOR_SYMBOLIC=30,
1498d519adbfSMatthew Knepley                MATOP_ICCFACTOR_SYMBOLIC=31,
1499d519adbfSMatthew Knepley                MATOP_GET_ARRAY=32,
1500d519adbfSMatthew Knepley                MATOP_RESTORE_ARRAY=33,
1501d519adbfSMatthew Knepley                MATOP_DUPLICATE=34,
1502d519adbfSMatthew Knepley                MATOP_FORWARD_SOLVE=35,
1503d519adbfSMatthew Knepley                MATOP_BACKWARD_SOLVE=36,
1504d519adbfSMatthew Knepley                MATOP_ILUFACTOR=37,
1505d519adbfSMatthew Knepley                MATOP_ICCFACTOR=38,
1506d519adbfSMatthew Knepley                MATOP_AXPY=39,
1507d519adbfSMatthew Knepley                MATOP_GET_SUBMATRICES=40,
1508d519adbfSMatthew Knepley                MATOP_INCREASE_OVERLAP=41,
1509d519adbfSMatthew Knepley                MATOP_GET_VALUES=42,
1510d519adbfSMatthew Knepley                MATOP_COPY=43,
1511d519adbfSMatthew Knepley                MATOP_GET_ROW_MAX=44,
1512d519adbfSMatthew Knepley                MATOP_SCALE=45,
1513d519adbfSMatthew Knepley                MATOP_SHIFT=46,
151435153367SBarry Smith                MATOP_DIAGONAL_SET=47,
1515d519adbfSMatthew Knepley                MATOP_ILUDT_FACTOR=48,
1516d519adbfSMatthew Knepley                MATOP_SET_BLOCK_SIZE=49,
1517d519adbfSMatthew Knepley                MATOP_GET_ROW_IJ=50,
1518d519adbfSMatthew Knepley                MATOP_RESTORE_ROW_IJ=51,
1519d519adbfSMatthew Knepley                MATOP_GET_COLUMN_IJ=52,
1520d519adbfSMatthew Knepley                MATOP_RESTORE_COLUMN_IJ=53,
1521d519adbfSMatthew Knepley                MATOP_FDCOLORING_CREATE=54,
1522d519adbfSMatthew Knepley                MATOP_COLORING_PATCH=55,
1523d519adbfSMatthew Knepley                MATOP_SET_UNFACTORED=56,
1524d519adbfSMatthew Knepley                MATOP_PERMUTE=57,
1525d519adbfSMatthew Knepley                MATOP_SET_VALUES_BLOCKED=58,
1526d519adbfSMatthew Knepley                MATOP_GET_SUBMATRIX=59,
1527d519adbfSMatthew Knepley                MATOP_DESTROY=60,
1528d519adbfSMatthew Knepley                MATOP_VIEW=61,
1529d519adbfSMatthew Knepley                MATOP_CONVERT_FROM=62,
1530d519adbfSMatthew Knepley                MATOP_USE_SCALED_FORM=63,
1531d519adbfSMatthew Knepley                MATOP_SCALE_SYSTEM=64,
1532d519adbfSMatthew Knepley                MATOP_UNSCALE_SYSTEM=65,
1533d519adbfSMatthew Knepley                MATOP_SET_LOCAL_TO_GLOBAL_MAP=66,
1534d519adbfSMatthew Knepley                MATOP_SET_VALUES_LOCAL=67,
1535d519adbfSMatthew Knepley                MATOP_ZERO_ROWS_LOCAL=68,
1536d519adbfSMatthew Knepley                MATOP_GET_ROW_MAX_ABS=69,
1537d519adbfSMatthew Knepley                MATOP_GET_ROW_MIN_ABS=70,
1538d519adbfSMatthew Knepley                MATOP_CONVERT=71,
1539d519adbfSMatthew Knepley                MATOP_SET_COLORING=72,
1540d519adbfSMatthew Knepley                MATOP_SET_VALUES_ADIC=73,
1541d519adbfSMatthew Knepley                MATOP_SET_VALUES_ADIFOR=74,
1542d519adbfSMatthew Knepley                MATOP_FD_COLORING_APPLY=75,
1543d519adbfSMatthew Knepley                MATOP_SET_FROM_OPTIONS=76,
1544d519adbfSMatthew Knepley                MATOP_MULT_CON=77,
1545d519adbfSMatthew Knepley                MATOP_MULT_TRANSPOSE_CON=78,
1546d519adbfSMatthew Knepley                MATOP_PERMUTE_SPARSIFY=79,
1547d519adbfSMatthew Knepley                MATOP_MULT_MULTIPLE=80,
1548d519adbfSMatthew Knepley                MATOP_SOLVE_MULTIPLE=81,
1549d519adbfSMatthew Knepley                MATOP_GET_INERTIA=82,
1550d519adbfSMatthew Knepley                MATOP_LOAD=83,
1551d519adbfSMatthew Knepley                MATOP_IS_SYMMETRIC=84,
1552d519adbfSMatthew Knepley                MATOP_IS_HERMITIAN=85,
1553d519adbfSMatthew Knepley                MATOP_IS_STRUCTURALLY_SYMMETRIC=86,
155441f059aeSBarry Smith                MATOP_DUMMY=87,
1555d519adbfSMatthew Knepley                MATOP_GET_VECS=88,
1556d519adbfSMatthew Knepley                MATOP_MAT_MULT=89,
1557d519adbfSMatthew Knepley                MATOP_MAT_MULT_SYMBOLIC=90,
1558d519adbfSMatthew Knepley                MATOP_MAT_MULT_NUMERIC=91,
1559d519adbfSMatthew Knepley                MATOP_PTAP=92,
1560d519adbfSMatthew Knepley                MATOP_PTAP_SYMBOLIC=93,
1561d519adbfSMatthew Knepley                MATOP_PTAP_NUMERIC=94,
1562d519adbfSMatthew Knepley                MATOP_MAT_MULTTRANSPOSE=95,
15631763ac4eSSatish Balay                MATOP_MAT_MULTTRANSPOSE_SYM=96,
15641763ac4eSSatish Balay                MATOP_MAT_MULTTRANSPOSE_NUM=97,
1565d519adbfSMatthew Knepley                MATOP_PTAP_SYMBOLIC_SEQAIJ=98,
1566d519adbfSMatthew Knepley                MATOP_PTAP_NUMERIC_SEQAIJ=99,
1567d519adbfSMatthew Knepley                MATOP_PTAP_SYMBOLIC_MPIAIJ=100,
1568d519adbfSMatthew Knepley                MATOP_PTAP_NUMERIC_MPIAIJ=101,
1569d519adbfSMatthew Knepley                MATOP_CONJUGATE=102,
1570d519adbfSMatthew Knepley                MATOP_SET_SIZES=103,
1571d519adbfSMatthew Knepley                MATOP_SET_VALUES_ROW=104,
1572d519adbfSMatthew Knepley                MATOP_REAL_PART=105,
1573d519adbfSMatthew Knepley                MATOP_IMAG_PART=106,
1574d519adbfSMatthew Knepley                MATOP_GET_ROW_UTRIANGULAR=107,
1575d519adbfSMatthew Knepley                MATOP_RESTORE_ROW_UTRIANGULAR=108,
1576d519adbfSMatthew Knepley                MATOP_MATSOLVE=109,
1577d519adbfSMatthew Knepley                MATOP_GET_REDUNDANTMATRIX=110,
1578d519adbfSMatthew Knepley                MATOP_GET_ROW_MIN=111,
1579d519adbfSMatthew Knepley                MATOP_GET_COLUMN_VEC=112,
1580d519adbfSMatthew Knepley                MATOP_MISSING_DIAGONAL=113,
1581d519adbfSMatthew Knepley                MATOP_MATGETSEQNONZEROSTRUCTURE=114,
158289c6957cSBarry Smith                MATOP_CREATE=115,
158389c6957cSBarry Smith                MATOP_GET_GHOSTS=116,
1584ea38565cSJed Brown                MATOP_GET_LOCALSUBMATRIX=117,
1585ea38565cSJed Brown                MATOP_RESTORE_LOCALSUBMATRIX=118,
1586eeffb40dSHong Zhang                MATOP_MULT_DIAGONAL_BLOCK=119,
1587547795f9SHong Zhang                MATOP_HERMITIANTRANSPOSE=120,
1588547795f9SHong Zhang                MATOP_MULTHERMITIANTRANSPOSE=121,
1589fbdbba38SShri Abhyankar                MATOP_MULTHERMITIANTRANSPOSEADD=122,
1590b9614d88SDmitry Karpeev                MATOP_GETMULTIPROCBLOCK=123,
15910716a85fSBarry Smith                MATOP_GETCOLUMNNORMS=125,
159237868618SMatthew G Knepley 	       MATOP_GET_SUBMATRICES_PARALLEL=128,
15932b8ad9a3SHong Zhang                MATOP_SET_VALUES_BATCH=129,
15942b8ad9a3SHong Zhang                MATOP_TRANSPOSEMATMULT=130,
15952b8ad9a3SHong Zhang                MATOP_TRANSPOSEMATMULT_SYMBOLIC=131,
15962b8ad9a3SHong Zhang                MATOP_TRANSPOSEMATMULT_NUMERIC=132,
15972b8ad9a3SHong Zhang                MATOP_TRANSPOSECOLORING_CREATE=133,
15982b8ad9a3SHong Zhang                MATOP_TRANSCOLORING_APPLY_SPTODEN=134,
15992b8ad9a3SHong Zhang                MATOP_TRANSCOLORING_APPLY_DENTOSP=135,
16002b8ad9a3SHong Zhang                MATOP_RARt=136,
16012b8ad9a3SHong Zhang                MATOP_RARt_SYMBOLIC=137,
16022274620bSMark F. Adams                MATOP_RARt_NUMERIC=138,
16032274620bSMark F. Adams                MATOP_SET_BLOCK_SIZES=139
1604fae171e0SBarry Smith              } MatOperation;
1605014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatHasOperation(Mat,MatOperation,PetscBool *);
1606014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat,MatOperation,void(*)(void));
1607014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat,MatOperation,void(**)(void));
1608014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat,void*);
1609112a2221SBarry Smith 
161090ace30eSBarry Smith /*
161190ace30eSBarry Smith    Codes for matrices stored on disk. By default they are
161290ace30eSBarry Smith    stored in a universal format. By changing the format with
16137973ad04SBarry Smith    PetscViewerSetFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will
161490ace30eSBarry Smith    be stored in a way natural for the matrix, for example dense matrices
161590ace30eSBarry Smith    would be stored as dense. Matrices stored this way may only be
1616f4403165SShri Abhyankar    read into matrices of the same type.
161790ace30eSBarry Smith */
161890ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1
161990ace30eSBarry Smith 
1620014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat,PetscReal);
1621014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat,Mat*);
1622014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat,Mat);
16231f4e1ec7SBarry Smith 
1624d9274352SBarry Smith /*S
1625d9274352SBarry Smith      MatNullSpace - Object that removes a null space from a vector, i.e.
1626d9274352SBarry Smith          orthogonalizes the vector to a subsapce
1627d9274352SBarry Smith 
1628f7a9e4ceSBarry Smith    Level: advanced
1629d9274352SBarry Smith 
1630d9274352SBarry Smith   Concepts: matrix; linear operator, null space
1631d9274352SBarry Smith 
16326e1639daSBarry Smith   Users manual sections:
16336e1639daSBarry Smith .   sec_singular
16346e1639daSBarry Smith 
1635d9274352SBarry Smith .seealso:  MatNullSpaceCreate()
1636d9274352SBarry Smith S*/
163774637425SBarry Smith typedef struct _p_MatNullSpace* MatNullSpace;
1638d9274352SBarry Smith 
1639014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm,PetscBool ,PetscInt,const Vec[],MatNullSpace*);
1640014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace,PetscErrorCode (*)(MatNullSpace,Vec,void*),void*);
1641014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace*);
1642014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace,Vec,Vec*);
1643014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *);
1644014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat,MatNullSpace);
1645014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat,MatNullSpace);
1646014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat,MatNullSpace*);
1647014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace,Mat,PetscBool  *);
1648014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace,PetscViewer);
1649014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace,PetscBool*,PetscInt*,const Vec**);
1650014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec,MatNullSpace*);
165174637425SBarry Smith 
1652014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat,IS);
1653014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat,PetscReal);
1654014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat,PetscInt *);
1655014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSeqBAIJInvertBlockDiagonal(Mat);
16563f1d51d7SBarry Smith 
1657014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat,PetscInt,Mat*);
1658014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat,PetscInt,Mat*);
1659014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat,Mat*);
1660c4f061fbSSatish Balay 
1661014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatComputeExplicitOperator(Mat,Mat*);
1662b0a32e0cSBarry Smith 
1663014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat,Vec);
166404f1ad80SBarry Smith 
1665014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,Mat*);
1666014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat,Vec,Vec);
1667014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat,PetscErrorCode(*)(void*,Vec,Vec),void*);
1668014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat,PetscErrorCode (*)(void*,PetscInt,Vec,PetscScalar*));
1669014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat,PetscErrorCode (*)(void*,Vec));
1670014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDAddNullSpace(Mat,MatNullSpace);
1671014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat,PetscScalar[],PetscInt);
1672014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat);
1673014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat,PetscReal);
1674014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat,PetscInt);
1675014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat,PetscScalar *);
1676014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat,const char[]);
1677014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void*,Vec,Vec,PetscScalar*);
1678014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat,PetscErrorCode (*)(void*,Vec,Vec,PetscScalar*),void*);
1679e884886fSBarry Smith 
16806370053bSBarry Smith /*S
16816370053bSBarry Smith     MatMFFD - A data structured used to manage the computation of the h differencing parameter for matrix-free
16826370053bSBarry Smith               Jacobian vector products
1683e884886fSBarry Smith 
16846370053bSBarry Smith     Notes: MATMFFD is a specific MatType which uses the MatMFFD data structure
16856370053bSBarry Smith 
16866370053bSBarry Smith            MatMFFD*() methods actually take the Mat as their first argument. Not a MatMFFD data structure
16876370053bSBarry Smith 
16886370053bSBarry Smith     Level: developer
16896370053bSBarry Smith 
16906370053bSBarry Smith .seealso: MATMFFD, MatCreateMFFD(), MatMFFDSetFuction(), MatMFFDSetType(), MatMFFDRegister()
16916370053bSBarry Smith S*/
1692e884886fSBarry Smith typedef struct _p_MatMFFD* MatMFFD;
1693e884886fSBarry Smith 
169476bdecfbSBarry Smith /*J
1695e884886fSBarry Smith     MatMFFDType - algorithm used to compute the h used in computing matrix-vector products via differencing of the function
1696e884886fSBarry Smith 
1697e884886fSBarry Smith    Level: beginner
1698e884886fSBarry Smith 
1699e884886fSBarry Smith .seealso: MatMFFDSetType(), MatMFFDRegister()
170076bdecfbSBarry Smith J*/
1701a313700dSBarry Smith #define MatMFFDType char*
1702e884886fSBarry Smith #define MATMFFD_DS  "ds"
1703e884886fSBarry Smith #define MATMFFD_WP  "wp"
1704e884886fSBarry Smith 
1705014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDSetType(Mat,const MatMFFDType);
1706014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDRegister(const char[],const char[],const char[],PetscErrorCode (*)(MatMFFD));
1707e884886fSBarry Smith 
1708e884886fSBarry Smith /*MC
1709e884886fSBarry Smith    MatMFFDRegisterDynamic - Adds a method to the MatMFFD registry.
1710e884886fSBarry Smith 
1711e884886fSBarry Smith    Synopsis:
17121890ba74SBarry Smith    PetscErrorCode MatMFFDRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(MatMFFD))
1713e884886fSBarry Smith 
1714e884886fSBarry Smith    Not Collective
1715e884886fSBarry Smith 
1716e884886fSBarry Smith    Input Parameters:
1717e884886fSBarry Smith +  name_solver - name of a new user-defined compute-h module
1718e884886fSBarry Smith .  path - path (either absolute or relative) the library containing this solver
1719e884886fSBarry Smith .  name_create - name of routine to create method context
1720e884886fSBarry Smith -  routine_create - routine to create method context
1721e884886fSBarry Smith 
1722e884886fSBarry Smith    Level: developer
1723e884886fSBarry Smith 
1724e884886fSBarry Smith    Notes:
1725e884886fSBarry Smith    MatMFFDRegisterDynamic() may be called multiple times to add several user-defined solvers.
1726e884886fSBarry Smith 
1727e884886fSBarry Smith    If dynamic libraries are used, then the fourth input argument (routine_create)
1728e884886fSBarry Smith    is ignored.
1729e884886fSBarry Smith 
1730e884886fSBarry Smith    Sample usage:
1731e884886fSBarry Smith .vb
1732e884886fSBarry Smith    MatMFFDRegisterDynamic("my_h",/home/username/my_lib/lib/libO/solaris/mylib.a,
1733e884886fSBarry Smith                "MyHCreate",MyHCreate);
1734e884886fSBarry Smith .ve
1735e884886fSBarry Smith 
1736e884886fSBarry Smith    Then, your solver can be chosen with the procedural interface via
1737e884886fSBarry Smith $     MatMFFDSetType(mfctx,"my_h")
1738e884886fSBarry Smith    or at runtime via the option
1739e884886fSBarry Smith $     -snes_mf_type my_h
1740e884886fSBarry Smith 
1741e884886fSBarry Smith .keywords: MatMFFD, register
1742e884886fSBarry Smith 
1743e884886fSBarry Smith .seealso: MatMFFDRegisterAll(), MatMFFDRegisterDestroy()
1744e884886fSBarry Smith M*/
1745e884886fSBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1746e884886fSBarry Smith #define MatMFFDRegisterDynamic(a,b,c,d) MatMFFDRegister(a,b,c,0)
1747e884886fSBarry Smith #else
1748e884886fSBarry Smith #define MatMFFDRegisterDynamic(a,b,c,d) MatMFFDRegister(a,b,c,d)
1749e884886fSBarry Smith #endif
1750e884886fSBarry Smith 
1751014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDRegisterAll(const char[]);
1752014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDRegisterDestroy(void);
1753014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat,PetscReal);
1754014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat,PetscBool );
1755e884886fSBarry Smith 
1756e884886fSBarry Smith 
1757014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
1758014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);
17597dbadf16SMatthew Knepley 
176097969023SHong Zhang /*
176197969023SHong Zhang    PETSc interface to MUMPS
176297969023SHong Zhang */
176397969023SHong Zhang #ifdef PETSC_HAVE_MUMPS
1764014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat,PetscInt,PetscInt);
176597969023SHong Zhang #endif
176623a5497aSJed Brown 
1767d954db57SHong Zhang /*
1768d954db57SHong Zhang    PETSc interface to SUPERLU
1769d954db57SHong Zhang */
1770d954db57SHong Zhang #ifdef PETSC_HAVE_SUPERLU
1771014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat,PetscReal);
1772d954db57SHong Zhang #endif
1773d954db57SHong Zhang 
177490c53902SBarry Smith #if defined(PETSC_HAVE_CUSP)
1775014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSP(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
1776014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateAIJCUSP(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
177790c53902SBarry Smith #endif
177890c53902SBarry Smith 
177954efbe56SHong Zhang /*
178054efbe56SHong Zhang    PETSc interface to FFTW
178154efbe56SHong Zhang */
178254efbe56SHong Zhang #if defined(PETSC_HAVE_FFTW)
1783014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat,Vec,Vec);
1784014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat,Vec,Vec);
1785014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatGetVecsFFTW(Mat,Vec*,Vec*,Vec*);
178654efbe56SHong Zhang #endif
178754efbe56SHong Zhang 
1788014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm,PetscInt,const IS[],PetscInt,const IS[],const Mat[],Mat*);
1789014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat,PetscInt*,PetscInt*);
1790014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat,IS[],IS[]);
1791014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat,IS[],IS[]);
1792014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat,PetscInt*,PetscInt*,Mat***);
1793014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat,PetscInt,PetscInt,Mat*);
1794014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat,const VecType);
1795014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat,PetscInt,const IS[],PetscInt,const IS[],const Mat[]);
1796014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat,PetscInt,PetscInt,Mat);
1797d8588912SDave May 
179815c1f1baSDmitry Karpeev /*
179915c1f1baSDmitry Karpeev  MatIJ:
180015c1f1baSDmitry Karpeev  An unweighted directed pseudograph
180115c1f1baSDmitry Karpeev  An interpretation of this matrix as a (pseudo)graph allows us to define additional operations on it:
180215c1f1baSDmitry Karpeev  A MatIJ can act on sparse arrays: arrays of indices, or index arrays of integers, scalars, or integer-scalar pairs
180315c1f1baSDmitry Karpeev  by mapping the indices to the indices connected to them by the (pseudo)graph ed
180415c1f1baSDmitry Karpeev  */
180515c1f1baSDmitry Karpeev typedef enum {MATIJ_LOCAL, MATIJ_GLOBAL} MatIJIndexType;
1806014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJSetMultivalued(Mat, PetscBool);
1807014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetMultivalued(Mat, PetscBool*);
1808014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJSetEdges(Mat, PetscInt, const PetscInt*, const PetscInt*);
1809014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetEdges(Mat, PetscInt *, PetscInt **, PetscInt **);
1810014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJSetEdgesIS(Mat, IS, IS);
1811014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetEdgesIS(Mat, IS*, IS*);
1812014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetRowSizes(Mat, MatIJIndexType, PetscInt, const PetscInt *, PetscInt **);
1813014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetMinRowSize(Mat, PetscInt *);
1814014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetMaxRowSize(Mat, PetscInt *);
1815014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetSupport(Mat,  PetscInt *, PetscInt **);
1816014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetSupportIS(Mat, IS *);
1817014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetImage(Mat, PetscInt*, PetscInt**);
1818014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetImageIS(Mat, IS *);
1819014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetSupportSize(Mat, PetscInt *);
1820014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJGetImageSize(Mat, PetscInt *);
182115c1f1baSDmitry Karpeev 
1822014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJBinRenumber(Mat, Mat*);
182315c1f1baSDmitry Karpeev 
1824014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJMap(Mat, MatIJIndexType, PetscInt,const PetscInt*,const PetscInt*,const PetscScalar*, MatIJIndexType,PetscInt*,PetscInt**,PetscInt**,PetscScalar**,PetscInt**);
1825014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJBin(Mat, MatIJIndexType, PetscInt,const PetscInt*,const PetscInt*,const PetscScalar*,PetscInt*,PetscInt**,PetscInt**,PetscScalar**,PetscInt**);
1826014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatIJBinMap(Mat,Mat, MatIJIndexType,PetscInt,const PetscInt*,const PetscInt*,const PetscScalar*,MatIJIndexType,PetscInt*,PetscInt**,PetscInt**,PetscScalar**,PetscInt**);
182715c1f1baSDmitry Karpeev 
182823a5497aSJed Brown #endif
1829