1 /* $Id: mat.h,v 1.112 1996/08/22 19:53:21 curfman Exp curfman $ */ 2 /* 3 Include file for the matrix component of PETSc 4 */ 5 #ifndef __MAT_PACKAGE 6 #define __MAT_PACKAGE 7 #include "vec.h" 8 9 #define MAT_COOKIE PETSC_COOKIE+5 10 11 typedef struct _Mat* Mat; 12 13 typedef enum { MATSAME=-1, MATSEQDENSE, MATSEQAIJ, MATMPIAIJ, MATSHELL, 14 MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG, 15 MATMPIDENSE, MATSEQBAIJ, MATMPIBAIJ} MatType; 16 17 extern int MatCreate(MPI_Comm,int,int,Mat*); 18 extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*); 19 extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*); 20 extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*); 21 extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*); 22 extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*); 23 extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*); 24 extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*); 25 extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 26 extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 27 28 extern int MatDestroy(Mat); 29 30 extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*); 31 extern int MatShellGetContext(Mat,void **); 32 33 34 extern int MatPrintHelp(Mat); 35 36 /* ------------------------------------------------------------*/ 37 extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode); 38 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType; 39 extern int MatAssemblyBegin(Mat,MatAssemblyType); 40 extern int MatAssemblyEnd(Mat,MatAssemblyType); 41 42 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4, 43 MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16, 44 MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64, 45 MAT_STRUCTURALLY_SYMMETRIC,MAT_NO_NEW_DIAGONALS, 46 MAT_YES_NEW_DIAGONALS,MAT_INODE_LIMIT_1,MAT_INODE_LIMIT_2, 47 MAT_INODE_LIMIT_3,MAT_INODE_LIMIT_4,MAT_INODE_LIMIT_5} MatOption; 48 extern int MatSetOption(Mat,MatOption); 49 extern int MatGetType(Mat,MatType*,char**); 50 extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*); 51 extern int MatGetValues(Mat,int,int*,int,int*,Scalar*); 52 extern int MatGetRow(Mat,int,int *,int **,Scalar**); 53 extern int MatRestoreRow(Mat,int,int *,int **,Scalar**); 54 extern int MatGetColumn(Mat,int,int *,int **,Scalar**); 55 extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**); 56 extern int MatGetArray(Mat,Scalar **); 57 extern int MatRestoreArray(Mat,Scalar **); 58 extern int MatGetBlockSize(Mat,int *); 59 60 extern int MatMult(Mat,Vec,Vec); 61 extern int MatMultAdd(Mat,Vec,Vec,Vec); 62 extern int MatMultTrans(Mat,Vec,Vec); 63 extern int MatMultTransAdd(Mat,Vec,Vec,Vec); 64 65 extern int MatConvert(Mat,MatType,Mat*); 66 extern int MatCopy(Mat,Mat); 67 extern int MatView(Mat,Viewer); 68 extern int MatLoad(Viewer,MatType,Mat*); 69 70 /* 71 Context of matrix information, used with MatGetInfo() 72 Note: If any entries are added to this context, be sure 73 to adjust MAT_INFO_SIZE in FINCLUDE/mat.h 74 */ 75 typedef struct { 76 double rows_global, columns_global; /* number of global rows and columns */ 77 double rows_local, columns_local; /* number of local rows and columns */ 78 double block_size; /* block size */ 79 double nz_allocated, nz_used, nz_unneeded; /* number of nonzeros */ 80 double memory; /* memory allocated */ 81 double assemblies; /* number of matrix assemblies */ 82 double mallocs; /* number of mallocs during MatSetValues() */ 83 double fill_ratio_given, fill_ratio_needed; /* fill ration for LU/ILU */ 84 double factor_mallocs; /* number of mallocs during factorization */ 85 } MatInfo; 86 87 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType; 88 extern int MatGetInfo(Mat,MatInfoType,MatInfo*); 89 extern int MatValid(Mat,PetscTruth*); 90 extern int MatGetDiagonal(Mat,Vec); 91 extern int MatTranspose(Mat,Mat*); 92 extern int MatDiagonalScale(Mat,Vec,Vec); 93 extern int MatDiagonalShift(Mat,Vec); 94 extern int MatEqual(Mat,Mat, PetscTruth*); 95 96 extern int MatNorm(Mat,NormType,double *); 97 extern int MatZeroEntries(Mat); 98 extern int MatZeroRows(Mat,IS,Scalar*); 99 extern int MatZeroColumns(Mat,IS,Scalar*); 100 101 extern int MatGetSize(Mat,int*,int*); 102 extern int MatGetLocalSize(Mat,int*,int*); 103 extern int MatGetOwnershipRange(Mat,int*,int*); 104 105 typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall; 106 extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **); 107 extern int MatDestroyMatrices(int, Mat **); 108 extern int MatIncreaseOverlap(Mat,int,IS *,int); 109 110 extern int MatAXPY(Scalar *,Mat,Mat); 111 extern int MatCompress(Mat); 112 113 extern int MatScale(Scalar *,Mat); 114 extern int MatShift(Scalar *,Mat); 115 116 /* Routines unique to particular data structures */ 117 extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***); 118 119 /* 120 These routines are not usually accessed directly, rather solving is 121 done through the SLES, KSP and PC interfaces. 122 */ 123 124 typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2, 125 ORDER_RCM=3,ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_FLOW, 126 ORDER_APPLICATION_1,ORDER_APPLICATION_2} MatReordering; 127 extern int MatGetReordering(Mat,MatReordering,IS*,IS*); 128 extern int MatGetReorderingTypeFromOptions(char *,MatReordering*); 129 extern int MatReorderingRegister(MatReordering *,char*,PetscTruth,int, 130 int (*)(int*,int*,int*,int*,int*)); 131 extern int MatReorderingRegisterAll(); 132 extern int MatReorderingRegisterDestroy(); 133 extern int MatReorderingGetName(MatReordering,char **); 134 extern PetscTruth MatReorderingRequiresSymmetric[]; 135 extern int MatReorderingIndexShift[]; 136 137 extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS); 138 139 extern int MatCholeskyFactor(Mat,IS,double); 140 extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*); 141 extern int MatCholeskyFactorNumeric(Mat,Mat*); 142 143 extern int MatLUFactor(Mat,IS,IS,double); 144 extern int MatILUFactor(Mat,IS,IS,double,int); 145 extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*); 146 extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*); 147 extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*); 148 extern int MatLUFactorNumeric(Mat,Mat*); 149 extern int MatILUDTFactor(Mat,double,int,IS,IS,Mat *); 150 151 152 extern int MatSolve(Mat,Vec,Vec); 153 extern int MatForwardSolve(Mat,Vec,Vec); 154 extern int MatBackwardSolve(Mat,Vec,Vec); 155 extern int MatSolveAdd(Mat,Vec,Vec,Vec); 156 extern int MatSolveTrans(Mat,Vec,Vec); 157 extern int MatSolveTransAdd(Mat,Vec,Vec,Vec); 158 159 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 160 SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 161 SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 162 SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128 163 } MatSORType; 164 extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec); 165 166 typedef enum { MAT_SET_VALUES=0, 167 MAT_GET_ROW=1, 168 MAT_RESTORE_ROW=2, 169 MAT_MULT=3, 170 MAT_MULT_ADD=4, 171 MAT_MULT_TRANS=5, 172 MAT_MULT_TRANS_ADD=6, 173 MAT_SOLVE=7, 174 MAT_SOLVE_ADD=8, 175 MAT_SOLVE_TRANS=9, 176 MAT_SOLVE_TRANS_ADD=10, 177 MAT_LUFACTOR=11, 178 MAT_CHOLESKYFACTOR=12, 179 MAT_RELAX=13, 180 MAT_TRANSPOSE=14, 181 MAT_GETINFO=15, 182 MAT_EQUAL=16, 183 MAT_GET_DIAGONAL=17, 184 MAT_DIAGONAL_SCALE=18, 185 MAT_NORM=19, 186 MAT_ASSEMBLY_BEGIN=20, 187 MAT_ASSEMBLY_END=21, 188 MAT_COMPRESS=22, 189 MAT_SET_OPTION=23, 190 MAT_ZERO_ENTRIES=24, 191 MAT_ZERO_ROWS=25, 192 MAT_GET_REORDERING=26, 193 MAT_LUFACTOR_SYMBOLIC=27, 194 MAT_LUFACTOR_NUMERIC=28, 195 MAT_CHOLESKY_FACTOR_SYMBOLIC=29, 196 MAT_CHOLESKY_FACTOR_NUMERIC=30, 197 MAT_GET_SIZE=31, 198 MAT_GET_LOCAL_SIZE=32, 199 MAT_GET_OWNERSHIP_RANGE=33, 200 MAT_ILUFACTOR_SYMBOLIC=34, 201 MAT_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=35, 202 MAT_GET_ARRAY=36, 203 MAT_RESTORE_ARRAY=37, 204 MAT_CONVERT=38, 205 MAT_GET_SUBMATRIX=39, 206 MAT_GET_SUBMATRIX_INPLACE=40, 207 MAT_CONVERT_SAME_TYPE=41, 208 MAT_FORWARD_SOLVE=42, 209 MAT_BACKWARD_SOLVE=43, 210 MAT_ILUFACTOR=44, 211 MAT_INCOMPLETECHOLESKYFACTOR=45, 212 MAT_AXPY=46, 213 MAT_GET_SUBMATRICES=47, 214 MAT_INCREASE_OVERLAP=48, 215 MAT_GET_VALUES=49, 216 MAT_COPY=50, 217 MAT_PRINT_HELP=51, 218 MAT_SCALE=52, 219 MAT_SHIFT=53, 220 MAT_DIAGONAL_SHIFT=54, 221 MAT_DESTROY=250, 222 MAT_VIEW=251 223 } MatOperation; 224 extern int MatHasOperation(Mat,MatOperation,PetscTruth*); 225 extern int MatShellSetOperation(Mat,MatOperation,void *); 226 227 /* 228 Codes for matrices stored on disk. By default they are 229 stored in a universal format. By changing the format with 230 ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will 231 be stored in a way natural for the matrix, for example dense matrices 232 would be stored as dense. Matrices stored this way may only be 233 read into matrices of the same time. 234 */ 235 #define MATRIX_BINARY_FORMAT_DENSE -1 236 237 #endif 238 239 240 241