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