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