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