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