xref: /petsc/include/petscmat.h (revision ca44d042d6f86ecc01fa7a52a5213a5161f95f53)
1*ca44d042SBarry Smith /* $Id: petscmat.h,v 1.190 2000/05/08 15:09:50 balay Exp bsmith $ */
22eac72dbSBarry Smith /*
32eac72dbSBarry Smith      Include file for the matrix component of PETSc
42eac72dbSBarry Smith */
50a835dfdSSatish Balay #ifndef __PETSCMAT_H
60a835dfdSSatish Balay #define __PETSCMAT_H
70a835dfdSSatish Balay #include "petscvec.h"
82eac72dbSBarry Smith 
99cd28387SBarry Smith #define MAT_COOKIE         PETSC_COOKIE+5
10f0479e8cSBarry Smith 
11e2a1c21fSSatish Balay typedef struct _p_Mat*           Mat;
122eac72dbSBarry Smith 
13f1d1b154SWilliam Gropp #define MAX_MATRIX_TYPES 14
14639f9d9dSBarry Smith /*
15639f9d9dSBarry Smith    The default matrix data storage formats and routines to create them.
16f1d1b154SWilliam Gropp 
17f1d1b154SWilliam Gropp    MATLASTTYPE is "end-of-list" marker that can be used to check that
18f1d1b154SWilliam Gropp    MAX_MATRIX_TYPES is large enough.  The rule is
19f1d1b154SWilliam Gropp    MAX_MATRIX_TYPES >= MATLASTTYPE .
20f1d1b154SWilliam Gropp 
21f1d1b154SWilliam Gropp    To do: add a test program that checks the consistency of these values.
22639f9d9dSBarry Smith */
234ac9ca07SLois Curfman McInnes typedef enum { MATSAME=-1,  MATSEQDENSE, MATSEQAIJ,   MATMPIAIJ,   MATSHELL,
2484cb2905SBarry Smith                MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG, MATMPIDENSE, MATSEQBAIJ,
253eda8832SBarry Smith                MATMPIBAIJ,  MATMPICSN,   MATSEQCSN,   MATMPIADJ, MATSEQSBAIJ,
268a3eeb68SSatish Balay                MATMPISBAIJ, MATLASTTYPE } MatType;
2728988994SBarry Smith 
28*ca44d042SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*);
29*ca44d042SBarry Smith EXTERN int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
30*ca44d042SBarry Smith EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
31*ca44d042SBarry Smith EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
32*ca44d042SBarry Smith EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
33*ca44d042SBarry Smith EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
34*ca44d042SBarry Smith EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
35*ca44d042SBarry Smith EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
36*ca44d042SBarry Smith EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
37*ca44d042SBarry Smith EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
38*ca44d042SBarry Smith EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int*,int*,int *,Mat*);
39*ca44d042SBarry Smith EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
40*ca44d042SBarry Smith EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
418a3eeb68SSatish Balay 
429717bf64SBarry Smith 
43*ca44d042SBarry Smith EXTERN int MatDestroy(Mat);
447b80b807SBarry Smith 
45*ca44d042SBarry Smith EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
46*ca44d042SBarry Smith EXTERN int MatShellGetContext(Mat,void **);
4721c89e3eSBarry Smith 
48*ca44d042SBarry Smith EXTERN int MatPrintHelp(Mat);
49*ca44d042SBarry Smith EXTERN int MatGetMaps(Mat,Map*,Map*);
50ec0117caSBarry Smith 
518ed539a5SBarry Smith /* ------------------------------------------------------------*/
52*ca44d042SBarry Smith EXTERN int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
53*ca44d042SBarry Smith EXTERN int MatSetValuesBlocked(Mat,int,int*,int,int*,Scalar*,InsertMode);
5484cb2905SBarry Smith 
556d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
56*ca44d042SBarry Smith EXTERN int MatAssemblyBegin(Mat,MatAssemblyType);
57*ca44d042SBarry Smith EXTERN int MatAssemblyEnd(Mat,MatAssemblyType);
58*ca44d042SBarry Smith EXTERN int MatAssembled(Mat,PetscTruth*);
594f9c727eSBarry Smith 
60b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \
61b951964fSBarry Smith {int _ierr,_row = i,_col = j; Scalar _va = va; \
62b951964fSBarry Smith   _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \
63b951964fSBarry Smith }
64ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \
65ea06a074SBarry Smith {int _ierr,_row = i,_col = j; \
66ea06a074SBarry Smith   _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \
67ea06a074SBarry Smith }
686ca9ecd3SBarry Smith /*
690a835dfdSSatish Balay    Any additions/changes here MUST also be made in include/finclude/petscmat.h
706ca9ecd3SBarry Smith */
716d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
726d4a8577SBarry Smith               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
736d4a8577SBarry Smith               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
746ca9ecd3SBarry Smith               MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66,
756ca9ecd3SBarry Smith               MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69,
766ca9ecd3SBarry Smith               MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72,
776ca9ecd3SBarry Smith               MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74,
784787f768SSatish Balay               MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76,
797c922b88SBarry Smith               MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78,
802bad1931SBarry Smith               MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81,
812bad1931SBarry Smith               MAT_DO_NOT_USE_INODES} MatOption;
82*ca44d042SBarry Smith EXTERN int MatSetOption(Mat,MatOption);
83*ca44d042SBarry Smith EXTERN int MatGetType(Mat,MatType*,char**);
84*ca44d042SBarry Smith EXTERN int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,PetscTruth*);
8584cb2905SBarry Smith 
86*ca44d042SBarry Smith EXTERN int MatGetValues(Mat,int,int*,int,int*,Scalar*);
87*ca44d042SBarry Smith EXTERN int MatGetRow(Mat,int,int *,int **,Scalar**);
88*ca44d042SBarry Smith EXTERN int MatRestoreRow(Mat,int,int *,int **,Scalar**);
89*ca44d042SBarry Smith EXTERN int MatGetColumn(Mat,int,int *,int **,Scalar**);
90*ca44d042SBarry Smith EXTERN int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
91*ca44d042SBarry Smith EXTERN int MatGetColumnVector(Mat,Vec,int);
92*ca44d042SBarry Smith EXTERN int MatGetArray(Mat,Scalar **);
93*ca44d042SBarry Smith EXTERN int MatRestoreArray(Mat,Scalar **);
94*ca44d042SBarry Smith EXTERN int MatGetBlockSize(Mat,int *);
957b80b807SBarry Smith 
96*ca44d042SBarry Smith EXTERN int MatMult(Mat,Vec,Vec);
97*ca44d042SBarry Smith EXTERN int MatMultAdd(Mat,Vec,Vec,Vec);
98*ca44d042SBarry Smith EXTERN int MatMultTranspose(Mat,Vec,Vec);
99*ca44d042SBarry Smith EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec);
1002eac72dbSBarry Smith 
1012e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption;
1022e8a6d31SBarry Smith 
103*ca44d042SBarry Smith EXTERN int MatConvert(Mat,MatType,Mat*);
104*ca44d042SBarry Smith EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*);
105*ca44d042SBarry Smith EXTERN int MatConvertRegister(MatType,MatType,int (*)(Mat,MatType,Mat*));
106*ca44d042SBarry Smith EXTERN int MatConvertRegisterAll(void);
10794a9d846SBarry Smith 
108cb5b572fSBarry Smith typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure;
109cb5b572fSBarry Smith 
110*ca44d042SBarry Smith EXTERN int MatCopy(Mat,Mat,MatStructure);
111*ca44d042SBarry Smith EXTERN int MatView(Mat,Viewer);
112*ca44d042SBarry Smith EXTERN int MatLoad(Viewer,MatType,Mat*);
113*ca44d042SBarry Smith EXTERN int MatLoadRegister(MatType,int (*)(Viewer,MatType,Mat*));
114*ca44d042SBarry Smith EXTERN int MatLoadRegisterAll(void);
1157b80b807SBarry Smith 
116*ca44d042SBarry Smith EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
117*ca44d042SBarry Smith EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
118*ca44d042SBarry Smith EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
119*ca44d042SBarry Smith EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
120d4fbbf0eSBarry Smith 
1211d607229SLois Curfman McInnes /*
1221d607229SLois Curfman McInnes    Context of matrix information, used with MatGetInfo()
1231d607229SLois Curfman McInnes    Note: If any entries are added to this context, be sure
1240a835dfdSSatish Balay          to adjust MAT_INFO_SIZE in finclude/petscmat.h
1251d607229SLois Curfman McInnes  */
1264e220ebcSLois Curfman McInnes typedef struct {
12737f753daSBarry Smith   PLogDouble rows_global,columns_global;         /* number of global rows and columns */
12837f753daSBarry Smith   PLogDouble rows_local,columns_local;           /* number of local rows and columns */
12937f753daSBarry Smith   PLogDouble block_size;                          /* block size */
13037f753daSBarry Smith   PLogDouble nz_allocated,nz_used,nz_unneeded;  /* number of nonzeros */
13137f753daSBarry Smith   PLogDouble memory;                              /* memory allocated */
13237f753daSBarry Smith   PLogDouble assemblies;                          /* number of matrix assemblies */
13337f753daSBarry Smith   PLogDouble mallocs;                             /* number of mallocs during MatSetValues() */
13437f753daSBarry Smith   PLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
13537f753daSBarry Smith   PLogDouble factor_mallocs;                      /* number of mallocs during factorization */
1364e220ebcSLois Curfman McInnes } MatInfo;
1374e220ebcSLois Curfman McInnes 
1387b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
139*ca44d042SBarry Smith EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*);
140*ca44d042SBarry Smith EXTERN int MatValid(Mat,PetscTruth*);
141*ca44d042SBarry Smith EXTERN int MatGetDiagonal(Mat,Vec);
142*ca44d042SBarry Smith EXTERN int MatTranspose(Mat,Mat*);
143*ca44d042SBarry Smith EXTERN int MatPermute(Mat,IS,IS,Mat *);
144*ca44d042SBarry Smith EXTERN int MatDiagonalScale(Mat,Vec,Vec);
145*ca44d042SBarry Smith EXTERN int MatDiagonalShift(Mat,Vec);
146*ca44d042SBarry Smith EXTERN int MatEqual(Mat,Mat,PetscTruth*);
1477b80b807SBarry Smith 
148*ca44d042SBarry Smith EXTERN int MatNorm(Mat,NormType,double *);
149*ca44d042SBarry Smith EXTERN int MatZeroEntries(Mat);
150*ca44d042SBarry Smith EXTERN int MatZeroRows(Mat,IS,Scalar*);
151*ca44d042SBarry Smith EXTERN int MatZeroColumns(Mat,IS,Scalar*);
1527b80b807SBarry Smith 
153*ca44d042SBarry Smith EXTERN int MatUseScaledForm(Mat,PetscTruth);
154*ca44d042SBarry Smith EXTERN int MatScaleSystem(Mat,Vec,Vec);
155*ca44d042SBarry Smith EXTERN int MatUnScaleSystem(Mat,Vec,Vec);
1565ef9f2a5SBarry Smith 
157*ca44d042SBarry Smith EXTERN int MatGetSize(Mat,int*,int*);
158*ca44d042SBarry Smith EXTERN int MatGetLocalSize(Mat,int*,int*);
159*ca44d042SBarry Smith EXTERN int MatGetOwnershipRange(Mat,int*,int*);
1607b80b807SBarry Smith 
1617b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse;
162*ca44d042SBarry Smith EXTERN int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **);
163*ca44d042SBarry Smith EXTERN int MatDestroyMatrices(int,Mat **);
164*ca44d042SBarry Smith EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *);
1658efafbd8SBarry Smith 
166*ca44d042SBarry Smith EXTERN int MatIncreaseOverlap(Mat,int,IS *,int);
1677b80b807SBarry Smith 
168*ca44d042SBarry Smith EXTERN int MatAXPY(Scalar *,Mat,Mat);
169*ca44d042SBarry Smith EXTERN int MatAYPX(Scalar *,Mat,Mat);
170*ca44d042SBarry Smith EXTERN int MatCompress(Mat);
1717b80b807SBarry Smith 
172*ca44d042SBarry Smith EXTERN int MatScale(Scalar *,Mat);
173*ca44d042SBarry Smith EXTERN int MatShift(Scalar *,Mat);
174052efed2SBarry Smith 
175*ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping);
176*ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping);
177*ca44d042SBarry Smith EXTERN int MatZeroRowsLocal(Mat,IS,Scalar*);
178*ca44d042SBarry Smith EXTERN int MatSetValuesLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
179*ca44d042SBarry Smith EXTERN int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
18090f02eecSBarry Smith 
181*ca44d042SBarry Smith EXTERN int MatSetStashInitialSize(Mat,int,int);
182649db694SBarry Smith 
183*ca44d042SBarry Smith EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec);
184*ca44d042SBarry Smith EXTERN int MatInterpolate(Mat,Vec,Vec);
185*ca44d042SBarry Smith EXTERN int MatRestrict(Mat,Vec,Vec);
1867c922b88SBarry Smith 
1877c922b88SBarry Smith /*
1887c922b88SBarry Smith       These three macros MUST be used together. The third one closes the open { of the first one
1897c922b88SBarry Smith */
1907c922b88SBarry Smith #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) \
1917c922b88SBarry Smith { \
1927c922b88SBarry Smith   int __ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
1937c922b88SBarry Smith   dnz = (int*)PetscMalloc(2*__tmp*sizeof(int));CHKPTRQ(dnz);onz = dnz + __tmp;\
1947c922b88SBarry Smith   __ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(__ierr);\
1957c922b88SBarry Smith   __ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __start = __end - __ctmp;\
1967c922b88SBarry Smith   __ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __rstart = __rstart - __tmp;
1977c922b88SBarry Smith 
1987c922b88SBarry Smith #define MatPreallocateSet(row,nc,cols,dnz,onz)\
1997c922b88SBarry Smith { int __i; \
2007c922b88SBarry Smith   for (__i=0; __i<nc; __i++) {\
2017c922b88SBarry Smith     if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \
2027c922b88SBarry Smith   }\
2037c922b88SBarry Smith   dnz[row - __rstart] = nc - onz[row - __rstart];\
2047c922b88SBarry Smith }
2057c922b88SBarry Smith 
2067c922b88SBarry Smith #define MatPreallocateFinalize(dnz,onz) __ierr = PetscFree(dnz);CHKERRQ(__ierr);}
2077c922b88SBarry Smith 
2087b80b807SBarry Smith /* Routines unique to particular data structures */
209*ca44d042SBarry Smith EXTERN int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
210*ca44d042SBarry Smith EXTERN int MatSeqAIJSetColumnIndices(Mat,int *);
211*ca44d042SBarry Smith EXTERN int MatSeqBAIJSetColumnIndices(Mat,int *);
212*ca44d042SBarry Smith EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,Scalar *,Mat*);
2137b80b807SBarry Smith 
214*ca44d042SBarry Smith EXTERN int MatStoreValues(Mat);
215*ca44d042SBarry Smith EXTERN int MatRetrieveValues(Mat);
2162e8a6d31SBarry Smith 
2177b80b807SBarry Smith /*
2187b80b807SBarry Smith   These routines are not usually accessed directly, rather solving is
2197b80b807SBarry Smith   done through the SLES, KSP and PC interfaces.
2207b80b807SBarry Smith */
2217b80b807SBarry Smith 
222b12f92e5SBarry Smith typedef char* MatOrderingType;
223b12f92e5SBarry Smith #define MATORDERING_NATURAL   "natural"
224b12f92e5SBarry Smith #define MATORDERING_ND        "nd"
225b12f92e5SBarry Smith #define MATORDERING_1WD       "1wd"
226b12f92e5SBarry Smith #define MATORDERING_RCM       "rcm"
227b12f92e5SBarry Smith #define MATORDERING_QMD       "qmd"
228b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength"
229b12f92e5SBarry Smith 
230*ca44d042SBarry Smith EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*);
231*ca44d042SBarry Smith EXTERN int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*));
232aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
233f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0)
234b12f92e5SBarry Smith #else
235f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d)
236b12f92e5SBarry Smith #endif
237*ca44d042SBarry Smith EXTERN int        MatOrderingRegisterDestroy(void);
238*ca44d042SBarry Smith EXTERN int        MatOrderingRegisterAll(char*);
2392bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled;
240d4fbbf0eSBarry Smith 
241*ca44d042SBarry Smith EXTERN int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
242a2ce50c7SBarry Smith 
243*ca44d042SBarry Smith EXTERN int MatCholeskyFactor(Mat,IS,double);
244*ca44d042SBarry Smith EXTERN int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
245*ca44d042SBarry Smith EXTERN int MatCholeskyFactorNumeric(Mat,Mat*);
246a2ce50c7SBarry Smith 
2475ef9f2a5SBarry Smith /*
2485ef9f2a5SBarry Smith    Context of matrix information, used with MatILUFactor() and MatILUFactorSymbolic()
2495ef9f2a5SBarry Smith    Note: If any entries are added to this context, be sure
2500a835dfdSSatish Balay          to adjust MAT_ILUINFO_SIZE in finclude/petscmat.h
2515ef9f2a5SBarry Smith 
2525ef9f2a5SBarry Smith    Note: The integer values below are passed in double to allow easy use from
2535ef9f2a5SBarry Smith          Fortran
2545ef9f2a5SBarry Smith  */
2555ef9f2a5SBarry Smith typedef struct {
2565ef9f2a5SBarry Smith   double     levels;  /* ILU(levels) */
2575ef9f2a5SBarry Smith   double     fill;    /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/
2585ef9f2a5SBarry Smith   double     diagonal_fill;  /* force diagonal to fill in if initially not filled */
25936db0b34SBarry Smith 
26036db0b34SBarry Smith   double     dt;             /* drop tolerance */
26136db0b34SBarry Smith   double     dtcol;          /* tolerance for pivoting */
26236db0b34SBarry Smith   double     dtcount;        /* maximum nonzeros to be allowed per row */
2635ef9f2a5SBarry Smith } MatILUInfo;
2645ef9f2a5SBarry Smith 
265*ca44d042SBarry Smith EXTERN int MatLUFactor(Mat,IS,IS,double);
266*ca44d042SBarry Smith EXTERN int MatILUFactor(Mat,IS,IS,MatILUInfo*);
267*ca44d042SBarry Smith EXTERN int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
268*ca44d042SBarry Smith EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*);
269*ca44d042SBarry Smith EXTERN int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
270*ca44d042SBarry Smith EXTERN int MatLUFactorNumeric(Mat,Mat*);
271*ca44d042SBarry Smith EXTERN int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *);
272a2ce50c7SBarry Smith 
273*ca44d042SBarry Smith EXTERN int MatSolve(Mat,Vec,Vec);
274*ca44d042SBarry Smith EXTERN int MatForwardSolve(Mat,Vec,Vec);
275*ca44d042SBarry Smith EXTERN int MatBackwardSolve(Mat,Vec,Vec);
276*ca44d042SBarry Smith EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec);
277*ca44d042SBarry Smith EXTERN int MatSolveTranspose(Mat,Vec,Vec);
278*ca44d042SBarry Smith EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
2798ed539a5SBarry Smith 
280*ca44d042SBarry Smith EXTERN int MatSetUnfactored(Mat);
281bb5a7306SBarry Smith 
282bb1eb677SSatish Balay /*  MatSORType may be bitwise ORd together, so do not change the numbers */
283bb1eb677SSatish Balay 
284ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
285ee50ffe9SBarry Smith               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
286ee50ffe9SBarry Smith               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
28784cb2905SBarry Smith               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
288*ca44d042SBarry Smith EXTERN int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
2898ed539a5SBarry Smith 
290d4fbbf0eSBarry Smith /*
291639f9d9dSBarry Smith     These routines are for efficiently computing Jacobians via finite differences.
292639f9d9dSBarry Smith */
293b12f92e5SBarry Smith 
294b12f92e5SBarry Smith typedef char* MatColoringType;
295b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural"
296b12f92e5SBarry Smith #define MATCOLORING_SL      "sl"
297b12f92e5SBarry Smith #define MATCOLORING_LF      "lf"
298b12f92e5SBarry Smith #define MATCOLORING_ID      "id"
299b12f92e5SBarry Smith 
300*ca44d042SBarry Smith EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*);
301*ca44d042SBarry Smith EXTERN int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *));
302aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
303f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0)
304b12f92e5SBarry Smith #else
305f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d)
306b12f92e5SBarry Smith #endif
307*ca44d042SBarry Smith EXTERN int        MatColoringRegisterAll(char *);
3082bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled;
309*ca44d042SBarry Smith EXTERN int        MatColoringRegisterDestroy(void);
310*ca44d042SBarry Smith EXTERN int MatColoringPatch(Mat,int,int *,ISColoring*);
311639f9d9dSBarry Smith 
31284cb2905SBarry Smith /*
31384cb2905SBarry Smith     Data structures used to compute Jacobian vector products
31484cb2905SBarry Smith   efficiently using finite differences.
31584cb2905SBarry Smith */
3161a0a18cdSSatish Balay #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 23
317639f9d9dSBarry Smith 
318e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring;
319639f9d9dSBarry Smith 
320*ca44d042SBarry Smith EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
321*ca44d042SBarry Smith EXTERN int MatFDColoringDestroy(MatFDColoring);
322*ca44d042SBarry Smith EXTERN int MatFDColoringView(MatFDColoring,Viewer);
323*ca44d042SBarry Smith EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*);
324*ca44d042SBarry Smith EXTERN int MatFDColoringSetParameters(MatFDColoring,double,double);
325*ca44d042SBarry Smith EXTERN int MatFDColoringSetFrequency(MatFDColoring,int);
326*ca44d042SBarry Smith EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*);
327*ca44d042SBarry Smith EXTERN int MatFDColoringSetFromOptions(MatFDColoring);
328*ca44d042SBarry Smith EXTERN int MatFDColoringPrintHelp(MatFDColoring);
329*ca44d042SBarry Smith EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *);
330*ca44d042SBarry Smith EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,double,Vec,MatStructure*,void *);
331639f9d9dSBarry Smith 
332639f9d9dSBarry Smith /*
3330752156aSBarry Smith     These routines are for partitioning matrices: currently used only
3343eda8832SBarry Smith   for adjacency matrix, MatCreateMPIAdj().
3350752156aSBarry Smith */
33691e9ee9fSBarry Smith #define MATPARTITIONING_COOKIE PETSC_COOKIE + 25
337ca161407SBarry Smith 
33891e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning;
3392aabb6bbSBarry Smith typedef char* MatPartitioningType;
3402aabb6bbSBarry Smith #define MATPARTITIONING_CURRENT  "current"
3412aabb6bbSBarry Smith #define MATPARTITIONING_PARMETIS "parmetis"
342ca161407SBarry Smith 
343*ca44d042SBarry Smith EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*);
344*ca44d042SBarry Smith EXTERN int MatPartitioningSetType(MatPartitioning,MatPartitioningType);
345*ca44d042SBarry Smith EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat);
346*ca44d042SBarry Smith EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,int*);
347*ca44d042SBarry Smith EXTERN int MatPartitioningApply(MatPartitioning,IS*);
348*ca44d042SBarry Smith EXTERN int MatPartitioningDestroy(MatPartitioning);
3492aabb6bbSBarry Smith 
350*ca44d042SBarry Smith EXTERN int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning));
351aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
352f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0)
3532aabb6bbSBarry Smith #else
354f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d)
3552aabb6bbSBarry Smith #endif
3562aabb6bbSBarry Smith 
357*ca44d042SBarry Smith EXTERN int        MatPartitioningRegisterAll(char *);
3582bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled;
359*ca44d042SBarry Smith EXTERN int        MatPartitioningRegisterDestroy(void);
3602bad1931SBarry Smith 
361*ca44d042SBarry Smith EXTERN int MatPartitioningView(MatPartitioning,Viewer);
362*ca44d042SBarry Smith EXTERN int MatPartitioningSetFromOptions(MatPartitioning);
363*ca44d042SBarry Smith EXTERN int MatPartitioningPrintHelp(MatPartitioning);
364*ca44d042SBarry Smith EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*);
365ca161407SBarry Smith 
366*ca44d042SBarry Smith EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
3670752156aSBarry Smith 
3680752156aSBarry Smith /*
3690a835dfdSSatish Balay     If you add entries here you must also add them to finclude/petscmat.h
370d4fbbf0eSBarry Smith */
3711c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0,
3721c1c02c0SLois Curfman McInnes                MATOP_GET_ROW=1,
3731c1c02c0SLois Curfman McInnes                MATOP_RESTORE_ROW=2,
3741c1c02c0SLois Curfman McInnes                MATOP_MULT=3,
3751c1c02c0SLois Curfman McInnes                MATOP_MULT_ADD=4,
3767c922b88SBarry Smith                MATOP_MULT_TRANSPOSE=5,
3777c922b88SBarry Smith                MATOP_MULT_TRANSPOSE_ADD=6,
3781c1c02c0SLois Curfman McInnes                MATOP_SOLVE=7,
3791c1c02c0SLois Curfman McInnes                MATOP_SOLVE_ADD=8,
3807c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE=9,
3817c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE_ADD=10,
3821c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR=11,
3831c1c02c0SLois Curfman McInnes                MATOP_CHOLESKYFACTOR=12,
3841c1c02c0SLois Curfman McInnes                MATOP_RELAX=13,
3851c1c02c0SLois Curfman McInnes                MATOP_TRANSPOSE=14,
3861c1c02c0SLois Curfman McInnes                MATOP_GETINFO=15,
3871c1c02c0SLois Curfman McInnes                MATOP_EQUAL=16,
3881c1c02c0SLois Curfman McInnes                MATOP_GET_DIAGONAL=17,
3891c1c02c0SLois Curfman McInnes                MATOP_DIAGONAL_SCALE=18,
3901c1c02c0SLois Curfman McInnes                MATOP_NORM=19,
3911c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_BEGIN=20,
3921c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_END=21,
3931c1c02c0SLois Curfman McInnes                MATOP_COMPRESS=22,
3941c1c02c0SLois Curfman McInnes                MATOP_SET_OPTION=23,
3951c1c02c0SLois Curfman McInnes                MATOP_ZERO_ENTRIES=24,
3961c1c02c0SLois Curfman McInnes                MATOP_ZERO_ROWS=25,
3971c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR_SYMBOLIC=26,
3981c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR_NUMERIC=27,
3991c1c02c0SLois Curfman McInnes                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
4001c1c02c0SLois Curfman McInnes                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
4011c1c02c0SLois Curfman McInnes                MATOP_GET_SIZE=30,
4021c1c02c0SLois Curfman McInnes                MATOP_GET_LOCAL_SIZE=31,
4031c1c02c0SLois Curfman McInnes                MATOP_GET_OWNERSHIP_RANGE=32,
4041c1c02c0SLois Curfman McInnes                MATOP_ILUFACTOR_SYMBOLIC=33,
4051c1c02c0SLois Curfman McInnes                MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
4061c1c02c0SLois Curfman McInnes                MATOP_GET_ARRAY=35,
4071c1c02c0SLois Curfman McInnes                MATOP_RESTORE_ARRAY=36,
4087bf97ca4SSatish Balay 
409005c665bSBarry Smith                MATOP_CONVERT_SAME_TYPE=37,
410005c665bSBarry Smith                MATOP_FORWARD_SOLVE=38,
411005c665bSBarry Smith                MATOP_BACKWARD_SOLVE=39,
412005c665bSBarry Smith                MATOP_ILUFACTOR=40,
413005c665bSBarry Smith                MATOP_INCOMPLETECHOLESKYFACTOR=41,
414005c665bSBarry Smith                MATOP_AXPY=42,
415005c665bSBarry Smith                MATOP_GET_SUBMATRICES=43,
416005c665bSBarry Smith                MATOP_INCREASE_OVERLAP=44,
417005c665bSBarry Smith                MATOP_GET_VALUES=45,
418005c665bSBarry Smith                MATOP_COPY=46,
419005c665bSBarry Smith                MATOP_PRINT_HELP=47,
420005c665bSBarry Smith                MATOP_SCALE=48,
421005c665bSBarry Smith                MATOP_SHIFT=49,
422005c665bSBarry Smith                MATOP_DIAGONAL_SHIFT=50,
423005c665bSBarry Smith                MATOP_ILUDT_FACTOR=51,
424005c665bSBarry Smith                MATOP_GET_BLOCK_SIZE=52,
425005c665bSBarry Smith                MATOP_GET_ROW_IJ=53,
426005c665bSBarry Smith                MATOP_RESTORE_ROW_IJ=54,
427005c665bSBarry Smith                MATOP_GET_COLUMN_IJ=55,
428005c665bSBarry Smith                MATOP_RESTORE_COLUMN_IJ=56,
429005c665bSBarry Smith                MATOP_FDCOLORING_CREATE=57,
430005c665bSBarry Smith                MATOP_COLORING_PATCH=58,
431005c665bSBarry Smith                MATOP_SET_UNFACTORED=59,
432005c665bSBarry Smith                MATOP_PERMUTE=60,
433005c665bSBarry Smith                MATOP_SET_VALUES_BLOCKED=61,
4341c1c02c0SLois Curfman McInnes                MATOP_DESTROY=250,
4351c1c02c0SLois Curfman McInnes                MATOP_VIEW=251
436fae171e0SBarry Smith              } MatOperation;
437*ca44d042SBarry Smith EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*);
438*ca44d042SBarry Smith EXTERN int MatShellSetOperation(Mat,MatOperation,void *);
439*ca44d042SBarry Smith EXTERN int MatShellGetOperation(Mat,MatOperation,void **);
440112a2221SBarry Smith 
44190ace30eSBarry Smith /*
44290ace30eSBarry Smith    Codes for matrices stored on disk. By default they are
44390ace30eSBarry Smith  stored in a universal format. By changing the format with
444639f9d9dSBarry Smith  ViewerSetFormat(viewer,VIEWER_FORMAT_BINARY_NATIVE); the matrices will
44590ace30eSBarry Smith  be stored in a way natural for the matrix, for example dense matrices
44690ace30eSBarry Smith  would be stored as dense. Matrices stored this way may only be
44790ace30eSBarry Smith  read into matrices of the same time.
44890ace30eSBarry Smith */
44990ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1
45090ace30eSBarry Smith 
4513f1d51d7SBarry Smith /*
4523f1d51d7SBarry Smith      New matrix classes not yet distributed
4533f1d51d7SBarry Smith */
4543f1d51d7SBarry Smith /*
4553f1d51d7SBarry Smith     MatAIJIndices is a data structure for storing the nonzero location information
4563f1d51d7SBarry Smith   for sparse matrices. Several matrices with identical nonzero structure can share
4573f1d51d7SBarry Smith   the same MatAIJIndices.
4583f1d51d7SBarry Smith */
459e2a1c21fSSatish Balay typedef struct _p_MatAIJIndices* MatAIJIndices;
4603f1d51d7SBarry Smith 
461*ca44d042SBarry Smith EXTERN int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*);
462*ca44d042SBarry Smith EXTERN int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*);
463*ca44d042SBarry Smith EXTERN int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*);
464*ca44d042SBarry Smith EXTERN int MatDestroyAIJIndices(MatAIJIndices);
465*ca44d042SBarry Smith EXTERN int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*);
466*ca44d042SBarry Smith EXTERN int MatValidateAIJIndices(int,MatAIJIndices);
467*ca44d042SBarry Smith EXTERN int MatShiftAIJIndices(MatAIJIndices);
468*ca44d042SBarry Smith EXTERN int MatShrinkAIJIndices(MatAIJIndices);
469*ca44d042SBarry Smith EXTERN int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*);
4703f1d51d7SBarry Smith 
471*ca44d042SBarry Smith EXTERN int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*);
472*ca44d042SBarry Smith EXTERN int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*);
473*ca44d042SBarry Smith EXTERN int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,ScalarPrecision,Mat*);
4743f1d51d7SBarry Smith 
475*ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *);
476*ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *);
477*ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,ScalarPrecision,Mat *);
4783f1d51d7SBarry Smith 
479*ca44d042SBarry Smith EXTERN int MatMPIBAIJSetHashTableFactor(Mat,double);
480*ca44d042SBarry Smith EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *);
481860d1616SSatish Balay 
4823f1d51d7SBarry Smith 
4832eac72dbSBarry Smith #endif
4842eac72dbSBarry Smith 
4852eac72dbSBarry Smith 
4869d00d63dSBarry Smith 
487