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