xref: /petsc/include/petscmat.h (revision 4ce68768e41e382c1fc596e135fd299def09fddc)
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 /*E
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
28 E*/
29 #define MATSAME            "same"
30 #define MATSEQMAIJ         "seqmaij"
31 #define MATMPIMAIJ         "mpimaij"
32 #define MATMAIJ            "maij"
33 #define MATIS              "is"
34 #define MATMPIROWBS        "mpirowbs"
35 #define MATSEQAIJ          "seqaij"
36 #define MATMPIAIJ          "mpiaij"
37 #define MATAIJ             "aij"
38 #define MATSHELL           "shell"
39 #define MATSEQBDIAG        "seqbdiag"
40 #define MATMPIBDIAG        "mpibdiag"
41 #define MATBDIAG           "bdiag"
42 #define MATSEQDENSE        "seqdense"
43 #define MATMPIDENSE        "mpidense"
44 #define MATDENSE           "dense"
45 #define MATSEQBAIJ         "seqbaij"
46 #define MATMPIBAIJ         "mpibaij"
47 #define MATBAIJ            "baij"
48 #define MATMPIADJ          "mpiadj"
49 #define MATSEQSBAIJ        "seqsbaij"
50 #define MATMPISBAIJ        "mpisbaij"
51 #define MATSBAIJ           "sbaij"
52 #define MATDAAD            "daad"
53 #define MATMFFD            "mffd"
54 #define MATESI             "esi"
55 #define MATPETSCESI        "petscesi"
56 #define MATNORMAL          "normal"
57 #define MATSEQAIJSPOOLES   "seqaijspooles"
58 #define MATMPIAIJSPOOLES   "mpiaijspooles"
59 #define MATSEQSBAIJSPOOLES "seqsbaijspooles"
60 #define MATMPISBAIJSPOOLES "mpisbaijspooles"
61 #define MATAIJSPOOLES      "aijspooles"
62 #define MATSBAIJSPOOLES    "sbaijspooles"
63 #define MATSUPERLU         "superlu"
64 #define MATSUPERLU_DIST    "superlu_dist"
65 #define MATUMFPACK         "umfpack"
66 #define MATESSL            "essl"
67 #define MATLUSOL           "lusol"
68 #define MATAIJMUMPS        "aijmumps"
69 #define MATSBAIJMUMPS      "sbaijmumps"
70 #define MATDSCPACK         "dscpack"
71 #define MATMATLAB          "matlab"
72 #define MatType char*
73 
74 /* Logging support */
75 #define    MAT_FILE_COOKIE 1211216    /* used to indicate matrices in binary files */
76 extern PetscCookie MAT_COOKIE, MATSNESMFCTX_COOKIE, MAT_FDCOLORING_COOKIE, MAT_PARTITIONING_COOKIE, MAT_NULLSPACE_COOKIE;
77 extern PetscEvent    MAT_Mult, MAT_MultMatrixFree, MAT_Mults, MAT_MultConstrained, MAT_MultAdd, MAT_MultTranspose;
78 extern PetscEvent    MAT_MultTransposeConstrained, MAT_MultTransposeAdd, MAT_Solve, MAT_Solves, MAT_SolveAdd, MAT_SolveTranspose;
79 extern PetscEvent    MAT_SolveTransposeAdd, MAT_Relax, MAT_ForwardSolve, MAT_BackwardSolve, MAT_LUFactor, MAT_LUFactorSymbolic;
80 extern PetscEvent    MAT_LUFactorNumeric, MAT_CholeskyFactor, MAT_CholeskyFactorSymbolic, MAT_CholeskyFactorNumeric, MAT_ILUFactor;
81 extern PetscEvent    MAT_ILUFactorSymbolic, MAT_ICCFactorSymbolic, MAT_Copy, MAT_Convert, MAT_Scale, MAT_AssemblyBegin;
82 extern PetscEvent    MAT_AssemblyEnd, MAT_SetValues, MAT_GetValues, MAT_GetRow, MAT_GetSubMatrices, MAT_GetColoring, MAT_GetOrdering;
83 extern PetscEvent    MAT_IncreaseOverlap, MAT_Partitioning, MAT_ZeroEntries, MAT_Load, MAT_View, MAT_AXPY, MAT_FDColoringCreate;
84 extern PetscEvent    MAT_FDColoringApply, MAT_Transpose, MAT_FDColoringFunction;
85 extern PetscEvent    MAT_MatMult, MAT_MatMultSymbolic, MAT_MatMultNumeric;
86 extern PetscEvent    MAT_PtAP, MAT_PtAPSymbolic, MAT_PtAPNumeric;
87 
88 EXTERN PetscErrorCode MatInitializePackage(char *);
89 
90 EXTERN PetscErrorCode MatCreate(MPI_Comm,int,int,int,int,Mat*);
91 EXTERN PetscErrorCode MatSetType(Mat,const MatType);
92 EXTERN PetscErrorCode MatSetFromOptions(Mat);
93 EXTERN PetscErrorCode MatSetUpPreallocation(Mat);
94 EXTERN PetscErrorCode MatRegisterAll(const char[]);
95 EXTERN PetscErrorCode MatRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat));
96 
97 /*MC
98    MatRegisterDynamic - Adds a new matrix type
99 
100    Synopsis:
101    int MatRegisterDynamic(char *name,char *path,char *name_create,PetscErrorCode (*routine_create)(Mat))
102 
103    Not Collective
104 
105    Input Parameters:
106 +  name - name of a new user-defined matrix type
107 .  path - path (either absolute or relative) the library containing this solver
108 .  name_create - name of routine to create method context
109 -  routine_create - routine to create method context
110 
111    Notes:
112    MatRegisterDynamic() may be called multiple times to add several user-defined solvers.
113 
114    If dynamic libraries are used, then the fourth input argument (routine_create)
115    is ignored.
116 
117    Sample usage:
118 .vb
119    MatRegisterDynamic("my_mat",/home/username/my_lib/lib/libO/solaris/mylib.a,
120                "MyMatCreate",MyMatCreate);
121 .ve
122 
123    Then, your solver can be chosen with the procedural interface via
124 $     MatSetType(Mat,"my_mat")
125    or at runtime via the option
126 $     -mat_type my_mat
127 
128    Level: advanced
129 
130    Notes: ${PETSC_ARCH} and ${BOPT} occuring in pathname will be replaced with appropriate values.
131          If your function is not being put into a shared library then use VecRegister() instead
132 
133 .keywords: Mat, register
134 
135 .seealso: MatRegisterAll(), MatRegisterDestroy()
136 
137 M*/
138 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
139 #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0)
140 #else
141 #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d)
142 #endif
143 
144 extern PetscTruth MatRegisterAllCalled;
145 extern PetscFList MatList;
146 
147 EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm,int,int,PetscScalar[],Mat*);
148 EXTERN PetscErrorCode MatCreateMPIDense(MPI_Comm,int,int,int,int,PetscScalar[],Mat*);
149 EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm,int,int,int,const int[],Mat*);
150 EXTERN PetscErrorCode MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,const int[],int,const int[],Mat*);
151 EXTERN PetscErrorCode MatCreateMPIRowbs(MPI_Comm,int,int,int,const int[],Mat*);
152 EXTERN PetscErrorCode MatCreateSeqBDiag(MPI_Comm,int,int,int,int,const int[],PetscScalar*[],Mat*);
153 EXTERN PetscErrorCode MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,const int[],PetscScalar*[],Mat*);
154 EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,const int[],Mat*);
155 EXTERN PetscErrorCode MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,const int[],int,const int[],Mat*);
156 EXTERN PetscErrorCode MatCreateMPIAdj(MPI_Comm,int,int,int[],int[],int[],Mat*);
157 EXTERN PetscErrorCode MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,const int[],Mat*);
158 EXTERN PetscErrorCode MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,const int[],int,const int[],Mat*);
159 EXTERN PetscErrorCode MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
160 EXTERN PetscErrorCode MatCreateAdic(MPI_Comm,int,int,int,int,int,void (*)(void),Mat*);
161 EXTERN PetscErrorCode MatCreateNormal(Mat,Mat*);
162 EXTERN PetscErrorCode MatDestroy(Mat);
163 
164 EXTERN PetscErrorCode MatPrintHelp(Mat);
165 EXTERN PetscErrorCode MatGetPetscMaps(Mat,PetscMap*,PetscMap*);
166 
167 /* ------------------------------------------------------------*/
168 EXTERN PetscErrorCode MatSetValues(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode);
169 EXTERN PetscErrorCode MatSetValuesBlocked(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode);
170 
171 /*S
172      MatStencil - Data structure (C struct) for storing information about a single row or
173         column of a matrix as index on an associated grid.
174 
175    Level: beginner
176 
177   Concepts: matrix; linear operator
178 
179 .seealso:  MatSetValuesStencil(), MatSetStencil(), MatSetValuesBlockStencil()
180 S*/
181 typedef struct {
182   int k,j,i,c;
183 } MatStencil;
184 
185 EXTERN PetscErrorCode MatSetValuesStencil(Mat,int,const MatStencil[],int,const MatStencil[],const PetscScalar[],InsertMode);
186 EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat,int,const MatStencil[],int,const MatStencil[],const PetscScalar[],InsertMode);
187 EXTERN PetscErrorCode MatSetStencil(Mat,int,const int[],const int[],int);
188 
189 EXTERN PetscErrorCode MatSetColoring(Mat,ISColoring);
190 EXTERN PetscErrorCode MatSetValuesAdic(Mat,void*);
191 EXTERN PetscErrorCode MatSetValuesAdifor(Mat,int,void*);
192 
193 /*E
194     MatAssemblyType - Indicates if the matrix is now to be used, or if you plan
195      to continue to add values to it
196 
197     Level: beginner
198 
199 .seealso: MatAssemblyBegin(), MatAssemblyEnd()
200 E*/
201 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
202 EXTERN PetscErrorCode MatAssemblyBegin(Mat,MatAssemblyType);
203 EXTERN PetscErrorCode MatAssemblyEnd(Mat,MatAssemblyType);
204 EXTERN PetscErrorCode MatAssembled(Mat,PetscTruth*);
205 
206 extern int         MatSetValue_Row, MatSetValue_Column;
207 extern PetscScalar MatSetValue_Value;
208 
209 /*MC
210    MatSetValue - Set a single entry into a matrix.
211 
212    Synopsis:
213    int MatSetValue(Mat m,int row,int col,PetscScalar value,InsertMode mode);
214 
215    Not collective
216 
217    Input Parameters:
218 +  m - the matrix
219 .  row - the row location of the entry
220 .  col - the column location of the entry
221 .  value - the value to insert
222 -  mode - either INSERT_VALUES or ADD_VALUES
223 
224    Notes:
225    For efficiency one should use MatSetValues() and set several or many
226    values simultaneously if possible.
227 
228    Level: beginner
229 
230 .seealso: MatSetValues(), MatSetValueLocal()
231 M*/
232 #define MatSetValue(v,i,j,va,mode) \
233   (MatSetValue_Row = i,MatSetValue_Column = j,MatSetValue_Value = va, \
234    MatSetValues(v,1,&MatSetValue_Row,1,&MatSetValue_Column,&MatSetValue_Value,mode))
235 
236 #define MatGetValue(v,i,j,va) \
237   (MatSetValue_Row = i,MatSetValue_Column = j,\
238    MatGetValues(v,1,&MatSetValue_Row,1,&MatSetValue_Column,&va))
239 
240 #define MatSetValueLocal(v,i,j,va,mode) \
241   (MatSetValue_Row = i,MatSetValue_Column = j,MatSetValue_Value = va, \
242    MatSetValuesLocal(v,1,&MatSetValue_Row,1,&MatSetValue_Column,&MatSetValue_Value,mode))
243 
244 /*E
245     MatOption - Options that may be set for a matrix and its behavior or storage
246 
247     Level: beginner
248 
249    Any additions/changes here MUST also be made in include/finclude/petscmat.h
250 
251 .seealso: MatSetOption()
252 E*/
253 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
254               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
255               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
256               MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66,
257               MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69,
258               MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72,
259               MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74,
260               MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76,
261               MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78,
262               MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81,
263               MAT_DO_NOT_USE_INODES=82,MAT_NOT_SYMMETRIC=83,MAT_HERMITIAN=84,
264               MAT_NOT_STRUCTURALLY_SYMMETRIC=85,MAT_NOT_HERMITIAN=86,
265               MAT_SYMMETRY_ETERNAL=87,MAT_NOT_SYMMETRY_ETERNAL=88} MatOption;
266 EXTERN PetscErrorCode MatSetOption(Mat,MatOption);
267 EXTERN PetscErrorCode MatGetType(Mat,MatType*);
268 
269 EXTERN PetscErrorCode MatGetValues(Mat,int,const int[],int,const int[],PetscScalar[]);
270 EXTERN PetscErrorCode MatGetRow(Mat,int,int *,const int *[],const PetscScalar*[]);
271 EXTERN PetscErrorCode MatRestoreRow(Mat,int,int *,const int *[],const PetscScalar*[]);
272 EXTERN PetscErrorCode MatGetColumn(Mat,int,int *,int *[],PetscScalar*[]);
273 EXTERN PetscErrorCode MatRestoreColumn(Mat,int,int *,int *[],PetscScalar*[]);
274 EXTERN PetscErrorCode MatGetColumnVector(Mat,Vec,int);
275 EXTERN PetscErrorCode MatGetArray(Mat,PetscScalar *[]);
276 EXTERN PetscErrorCode MatRestoreArray(Mat,PetscScalar *[]);
277 EXTERN PetscErrorCode MatGetBlockSize(Mat,int *);
278 
279 EXTERN PetscErrorCode MatMult(Mat,Vec,Vec);
280 EXTERN PetscErrorCode MatMultAdd(Mat,Vec,Vec,Vec);
281 EXTERN PetscErrorCode MatMultTranspose(Mat,Vec,Vec);
282 EXTERN PetscErrorCode MatIsTranspose(Mat,Mat,PetscReal,PetscTruth*);
283 EXTERN PetscErrorCode MatMultTransposeAdd(Mat,Vec,Vec,Vec);
284 EXTERN PetscErrorCode MatMultConstrained(Mat,Vec,Vec);
285 EXTERN PetscErrorCode MatMultTransposeConstrained(Mat,Vec,Vec);
286 
287 /*E
288     MatDuplicateOption - Indicates if a duplicated sparse matrix should have
289   its numerical values copied over or just its nonzero structure.
290 
291     Level: beginner
292 
293    Any additions/changes here MUST also be made in include/finclude/petscmat.h
294 
295 .seealso: MatDuplicate()
296 E*/
297 typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption;
298 
299 EXTERN PetscErrorCode MatConvertRegister(const char[],const char[],const char[],PetscErrorCode (*)(Mat,MatType,Mat*));
300 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
301 #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,0)
302 #else
303 #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,d)
304 #endif
305 EXTERN PetscErrorCode        MatConvertRegisterAll(const char[]);
306 EXTERN PetscErrorCode        MatConvertRegisterDestroy(void);
307 extern PetscTruth MatConvertRegisterAllCalled;
308 extern PetscFList MatConvertList;
309 EXTERN PetscErrorCode        MatConvert(Mat,const MatType,Mat*);
310 EXTERN PetscErrorCode        MatDuplicate(Mat,MatDuplicateOption,Mat*);
311 
312 /*E
313     MatStructure - Indicates if the matrix has the same nonzero structure
314 
315     Level: beginner
316 
317    Any additions/changes here MUST also be made in include/finclude/petscmat.h
318 
319 .seealso: MatCopy(), KSPSetOperators(), PCSetOperators()
320 E*/
321 typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER,SUBSET_NONZERO_PATTERN} MatStructure;
322 
323 EXTERN PetscErrorCode MatCopy(Mat,Mat,MatStructure);
324 EXTERN PetscErrorCode MatView(Mat,PetscViewer);
325 EXTERN PetscErrorCode MatIsSymmetric(Mat,PetscReal,PetscTruth*);
326 EXTERN PetscErrorCode MatIsSymmetricKnown(Mat,PetscTruth*,PetscTruth*);
327 EXTERN PetscErrorCode MatLoad(PetscViewer,const MatType,Mat*);
328 
329 EXTERN PetscErrorCode MatGetRowIJ(Mat,int,PetscTruth,int*,int *[],int *[],PetscTruth *);
330 EXTERN PetscErrorCode MatRestoreRowIJ(Mat,int,PetscTruth,int *,int *[],int *[],PetscTruth *);
331 EXTERN PetscErrorCode MatGetColumnIJ(Mat,int,PetscTruth,int*,int *[],int *[],PetscTruth *);
332 EXTERN PetscErrorCode MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int *[],int *[],PetscTruth *);
333 
334 /*S
335      MatInfo - Context of matrix information, used with MatGetInfo()
336 
337    In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE
338 
339    Level: intermediate
340 
341   Concepts: matrix^nonzero information
342 
343 .seealso:  MatGetInfo(), MatInfoType
344 S*/
345 typedef struct {
346   PetscLogDouble rows_global,columns_global;         /* number of global rows and columns */
347   PetscLogDouble rows_local,columns_local;           /* number of local rows and columns */
348   PetscLogDouble block_size;                         /* block size */
349   PetscLogDouble nz_allocated,nz_used,nz_unneeded;   /* number of nonzeros */
350   PetscLogDouble memory;                             /* memory allocated */
351   PetscLogDouble assemblies;                         /* number of matrix assemblies called */
352   PetscLogDouble mallocs;                            /* number of mallocs during MatSetValues() */
353   PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
354   PetscLogDouble factor_mallocs;                     /* number of mallocs during factorization */
355 } MatInfo;
356 
357 /*E
358     MatInfoType - Indicates if you want information about the local part of the matrix,
359      the entire parallel matrix or the maximum over all the local parts.
360 
361     Level: beginner
362 
363    Any additions/changes here MUST also be made in include/finclude/petscmat.h
364 
365 .seealso: MatGetInfo(), MatInfo
366 E*/
367 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
368 EXTERN PetscErrorCode MatGetInfo(Mat,MatInfoType,MatInfo*);
369 EXTERN PetscErrorCode MatValid(Mat,PetscTruth*);
370 EXTERN PetscErrorCode MatGetDiagonal(Mat,Vec);
371 EXTERN PetscErrorCode MatGetRowMax(Mat,Vec);
372 EXTERN PetscErrorCode MatTranspose(Mat,Mat*);
373 EXTERN PetscErrorCode MatPermute(Mat,IS,IS,Mat *);
374 EXTERN PetscErrorCode MatPermuteSparsify(Mat,int,PetscReal,PetscReal,IS,IS,Mat *);
375 EXTERN PetscErrorCode MatDiagonalScale(Mat,Vec,Vec);
376 EXTERN PetscErrorCode MatDiagonalSet(Mat,Vec,InsertMode);
377 EXTERN PetscErrorCode MatEqual(Mat,Mat,PetscTruth*);
378 
379 EXTERN PetscErrorCode MatNorm(Mat,NormType,PetscReal *);
380 EXTERN PetscErrorCode MatZeroEntries(Mat);
381 EXTERN PetscErrorCode MatZeroRows(Mat,IS,const PetscScalar*);
382 EXTERN PetscErrorCode MatZeroColumns(Mat,IS,const PetscScalar*);
383 
384 EXTERN PetscErrorCode MatUseScaledForm(Mat,PetscTruth);
385 EXTERN PetscErrorCode MatScaleSystem(Mat,Vec,Vec);
386 EXTERN PetscErrorCode MatUnScaleSystem(Mat,Vec,Vec);
387 
388 EXTERN PetscErrorCode MatGetSize(Mat,int*,int*);
389 EXTERN PetscErrorCode MatGetLocalSize(Mat,int*,int*);
390 EXTERN PetscErrorCode MatGetOwnershipRange(Mat,int*,int*);
391 
392 /*E
393     MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices()
394      or MatGetSubMatrix() are to be reused to store the new matrix values.
395 
396     Level: beginner
397 
398    Any additions/changes here MUST also be made in include/finclude/petscmat.h
399 
400 .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices()
401 E*/
402 typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse;
403 EXTERN PetscErrorCode MatGetSubMatrices(Mat,int,const IS[],const IS[],MatReuse,Mat *[]);
404 EXTERN PetscErrorCode MatDestroyMatrices(int,Mat *[]);
405 EXTERN PetscErrorCode MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *);
406 EXTERN PetscErrorCode MatMerge(MPI_Comm,Mat,MatReuse,Mat*);
407 EXTERN PetscErrorCode MatMerge_SeqsToMPI(MPI_Comm,Mat,MatReuse,Mat*);
408 
409 EXTERN PetscErrorCode MatIncreaseOverlap(Mat,int,IS[],int);
410 
411 EXTERN PetscErrorCode MatMatMult(Mat,Mat,MatReuse,PetscReal,Mat*);
412 EXTERN PetscErrorCode MatMatMultSymbolic(Mat,Mat,PetscReal,Mat*);
413 EXTERN PetscErrorCode MatMatMultNumeric(Mat,Mat,Mat);
414 
415 EXTERN PetscErrorCode MatPtAP(Mat,Mat,MatReuse,PetscReal,Mat*);
416 EXTERN PetscErrorCode MatPtAPSymbolic(Mat,Mat,PetscReal,Mat*);
417 EXTERN PetscErrorCode MatPtAPNumeric(Mat,Mat,Mat);
418 
419 EXTERN PetscErrorCode MatAXPY(const PetscScalar *,Mat,Mat,MatStructure);
420 EXTERN PetscErrorCode MatAYPX(const PetscScalar *,Mat,Mat);
421 EXTERN PetscErrorCode MatCompress(Mat);
422 
423 EXTERN PetscErrorCode MatScale(const PetscScalar *,Mat);
424 EXTERN PetscErrorCode MatShift(const PetscScalar *,Mat);
425 
426 EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping);
427 EXTERN PetscErrorCode MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping);
428 EXTERN PetscErrorCode MatZeroRowsLocal(Mat,IS,const PetscScalar*);
429 EXTERN PetscErrorCode MatSetValuesLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode);
430 EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode);
431 
432 EXTERN PetscErrorCode MatStashSetInitialSize(Mat,int,int);
433 EXTERN PetscErrorCode MatStashGetInfo(Mat,int*,int*,int*,int*);
434 
435 EXTERN PetscErrorCode MatInterpolateAdd(Mat,Vec,Vec,Vec);
436 EXTERN PetscErrorCode MatInterpolate(Mat,Vec,Vec);
437 EXTERN PetscErrorCode MatRestrict(Mat,Vec,Vec);
438 EXTERN PetscErrorCode MatGetVecs(Mat,Vec*,Vec*);
439 
440 /*MC
441    MatPreallocInitialize - Begins the block of code that will count the number of nonzeros per
442        row in a matrix providing the data that one can use to correctly preallocate the matrix.
443 
444    Synopsis:
445    int MatPreallocateInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz)
446 
447    Collective on MPI_Comm
448 
449    Input Parameters:
450 +  comm - the communicator that will share the eventually allocated matrix
451 .  nrows - the number of rows in the matrix
452 -  ncols - the number of columns in the matrix
453 
454    Output Parameters:
455 +  dnz - the array that will be passed to the matrix preallocation routines
456 -  ozn - the other array passed to the matrix preallocation routines
457 
458 
459    Level: intermediate
460 
461    Notes:
462    See the chapter in the users manual on performance for more details
463 
464    Do not malloc or free dnz and onz, that is handled internally by these routines
465 
466    Use MatPreallocateInitializeSymmetric() for symmetric matrices (MPISBAIJ matrices)
467 
468   Concepts: preallocation^Matrix
469 
470 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
471           MatPreallocateInitializeSymmetric(), MatPreallocateSymmetricSetLocal()
472 M*/
473 #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \
474 { \
475   PetscErrorCode _4_ierr; int __tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
476   _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\
477   _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\
478   _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\
479   _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp;
480 
481 /*MC
482    MatPreallocSymmetricInitialize - Begins the block of code that will count the number of nonzeros per
483        row in a matrix providing the data that one can use to correctly preallocate the matrix.
484 
485    Synopsis:
486    int MatPreallocateSymmetricInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz)
487 
488    Collective on MPI_Comm
489 
490    Input Parameters:
491 +  comm - the communicator that will share the eventually allocated matrix
492 .  nrows - the number of rows in the matrix
493 -  ncols - the number of columns in the matrix
494 
495    Output Parameters:
496 +  dnz - the array that will be passed to the matrix preallocation routines
497 -  ozn - the other array passed to the matrix preallocation routines
498 
499 
500    Level: intermediate
501 
502    Notes:
503    See the chapter in the users manual on performance for more details
504 
505    Do not malloc or free dnz and onz, that is handled internally by these routines
506 
507   Concepts: preallocation^Matrix
508 
509 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
510           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal()
511 M*/
512 #define MatPreallocateSymmetricInitialize(comm,nrows,ncols,dnz,onz) 0; \
513 { \
514   PetscErrorCode _4_ierr; int __tmp = (nrows),__ctmp = (ncols),__rstart,__end; \
515   _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\
516   _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\
517   _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr);\
518   _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp;
519 
520 /*MC
521    MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
522        inserted using a local number of the rows and columns
523 
524    Synopsis:
525    int MatPreallocateSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz)
526 
527    Not Collective
528 
529    Input Parameters:
530 +  map - the mapping between local numbering and global numbering
531 .  nrows - the number of rows indicated
532 .  rows - the indices of the rows
533 .  ncols - the number of columns in the matrix
534 .  cols - the columns indicated
535 .  dnz - the array that will be passed to the matrix preallocation routines
536 -  ozn - the other array passed to the matrix preallocation routines
537 
538 
539    Level: intermediate
540 
541    Notes:
542    See the chapter in the users manual on performance for more details
543 
544    Do not malloc or free dnz and onz, that is handled internally by these routines
545 
546   Concepts: preallocation^Matrix
547 
548 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
549           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal()
550 M*/
551 #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\
552 {\
553   int __l;\
554   _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\
555   _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\
556   for (__l=0;__l<nrows;__l++) {\
557     _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
558   }\
559 }
560 
561 /*MC
562    MatPreallocateSymmetricSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
563        inserted using a local number of the rows and columns
564 
565    Synopsis:
566    int MatPreallocateSymmetricSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz)
567 
568    Not Collective
569 
570    Input Parameters:
571 +  map - the mapping between local numbering and global numbering
572 .  nrows - the number of rows indicated
573 .  rows - the indices of the rows
574 .  ncols - the number of columns in the matrix
575 .  cols - the columns indicated
576 .  dnz - the array that will be passed to the matrix preallocation routines
577 -  ozn - the other array passed to the matrix preallocation routines
578 
579 
580    Level: intermediate
581 
582    Notes:
583    See the chapter in the users manual on performance for more details
584 
585    Do not malloc or free dnz and onz that is handled internally by these routines
586 
587   Concepts: preallocation^Matrix
588 
589 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
590           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
591 M*/
592 #define MatPreallocateSymmetricSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\
593 {\
594   int __l;\
595   _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\
596   _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\
597   for (__l=0;__l<nrows;__l++) {\
598     _4_ierr = MatPreallocateSymmetricSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\
599   }\
600 }
601 
602 /*MC
603    MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
604        inserted using a local number of the rows and columns
605 
606    Synopsis:
607    int MatPreallocateSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz)
608 
609    Not Collective
610 
611    Input Parameters:
612 +  nrows - the number of rows indicated
613 .  rows - the indices of the rows
614 .  ncols - the number of columns in the matrix
615 -  cols - the columns indicated
616 
617    Output Parameters:
618 +  dnz - the array that will be passed to the matrix preallocation routines
619 -  ozn - the other array passed to the matrix preallocation routines
620 
621 
622    Level: intermediate
623 
624    Notes:
625    See the chapter in the users manual on performance for more details
626 
627    Do not malloc or free dnz and onz that is handled internally by these routines
628 
629   Concepts: preallocation^Matrix
630 
631 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
632           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
633 M*/
634 #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\
635 { int __i; \
636   for (__i=0; __i<nc; __i++) {\
637     if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \
638   }\
639   dnz[row - __rstart] = nc - onz[row - __rstart];\
640 }
641 
642 /*MC
643    MatPreallocateSymmetricSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
644        inserted using a local number of the rows and columns
645 
646    Synopsis:
647    int MatPreallocateSymmetricSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz)
648 
649    Not Collective
650 
651    Input Parameters:
652 +  nrows - the number of rows indicated
653 .  rows - the indices of the rows
654 .  ncols - the number of columns in the matrix
655 .  cols - the columns indicated
656 .  dnz - the array that will be passed to the matrix preallocation routines
657 -  ozn - the other array passed to the matrix preallocation routines
658 
659 
660    Level: intermediate
661 
662    Notes:
663    See the chapter in the users manual on performance for more details
664 
665    Do not malloc or free dnz and onz that is handled internally by these routines
666 
667   Concepts: preallocation^Matrix
668 
669 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(),
670           MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal()
671 M*/
672 #define MatPreallocateSymmetricSet(row,nc,cols,dnz,onz) 0;\
673 { int __i; \
674   for (__i=0; __i<nc; __i++) {\
675     if (cols[__i] >= __end) onz[row - __rstart]++; \
676     else if (cols[__i] >= row) dnz[row - __rstart]++;\
677   }\
678 }
679 
680 /*MC
681    MatPreallocFinalize - Ends the block of code that will count the number of nonzeros per
682        row in a matrix providing the data that one can use to correctly preallocate the matrix.
683 
684    Synopsis:
685    int MatPreallocateFinalize(int *dnz, int *onz)
686 
687    Collective on MPI_Comm
688 
689    Input Parameters:
690 +  dnz - the array that will be passed to the matrix preallocation routines
691 -  ozn - the other array passed to the matrix preallocation routines
692 
693 
694    Level: intermediate
695 
696    Notes:
697    See the chapter in the users manual on performance for more details
698 
699    Do not malloc or free dnz and onz that is handled internally by these routines
700 
701   Concepts: preallocation^Matrix
702 
703 .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(),
704           MatPreallocateSymmetricInitialize(), MatPreallocateSymmetricSetLocal()
705 M*/
706 #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree(dnz);CHKERRQ(_4_ierr);}
707 
708 
709 
710 /* Routines unique to particular data structures */
711 EXTERN PetscErrorCode MatShellGetContext(Mat,void **);
712 
713 EXTERN PetscErrorCode MatBDiagGetData(Mat,int*,int*,int*[],int*[],PetscScalar***);
714 EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat,int[]);
715 EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat,int[]);
716 EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int[],int[],PetscScalar[],Mat*);
717 
718 EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat,int,int,const int[]);
719 EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat,int,int,const int[]);
720 EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat,int,const int[]);
721 EXTERN PetscErrorCode MatSeqDensePreallocation(Mat,PetscScalar[]);
722 EXTERN PetscErrorCode MatSeqBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]);
723 EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat,PetscScalar[]);
724 
725 EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]);
726 EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]);
727 EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat,int,const int[],int,const int[]);
728 EXTERN PetscErrorCode MatMPIDensePreallocation(Mat,PetscScalar[]);
729 EXTERN PetscErrorCode MatMPIBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]);
730 EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat,int[],int[],int[]);
731 EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat,PetscScalar[]);
732 EXTERN PetscErrorCode MatMPIRowbsSetPreallocation(Mat,int,const int[]);
733 EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,int*[]);
734 EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,int*[]);
735 EXTERN PetscErrorCode MatAdicSetLocalFunction(Mat,void (*)(void));
736 
737 EXTERN PetscErrorCode MatSeqDenseSetLDA(Mat,int);
738 
739 EXTERN PetscErrorCode MatStoreValues(Mat);
740 EXTERN PetscErrorCode MatRetrieveValues(Mat);
741 
742 EXTERN PetscErrorCode MatDAADSetCtx(Mat,void*);
743 
744 /*
745   These routines are not usually accessed directly, rather solving is
746   done through the KSP and PC interfaces.
747 */
748 
749 /*E
750     MatOrderingType - String with the name of a PETSc matrix ordering or the creation function
751        with an optional dynamic library name, for example
752        http://www.mcs.anl.gov/petsc/lib.a:orderingcreate()
753 
754    Level: beginner
755 
756 .seealso: MatGetOrdering()
757 E*/
758 #define MatOrderingType char*
759 #define MATORDERING_NATURAL   "natural"
760 #define MATORDERING_ND        "nd"
761 #define MATORDERING_1WD       "1wd"
762 #define MATORDERING_RCM       "rcm"
763 #define MATORDERING_QMD       "qmd"
764 #define MATORDERING_ROWLENGTH "rowlength"
765 #define MATORDERING_DSC_ND    "dsc_nd"
766 #define MATORDERING_DSC_MMD   "dsc_mmd"
767 #define MATORDERING_DSC_MDF   "dsc_mdf"
768 #define MATORDERING_CONSTRAINED "constrained"
769 #define MATORDERING_IDENTITY  "identity"
770 #define MATORDERING_REVERSE   "reverse"
771 
772 EXTERN PetscErrorCode MatGetOrdering(Mat,const MatOrderingType,IS*,IS*);
773 EXTERN PetscErrorCode MatOrderingRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,const MatOrderingType,IS*,IS*));
774 
775 /*MC
776    MatOrderingRegisterDynamic - Adds a new sparse matrix ordering to the
777                                matrix package.
778 
779    Synopsis:
780    int MatOrderingRegisterDynamic(char *name_ordering,char *path,char *name_create,PetscErrorCode (*routine_create)(MatOrdering))
781 
782    Not Collective
783 
784    Input Parameters:
785 +  sname - name of ordering (for example MATORDERING_ND)
786 .  path - location of library where creation routine is
787 .  name - name of function that creates the ordering type,a string
788 -  function - function pointer that creates the ordering
789 
790    Level: developer
791 
792    If dynamic libraries are used, then the fourth input argument (function)
793    is ignored.
794 
795    Sample usage:
796 .vb
797    MatOrderingRegisterDynamic("my_order",/home/username/my_lib/lib/libO/solaris/mylib.a,
798                "MyOrder",MyOrder);
799 .ve
800 
801    Then, your partitioner can be chosen with the procedural interface via
802 $     MatOrderingSetType(part,"my_order)
803    or at runtime via the option
804 $     -pc_ilu_mat_ordering_type my_order
805 $     -pc_lu_mat_ordering_type my_order
806 
807    ${PETSC_ARCH} and ${BOPT} occuring in pathname will be replaced with appropriate values.
808 
809 .keywords: matrix, ordering, register
810 
811 .seealso: MatOrderingRegisterDestroy(), MatOrderingRegisterAll()
812 M*/
813 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
814 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0)
815 #else
816 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d)
817 #endif
818 
819 EXTERN PetscErrorCode        MatOrderingRegisterDestroy(void);
820 EXTERN PetscErrorCode        MatOrderingRegisterAll(const char[]);
821 extern PetscTruth MatOrderingRegisterAllCalled;
822 extern PetscFList MatOrderingList;
823 
824 EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS);
825 
826 /*S
827    MatFactorInfo - Data based into the matrix factorization routines
828 
829    In Fortran these are simply double precision arrays of size MAT_FACTORINFO_SIZE
830 
831    Notes: These are not usually directly used by users, instead use PC type of LU, ILU, CHOLESKY or ICC.
832 
833    Level: developer
834 
835 .seealso: MatLUFactorSymbolic(), MatILUFactorSymbolic(), MatCholeskyFactorSymbolic(), MatICCFactorSymbolic(), MatICCFactor()
836 
837 S*/
838 typedef struct {
839   PetscReal     damping;        /* scaling of identity added to matrix to prevent zero pivots */
840   PetscReal     shift;          /* if true, shift until positive pivots */
841   PetscReal     shift_fraction; /* record shift fraction taken */
842   PetscReal     diagonal_fill;  /* force diagonal to fill in if initially not filled */
843   PetscReal     dt;             /* drop tolerance */
844   PetscReal     dtcol;          /* tolerance for pivoting */
845   PetscReal     dtcount;        /* maximum nonzeros to be allowed per row */
846   PetscReal     fill;           /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/
847   PetscReal     levels;         /* ICC/ILU(levels) */
848   PetscReal     pivotinblocks;  /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0
849                                    factorization may be faster if do not pivot */
850   PetscReal     zeropivot;      /* pivot is called zero if less than this */
851 } MatFactorInfo;
852 
853 EXTERN PetscErrorCode MatCholeskyFactor(Mat,IS,MatFactorInfo*);
854 EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*);
855 EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat,Mat*);
856 EXTERN PetscErrorCode MatLUFactor(Mat,IS,IS,MatFactorInfo*);
857 EXTERN PetscErrorCode MatILUFactor(Mat,IS,IS,MatFactorInfo*);
858 EXTERN PetscErrorCode MatLUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*);
859 EXTERN PetscErrorCode MatILUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*);
860 EXTERN PetscErrorCode MatICCFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*);
861 EXTERN PetscErrorCode MatICCFactor(Mat,IS,MatFactorInfo*);
862 EXTERN PetscErrorCode MatLUFactorNumeric(Mat,Mat*);
863 EXTERN PetscErrorCode MatILUDTFactor(Mat,MatFactorInfo*,IS,IS,Mat *);
864 EXTERN PetscErrorCode MatGetInertia(Mat,int*,int*,int*);
865 EXTERN PetscErrorCode MatSolve(Mat,Vec,Vec);
866 EXTERN PetscErrorCode MatForwardSolve(Mat,Vec,Vec);
867 EXTERN PetscErrorCode MatBackwardSolve(Mat,Vec,Vec);
868 EXTERN PetscErrorCode MatSolveAdd(Mat,Vec,Vec,Vec);
869 EXTERN PetscErrorCode MatSolveTranspose(Mat,Vec,Vec);
870 EXTERN PetscErrorCode MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
871 EXTERN PetscErrorCode MatSolves(Mat,Vecs,Vecs);
872 
873 EXTERN PetscErrorCode MatSetUnfactored(Mat);
874 
875 /*E
876     MatSORType - What type of (S)SOR to perform
877 
878     Level: beginner
879 
880    May be bitwise ORd together
881 
882    Any additions/changes here MUST also be made in include/finclude/petscmat.h
883 
884    MatSORType may be bitwise ORd together, so do not change the numbers
885 
886 .seealso: MatRelax(), MatPBRelax()
887 E*/
888 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
889               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
890               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
891               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
892 EXTERN PetscErrorCode MatRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec);
893 EXTERN PetscErrorCode MatPBRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec);
894 
895 /*
896     These routines are for efficiently computing Jacobians via finite differences.
897 */
898 
899 /*E
900     MatColoringType - String with the name of a PETSc matrix coloring or the creation function
901        with an optional dynamic library name, for example
902        http://www.mcs.anl.gov/petsc/lib.a:coloringcreate()
903 
904    Level: beginner
905 
906 .seealso: MatGetColoring()
907 E*/
908 #define MatColoringType char*
909 #define MATCOLORING_NATURAL "natural"
910 #define MATCOLORING_SL      "sl"
911 #define MATCOLORING_LF      "lf"
912 #define MATCOLORING_ID      "id"
913 
914 EXTERN PetscErrorCode MatGetColoring(Mat,const MatColoringType,ISColoring*);
915 EXTERN PetscErrorCode MatColoringRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,const MatColoringType,ISColoring *));
916 
917 /*MC
918    MatColoringRegisterDynamic - Adds a new sparse matrix coloring to the
919                                matrix package.
920 
921    Synopsis:
922    int MatColoringRegisterDynamic(char *name_coloring,char *path,char *name_create,PetscErrorCode (*routine_create)(MatColoring))
923 
924    Not Collective
925 
926    Input Parameters:
927 +  sname - name of Coloring (for example MATCOLORING_SL)
928 .  path - location of library where creation routine is
929 .  name - name of function that creates the Coloring type, a string
930 -  function - function pointer that creates the coloring
931 
932    Level: developer
933 
934    If dynamic libraries are used, then the fourth input argument (function)
935    is ignored.
936 
937    Sample usage:
938 .vb
939    MatColoringRegisterDynamic("my_color",/home/username/my_lib/lib/libO/solaris/mylib.a,
940                "MyColor",MyColor);
941 .ve
942 
943    Then, your partitioner can be chosen with the procedural interface via
944 $     MatColoringSetType(part,"my_color")
945    or at runtime via the option
946 $     -mat_coloring_type my_color
947 
948    $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
949 
950 .keywords: matrix, Coloring, register
951 
952 .seealso: MatColoringRegisterDestroy(), MatColoringRegisterAll()
953 M*/
954 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
955 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0)
956 #else
957 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d)
958 #endif
959 
960 EXTERN PetscErrorCode        MatColoringRegisterAll(const char[]);
961 extern PetscTruth MatColoringRegisterAllCalled;
962 EXTERN PetscErrorCode        MatColoringRegisterDestroy(void);
963 EXTERN PetscErrorCode        MatColoringPatch(Mat,int,int,const ISColoringValue[],ISColoring*);
964 
965 /*S
966      MatFDColoring - Object for computing a sparse Jacobian via finite differences
967         and coloring
968 
969    Level: beginner
970 
971   Concepts: coloring, sparse Jacobian, finite differences
972 
973 .seealso:  MatFDColoringCreate()
974 S*/
975 typedef struct _p_MatFDColoring *MatFDColoring;
976 
977 EXTERN PetscErrorCode MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
978 EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring);
979 EXTERN PetscErrorCode MatFDColoringView(MatFDColoring,PetscViewer);
980 EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring,PetscErrorCode (*)(void),void*);
981 EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal);
982 EXTERN PetscErrorCode MatFDColoringSetFrequency(MatFDColoring,int);
983 EXTERN PetscErrorCode MatFDColoringGetFrequency(MatFDColoring,int*);
984 EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring);
985 EXTERN PetscErrorCode MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *);
986 EXTERN PetscErrorCode MatFDColoringApplyTS(Mat,MatFDColoring,PetscReal,Vec,MatStructure*,void *);
987 EXTERN PetscErrorCode MatFDColoringSetRecompute(MatFDColoring);
988 EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring,Vec);
989 EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring,int*,int*[]);
990 /*
991     These routines are for partitioning matrices: currently used only
992   for adjacency matrix, MatCreateMPIAdj().
993 */
994 
995 /*S
996      MatPartitioning - Object for managing the partitioning of a matrix or graph
997 
998    Level: beginner
999 
1000   Concepts: partitioning
1001 
1002 .seealso:  MatPartitioningCreate(), MatPartitioningType
1003 S*/
1004 typedef struct _p_MatPartitioning *MatPartitioning;
1005 
1006 /*E
1007     MatPartitioningType - String with the name of a PETSc matrix partitioning or the creation function
1008        with an optional dynamic library name, for example
1009        http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate()
1010 
1011    Level: beginner
1012 
1013 .seealso: MatPartitioningCreate(), MatPartitioning
1014 E*/
1015 #define MatPartitioningType char*
1016 #define MAT_PARTITIONING_CURRENT  "current"
1017 #define MAT_PARTITIONING_PARMETIS "parmetis"
1018 #define MAT_PARTITIONING_CHACO    "chaco"
1019 #define MAT_PARTITIONING_JOSTLE   "jostle"
1020 #define MAT_PARTITIONING_PARTY    "party"
1021 #define MAT_PARTITIONING_SCOTCH   "scotch"
1022 
1023 
1024 EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm,MatPartitioning*);
1025 EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning,const MatPartitioningType);
1026 EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning,int);
1027 EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning,Mat);
1028 EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning,const int[]);
1029 EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning,const PetscReal []);
1030 EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning,IS*);
1031 EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning);
1032 
1033 EXTERN PetscErrorCode MatPartitioningRegister(const char[],const char[],const char[],PetscErrorCode (*)(MatPartitioning));
1034 
1035 /*MC
1036    MatPartitioningRegisterDynamic - Adds a new sparse matrix partitioning to the
1037    matrix package.
1038 
1039    Synopsis:
1040    int MatPartitioningRegisterDynamic(char *name_partitioning,char *path,char *name_create,PetscErrorCode (*routine_create)(MatPartitioning))
1041 
1042    Not Collective
1043 
1044    Input Parameters:
1045 +  sname - name of partitioning (for example MAT_PARTITIONING_CURRENT) or parmetis
1046 .  path - location of library where creation routine is
1047 .  name - name of function that creates the partitioning type, a string
1048 -  function - function pointer that creates the partitioning type
1049 
1050    Level: developer
1051 
1052    If dynamic libraries are used, then the fourth input argument (function)
1053    is ignored.
1054 
1055    Sample usage:
1056 .vb
1057    MatPartitioningRegisterDynamic("my_part",/home/username/my_lib/lib/libO/solaris/mylib.a,
1058                "MyPartCreate",MyPartCreate);
1059 .ve
1060 
1061    Then, your partitioner can be chosen with the procedural interface via
1062 $     MatPartitioningSetType(part,"my_part")
1063    or at runtime via the option
1064 $     -mat_partitioning_type my_part
1065 
1066    $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
1067 
1068 .keywords: matrix, partitioning, register
1069 
1070 .seealso: MatPartitioningRegisterDestroy(), MatPartitioningRegisterAll()
1071 M*/
1072 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1073 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0)
1074 #else
1075 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d)
1076 #endif
1077 
1078 EXTERN PetscErrorCode        MatPartitioningRegisterAll(const char[]);
1079 extern PetscTruth MatPartitioningRegisterAllCalled;
1080 EXTERN PetscErrorCode        MatPartitioningRegisterDestroy(void);
1081 
1082 EXTERN PetscErrorCode MatPartitioningView(MatPartitioning,PetscViewer);
1083 EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning);
1084 EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning,MatPartitioningType*);
1085 
1086 EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1087 
1088 EXTERN PetscErrorCode MatPartitioningJostleSetCoarseLevel(MatPartitioning,PetscReal);
1089 EXTERN PetscErrorCode MatPartitioningJostleSetCoarseSequential(MatPartitioning);
1090 
1091 typedef enum { MP_CHACO_MULTILEVEL_KL, MP_CHACO_SPECTRAL, MP_CHACO_LINEAR,
1092     MP_CHACO_RANDOM, MP_CHACO_SCATTERED } MPChacoGlobalType;
1093 EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning, MPChacoGlobalType);
1094 typedef enum { MP_CHACO_KERNIGHAN_LIN, MP_CHACO_NONE } MPChacoLocalType;
1095 EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning, MPChacoLocalType);
1096 EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning,PetscReal);
1097 typedef enum { MP_CHACO_LANCZOS, MP_CHACO_RQI_SYMMLQ } MPChacoEigenType;
1098 EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning,MPChacoEigenType);
1099 EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning, PetscReal);
1100 EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning, int);
1101 
1102 #define MP_PARTY_OPT "opt"
1103 #define MP_PARTY_LIN "lin"
1104 #define MP_PARTY_SCA "sca"
1105 #define MP_PARTY_RAN "ran"
1106 #define MP_PARTY_GBF "gbf"
1107 #define MP_PARTY_GCF "gcf"
1108 #define MP_PARTY_BUB "bub"
1109 #define MP_PARTY_DEF "def"
1110 EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning, const char*);
1111 #define MP_PARTY_HELPFUL_SETS "hs"
1112 #define MP_PARTY_KERNIGHAN_LIN "kl"
1113 #define MP_PARTY_NONE "no"
1114 EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning, const char*);
1115 EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning,PetscReal);
1116 EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning,PetscTruth);
1117 EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning,PetscTruth);
1118 
1119 typedef enum { MP_SCOTCH_GREEDY, MP_SCOTCH_GPS, MP_SCOTCH_GR_GPS } MPScotchGlobalType;
1120 EXTERN PetscErrorCode MatPartitioningScotchSetArch(MatPartitioning,const char*);
1121 EXTERN PetscErrorCode MatPartitioningScotchSetMultilevel(MatPartitioning);
1122 EXTERN PetscErrorCode MatPartitioningScotchSetGlobal(MatPartitioning,MPScotchGlobalType);
1123 EXTERN PetscErrorCode MatPartitioningScotchSetCoarseLevel(MatPartitioning,PetscReal);
1124 EXTERN PetscErrorCode MatPartitioningScotchSetHostList(MatPartitioning,const char*);
1125 typedef enum { MP_SCOTCH_KERNIGHAN_LIN, MP_SCOTCH_NONE } MPScotchLocalType;
1126 EXTERN PetscErrorCode MatPartitioningScotchSetLocal(MatPartitioning,MPScotchLocalType);
1127 EXTERN PetscErrorCode MatPartitioningScotchSetMapping(MatPartitioning);
1128 EXTERN PetscErrorCode MatPartitioningScotchSetStrategy(MatPartitioning,char*);
1129 
1130 /*
1131     If you add entries here you must also add them to finclude/petscmat.h
1132 */
1133 typedef enum { MATOP_SET_VALUES=0,
1134                MATOP_GET_ROW=1,
1135                MATOP_RESTORE_ROW=2,
1136                MATOP_MULT=3,
1137                MATOP_MULT_ADD=4,
1138                MATOP_MULT_TRANSPOSE=5,
1139                MATOP_MULT_TRANSPOSE_ADD=6,
1140                MATOP_SOLVE=7,
1141                MATOP_SOLVE_ADD=8,
1142                MATOP_SOLVE_TRANSPOSE=9,
1143                MATOP_SOLVE_TRANSPOSE_ADD=10,
1144                MATOP_LUFACTOR=11,
1145                MATOP_CHOLESKYFACTOR=12,
1146                MATOP_RELAX=13,
1147                MATOP_TRANSPOSE=14,
1148                MATOP_GETINFO=15,
1149                MATOP_EQUAL=16,
1150                MATOP_GET_DIAGONAL=17,
1151                MATOP_DIAGONAL_SCALE=18,
1152                MATOP_NORM=19,
1153                MATOP_ASSEMBLY_BEGIN=20,
1154                MATOP_ASSEMBLY_END=21,
1155                MATOP_COMPRESS=22,
1156                MATOP_SET_OPTION=23,
1157                MATOP_ZERO_ENTRIES=24,
1158                MATOP_ZERO_ROWS=25,
1159                MATOP_LUFACTOR_SYMBOLIC=26,
1160                MATOP_LUFACTOR_NUMERIC=27,
1161                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
1162                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
1163                MATOP_SETUP_PREALLOCATION=30,
1164                MATOP_ILUFACTOR_SYMBOLIC=31,
1165                MATOP_ICCFACTOR_SYMBOLIC=32,
1166                MATOP_GET_ARRAY=33,
1167                MATOP_RESTORE_ARRAY=34,
1168                MATOP_DUPLCIATE=35,
1169                MATOP_FORWARD_SOLVE=36,
1170                MATOP_BACKWARD_SOLVE=37,
1171                MATOP_ILUFACTOR=38,
1172                MATOP_ICCFACTOR=39,
1173                MATOP_AXPY=40,
1174                MATOP_GET_SUBMATRICES=41,
1175                MATOP_INCREASE_OVERLAP=42,
1176                MATOP_GET_VALUES=43,
1177                MATOP_COPY=44,
1178                MATOP_PRINT_HELP=45,
1179                MATOP_SCALE=46,
1180                MATOP_SHIFT=47,
1181                MATOP_DIAGONAL_SHIFT=48,
1182                MATOP_ILUDT_FACTOR=49,
1183                MATOP_GET_BLOCK_SIZE=50,
1184                MATOP_GET_ROW_IJ=51,
1185                MATOP_RESTORE_ROW_IJ=52,
1186                MATOP_GET_COLUMN_IJ=53,
1187                MATOP_RESTORE_COLUMN_IJ=54,
1188                MATOP_FDCOLORING_CREATE=55,
1189                MATOP_COLORING_PATCH=56,
1190                MATOP_SET_UNFACTORED=57,
1191                MATOP_PERMUTE=58,
1192                MATOP_SET_VALUES_BLOCKED=59,
1193                MATOP_GET_SUBMATRIX=60,
1194                MATOP_DESTROY=61,
1195                MATOP_VIEW=62,
1196                MATOP_GET_MAPS=63,
1197                MATOP_USE_SCALED_FORM=64,
1198                MATOP_SCALE_SYSTEM=65,
1199                MATOP_UNSCALE_SYSTEM=66,
1200                MATOP_SET_LOCAL_TO_GLOBAL_MAP=67,
1201                MATOP_SET_VALUES_LOCAL=68,
1202                MATOP_ZERO_ROWS_LOCAL=69,
1203                MATOP_GET_ROW_MAX=70,
1204                MATOP_CONVERT=71,
1205                MATOP_SET_COLORING=72,
1206                MATOP_SET_VALUES_ADIC=73,
1207                MATOP_SET_VALUES_ADIFOR=74,
1208                MATOP_FD_COLORING_APPLY=75,
1209                MATOP_SET_FROM_OPTIONS=76,
1210                MATOP_MULT_CON=77,
1211                MATOP_MULT_TRANSPOSE_CON=78,
1212                MATOP_ILU_FACTOR_SYMBOLIC_CON=79,
1213                MATOP_PERMUTE_SPARSIFY=80,
1214                MATOP_MULT_MULTIPLE=81,
1215                MATOP_SOLVE_MULTIPLE=82,
1216                MATOP_GET_INERTIA=83,
1217                MATOP_LOAD=84,
1218                MATOP_IS_SYMMETRIC=85,
1219                MATOP_IS_HERMITIAN=86,
1220                MATOP_IS_STRUCTURALLY_SYMMETRIC=87,
1221                MATOP_PB_RELAX=88,
1222                MATOP_GET_VECS=89,
1223                MATOP_MAT_MULT=90,
1224                MATOP_MAT_MULT_SYMBOLIC=91,
1225                MATOP_MAT_MULT_NUMERIC=92,
1226                MATOP_PTAP=93,
1227                MATOP_PTAP_SYMBOLIC=94,
1228                MATOP_PTAP_NUMERIC=95
1229              } MatOperation;
1230 EXTERN PetscErrorCode MatHasOperation(Mat,MatOperation,PetscTruth*);
1231 EXTERN PetscErrorCode MatShellSetOperation(Mat,MatOperation,void(*)(void));
1232 EXTERN PetscErrorCode MatShellGetOperation(Mat,MatOperation,void(**)(void));
1233 EXTERN PetscErrorCode MatShellSetContext(Mat,void*);
1234 
1235 /*
1236    Codes for matrices stored on disk. By default they are
1237  stored in a universal format. By changing the format with
1238  PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will
1239  be stored in a way natural for the matrix, for example dense matrices
1240  would be stored as dense. Matrices stored this way may only be
1241  read into matrices of the same time.
1242 */
1243 #define MATRIX_BINARY_FORMAT_DENSE -1
1244 
1245 EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat,PetscReal);
1246 EXTERN PetscErrorCode MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *);
1247 EXTERN PetscErrorCode MatMPIRowbsGetColor(Mat,ISColoring *);
1248 
1249 EXTERN PetscErrorCode MatISGetLocalMat(Mat,Mat*);
1250 
1251 /*S
1252      MatNullSpace - Object that removes a null space from a vector, i.e.
1253          orthogonalizes the vector to a subsapce
1254 
1255    Level: advanced
1256 
1257   Concepts: matrix; linear operator, null space
1258 
1259   Users manual sections:
1260 .   sec_singular
1261 
1262 .seealso:  MatNullSpaceCreate()
1263 S*/
1264 typedef struct _p_MatNullSpace* MatNullSpace;
1265 
1266 EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm,int,int,const Vec[],MatNullSpace*);
1267 EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace);
1268 EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace,Vec,Vec*);
1269 EXTERN PetscErrorCode MatNullSpaceAttach(Mat,MatNullSpace);
1270 EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace,Mat);
1271 
1272 EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat,IS);
1273 EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat,PetscReal);
1274 EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat,int *);
1275 
1276 
1277 EXTERN PetscErrorCode MatCreateMAIJ(Mat,int,Mat*);
1278 EXTERN PetscErrorCode MatMAIJRedimension(Mat,int,Mat*);
1279 EXTERN PetscErrorCode MatMAIJGetAIJ(Mat,Mat*);
1280 
1281 EXTERN PetscErrorCode MatComputeExplicitOperator(Mat,Mat*);
1282 
1283 EXTERN PetscErrorCode MatESISetType(Mat,const char*);
1284 EXTERN PetscErrorCode MatESISetFromOptions(Mat);
1285 
1286 EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat,Vec);
1287 
1288 EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, int, int, PetscReal *);
1289 EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, int, int, int *, int *, PetscReal *);
1290 
1291 PETSC_EXTERN_CXX_END
1292 #endif
1293