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