xref: /petsc/include/petscmat.h (revision ae5cfb4a3679d07b6904bd2c794eee8dc00ed47b)
1 /*
2      Include file for the matrix component of PETSc
3 */
4 #ifndef __PETSCMAT_H
5 #define __PETSCMAT_H
6 #include <petscvec.h>
7 
8 /*S
9      Mat - Abstract PETSc matrix object used to manage all linear operators in PETSc, even those without
10            an explicit sparse representation (such as matrix-free operators)
11 
12    Level: beginner
13 
14   Concepts: matrix; linear operator
15 
16 .seealso:  MatCreate(), MatType, MatSetType(), MatDestroy()
17 S*/
18 typedef struct _p_Mat*           Mat;
19 
20 /*J
21     MatType - String with the name of a PETSc matrix type
22 
23    Level: beginner
24 
25 .seealso: MatSetType(), Mat, MatSolverPackage, MatRegister()
26 J*/
27 typedef const char* MatType;
28 #define MATSAME            "same"
29 #define MATMAIJ            "maij"
30 #define MATSEQMAIJ         "seqmaij"
31 #define MATMPIMAIJ         "mpimaij"
32 #define MATIS              "is"
33 #define MATAIJ             "aij"
34 #define MATSEQAIJ          "seqaij"
35 #define MATSEQAIJPTHREAD   "seqaijpthread"
36 #define MATAIJPTHREAD      "aijpthread"
37 #define MATMPIAIJ          "mpiaij"
38 #define MATAIJCRL          "aijcrl"
39 #define MATSEQAIJCRL       "seqaijcrl"
40 #define MATMPIAIJCRL       "mpiaijcrl"
41 #define MATAIJCUSP         "aijcusp"
42 #define MATSEQAIJCUSP      "seqaijcusp"
43 #define MATMPIAIJCUSP      "mpiaijcusp"
44 #define MATAIJCUSPARSE     "aijcusparse"
45 #define MATSEQAIJCUSPARSE  "seqaijcusparse"
46 #define MATMPIAIJCUSPARSE  "mpiaijcusparse"
47 #define MATAIJVIENNACL     "aijviennacl"
48 #define MATSEQAIJVIENNACL  "seqaijviennacl"
49 #define MATMPIAIJVIENNACL  "mpiaijviennacl"
50 #define MATAIJPERM         "aijperm"
51 #define MATSEQAIJPERM      "seqaijperm"
52 #define MATMPIAIJPERM      "mpiaijperm"
53 #define MATSHELL           "shell"
54 #define MATDENSE           "dense"
55 #define MATSEQDENSE        "seqdense"
56 #define MATMPIDENSE        "mpidense"
57 #define MATELEMENTAL       "elemental"
58 #define MATBAIJ            "baij"
59 #define MATSEQBAIJ         "seqbaij"
60 #define MATMPIBAIJ         "mpibaij"
61 #define MATMPIADJ          "mpiadj"
62 #define MATSBAIJ           "sbaij"
63 #define MATSEQSBAIJ        "seqsbaij"
64 #define MATMPISBAIJ        "mpisbaij"
65 #define MATSEQBSTRM        "seqbstrm"
66 #define MATMPIBSTRM        "mpibstrm"
67 #define MATBSTRM           "bstrm"
68 #define MATSEQSBSTRM       "seqsbstrm"
69 #define MATMPISBSTRM       "mpisbstrm"
70 #define MATSBSTRM          "sbstrm"
71 #define MATDAAD            "daad"
72 #define MATMFFD            "mffd"
73 #define MATNORMAL          "normal"
74 #define MATLRC             "lrc"
75 #define MATSCATTER         "scatter"
76 #define MATBLOCKMAT        "blockmat"
77 #define MATCOMPOSITE       "composite"
78 #define MATFFT             "fft"
79 #define MATFFTW            "fftw"
80 #define MATSEQCUFFT        "seqcufft"
81 #define MATTRANSPOSEMAT    "transpose"
82 #define MATSCHURCOMPLEMENT "schurcomplement"
83 #define MATPYTHON          "python"
84 #define MATHYPRESTRUCT     "hyprestruct"
85 #define MATHYPRESSTRUCT    "hypresstruct"
86 #define MATSUBMATRIX       "submatrix"
87 #define MATLOCALREF        "localref"
88 #define MATNEST            "nest"
89 
90 /*J
91     MatSolverPackage - String with the name of a PETSc matrix solver type.
92 
93     For example: "petsc" indicates what PETSc provides, "superlu" indicates either
94        SuperLU or SuperLU_Dist etc.
95 
96 
97    Level: beginner
98 
99 .seealso: MatGetFactor(), Mat, MatSetType(), MatType
100 J*/
101 #define MatSolverPackage char*
102 #define MATSOLVERSUPERLU      "superlu"
103 #define MATSOLVERSUPERLU_DIST "superlu_dist"
104 #define MATSOLVERUMFPACK      "umfpack"
105 #define MATSOLVERCHOLMOD      "cholmod"
106 #define MATSOLVERESSL         "essl"
107 #define MATSOLVERLUSOL        "lusol"
108 #define MATSOLVERMUMPS        "mumps"
109 #define MATSOLVERMKL_PARDISO  "mkl_pardiso"
110 #define MATSOLVERMKL_CPARDISO "mkl_cpardiso"
111 #define MATSOLVERPASTIX       "pastix"
112 #define MATSOLVERMATLAB       "matlab"
113 #define MATSOLVERPETSC        "petsc"
114 #define MATSOLVERBAS          "bas"
115 #define MATSOLVERCUSPARSE     "cusparse"
116 #define MATSOLVERBSTRM        "bstrm"
117 #define MATSOLVERSBSTRM       "sbstrm"
118 #define MATSOLVERELEMENTAL    "elemental"
119 #define MATSOLVERCLIQUE       "clique"
120 #define MATSOLVERKLU          "klu"
121 
122 /*E
123     MatFactorType - indicates what type of factorization is requested
124 
125     Level: beginner
126 
127    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
128 
129 .seealso: MatSolverPackage, MatGetFactor()
130 E*/
131 typedef enum {MAT_FACTOR_NONE, MAT_FACTOR_LU, MAT_FACTOR_CHOLESKY, MAT_FACTOR_ILU, MAT_FACTOR_ICC,MAT_FACTOR_ILUDT} MatFactorType;
132 PETSC_EXTERN const char *const MatFactorTypes[];
133 
134 PETSC_EXTERN PetscErrorCode MatGetFactor(Mat,const MatSolverPackage,MatFactorType,Mat*);
135 PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat,const MatSolverPackage,MatFactorType,PetscBool *);
136 PETSC_EXTERN PetscErrorCode MatFactorGetSolverPackage(Mat,const MatSolverPackage*);
137 PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat,MatFactorType*);
138 PETSC_EXTERN PetscErrorCode MatSolverPackageRegister(const MatSolverPackage,const MatType,MatFactorType,PetscErrorCode(*)(Mat,MatFactorType,Mat*));
139 PETSC_EXTERN PetscErrorCode MatSolverPackageGet(const MatSolverPackage,const MatType,MatFactorType,PetscBool*,PetscBool*,PetscErrorCode (**)(Mat,MatFactorType,Mat*));
140 
141 /* Logging support */
142 #define    MAT_FILE_CLASSID 1211216    /* used to indicate matrices in binary files */
143 PETSC_EXTERN PetscClassId MAT_CLASSID;
144 PETSC_EXTERN PetscClassId MAT_COLORING_CLASSID;
145 PETSC_EXTERN PetscClassId MAT_FDCOLORING_CLASSID;
146 PETSC_EXTERN PetscClassId MAT_TRANSPOSECOLORING_CLASSID;
147 PETSC_EXTERN PetscClassId MAT_PARTITIONING_CLASSID;
148 PETSC_EXTERN PetscClassId MAT_COARSEN_CLASSID;
149 PETSC_EXTERN PetscClassId MAT_NULLSPACE_CLASSID;
150 PETSC_EXTERN PetscClassId MATMFFD_CLASSID;
151 
152 /*E
153     MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices()
154      or MatGetSubMatrix() are to be reused to store the new matrix values. For MatConvert() is used to indicate
155      that the input matrix is to be replaced with the converted matrix.
156 
157     Level: beginner
158 
159    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
160 
161 .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices(), MatConvert()
162 E*/
163 typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX,MAT_IGNORE_MATRIX} MatReuse;
164 
165 /*E
166     MatGetSubMatrixOption - Indicates if matrices obtained from a call to MatGetSubMatrices()
167      include the matrix values. Currently it is only used by MatGetSeqNonzerostructure().
168 
169     Level: beginner
170 
171 .seealso: MatGetSeqNonzerostructure()
172 E*/
173 typedef enum {MAT_DO_NOT_GET_VALUES,MAT_GET_VALUES} MatGetSubMatrixOption;
174 
175 PETSC_EXTERN PetscErrorCode MatInitializePackage(void);
176 
177 PETSC_EXTERN PetscErrorCode MatCreate(MPI_Comm,Mat*);
178 PETSC_EXTERN PetscErrorCode MatSetSizes(Mat,PetscInt,PetscInt,PetscInt,PetscInt);
179 PETSC_EXTERN PetscErrorCode MatSetType(Mat,MatType);
180 PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat);
181 PETSC_STATIC_INLINE PetscErrorCode MatViewFromOptions(Mat A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
182 PETSC_EXTERN PetscErrorCode MatRegisterAll(void);
183 PETSC_EXTERN PetscErrorCode MatRegister(const char[],PetscErrorCode(*)(Mat));
184 PETSC_EXTERN PetscErrorCode MatRegisterBaseName(const char[],const char[],const char[]);
185 PETSC_EXTERN PetscErrorCode MatSetOptionsPrefix(Mat,const char[]);
186 PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefix(Mat,const char[]);
187 PETSC_EXTERN PetscErrorCode MatGetOptionsPrefix(Mat,const char*[]);
188 
189 PETSC_EXTERN PetscBool         MatRegisterAllCalled;
190 PETSC_EXTERN PetscFunctionList MatList;
191 PETSC_EXTERN PetscFunctionList MatColoringList;
192 PETSC_EXTERN PetscFunctionList MatPartitioningList;
193 PETSC_EXTERN PetscFunctionList MatCoarsenList;
194 
195 /*E
196     MatStructure - Indicates if two matrices have the same nonzero structure
197 
198     Level: beginner
199 
200    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
201 
202 .seealso: MatCopy(), MatAXPY()
203 E*/
204 typedef enum {DIFFERENT_NONZERO_PATTERN,SUBSET_NONZERO_PATTERN,SAME_NONZERO_PATTERN} MatStructure;
205 
206 PETSC_EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm,PetscInt,PetscInt,PetscScalar[],Mat*);
207 PETSC_EXTERN PetscErrorCode MatCreateDense(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar[],Mat*);
208 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
209 PETSC_EXTERN PetscErrorCode MatCreateAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
210 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat *);
211 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSplitArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],PetscInt[],PetscInt[],PetscScalar[],Mat*);
212 
213 PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
214 PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
215 PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat*);
216 
217 PETSC_EXTERN PetscErrorCode MatCreateMPIAdj(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscInt[],Mat*);
218 PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
219 
220 PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
221 PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],Mat *);
222 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
223 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
224 PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],const PetscInt[]);
225 
226 PETSC_EXTERN PetscErrorCode MatCreateShell(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,void *,Mat*);
227 PETSC_EXTERN PetscErrorCode MatCreateNormal(Mat,Mat*);
228 PETSC_EXTERN PetscErrorCode MatCreateLRC(Mat,Mat,Mat,Mat*);
229 PETSC_EXTERN PetscErrorCode MatCreateIS(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,ISLocalToGlobalMapping,Mat*);
230 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCRL(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
231 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
232 
233 PETSC_EXTERN PetscErrorCode MatCreateSeqBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
234 PETSC_EXTERN PetscErrorCode MatCreateMPIBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
235 PETSC_EXTERN PetscErrorCode MatCreateSeqSBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
236 PETSC_EXTERN PetscErrorCode MatCreateMPISBSTRM(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
237 
238 PETSC_EXTERN PetscErrorCode MatCreateScatter(MPI_Comm,VecScatter,Mat*);
239 PETSC_EXTERN PetscErrorCode MatScatterSetVecScatter(Mat,VecScatter);
240 PETSC_EXTERN PetscErrorCode MatScatterGetVecScatter(Mat,VecScatter*);
241 PETSC_EXTERN PetscErrorCode MatCreateBlockMat(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,Mat*);
242 PETSC_EXTERN PetscErrorCode MatCompositeAddMat(Mat,Mat);
243 PETSC_EXTERN PetscErrorCode MatCompositeMerge(Mat);
244 PETSC_EXTERN PetscErrorCode MatCreateComposite(MPI_Comm,PetscInt,const Mat*,Mat*);
245 typedef enum {MAT_COMPOSITE_ADDITIVE,MAT_COMPOSITE_MULTIPLICATIVE} MatCompositeType;
246 PETSC_EXTERN PetscErrorCode MatCompositeSetType(Mat,MatCompositeType);
247 
248 PETSC_EXTERN PetscErrorCode MatCreateFFT(MPI_Comm,PetscInt,const PetscInt[],MatType,Mat*);
249 PETSC_EXTERN PetscErrorCode MatCreateSeqCUFFT(MPI_Comm,PetscInt,const PetscInt[],Mat*);
250 
251 PETSC_EXTERN PetscErrorCode MatCreateTranspose(Mat,Mat*);
252 PETSC_EXTERN PetscErrorCode MatCreateSubMatrix(Mat,IS,IS,Mat*);
253 PETSC_EXTERN PetscErrorCode MatSubMatrixUpdate(Mat,Mat,IS,IS);
254 PETSC_EXTERN PetscErrorCode MatCreateLocalRef(Mat,IS,IS,Mat*);
255 
256 PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat,const char[]);
257 
258 PETSC_EXTERN PetscErrorCode MatSetUp(Mat);
259 PETSC_EXTERN PetscErrorCode MatDestroy(Mat*);
260 PETSC_EXTERN PetscErrorCode MatGetNonzeroState(Mat,PetscObjectState*);
261 
262 PETSC_EXTERN PetscErrorCode MatConjugate(Mat);
263 PETSC_EXTERN PetscErrorCode MatRealPart(Mat);
264 PETSC_EXTERN PetscErrorCode MatImaginaryPart(Mat);
265 PETSC_EXTERN PetscErrorCode MatGetDiagonalBlock(Mat,Mat*);
266 PETSC_EXTERN PetscErrorCode MatGetTrace(Mat,PetscScalar*);
267 PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonal(Mat,const PetscScalar **);
268 
269 /* ------------------------------------------------------------*/
270 PETSC_EXTERN PetscErrorCode MatSetValues(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
271 PETSC_EXTERN PetscErrorCode MatSetValuesBlocked(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
272 PETSC_EXTERN PetscErrorCode MatSetValuesRow(Mat,PetscInt,const PetscScalar[]);
273 PETSC_EXTERN PetscErrorCode MatSetValuesRowLocal(Mat,PetscInt,const PetscScalar[]);
274 PETSC_EXTERN PetscErrorCode MatSetValuesBatch(Mat,PetscInt,PetscInt,PetscInt[],const PetscScalar[]);
275 PETSC_EXTERN PetscErrorCode MatSetRandom(Mat,PetscRandom);
276 
277 /*S
278      MatStencil - Data structure (C struct) for storing information about a single row or
279         column of a matrix as indexed on an associated grid.
280 
281    Fortran usage is different, see MatSetValuesStencil() for details.
282 
283    Level: beginner
284 
285   Concepts: matrix; linear operator
286 
287 .seealso:  MatSetValuesStencil(), MatSetStencil(), MatSetValuesBlockedStencil()
288 S*/
289 typedef struct {
290   PetscInt k,j,i,c;
291 } MatStencil;
292 
293 PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat,PetscInt,const MatStencil[],PetscInt,const MatStencil[],const PetscScalar[],InsertMode);
294 PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat,PetscInt,const MatStencil[],PetscInt,const MatStencil[],const PetscScalar[],InsertMode);
295 PETSC_EXTERN PetscErrorCode MatSetStencil(Mat,PetscInt,const PetscInt[],const PetscInt[],PetscInt);
296 
297 PETSC_EXTERN PetscErrorCode MatSetColoring(Mat,ISColoring);
298 PETSC_EXTERN PetscErrorCode MatSetValuesAdifor(Mat,PetscInt,void*);
299 
300 /*E
301     MatAssemblyType - Indicates if the matrix is now to be used, or if you plan
302      to continue to add values to it
303 
304     Level: beginner
305 
306 .seealso: MatAssemblyBegin(), MatAssemblyEnd()
307 E*/
308 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
309 PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat,MatAssemblyType);
310 PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat,MatAssemblyType);
311 PETSC_EXTERN PetscErrorCode MatAssembled(Mat,PetscBool *);
312 
313 
314 
315 /*E
316     MatOption - Options that may be set for a matrix and its behavior or storage
317 
318     Level: beginner
319 
320    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
321 
322    Developer Notes: Entries that are negative need not be called collectively by all processes.
323 
324 .seealso: MatSetOption()
325 E*/
326 typedef enum {MAT_OPTION_MIN = -5,
327               MAT_NEW_NONZERO_LOCATION_ERR = -4,
328               MAT_UNUSED_NONZERO_LOCATION_ERR = -3,
329               MAT_NEW_NONZERO_ALLOCATION_ERR = -2,
330               MAT_ROW_ORIENTED = -1,
331               MAT_SYMMETRIC = 1,
332               MAT_STRUCTURALLY_SYMMETRIC = 2,
333               MAT_NEW_DIAGONALS = 3,
334               MAT_IGNORE_OFF_PROC_ENTRIES = 4,
335               MAT_USE_HASH_TABLE = 5,
336               MAT_KEEP_NONZERO_PATTERN = 6,
337               MAT_IGNORE_ZERO_ENTRIES = 7,
338               MAT_USE_INODES = 8,
339               MAT_HERMITIAN = 9,
340               MAT_SYMMETRY_ETERNAL = 10,
341               MAT_DUMMY = 11,
342               MAT_IGNORE_LOWER_TRIANGULAR = 12,
343               MAT_ERROR_LOWER_TRIANGULAR = 13,
344               MAT_GETROW_UPPERTRIANGULAR = 14,
345               MAT_SPD = 15,
346               MAT_NO_OFF_PROC_ZERO_ROWS = 16,
347               MAT_NO_OFF_PROC_ENTRIES = 17,
348               MAT_NEW_NONZERO_LOCATIONS = 18,
349               MAT_OPTION_MAX = 19} MatOption;
350 
351 PETSC_EXTERN const char *MatOptions[];
352 PETSC_EXTERN PetscErrorCode MatSetOption(Mat,MatOption,PetscBool );
353 PETSC_EXTERN PetscErrorCode MatGetType(Mat,MatType*);
354 
355 PETSC_EXTERN PetscErrorCode MatGetValues(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscScalar[]);
356 PETSC_EXTERN PetscErrorCode MatGetRow(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
357 PETSC_EXTERN PetscErrorCode MatRestoreRow(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
358 PETSC_EXTERN PetscErrorCode MatGetRowUpperTriangular(Mat);
359 PETSC_EXTERN PetscErrorCode MatRestoreRowUpperTriangular(Mat);
360 PETSC_EXTERN PetscErrorCode MatGetColumn(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
361 PETSC_EXTERN PetscErrorCode MatRestoreColumn(Mat,PetscInt,PetscInt *,const PetscInt *[],const PetscScalar*[]);
362 PETSC_EXTERN PetscErrorCode MatGetColumnVector(Mat,Vec,PetscInt);
363 PETSC_EXTERN PetscErrorCode MatSeqAIJGetArray(Mat,PetscScalar *[]);
364 PETSC_EXTERN PetscErrorCode MatSeqAIJRestoreArray(Mat,PetscScalar *[]);
365 PETSC_EXTERN PetscErrorCode MatSeqAIJGetMaxRowNonzeros(Mat,PetscInt*);
366 PETSC_EXTERN PetscErrorCode MatSeqAIJSetValuesLocalFast(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
367 PETSC_EXTERN PetscErrorCode MatDenseGetArray(Mat,PetscScalar *[]);
368 PETSC_EXTERN PetscErrorCode MatDenseRestoreArray(Mat,PetscScalar *[]);
369 PETSC_EXTERN PetscErrorCode MatGetBlockSize(Mat,PetscInt *);
370 PETSC_EXTERN PetscErrorCode MatSetBlockSize(Mat,PetscInt);
371 PETSC_EXTERN PetscErrorCode MatGetBlockSizes(Mat,PetscInt *,PetscInt *);
372 PETSC_EXTERN PetscErrorCode MatSetBlockSizes(Mat,PetscInt,PetscInt);
373 PETSC_EXTERN PetscErrorCode MatSetBlockSizesFromMats(Mat,Mat,Mat);
374 PETSC_EXTERN PetscErrorCode MatSetNThreads(Mat,PetscInt);
375 PETSC_EXTERN PetscErrorCode MatGetNThreads(Mat,PetscInt*);
376 
377 PETSC_EXTERN PetscErrorCode MatMult(Mat,Vec,Vec);
378 PETSC_EXTERN PetscErrorCode MatMultDiagonalBlock(Mat,Vec,Vec);
379 PETSC_EXTERN PetscErrorCode MatMultAdd(Mat,Vec,Vec,Vec);
380 PETSC_EXTERN PetscErrorCode MatMultTranspose(Mat,Vec,Vec);
381 PETSC_EXTERN PetscErrorCode MatMultHermitianTranspose(Mat,Vec,Vec);
382 PETSC_EXTERN PetscErrorCode MatIsTranspose(Mat,Mat,PetscReal,PetscBool *);
383 PETSC_EXTERN PetscErrorCode MatIsHermitianTranspose(Mat,Mat,PetscReal,PetscBool *);
384 PETSC_EXTERN PetscErrorCode MatMultTransposeAdd(Mat,Vec,Vec,Vec);
385 PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAdd(Mat,Vec,Vec,Vec);
386 PETSC_EXTERN PetscErrorCode MatMultConstrained(Mat,Vec,Vec);
387 PETSC_EXTERN PetscErrorCode MatMultTransposeConstrained(Mat,Vec,Vec);
388 PETSC_EXTERN PetscErrorCode MatMatSolve(Mat,Mat,Mat);
389 PETSC_EXTERN PetscErrorCode MatResidual(Mat,Vec,Vec,Vec);
390 
391 /*E
392     MatDuplicateOption - Indicates if a duplicated sparse matrix should have
393   its numerical values copied over or just its nonzero structure.
394 
395     Level: beginner
396 
397    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
398 
399 $   MAT_SHARE_NONZERO_PATTERN - the i and j arrays in the new matrix will be shared with the original matrix
400 $                               this also triggers the MAT_DO_NOT_COPY_VALUES option. This is used when you
401 $                               have several matrices with the same nonzero pattern.
402 
403 .seealso: MatDuplicate()
404 E*/
405 typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES,MAT_SHARE_NONZERO_PATTERN} MatDuplicateOption;
406 
407 PETSC_EXTERN PetscErrorCode MatConvert(Mat,MatType,MatReuse,Mat*);
408 PETSC_EXTERN PetscErrorCode MatDuplicate(Mat,MatDuplicateOption,Mat*);
409 
410 
411 PETSC_EXTERN PetscErrorCode MatCopy(Mat,Mat,MatStructure);
412 PETSC_EXTERN PetscErrorCode MatView(Mat,PetscViewer);
413 PETSC_EXTERN PetscErrorCode MatIsSymmetric(Mat,PetscReal,PetscBool *);
414 PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetric(Mat,PetscBool *);
415 PETSC_EXTERN PetscErrorCode MatIsHermitian(Mat,PetscReal,PetscBool *);
416 PETSC_EXTERN PetscErrorCode MatIsSymmetricKnown(Mat,PetscBool *,PetscBool *);
417 PETSC_EXTERN PetscErrorCode MatIsHermitianKnown(Mat,PetscBool *,PetscBool *);
418 PETSC_EXTERN PetscErrorCode MatMissingDiagonal(Mat,PetscBool  *,PetscInt *);
419 PETSC_EXTERN PetscErrorCode MatLoad(Mat, PetscViewer);
420 
421 PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool  *);
422 PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,const PetscInt *[],const PetscInt *[],PetscBool  *);
423 PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool  *);
424 PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,const PetscInt *[],const PetscInt *[],PetscBool  *);
425 
426 /*S
427      MatInfo - Context of matrix information, used with MatGetInfo()
428 
429    In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE
430 
431    Level: intermediate
432 
433   Concepts: matrix^nonzero information
434 
435 .seealso:  MatGetInfo(), MatInfoType
436 S*/
437 typedef struct {
438   PetscLogDouble block_size;                         /* block size */
439   PetscLogDouble nz_allocated,nz_used,nz_unneeded;   /* number of nonzeros */
440   PetscLogDouble memory;                             /* memory allocated */
441   PetscLogDouble assemblies;                         /* number of matrix assemblies called */
442   PetscLogDouble mallocs;                            /* number of mallocs during MatSetValues() */
443   PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
444   PetscLogDouble factor_mallocs;                     /* number of mallocs during factorization */
445 } MatInfo;
446 
447 /*E
448     MatInfoType - Indicates if you want information about the local part of the matrix,
449      the entire parallel matrix or the maximum over all the local parts.
450 
451     Level: beginner
452 
453    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
454 
455 .seealso: MatGetInfo(), MatInfo
456 E*/
457 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
458 PETSC_EXTERN PetscErrorCode MatGetInfo(Mat,MatInfoType,MatInfo*);
459 PETSC_EXTERN PetscErrorCode MatGetDiagonal(Mat,Vec);
460 PETSC_EXTERN PetscErrorCode MatGetRowMax(Mat,Vec,PetscInt[]);
461 PETSC_EXTERN PetscErrorCode MatGetRowMin(Mat,Vec,PetscInt[]);
462 PETSC_EXTERN PetscErrorCode MatGetRowMaxAbs(Mat,Vec,PetscInt[]);
463 PETSC_EXTERN PetscErrorCode MatGetRowMinAbs(Mat,Vec,PetscInt[]);
464 PETSC_EXTERN PetscErrorCode MatGetRowSum(Mat,Vec);
465 PETSC_EXTERN PetscErrorCode MatTranspose(Mat,MatReuse,Mat*);
466 PETSC_EXTERN PetscErrorCode MatHermitianTranspose(Mat,MatReuse,Mat*);
467 PETSC_EXTERN PetscErrorCode MatPermute(Mat,IS,IS,Mat *);
468 PETSC_EXTERN PetscErrorCode MatDiagonalScale(Mat,Vec,Vec);
469 PETSC_EXTERN PetscErrorCode MatDiagonalSet(Mat,Vec,InsertMode);
470 PETSC_EXTERN PetscErrorCode MatEqual(Mat,Mat,PetscBool *);
471 PETSC_EXTERN PetscErrorCode MatMultEqual(Mat,Mat,PetscInt,PetscBool *);
472 PETSC_EXTERN PetscErrorCode MatMultAddEqual(Mat,Mat,PetscInt,PetscBool *);
473 PETSC_EXTERN PetscErrorCode MatMultTransposeEqual(Mat,Mat,PetscInt,PetscBool *);
474 PETSC_EXTERN PetscErrorCode MatMultTransposeAddEqual(Mat,Mat,PetscInt,PetscBool *);
475 
476 PETSC_EXTERN PetscErrorCode MatNorm(Mat,NormType,PetscReal *);
477 PETSC_EXTERN PetscErrorCode MatGetColumnNorms(Mat,NormType,PetscReal *);
478 PETSC_EXTERN PetscErrorCode MatZeroEntries(Mat);
479 PETSC_EXTERN PetscErrorCode MatZeroRows(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
480 PETSC_EXTERN PetscErrorCode MatZeroRowsIS(Mat,IS,PetscScalar,Vec,Vec);
481 PETSC_EXTERN PetscErrorCode MatZeroRowsStencil(Mat,PetscInt,const MatStencil [],PetscScalar,Vec,Vec);
482 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsStencil(Mat,PetscInt,const MatStencil[],PetscScalar,Vec,Vec);
483 PETSC_EXTERN PetscErrorCode MatZeroRowsColumns(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
484 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsIS(Mat,IS,PetscScalar,Vec,Vec);
485 
486 PETSC_EXTERN PetscErrorCode MatGetSize(Mat,PetscInt*,PetscInt*);
487 PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat,PetscInt*,PetscInt*);
488 PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat,PetscInt*,PetscInt*);
489 PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat,const PetscInt**);
490 PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat,PetscInt*,PetscInt*);
491 PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat,const PetscInt**);
492 PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat,IS*,IS*);
493 
494 PETSC_EXTERN PetscErrorCode MatGetSubMatrices(Mat,PetscInt,const IS[],const IS[],MatReuse,Mat *[]);
495 PETSC_EXTERN PetscErrorCode MatGetSubMatricesParallel(Mat,PetscInt,const IS[],const IS[],MatReuse,Mat *[]);
496 PETSC_EXTERN PetscErrorCode MatDestroyMatrices(PetscInt,Mat *[]);
497 PETSC_EXTERN PetscErrorCode MatGetSubMatrix(Mat,IS,IS,MatReuse,Mat *);
498 PETSC_EXTERN PetscErrorCode MatGetLocalSubMatrix(Mat,IS,IS,Mat*);
499 PETSC_EXTERN PetscErrorCode MatRestoreLocalSubMatrix(Mat,IS,IS,Mat*);
500 PETSC_EXTERN PetscErrorCode MatGetSeqNonzeroStructure(Mat,Mat*);
501 PETSC_EXTERN PetscErrorCode MatDestroySeqNonzeroStructure(Mat*);
502 
503 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJ(MPI_Comm,Mat,PetscInt,PetscInt,MatReuse,Mat*);
504 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJSymbolic(MPI_Comm,Mat,PetscInt,PetscInt,Mat*);
505 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJNumeric(Mat,Mat);
506 PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMat(Mat,MatReuse,Mat*);
507 PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatCondensed(Mat,MatReuse,IS*,IS*,Mat*);
508 PETSC_EXTERN PetscErrorCode MatGetBrowsOfAcols(Mat,Mat,MatReuse,IS*,IS*,Mat*);
509 PETSC_EXTERN PetscErrorCode MatGetGhosts(Mat, PetscInt *,const PetscInt *[]);
510 
511 PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat,PetscInt,IS[],PetscInt);
512 
513 PETSC_EXTERN PetscErrorCode MatMatMult(Mat,Mat,MatReuse,PetscReal,Mat*);
514 PETSC_EXTERN PetscErrorCode MatMatMultSymbolic(Mat,Mat,PetscReal,Mat*);
515 PETSC_EXTERN PetscErrorCode MatMatMultNumeric(Mat,Mat,Mat);
516 
517 PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat,Mat,Mat,MatReuse,PetscReal,Mat*);
518 PETSC_EXTERN PetscErrorCode MatMatMatMultSymbolic(Mat,Mat,Mat,PetscReal,Mat*);
519 PETSC_EXTERN PetscErrorCode MatMatMatMultNumeric(Mat,Mat,Mat,Mat);
520 
521 PETSC_EXTERN PetscErrorCode MatPtAP(Mat,Mat,MatReuse,PetscReal,Mat*);
522 PETSC_EXTERN PetscErrorCode MatPtAPSymbolic(Mat,Mat,PetscReal,Mat*);
523 PETSC_EXTERN PetscErrorCode MatPtAPNumeric(Mat,Mat,Mat);
524 PETSC_EXTERN PetscErrorCode MatRARt(Mat,Mat,MatReuse,PetscReal,Mat*);
525 PETSC_EXTERN PetscErrorCode MatRARtSymbolic(Mat,Mat,PetscReal,Mat*);
526 PETSC_EXTERN PetscErrorCode MatRARtNumeric(Mat,Mat,Mat);
527 
528 PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat,Mat,MatReuse,PetscReal,Mat*);
529 PETSC_EXTERN PetscErrorCode MatTransposetMatMultSymbolic(Mat,Mat,PetscReal,Mat*);
530 PETSC_EXTERN PetscErrorCode MatTransposetMatMultNumeric(Mat,Mat,Mat);
531 PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat,Mat,MatReuse,PetscReal,Mat*);
532 PETSC_EXTERN PetscErrorCode MatMatTransposeMultSymbolic(Mat,Mat,PetscReal,Mat*);
533 PETSC_EXTERN PetscErrorCode MatMatTransposeMultNumeric(Mat,Mat,Mat);
534 
535 PETSC_EXTERN PetscErrorCode MatAXPY(Mat,PetscScalar,Mat,MatStructure);
536 PETSC_EXTERN PetscErrorCode MatAYPX(Mat,PetscScalar,Mat,MatStructure);
537 
538 PETSC_EXTERN PetscErrorCode MatScale(Mat,PetscScalar);
539 PETSC_EXTERN PetscErrorCode MatShift(Mat,PetscScalar);
540 
541 PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping,ISLocalToGlobalMapping);
542 PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping*,ISLocalToGlobalMapping*);
543 PETSC_EXTERN PetscErrorCode MatGetLayouts(Mat,PetscLayout*,PetscLayout*);
544 PETSC_EXTERN PetscErrorCode MatZeroRowsLocal(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
545 PETSC_EXTERN PetscErrorCode MatZeroRowsLocalIS(Mat,IS,PetscScalar,Vec,Vec);
546 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocal(Mat,PetscInt,const PetscInt [],PetscScalar,Vec,Vec);
547 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocalIS(Mat,IS,PetscScalar,Vec,Vec);
548 PETSC_EXTERN PetscErrorCode MatSetValuesLocal(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
549 PETSC_EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
550 
551 PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat,PetscInt,PetscInt);
552 PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
553 
554 PETSC_EXTERN PetscErrorCode MatInterpolate(Mat,Vec,Vec);
555 PETSC_EXTERN PetscErrorCode MatInterpolateAdd(Mat,Vec,Vec,Vec);
556 PETSC_EXTERN PetscErrorCode MatRestrict(Mat,Vec,Vec);
557 PETSC_EXTERN PetscErrorCode MatCreateVecs(Mat,Vec*,Vec*);
558 PETSC_DEPRECATED("Use MatCreateVecs()") PETSC_STATIC_INLINE PetscErrorCode MatGetVecs(Mat mat,Vec *x,Vec *y) {return MatCreateVecs(mat,x,y);}
559 PETSC_EXTERN PetscErrorCode MatCreateRedundantMatrix(Mat,PetscInt,MPI_Comm,MatReuse,Mat*);
560 PETSC_EXTERN PetscErrorCode MatGetMultiProcBlock(Mat,MPI_Comm,MatReuse,Mat*);
561 PETSC_EXTERN PetscErrorCode MatFindZeroDiagonals(Mat,IS*);
562 PETSC_EXTERN PetscErrorCode MatFindOffBlockDiagonalEntries(Mat,IS*);
563 PETSC_EXTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat(MPI_Comm,Mat,PetscInt,MatReuse,Mat*);
564 
565 /*MC
566    MatSetValue - Set a single entry into a matrix.
567 
568    Not collective
569 
570    Synopsis:
571      #include <petscmat.h>
572      PetscErrorCode MatSetValue(Mat m,PetscInt row,PetscInt col,PetscScalar value,InsertMode mode)
573 
574    Input Parameters:
575 +  m - the matrix
576 .  row - the row location of the entry
577 .  col - the column location of the entry
578 .  value - the value to insert
579 -  mode - either INSERT_VALUES or ADD_VALUES
580 
581    Notes:
582    For efficiency one should use MatSetValues() and set several or many
583    values simultaneously if possible.
584 
585    Level: beginner
586 
587 .seealso: MatSetValues(), MatSetValueLocal()
588 M*/
589 PETSC_STATIC_INLINE PetscErrorCode MatSetValue(Mat v,PetscInt i,PetscInt j,PetscScalar va,InsertMode mode) {return MatSetValues(v,1,&i,1,&j,&va,mode);}
590 
591 PETSC_STATIC_INLINE PetscErrorCode MatGetValue(Mat v,PetscInt i,PetscInt j,PetscScalar *va) {return MatGetValues(v,1,&i,1,&j,va);}
592 
593 PETSC_STATIC_INLINE PetscErrorCode MatSetValueLocal(Mat v,PetscInt i,PetscInt j,PetscScalar va,InsertMode mode) {return MatSetValuesLocal(v,1,&i,1,&j,&va,mode);}
594 
595 /*MC
596    MatPreallocateInitialize - Begins the block of code that will count the number of nonzeros per
597        row in a matrix providing the data that one can use to correctly preallocate the matrix.
598 
599    Synopsis:
600    #include <petscmat.h>
601    PetscErrorCode MatPreallocateInitialize(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)
602 
603    Collective on MPI_Comm
604 
605    Input Parameters:
606 +  comm - the communicator that will share the eventually allocated matrix
607 .  nrows - the number of LOCAL rows in the matrix
608 -  ncols - the number of LOCAL columns in the matrix
609 
610    Output Parameters:
611 +  dnz - the array that will be passed to the matrix preallocation routines
612 -  ozn - the other array passed to the matrix preallocation routines
613 
614    Level: intermediate
615 
616    Notes:
617     See Users-Manual: ch_performance for more details.
618 
619    Do not malloc or free dnz and onz, that is handled internally by these routines
620 
621    Use MatPreallocateInitializeSymmetric() for symmetric matrices (MPISBAIJ matrices)
622 
623    This is a MACRO not a function because it has a leading { that is closed by PetscPreallocateFinalize().
624 
625   Concepts: preallocation^Matrix
626 
627 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateSetLocal(),
628           MatPreallocateInitializeSymmetric(), MatPreallocateSymmetricSetLocalBlock()
629 M*/
630 #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \
631 { \
632   PetscErrorCode _4_ierr; PetscInt __nrows = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
633   _4_ierr = PetscCalloc2(__nrows,&dnz,__nrows,&onz);CHKERRQ(_4_ierr); \
634   __start = 0; __end = __start;                                         \
635   _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPIU_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\
636   _4_ierr = MPI_Scan(&__nrows,&__rstart,1,MPIU_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __nrows;
637 
638 /*MC
639    MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
640        inserted using a local number of the rows and columns
641 
642    Synopsis:
643    #include <petscmat.h>
644    PetscErrorCode MatPreallocateSetLocal(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
645 
646    Not Collective
647 
648    Input Parameters:
649 +  map - the row mapping from local numbering to global numbering
650 .  nrows - the number of rows indicated
651 .  rows - the indices of the rows
652 .  cmap - the column mapping from local to global numbering
653 .  ncols - the number of columns in the matrix
654 .  cols - the columns indicated
655 .  dnz - the array that will be passed to the matrix preallocation routines
656 -  ozn - the other array passed to the matrix preallocation routines
657 
658    Level: intermediate
659 
660    Notes:
661     See Users-Manual: ch_performance for more details.
662 
663    Do not malloc or free dnz and onz, that is handled internally by these routines
664 
665   Concepts: preallocation^Matrix
666 
667 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateInitialize(),
668           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocalBlock()
669 M*/
670 #define MatPreallocateSetLocal(rmap,nrows,rows,cmap,ncols,cols,dnz,onz) 0; \
671 {\
672   PetscInt __l;\
673   _4_ierr = ISLocalToGlobalMappingApply(rmap,nrows,rows,rows);CHKERRQ(_4_ierr);\
674   _4_ierr = ISLocalToGlobalMappingApply(cmap,ncols,cols,cols);CHKERRQ(_4_ierr);\
675   for (__l=0;__l<nrows;__l++) {\
676     _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
677   }\
678 }
679 
680 /*MC
681    MatPreallocateSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
682        inserted using a local number of the rows and columns
683 
684    Synopsis:
685    #include <petscmat.h>
686    PetscErrorCode MatPreallocateSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
687 
688    Not Collective
689 
690    Input Parameters:
691 +  map - the row mapping from local numbering to global numbering
692 .  nrows - the number of rows indicated
693 .  rows - the indices of the rows
694 .  cmap - the column mapping from local to global numbering
695 .  ncols - the number of columns in the matrix
696 .  cols - the columns indicated
697 .  dnz - the array that will be passed to the matrix preallocation routines
698 -  ozn - the other array passed to the matrix preallocation routines
699 
700    Level: intermediate
701 
702    Notes:
703     See Users-Manual: ch_performance for more details.
704 
705    Do not malloc or free dnz and onz, that is handled internally by these routines
706 
707   Concepts: preallocation^Matrix
708 
709 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateInitialize(),
710           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocalBlock()
711 M*/
712 #define MatPreallocateSetLocalBlock(rmap,nrows,rows,cmap,ncols,cols,dnz,onz) 0; \
713 {\
714   PetscInt __l;\
715   _4_ierr = ISLocalToGlobalMappingApplyBlock(rmap,nrows,rows,rows);CHKERRQ(_4_ierr);\
716   _4_ierr = ISLocalToGlobalMappingApplyBlock(cmap,ncols,cols,cols);CHKERRQ(_4_ierr);\
717   for (__l=0;__l<nrows;__l++) {\
718     _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
719   }\
720 }
721 
722 /*MC
723    MatPreallocateSymmetricSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
724        inserted using a local number of the rows and columns
725 
726    Synopsis:
727    #include <petscmat.h>
728    PetscErrorCode MatPreallocateSymmetricSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
729 
730    Not Collective
731 
732    Input Parameters:
733 +  map - the mapping between local numbering and global numbering
734 .  nrows - the number of rows indicated
735 .  rows - the indices of the rows
736 .  ncols - the number of columns in the matrix
737 .  cols - the columns indicated
738 .  dnz - the array that will be passed to the matrix preallocation routines
739 -  ozn - the other array passed to the matrix preallocation routines
740 
741    Level: intermediate
742 
743    Notes:
744     See Users-Manual: ch_performance for more details.
745 
746    Do not malloc or free dnz and onz that is handled internally by these routines
747 
748   Concepts: preallocation^Matrix
749 
750 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateInitialize(),
751           MatPreallocateInitialize(),  MatPreallocateSetLocal()
752 M*/
753 #define MatPreallocateSymmetricSetLocalBlock(map,nrows,rows,ncols,cols,dnz,onz) 0;\
754 {\
755   PetscInt __l;\
756   _4_ierr = ISLocalToGlobalMappingApplyBlock(map,nrows,rows,rows);CHKERRQ(_4_ierr);\
757   _4_ierr = ISLocalToGlobalMappingApplyBlock(map,ncols,cols,cols);CHKERRQ(_4_ierr);\
758   for (__l=0;__l<nrows;__l++) {\
759     _4_ierr = MatPreallocateSymmetricSetBlock((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
760   }\
761 }
762 /*MC
763    MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
764        inserted using a local number of the rows and columns
765 
766    Synopsis:
767    #include <petscmat.h>
768    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
769 
770    Not Collective
771 
772    Input Parameters:
773 +  row - the row
774 .  ncols - the number of columns in the matrix
775 -  cols - the columns indicated
776 
777    Output Parameters:
778 +  dnz - the array that will be passed to the matrix preallocation routines
779 -  ozn - the other array passed to the matrix preallocation routines
780 
781    Level: intermediate
782 
783    Notes:
784     See Users-Manual: ch_performance for more details.
785 
786    Do not malloc or free dnz and onz that is handled internally by these routines
787 
788    This is a MACRO not a function because it uses variables declared in MatPreallocateInitialize().
789 
790   Concepts: preallocation^Matrix
791 
792 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateInitialize(),
793           MatPreallocateInitialize(), MatPreallocateSetLocal()
794 M*/
795 #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\
796 { PetscInt __i; \
797   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);\
798   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);\
799   for (__i=0; __i<nc; __i++) {\
800     if ((cols)[__i] < __start || (cols)[__i] >= __end) onz[row - __rstart]++; \
801     else dnz[row - __rstart]++;\
802   }\
803 }
804 
805 /*MC
806    MatPreallocateSymmetricSetBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
807        inserted using a local number of the rows and columns
808 
809    Synopsis:
810    #include <petscmat.h>
811    PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)
812 
813    Not Collective
814 
815    Input Parameters:
816 +  nrows - the number of rows indicated
817 .  rows - the indices of the rows
818 .  ncols - the number of columns in the matrix
819 .  cols - the columns indicated
820 .  dnz - the array that will be passed to the matrix preallocation routines
821 -  ozn - the other array passed to the matrix preallocation routines
822 
823    Level: intermediate
824 
825    Notes:
826     See Users-Manual: ch_performance for more details.
827 
828    Do not malloc or free dnz and onz that is handled internally by these routines
829 
830    This is a MACRO not a function because it uses variables declared in MatPreallocateInitialize().
831 
832   Concepts: preallocation^Matrix
833 
834 .seealso: MatPreallocateFinalize(), MatPreallocateSet(),  MatPreallocateInitialize(),
835           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocalBlock(), MatPreallocateSetLocal()
836 M*/
837 #define MatPreallocateSymmetricSetBlock(row,nc,cols,dnz,onz) 0;\
838 { PetscInt __i; \
839   for (__i=0; __i<nc; __i++) {\
840     if (cols[__i] >= __end) onz[row - __rstart]++; \
841     else if (cols[__i] >= row) dnz[row - __rstart]++;\
842   }\
843 }
844 
845 /*MC
846    MatPreallocateLocation -  An alternative to MatPreallocationSet() that puts the nonzero locations into the matrix if it exists
847 
848    Synopsis:
849    #include <petscmat.h>
850    PetscErrorCode MatPreallocateLocations(Mat A,PetscInt row,PetscInt ncols,PetscInt *cols,PetscInt *dnz,PetscInt *onz)
851 
852    Not Collective
853 
854    Input Parameters:
855 .  A - matrix
856 .  row - row where values exist (must be local to this process)
857 .  ncols - number of columns
858 .  cols - columns with nonzeros
859 .  dnz - the array that will be passed to the matrix preallocation routines
860 -  ozn - the other array passed to the matrix preallocation routines
861 
862    Level: intermediate
863 
864    Notes:
865     See Users-Manual: ch_performance for more details.
866 
867    Do not malloc or free dnz and onz that is handled internally by these routines
868 
869    This is a MACRO not a function because it uses a bunch of variables private to the MatPreallocation.... routines.
870 
871   Concepts: preallocation^Matrix
872 
873 .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateSetLocal(),
874           MatPreallocateSymmetricSetLocalBlock()
875 M*/
876 #define MatPreallocateLocation(A,row,ncols,cols,dnz,onz) 0;if (A) {ierr = MatSetValues(A,1,&row,ncols,cols,NULL,INSERT_VALUES);CHKERRQ(ierr);} else {ierr =  MatPreallocateSet(row,ncols,cols,dnz,onz);CHKERRQ(ierr);}
877 
878 
879 /*MC
880    MatPreallocateFinalize - Ends the block of code that will count the number of nonzeros per
881        row in a matrix providing the data that one can use to correctly preallocate the matrix.
882 
883    Synopsis:
884    #include <petscmat.h>
885    PetscErrorCode MatPreallocateFinalize(PetscInt *dnz, PetscInt *onz)
886 
887    Collective on MPI_Comm
888 
889    Input Parameters:
890 +  dnz - the array that was be passed to the matrix preallocation routines
891 -  ozn - the other array passed to the matrix preallocation routines
892 
893    Level: intermediate
894 
895    Notes:
896     See Users-Manual: ch_performance for more details.
897 
898    Do not malloc or free dnz and onz that is handled internally by these routines
899 
900    This is a MACRO not a function because it closes the { started in MatPreallocateInitialize().
901 
902   Concepts: preallocation^Matrix
903 
904 .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSetBlock(), MatPreallocateSetLocal(),
905           MatPreallocateSymmetricSetLocalBlock()
906 M*/
907 #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree2(dnz,onz);CHKERRQ(_4_ierr);}
908 
909 /* Routines unique to particular data structures */
910 PETSC_EXTERN PetscErrorCode MatShellGetContext(Mat,void *);
911 
912 PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat,IS*,IS*);
913 PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat,PetscInt *,PetscInt *[],PetscInt *);
914 
915 PETSC_EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat,PetscInt[]);
916 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat,PetscInt[]);
917 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
918 PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
919 PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJWithArrays(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*);
920 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJFromTriple(MPI_Comm,PetscInt,PetscInt,PetscInt[],PetscInt[],PetscScalar[],Mat*,PetscInt,PetscBool);
921 
922 #define MAT_SKIP_ALLOCATION -4
923 
924 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[]);
925 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[]);
926 PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat,PetscInt,const PetscInt[]);
927 
928 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
929 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
930 PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
931 PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat,const PetscInt [],const PetscInt [],const PetscScalar []);
932 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
933 PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat,const PetscInt[],const PetscInt[],const PetscScalar[]);
934 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[]);
935 PETSC_EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat,PetscInt[],PetscInt[],PetscInt[]);
936 PETSC_EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat,PetscScalar[]);
937 PETSC_EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat,PetscScalar[]);
938 PETSC_EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,const PetscInt*[]);
939 PETSC_EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,const PetscInt*[]);
940 PETSC_EXTERN PetscErrorCode MatMPIAdjCreateNonemptySubcommMat(Mat,Mat*);
941 
942 PETSC_EXTERN PetscErrorCode MatISSetPreallocation(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
943 PETSC_EXTERN PetscErrorCode MatSeqDenseSetLDA(Mat,PetscInt);
944 PETSC_EXTERN PetscErrorCode MatDenseGetLocalMatrix(Mat,Mat*);
945 
946 PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
947 PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);
948 
949 PETSC_EXTERN PetscErrorCode MatDAADSetCtx(Mat,void*);
950 
951 PETSC_EXTERN PetscErrorCode MatFindNonzeroRows(Mat,IS*);
952 /*
953   These routines are not usually accessed directly, rather solving is
954   done through the KSP and PC interfaces.
955 */
956 
957 /*J
958     MatOrderingType - String with the name of a PETSc matrix ordering
959 
960    Level: beginner
961 
962 .seealso: MatGetOrdering()
963 J*/
964 typedef const char* MatOrderingType;
965 #define MATORDERINGNATURAL     "natural"
966 #define MATORDERINGND          "nd"
967 #define MATORDERING1WD         "1wd"
968 #define MATORDERINGRCM         "rcm"
969 #define MATORDERINGQMD         "qmd"
970 #define MATORDERINGROWLENGTH   "rowlength"
971 #define MATORDERINGWBM         "wbm"
972 #define MATORDERINGSPECTRAL    "spectral"
973 #define MATORDERINGAMD         "amd"            /* only works if UMFPACK is installed with PETSc */
974 
975 PETSC_EXTERN PetscErrorCode MatGetOrdering(Mat,MatOrderingType,IS*,IS*);
976 PETSC_EXTERN PetscErrorCode MatGetOrderingList(PetscFunctionList*);
977 PETSC_EXTERN PetscErrorCode MatOrderingRegister(const char[],PetscErrorCode(*)(Mat,MatOrderingType,IS*,IS*));
978 PETSC_EXTERN PetscErrorCode MatOrderingRegisterAll(void);
979 PETSC_EXTERN PetscBool         MatOrderingRegisterAllCalled;
980 PETSC_EXTERN PetscFunctionList MatOrderingList;
981 
982 PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS);
983 PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat,PetscReal,PetscBool,Mat*);
984 
985 /*S
986     MatFactorShiftType - Numeric Shift.
987 
988    Level: beginner
989 
990 S*/
991 typedef enum {MAT_SHIFT_NONE,MAT_SHIFT_NONZERO,MAT_SHIFT_POSITIVE_DEFINITE,MAT_SHIFT_INBLOCKS} MatFactorShiftType;
992 PETSC_EXTERN const char *const MatFactorShiftTypes[];
993 PETSC_EXTERN const char *const MatFactorShiftTypesDetail[];
994 
995 /*S
996    MatFactorInfo - Data passed into the matrix factorization routines
997 
998    In Fortran these are simply double precision arrays of size MAT_FACTORINFO_SIZE, that is use
999 $     MatFactorInfo  info(MAT_FACTORINFO_SIZE)
1000 
1001    Notes: These are not usually directly used by users, instead use PC type of LU, ILU, CHOLESKY or ICC.
1002 
1003       You can use MatFactorInfoInitialize() to set default values.
1004 
1005    Level: developer
1006 
1007 .seealso: MatLUFactorSymbolic(), MatILUFactorSymbolic(), MatCholeskyFactorSymbolic(), MatICCFactorSymbolic(), MatICCFactor(),
1008           MatFactorInfoInitialize()
1009 
1010 S*/
1011 typedef struct {
1012   PetscReal     diagonal_fill;  /* force diagonal to fill in if initially not filled */
1013   PetscReal     usedt;
1014   PetscReal     dt;             /* drop tolerance */
1015   PetscReal     dtcol;          /* tolerance for pivoting */
1016   PetscReal     dtcount;        /* maximum nonzeros to be allowed per row */
1017   PetscReal     fill;           /* expected fill, nonzeros in factored matrix/nonzeros in original matrix */
1018   PetscReal     levels;         /* ICC/ILU(levels) */
1019   PetscReal     pivotinblocks;  /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0
1020                                    factorization may be faster if do not pivot */
1021   PetscReal     zeropivot;      /* pivot is called zero if less than this */
1022   PetscReal     shifttype;      /* type of shift added to matrix factor to prevent zero pivots */
1023   PetscReal     shiftamount;     /* how large the shift is */
1024 } MatFactorInfo;
1025 
1026 PETSC_EXTERN PetscErrorCode MatFactorInfoInitialize(MatFactorInfo*);
1027 PETSC_EXTERN PetscErrorCode MatCholeskyFactor(Mat,IS,const MatFactorInfo*);
1028 PETSC_EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat,Mat,IS,const MatFactorInfo*);
1029 PETSC_EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat,Mat,const MatFactorInfo*);
1030 PETSC_EXTERN PetscErrorCode MatLUFactor(Mat,IS,IS,const MatFactorInfo*);
1031 PETSC_EXTERN PetscErrorCode MatILUFactor(Mat,IS,IS,const MatFactorInfo*);
1032 PETSC_EXTERN PetscErrorCode MatLUFactorSymbolic(Mat,Mat,IS,IS,const MatFactorInfo*);
1033 PETSC_EXTERN PetscErrorCode MatILUFactorSymbolic(Mat,Mat,IS,IS,const MatFactorInfo*);
1034 PETSC_EXTERN PetscErrorCode MatICCFactorSymbolic(Mat,Mat,IS,const MatFactorInfo*);
1035 PETSC_EXTERN PetscErrorCode MatICCFactor(Mat,IS,const MatFactorInfo*);
1036 PETSC_EXTERN PetscErrorCode MatLUFactorNumeric(Mat,Mat,const MatFactorInfo*);
1037 PETSC_EXTERN PetscErrorCode MatGetInertia(Mat,PetscInt*,PetscInt*,PetscInt*);
1038 PETSC_EXTERN PetscErrorCode MatSolve(Mat,Vec,Vec);
1039 PETSC_EXTERN PetscErrorCode MatForwardSolve(Mat,Vec,Vec);
1040 PETSC_EXTERN PetscErrorCode MatBackwardSolve(Mat,Vec,Vec);
1041 PETSC_EXTERN PetscErrorCode MatSolveAdd(Mat,Vec,Vec,Vec);
1042 PETSC_EXTERN PetscErrorCode MatSolveTranspose(Mat,Vec,Vec);
1043 PETSC_EXTERN PetscErrorCode MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
1044 PETSC_EXTERN PetscErrorCode MatSolves(Mat,Vecs,Vecs);
1045 
1046 PETSC_EXTERN PetscErrorCode MatSetUnfactored(Mat);
1047 
1048 /*E
1049     MatSORType - What type of (S)SOR to perform
1050 
1051     Level: beginner
1052 
1053    May be bitwise ORd together
1054 
1055    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
1056 
1057    MatSORType may be bitwise ORd together, so do not change the numbers
1058 
1059 .seealso: MatSOR()
1060 E*/
1061 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
1062               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
1063               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
1064               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
1065 PETSC_EXTERN PetscErrorCode MatSOR(Mat,Vec,PetscReal,MatSORType,PetscReal,PetscInt,PetscInt,Vec);
1066 
1067 /*
1068     These routines are for efficiently computing Jacobians via finite differences.
1069 */
1070 
1071 /*S
1072      MatColoring - Object for managing the coloring of matrices.
1073 
1074    Level: beginner
1075 
1076   Concepts: matrix, coloring
1077 
1078 .seealso:  MatFDColoringCreate() ISColoring MatFDColoring
1079 S*/
1080 typedef struct _p_MatColoring* MatColoring;
1081 /*J
1082     MatColoringType - String with the name of a PETSc matrix coloring
1083 
1084    Level: beginner
1085 
1086 .seealso: MatColoringSetType(), MatColoring
1087 J*/
1088 
1089 typedef const  char*           MatColoringType;
1090 #define MATCOLORINGJP      "jp"
1091 #define MATCOLORINGPOWER   "power"
1092 #define MATCOLORINGNATURAL "natural"
1093 #define MATCOLORINGSL      "sl"
1094 #define MATCOLORINGLF      "lf"
1095 #define MATCOLORINGID      "id"
1096 #define MATCOLORINGGREEDY  "greedy"
1097 
1098 /*E
1099    MatColoringWeightType - Type of weight scheme
1100 
1101     Not Collective
1102 
1103 +   MAT_COLORING_RANDOM  - Random weights
1104 .   MAT_COLORING_LEXICAL - Lexical weighting based upon global numbering.
1105 -   MAT_COLORING_LF      - Last-first weighting.
1106 
1107     Level: intermediate
1108 
1109    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
1110 
1111 .seealso: MatCUSPSetFormat(), MatCUSPFormatOperation
1112 E*/
1113 typedef enum {MAT_COLORING_WEIGHT_RANDOM,MAT_COLORING_WEIGHT_LEXICAL,MAT_COLORING_WEIGHT_LF,MAT_COLORING_WEIGHT_SL} MatColoringWeightType;
1114 
1115 PETSC_EXTERN PetscErrorCode MatColoringCreate(Mat,MatColoring*);
1116 PETSC_EXTERN PetscErrorCode MatColoringGetDegrees(Mat,PetscInt,PetscInt*);
1117 PETSC_EXTERN PetscErrorCode MatColoringDestroy(MatColoring*);
1118 PETSC_EXTERN PetscErrorCode MatColoringView(MatColoring,PetscViewer);
1119 PETSC_EXTERN PetscErrorCode MatColoringSetType(MatColoring,MatColoringType);
1120 PETSC_EXTERN PetscErrorCode MatColoringSetFromOptions(MatColoring);
1121 PETSC_EXTERN PetscErrorCode MatColoringSetDistance(MatColoring,PetscInt);
1122 PETSC_EXTERN PetscErrorCode MatColoringGetDistance(MatColoring,PetscInt*);
1123 PETSC_EXTERN PetscErrorCode MatColoringSetMaxColors(MatColoring,PetscInt);
1124 PETSC_EXTERN PetscErrorCode MatColoringGetMaxColors(MatColoring,PetscInt*);
1125 PETSC_EXTERN PetscErrorCode MatColoringApply(MatColoring,ISColoring*);
1126 PETSC_EXTERN PetscErrorCode MatColoringRegisterAll(void);
1127 PETSC_EXTERN PetscErrorCode MatColoringRegister(const char[],PetscErrorCode(*)(MatColoring));
1128 PETSC_EXTERN PetscBool MatColoringRegisterAllCalled;
1129 PETSC_EXTERN PetscErrorCode MatColoringPatch(Mat,PetscInt,PetscInt,ISColoringValue[],ISColoring*);
1130 PETSC_EXTERN PetscErrorCode MatColoringSetWeightType(MatColoring,MatColoringWeightType);
1131 PETSC_EXTERN PetscErrorCode MatColoringSetWeights(MatColoring,PetscReal*,PetscInt*);
1132 PETSC_EXTERN PetscErrorCode MatColoringCreateWeights(MatColoring,PetscReal **,PetscInt **lperm);
1133 
1134 /*S
1135      MatFDColoring - Object for computing a sparse Jacobian via finite differences
1136         and coloring
1137 
1138    Level: beginner
1139 
1140   Concepts: coloring, sparse Jacobian, finite differences
1141 
1142 .seealso:  MatFDColoringCreate()
1143 S*/
1144 typedef struct _p_MatFDColoring* MatFDColoring;
1145 
1146 PETSC_EXTERN PetscErrorCode MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
1147 PETSC_EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring*);
1148 PETSC_EXTERN PetscErrorCode MatFDColoringView(MatFDColoring,PetscViewer);
1149 PETSC_EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring,PetscErrorCode (*)(void),void*);
1150 PETSC_EXTERN PetscErrorCode MatFDColoringGetFunction(MatFDColoring,PetscErrorCode (**)(void),void**);
1151 PETSC_EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal);
1152 PETSC_EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring);
1153 PETSC_EXTERN PetscErrorCode MatFDColoringApply(Mat,MatFDColoring,Vec,void *);
1154 PETSC_EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring,Vec);
1155 PETSC_EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring,PetscInt*,PetscInt*[]);
1156 PETSC_EXTERN PetscErrorCode MatFDColoringSetUp(Mat,ISColoring,MatFDColoring);
1157 PETSC_EXTERN PetscErrorCode MatFDColoringSetBlockSize(MatFDColoring,PetscInt,PetscInt);
1158 
1159 
1160 /*S
1161      MatTransposeColoring - Object for computing a sparse matrix product C=A*B^T via coloring
1162 
1163    Level: beginner
1164 
1165   Concepts: coloring, sparse matrix product
1166 
1167 .seealso:  MatTransposeColoringCreate()
1168 S*/
1169 typedef struct _p_MatTransposeColoring* MatTransposeColoring;
1170 
1171 PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat,ISColoring,MatTransposeColoring *);
1172 PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring,Mat,Mat);
1173 PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring,Mat,Mat);
1174 PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring*);
1175 
1176 /*
1177     These routines are for partitioning matrices: currently used only
1178   for adjacency matrix, MatCreateMPIAdj().
1179 */
1180 
1181 /*S
1182      MatPartitioning - Object for managing the partitioning of a matrix or graph
1183 
1184    Level: beginner
1185 
1186   Concepts: partitioning
1187 
1188 .seealso:  MatPartitioningCreate(), MatPartitioningType
1189 S*/
1190 typedef struct _p_MatPartitioning* MatPartitioning;
1191 
1192 /*J
1193     MatPartitioningType - String with the name of a PETSc matrix partitioning
1194 
1195    Level: beginner
1196 dm
1197 .seealso: MatPartitioningCreate(), MatPartitioning
1198 J*/
1199 typedef const char* MatPartitioningType;
1200 #define MATPARTITIONINGCURRENT  "current"
1201 #define MATPARTITIONINGSQUARE   "square"
1202 #define MATPARTITIONINGPARMETIS "parmetis"
1203 #define MATPARTITIONINGCHACO    "chaco"
1204 #define MATPARTITIONINGPARTY    "party"
1205 #define MATPARTITIONINGPTSCOTCH "ptscotch"
1206 
1207 
1208 PETSC_EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm,MatPartitioning*);
1209 PETSC_EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning,MatPartitioningType);
1210 PETSC_EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning,PetscInt);
1211 PETSC_EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning,Mat);
1212 PETSC_EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning,const PetscInt[]);
1213 PETSC_EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning,const PetscReal []);
1214 PETSC_EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning,IS*);
1215 PETSC_EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning*);
1216 
1217 PETSC_EXTERN PetscErrorCode MatPartitioningRegister(const char[],PetscErrorCode (*)(MatPartitioning));
1218 
1219 PETSC_EXTERN PetscBool MatPartitioningRegisterAllCalled;
1220 
1221 PETSC_EXTERN PetscErrorCode MatPartitioningRegisterAll(void);
1222 
1223 PETSC_EXTERN PetscErrorCode MatPartitioningView(MatPartitioning,PetscViewer);
1224 PETSC_EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning);
1225 PETSC_EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning,MatPartitioningType*);
1226 
1227 PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1228 PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *);
1229 
1230 typedef enum { MP_CHACO_MULTILEVEL=1,MP_CHACO_SPECTRAL=2,MP_CHACO_LINEAR=4,MP_CHACO_RANDOM=5,MP_CHACO_SCATTERED=6 } MPChacoGlobalType;
1231 PETSC_EXTERN const char *const MPChacoGlobalTypes[];
1232 typedef enum { MP_CHACO_KERNIGHAN=1,MP_CHACO_NONE=2 } MPChacoLocalType;
1233 PETSC_EXTERN const char *const MPChacoLocalTypes[];
1234 typedef enum { MP_CHACO_LANCZOS=0,MP_CHACO_RQI=1 } MPChacoEigenType;
1235 PETSC_EXTERN const char *const MPChacoEigenTypes[];
1236 
1237 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning,MPChacoGlobalType);
1238 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning,MPChacoGlobalType*);
1239 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning,MPChacoLocalType);
1240 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning,MPChacoLocalType*);
1241 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning,PetscReal);
1242 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning,MPChacoEigenType);
1243 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning,MPChacoEigenType*);
1244 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning,PetscReal);
1245 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning,PetscReal*);
1246 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning,PetscInt);
1247 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning,PetscInt*);
1248 
1249 #define MP_PARTY_OPT "opt"
1250 #define MP_PARTY_LIN "lin"
1251 #define MP_PARTY_SCA "sca"
1252 #define MP_PARTY_RAN "ran"
1253 #define MP_PARTY_GBF "gbf"
1254 #define MP_PARTY_GCF "gcf"
1255 #define MP_PARTY_BUB "bub"
1256 #define MP_PARTY_DEF "def"
1257 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning,const char*);
1258 #define MP_PARTY_HELPFUL_SETS "hs"
1259 #define MP_PARTY_KERNIGHAN_LIN "kl"
1260 #define MP_PARTY_NONE "no"
1261 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning,const char*);
1262 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning,PetscReal);
1263 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning,PetscBool);
1264 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning,PetscBool);
1265 
1266 typedef enum { MP_PTSCOTCH_QUALITY,MP_PTSCOTCH_SPEED,MP_PTSCOTCH_BALANCE,MP_PTSCOTCH_SAFETY,MP_PTSCOTCH_SCALABILITY } MPPTScotchStrategyType;
1267 PETSC_EXTERN const char *const MPPTScotchStrategyTypes[];
1268 
1269 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning,PetscReal);
1270 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning,PetscReal*);
1271 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning,MPPTScotchStrategyType);
1272 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning,MPPTScotchStrategyType*);
1273 
1274 /*
1275     These routines are for coarsening matrices:
1276 */
1277 
1278 /*S
1279      MatCoarsen - Object for managing the coarsening of a graph (symmetric matrix)
1280 
1281    Level: beginner
1282 
1283   Concepts: coarsen
1284 
1285 .seealso:  MatCoarsenCreate), MatCoarsenType
1286 S*/
1287 typedef struct _p_MatCoarsen* MatCoarsen;
1288 
1289 /*J
1290     MatCoarsenType - String with the name of a PETSc matrix coarsen
1291 
1292    Level: beginner
1293 
1294 .seealso: MatCoarsenCreate(), MatCoarsen
1295 J*/
1296 typedef const char* MatCoarsenType;
1297 #define MATCOARSENMIS  "mis"
1298 #define MATCOARSENHEM  "hem"
1299 
1300 /* linked list for aggregates */
1301 typedef struct _PetscCDIntNd{
1302   struct _PetscCDIntNd *next;
1303   PetscInt             gid;
1304 }PetscCDIntNd;
1305 
1306 /* only used by node pool */
1307 typedef struct _PetscCDArrNd{
1308   struct _PetscCDArrNd *next;
1309   struct _PetscCDIntNd *array;
1310 }PetscCDArrNd;
1311 
1312 typedef struct _PetscCoarsenData{
1313   PetscCDArrNd pool_list;  /* node pool */
1314   PetscCDIntNd *new_node;
1315   PetscInt     new_left;
1316   PetscInt     chk_sz;
1317   PetscCDIntNd *extra_nodes;
1318   PetscCDIntNd **array;  /* Array of lists */
1319   PetscInt     size;
1320   Mat          mat;  /* cache a Mat for communication data */
1321 }PetscCoarsenData;
1322 
1323 PETSC_EXTERN PetscErrorCode MatCoarsenCreate(MPI_Comm,MatCoarsen*);
1324 PETSC_EXTERN PetscErrorCode MatCoarsenSetType(MatCoarsen,MatCoarsenType);
1325 PETSC_EXTERN PetscErrorCode MatCoarsenSetAdjacency(MatCoarsen,Mat);
1326 PETSC_EXTERN PetscErrorCode MatCoarsenSetGreedyOrdering(MatCoarsen,const IS);
1327 PETSC_EXTERN PetscErrorCode MatCoarsenSetStrictAggs(MatCoarsen,PetscBool);
1328 PETSC_EXTERN PetscErrorCode MatCoarsenSetVerbose(MatCoarsen,PetscInt);
1329 PETSC_EXTERN PetscErrorCode MatCoarsenGetData( MatCoarsen, PetscCoarsenData ** );
1330 PETSC_EXTERN PetscErrorCode MatCoarsenApply(MatCoarsen);
1331 PETSC_EXTERN PetscErrorCode MatCoarsenDestroy(MatCoarsen*);
1332 
1333 PETSC_EXTERN PetscErrorCode MatCoarsenRegister(const char[],PetscErrorCode (*)(MatCoarsen));
1334 
1335 PETSC_EXTERN PetscBool MatCoarsenRegisterAllCalled;
1336 
1337 PETSC_EXTERN PetscErrorCode MatCoarsenRegisterAll(void);
1338 
1339 PETSC_EXTERN PetscErrorCode MatCoarsenView(MatCoarsen,PetscViewer);
1340 PETSC_EXTERN PetscErrorCode MatCoarsenSetFromOptions(MatCoarsen);
1341 PETSC_EXTERN PetscErrorCode MatCoarsenGetType(MatCoarsen,MatCoarsenType*);
1342 PETSC_STATIC_INLINE PetscErrorCode MatCoarsenViewFromOptions(MatCoarsen A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
1343 
1344 PETSC_EXTERN PetscErrorCode MatMeshToVertexGraph(Mat,PetscInt,Mat*);
1345 PETSC_EXTERN PetscErrorCode MatMeshToCellGraph(Mat,PetscInt,Mat*);
1346 
1347 /*
1348     If you add entries here you must also add them to petsc-finclude/petscmat.h
1349 */
1350 typedef enum { MATOP_SET_VALUES=0,
1351                MATOP_GET_ROW=1,
1352                MATOP_RESTORE_ROW=2,
1353                MATOP_MULT=3,
1354                MATOP_MULT_ADD=4,
1355                MATOP_MULT_TRANSPOSE=5,
1356                MATOP_MULT_TRANSPOSE_ADD=6,
1357                MATOP_SOLVE=7,
1358                MATOP_SOLVE_ADD=8,
1359                MATOP_SOLVE_TRANSPOSE=9,
1360                MATOP_SOLVE_TRANSPOSE_ADD=10,
1361                MATOP_LUFACTOR=11,
1362                MATOP_CHOLESKYFACTOR=12,
1363                MATOP_SOR=13,
1364                MATOP_TRANSPOSE=14,
1365                MATOP_GETINFO=15,
1366                MATOP_EQUAL=16,
1367                MATOP_GET_DIAGONAL=17,
1368                MATOP_DIAGONAL_SCALE=18,
1369                MATOP_NORM=19,
1370                MATOP_ASSEMBLY_BEGIN=20,
1371                MATOP_ASSEMBLY_END=21,
1372                MATOP_SET_OPTION=22,
1373                MATOP_ZERO_ENTRIES=23,
1374                MATOP_ZERO_ROWS=24,
1375                MATOP_LUFACTOR_SYMBOLIC=25,
1376                MATOP_LUFACTOR_NUMERIC=26,
1377                MATOP_CHOLESKY_FACTOR_SYMBOLIC=27,
1378                MATOP_CHOLESKY_FACTOR_NUMERIC=28,
1379                MATOP_SETUP_PREALLOCATION=29,
1380                MATOP_ILUFACTOR_SYMBOLIC=30,
1381                MATOP_ICCFACTOR_SYMBOLIC=31,
1382                /* MATOP_PLACEHOLDER_32=32, */
1383                /* MATOP_PLACEHOLDER_33=33, */
1384                MATOP_DUPLICATE=34,
1385                MATOP_FORWARD_SOLVE=35,
1386                MATOP_BACKWARD_SOLVE=36,
1387                MATOP_ILUFACTOR=37,
1388                MATOP_ICCFACTOR=38,
1389                MATOP_AXPY=39,
1390                MATOP_GET_SUBMATRICES=40,
1391                MATOP_INCREASE_OVERLAP=41,
1392                MATOP_GET_VALUES=42,
1393                MATOP_COPY=43,
1394                MATOP_GET_ROW_MAX=44,
1395                MATOP_SCALE=45,
1396                MATOP_SHIFT=46,
1397                MATOP_DIAGONAL_SET=47,
1398                MATOP_ZERO_ROWS_COLUMNS=48,
1399                MATOP_SET_RANDOM=49,
1400                MATOP_GET_ROW_IJ=50,
1401                MATOP_RESTORE_ROW_IJ=51,
1402                MATOP_GET_COLUMN_IJ=52,
1403                MATOP_RESTORE_COLUMN_IJ=53,
1404                MATOP_FDCOLORING_CREATE=54,
1405                MATOP_COLORING_PATCH=55,
1406                MATOP_SET_UNFACTORED=56,
1407                MATOP_PERMUTE=57,
1408                MATOP_SET_VALUES_BLOCKED=58,
1409                MATOP_GET_SUBMATRIX=59,
1410                MATOP_DESTROY=60,
1411                MATOP_VIEW=61,
1412                MATOP_CONVERT_FROM=62,
1413                MATOP_MATMAT_MULT=63,
1414                MATOP_MATMAT_MULT_SYMBOLIC=64,
1415                MATOP_MATMAT_MULT_NUMERIC=65,
1416                MATOP_SET_LOCAL_TO_GLOBAL_MAP=66,
1417                MATOP_SET_VALUES_LOCAL=67,
1418                MATOP_ZERO_ROWS_LOCAL=68,
1419                MATOP_GET_ROW_MAX_ABS=69,
1420                MATOP_GET_ROW_MIN_ABS=70,
1421                MATOP_CONVERT=71,
1422                MATOP_SET_COLORING=72,
1423                /* MATOP_PLACEHOLDER_73=73, */
1424                MATOP_SET_VALUES_ADIFOR=74,
1425                MATOP_FD_COLORING_APPLY=75,
1426                MATOP_SET_FROM_OPTIONS=76,
1427                MATOP_MULT_CONSTRAINED=77,
1428                MATOP_MULT_TRANSPOSE_CONSTRAIN=78,
1429                MATOP_FIND_ZERO_DIAGONALS=79,
1430                MATOP_MULT_MULTIPLE=80,
1431                MATOP_SOLVE_MULTIPLE=81,
1432                MATOP_GET_INERTIA=82,
1433                MATOP_LOAD=83,
1434                MATOP_IS_SYMMETRIC=84,
1435                MATOP_IS_HERMITIAN=85,
1436                MATOP_IS_STRUCTURALLY_SYMMETRIC=86,
1437                MATOP_SET_VALUES_BLOCKEDLOCAL=87,
1438                MATOP_GET_VECS=88,
1439                MATOP_MAT_MULT=89,
1440                MATOP_MAT_MULT_SYMBOLIC=90,
1441                MATOP_MAT_MULT_NUMERIC=91,
1442                MATOP_PTAP=92,
1443                MATOP_PTAP_SYMBOLIC=93,
1444                MATOP_PTAP_NUMERIC=94,
1445                MATOP_MAT_TRANSPOSE_MULT=95,
1446                MATOP_MAT_TRANSPOSE_MULT_SYMBO=96,
1447                MATOP_MAT_TRANSPOSE_MULT_NUMER=97,
1448                /* MATOP_PLACEHOLDER_98=98, */
1449                /* MATOP_PLACEHOLDER_99=99, */
1450                /* MATOP_PLACEHOLDER_100=100, */
1451                /* MATOP_PLACEHOLDER_101=101, */
1452                MATOP_CONJUGATE=102,
1453                /* MATOP_PLACEHOLDER_103=103, */
1454                MATOP_SET_VALUES_ROW=104,
1455                MATOP_REAL_PART=105,
1456                MATOP_IMAGINARY_PART=106,
1457                MATOP_GET_ROW_UPPER_TRIANGULAR=107,
1458                MATOP_RESTORE_ROW_UPPER_TRIANG=108,
1459                MATOP_MAT_SOLVE=109,
1460                MATOP_GET_REDUNDANT_MATRIX=110,
1461                MATOP_GET_ROW_MIN=111,
1462                MATOP_GET_COLUMN_VECTOR=112,
1463                MATOP_MISSING_DIAGONAL=113,
1464                MATOP_GET_SEQ_NONZERO_STRUCTUR=114,
1465                MATOP_CREATE=115,
1466                MATOP_GET_GHOSTS=116,
1467                MATOP_GET_LOCAL_SUB_MATRIX=117,
1468                MATOP_RESTORE_LOCALSUB_MATRIX=118,
1469                MATOP_MULT_DIAGONAL_BLOCK=119,
1470                MATOP_HERMITIAN_TRANSPOSE=120,
1471                MATOP_MULT_HERMITIAN_TRANSPOSE=121,
1472                MATOP_MULT_HERMITIAN_TRANS_ADD=122,
1473                MATOP_GET_MULTI_PROC_BLOCK=123,
1474                MATOP_FIND_NONZERO_ROWS=124,
1475                MATOP_GET_COLUMN_NORMS=125,
1476                MATOP_INVERT_BLOCK_DIAGONAL=126,
1477                /* MATOP_PLACEHOLDER_127=127, */
1478                MATOP_GET_SUB_MATRICES_PARALLE=128,
1479                MATOP_SET_VALUES_BATCH=129,
1480                MATOP_TRANSPOSE_MAT_MULT=130,
1481                MATOP_TRANSPOSE_MAT_MULT_SYMBO=131,
1482                MATOP_TRANSPOSE_MAT_MULT_NUMER=132,
1483                MATOP_TRANSPOSE_COLORING_CREAT=133,
1484                MATOP_TRANS_COLORING_APPLY_SPT=134,
1485                MATOP_TRANS_COLORING_APPLY_DEN=135,
1486                MATOP_RART=136,
1487                MATOP_RART_SYMBOLIC=137,
1488                MATOP_RART_NUMERIC=138,
1489                MATOP_SET_BLOCK_SIZES=139,
1490                MATOP_AYPX=140,
1491                MATOP_RESIDUAL=141,
1492                MATOP_FDCOLORING_SETUP=142,
1493                MATOP_MPICONCATENATESEQ=144
1494              } MatOperation;
1495 PETSC_EXTERN PetscErrorCode MatHasOperation(Mat,MatOperation,PetscBool *);
1496 PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat,MatOperation,void(*)(void));
1497 PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat,MatOperation,void(**)(void));
1498 PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat,void*);
1499 
1500 /*
1501    Codes for matrices stored on disk. By default they are
1502    stored in a universal format. By changing the format with
1503    PetscViewerSetFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will
1504    be stored in a way natural for the matrix, for example dense matrices
1505    would be stored as dense. Matrices stored this way may only be
1506    read into matrices of the same type.
1507 */
1508 #define MATRIX_BINARY_FORMAT_DENSE -1
1509 
1510 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat,PetscReal);
1511 PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat,Mat*);
1512 PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat,Mat);
1513 PETSC_EXTERN PetscErrorCode MatISGetMPIXAIJ(Mat,MatReuse,Mat*);
1514 
1515 /*S
1516      MatNullSpace - Object that removes a null space from a vector, i.e.
1517          orthogonalizes the vector to a subsapce
1518 
1519    Level: advanced
1520 
1521   Concepts: matrix; linear operator, null space
1522 
1523   Users manual sections:
1524 .   sec_singular
1525 
1526 .seealso:  MatNullSpaceCreate()
1527 S*/
1528 typedef struct _p_MatNullSpace* MatNullSpace;
1529 
1530 PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm,PetscBool ,PetscInt,const Vec[],MatNullSpace*);
1531 PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace,PetscErrorCode (*)(MatNullSpace,Vec,void*),void*);
1532 PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace*);
1533 PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace,Vec);
1534 PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *);
1535 PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat,MatNullSpace);
1536 PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat,MatNullSpace);
1537 PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat,MatNullSpace*);
1538 PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace,Mat,PetscBool  *);
1539 PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace,PetscViewer);
1540 PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace,PetscBool*,PetscInt*,const Vec**);
1541 PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec,MatNullSpace*);
1542 
1543 PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat,IS);
1544 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat,PetscReal);
1545 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat,PetscInt *);
1546 PETSC_EXTERN PetscErrorCode MatSeqBAIJInvertBlockDiagonal(Mat);
1547 
1548 PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat,PetscInt,Mat*);
1549 PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat,PetscInt,Mat*);
1550 PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat,Mat*);
1551 
1552 PETSC_EXTERN PetscErrorCode MatComputeExplicitOperator(Mat,Mat*);
1553 
1554 PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat,Vec);
1555 
1556 PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,Mat*);
1557 PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat,Vec,Vec);
1558 PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat,PetscErrorCode(*)(void*,Vec,Vec),void*);
1559 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat,PetscErrorCode (*)(void*,PetscInt,Vec,PetscScalar*));
1560 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat,PetscErrorCode (*)(void*,Vec));
1561 PETSC_EXTERN PetscErrorCode MatMFFDAddNullSpace(Mat,MatNullSpace);
1562 PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat,PetscScalar[],PetscInt);
1563 PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat);
1564 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat,PetscReal);
1565 PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat,PetscInt);
1566 PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat,PetscScalar *);
1567 PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat,const char[]);
1568 PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void*,Vec,Vec,PetscScalar*);
1569 PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat,PetscErrorCode (*)(void*,Vec,Vec,PetscScalar*),void*);
1570 
1571 /*S
1572     MatMFFD - A data structured used to manage the computation of the h differencing parameter for matrix-free
1573               Jacobian vector products
1574 
1575     Notes: MATMFFD is a specific MatType which uses the MatMFFD data structure
1576 
1577            MatMFFD*() methods actually take the Mat as their first argument. Not a MatMFFD data structure
1578 
1579     Level: developer
1580 
1581 .seealso: MATMFFD, MatCreateMFFD(), MatMFFDSetFuction(), MatMFFDSetType(), MatMFFDRegister()
1582 S*/
1583 typedef struct _p_MatMFFD* MatMFFD;
1584 
1585 /*J
1586     MatMFFDType - algorithm used to compute the h used in computing matrix-vector products via differencing of the function
1587 
1588    Level: beginner
1589 
1590 .seealso: MatMFFDSetType(), MatMFFDRegister()
1591 J*/
1592 typedef const char* MatMFFDType;
1593 #define MATMFFD_DS  "ds"
1594 #define MATMFFD_WP  "wp"
1595 
1596 PETSC_EXTERN PetscErrorCode MatMFFDSetType(Mat,MatMFFDType);
1597 PETSC_EXTERN PetscErrorCode MatMFFDRegister(const char[],PetscErrorCode (*)(MatMFFD));
1598 
1599 PETSC_EXTERN PetscErrorCode MatMFFDRegisterAll(void);
1600 PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat,PetscReal);
1601 PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat,PetscBool );
1602 
1603 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
1604 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);
1605 
1606 /*
1607    PETSc interface to MUMPS
1608 */
1609 #ifdef PETSC_HAVE_MUMPS
1610 PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat,PetscInt,PetscInt);
1611 PETSC_EXTERN PetscErrorCode MatMumpsGetIcntl(Mat,PetscInt,PetscInt*);
1612 PETSC_EXTERN PetscErrorCode MatMumpsSetCntl(Mat,PetscInt,PetscReal);
1613 PETSC_EXTERN PetscErrorCode MatMumpsGetCntl(Mat,PetscInt,PetscReal*);
1614 
1615 PETSC_EXTERN PetscErrorCode MatMumpsGetInfo(Mat,PetscInt,PetscInt*);
1616 PETSC_EXTERN PetscErrorCode MatMumpsGetInfog(Mat,PetscInt,PetscInt*);
1617 PETSC_EXTERN PetscErrorCode MatMumpsGetRinfo(Mat,PetscInt,PetscReal*);
1618 PETSC_EXTERN PetscErrorCode MatMumpsGetRinfog(Mat,PetscInt,PetscReal*);
1619 #endif
1620 
1621 /*
1622    PETSc interface to Mkl_Pardiso
1623 */
1624 #ifdef PETSC_HAVE_MKL_PARDISO
1625 PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat,PetscInt,PetscInt);
1626 #endif
1627 
1628 /*
1629    PETSc interface to Mkl_CPardiso
1630 */
1631 #ifdef PETSC_HAVE_MKL_CPARDISO
1632 PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat,PetscInt,PetscInt);
1633 #endif
1634 
1635 /*
1636    PETSc interface to SUPERLU
1637 */
1638 #ifdef PETSC_HAVE_SUPERLU
1639 PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat,PetscReal);
1640 #endif
1641 
1642 #ifdef PETSC_HAVE_CUDA
1643 /*E
1644     MatCUSPARSEStorageFormat - indicates the storage format for CUSPARSE (GPU)
1645     matrices.
1646 
1647     Not Collective
1648 
1649 +   MAT_CUSPARSE_CSR - Compressed Sparse Row
1650 .   MAT_CUSPARSE_ELL - Ellpack (requires CUDA 4.2 or later).
1651 -   MAT_CUSPARSE_HYB - Hybrid, a combination of Ellpack and Coordinate format (requires CUDA 4.2 or later).
1652 
1653     Level: intermediate
1654 
1655    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
1656 
1657 .seealso: MatCUSPARSESetFormat(), MatCUSPARSEFormatOperation
1658 E*/
1659 
1660 typedef enum {MAT_CUSPARSE_CSR, MAT_CUSPARSE_ELL, MAT_CUSPARSE_HYB} MatCUSPARSEStorageFormat;
1661 
1662 /* these will be strings associated with enumerated type defined above */
1663 PETSC_EXTERN const char *const MatCUSPARSEStorageFormats[];
1664 
1665 /*E
1666     MatCUSPARSEFormatOperation - indicates the operation of CUSPARSE (GPU)
1667     matrices whose operation should use a particular storage format.
1668 
1669     Not Collective
1670 
1671 +   MAT_CUSPARSE_MULT_DIAG - sets the storage format for the diagonal matrix in the parallel MatMult
1672 .   MAT_CUSPARSE_MULT_OFFDIAG - sets the storage format for the offdiagonal matrix in the parallel MatMult
1673 .   MAT_CUSPARSE_MULT - sets the storage format for the entire matrix in the serial (single GPU) MatMult
1674 -   MAT_CUSPARSE_ALL - sets the storage format for all CUSPARSE (GPU) matrices
1675 
1676     Level: intermediate
1677 
1678 .seealso: MatCUSPARSESetFormat(), MatCUSPARSEStorageFormat
1679 E*/
1680 typedef enum {MAT_CUSPARSE_MULT_DIAG, MAT_CUSPARSE_MULT_OFFDIAG, MAT_CUSPARSE_MULT, MAT_CUSPARSE_ALL} MatCUSPARSEFormatOperation;
1681 
1682 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSPARSE(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
1683 PETSC_EXTERN PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
1684 PETSC_EXTERN PetscErrorCode MatCUSPARSESetFormat(Mat,MatCUSPARSEFormatOperation,MatCUSPARSEStorageFormat);
1685 #endif
1686 
1687 #if defined(PETSC_HAVE_CUSP)
1688 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSP(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
1689 PETSC_EXTERN PetscErrorCode MatCreateAIJCUSP(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
1690 
1691 /*E
1692     MatCUSPStorageFormat - indicates the storage format for CUSP (GPU)
1693     matrices.
1694 
1695     Not Collective
1696 
1697 +   MAT_CUSP_CSR - Compressed Sparse Row
1698 .   MAT_CUSP_DIA - Diagonal
1699 -   MAT_CUSP_ELL - Ellpack
1700 
1701     Level: intermediate
1702 
1703    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
1704 
1705 .seealso: MatCUSPSetFormat(), MatCUSPFormatOperation
1706 E*/
1707 typedef enum {MAT_CUSP_CSR, MAT_CUSP_DIA, MAT_CUSP_ELL} MatCUSPStorageFormat;
1708 
1709 /* these will be strings associated with enumerated type defined above */
1710 PETSC_EXTERN const char *const MatCUSPStorageFormats[];
1711 
1712 /*E
1713     MatCUSPFormatOperation - indicates the operation of CUSP (GPU)
1714     matrices whose operation should use a particular storage format.
1715 
1716     Not Collective
1717 
1718 +   MAT_CUSP_MULT_DIAG - sets the storage format for the diagonal matrix in the parallel MatMult
1719 .   MAT_CUSP_MULT_OFFDIAG - sets the storage format for the offdiagonal matrix in the parallel MatMult
1720 .   MAT_CUSP_MULT - sets the storage format for the entire matrix in the serial (single GPU) MatMult
1721 -   MAT_CUSP_ALL - sets the storage format for all CUSP (GPU) matrices
1722 
1723     Level: intermediate
1724 
1725    Any additions/changes here MUST also be made in include/petsc-finclude/petscmat.h
1726 
1727 .seealso: MatCUSPSetFormat(), MatCUSPStorageFormat
1728 E*/
1729 typedef enum {MAT_CUSP_MULT_DIAG, MAT_CUSP_MULT_OFFDIAG, MAT_CUSP_MULT, MAT_CUSP_ALL} MatCUSPFormatOperation;
1730 
1731 PETSC_EXTERN PetscErrorCode MatCUSPSetFormat(Mat,MatCUSPFormatOperation,MatCUSPStorageFormat);
1732 #endif
1733 
1734 #if defined(PETSC_HAVE_VIENNACL)
1735 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJViennaCL(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Mat*);
1736 PETSC_EXTERN PetscErrorCode MatCreateAIJViennaCL(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Mat*);
1737 #endif
1738 
1739 /*
1740    PETSc interface to FFTW
1741 */
1742 #if defined(PETSC_HAVE_FFTW)
1743 PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat,Vec,Vec);
1744 PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat,Vec,Vec);
1745 PETSC_EXTERN PetscErrorCode MatCreateVecsFFTW(Mat,Vec*,Vec*,Vec*);
1746 #endif
1747 
1748 /*
1749    PETSc interface to ELEMENTAL
1750 */
1751 #if defined(PETSC_HAVE_ELEMENTAL)
1752 #if defined(__cplusplus)
1753 #include <elemental.hpp>
1754 /* c++ prototypes requiring elemental datatypes. */
1755 PETSC_EXTERN PetscErrorCode MatElementalHermitianGenDefiniteEig(elem::HermitianGenDefiniteEigType,elem::UpperOrLower,Mat,Mat,Mat*,Mat*,PetscReal,PetscReal);
1756 #endif
1757 PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
1758 PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
1759 #endif
1760 
1761 PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm,PetscInt,const IS[],PetscInt,const IS[],const Mat[],Mat*);
1762 PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat,PetscInt*,PetscInt*);
1763 PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat,IS[],IS[]);
1764 PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat,IS[],IS[]);
1765 PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat,PetscInt*,PetscInt*,Mat***);
1766 PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat,PetscInt,PetscInt,Mat*);
1767 PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat,VecType);
1768 PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat,PetscInt,const IS[],PetscInt,const IS[],const Mat[]);
1769 PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat,PetscInt,PetscInt,Mat);
1770 
1771 PETSC_EXTERN PetscErrorCode MatChop(Mat,PetscReal);
1772 PETSC_EXTERN PetscErrorCode MatComputeBandwidth(Mat,PetscReal,PetscInt*);
1773 
1774 #endif
1775