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