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