xref: /petsc/include/petscmat.h (revision 2bad193124dd672e072fdd6cce6f9d88f362c510)
1*2bad1931SBarry Smith /* $Id: mat.h,v 1.186 2000/01/13 22:20:22 bsmith Exp bsmith $ */
22eac72dbSBarry Smith /*
32eac72dbSBarry Smith      Include file for the matrix component of PETSc
42eac72dbSBarry Smith */
5a009ddc3SBarry Smith #ifndef __MAT_H
6a009ddc3SBarry Smith #define __MAT_H
78ed539a5SBarry Smith #include "vec.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,
253f71ed49SBarry Smith                MATMPIBAIJ,  MATMPICSN,   MATSEQCSN,   MATMPICSR, MATSEQSBAIJ,
26f1d1b154SWilliam Gropp                MATLASTTYPE } MatType;
2728988994SBarry Smith 
28b12f92e5SBarry Smith extern int MatCreate(MPI_Comm,int,int,int,int,Mat*);
29df6e0191SLois Curfman McInnes extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
30d5bc1036SLois Curfman McInnes extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
31de7da479SBarry Smith extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
329717bf64SBarry Smith extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
33cfe223acSLois Curfman McInnes extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
34f26ada1bSBarry Smith extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
35f26ada1bSBarry Smith extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
36df8a92d1SBarry Smith extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
37eba03b66SLois Curfman McInnes extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
38*2bad1931SBarry Smith extern int MatCreateMPICSR(MPI_Comm,int,int,int*,int*,int *,Mat*);
399717bf64SBarry Smith 
407b80b807SBarry Smith extern int MatDestroy(Mat);
417b80b807SBarry Smith 
427ddc982cSLois Curfman McInnes extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
4317116c71SBarry Smith extern int MatShellGetContext(Mat,void **);
4421c89e3eSBarry Smith 
45ec0117caSBarry Smith extern int MatPrintHelp(Mat);
46cda55fadSBarry Smith extern int MatGetMaps(Mat,Map*,Map*);
47ec0117caSBarry Smith 
488ed539a5SBarry Smith /* ------------------------------------------------------------*/
49ee50ffe9SBarry Smith extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
5095e63191SSatish Balay extern int MatSetValuesBlocked(Mat,int,int*,int,int*,Scalar*,InsertMode);
5184cb2905SBarry Smith 
526d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
53ee50ffe9SBarry Smith extern int MatAssemblyBegin(Mat,MatAssemblyType);
54ee50ffe9SBarry Smith extern int MatAssemblyEnd(Mat,MatAssemblyType);
554f9c727eSBarry Smith extern int MatAssembled(Mat,PetscTruth*);
564f9c727eSBarry Smith 
57b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \
58b951964fSBarry Smith {int _ierr,_row = i,_col = j; Scalar _va = va; \
59b951964fSBarry Smith   _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \
60b951964fSBarry Smith }
61ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \
62ea06a074SBarry Smith {int _ierr,_row = i,_col = j; \
63ea06a074SBarry Smith   _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \
64ea06a074SBarry Smith }
656ca9ecd3SBarry Smith /*
666ca9ecd3SBarry Smith    Any additions/changes here MUST also be made in include/finclude/mat.h
676ca9ecd3SBarry Smith */
686d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
696d4a8577SBarry Smith               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
706d4a8577SBarry Smith               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
716ca9ecd3SBarry Smith               MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66,
726ca9ecd3SBarry Smith               MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69,
736ca9ecd3SBarry Smith               MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72,
746ca9ecd3SBarry Smith               MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74,
754787f768SSatish Balay               MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76,
767c922b88SBarry Smith               MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78,
77*2bad1931SBarry Smith               MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81,
78*2bad1931SBarry Smith               MAT_DO_NOT_USE_INODES} MatOption;
79ee50ffe9SBarry Smith extern int MatSetOption(Mat,MatOption);
804b0e389bSBarry Smith extern int MatGetType(Mat,MatType*,char**);
8156cd22aeSBarry Smith extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,PetscTruth*);
8284cb2905SBarry Smith 
83ee50ffe9SBarry Smith extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
848ed539a5SBarry Smith extern int MatGetRow(Mat,int,int *,int **,Scalar**);
858ed539a5SBarry Smith extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
8677c4ece6SBarry Smith extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
8777c4ece6SBarry Smith extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
885cd4b4e6SBarry Smith extern int MatGetColumnVector(Mat,Vec,int);
8964e87e97SBarry Smith extern int MatGetArray(Mat,Scalar **);
9009883261SBarry Smith extern int MatRestoreArray(Mat,Scalar **);
91870582ebSSatish Balay extern int MatGetBlockSize(Mat,int *);
927b80b807SBarry Smith 
938ed539a5SBarry Smith extern int MatMult(Mat,Vec,Vec);
948ed539a5SBarry Smith extern int MatMultAdd(Mat,Vec,Vec,Vec);
957c922b88SBarry Smith extern int MatMultTranspose(Mat,Vec,Vec);
967c922b88SBarry Smith extern int MatMultTransposeAdd(Mat,Vec,Vec,Vec);
972eac72dbSBarry Smith 
982e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption;
992e8a6d31SBarry Smith 
1007b80b807SBarry Smith extern int MatConvert(Mat,MatType,Mat*);
1012e8a6d31SBarry Smith extern int MatDuplicate(Mat,MatDuplicateOption,Mat*);
10294a9d846SBarry Smith extern int MatConvertRegister(MatType,MatType,int (*)(Mat,MatType,Mat*));
103cf256101SBarry Smith extern int MatConvertRegisterAll(void);
10494a9d846SBarry Smith 
105cb5b572fSBarry Smith typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure;
106cb5b572fSBarry Smith 
107cb5b572fSBarry Smith extern int MatCopy(Mat,Mat,MatStructure);
1087b80b807SBarry Smith extern int MatView(Mat,Viewer);
1097b80b807SBarry Smith extern int MatLoad(Viewer,MatType,Mat*);
11094a9d846SBarry Smith extern int MatLoadRegister(MatType,int (*)(Viewer,MatType,Mat*));
111cf256101SBarry Smith extern int MatLoadRegisterAll(void);
1127b80b807SBarry Smith 
113d4fbbf0eSBarry Smith extern int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
114d4fbbf0eSBarry Smith extern int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
115d4fbbf0eSBarry Smith extern int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
116d4fbbf0eSBarry Smith extern int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
117d4fbbf0eSBarry Smith 
1181d607229SLois Curfman McInnes /*
1191d607229SLois Curfman McInnes    Context of matrix information, used with MatGetInfo()
1201d607229SLois Curfman McInnes    Note: If any entries are added to this context, be sure
12126cd32c0SSatish Balay          to adjust MAT_INFO_SIZE in finclude/mat.h
1221d607229SLois Curfman McInnes  */
1234e220ebcSLois Curfman McInnes typedef struct {
12437f753daSBarry Smith   PLogDouble rows_global,columns_global;         /* number of global rows and columns */
12537f753daSBarry Smith   PLogDouble rows_local,columns_local;           /* number of local rows and columns */
12637f753daSBarry Smith   PLogDouble block_size;                          /* block size */
12737f753daSBarry Smith   PLogDouble nz_allocated,nz_used,nz_unneeded;  /* number of nonzeros */
12837f753daSBarry Smith   PLogDouble memory;                              /* memory allocated */
12937f753daSBarry Smith   PLogDouble assemblies;                          /* number of matrix assemblies */
13037f753daSBarry Smith   PLogDouble mallocs;                             /* number of mallocs during MatSetValues() */
13137f753daSBarry Smith   PLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
13237f753daSBarry Smith   PLogDouble factor_mallocs;                      /* number of mallocs during factorization */
1334e220ebcSLois Curfman McInnes } MatInfo;
1344e220ebcSLois Curfman McInnes 
1357b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
1364e220ebcSLois Curfman McInnes extern int MatGetInfo(Mat,MatInfoType,MatInfo*);
13777c4ece6SBarry Smith extern int MatValid(Mat,PetscTruth*);
1387b80b807SBarry Smith extern int MatGetDiagonal(Mat,Vec);
139cd8486b4SBarry Smith extern int MatTranspose(Mat,Mat*);
1400513a670SBarry Smith extern int MatPermute(Mat,IS,IS,Mat *);
141f4c33d5aSBarry Smith extern int MatDiagonalScale(Mat,Vec,Vec);
1428b3e568eSBarry Smith extern int MatDiagonalShift(Mat,Vec);
14377c4ece6SBarry Smith extern int MatEqual(Mat,Mat,PetscTruth*);
1447b80b807SBarry Smith 
1457b80b807SBarry Smith extern int MatNorm(Mat,NormType,double *);
1467b80b807SBarry Smith extern int MatZeroEntries(Mat);
1477b80b807SBarry Smith extern int MatZeroRows(Mat,IS,Scalar*);
1487b80b807SBarry Smith extern int MatZeroColumns(Mat,IS,Scalar*);
1497b80b807SBarry Smith 
1505ef9f2a5SBarry Smith extern int MatUseScaledForm(Mat,PetscTruth);
1515ef9f2a5SBarry Smith extern int MatScaleSystem(Mat,Vec,Vec);
1525ef9f2a5SBarry Smith extern int MatUnScaleSystem(Mat,Vec,Vec);
1535ef9f2a5SBarry Smith 
1547b80b807SBarry Smith extern int MatGetSize(Mat,int*,int*);
1557b80b807SBarry Smith extern int MatGetLocalSize(Mat,int*,int*);
1567b80b807SBarry Smith extern int MatGetOwnershipRange(Mat,int*,int*);
1577b80b807SBarry Smith 
1587b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse;
1597b2a1423SBarry Smith extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **);
160905e6a2fSBarry Smith extern int MatDestroyMatrices(int,Mat **);
1617b2a1423SBarry Smith extern int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *);
1628efafbd8SBarry Smith 
1637b80b807SBarry Smith extern int MatIncreaseOverlap(Mat,int,IS *,int);
1647b80b807SBarry Smith 
1657b80b807SBarry Smith extern int MatAXPY(Scalar *,Mat,Mat);
16686787d2cSSatish Balay extern int MatAYPX(Scalar *,Mat,Mat);
1677b80b807SBarry Smith extern int MatCompress(Mat);
1687b80b807SBarry Smith 
169052efed2SBarry Smith extern int MatScale(Scalar *,Mat);
170052efed2SBarry Smith extern int MatShift(Scalar *,Mat);
171052efed2SBarry Smith 
172d4bb536fSBarry Smith extern int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping);
173497365bdSBarry Smith extern int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping);
17490f02eecSBarry Smith extern int MatZeroRowsLocal(Mat,IS,Scalar*);
17590f02eecSBarry Smith extern int MatSetValuesLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
1764a387fc0SSatish Balay extern int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
17790f02eecSBarry Smith 
178649db694SBarry Smith extern int MatSetStashInitialSize(Mat,int,int);
179649db694SBarry Smith 
1807c922b88SBarry Smith extern int MatInterpolateAdd(Mat,Vec,Vec,Vec);
1817c922b88SBarry Smith extern int MatInterpolate(Mat,Vec,Vec);
1827c922b88SBarry Smith extern int MatRestrict(Mat,Vec,Vec);
1837c922b88SBarry Smith 
1847c922b88SBarry Smith /*
1857c922b88SBarry Smith       These three macros MUST be used together. The third one closes the open { of the first one
1867c922b88SBarry Smith */
1877c922b88SBarry Smith #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) \
1887c922b88SBarry Smith { \
1897c922b88SBarry Smith   int __ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
1907c922b88SBarry Smith   dnz = (int*)PetscMalloc(2*__tmp*sizeof(int));CHKPTRQ(dnz);onz = dnz + __tmp;\
1917c922b88SBarry Smith   __ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(__ierr);\
1927c922b88SBarry Smith   __ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __start = __end - __ctmp;\
1937c922b88SBarry Smith   __ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __rstart = __rstart - __tmp;
1947c922b88SBarry Smith 
1957c922b88SBarry Smith #define MatPreallocateSet(row,nc,cols,dnz,onz)\
1967c922b88SBarry Smith { int __i; \
1977c922b88SBarry Smith   for (__i=0; __i<nc; __i++) {\
1987c922b88SBarry Smith     if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \
1997c922b88SBarry Smith   }\
2007c922b88SBarry Smith   dnz[row - __rstart] = nc - onz[row - __rstart];\
2017c922b88SBarry Smith }
2027c922b88SBarry Smith 
2037c922b88SBarry Smith #define MatPreallocateFinalize(dnz,onz) __ierr = PetscFree(dnz);CHKERRQ(__ierr);}
2047c922b88SBarry Smith 
2057b80b807SBarry Smith /* Routines unique to particular data structures */
2067b80b807SBarry Smith extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
2076f0482c6SBarry Smith extern int MatSeqAIJSetColumnIndices(Mat,int *);
2086f0482c6SBarry Smith extern int MatSeqBAIJSetColumnIndices(Mat,int *);
20936db0b34SBarry Smith extern int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,Scalar *,Mat*);
2107b80b807SBarry Smith 
2112e8a6d31SBarry Smith extern int MatStoreValues(Mat);
2122e8a6d31SBarry Smith extern int MatRetrieveValues(Mat);
2132e8a6d31SBarry Smith 
2147b80b807SBarry Smith /*
2157b80b807SBarry Smith   These routines are not usually accessed directly, rather solving is
2167b80b807SBarry Smith   done through the SLES, KSP and PC interfaces.
2177b80b807SBarry Smith */
2187b80b807SBarry Smith 
219b12f92e5SBarry Smith typedef char* MatOrderingType;
220b12f92e5SBarry Smith #define MATORDERING_NATURAL   "natural"
221b12f92e5SBarry Smith #define MATORDERING_ND        "nd"
222b12f92e5SBarry Smith #define MATORDERING_1WD       "1wd"
223b12f92e5SBarry Smith #define MATORDERING_RCM       "rcm"
224b12f92e5SBarry Smith #define MATORDERING_QMD       "qmd"
225b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength"
226b12f92e5SBarry Smith 
22791e9ee9fSBarry Smith extern int MatGetOrdering(Mat,MatOrderingType,IS*,IS*);
228f1af5d2fSBarry Smith extern int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*));
229aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
230f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0)
231b12f92e5SBarry Smith #else
232f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d)
233b12f92e5SBarry Smith #endif
23491e9ee9fSBarry Smith extern int        MatOrderingRegisterDestroy(void);
235b12f92e5SBarry Smith extern int        MatOrderingRegisterAll(char*);
236*2bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled;
237d4fbbf0eSBarry Smith 
238a2ce50c7SBarry Smith extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
239a2ce50c7SBarry Smith 
240a2ce50c7SBarry Smith extern int MatCholeskyFactor(Mat,IS,double);
241a2ce50c7SBarry Smith extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
242a2ce50c7SBarry Smith extern int MatCholeskyFactorNumeric(Mat,Mat*);
243a2ce50c7SBarry Smith 
2445ef9f2a5SBarry Smith /*
2455ef9f2a5SBarry Smith    Context of matrix information, used with MatILUFactor() and MatILUFactorSymbolic()
2465ef9f2a5SBarry Smith    Note: If any entries are added to this context, be sure
2475ef9f2a5SBarry Smith          to adjust MAT_ILUINFO_SIZE in finclude/mat.h
2485ef9f2a5SBarry Smith 
2495ef9f2a5SBarry Smith    Note: The integer values below are passed in double to allow easy use from
2505ef9f2a5SBarry Smith          Fortran
2515ef9f2a5SBarry Smith  */
2525ef9f2a5SBarry Smith typedef struct {
2535ef9f2a5SBarry Smith   double     levels;  /* ILU(levels) */
2545ef9f2a5SBarry Smith   double     fill;    /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/
2555ef9f2a5SBarry Smith   double     diagonal_fill;  /* force diagonal to fill in if initially not filled */
25636db0b34SBarry Smith 
25736db0b34SBarry Smith   double     dt;             /* drop tolerance */
25836db0b34SBarry Smith   double     dtcol;          /* tolerance for pivoting */
25936db0b34SBarry Smith   double     dtcount;        /* maximum nonzeros to be allowed per row */
2605ef9f2a5SBarry Smith } MatILUInfo;
2615ef9f2a5SBarry Smith 
26249d8b64dSBarry Smith extern int MatLUFactor(Mat,IS,IS,double);
2635ef9f2a5SBarry Smith extern int MatILUFactor(Mat,IS,IS,MatILUInfo*);
26464051cb3SBarry Smith extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
2655ef9f2a5SBarry Smith extern int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*);
26664051cb3SBarry Smith extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
26720563c6bSBarry Smith extern int MatLUFactorNumeric(Mat,Mat*);
26836db0b34SBarry Smith extern int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *);
269a2ce50c7SBarry Smith 
2708ed539a5SBarry Smith extern int MatSolve(Mat,Vec,Vec);
27122169318SLois Curfman McInnes extern int MatForwardSolve(Mat,Vec,Vec);
27222169318SLois Curfman McInnes extern int MatBackwardSolve(Mat,Vec,Vec);
2738ed539a5SBarry Smith extern int MatSolveAdd(Mat,Vec,Vec,Vec);
2747c922b88SBarry Smith extern int MatSolveTranspose(Mat,Vec,Vec);
2757c922b88SBarry Smith extern int MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
2768ed539a5SBarry Smith 
277bb5a7306SBarry Smith extern int MatSetUnfactored(Mat);
278bb5a7306SBarry Smith 
279bb1eb677SSatish Balay /*  MatSORType may be bitwise ORd together, so do not change the numbers */
280bb1eb677SSatish Balay 
281ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
282ee50ffe9SBarry Smith               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
283ee50ffe9SBarry Smith               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
28484cb2905SBarry Smith               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
285ca9b4cbeSLois Curfman McInnes extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
2868ed539a5SBarry Smith 
287d4fbbf0eSBarry Smith /*
288639f9d9dSBarry Smith     These routines are for efficiently computing Jacobians via finite differences.
289639f9d9dSBarry Smith */
290b12f92e5SBarry Smith 
291b12f92e5SBarry Smith typedef char* MatColoringType;
292b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural"
293b12f92e5SBarry Smith #define MATCOLORING_SL      "sl"
294b12f92e5SBarry Smith #define MATCOLORING_LF      "lf"
295b12f92e5SBarry Smith #define MATCOLORING_ID      "id"
296b12f92e5SBarry Smith 
297df8cb225SBarry Smith extern int MatGetColoring(Mat,MatColoringType,ISColoring*);
298f1af5d2fSBarry Smith extern int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *));
299aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
300f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0)
301b12f92e5SBarry Smith #else
302f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d)
303b12f92e5SBarry Smith #endif
304b12f92e5SBarry Smith extern int        MatColoringRegisterAll(char *);
305*2bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled;
306cf256101SBarry Smith extern int        MatColoringRegisterDestroy(void);
307639f9d9dSBarry Smith extern int MatColoringPatch(Mat,int,int *,ISColoring*);
308639f9d9dSBarry Smith 
30984cb2905SBarry Smith /*
31084cb2905SBarry Smith     Data structures used to compute Jacobian vector products
31184cb2905SBarry Smith   efficiently using finite differences.
31284cb2905SBarry Smith */
3131a0a18cdSSatish Balay #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 23
314639f9d9dSBarry Smith 
315e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring;
316639f9d9dSBarry Smith 
317639f9d9dSBarry Smith extern int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
318639f9d9dSBarry Smith extern int MatFDColoringDestroy(MatFDColoring);
319639f9d9dSBarry Smith extern int MatFDColoringView(MatFDColoring,Viewer);
3206eb013d7SBarry Smith extern int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*);
321639f9d9dSBarry Smith extern int MatFDColoringSetParameters(MatFDColoring,double,double);
322005c665bSBarry Smith extern int MatFDColoringSetFrequency(MatFDColoring,int);
3238bba8e72SBarry Smith extern int MatFDColoringGetFrequency(MatFDColoring,int*);
324639f9d9dSBarry Smith extern int MatFDColoringSetFromOptions(MatFDColoring);
325639f9d9dSBarry Smith extern int MatFDColoringPrintHelp(MatFDColoring);
326005c665bSBarry Smith extern int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *);
3276eb013d7SBarry Smith extern int MatFDColoringApplyTS(Mat,MatFDColoring,double,Vec,MatStructure*,void *);
328639f9d9dSBarry Smith 
329639f9d9dSBarry Smith /*
3300752156aSBarry Smith     These routines are for partitioning matrices: currently used only
33136db0b34SBarry Smith   for adjacency matrix, MatCreateMPICSR().
3320752156aSBarry Smith */
33391e9ee9fSBarry Smith #define MATPARTITIONING_COOKIE PETSC_COOKIE + 25
334ca161407SBarry Smith 
33591e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning;
3362aabb6bbSBarry Smith typedef char* MatPartitioningType;
3372aabb6bbSBarry Smith #define MATPARTITIONING_CURRENT  "current"
3382aabb6bbSBarry Smith #define MATPARTITIONING_PARMETIS "parmetis"
339ca161407SBarry Smith 
34091e9ee9fSBarry Smith extern int MatPartitioningCreate(MPI_Comm,MatPartitioning*);
34191e9ee9fSBarry Smith extern int MatPartitioningSetType(MatPartitioning,MatPartitioningType);
34291e9ee9fSBarry Smith extern int MatPartitioningSetAdjacency(MatPartitioning,Mat);
343*2bad1931SBarry Smith extern int MatPartitioningSetVertexWeights(MatPartitioning,int*);
34491e9ee9fSBarry Smith extern int MatPartitioningApply(MatPartitioning,IS*);
34591e9ee9fSBarry Smith extern int MatPartitioningDestroy(MatPartitioning);
3462aabb6bbSBarry Smith 
347f1af5d2fSBarry Smith extern int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning));
348aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
349f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0)
3502aabb6bbSBarry Smith #else
351f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d)
3522aabb6bbSBarry Smith #endif
3532aabb6bbSBarry Smith 
3542aabb6bbSBarry Smith extern int        MatPartitioningRegisterAll(char *);
355*2bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled;
35691e9ee9fSBarry Smith extern int        MatPartitioningRegisterDestroy(void);
357*2bad1931SBarry Smith 
35891e9ee9fSBarry Smith extern int MatPartitioningView(MatPartitioning,Viewer);
35991e9ee9fSBarry Smith extern int MatPartitioningSetFromOptions(MatPartitioning);
36091e9ee9fSBarry Smith extern int MatPartitioningPrintHelp(MatPartitioning);
361e905bf0dSBarry Smith extern int MatPartitioningGetType(MatPartitioning,MatPartitioningType*);
362ca161407SBarry Smith 
36391e9ee9fSBarry Smith extern int MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
3640752156aSBarry Smith 
3650752156aSBarry Smith /*
36626cd32c0SSatish Balay     If you add entries here you must also add them to finclude/mat.h
367d4fbbf0eSBarry Smith */
3681c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0,
3691c1c02c0SLois Curfman McInnes                MATOP_GET_ROW=1,
3701c1c02c0SLois Curfman McInnes                MATOP_RESTORE_ROW=2,
3711c1c02c0SLois Curfman McInnes                MATOP_MULT=3,
3721c1c02c0SLois Curfman McInnes                MATOP_MULT_ADD=4,
3737c922b88SBarry Smith                MATOP_MULT_TRANSPOSE=5,
3747c922b88SBarry Smith                MATOP_MULT_TRANSPOSE_ADD=6,
3751c1c02c0SLois Curfman McInnes                MATOP_SOLVE=7,
3761c1c02c0SLois Curfman McInnes                MATOP_SOLVE_ADD=8,
3777c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE=9,
3787c922b88SBarry Smith                MATOP_SOLVE_TRANSPOSE_ADD=10,
3791c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR=11,
3801c1c02c0SLois Curfman McInnes                MATOP_CHOLESKYFACTOR=12,
3811c1c02c0SLois Curfman McInnes                MATOP_RELAX=13,
3821c1c02c0SLois Curfman McInnes                MATOP_TRANSPOSE=14,
3831c1c02c0SLois Curfman McInnes                MATOP_GETINFO=15,
3841c1c02c0SLois Curfman McInnes                MATOP_EQUAL=16,
3851c1c02c0SLois Curfman McInnes                MATOP_GET_DIAGONAL=17,
3861c1c02c0SLois Curfman McInnes                MATOP_DIAGONAL_SCALE=18,
3871c1c02c0SLois Curfman McInnes                MATOP_NORM=19,
3881c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_BEGIN=20,
3891c1c02c0SLois Curfman McInnes                MATOP_ASSEMBLY_END=21,
3901c1c02c0SLois Curfman McInnes                MATOP_COMPRESS=22,
3911c1c02c0SLois Curfman McInnes                MATOP_SET_OPTION=23,
3921c1c02c0SLois Curfman McInnes                MATOP_ZERO_ENTRIES=24,
3931c1c02c0SLois Curfman McInnes                MATOP_ZERO_ROWS=25,
3941c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR_SYMBOLIC=26,
3951c1c02c0SLois Curfman McInnes                MATOP_LUFACTOR_NUMERIC=27,
3961c1c02c0SLois Curfman McInnes                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
3971c1c02c0SLois Curfman McInnes                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
3981c1c02c0SLois Curfman McInnes                MATOP_GET_SIZE=30,
3991c1c02c0SLois Curfman McInnes                MATOP_GET_LOCAL_SIZE=31,
4001c1c02c0SLois Curfman McInnes                MATOP_GET_OWNERSHIP_RANGE=32,
4011c1c02c0SLois Curfman McInnes                MATOP_ILUFACTOR_SYMBOLIC=33,
4021c1c02c0SLois Curfman McInnes                MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
4031c1c02c0SLois Curfman McInnes                MATOP_GET_ARRAY=35,
4041c1c02c0SLois Curfman McInnes                MATOP_RESTORE_ARRAY=36,
4057bf97ca4SSatish Balay 
406005c665bSBarry Smith                MATOP_CONVERT_SAME_TYPE=37,
407005c665bSBarry Smith                MATOP_FORWARD_SOLVE=38,
408005c665bSBarry Smith                MATOP_BACKWARD_SOLVE=39,
409005c665bSBarry Smith                MATOP_ILUFACTOR=40,
410005c665bSBarry Smith                MATOP_INCOMPLETECHOLESKYFACTOR=41,
411005c665bSBarry Smith                MATOP_AXPY=42,
412005c665bSBarry Smith                MATOP_GET_SUBMATRICES=43,
413005c665bSBarry Smith                MATOP_INCREASE_OVERLAP=44,
414005c665bSBarry Smith                MATOP_GET_VALUES=45,
415005c665bSBarry Smith                MATOP_COPY=46,
416005c665bSBarry Smith                MATOP_PRINT_HELP=47,
417005c665bSBarry Smith                MATOP_SCALE=48,
418005c665bSBarry Smith                MATOP_SHIFT=49,
419005c665bSBarry Smith                MATOP_DIAGONAL_SHIFT=50,
420005c665bSBarry Smith                MATOP_ILUDT_FACTOR=51,
421005c665bSBarry Smith                MATOP_GET_BLOCK_SIZE=52,
422005c665bSBarry Smith                MATOP_GET_ROW_IJ=53,
423005c665bSBarry Smith                MATOP_RESTORE_ROW_IJ=54,
424005c665bSBarry Smith                MATOP_GET_COLUMN_IJ=55,
425005c665bSBarry Smith                MATOP_RESTORE_COLUMN_IJ=56,
426005c665bSBarry Smith                MATOP_FDCOLORING_CREATE=57,
427005c665bSBarry Smith                MATOP_COLORING_PATCH=58,
428005c665bSBarry Smith                MATOP_SET_UNFACTORED=59,
429005c665bSBarry Smith                MATOP_PERMUTE=60,
430005c665bSBarry Smith                MATOP_SET_VALUES_BLOCKED=61,
4311c1c02c0SLois Curfman McInnes                MATOP_DESTROY=250,
4321c1c02c0SLois Curfman McInnes                MATOP_VIEW=251
433fae171e0SBarry Smith              } MatOperation;
434112a2221SBarry Smith extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
435fae171e0SBarry Smith extern int MatShellSetOperation(Mat,MatOperation,void *);
436d4bb536fSBarry Smith extern int MatShellGetOperation(Mat,MatOperation,void **);
437112a2221SBarry Smith 
43890ace30eSBarry Smith /*
43990ace30eSBarry Smith    Codes for matrices stored on disk. By default they are
44090ace30eSBarry Smith  stored in a universal format. By changing the format with
441639f9d9dSBarry Smith  ViewerSetFormat(viewer,VIEWER_FORMAT_BINARY_NATIVE); the matrices will
44290ace30eSBarry Smith  be stored in a way natural for the matrix, for example dense matrices
44390ace30eSBarry Smith  would be stored as dense. Matrices stored this way may only be
44490ace30eSBarry Smith  read into matrices of the same time.
44590ace30eSBarry Smith */
44690ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1
44790ace30eSBarry Smith 
4483f1d51d7SBarry Smith /*
4493f1d51d7SBarry Smith      New matrix classes not yet distributed
4503f1d51d7SBarry Smith */
4513f1d51d7SBarry Smith /*
4523f1d51d7SBarry Smith     MatAIJIndices is a data structure for storing the nonzero location information
4533f1d51d7SBarry Smith   for sparse matrices. Several matrices with identical nonzero structure can share
4543f1d51d7SBarry Smith   the same MatAIJIndices.
4553f1d51d7SBarry Smith */
456e2a1c21fSSatish Balay typedef struct _p_MatAIJIndices* MatAIJIndices;
4573f1d51d7SBarry Smith 
4583f1d51d7SBarry Smith extern int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*);
4593f1d51d7SBarry Smith extern int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*);
4603f1d51d7SBarry Smith extern int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*);
4613f1d51d7SBarry Smith extern int MatDestroyAIJIndices(MatAIJIndices);
4623f1d51d7SBarry Smith extern int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*);
4633f1d51d7SBarry Smith extern int MatValidateAIJIndices(int,MatAIJIndices);
4643f1d51d7SBarry Smith extern int MatShiftAIJIndices(MatAIJIndices);
4653f1d51d7SBarry Smith extern int MatShrinkAIJIndices(MatAIJIndices);
4663f1d51d7SBarry Smith extern int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*);
4673f1d51d7SBarry Smith 
4683f1d51d7SBarry Smith extern int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*);
4693f1d51d7SBarry Smith extern int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*);
4703f1d51d7SBarry Smith extern int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,ScalarPrecision,Mat*);
4713f1d51d7SBarry Smith 
4723f1d51d7SBarry Smith extern int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *);
4733f1d51d7SBarry Smith extern int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *);
4743f1d51d7SBarry Smith extern int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,ScalarPrecision,Mat *);
4753f1d51d7SBarry Smith 
476aa6d738dSSatish Balay extern int MatMPIBAIJSetHashTableFactor(Mat,double);
4772e8a6d31SBarry Smith extern int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *);
478860d1616SSatish Balay 
4793f1d51d7SBarry Smith 
4802eac72dbSBarry Smith #endif
4812eac72dbSBarry Smith 
4822eac72dbSBarry Smith 
4839d00d63dSBarry Smith 
484