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