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 410 EXTERN PetscErrorCode MatIncreaseOverlap(Mat,int,IS[],int); 411 412 EXTERN PetscErrorCode MatMatMult(Mat,Mat,MatReuse,PetscReal,Mat*); 413 EXTERN PetscErrorCode MatMatMultSymbolic(Mat,Mat,PetscReal,Mat*); 414 EXTERN PetscErrorCode MatMatMultNumeric(Mat,Mat,Mat); 415 416 EXTERN PetscErrorCode MatPtAP(Mat,Mat,MatReuse,PetscReal,Mat*); 417 EXTERN PetscErrorCode MatPtAPSymbolic(Mat,Mat,PetscReal,Mat*); 418 EXTERN PetscErrorCode MatPtAPNumeric(Mat,Mat,Mat); 419 420 EXTERN PetscErrorCode MatMatMultTranspose(Mat,Mat,MatReuse,PetscReal,Mat*); 421 EXTERN PetscErrorCode MatMatMultTransposeSymbolic(Mat,Mat,PetscReal,Mat*); 422 EXTERN PetscErrorCode MatMatMultTransposeNumeric(Mat,Mat,Mat); 423 424 EXTERN PetscErrorCode MatAXPY(const PetscScalar *,Mat,Mat,MatStructure); 425 EXTERN PetscErrorCode MatAYPX(const PetscScalar *,Mat,Mat); 426 EXTERN PetscErrorCode MatCompress(Mat); 427 428 EXTERN PetscErrorCode MatScale(const PetscScalar *,Mat); 429 EXTERN PetscErrorCode MatShift(const PetscScalar *,Mat); 430 431 EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping); 432 EXTERN PetscErrorCode MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping); 433 EXTERN PetscErrorCode MatZeroRowsLocal(Mat,IS,const PetscScalar*); 434 EXTERN PetscErrorCode MatSetValuesLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 435 EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 436 437 EXTERN PetscErrorCode MatStashSetInitialSize(Mat,int,int); 438 EXTERN PetscErrorCode MatStashGetInfo(Mat,int*,int*,int*,int*); 439 440 EXTERN PetscErrorCode MatInterpolateAdd(Mat,Vec,Vec,Vec); 441 EXTERN PetscErrorCode MatInterpolate(Mat,Vec,Vec); 442 EXTERN PetscErrorCode MatRestrict(Mat,Vec,Vec); 443 EXTERN PetscErrorCode MatGetVecs(Mat,Vec*,Vec*); 444 445 /*MC 446 MatPreallocInitialize - Begins the block of code that will count the number of nonzeros per 447 row in a matrix providing the data that one can use to correctly preallocate the matrix. 448 449 Synopsis: 450 int MatPreallocateInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz) 451 452 Collective on MPI_Comm 453 454 Input Parameters: 455 + comm - the communicator that will share the eventually allocated matrix 456 . nrows - the number of rows in the matrix 457 - ncols - the number of columns in the matrix 458 459 Output Parameters: 460 + dnz - the array that will be passed to the matrix preallocation routines 461 - ozn - the other array passed to the matrix preallocation routines 462 463 464 Level: intermediate 465 466 Notes: 467 See the chapter in the users manual on performance for more details 468 469 Do not malloc or free dnz and onz, that is handled internally by these routines 470 471 Use MatPreallocateInitializeSymmetric() for symmetric matrices (MPISBAIJ matrices) 472 473 Concepts: preallocation^Matrix 474 475 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 476 MatPreallocateInitializeSymmetric(), MatPreallocateSymmetricSetLocal() 477 M*/ 478 #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \ 479 { \ 480 PetscErrorCode _4_ierr; int __tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \ 481 _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 482 _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 483 _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\ 484 _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 485 486 /*MC 487 MatPreallocSymmetricInitialize - Begins the block of code that will count the number of nonzeros per 488 row in a matrix providing the data that one can use to correctly preallocate the matrix. 489 490 Synopsis: 491 int MatPreallocateSymmetricInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz) 492 493 Collective on MPI_Comm 494 495 Input Parameters: 496 + comm - the communicator that will share the eventually allocated matrix 497 . nrows - the number of rows in the matrix 498 - ncols - the number of columns in the matrix 499 500 Output Parameters: 501 + dnz - the array that will be passed to the matrix preallocation routines 502 - ozn - the other array passed to the matrix preallocation routines 503 504 505 Level: intermediate 506 507 Notes: 508 See the chapter in the users manual on performance for more details 509 510 Do not malloc or free dnz and onz, that is handled internally by these routines 511 512 Concepts: preallocation^Matrix 513 514 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 515 MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal() 516 M*/ 517 #define MatPreallocateSymmetricInitialize(comm,nrows,ncols,dnz,onz) 0; \ 518 { \ 519 PetscErrorCode _4_ierr; int __tmp = (nrows),__ctmp = (ncols),__rstart,__end; \ 520 _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 521 _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 522 _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr);\ 523 _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 524 525 /*MC 526 MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be 527 inserted using a local number of the rows and columns 528 529 Synopsis: 530 int MatPreallocateSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 531 532 Not Collective 533 534 Input Parameters: 535 + map - the mapping between local numbering and global numbering 536 . nrows - the number of rows indicated 537 . rows - the indices of the rows 538 . ncols - the number of columns in the matrix 539 . cols - the columns indicated 540 . dnz - the array that will be passed to the matrix preallocation routines 541 - ozn - the other array passed to the matrix preallocation routines 542 543 544 Level: intermediate 545 546 Notes: 547 See the chapter in the users manual on performance for more details 548 549 Do not malloc or free dnz and onz, that is handled internally by these routines 550 551 Concepts: preallocation^Matrix 552 553 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 554 MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal() 555 M*/ 556 #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 557 {\ 558 int __l;\ 559 _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 560 _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 561 for (__l=0;__l<nrows;__l++) {\ 562 _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 563 }\ 564 } 565 566 /*MC 567 MatPreallocateSymmetricSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be 568 inserted using a local number of the rows and columns 569 570 Synopsis: 571 int MatPreallocateSymmetricSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 572 573 Not Collective 574 575 Input Parameters: 576 + map - the mapping between local numbering and global numbering 577 . nrows - the number of rows indicated 578 . rows - the indices of the rows 579 . ncols - the number of columns in the matrix 580 . cols - the columns indicated 581 . dnz - the array that will be passed to the matrix preallocation routines 582 - ozn - the other array passed to the matrix preallocation routines 583 584 585 Level: intermediate 586 587 Notes: 588 See the chapter in the users manual on performance for more details 589 590 Do not malloc or free dnz and onz that is handled internally by these routines 591 592 Concepts: preallocation^Matrix 593 594 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 595 MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 596 M*/ 597 #define MatPreallocateSymmetricSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 598 {\ 599 int __l;\ 600 _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 601 _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 602 for (__l=0;__l<nrows;__l++) {\ 603 _4_ierr = MatPreallocateSymmetricSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 604 }\ 605 } 606 607 /*MC 608 MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be 609 inserted using a local number of the rows and columns 610 611 Synopsis: 612 int MatPreallocateSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 613 614 Not Collective 615 616 Input Parameters: 617 + nrows - the number of rows indicated 618 . rows - the indices of the rows 619 . ncols - the number of columns in the matrix 620 - cols - the columns indicated 621 622 Output Parameters: 623 + dnz - the array that will be passed to the matrix preallocation routines 624 - ozn - the other array passed to the matrix preallocation routines 625 626 627 Level: intermediate 628 629 Notes: 630 See the chapter in the users manual on performance for more details 631 632 Do not malloc or free dnz and onz that is handled internally by these routines 633 634 Concepts: preallocation^Matrix 635 636 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 637 MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 638 M*/ 639 #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\ 640 { int __i; \ 641 for (__i=0; __i<nc; __i++) {\ 642 if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \ 643 }\ 644 dnz[row - __rstart] = nc - onz[row - __rstart];\ 645 } 646 647 /*MC 648 MatPreallocateSymmetricSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be 649 inserted using a local number of the rows and columns 650 651 Synopsis: 652 int MatPreallocateSymmetricSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 653 654 Not Collective 655 656 Input Parameters: 657 + nrows - the number of rows indicated 658 . rows - the indices of the rows 659 . ncols - the number of columns in the matrix 660 . cols - the columns indicated 661 . dnz - the array that will be passed to the matrix preallocation routines 662 - ozn - the other array passed to the matrix preallocation routines 663 664 665 Level: intermediate 666 667 Notes: 668 See the chapter in the users manual on performance for more details 669 670 Do not malloc or free dnz and onz that is handled internally by these routines 671 672 Concepts: preallocation^Matrix 673 674 .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 675 MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 676 M*/ 677 #define MatPreallocateSymmetricSet(row,nc,cols,dnz,onz) 0;\ 678 { int __i; \ 679 for (__i=0; __i<nc; __i++) {\ 680 if (cols[__i] >= __end) onz[row - __rstart]++; \ 681 else if (cols[__i] >= row) dnz[row - __rstart]++;\ 682 }\ 683 } 684 685 /*MC 686 MatPreallocFinalize - Ends the block of code that will count the number of nonzeros per 687 row in a matrix providing the data that one can use to correctly preallocate the matrix. 688 689 Synopsis: 690 int MatPreallocateFinalize(int *dnz, int *onz) 691 692 Collective on MPI_Comm 693 694 Input Parameters: 695 + dnz - the array that will be passed to the matrix preallocation routines 696 - ozn - the other array passed to the matrix preallocation routines 697 698 699 Level: intermediate 700 701 Notes: 702 See the chapter in the users manual on performance for more details 703 704 Do not malloc or free dnz and onz that is handled internally by these routines 705 706 Concepts: preallocation^Matrix 707 708 .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 709 MatPreallocateSymmetricInitialize(), MatPreallocateSymmetricSetLocal() 710 M*/ 711 #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree(dnz);CHKERRQ(_4_ierr);} 712 713 714 715 /* Routines unique to particular data structures */ 716 EXTERN PetscErrorCode MatShellGetContext(Mat,void **); 717 718 EXTERN PetscErrorCode MatBDiagGetData(Mat,int*,int*,int*[],int*[],PetscScalar***); 719 EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat,int[]); 720 EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat,int[]); 721 EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int[],int[],PetscScalar[],Mat*); 722 723 EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat,int,int,const int[]); 724 EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat,int,int,const int[]); 725 EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat,int,const int[]); 726 EXTERN PetscErrorCode MatSeqDensePreallocation(Mat,PetscScalar[]); 727 EXTERN PetscErrorCode MatSeqBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]); 728 EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat,PetscScalar[]); 729 730 EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]); 731 EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]); 732 EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat,int,const int[],int,const int[]); 733 EXTERN PetscErrorCode MatMPIDensePreallocation(Mat,PetscScalar[]); 734 EXTERN PetscErrorCode MatMPIBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]); 735 EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat,int[],int[],int[]); 736 EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat,PetscScalar[]); 737 EXTERN PetscErrorCode MatMPIRowbsSetPreallocation(Mat,int,const int[]); 738 EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,int*[]); 739 EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,int*[]); 740 EXTERN PetscErrorCode MatAdicSetLocalFunction(Mat,void (*)(void)); 741 742 EXTERN PetscErrorCode MatSeqDenseSetLDA(Mat,int); 743 744 EXTERN PetscErrorCode MatStoreValues(Mat); 745 EXTERN PetscErrorCode MatRetrieveValues(Mat); 746 747 EXTERN PetscErrorCode MatDAADSetCtx(Mat,void*); 748 749 /* 750 These routines are not usually accessed directly, rather solving is 751 done through the KSP and PC interfaces. 752 */ 753 754 /*E 755 MatOrderingType - String with the name of a PETSc matrix ordering or the creation function 756 with an optional dynamic library name, for example 757 http://www.mcs.anl.gov/petsc/lib.a:orderingcreate() 758 759 Level: beginner 760 761 .seealso: MatGetOrdering() 762 E*/ 763 #define MatOrderingType char* 764 #define MATORDERING_NATURAL "natural" 765 #define MATORDERING_ND "nd" 766 #define MATORDERING_1WD "1wd" 767 #define MATORDERING_RCM "rcm" 768 #define MATORDERING_QMD "qmd" 769 #define MATORDERING_ROWLENGTH "rowlength" 770 #define MATORDERING_DSC_ND "dsc_nd" 771 #define MATORDERING_DSC_MMD "dsc_mmd" 772 #define MATORDERING_DSC_MDF "dsc_mdf" 773 #define MATORDERING_CONSTRAINED "constrained" 774 #define MATORDERING_IDENTITY "identity" 775 #define MATORDERING_REVERSE "reverse" 776 777 EXTERN PetscErrorCode MatGetOrdering(Mat,const MatOrderingType,IS*,IS*); 778 EXTERN PetscErrorCode MatOrderingRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,const MatOrderingType,IS*,IS*)); 779 780 /*MC 781 MatOrderingRegisterDynamic - Adds a new sparse matrix ordering to the 782 matrix package. 783 784 Synopsis: 785 int MatOrderingRegisterDynamic(char *name_ordering,char *path,char *name_create,PetscErrorCode (*routine_create)(MatOrdering)) 786 787 Not Collective 788 789 Input Parameters: 790 + sname - name of ordering (for example MATORDERING_ND) 791 . path - location of library where creation routine is 792 . name - name of function that creates the ordering type,a string 793 - function - function pointer that creates the ordering 794 795 Level: developer 796 797 If dynamic libraries are used, then the fourth input argument (function) 798 is ignored. 799 800 Sample usage: 801 .vb 802 MatOrderingRegisterDynamic("my_order",/home/username/my_lib/lib/libO/solaris/mylib.a, 803 "MyOrder",MyOrder); 804 .ve 805 806 Then, your partitioner can be chosen with the procedural interface via 807 $ MatOrderingSetType(part,"my_order) 808 or at runtime via the option 809 $ -pc_ilu_mat_ordering_type my_order 810 $ -pc_lu_mat_ordering_type my_order 811 812 ${PETSC_ARCH} and ${BOPT} occuring in pathname will be replaced with appropriate values. 813 814 .keywords: matrix, ordering, register 815 816 .seealso: MatOrderingRegisterDestroy(), MatOrderingRegisterAll() 817 M*/ 818 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 819 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0) 820 #else 821 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d) 822 #endif 823 824 EXTERN PetscErrorCode MatOrderingRegisterDestroy(void); 825 EXTERN PetscErrorCode MatOrderingRegisterAll(const char[]); 826 extern PetscTruth MatOrderingRegisterAllCalled; 827 extern PetscFList MatOrderingList; 828 829 EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS); 830 831 /*S 832 MatFactorInfo - Data based into the matrix factorization routines 833 834 In Fortran these are simply double precision arrays of size MAT_FACTORINFO_SIZE 835 836 Notes: These are not usually directly used by users, instead use PC type of LU, ILU, CHOLESKY or ICC. 837 838 Level: developer 839 840 .seealso: MatLUFactorSymbolic(), MatILUFactorSymbolic(), MatCholeskyFactorSymbolic(), MatICCFactorSymbolic(), MatICCFactor() 841 842 S*/ 843 typedef struct { 844 PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 845 PetscReal shift; /* if true, shift until positive pivots */ 846 PetscReal shift_fraction; /* record shift fraction taken */ 847 PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */ 848 PetscReal dt; /* drop tolerance */ 849 PetscReal dtcol; /* tolerance for pivoting */ 850 PetscReal dtcount; /* maximum nonzeros to be allowed per row */ 851 PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 852 PetscReal levels; /* ICC/ILU(levels) */ 853 PetscReal pivotinblocks; /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0 854 factorization may be faster if do not pivot */ 855 PetscReal zeropivot; /* pivot is called zero if less than this */ 856 } MatFactorInfo; 857 858 EXTERN PetscErrorCode MatCholeskyFactor(Mat,IS,MatFactorInfo*); 859 EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*); 860 EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat,Mat*); 861 EXTERN PetscErrorCode MatLUFactor(Mat,IS,IS,MatFactorInfo*); 862 EXTERN PetscErrorCode MatILUFactor(Mat,IS,IS,MatFactorInfo*); 863 EXTERN PetscErrorCode MatLUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*); 864 EXTERN PetscErrorCode MatILUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*); 865 EXTERN PetscErrorCode MatICCFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*); 866 EXTERN PetscErrorCode MatICCFactor(Mat,IS,MatFactorInfo*); 867 EXTERN PetscErrorCode MatLUFactorNumeric(Mat,Mat*); 868 EXTERN PetscErrorCode MatILUDTFactor(Mat,MatFactorInfo*,IS,IS,Mat *); 869 EXTERN PetscErrorCode MatGetInertia(Mat,int*,int*,int*); 870 EXTERN PetscErrorCode MatSolve(Mat,Vec,Vec); 871 EXTERN PetscErrorCode MatForwardSolve(Mat,Vec,Vec); 872 EXTERN PetscErrorCode MatBackwardSolve(Mat,Vec,Vec); 873 EXTERN PetscErrorCode MatSolveAdd(Mat,Vec,Vec,Vec); 874 EXTERN PetscErrorCode MatSolveTranspose(Mat,Vec,Vec); 875 EXTERN PetscErrorCode MatSolveTransposeAdd(Mat,Vec,Vec,Vec); 876 EXTERN PetscErrorCode MatSolves(Mat,Vecs,Vecs); 877 878 EXTERN PetscErrorCode MatSetUnfactored(Mat); 879 880 /*E 881 MatSORType - What type of (S)SOR to perform 882 883 Level: beginner 884 885 May be bitwise ORd together 886 887 Any additions/changes here MUST also be made in include/finclude/petscmat.h 888 889 MatSORType may be bitwise ORd together, so do not change the numbers 890 891 .seealso: MatRelax(), MatPBRelax() 892 E*/ 893 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 894 SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 895 SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 896 SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType; 897 EXTERN PetscErrorCode MatRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec); 898 EXTERN PetscErrorCode MatPBRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec); 899 900 /* 901 These routines are for efficiently computing Jacobians via finite differences. 902 */ 903 904 /*E 905 MatColoringType - String with the name of a PETSc matrix coloring or the creation function 906 with an optional dynamic library name, for example 907 http://www.mcs.anl.gov/petsc/lib.a:coloringcreate() 908 909 Level: beginner 910 911 .seealso: MatGetColoring() 912 E*/ 913 #define MatColoringType char* 914 #define MATCOLORING_NATURAL "natural" 915 #define MATCOLORING_SL "sl" 916 #define MATCOLORING_LF "lf" 917 #define MATCOLORING_ID "id" 918 919 EXTERN PetscErrorCode MatGetColoring(Mat,const MatColoringType,ISColoring*); 920 EXTERN PetscErrorCode MatColoringRegister(const char[],const char[],const char[],PetscErrorCode(*)(Mat,const MatColoringType,ISColoring *)); 921 922 /*MC 923 MatColoringRegisterDynamic - Adds a new sparse matrix coloring to the 924 matrix package. 925 926 Synopsis: 927 int MatColoringRegisterDynamic(char *name_coloring,char *path,char *name_create,PetscErrorCode (*routine_create)(MatColoring)) 928 929 Not Collective 930 931 Input Parameters: 932 + sname - name of Coloring (for example MATCOLORING_SL) 933 . path - location of library where creation routine is 934 . name - name of function that creates the Coloring type, a string 935 - function - function pointer that creates the coloring 936 937 Level: developer 938 939 If dynamic libraries are used, then the fourth input argument (function) 940 is ignored. 941 942 Sample usage: 943 .vb 944 MatColoringRegisterDynamic("my_color",/home/username/my_lib/lib/libO/solaris/mylib.a, 945 "MyColor",MyColor); 946 .ve 947 948 Then, your partitioner can be chosen with the procedural interface via 949 $ MatColoringSetType(part,"my_color") 950 or at runtime via the option 951 $ -mat_coloring_type my_color 952 953 $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values. 954 955 .keywords: matrix, Coloring, register 956 957 .seealso: MatColoringRegisterDestroy(), MatColoringRegisterAll() 958 M*/ 959 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 960 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0) 961 #else 962 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d) 963 #endif 964 965 EXTERN PetscErrorCode MatColoringRegisterAll(const char[]); 966 extern PetscTruth MatColoringRegisterAllCalled; 967 EXTERN PetscErrorCode MatColoringRegisterDestroy(void); 968 EXTERN PetscErrorCode MatColoringPatch(Mat,int,int,const ISColoringValue[],ISColoring*); 969 970 /*S 971 MatFDColoring - Object for computing a sparse Jacobian via finite differences 972 and coloring 973 974 Level: beginner 975 976 Concepts: coloring, sparse Jacobian, finite differences 977 978 .seealso: MatFDColoringCreate() 979 S*/ 980 typedef struct _p_MatFDColoring *MatFDColoring; 981 982 EXTERN PetscErrorCode MatFDColoringCreate(Mat,ISColoring,MatFDColoring *); 983 EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring); 984 EXTERN PetscErrorCode MatFDColoringView(MatFDColoring,PetscViewer); 985 EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring,PetscErrorCode (*)(void),void*); 986 EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal); 987 EXTERN PetscErrorCode MatFDColoringSetFrequency(MatFDColoring,int); 988 EXTERN PetscErrorCode MatFDColoringGetFrequency(MatFDColoring,int*); 989 EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring); 990 EXTERN PetscErrorCode MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *); 991 EXTERN PetscErrorCode MatFDColoringApplyTS(Mat,MatFDColoring,PetscReal,Vec,MatStructure*,void *); 992 EXTERN PetscErrorCode MatFDColoringSetRecompute(MatFDColoring); 993 EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring,Vec); 994 EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring,int*,int*[]); 995 /* 996 These routines are for partitioning matrices: currently used only 997 for adjacency matrix, MatCreateMPIAdj(). 998 */ 999 1000 /*S 1001 MatPartitioning - Object for managing the partitioning of a matrix or graph 1002 1003 Level: beginner 1004 1005 Concepts: partitioning 1006 1007 .seealso: MatPartitioningCreate(), MatPartitioningType 1008 S*/ 1009 typedef struct _p_MatPartitioning *MatPartitioning; 1010 1011 /*E 1012 MatPartitioningType - String with the name of a PETSc matrix partitioning or the creation function 1013 with an optional dynamic library name, for example 1014 http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate() 1015 1016 Level: beginner 1017 1018 .seealso: MatPartitioningCreate(), MatPartitioning 1019 E*/ 1020 #define MatPartitioningType char* 1021 #define MAT_PARTITIONING_CURRENT "current" 1022 #define MAT_PARTITIONING_PARMETIS "parmetis" 1023 #define MAT_PARTITIONING_CHACO "chaco" 1024 #define MAT_PARTITIONING_JOSTLE "jostle" 1025 #define MAT_PARTITIONING_PARTY "party" 1026 #define MAT_PARTITIONING_SCOTCH "scotch" 1027 1028 1029 EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm,MatPartitioning*); 1030 EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning,const MatPartitioningType); 1031 EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning,int); 1032 EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning,Mat); 1033 EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning,const int[]); 1034 EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning,const PetscReal []); 1035 EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning,IS*); 1036 EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning); 1037 1038 EXTERN PetscErrorCode MatPartitioningRegister(const char[],const char[],const char[],PetscErrorCode (*)(MatPartitioning)); 1039 1040 /*MC 1041 MatPartitioningRegisterDynamic - Adds a new sparse matrix partitioning to the 1042 matrix package. 1043 1044 Synopsis: 1045 int MatPartitioningRegisterDynamic(char *name_partitioning,char *path,char *name_create,PetscErrorCode (*routine_create)(MatPartitioning)) 1046 1047 Not Collective 1048 1049 Input Parameters: 1050 + sname - name of partitioning (for example MAT_PARTITIONING_CURRENT) or parmetis 1051 . path - location of library where creation routine is 1052 . name - name of function that creates the partitioning type, a string 1053 - function - function pointer that creates the partitioning type 1054 1055 Level: developer 1056 1057 If dynamic libraries are used, then the fourth input argument (function) 1058 is ignored. 1059 1060 Sample usage: 1061 .vb 1062 MatPartitioningRegisterDynamic("my_part",/home/username/my_lib/lib/libO/solaris/mylib.a, 1063 "MyPartCreate",MyPartCreate); 1064 .ve 1065 1066 Then, your partitioner can be chosen with the procedural interface via 1067 $ MatPartitioningSetType(part,"my_part") 1068 or at runtime via the option 1069 $ -mat_partitioning_type my_part 1070 1071 $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values. 1072 1073 .keywords: matrix, partitioning, register 1074 1075 .seealso: MatPartitioningRegisterDestroy(), MatPartitioningRegisterAll() 1076 M*/ 1077 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1078 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0) 1079 #else 1080 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d) 1081 #endif 1082 1083 EXTERN PetscErrorCode MatPartitioningRegisterAll(const char[]); 1084 extern PetscTruth MatPartitioningRegisterAllCalled; 1085 EXTERN PetscErrorCode MatPartitioningRegisterDestroy(void); 1086 1087 EXTERN PetscErrorCode MatPartitioningView(MatPartitioning,PetscViewer); 1088 EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning); 1089 EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning,MatPartitioningType*); 1090 1091 EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 1092 1093 EXTERN PetscErrorCode MatPartitioningJostleSetCoarseLevel(MatPartitioning,PetscReal); 1094 EXTERN PetscErrorCode MatPartitioningJostleSetCoarseSequential(MatPartitioning); 1095 1096 typedef enum { MP_CHACO_MULTILEVEL_KL, MP_CHACO_SPECTRAL, MP_CHACO_LINEAR, 1097 MP_CHACO_RANDOM, MP_CHACO_SCATTERED } MPChacoGlobalType; 1098 EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning, MPChacoGlobalType); 1099 typedef enum { MP_CHACO_KERNIGHAN_LIN, MP_CHACO_NONE } MPChacoLocalType; 1100 EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning, MPChacoLocalType); 1101 EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning,PetscReal); 1102 typedef enum { MP_CHACO_LANCZOS, MP_CHACO_RQI_SYMMLQ } MPChacoEigenType; 1103 EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning,MPChacoEigenType); 1104 EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning, PetscReal); 1105 EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning, int); 1106 1107 #define MP_PARTY_OPT "opt" 1108 #define MP_PARTY_LIN "lin" 1109 #define MP_PARTY_SCA "sca" 1110 #define MP_PARTY_RAN "ran" 1111 #define MP_PARTY_GBF "gbf" 1112 #define MP_PARTY_GCF "gcf" 1113 #define MP_PARTY_BUB "bub" 1114 #define MP_PARTY_DEF "def" 1115 EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning, const char*); 1116 #define MP_PARTY_HELPFUL_SETS "hs" 1117 #define MP_PARTY_KERNIGHAN_LIN "kl" 1118 #define MP_PARTY_NONE "no" 1119 EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning, const char*); 1120 EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning,PetscReal); 1121 EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning,PetscTruth); 1122 EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning,PetscTruth); 1123 1124 typedef enum { MP_SCOTCH_GREEDY, MP_SCOTCH_GPS, MP_SCOTCH_GR_GPS } MPScotchGlobalType; 1125 EXTERN PetscErrorCode MatPartitioningScotchSetArch(MatPartitioning,const char*); 1126 EXTERN PetscErrorCode MatPartitioningScotchSetMultilevel(MatPartitioning); 1127 EXTERN PetscErrorCode MatPartitioningScotchSetGlobal(MatPartitioning,MPScotchGlobalType); 1128 EXTERN PetscErrorCode MatPartitioningScotchSetCoarseLevel(MatPartitioning,PetscReal); 1129 EXTERN PetscErrorCode MatPartitioningScotchSetHostList(MatPartitioning,const char*); 1130 typedef enum { MP_SCOTCH_KERNIGHAN_LIN, MP_SCOTCH_NONE } MPScotchLocalType; 1131 EXTERN PetscErrorCode MatPartitioningScotchSetLocal(MatPartitioning,MPScotchLocalType); 1132 EXTERN PetscErrorCode MatPartitioningScotchSetMapping(MatPartitioning); 1133 EXTERN PetscErrorCode MatPartitioningScotchSetStrategy(MatPartitioning,char*); 1134 1135 /* 1136 If you add entries here you must also add them to finclude/petscmat.h 1137 */ 1138 typedef enum { MATOP_SET_VALUES=0, 1139 MATOP_GET_ROW=1, 1140 MATOP_RESTORE_ROW=2, 1141 MATOP_MULT=3, 1142 MATOP_MULT_ADD=4, 1143 MATOP_MULT_TRANSPOSE=5, 1144 MATOP_MULT_TRANSPOSE_ADD=6, 1145 MATOP_SOLVE=7, 1146 MATOP_SOLVE_ADD=8, 1147 MATOP_SOLVE_TRANSPOSE=9, 1148 MATOP_SOLVE_TRANSPOSE_ADD=10, 1149 MATOP_LUFACTOR=11, 1150 MATOP_CHOLESKYFACTOR=12, 1151 MATOP_RELAX=13, 1152 MATOP_TRANSPOSE=14, 1153 MATOP_GETINFO=15, 1154 MATOP_EQUAL=16, 1155 MATOP_GET_DIAGONAL=17, 1156 MATOP_DIAGONAL_SCALE=18, 1157 MATOP_NORM=19, 1158 MATOP_ASSEMBLY_BEGIN=20, 1159 MATOP_ASSEMBLY_END=21, 1160 MATOP_COMPRESS=22, 1161 MATOP_SET_OPTION=23, 1162 MATOP_ZERO_ENTRIES=24, 1163 MATOP_ZERO_ROWS=25, 1164 MATOP_LUFACTOR_SYMBOLIC=26, 1165 MATOP_LUFACTOR_NUMERIC=27, 1166 MATOP_CHOLESKY_FACTOR_SYMBOLIC=28, 1167 MATOP_CHOLESKY_FACTOR_NUMERIC=29, 1168 MATOP_SETUP_PREALLOCATION=30, 1169 MATOP_ILUFACTOR_SYMBOLIC=31, 1170 MATOP_ICCFACTOR_SYMBOLIC=32, 1171 MATOP_GET_ARRAY=33, 1172 MATOP_RESTORE_ARRAY=34, 1173 MATOP_DUPLCIATE=35, 1174 MATOP_FORWARD_SOLVE=36, 1175 MATOP_BACKWARD_SOLVE=37, 1176 MATOP_ILUFACTOR=38, 1177 MATOP_ICCFACTOR=39, 1178 MATOP_AXPY=40, 1179 MATOP_GET_SUBMATRICES=41, 1180 MATOP_INCREASE_OVERLAP=42, 1181 MATOP_GET_VALUES=43, 1182 MATOP_COPY=44, 1183 MATOP_PRINT_HELP=45, 1184 MATOP_SCALE=46, 1185 MATOP_SHIFT=47, 1186 MATOP_DIAGONAL_SHIFT=48, 1187 MATOP_ILUDT_FACTOR=49, 1188 MATOP_GET_BLOCK_SIZE=50, 1189 MATOP_GET_ROW_IJ=51, 1190 MATOP_RESTORE_ROW_IJ=52, 1191 MATOP_GET_COLUMN_IJ=53, 1192 MATOP_RESTORE_COLUMN_IJ=54, 1193 MATOP_FDCOLORING_CREATE=55, 1194 MATOP_COLORING_PATCH=56, 1195 MATOP_SET_UNFACTORED=57, 1196 MATOP_PERMUTE=58, 1197 MATOP_SET_VALUES_BLOCKED=59, 1198 MATOP_GET_SUBMATRIX=60, 1199 MATOP_DESTROY=61, 1200 MATOP_VIEW=62, 1201 MATOP_GET_MAPS=63, 1202 MATOP_USE_SCALED_FORM=64, 1203 MATOP_SCALE_SYSTEM=65, 1204 MATOP_UNSCALE_SYSTEM=66, 1205 MATOP_SET_LOCAL_TO_GLOBAL_MAP=67, 1206 MATOP_SET_VALUES_LOCAL=68, 1207 MATOP_ZERO_ROWS_LOCAL=69, 1208 MATOP_GET_ROW_MAX=70, 1209 MATOP_CONVERT=71, 1210 MATOP_SET_COLORING=72, 1211 MATOP_SET_VALUES_ADIC=73, 1212 MATOP_SET_VALUES_ADIFOR=74, 1213 MATOP_FD_COLORING_APPLY=75, 1214 MATOP_SET_FROM_OPTIONS=76, 1215 MATOP_MULT_CON=77, 1216 MATOP_MULT_TRANSPOSE_CON=78, 1217 MATOP_ILU_FACTOR_SYMBOLIC_CON=79, 1218 MATOP_PERMUTE_SPARSIFY=80, 1219 MATOP_MULT_MULTIPLE=81, 1220 MATOP_SOLVE_MULTIPLE=82, 1221 MATOP_GET_INERTIA=83, 1222 MATOP_LOAD=84, 1223 MATOP_IS_SYMMETRIC=85, 1224 MATOP_IS_HERMITIAN=86, 1225 MATOP_IS_STRUCTURALLY_SYMMETRIC=87, 1226 MATOP_PB_RELAX=88, 1227 MATOP_GET_VECS=89, 1228 MATOP_MAT_MULT=90, 1229 MATOP_MAT_MULT_SYMBOLIC=91, 1230 MATOP_MAT_MULT_NUMERIC=92, 1231 MATOP_PTAP=93, 1232 MATOP_PTAP_SYMBOLIC=94, 1233 MATOP_PTAP_NUMERIC=95, 1234 MATOP_MAT_MULTTRANSPOSE=96, 1235 MATOP_MAT_MULTTRANSPOSE_SYMBOLIC=97, 1236 MATOP_MAT_MULTTRANSPOSE_NUMERIC=98 1237 } MatOperation; 1238 EXTERN PetscErrorCode MatHasOperation(Mat,MatOperation,PetscTruth*); 1239 EXTERN PetscErrorCode MatShellSetOperation(Mat,MatOperation,void(*)(void)); 1240 EXTERN PetscErrorCode MatShellGetOperation(Mat,MatOperation,void(**)(void)); 1241 EXTERN PetscErrorCode MatShellSetContext(Mat,void*); 1242 1243 /* 1244 Codes for matrices stored on disk. By default they are 1245 stored in a universal format. By changing the format with 1246 PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will 1247 be stored in a way natural for the matrix, for example dense matrices 1248 would be stored as dense. Matrices stored this way may only be 1249 read into matrices of the same time. 1250 */ 1251 #define MATRIX_BINARY_FORMAT_DENSE -1 1252 1253 EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat,PetscReal); 1254 EXTERN PetscErrorCode MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *); 1255 EXTERN PetscErrorCode MatMPIRowbsGetColor(Mat,ISColoring *); 1256 1257 EXTERN PetscErrorCode MatISGetLocalMat(Mat,Mat*); 1258 1259 /*S 1260 MatNullSpace - Object that removes a null space from a vector, i.e. 1261 orthogonalizes the vector to a subsapce 1262 1263 Level: advanced 1264 1265 Concepts: matrix; linear operator, null space 1266 1267 Users manual sections: 1268 . sec_singular 1269 1270 .seealso: MatNullSpaceCreate() 1271 S*/ 1272 typedef struct _p_MatNullSpace* MatNullSpace; 1273 1274 EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm,int,int,const Vec[],MatNullSpace*); 1275 EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace); 1276 EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace,Vec,Vec*); 1277 EXTERN PetscErrorCode MatNullSpaceAttach(Mat,MatNullSpace); 1278 EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace,Mat); 1279 1280 EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat,IS); 1281 EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat,PetscReal); 1282 EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat,int *); 1283 1284 1285 EXTERN PetscErrorCode MatCreateMAIJ(Mat,int,Mat*); 1286 EXTERN PetscErrorCode MatMAIJRedimension(Mat,int,Mat*); 1287 EXTERN PetscErrorCode MatMAIJGetAIJ(Mat,Mat*); 1288 1289 EXTERN PetscErrorCode MatComputeExplicitOperator(Mat,Mat*); 1290 1291 EXTERN PetscErrorCode MatESISetType(Mat,const char*); 1292 EXTERN PetscErrorCode MatESISetFromOptions(Mat); 1293 1294 EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat,Vec); 1295 1296 EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, int, int, PetscReal *); 1297 EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, int, int, int *, int *, PetscReal *); 1298 1299 PETSC_EXTERN_CXX_END 1300 #endif 1301