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