1*4bbc92c1SBarry Smith /* $Id: petscmat.h,v 1.204 2000/08/24 22:43:56 bsmith 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 28ca44d042SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 29ca44d042SBarry Smith EXTERN int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*); 30ca44d042SBarry Smith EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*); 31ca44d042SBarry Smith EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*); 32ca44d042SBarry Smith EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*); 33c4f061fbSSatish Balay EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,Mat*); 34ca44d042SBarry Smith EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*); 35ca44d042SBarry Smith EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*); 36ca44d042SBarry Smith EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 37ca44d042SBarry Smith EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 38ca44d042SBarry Smith EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int*,int*,int *,Mat*); 39ca44d042SBarry Smith EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 40ca44d042SBarry Smith EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 418a3eeb68SSatish Balay 429717bf64SBarry Smith 43f2f9cf34SSatish Balay EXTERN int MatSetTypeFromOptions(Mat); 44ca44d042SBarry Smith EXTERN int MatDestroy(Mat); 457b80b807SBarry Smith 46ca44d042SBarry Smith EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*); 47ca44d042SBarry Smith EXTERN int MatShellGetContext(Mat,void **); 4821c89e3eSBarry Smith 49ca44d042SBarry Smith EXTERN int MatPrintHelp(Mat); 50ca44d042SBarry Smith EXTERN int MatGetMaps(Mat,Map*,Map*); 51ec0117caSBarry Smith 528ed539a5SBarry Smith /* ------------------------------------------------------------*/ 53ca44d042SBarry Smith EXTERN int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode); 54ca44d042SBarry Smith EXTERN int MatSetValuesBlocked(Mat,int,int*,int,int*,Scalar*,InsertMode); 5584cb2905SBarry Smith 566d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType; 57ca44d042SBarry Smith EXTERN int MatAssemblyBegin(Mat,MatAssemblyType); 58ca44d042SBarry Smith EXTERN int MatAssemblyEnd(Mat,MatAssemblyType); 59ca44d042SBarry Smith EXTERN int MatAssembled(Mat,PetscTruth*); 604f9c727eSBarry Smith 61b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \ 62b951964fSBarry Smith {int _ierr,_row = i,_col = j; Scalar _va = va; \ 63b951964fSBarry Smith _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 64b951964fSBarry Smith } 65ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \ 66ea06a074SBarry Smith {int _ierr,_row = i,_col = j; \ 67ea06a074SBarry Smith _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \ 68ea06a074SBarry Smith } 696ca9ecd3SBarry Smith /* 700a835dfdSSatish Balay Any additions/changes here MUST also be made in include/finclude/petscmat.h 716ca9ecd3SBarry Smith */ 726d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4, 736d4a8577SBarry Smith MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16, 746d4a8577SBarry Smith MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64, 756ca9ecd3SBarry Smith MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66, 766ca9ecd3SBarry Smith MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69, 776ca9ecd3SBarry Smith MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72, 786ca9ecd3SBarry Smith MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74, 794787f768SSatish Balay MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76, 807c922b88SBarry Smith MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78, 812bad1931SBarry Smith MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81, 82f9d29acdSSatish Balay MAT_DO_NOT_USE_INODES=82} MatOption; 83ca44d042SBarry Smith EXTERN int MatSetOption(Mat,MatOption); 84ca44d042SBarry Smith EXTERN int MatGetType(Mat,MatType*,char**); 85ca44d042SBarry Smith EXTERN int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,PetscTruth*); 8684cb2905SBarry Smith 87ca44d042SBarry Smith EXTERN int MatGetValues(Mat,int,int*,int,int*,Scalar*); 88ca44d042SBarry Smith EXTERN int MatGetRow(Mat,int,int *,int **,Scalar**); 89ca44d042SBarry Smith EXTERN int MatRestoreRow(Mat,int,int *,int **,Scalar**); 90ca44d042SBarry Smith EXTERN int MatGetColumn(Mat,int,int *,int **,Scalar**); 91ca44d042SBarry Smith EXTERN int MatRestoreColumn(Mat,int,int *,int **,Scalar**); 92ca44d042SBarry Smith EXTERN int MatGetColumnVector(Mat,Vec,int); 93ca44d042SBarry Smith EXTERN int MatGetArray(Mat,Scalar **); 94ca44d042SBarry Smith EXTERN int MatRestoreArray(Mat,Scalar **); 95ca44d042SBarry Smith EXTERN int MatGetBlockSize(Mat,int *); 967b80b807SBarry Smith 97ca44d042SBarry Smith EXTERN int MatMult(Mat,Vec,Vec); 98ca44d042SBarry Smith EXTERN int MatMultAdd(Mat,Vec,Vec,Vec); 99ca44d042SBarry Smith EXTERN int MatMultTranspose(Mat,Vec,Vec); 100ca44d042SBarry Smith EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec); 1012eac72dbSBarry Smith 1022e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption; 1032e8a6d31SBarry Smith 104ca44d042SBarry Smith EXTERN int MatConvert(Mat,MatType,Mat*); 105ca44d042SBarry Smith EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*); 106ca44d042SBarry Smith EXTERN int MatConvertRegister(MatType,MatType,int (*)(Mat,MatType,Mat*)); 107ca44d042SBarry Smith EXTERN int MatConvertRegisterAll(void); 10894a9d846SBarry Smith 109cb5b572fSBarry Smith typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure; 110cb5b572fSBarry Smith 111ca44d042SBarry Smith EXTERN int MatCopy(Mat,Mat,MatStructure); 112ca44d042SBarry Smith EXTERN int MatView(Mat,Viewer); 113ca44d042SBarry Smith EXTERN int MatLoad(Viewer,MatType,Mat*); 114ca44d042SBarry Smith EXTERN int MatLoadRegister(MatType,int (*)(Viewer,MatType,Mat*)); 115ca44d042SBarry Smith EXTERN int MatLoadRegisterAll(void); 1167b80b807SBarry Smith 117ca44d042SBarry Smith EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 118ca44d042SBarry Smith EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 119ca44d042SBarry Smith EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 120ca44d042SBarry Smith EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 121d4fbbf0eSBarry Smith 1221d607229SLois Curfman McInnes /* 1231d607229SLois Curfman McInnes Context of matrix information, used with MatGetInfo() 1241d607229SLois Curfman McInnes Note: If any entries are added to this context, be sure 1250a835dfdSSatish Balay to adjust MAT_INFO_SIZE in finclude/petscmat.h 1261d607229SLois Curfman McInnes */ 1274e220ebcSLois Curfman McInnes typedef struct { 12837f753daSBarry Smith PLogDouble rows_global,columns_global; /* number of global rows and columns */ 12937f753daSBarry Smith PLogDouble rows_local,columns_local; /* number of local rows and columns */ 13037f753daSBarry Smith PLogDouble block_size; /* block size */ 13137f753daSBarry Smith PLogDouble nz_allocated,nz_used,nz_unneeded; /* number of nonzeros */ 13237f753daSBarry Smith PLogDouble memory; /* memory allocated */ 13337f753daSBarry Smith PLogDouble assemblies; /* number of matrix assemblies */ 13437f753daSBarry Smith PLogDouble mallocs; /* number of mallocs during MatSetValues() */ 13537f753daSBarry Smith PLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */ 13637f753daSBarry Smith PLogDouble factor_mallocs; /* number of mallocs during factorization */ 1374e220ebcSLois Curfman McInnes } MatInfo; 1384e220ebcSLois Curfman McInnes 1397b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType; 140ca44d042SBarry Smith EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*); 141ca44d042SBarry Smith EXTERN int MatValid(Mat,PetscTruth*); 142ca44d042SBarry Smith EXTERN int MatGetDiagonal(Mat,Vec); 143ca44d042SBarry Smith EXTERN int MatTranspose(Mat,Mat*); 144ca44d042SBarry Smith EXTERN int MatPermute(Mat,IS,IS,Mat *); 145ca44d042SBarry Smith EXTERN int MatDiagonalScale(Mat,Vec,Vec); 14606ef90c2SBarry Smith EXTERN int MatDiagonalSet(Mat,Vec,InsertMode); 147ca44d042SBarry Smith EXTERN int MatEqual(Mat,Mat,PetscTruth*); 1487b80b807SBarry Smith 149ca44d042SBarry Smith EXTERN int MatNorm(Mat,NormType,double *); 150ca44d042SBarry Smith EXTERN int MatZeroEntries(Mat); 151ca44d042SBarry Smith EXTERN int MatZeroRows(Mat,IS,Scalar*); 152ca44d042SBarry Smith EXTERN int MatZeroColumns(Mat,IS,Scalar*); 1537b80b807SBarry Smith 154ca44d042SBarry Smith EXTERN int MatUseScaledForm(Mat,PetscTruth); 155ca44d042SBarry Smith EXTERN int MatScaleSystem(Mat,Vec,Vec); 156ca44d042SBarry Smith EXTERN int MatUnScaleSystem(Mat,Vec,Vec); 1575ef9f2a5SBarry Smith 158ca44d042SBarry Smith EXTERN int MatGetSize(Mat,int*,int*); 159ca44d042SBarry Smith EXTERN int MatGetLocalSize(Mat,int*,int*); 160ca44d042SBarry Smith EXTERN int MatGetOwnershipRange(Mat,int*,int*); 1617b80b807SBarry Smith 1627b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse; 163ca44d042SBarry Smith EXTERN int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **); 164ca44d042SBarry Smith EXTERN int MatDestroyMatrices(int,Mat **); 165ca44d042SBarry Smith EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *); 1668efafbd8SBarry Smith 167ca44d042SBarry Smith EXTERN int MatIncreaseOverlap(Mat,int,IS *,int); 1687b80b807SBarry Smith 169ca44d042SBarry Smith EXTERN int MatAXPY(Scalar *,Mat,Mat); 170ca44d042SBarry Smith EXTERN int MatAYPX(Scalar *,Mat,Mat); 171ca44d042SBarry Smith EXTERN int MatCompress(Mat); 1727b80b807SBarry Smith 173ca44d042SBarry Smith EXTERN int MatScale(Scalar *,Mat); 174ca44d042SBarry Smith EXTERN int MatShift(Scalar *,Mat); 175052efed2SBarry Smith 176ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping); 177ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping); 178ca44d042SBarry Smith EXTERN int MatZeroRowsLocal(Mat,IS,Scalar*); 179ca44d042SBarry Smith EXTERN int MatSetValuesLocal(Mat,int,int*,int,int*,Scalar*,InsertMode); 180ca44d042SBarry Smith EXTERN int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,Scalar*,InsertMode); 18190f02eecSBarry Smith 182ca44d042SBarry Smith EXTERN int MatSetStashInitialSize(Mat,int,int); 183649db694SBarry Smith 184ca44d042SBarry Smith EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec); 185ca44d042SBarry Smith EXTERN int MatInterpolate(Mat,Vec,Vec); 186ca44d042SBarry Smith EXTERN int MatRestrict(Mat,Vec,Vec); 1877c922b88SBarry Smith 1887c922b88SBarry Smith /* 189c4f061fbSSatish Balay These three (or four) macros MUST be used together. The third one closes the open { of the first one 1907c922b88SBarry Smith */ 191c4f061fbSSatish Balay #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \ 1927c922b88SBarry Smith { \ 1937c922b88SBarry Smith int __ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \ 1947c922b88SBarry Smith dnz = (int*)PetscMalloc(2*__tmp*sizeof(int));CHKPTRQ(dnz);onz = dnz + __tmp;\ 1957c922b88SBarry Smith __ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(__ierr);\ 1967c922b88SBarry Smith __ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __start = __end - __ctmp;\ 1977c922b88SBarry Smith __ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __rstart = __rstart - __tmp; 1987c922b88SBarry Smith 199c4f061fbSSatish Balay #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 200c4f061fbSSatish Balay {\ 201c4f061fbSSatish Balay int __l;\ 202c4f061fbSSatish Balay __ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(__ierr);\ 203c4f061fbSSatish Balay __ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(__ierr);\ 204c4f061fbSSatish Balay for (__l=0;__l<nrows;__l++) {\ 205c4f061fbSSatish Balay __ierr = MatPreallocateSet(rows[__l],ncols,cols,dnz,onz);CHKERRQ(__ierr);\ 206c4f061fbSSatish Balay }\ 207c4f061fbSSatish Balay } 208c4f061fbSSatish Balay 209c4f061fbSSatish Balay #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\ 2107c922b88SBarry Smith { int __i; \ 2117c922b88SBarry Smith for (__i=0; __i<nc; __i++) {\ 2127c922b88SBarry Smith if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \ 2137c922b88SBarry Smith }\ 2147c922b88SBarry Smith dnz[row - __rstart] = nc - onz[row - __rstart];\ 2157c922b88SBarry Smith } 2167c922b88SBarry Smith 217c4f061fbSSatish Balay #define MatPreallocateFinalize(dnz,onz) 0;__ierr = PetscFree(dnz);CHKERRQ(__ierr);} 2187c922b88SBarry Smith 2197b80b807SBarry Smith /* Routines unique to particular data structures */ 220ca44d042SBarry Smith EXTERN int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***); 221ca44d042SBarry Smith EXTERN int MatSeqAIJSetColumnIndices(Mat,int *); 222ca44d042SBarry Smith EXTERN int MatSeqBAIJSetColumnIndices(Mat,int *); 223ca44d042SBarry Smith EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,Scalar *,Mat*); 2247b80b807SBarry Smith 225ca44d042SBarry Smith EXTERN int MatStoreValues(Mat); 226ca44d042SBarry Smith EXTERN int MatRetrieveValues(Mat); 2272e8a6d31SBarry Smith 2287b80b807SBarry Smith /* 2297b80b807SBarry Smith These routines are not usually accessed directly, rather solving is 2307b80b807SBarry Smith done through the SLES, KSP and PC interfaces. 2317b80b807SBarry Smith */ 2327b80b807SBarry Smith 233b12f92e5SBarry Smith typedef char* MatOrderingType; 234b12f92e5SBarry Smith #define MATORDERING_NATURAL "natural" 235b12f92e5SBarry Smith #define MATORDERING_ND "nd" 236b12f92e5SBarry Smith #define MATORDERING_1WD "1wd" 237b12f92e5SBarry Smith #define MATORDERING_RCM "rcm" 238b12f92e5SBarry Smith #define MATORDERING_QMD "qmd" 239b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength" 240b12f92e5SBarry Smith 241ca44d042SBarry Smith EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*); 242ca44d042SBarry Smith EXTERN int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*)); 243aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 244f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0) 245b12f92e5SBarry Smith #else 246f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d) 247b12f92e5SBarry Smith #endif 248ca44d042SBarry Smith EXTERN int MatOrderingRegisterDestroy(void); 249ca44d042SBarry Smith EXTERN int MatOrderingRegisterAll(char*); 2502bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled; 251*4bbc92c1SBarry Smith extern FList MatOrderingList; 252d4fbbf0eSBarry Smith 253ca44d042SBarry Smith EXTERN int MatReorderForNonzeroDiagonal(Mat,double,IS,IS); 254a2ce50c7SBarry Smith 255ca44d042SBarry Smith EXTERN int MatCholeskyFactor(Mat,IS,double); 256ca44d042SBarry Smith EXTERN int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*); 257ca44d042SBarry Smith EXTERN int MatCholeskyFactorNumeric(Mat,Mat*); 258a2ce50c7SBarry Smith 2595ef9f2a5SBarry Smith /* 2605ef9f2a5SBarry Smith Context of matrix information, used with MatILUFactor() and MatILUFactorSymbolic() 26114822f30SBarry Smith of MatLUFactor() and MatLUFactorSymbolic() 2625ef9f2a5SBarry Smith 26314822f30SBarry Smith Note: If any entries are added to this context, be sure 26414822f30SBarry Smith to adjust MAT_ILUINFO_SIZE in finclude/petscmat.h and/or 26514822f30SBarry Smith to adjust MAT_LUINFO_SIZE in finclude/petscmat.h 26614822f30SBarry Smith 26714822f30SBarry Smith Note: The integer values below are passed in double to allow easy use from Fortran 2685ef9f2a5SBarry Smith */ 2695ef9f2a5SBarry Smith typedef struct { 2705ef9f2a5SBarry Smith double levels; /* ILU(levels) */ 2715ef9f2a5SBarry Smith double fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 2725ef9f2a5SBarry Smith double diagonal_fill; /* force diagonal to fill in if initially not filled */ 27336db0b34SBarry Smith 27436db0b34SBarry Smith double dt; /* drop tolerance */ 27536db0b34SBarry Smith double dtcol; /* tolerance for pivoting */ 27636db0b34SBarry Smith double dtcount; /* maximum nonzeros to be allowed per row */ 277c4f061fbSSatish Balay double damping; /* damping factor - i.e. scaling of identity added to matrix to prevent zero pivots */ 278b08993e5SBarry Smith double damp; /* if factorization fails, damp until successful */ 2795ef9f2a5SBarry Smith } MatILUInfo; 2805ef9f2a5SBarry Smith 28114822f30SBarry Smith typedef struct { 28214822f30SBarry Smith double fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 28314822f30SBarry Smith double dtcol; /* tolerance for pivoting; pivot if off_diagonal*dtcol > diagonal */ 284c4f061fbSSatish Balay double damping; /* damping factor - i.e. scaling of identity added to matrix to prevent zero pivots */ 285b08993e5SBarry Smith double damp; /* if factorization fails, damp until successful */ 28614822f30SBarry Smith } MatLUInfo; 28714822f30SBarry Smith 28814822f30SBarry Smith EXTERN int MatLUFactor(Mat,IS,IS,MatLUInfo*); 289ca44d042SBarry Smith EXTERN int MatILUFactor(Mat,IS,IS,MatILUInfo*); 29014822f30SBarry Smith EXTERN int MatLUFactorSymbolic(Mat,IS,IS,MatLUInfo*,Mat*); 291ca44d042SBarry Smith EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*); 292ca44d042SBarry Smith EXTERN int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*); 29374637425SBarry Smith EXTERN int MatIncompleteCholeskyFactor(Mat,IS,double,int); 294ca44d042SBarry Smith EXTERN int MatLUFactorNumeric(Mat,Mat*); 295ca44d042SBarry Smith EXTERN int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *); 296a2ce50c7SBarry Smith 297ca44d042SBarry Smith EXTERN int MatSolve(Mat,Vec,Vec); 298ca44d042SBarry Smith EXTERN int MatForwardSolve(Mat,Vec,Vec); 299ca44d042SBarry Smith EXTERN int MatBackwardSolve(Mat,Vec,Vec); 300ca44d042SBarry Smith EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec); 301ca44d042SBarry Smith EXTERN int MatSolveTranspose(Mat,Vec,Vec); 302ca44d042SBarry Smith EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec); 3038ed539a5SBarry Smith 304ca44d042SBarry Smith EXTERN int MatSetUnfactored(Mat); 305bb5a7306SBarry Smith 306bb1eb677SSatish Balay /* MatSORType may be bitwise ORd together, so do not change the numbers */ 307bb1eb677SSatish Balay 308ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 309ee50ffe9SBarry Smith SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 310ee50ffe9SBarry Smith SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 31184cb2905SBarry Smith SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType; 312ca44d042SBarry Smith EXTERN int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec); 3138ed539a5SBarry Smith 314d4fbbf0eSBarry Smith /* 315639f9d9dSBarry Smith These routines are for efficiently computing Jacobians via finite differences. 316639f9d9dSBarry Smith */ 317b12f92e5SBarry Smith 318b12f92e5SBarry Smith typedef char* MatColoringType; 319b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural" 320b12f92e5SBarry Smith #define MATCOLORING_SL "sl" 321b12f92e5SBarry Smith #define MATCOLORING_LF "lf" 322b12f92e5SBarry Smith #define MATCOLORING_ID "id" 323b12f92e5SBarry Smith 324ca44d042SBarry Smith EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*); 325ca44d042SBarry Smith EXTERN int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *)); 326aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 327f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0) 328b12f92e5SBarry Smith #else 329f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d) 330b12f92e5SBarry Smith #endif 331ca44d042SBarry Smith EXTERN int MatColoringRegisterAll(char *); 3322bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled; 333ca44d042SBarry Smith EXTERN int MatColoringRegisterDestroy(void); 334ca44d042SBarry Smith EXTERN int MatColoringPatch(Mat,int,int *,ISColoring*); 335639f9d9dSBarry Smith 33684cb2905SBarry Smith /* 33784cb2905SBarry Smith Data structures used to compute Jacobian vector products 33884cb2905SBarry Smith efficiently using finite differences. 33984cb2905SBarry Smith */ 3401a0a18cdSSatish Balay #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 23 341639f9d9dSBarry Smith 342e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring; 343639f9d9dSBarry Smith 344ca44d042SBarry Smith EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *); 345ca44d042SBarry Smith EXTERN int MatFDColoringDestroy(MatFDColoring); 346ca44d042SBarry Smith EXTERN int MatFDColoringView(MatFDColoring,Viewer); 347ca44d042SBarry Smith EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*); 348ca44d042SBarry Smith EXTERN int MatFDColoringSetParameters(MatFDColoring,double,double); 349ca44d042SBarry Smith EXTERN int MatFDColoringSetFrequency(MatFDColoring,int); 350ca44d042SBarry Smith EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*); 351ca44d042SBarry Smith EXTERN int MatFDColoringSetFromOptions(MatFDColoring); 352ca44d042SBarry Smith EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *); 353ca44d042SBarry Smith EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,double,Vec,MatStructure*,void *); 354639f9d9dSBarry Smith 355639f9d9dSBarry Smith /* 3560752156aSBarry Smith These routines are for partitioning matrices: currently used only 3573eda8832SBarry Smith for adjacency matrix, MatCreateMPIAdj(). 3580752156aSBarry Smith */ 35991e9ee9fSBarry Smith #define MATPARTITIONING_COOKIE PETSC_COOKIE + 25 360ca161407SBarry Smith 36191e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning; 3622aabb6bbSBarry Smith typedef char* MatPartitioningType; 3632aabb6bbSBarry Smith #define MATPARTITIONING_CURRENT "current" 3642aabb6bbSBarry Smith #define MATPARTITIONING_PARMETIS "parmetis" 365ca161407SBarry Smith 366ca44d042SBarry Smith EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*); 367ca44d042SBarry Smith EXTERN int MatPartitioningSetType(MatPartitioning,MatPartitioningType); 368ca44d042SBarry Smith EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat); 369ca44d042SBarry Smith EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,int*); 370ca44d042SBarry Smith EXTERN int MatPartitioningApply(MatPartitioning,IS*); 371ca44d042SBarry Smith EXTERN int MatPartitioningDestroy(MatPartitioning); 3722aabb6bbSBarry Smith 373ca44d042SBarry Smith EXTERN int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning)); 374aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 375f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0) 3762aabb6bbSBarry Smith #else 377f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d) 3782aabb6bbSBarry Smith #endif 3792aabb6bbSBarry Smith 380ca44d042SBarry Smith EXTERN int MatPartitioningRegisterAll(char *); 3812bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled; 382ca44d042SBarry Smith EXTERN int MatPartitioningRegisterDestroy(void); 3832bad1931SBarry Smith 384ca44d042SBarry Smith EXTERN int MatPartitioningView(MatPartitioning,Viewer); 385ca44d042SBarry Smith EXTERN int MatPartitioningSetFromOptions(MatPartitioning); 386ca44d042SBarry Smith EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*); 387ca161407SBarry Smith 388ca44d042SBarry Smith EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 3890752156aSBarry Smith 3900752156aSBarry Smith /* 3910a835dfdSSatish Balay If you add entries here you must also add them to finclude/petscmat.h 392d4fbbf0eSBarry Smith */ 3931c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0, 3941c1c02c0SLois Curfman McInnes MATOP_GET_ROW=1, 3951c1c02c0SLois Curfman McInnes MATOP_RESTORE_ROW=2, 3961c1c02c0SLois Curfman McInnes MATOP_MULT=3, 3971c1c02c0SLois Curfman McInnes MATOP_MULT_ADD=4, 3987c922b88SBarry Smith MATOP_MULT_TRANSPOSE=5, 3997c922b88SBarry Smith MATOP_MULT_TRANSPOSE_ADD=6, 4001c1c02c0SLois Curfman McInnes MATOP_SOLVE=7, 4011c1c02c0SLois Curfman McInnes MATOP_SOLVE_ADD=8, 4027c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE=9, 4037c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE_ADD=10, 4041c1c02c0SLois Curfman McInnes MATOP_LUFACTOR=11, 4051c1c02c0SLois Curfman McInnes MATOP_CHOLESKYFACTOR=12, 4061c1c02c0SLois Curfman McInnes MATOP_RELAX=13, 4071c1c02c0SLois Curfman McInnes MATOP_TRANSPOSE=14, 4081c1c02c0SLois Curfman McInnes MATOP_GETINFO=15, 4091c1c02c0SLois Curfman McInnes MATOP_EQUAL=16, 4101c1c02c0SLois Curfman McInnes MATOP_GET_DIAGONAL=17, 4111c1c02c0SLois Curfman McInnes MATOP_DIAGONAL_SCALE=18, 4121c1c02c0SLois Curfman McInnes MATOP_NORM=19, 4131c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_BEGIN=20, 4141c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_END=21, 4151c1c02c0SLois Curfman McInnes MATOP_COMPRESS=22, 4161c1c02c0SLois Curfman McInnes MATOP_SET_OPTION=23, 4171c1c02c0SLois Curfman McInnes MATOP_ZERO_ENTRIES=24, 4181c1c02c0SLois Curfman McInnes MATOP_ZERO_ROWS=25, 4191c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_SYMBOLIC=26, 4201c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_NUMERIC=27, 4211c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_SYMBOLIC=28, 4221c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_NUMERIC=29, 4231c1c02c0SLois Curfman McInnes MATOP_GET_SIZE=30, 4241c1c02c0SLois Curfman McInnes MATOP_GET_LOCAL_SIZE=31, 4251c1c02c0SLois Curfman McInnes MATOP_GET_OWNERSHIP_RANGE=32, 4261c1c02c0SLois Curfman McInnes MATOP_ILUFACTOR_SYMBOLIC=33, 4271c1c02c0SLois Curfman McInnes MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34, 4281c1c02c0SLois Curfman McInnes MATOP_GET_ARRAY=35, 4291c1c02c0SLois Curfman McInnes MATOP_RESTORE_ARRAY=36, 4307bf97ca4SSatish Balay 431005c665bSBarry Smith MATOP_CONVERT_SAME_TYPE=37, 432005c665bSBarry Smith MATOP_FORWARD_SOLVE=38, 433005c665bSBarry Smith MATOP_BACKWARD_SOLVE=39, 434005c665bSBarry Smith MATOP_ILUFACTOR=40, 435005c665bSBarry Smith MATOP_INCOMPLETECHOLESKYFACTOR=41, 436005c665bSBarry Smith MATOP_AXPY=42, 437005c665bSBarry Smith MATOP_GET_SUBMATRICES=43, 438005c665bSBarry Smith MATOP_INCREASE_OVERLAP=44, 439005c665bSBarry Smith MATOP_GET_VALUES=45, 440005c665bSBarry Smith MATOP_COPY=46, 441005c665bSBarry Smith MATOP_PRINT_HELP=47, 442005c665bSBarry Smith MATOP_SCALE=48, 443005c665bSBarry Smith MATOP_SHIFT=49, 444005c665bSBarry Smith MATOP_DIAGONAL_SHIFT=50, 445005c665bSBarry Smith MATOP_ILUDT_FACTOR=51, 446005c665bSBarry Smith MATOP_GET_BLOCK_SIZE=52, 447005c665bSBarry Smith MATOP_GET_ROW_IJ=53, 448005c665bSBarry Smith MATOP_RESTORE_ROW_IJ=54, 449005c665bSBarry Smith MATOP_GET_COLUMN_IJ=55, 450005c665bSBarry Smith MATOP_RESTORE_COLUMN_IJ=56, 451005c665bSBarry Smith MATOP_FDCOLORING_CREATE=57, 452005c665bSBarry Smith MATOP_COLORING_PATCH=58, 453005c665bSBarry Smith MATOP_SET_UNFACTORED=59, 454005c665bSBarry Smith MATOP_PERMUTE=60, 455005c665bSBarry Smith MATOP_SET_VALUES_BLOCKED=61, 4561c1c02c0SLois Curfman McInnes MATOP_DESTROY=250, 4571c1c02c0SLois Curfman McInnes MATOP_VIEW=251 458fae171e0SBarry Smith } MatOperation; 459ca44d042SBarry Smith EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*); 460ca44d042SBarry Smith EXTERN int MatShellSetOperation(Mat,MatOperation,void *); 461ca44d042SBarry Smith EXTERN int MatShellGetOperation(Mat,MatOperation,void **); 462112a2221SBarry Smith 46390ace30eSBarry Smith /* 46490ace30eSBarry Smith Codes for matrices stored on disk. By default they are 46590ace30eSBarry Smith stored in a universal format. By changing the format with 466639f9d9dSBarry Smith ViewerSetFormat(viewer,VIEWER_FORMAT_BINARY_NATIVE); the matrices will 46790ace30eSBarry Smith be stored in a way natural for the matrix, for example dense matrices 46890ace30eSBarry Smith would be stored as dense. Matrices stored this way may only be 46990ace30eSBarry Smith read into matrices of the same time. 47090ace30eSBarry Smith */ 47190ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1 47290ace30eSBarry Smith 4733f1d51d7SBarry Smith /* 4743f1d51d7SBarry Smith New matrix classes not yet distributed 4753f1d51d7SBarry Smith */ 4763f1d51d7SBarry Smith /* 4773f1d51d7SBarry Smith MatAIJIndices is a data structure for storing the nonzero location information 4783f1d51d7SBarry Smith for sparse matrices. Several matrices with identical nonzero structure can share 4793f1d51d7SBarry Smith the same MatAIJIndices. 4803f1d51d7SBarry Smith */ 481e2a1c21fSSatish Balay typedef struct _p_MatAIJIndices* MatAIJIndices; 4823f1d51d7SBarry Smith 483ca44d042SBarry Smith EXTERN int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*); 484ca44d042SBarry Smith EXTERN int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*); 485ca44d042SBarry Smith EXTERN int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*); 486ca44d042SBarry Smith EXTERN int MatDestroyAIJIndices(MatAIJIndices); 487ca44d042SBarry Smith EXTERN int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*); 488ca44d042SBarry Smith EXTERN int MatValidateAIJIndices(int,MatAIJIndices); 489ca44d042SBarry Smith EXTERN int MatShiftAIJIndices(MatAIJIndices); 490ca44d042SBarry Smith EXTERN int MatShrinkAIJIndices(MatAIJIndices); 491ca44d042SBarry Smith EXTERN int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*); 4923f1d51d7SBarry Smith 493ca44d042SBarry Smith EXTERN int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*); 494ca44d042SBarry Smith EXTERN int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*); 495ca44d042SBarry Smith EXTERN int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,ScalarPrecision,Mat*); 4963f1d51d7SBarry Smith 497ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *); 498ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *); 499ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,ScalarPrecision,Mat *); 5003f1d51d7SBarry Smith 5016d053be9SSatish Balay EXTERN int MatMPIBAIJSetHashTableFactor(Mat,PetscReal); 502ca44d042SBarry Smith EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *); 50308918a0eSSatish Balay EXTERN int MatMPIRowbsGetColor(Mat,ISColoring *); 504860d1616SSatish Balay 50574637425SBarry Smith typedef struct _p_MatNullSpace* MatNullSpace; 50674637425SBarry Smith #define MATNULLSPACE_COOKIE PETSC_COOKIE+17 50774637425SBarry Smith 50874637425SBarry Smith EXTERN int MatNullSpaceCreate(MPI_Comm,int,int,Vec *,MatNullSpace*); 50974637425SBarry Smith EXTERN int MatNullSpaceDestroy(MatNullSpace); 51074637425SBarry Smith EXTERN int MatNullSpaceRemove(MatNullSpace,Vec,Vec*); 51174637425SBarry Smith EXTERN int MatNullSpaceAttach(Mat,MatNullSpace); 51274637425SBarry Smith EXTERN int MatNullSpaceTest(MatNullSpace,Mat); 51374637425SBarry Smith 514f069c275SSatish Balay typedef char* MATType; 515f069c275SSatish Balay EXTERN int MATCreate(MPI_Comm,int,int,int,int,Mat*); 516f069c275SSatish Balay EXTERN int MatSetType(Mat,MATType); 517f069c275SSatish Balay EXTERN int MatRegisterAll(char*); 518f069c275SSatish Balay EXTERN int MatRegister(char*,char*,char*,int(*)(Mat)); 519f069c275SSatish Balay #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 520f069c275SSatish Balay #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0) 521f069c275SSatish Balay #else 522f069c275SSatish Balay #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d) 523f069c275SSatish Balay #endif 5243f1d51d7SBarry Smith 525f069c275SSatish Balay EXTERN int MatCreateMAIJ(Mat,int,Mat*); 526c4f061fbSSatish Balay EXTERN int MatMAIJRedimension(Mat,int,Mat*); 527c4f061fbSSatish Balay EXTERN int MatMAIJGetAIJ(Mat,Mat*); 528c4f061fbSSatish Balay 529f2f9cf34SSatish Balay EXTERN int MatReorderingSeqSBAIJ(Mat A,IS isp); 5306d053be9SSatish Balay EXTERN int MatMPISBAIJSetHashTableFactor(Mat,PetscReal); 5316d053be9SSatish Balay EXTERN int MatSeqSBAIJSetColumnIndices(Mat,int *); 532f069c275SSatish Balay 533c4f061fbSSatish Balay #define MATSEQMAIJ "seqmaij" 534c4f061fbSSatish Balay #define MATMPIMAIJ "mpimaij" 535186905e3SBarry Smith #define MATIS "is" 5362eac72dbSBarry Smith #endif 5372eac72dbSBarry Smith 5382eac72dbSBarry Smith 5399d00d63dSBarry Smith 540