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