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