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