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