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