1 /* 2 Include file for the matrix component of PETSc 3 */ 4 #pragma once 5 6 #include <petscvec.h> 7 8 /* SUBMANSEC = Mat */ 9 10 /*S 11 Mat - Abstract PETSc matrix object used to manage all linear operators in PETSc, even those without 12 an explicit sparse representation (such as matrix-free operators). Also used to hold representations of graphs 13 for graph operations such as coloring, `MatColoringCreate()` 14 15 Level: beginner 16 17 Note: 18 See [](doc_matrix), [](ch_matrices) and `MatType` for available matrix types 19 20 .seealso: [](doc_matrix), [](ch_matrices), `MatCreate()`, `MatType`, `MatSetType()`, `MatDestroy()` 21 S*/ 22 typedef struct _p_Mat *Mat; 23 24 /*J 25 MatType - String with the name of a PETSc matrix type 26 27 Level: beginner 28 29 Note: 30 [](doc_matrix) for a table of available matrix types 31 32 .seealso: [](doc_matrix), [](ch_matrices), `MatSetType()`, `Mat`, `MatSolverType`, `MatRegister()` 33 J*/ 34 typedef const char *MatType; 35 #define MATSAME "same" 36 #define MATMAIJ "maij" 37 #define MATSEQMAIJ "seqmaij" 38 #define MATMPIMAIJ "mpimaij" 39 #define MATKAIJ "kaij" 40 #define MATSEQKAIJ "seqkaij" 41 #define MATMPIKAIJ "mpikaij" 42 #define MATIS "is" 43 #define MATAIJ "aij" 44 #define MATSEQAIJ "seqaij" 45 #define MATMPIAIJ "mpiaij" 46 #define MATAIJCRL "aijcrl" 47 #define MATSEQAIJCRL "seqaijcrl" 48 #define MATMPIAIJCRL "mpiaijcrl" 49 #define MATAIJCUSPARSE "aijcusparse" 50 #define MATSEQAIJCUSPARSE "seqaijcusparse" 51 #define MATMPIAIJCUSPARSE "mpiaijcusparse" 52 #define MATAIJHIPSPARSE "aijhipsparse" 53 #define MATSEQAIJHIPSPARSE "seqaijhipsparse" 54 #define MATMPIAIJHIPSPARSE "mpiaijhipsparse" 55 #define MATAIJKOKKOS "aijkokkos" 56 #define MATSEQAIJKOKKOS "seqaijkokkos" 57 #define MATMPIAIJKOKKOS "mpiaijkokkos" 58 #define MATAIJVIENNACL "aijviennacl" 59 #define MATSEQAIJVIENNACL "seqaijviennacl" 60 #define MATMPIAIJVIENNACL "mpiaijviennacl" 61 #define MATAIJPERM "aijperm" 62 #define MATSEQAIJPERM "seqaijperm" 63 #define MATMPIAIJPERM "mpiaijperm" 64 #define MATAIJSELL "aijsell" 65 #define MATSEQAIJSELL "seqaijsell" 66 #define MATMPIAIJSELL "mpiaijsell" 67 #define MATAIJMKL "aijmkl" 68 #define MATSEQAIJMKL "seqaijmkl" 69 #define MATMPIAIJMKL "mpiaijmkl" 70 #define MATBAIJMKL "baijmkl" 71 #define MATSEQBAIJMKL "seqbaijmkl" 72 #define MATMPIBAIJMKL "mpibaijmkl" 73 #define MATSHELL "shell" 74 #define MATCENTERING "centering" 75 #define MATDENSE "dense" 76 #define MATDENSECUDA "densecuda" 77 #define MATDENSEHIP "densehip" 78 #define MATSEQDENSE "seqdense" 79 #define MATSEQDENSECUDA "seqdensecuda" 80 #define MATSEQDENSEHIP "seqdensehip" 81 #define MATMPIDENSE "mpidense" 82 #define MATMPIDENSECUDA "mpidensecuda" 83 #define MATMPIDENSEHIP "mpidensehip" 84 #define MATELEMENTAL "elemental" 85 #define MATSCALAPACK "scalapack" 86 #define MATBAIJ "baij" 87 #define MATSEQBAIJ "seqbaij" 88 #define MATMPIBAIJ "mpibaij" 89 #define MATMPIADJ "mpiadj" 90 #define MATSBAIJ "sbaij" 91 #define MATSEQSBAIJ "seqsbaij" 92 #define MATMPISBAIJ "mpisbaij" 93 #define MATMFFD "mffd" 94 #define MATNORMAL "normal" 95 #define MATNORMALHERMITIAN "normalh" 96 #define MATLRC "lrc" 97 #define MATSCATTER "scatter" 98 #define MATBLOCKMAT "blockmat" 99 #define MATCOMPOSITE "composite" 100 #define MATFFT "fft" 101 #define MATFFTW "fftw" 102 #define MATSEQCUFFT "seqcufft" 103 #define MATSEQHIPFFT "seqhipfft" 104 #define MATTRANSPOSEMAT PETSC_DEPRECATED_MACRO(3, 18, 0, "MATTRANSPOSEVIRTUAL", ) "transpose" 105 #define MATTRANSPOSEVIRTUAL "transpose" 106 #define MATHERMITIANTRANSPOSEVIRTUAL "hermitiantranspose" 107 #define MATSCHURCOMPLEMENT "schurcomplement" 108 #define MATPYTHON "python" 109 #define MATHYPRE "hypre" 110 #define MATHYPRESTRUCT "hyprestruct" 111 #define MATHYPRESSTRUCT "hypresstruct" 112 #define MATSUBMATRIX "submatrix" 113 #define MATLOCALREF "localref" 114 #define MATNEST "nest" 115 #define MATPREALLOCATOR "preallocator" 116 #define MATSELL "sell" 117 #define MATSEQSELL "seqsell" 118 #define MATMPISELL "mpisell" 119 #define MATSELLCUDA "sellcuda" 120 #define MATSEQSELLCUDA "seqsellcuda" 121 #define MATMPISELLCUDA "mpisellcuda" 122 #define MATDUMMY "dummy" 123 #define MATLMVM "lmvm" 124 #define MATLMVMDFP "lmvmdfp" 125 #define MATLMVMBFGS "lmvmbfgs" 126 #define MATLMVMSR1 "lmvmsr1" 127 #define MATLMVMBROYDEN "lmvmbroyden" 128 #define MATLMVMBADBROYDEN "lmvmbadbroyden" 129 #define MATLMVMSYMBROYDEN "lmvmsymbroyden" 130 #define MATLMVMSYMBADBROYDEN "lmvmsymbadbroyden" 131 #define MATLMVMDIAGBROYDEN "lmvmdiagbroyden" 132 #define MATCONSTANTDIAGONAL "constantdiagonal" 133 #define MATDIAGONAL "diagonal" 134 #define MATHTOOL "htool" 135 #define MATH2OPUS "h2opus" 136 137 /*J 138 MatSolverType - String with the name of a PETSc factorization-based matrix solver type. 139 140 For example: "petsc" indicates what PETSc provides, "superlu_dist" the parallel SuperLU_DIST package etc 141 142 Level: beginner 143 144 Note: 145 `MATSOLVERUMFPACK`, `MATSOLVERCHOLMOD`, `MATSOLVERKLU`, `MATSOLVERSPQR` form the SuiteSparse package; you can use `--download-suitesparse` as 146 a ./configure option to install them 147 148 .seealso: [](sec_matfactor), [](ch_matrices), `MatGetFactor()`, `PCFactorSetMatSolverType()`, `PCFactorGetMatSolverType()` 149 J*/ 150 typedef const char *MatSolverType; 151 #define MATSOLVERSUPERLU "superlu" 152 #define MATSOLVERSUPERLU_DIST "superlu_dist" 153 #define MATSOLVERSTRUMPACK "strumpack" 154 #define MATSOLVERUMFPACK "umfpack" 155 #define MATSOLVERCHOLMOD "cholmod" 156 #define MATSOLVERKLU "klu" 157 #define MATSOLVERELEMENTAL "elemental" 158 #define MATSOLVERSCALAPACK "scalapack" 159 #define MATSOLVERESSL "essl" 160 #define MATSOLVERLUSOL "lusol" 161 #define MATSOLVERMUMPS "mumps" 162 #define MATSOLVERMKL_PARDISO "mkl_pardiso" 163 #define MATSOLVERMKL_CPARDISO "mkl_cpardiso" 164 #define MATSOLVERPASTIX "pastix" 165 #define MATSOLVERMATLAB "matlab" 166 #define MATSOLVERPETSC "petsc" 167 #define MATSOLVERBAS "bas" 168 #define MATSOLVERCUSPARSE "cusparse" 169 #define MATSOLVERCUDA "cuda" 170 #define MATSOLVERHIPSPARSE "hipsparse" 171 #define MATSOLVERHIP "hip" 172 #define MATSOLVERKOKKOS "kokkos" 173 #define MATSOLVERSPQR "spqr" 174 175 /*E 176 MatFactorType - indicates what type of factorization is requested 177 178 Values: 179 + `MAT_FACTOR_LU` - LU factorization 180 . `MAT_FACTOR_CHOLESKY` - Cholesky factorization 181 . `MAT_FACTOR_ILU` - ILU factorization 182 . `MAT_FACTOR_ICC` - incomplete Cholesky factorization 183 . `MAT_FACTOR_ILUDT` - ILU factorization with drop tolerance 184 - `MAT_FACTOR_QR` - QR factorization 185 186 Level: beginner 187 188 .seealso: [](ch_matrices), `MatSolverType`, `MatGetFactor()`, `MatGetFactorAvailable()`, `MatSolverTypeRegister()` 189 E*/ 190 typedef enum { 191 MAT_FACTOR_NONE, 192 MAT_FACTOR_LU, 193 MAT_FACTOR_CHOLESKY, 194 MAT_FACTOR_ILU, 195 MAT_FACTOR_ICC, 196 MAT_FACTOR_ILUDT, 197 MAT_FACTOR_QR, 198 MAT_FACTOR_NUM_TYPES 199 } MatFactorType; 200 PETSC_EXTERN const char *const MatFactorTypes[]; 201 202 PETSC_EXTERN PetscErrorCode MatGetFactor(Mat, MatSolverType, MatFactorType, Mat *); 203 PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat, MatSolverType, MatFactorType, PetscBool *); 204 PETSC_EXTERN PetscErrorCode MatFactorGetCanUseOrdering(Mat, PetscBool *); 205 PETSC_DEPRECATED_FUNCTION(3, 15, 0, "MatFactorGetCanUseOrdering()", ) static inline PetscErrorCode MatFactorGetUseOrdering(Mat A, PetscBool *b) 206 { 207 return MatFactorGetCanUseOrdering(A, b); 208 } 209 PETSC_EXTERN PetscErrorCode MatFactorGetSolverType(Mat, MatSolverType *); 210 PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat, MatFactorType *); 211 PETSC_EXTERN PetscErrorCode MatSetFactorType(Mat, MatFactorType); 212 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*MatSolverFunction)(Mat, MatFactorType, Mat *); 213 PETSC_EXTERN PetscErrorCode MatSolverTypeRegister(MatSolverType, MatType, MatFactorType, MatSolverFunction); 214 PETSC_EXTERN PetscErrorCode MatSolverTypeGet(MatSolverType, MatType, MatFactorType, PetscBool *, PetscBool *, MatSolverFunction *); 215 typedef MatSolverType MatSolverPackage PETSC_DEPRECATED_TYPEDEF(3, 9, 0, "MatSolverType", ); 216 PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeRegister()", ) static inline PetscErrorCode MatSolverPackageRegister(MatSolverType stype, MatType mtype, MatFactorType ftype, MatSolverFunction f) 217 { 218 return MatSolverTypeRegister(stype, mtype, ftype, f); 219 } 220 PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeGet()", ) static inline PetscErrorCode MatSolverPackageGet(MatSolverType stype, MatType mtype, MatFactorType ftype, PetscBool *foundmtype, PetscBool *foundstype, MatSolverFunction *f) 221 { 222 return MatSolverTypeGet(stype, mtype, ftype, foundmtype, foundstype, f); 223 } 224 225 /*E 226 MatProductType - indicates what type of matrix product to compute 227 228 Values: 229 + `MATPRODUCT_AB` - product of two matrices 230 . `MATPRODUCT_AtB` - product of the transpose of a given matrix with a matrix 231 . `MATPRODUCT_ABt` - product of a matrix with the transpose of another given matrix 232 . `MATPRODUCT_PtAP` - the triple product of the transpose of a matrix with another matrix and itself 233 . `MATPRODUCT_RARt` - the triple product of a matrix, another matrix and the transpose of the first matrix 234 - `MATPRODUCT_ABC` - the product of three matrices 235 236 Level: beginner 237 238 .seealso: [](sec_matmatproduct), [](ch_matrices), `MatProductSetType()` 239 E*/ 240 typedef enum { 241 MATPRODUCT_UNSPECIFIED = 0, 242 MATPRODUCT_AB, 243 MATPRODUCT_AtB, 244 MATPRODUCT_ABt, 245 MATPRODUCT_PtAP, 246 MATPRODUCT_RARt, 247 MATPRODUCT_ABC 248 } MatProductType; 249 PETSC_EXTERN const char *const MatProductTypes[]; 250 251 /*J 252 MatProductAlgorithm - String with the name of an algorithm for a PETSc matrix product implementation 253 254 Level: beginner 255 256 .seealso: [](sec_matmatproduct), [](ch_matrices), `MatSetType()`, `Mat`, `MatProductSetAlgorithm()`, `MatProductType` 257 J*/ 258 typedef const char *MatProductAlgorithm; 259 #define MATPRODUCTALGORITHMDEFAULT "default" 260 #define MATPRODUCTALGORITHMSORTED "sorted" 261 #define MATPRODUCTALGORITHMSCALABLE "scalable" 262 #define MATPRODUCTALGORITHMSCALABLEFAST "scalable_fast" 263 #define MATPRODUCTALGORITHMHEAP "heap" 264 #define MATPRODUCTALGORITHMBHEAP "btheap" 265 #define MATPRODUCTALGORITHMLLCONDENSED "llcondensed" 266 #define MATPRODUCTALGORITHMROWMERGE "rowmerge" 267 #define MATPRODUCTALGORITHMOUTERPRODUCT "outerproduct" 268 #define MATPRODUCTALGORITHMATB "at*b" 269 #define MATPRODUCTALGORITHMRAP "rap" 270 #define MATPRODUCTALGORITHMNONSCALABLE "nonscalable" 271 #define MATPRODUCTALGORITHMSEQMPI "seqmpi" 272 #define MATPRODUCTALGORITHMBACKEND "backend" 273 #define MATPRODUCTALGORITHMOVERLAPPING "overlapping" 274 #define MATPRODUCTALGORITHMMERGED "merged" 275 #define MATPRODUCTALGORITHMALLATONCE "allatonce" 276 #define MATPRODUCTALGORITHMALLATONCEMERGED "allatonce_merged" 277 #define MATPRODUCTALGORITHMALLGATHERV "allgatherv" 278 #define MATPRODUCTALGORITHMCYCLIC "cyclic" 279 #if defined(PETSC_HAVE_HYPRE) 280 #define MATPRODUCTALGORITHMHYPRE "hypre" 281 #endif 282 283 PETSC_EXTERN PetscErrorCode MatProductCreate(Mat, Mat, Mat, Mat *); 284 PETSC_EXTERN PetscErrorCode MatProductCreateWithMat(Mat, Mat, Mat, Mat); 285 PETSC_EXTERN PetscErrorCode MatProductSetType(Mat, MatProductType); 286 PETSC_EXTERN PetscErrorCode MatProductSetAlgorithm(Mat, MatProductAlgorithm); 287 PETSC_EXTERN PetscErrorCode MatProductGetAlgorithm(Mat, MatProductAlgorithm *); 288 PETSC_EXTERN PetscErrorCode MatProductSetFill(Mat, PetscReal); 289 PETSC_EXTERN PetscErrorCode MatProductSetFromOptions(Mat); 290 PETSC_EXTERN PetscErrorCode MatProductSymbolic(Mat); 291 PETSC_EXTERN PetscErrorCode MatProductNumeric(Mat); 292 PETSC_EXTERN PetscErrorCode MatProductReplaceMats(Mat, Mat, Mat, Mat); 293 PETSC_EXTERN PetscErrorCode MatProductClear(Mat); 294 PETSC_EXTERN PetscErrorCode MatProductView(Mat, PetscViewer); 295 PETSC_EXTERN PetscErrorCode MatProductGetType(Mat, MatProductType *); 296 PETSC_EXTERN PetscErrorCode MatProductGetMats(Mat, Mat *, Mat *, Mat *); 297 298 /* Logging support */ 299 #define MAT_FILE_CLASSID 1211216 /* used to indicate matrices in binary files */ 300 PETSC_EXTERN PetscClassId MAT_CLASSID; 301 PETSC_EXTERN PetscClassId MAT_COLORING_CLASSID; 302 PETSC_EXTERN PetscClassId MAT_FDCOLORING_CLASSID; 303 PETSC_EXTERN PetscClassId MAT_TRANSPOSECOLORING_CLASSID; 304 PETSC_EXTERN PetscClassId MAT_PARTITIONING_CLASSID; 305 PETSC_EXTERN PetscClassId MAT_COARSEN_CLASSID; 306 PETSC_EXTERN PetscClassId MAT_NULLSPACE_CLASSID; 307 PETSC_EXTERN PetscClassId MATMFFD_CLASSID; 308 309 /*E 310 MatReuse - Indicates if matrices obtained from a previous call to `MatCreateSubMatrices()`, `MatCreateSubMatrix()`, `MatConvert()` or several other functions 311 are to be reused to store the new matrix values. 312 313 Values: 314 + `MAT_INITIAL_MATRIX` - create a new matrix 315 . `MAT_REUSE_MATRIX` - reuse the matrix created with a previous call that used `MAT_INITIAL_MATRIX` 316 . `MAT_INPLACE_MATRIX` - replace the first input matrix with the new matrix (not applicable to all functions) 317 - `MAT_IGNORE_MATRIX` - do not create a new matrix or reuse a give matrix, just ignore that matrix argument (not applicable to all functions) 318 319 Level: beginner 320 321 .seealso: [](ch_matrices), `Mat`, `MatCreateSubMatrices()`, `MatCreateSubMatrix()`, `MatDestroyMatrices()`, `MatConvert()` 322 E*/ 323 typedef enum { 324 MAT_INITIAL_MATRIX, 325 MAT_REUSE_MATRIX, 326 MAT_IGNORE_MATRIX, 327 MAT_INPLACE_MATRIX 328 } MatReuse; 329 330 /*E 331 MatCreateSubMatrixOption - Indicates if matrices obtained from a call to `MatCreateSubMatrices()` 332 include the matrix values. Currently it is only used by `MatGetSeqNonzeroStructure()`. 333 334 Values: 335 + `MAT_DO_NOT_GET_VALUES` - do not copy the matrix values 336 - `MAT_GET_VALUES` - copy the matrix values 337 338 Level: developer 339 340 Developer Note: 341 Why is not just a boolean used for this information? 342 343 .seealso: [](ch_matrices), `Mat`, `MatDuplicateOption`, `PetscCopyMode`, `MatGetSeqNonzeroStructure()` 344 E*/ 345 typedef enum { 346 MAT_DO_NOT_GET_VALUES, 347 MAT_GET_VALUES 348 } MatCreateSubMatrixOption; 349 350 PETSC_EXTERN PetscErrorCode MatInitializePackage(void); 351 PETSC_EXTERN PetscErrorCode MatFinalizePackage(void); 352 353 PETSC_EXTERN PetscErrorCode MatCreate(MPI_Comm, Mat *); 354 PETSC_EXTERN PetscErrorCode MatCreateFromOptions(MPI_Comm, const char *, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *); 355 PETSC_EXTERN PetscErrorCode MatSetSizes(Mat, PetscInt, PetscInt, PetscInt, PetscInt); 356 PETSC_EXTERN PetscErrorCode MatSetType(Mat, MatType); 357 PETSC_EXTERN PetscErrorCode MatGetVecType(Mat, VecType *); 358 PETSC_EXTERN PetscErrorCode MatSetVecType(Mat, VecType); 359 PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat); 360 PETSC_EXTERN PetscErrorCode MatViewFromOptions(Mat, PetscObject, const char[]); 361 PETSC_EXTERN PetscErrorCode MatRegister(const char[], PetscErrorCode (*)(Mat)); 362 PETSC_EXTERN PetscErrorCode MatRegisterRootName(const char[], const char[], const char[]); 363 PETSC_EXTERN PetscErrorCode MatSetOptionsPrefix(Mat, const char[]); 364 PETSC_EXTERN PetscErrorCode MatSetOptionsPrefixFactor(Mat, const char[]); 365 PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefixFactor(Mat, const char[]); 366 PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefix(Mat, const char[]); 367 PETSC_EXTERN PetscErrorCode MatGetOptionsPrefix(Mat, const char *[]); 368 PETSC_EXTERN PetscErrorCode MatSetErrorIfFailure(Mat, PetscBool); 369 370 PETSC_EXTERN PetscFunctionList MatList; 371 PETSC_EXTERN PetscFunctionList MatColoringList; 372 PETSC_EXTERN PetscFunctionList MatPartitioningList; 373 374 /*E 375 MatStructure - Indicates if two matrices have the same nonzero structure 376 377 Values: 378 + `SAME_NONZERO_PATTERN` - the two matrices have identical nonzero patterns 379 . `DIFFERENT_NONZERO_PATTERN` - the two matrices may have different nonzero patterns 380 . `SUBSET_NONZERO_PATTERN` - the nonzero pattern of the second matrix is a subset of the nonzero pattern of the first matrix 381 - `UNKNOWN_NONZERO_PATTERN` - there is no known relationship between the nonzero patterns. In this case the implementations 382 may try to detect a relationship to optimize the operation 383 384 Level: beginner 385 386 Note: 387 Certain matrix operations (such as `MatAXPY()`) can run much faster if the sparsity pattern of the matrices are the same. But actually determining if 388 the patterns are the same may be costly. This provides a way for users who know something about the sparsity patterns to provide this information 389 to certain PETSc routines. 390 391 .seealso: [](ch_matrices), `Mat`, `MatCopy()`, `MatAXPY()`, `MatAYPX()` 392 E*/ 393 typedef enum { 394 DIFFERENT_NONZERO_PATTERN, 395 SUBSET_NONZERO_PATTERN, 396 SAME_NONZERO_PATTERN, 397 UNKNOWN_NONZERO_PATTERN 398 } MatStructure; 399 PETSC_EXTERN const char *const MatStructures[]; 400 401 #if defined PETSC_HAVE_MKL_SPARSE 402 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 403 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 404 PETSC_EXTERN PetscErrorCode MatCreateBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 405 PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 406 #endif 407 408 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJPERM(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 409 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJPERM(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 410 411 PETSC_EXTERN PetscErrorCode MatCreateSeqSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 412 PETSC_EXTERN PetscErrorCode MatCreateSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 413 PETSC_EXTERN PetscErrorCode MatSeqSELLSetPreallocation(Mat, PetscInt, const PetscInt[]); 414 PETSC_EXTERN PetscErrorCode MatMPISELLSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 415 PETSC_EXTERN PetscErrorCode MatSeqSELLGetFillRatio(Mat, PetscReal *); 416 PETSC_EXTERN PetscErrorCode MatSeqSELLGetMaxSliceWidth(Mat, PetscInt *); 417 PETSC_EXTERN PetscErrorCode MatSeqSELLGetAvgSliceWidth(Mat, PetscReal *); 418 PETSC_EXTERN PetscErrorCode MatSeqSELLSetSliceHeight(Mat, PetscInt); 419 PETSC_EXTERN PetscErrorCode MatSeqSELLGetVarSliceSize(Mat, PetscReal *); 420 421 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 422 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 423 PETSC_EXTERN PetscErrorCode MatMPISELLGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *); 424 PETSC_EXTERN PetscErrorCode MatMPISELLGetSeqSELL(Mat, Mat *, Mat *, const PetscInt *[]); 425 426 PETSC_EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *); 427 PETSC_EXTERN PetscErrorCode MatCreateDense(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *); 428 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 429 PETSC_EXTERN PetscErrorCode MatCreateAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 430 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *); 431 PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArrays(Mat, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]); 432 PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArray(Mat, const PetscScalar[]); 433 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSplitArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], PetscInt[], PetscInt[], PetscScalar[], Mat *); 434 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSeqAIJ(MPI_Comm, Mat, Mat, const PetscInt[], Mat *); 435 436 PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 437 PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 438 PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *); 439 440 PETSC_EXTERN PetscErrorCode MatSetPreallocationCOO(Mat, PetscCount, PetscInt[], PetscInt[]); 441 PETSC_EXTERN PetscErrorCode MatSetPreallocationCOOLocal(Mat, PetscCount, PetscInt[], PetscInt[]); 442 PETSC_EXTERN PetscErrorCode MatSetValuesCOO(Mat, const PetscScalar[], InsertMode); 443 444 PETSC_EXTERN PetscErrorCode MatCreateMPIAdj(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscInt[], Mat *); 445 PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 446 447 PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 448 PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *); 449 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]); 450 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]); 451 PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscInt[], const PetscInt[]); 452 453 PETSC_EXTERN PetscErrorCode MatCreateShell(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, void *, Mat *); 454 PETSC_EXTERN PetscErrorCode MatCreateCentering(MPI_Comm, PetscInt, PetscInt, Mat *); 455 PETSC_EXTERN PetscErrorCode MatCreateNormal(Mat, Mat *); 456 PETSC_EXTERN PetscErrorCode MatCreateNormalHermitian(Mat, Mat *); 457 PETSC_EXTERN PetscErrorCode MatCreateLRC(Mat, Mat, Vec, Mat, Mat *); 458 PETSC_EXTERN PetscErrorCode MatLRCGetMats(Mat, Mat *, Mat *, Vec *, Mat *); 459 PETSC_EXTERN PetscErrorCode MatLRCSetMats(Mat, Mat, Mat, Vec, Mat); 460 PETSC_EXTERN PetscErrorCode MatCreateIS(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, ISLocalToGlobalMapping, ISLocalToGlobalMapping, Mat *); 461 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 462 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 463 464 PETSC_EXTERN PetscErrorCode MatCreateScatter(MPI_Comm, VecScatter, Mat *); 465 PETSC_EXTERN PetscErrorCode MatScatterSetVecScatter(Mat, VecScatter); 466 PETSC_EXTERN PetscErrorCode MatScatterGetVecScatter(Mat, VecScatter *); 467 PETSC_EXTERN PetscErrorCode MatCreateBlockMat(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt *, Mat *); 468 PETSC_EXTERN PetscErrorCode MatCompositeAddMat(Mat, Mat); 469 PETSC_EXTERN PetscErrorCode MatCompositeMerge(Mat); 470 typedef enum { 471 MAT_COMPOSITE_MERGE_RIGHT, 472 MAT_COMPOSITE_MERGE_LEFT 473 } MatCompositeMergeType; 474 PETSC_EXTERN PetscErrorCode MatCompositeSetMergeType(Mat, MatCompositeMergeType); 475 PETSC_EXTERN PetscErrorCode MatCreateComposite(MPI_Comm, PetscInt, const Mat *, Mat *); 476 typedef enum { 477 MAT_COMPOSITE_ADDITIVE, 478 MAT_COMPOSITE_MULTIPLICATIVE 479 } MatCompositeType; 480 PETSC_EXTERN PetscErrorCode MatCompositeSetType(Mat, MatCompositeType); 481 PETSC_EXTERN PetscErrorCode MatCompositeGetType(Mat, MatCompositeType *); 482 PETSC_EXTERN PetscErrorCode MatCompositeSetMatStructure(Mat, MatStructure); 483 PETSC_EXTERN PetscErrorCode MatCompositeGetMatStructure(Mat, MatStructure *); 484 PETSC_EXTERN PetscErrorCode MatCompositeGetNumberMat(Mat, PetscInt *); 485 PETSC_EXTERN PetscErrorCode MatCompositeGetMat(Mat, PetscInt, Mat *); 486 PETSC_EXTERN PetscErrorCode MatCompositeSetScalings(Mat, const PetscScalar *); 487 488 PETSC_EXTERN PetscErrorCode MatCreateFFT(MPI_Comm, PetscInt, const PetscInt[], MatType, Mat *); 489 PETSC_EXTERN PetscErrorCode MatCreateSeqCUFFT(MPI_Comm, PetscInt, const PetscInt[], Mat *); 490 491 PETSC_EXTERN PetscErrorCode MatCreateTranspose(Mat, Mat *); 492 PETSC_EXTERN PetscErrorCode MatTransposeGetMat(Mat, Mat *); 493 PETSC_EXTERN PetscErrorCode MatCreateHermitianTranspose(Mat, Mat *); 494 PETSC_EXTERN PetscErrorCode MatHermitianTransposeGetMat(Mat, Mat *); 495 PETSC_EXTERN PetscErrorCode MatNormalGetMat(Mat, Mat *); 496 PETSC_EXTERN PetscErrorCode MatNormalHermitianGetMat(Mat, Mat *); 497 PETSC_EXTERN PetscErrorCode MatCreateSubMatrixVirtual(Mat, IS, IS, Mat *); 498 PETSC_EXTERN PetscErrorCode MatSubMatrixVirtualUpdate(Mat, Mat, IS, IS); 499 PETSC_EXTERN PetscErrorCode MatCreateLocalRef(Mat, IS, IS, Mat *); 500 PETSC_EXTERN PetscErrorCode MatCreateConstantDiagonal(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar, Mat *); 501 PETSC_EXTERN PetscErrorCode MatCreateDiagonal(Vec, Mat *); 502 PETSC_EXTERN PetscErrorCode MatDiagonalGetDiagonal(Mat, Vec *); 503 PETSC_EXTERN PetscErrorCode MatDiagonalRestoreDiagonal(Mat, Vec *); 504 PETSC_EXTERN PetscErrorCode MatDiagonalGetInverseDiagonal(Mat, Vec *); 505 PETSC_EXTERN PetscErrorCode MatDiagonalRestoreInverseDiagonal(Mat, Vec *); 506 507 #if defined(PETSC_HAVE_HYPRE) 508 PETSC_EXTERN PetscErrorCode MatHYPRESetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 509 #endif 510 511 PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat, const char[]); 512 PETSC_EXTERN PetscErrorCode MatPythonGetType(Mat, const char *[]); 513 514 PETSC_EXTERN PetscErrorCode MatResetPreallocation(Mat); 515 PETSC_EXTERN PetscErrorCode MatSetUp(Mat); 516 PETSC_EXTERN PetscErrorCode MatDestroy(Mat *); 517 PETSC_EXTERN PetscErrorCode MatGetNonzeroState(Mat, PetscObjectState *); 518 519 PETSC_EXTERN PetscErrorCode MatConjugate(Mat); 520 PETSC_EXTERN PetscErrorCode MatRealPart(Mat); 521 PETSC_EXTERN PetscErrorCode MatImaginaryPart(Mat); 522 PETSC_EXTERN PetscErrorCode MatGetDiagonalBlock(Mat, Mat *); 523 PETSC_EXTERN PetscErrorCode MatGetTrace(Mat, PetscScalar *); 524 PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonal(Mat, const PetscScalar **); 525 PETSC_EXTERN PetscErrorCode MatInvertVariableBlockDiagonal(Mat, PetscInt, const PetscInt *, PetscScalar *); 526 PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonalMat(Mat, Mat); 527 PETSC_EXTERN PetscErrorCode MatInvertVariableBlockEnvelope(Mat, MatReuse, Mat *); 528 PETSC_EXTERN PetscErrorCode MatComputeVariableBlockEnvelope(Mat); 529 530 PETSC_EXTERN PetscErrorCode MatSetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 531 PETSC_EXTERN PetscErrorCode MatSetValuesIS(Mat, IS, IS, const PetscScalar[], InsertMode); 532 PETSC_EXTERN PetscErrorCode MatSetValuesBlocked(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 533 PETSC_EXTERN PetscErrorCode MatSetValuesRow(Mat, PetscInt, const PetscScalar[]); 534 PETSC_EXTERN PetscErrorCode MatSetValuesRowLocal(Mat, PetscInt, const PetscScalar[]); 535 PETSC_EXTERN PetscErrorCode MatSetValuesBatch(Mat, PetscInt, PetscInt, PetscInt[], const PetscScalar[]); 536 PETSC_EXTERN PetscErrorCode MatSetRandom(Mat, PetscRandom); 537 538 /*S 539 MatStencil - Data structure (C struct) for storing information about rows and 540 columns of a matrix as indexed on an associated grid. These are arguments to `MatSetStencil()` and `MatSetBlockStencil()` 541 542 Level: beginner 543 544 Notes: 545 The i,j, and k represent the logical coordinates over the entire grid (for 2 and 1 dimensional problems the k and j entries are ignored). 546 The c represents the the degrees of freedom at each grid point (the dof argument to `DMDASetDOF()`). If dof is 1 then this entry is ignored. 547 548 For stencil access to vectors see `DMDAVecGetArray()`, `DMDAVecGetArrayF90()`. 549 550 For staggered grids, see `DMStagStencil` 551 552 Fortran Note: 553 See `MatSetValuesStencil()` for details. 554 555 .seealso: [](ch_matrices), `Mat`, `MatSetValuesStencil()`, `MatSetStencil()`, `MatSetValuesBlockedStencil()`, `DMDAVecGetArray()`, `DMDAVecGetArrayF90()`, 556 `DMStagStencil` 557 S*/ 558 typedef struct { 559 PetscInt k, j, i, c; 560 } MatStencil; 561 562 PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode); 563 PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode); 564 PETSC_EXTERN PetscErrorCode MatSetStencil(Mat, PetscInt, const PetscInt[], const PetscInt[], PetscInt); 565 566 /*E 567 MatAssemblyType - Indicates if the process of setting values into the matrix is complete, and the matrix is ready for use 568 569 Values: 570 + `MAT_FLUSH_ASSEMBLY` - you will continue to put values into the matrix 571 - `MAT_FINAL_ASSEMBLY` - you wish to use the matrix with the values currently inserted 572 573 Level: beginner 574 575 .seealso: [](ch_matrices), `Mat`, `MatSetValues`, `MatAssemblyBegin()`, `MatAssemblyEnd()` 576 E*/ 577 typedef enum { 578 MAT_FLUSH_ASSEMBLY = 1, 579 MAT_FINAL_ASSEMBLY = 0 580 } MatAssemblyType; 581 PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat, MatAssemblyType); 582 PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat, MatAssemblyType); 583 PETSC_EXTERN PetscErrorCode MatAssembled(Mat, PetscBool *); 584 585 /*E 586 MatOption - Options that may be set for a matrix that indicate properties of the matrix or affect its behavior or storage 587 588 Level: beginner 589 590 Note: 591 See `MatSetOption()` for the use of the options 592 593 Developer Note: 594 Entries that are negative need not be called collectively by all processes. 595 596 .seealso: [](ch_matrices), `Mat`, `MatSetOption()` 597 E*/ 598 typedef enum { 599 MAT_OPTION_MIN = -3, 600 MAT_UNUSED_NONZERO_LOCATION_ERR = -2, 601 MAT_ROW_ORIENTED = -1, 602 MAT_SYMMETRIC = 1, 603 MAT_STRUCTURALLY_SYMMETRIC = 2, 604 MAT_FORCE_DIAGONAL_ENTRIES = 3, 605 MAT_IGNORE_OFF_PROC_ENTRIES = 4, 606 MAT_USE_HASH_TABLE = 5, 607 MAT_KEEP_NONZERO_PATTERN = 6, 608 MAT_IGNORE_ZERO_ENTRIES = 7, 609 MAT_USE_INODES = 8, 610 MAT_HERMITIAN = 9, 611 MAT_SYMMETRY_ETERNAL = 10, 612 MAT_NEW_NONZERO_LOCATION_ERR = 11, 613 MAT_IGNORE_LOWER_TRIANGULAR = 12, 614 MAT_ERROR_LOWER_TRIANGULAR = 13, 615 MAT_GETROW_UPPERTRIANGULAR = 14, 616 MAT_SPD = 15, 617 MAT_NO_OFF_PROC_ZERO_ROWS = 16, 618 MAT_NO_OFF_PROC_ENTRIES = 17, 619 MAT_NEW_NONZERO_LOCATIONS = 18, 620 MAT_NEW_NONZERO_ALLOCATION_ERR = 19, 621 MAT_SUBSET_OFF_PROC_ENTRIES = 20, 622 MAT_SUBMAT_SINGLEIS = 21, 623 MAT_STRUCTURE_ONLY = 22, 624 MAT_SORTED_FULL = 23, 625 MAT_FORM_EXPLICIT_TRANSPOSE = 24, 626 MAT_STRUCTURAL_SYMMETRY_ETERNAL = 25, 627 MAT_SPD_ETERNAL = 26, 628 MAT_OPTION_MAX = 27 629 } MatOption; 630 631 PETSC_EXTERN const char *const *MatOptions; 632 PETSC_EXTERN PetscErrorCode MatSetOption(Mat, MatOption, PetscBool); 633 PETSC_EXTERN PetscErrorCode MatGetOption(Mat, MatOption, PetscBool *); 634 PETSC_EXTERN PetscErrorCode MatPropagateSymmetryOptions(Mat, Mat); 635 PETSC_EXTERN PetscErrorCode MatGetType(Mat, MatType *); 636 637 PETSC_EXTERN PetscErrorCode MatGetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]); 638 PETSC_EXTERN PetscErrorCode MatGetRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]); 639 PETSC_EXTERN PetscErrorCode MatRestoreRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]); 640 PETSC_EXTERN PetscErrorCode MatGetRowUpperTriangular(Mat); 641 PETSC_EXTERN PetscErrorCode MatRestoreRowUpperTriangular(Mat); 642 PETSC_EXTERN PetscErrorCode MatGetColumnVector(Mat, Vec, PetscInt); 643 PETSC_EXTERN PetscErrorCode MatSeqAIJGetArray(Mat, PetscScalar *[]); 644 PETSC_EXTERN PetscErrorCode MatSeqAIJGetArrayRead(Mat, const PetscScalar *[]); 645 PETSC_EXTERN PetscErrorCode MatSeqAIJGetArrayWrite(Mat, PetscScalar *[]); 646 PETSC_EXTERN PetscErrorCode MatSeqAIJRestoreArray(Mat, PetscScalar *[]); 647 PETSC_EXTERN PetscErrorCode MatSeqAIJRestoreArrayRead(Mat, const PetscScalar *[]); 648 PETSC_EXTERN PetscErrorCode MatSeqAIJRestoreArrayWrite(Mat, PetscScalar *[]); 649 PETSC_EXTERN PetscErrorCode MatSeqAIJGetMaxRowNonzeros(Mat, PetscInt *); 650 PETSC_EXTERN PetscErrorCode MatSeqAIJSetValuesLocalFast(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 651 PETSC_EXTERN PetscErrorCode MatSeqAIJSetType(Mat, MatType); 652 PETSC_EXTERN PetscErrorCode MatSeqAIJKron(Mat, Mat, MatReuse, Mat *); 653 PETSC_EXTERN PetscErrorCode MatSeqAIJRegister(const char[], PetscErrorCode (*)(Mat, MatType, MatReuse, Mat *)); 654 PETSC_EXTERN PetscFunctionList MatSeqAIJList; 655 PETSC_EXTERN PetscErrorCode MatSeqBAIJGetArray(Mat, PetscScalar *[]); 656 PETSC_EXTERN PetscErrorCode MatSeqBAIJRestoreArray(Mat, PetscScalar *[]); 657 PETSC_EXTERN PetscErrorCode MatSeqSBAIJGetArray(Mat, PetscScalar *[]); 658 PETSC_EXTERN PetscErrorCode MatSeqSBAIJRestoreArray(Mat, PetscScalar *[]); 659 PETSC_EXTERN PetscErrorCode MatDenseGetArray(Mat, PetscScalar *[]); 660 PETSC_EXTERN PetscErrorCode MatDenseRestoreArray(Mat, PetscScalar *[]); 661 PETSC_EXTERN PetscErrorCode MatDensePlaceArray(Mat, const PetscScalar[]); 662 PETSC_EXTERN PetscErrorCode MatDenseReplaceArray(Mat, const PetscScalar[]); 663 PETSC_EXTERN PetscErrorCode MatDenseResetArray(Mat); 664 PETSC_EXTERN PetscErrorCode MatDenseGetArrayRead(Mat, const PetscScalar *[]); 665 PETSC_EXTERN PetscErrorCode MatDenseRestoreArrayRead(Mat, const PetscScalar *[]); 666 PETSC_EXTERN PetscErrorCode MatDenseGetArrayWrite(Mat, PetscScalar *[]); 667 PETSC_EXTERN PetscErrorCode MatDenseRestoreArrayWrite(Mat, PetscScalar *[]); 668 PETSC_EXTERN PetscErrorCode MatDenseGetArrayAndMemType(Mat, PetscScalar *[], PetscMemType *); 669 PETSC_EXTERN PetscErrorCode MatDenseRestoreArrayAndMemType(Mat, PetscScalar *[]); 670 PETSC_EXTERN PetscErrorCode MatDenseGetArrayReadAndMemType(Mat, const PetscScalar *[], PetscMemType *); 671 PETSC_EXTERN PetscErrorCode MatDenseRestoreArrayReadAndMemType(Mat, const PetscScalar *[]); 672 PETSC_EXTERN PetscErrorCode MatDenseGetArrayWriteAndMemType(Mat, PetscScalar *[], PetscMemType *); 673 PETSC_EXTERN PetscErrorCode MatDenseRestoreArrayWriteAndMemType(Mat, PetscScalar *[]); 674 PETSC_EXTERN PetscErrorCode MatGetBlockSize(Mat, PetscInt *); 675 PETSC_EXTERN PetscErrorCode MatSetBlockSize(Mat, PetscInt); 676 PETSC_EXTERN PetscErrorCode MatGetBlockSizes(Mat, PetscInt *, PetscInt *); 677 PETSC_EXTERN PetscErrorCode MatSetBlockSizes(Mat, PetscInt, PetscInt); 678 PETSC_EXTERN PetscErrorCode MatSetBlockSizesFromMats(Mat, Mat, Mat); 679 PETSC_EXTERN PetscErrorCode MatSetVariableBlockSizes(Mat, PetscInt, PetscInt *); 680 PETSC_EXTERN PetscErrorCode MatGetVariableBlockSizes(Mat, PetscInt *, const PetscInt **); 681 682 PETSC_EXTERN PetscErrorCode MatDenseGetColumn(Mat, PetscInt, PetscScalar *[]); 683 PETSC_EXTERN PetscErrorCode MatDenseRestoreColumn(Mat, PetscScalar *[]); 684 PETSC_EXTERN PetscErrorCode MatDenseGetColumnVec(Mat, PetscInt, Vec *); 685 PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVec(Mat, PetscInt, Vec *); 686 PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecRead(Mat, PetscInt, Vec *); 687 PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecRead(Mat, PetscInt, Vec *); 688 PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecWrite(Mat, PetscInt, Vec *); 689 PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecWrite(Mat, PetscInt, Vec *); 690 PETSC_EXTERN PetscErrorCode MatDenseGetSubMatrix(Mat, PetscInt, PetscInt, PetscInt, PetscInt, Mat *); 691 PETSC_EXTERN PetscErrorCode MatDenseRestoreSubMatrix(Mat, Mat *); 692 693 PETSC_EXTERN PetscErrorCode MatMult(Mat, Vec, Vec); 694 PETSC_EXTERN PetscErrorCode MatMultDiagonalBlock(Mat, Vec, Vec); 695 PETSC_EXTERN PetscErrorCode MatMultAdd(Mat, Vec, Vec, Vec); 696 PETSC_EXTERN PetscErrorCode MatMultTranspose(Mat, Vec, Vec); 697 PETSC_EXTERN PetscErrorCode MatMultHermitianTranspose(Mat, Vec, Vec); 698 PETSC_EXTERN PetscErrorCode MatIsTranspose(Mat, Mat, PetscReal, PetscBool *); 699 PETSC_EXTERN PetscErrorCode MatIsHermitianTranspose(Mat, Mat, PetscReal, PetscBool *); 700 PETSC_EXTERN PetscErrorCode MatMultTransposeAdd(Mat, Vec, Vec, Vec); 701 PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAdd(Mat, Vec, Vec, Vec); 702 PETSC_EXTERN PetscErrorCode MatMatSolve(Mat, Mat, Mat); 703 PETSC_EXTERN PetscErrorCode MatMatSolveTranspose(Mat, Mat, Mat); 704 PETSC_EXTERN PetscErrorCode MatMatTransposeSolve(Mat, Mat, Mat); 705 PETSC_EXTERN PetscErrorCode MatResidual(Mat, Vec, Vec, Vec); 706 707 /*E 708 MatDuplicateOption - Indicates if a duplicated sparse matrix should have 709 its numerical values copied over or just its nonzero structure. 710 711 Values: 712 + `MAT_DO_NOT_COPY_VALUES` - Create a matrix using the same nonzero pattern as the original matrix, 713 with zeros for the numerical values 714 . `MAT_COPY_VALUES` - Create a matrix with the same nonzero pattern as the original matrix 715 and with the same numerical values. 716 - `MAT_SHARE_NONZERO_PATTERN` - Create a matrix that shares the nonzero structure with the previous matrix 717 and does not copy it, using zeros for the numerical values. The parent and 718 child matrices will share their index (i and j) arrays, and you cannot 719 insert new nonzero entries into either matrix 720 721 Level: beginner 722 723 Note: 724 Many matrix types (including `MATSEQAIJ`) do not support the `MAT_SHARE_NONZERO_PATTERN` optimization; in 725 this case the behavior is as if `MAT_DO_NOT_COPY_VALUES` has been specified. 726 727 .seealso: [](ch_matrices), `Mat`, `MatDuplicate()` 728 E*/ 729 typedef enum { 730 MAT_DO_NOT_COPY_VALUES, 731 MAT_COPY_VALUES, 732 MAT_SHARE_NONZERO_PATTERN 733 } MatDuplicateOption; 734 735 PETSC_EXTERN PetscErrorCode MatConvert(Mat, MatType, MatReuse, Mat *); 736 PETSC_EXTERN PetscErrorCode MatDuplicate(Mat, MatDuplicateOption, Mat *); 737 738 PETSC_EXTERN PetscErrorCode MatCopy(Mat, Mat, MatStructure); 739 PETSC_EXTERN PetscErrorCode MatView(Mat, PetscViewer); 740 PETSC_EXTERN PetscErrorCode MatIsSymmetric(Mat, PetscReal, PetscBool *); 741 PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetric(Mat, PetscBool *); 742 PETSC_EXTERN PetscErrorCode MatIsHermitian(Mat, PetscReal, PetscBool *); 743 PETSC_EXTERN PetscErrorCode MatIsSymmetricKnown(Mat, PetscBool *, PetscBool *); 744 PETSC_EXTERN PetscErrorCode MatIsHermitianKnown(Mat, PetscBool *, PetscBool *); 745 PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetricKnown(Mat, PetscBool *, PetscBool *); 746 PETSC_EXTERN PetscErrorCode MatIsSPDKnown(Mat, PetscBool *, PetscBool *); 747 PETSC_EXTERN PetscErrorCode MatMissingDiagonal(Mat, PetscBool *, PetscInt *); 748 PETSC_EXTERN PetscErrorCode MatLoad(Mat, PetscViewer); 749 750 PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *); 751 PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *); 752 PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *); 753 PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *); 754 755 /*S 756 MatInfo - Context of matrix information, used with `MatGetInfo()` 757 758 Level: intermediate 759 760 Fortran Note: 761 Information is stored as a double-precision array of dimension `MAT_INFO_SIZE` 762 763 .seealso: [](ch_matrices), `Mat`, `MatGetInfo()`, `MatInfoType` 764 S*/ 765 typedef struct { 766 PetscLogDouble block_size; /* block size */ 767 PetscLogDouble nz_allocated, nz_used, nz_unneeded; /* number of nonzeros */ 768 PetscLogDouble memory; /* memory allocated */ 769 PetscLogDouble assemblies; /* number of matrix assemblies called */ 770 PetscLogDouble mallocs; /* number of mallocs during MatSetValues() */ 771 PetscLogDouble fill_ratio_given, fill_ratio_needed; /* fill ratio for LU/ILU */ 772 PetscLogDouble factor_mallocs; /* number of mallocs during factorization */ 773 } MatInfo; 774 775 /*E 776 MatInfoType - Indicates if you want information about the local part of the matrix, 777 the entire parallel matrix or the maximum over all the local parts. 778 779 Values: 780 + `MAT_LOCAL` - values for each MPI process part of the matrix 781 . `MAT_GLOBAL_MAX` - maximum of each value over all MPI processes 782 - `MAT_GLOBAL_SUM` - sum of each value over all MPI processes 783 784 Level: beginner 785 786 .seealso: [](ch_matrices), `MatGetInfo()`, `MatInfo` 787 E*/ 788 typedef enum { 789 MAT_LOCAL = 1, 790 MAT_GLOBAL_MAX = 2, 791 MAT_GLOBAL_SUM = 3 792 } MatInfoType; 793 PETSC_EXTERN PetscErrorCode MatGetInfo(Mat, MatInfoType, MatInfo *); 794 PETSC_EXTERN PetscErrorCode MatGetDiagonal(Mat, Vec); 795 PETSC_EXTERN PetscErrorCode MatGetRowMax(Mat, Vec, PetscInt[]); 796 PETSC_EXTERN PetscErrorCode MatGetRowMin(Mat, Vec, PetscInt[]); 797 PETSC_EXTERN PetscErrorCode MatGetRowMaxAbs(Mat, Vec, PetscInt[]); 798 PETSC_EXTERN PetscErrorCode MatGetRowMinAbs(Mat, Vec, PetscInt[]); 799 PETSC_EXTERN PetscErrorCode MatGetRowSum(Mat, Vec); 800 PETSC_EXTERN PetscErrorCode MatTranspose(Mat, MatReuse, Mat *); 801 PETSC_EXTERN PetscErrorCode MatTransposeSymbolic(Mat, Mat *); 802 PETSC_EXTERN PetscErrorCode MatTransposeSetPrecursor(Mat, Mat); 803 PETSC_EXTERN PetscErrorCode MatHermitianTranspose(Mat, MatReuse, Mat *); 804 PETSC_EXTERN PetscErrorCode MatPermute(Mat, IS, IS, Mat *); 805 PETSC_EXTERN PetscErrorCode MatDiagonalScale(Mat, Vec, Vec); 806 PETSC_EXTERN PetscErrorCode MatDiagonalSet(Mat, Vec, InsertMode); 807 808 PETSC_EXTERN PetscErrorCode MatEqual(Mat, Mat, PetscBool *); 809 PETSC_EXTERN PetscErrorCode MatMultEqual(Mat, Mat, PetscInt, PetscBool *); 810 PETSC_EXTERN PetscErrorCode MatMultAddEqual(Mat, Mat, PetscInt, PetscBool *); 811 PETSC_EXTERN PetscErrorCode MatMultTransposeEqual(Mat, Mat, PetscInt, PetscBool *); 812 PETSC_EXTERN PetscErrorCode MatMultTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *); 813 PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeEqual(Mat, Mat, PetscInt, PetscBool *); 814 PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *); 815 PETSC_EXTERN PetscErrorCode MatMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *); 816 PETSC_EXTERN PetscErrorCode MatTransposeMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *); 817 PETSC_EXTERN PetscErrorCode MatMatTransposeMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *); 818 PETSC_EXTERN PetscErrorCode MatPtAPMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *); 819 PETSC_EXTERN PetscErrorCode MatRARtMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *); 820 PETSC_EXTERN PetscErrorCode MatIsLinear(Mat, PetscInt, PetscBool *); 821 822 PETSC_EXTERN PetscErrorCode MatNorm(Mat, NormType, PetscReal *); 823 PETSC_EXTERN PetscErrorCode MatGetColumnNorms(Mat, NormType, PetscReal *); 824 PETSC_EXTERN PetscErrorCode MatGetColumnSums(Mat, PetscScalar *); 825 PETSC_EXTERN PetscErrorCode MatGetColumnSumsRealPart(Mat, PetscReal *); 826 PETSC_EXTERN PetscErrorCode MatGetColumnSumsImaginaryPart(Mat, PetscReal *); 827 PETSC_EXTERN PetscErrorCode MatGetColumnMeans(Mat, PetscScalar *); 828 PETSC_EXTERN PetscErrorCode MatGetColumnMeansRealPart(Mat, PetscReal *); 829 PETSC_EXTERN PetscErrorCode MatGetColumnMeansImaginaryPart(Mat, PetscReal *); 830 PETSC_EXTERN PetscErrorCode MatGetColumnReductions(Mat, PetscInt, PetscReal *); 831 PETSC_EXTERN PetscErrorCode MatZeroEntries(Mat); 832 PETSC_EXTERN PetscErrorCode MatSetInf(Mat); 833 PETSC_EXTERN PetscErrorCode MatZeroRows(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec); 834 PETSC_EXTERN PetscErrorCode MatZeroRowsIS(Mat, IS, PetscScalar, Vec, Vec); 835 PETSC_EXTERN PetscErrorCode MatZeroRowsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec); 836 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec); 837 PETSC_EXTERN PetscErrorCode MatZeroRowsColumns(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec); 838 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsIS(Mat, IS, PetscScalar, Vec, Vec); 839 840 PETSC_EXTERN PetscErrorCode MatGetSize(Mat, PetscInt *, PetscInt *); 841 PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat, PetscInt *, PetscInt *); 842 PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat, PetscInt *, PetscInt *); 843 PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat, const PetscInt **); 844 PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat, PetscInt *, PetscInt *); 845 PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat, const PetscInt **); 846 PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat, IS *, IS *); 847 848 PETSC_EXTERN PetscErrorCode MatCreateSubMatrices(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]); 849 PETSC_DEPRECATED_FUNCTION(3, 8, 0, "MatCreateSubMatrices()", ) static inline PetscErrorCode MatGetSubMatrices(Mat mat, PetscInt n, const IS irow[], const IS icol[], MatReuse scall, Mat *submat[]) 850 { 851 return MatCreateSubMatrices(mat, n, irow, icol, scall, submat); 852 } 853 PETSC_EXTERN PetscErrorCode MatCreateSubMatricesMPI(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]); 854 PETSC_DEPRECATED_FUNCTION(3, 8, 0, "MatCreateSubMatricesMPI()", ) static inline PetscErrorCode MatGetSubMatricesMPI(Mat mat, PetscInt n, const IS irow[], const IS icol[], MatReuse scall, Mat *submat[]) 855 { 856 return MatCreateSubMatricesMPI(mat, n, irow, icol, scall, submat); 857 } 858 PETSC_EXTERN PetscErrorCode MatDestroyMatrices(PetscInt, Mat *[]); 859 PETSC_EXTERN PetscErrorCode MatDestroySubMatrices(PetscInt, Mat *[]); 860 PETSC_EXTERN PetscErrorCode MatCreateSubMatrix(Mat, IS, IS, MatReuse, Mat *); 861 PETSC_DEPRECATED_FUNCTION(3, 8, 0, "MatCreateSubMatrix()", ) static inline PetscErrorCode MatGetSubMatrix(Mat mat, IS isrow, IS iscol, MatReuse cll, Mat *newmat) 862 { 863 return MatCreateSubMatrix(mat, isrow, iscol, cll, newmat); 864 } 865 PETSC_EXTERN PetscErrorCode MatGetLocalSubMatrix(Mat, IS, IS, Mat *); 866 PETSC_EXTERN PetscErrorCode MatRestoreLocalSubMatrix(Mat, IS, IS, Mat *); 867 PETSC_EXTERN PetscErrorCode MatGetSeqNonzeroStructure(Mat, Mat *); 868 PETSC_EXTERN PetscErrorCode MatDestroySeqNonzeroStructure(Mat *); 869 870 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJ(MPI_Comm, Mat, PetscInt, PetscInt, MatReuse, Mat *); 871 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJSymbolic(MPI_Comm, Mat, PetscInt, PetscInt, Mat *); 872 PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJNumeric(Mat, Mat); 873 PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMat(Mat, MatReuse, Mat *); 874 PETSC_EXTERN PetscErrorCode MatAIJGetLocalMat(Mat, Mat *); 875 PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *); 876 PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatMerge(Mat, MatReuse, IS *, Mat *); 877 PETSC_EXTERN PetscErrorCode MatMPIAIJGetNumberNonzeros(Mat, PetscCount *); 878 PETSC_EXTERN PetscErrorCode MatGetBrowsOfAcols(Mat, Mat, MatReuse, IS *, IS *, Mat *); 879 PETSC_EXTERN PetscErrorCode MatGetGhosts(Mat, PetscInt *, const PetscInt *[]); 880 881 PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat, PetscInt, IS[], PetscInt); 882 PETSC_EXTERN PetscErrorCode MatIncreaseOverlapSplit(Mat mat, PetscInt n, IS is[], PetscInt ov); 883 PETSC_EXTERN PetscErrorCode MatMPIAIJSetUseScalableIncreaseOverlap(Mat, PetscBool); 884 885 PETSC_EXTERN PetscErrorCode MatMatMult(Mat, Mat, MatReuse, PetscReal, Mat *); 886 887 PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat, Mat, Mat, MatReuse, PetscReal, Mat *); 888 PETSC_EXTERN PetscErrorCode MatGalerkin(Mat, Mat, Mat, MatReuse, PetscReal, Mat *); 889 890 PETSC_EXTERN PetscErrorCode MatPtAP(Mat, Mat, MatReuse, PetscReal, Mat *); 891 PETSC_EXTERN PetscErrorCode MatRARt(Mat, Mat, MatReuse, PetscReal, Mat *); 892 893 PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat, Mat, MatReuse, PetscReal, Mat *); 894 PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat, Mat, MatReuse, PetscReal, Mat *); 895 896 PETSC_EXTERN PetscErrorCode MatAXPY(Mat, PetscScalar, Mat, MatStructure); 897 PETSC_EXTERN PetscErrorCode MatAYPX(Mat, PetscScalar, Mat, MatStructure); 898 899 PETSC_EXTERN PetscErrorCode MatScale(Mat, PetscScalar); 900 PETSC_EXTERN PetscErrorCode MatShift(Mat, PetscScalar); 901 902 PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping, ISLocalToGlobalMapping); 903 PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *); 904 PETSC_EXTERN PetscErrorCode MatGetLayouts(Mat, PetscLayout *, PetscLayout *); 905 PETSC_EXTERN PetscErrorCode MatSetLayouts(Mat, PetscLayout, PetscLayout); 906 PETSC_EXTERN PetscErrorCode MatZeroRowsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec); 907 PETSC_EXTERN PetscErrorCode MatZeroRowsLocalIS(Mat, IS, PetscScalar, Vec, Vec); 908 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec); 909 PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocalIS(Mat, IS, PetscScalar, Vec, Vec); 910 PETSC_EXTERN PetscErrorCode MatGetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]); 911 PETSC_EXTERN PetscErrorCode MatSetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 912 PETSC_EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 913 914 PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat, PetscInt, PetscInt); 915 PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat, PetscInt *, PetscInt *, PetscInt *, PetscInt *); 916 917 PETSC_EXTERN PetscErrorCode MatInterpolate(Mat, Vec, Vec); 918 PETSC_EXTERN PetscErrorCode MatInterpolateAdd(Mat, Vec, Vec, Vec); 919 PETSC_EXTERN PetscErrorCode MatRestrict(Mat, Vec, Vec); 920 PETSC_EXTERN PetscErrorCode MatMatInterpolate(Mat, Mat, Mat *); 921 PETSC_EXTERN PetscErrorCode MatMatInterpolateAdd(Mat, Mat, Mat, Mat *); 922 PETSC_EXTERN PetscErrorCode MatMatRestrict(Mat, Mat, Mat *); 923 PETSC_EXTERN PetscErrorCode MatCreateVecs(Mat, Vec *, Vec *); 924 PETSC_DEPRECATED_FUNCTION(3, 6, 0, "MatCreateVecs()", ) static inline PetscErrorCode MatGetVecs(Mat mat, Vec *x, Vec *y) 925 { 926 return MatCreateVecs(mat, x, y); 927 } 928 PETSC_EXTERN PetscErrorCode MatCreateRedundantMatrix(Mat, PetscInt, MPI_Comm, MatReuse, Mat *); 929 PETSC_EXTERN PetscErrorCode MatGetMultiProcBlock(Mat, MPI_Comm, MatReuse, Mat *); 930 PETSC_EXTERN PetscErrorCode MatFindZeroDiagonals(Mat, IS *); 931 PETSC_EXTERN PetscErrorCode MatFindOffBlockDiagonalEntries(Mat, IS *); 932 PETSC_EXTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat(MPI_Comm, Mat, PetscInt, MatReuse, Mat *); 933 934 /*@C 935 MatSetValue - Set a single entry into a matrix. 936 937 Not Collective 938 939 Input Parameters: 940 + mat - the matrix 941 . i - the row location of the entry 942 . j - the column location of the entry 943 . va - the value to insert 944 - mode - either `INSERT_VALUES` or `ADD_VALUES` 945 946 Level: beginner 947 948 Notes: 949 This value may be cached, so `MatAssemblyBegin()` and `MatAssemblyEnd()` 950 MUST be called after all calls to `MatSetValue()` have been completed. 951 952 For efficiency one should use `MatSetValues()` and set several values simultaneously. 953 954 .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `InsertMode`, `MatGetValue()`, `MatSetValues()`, 955 `MatSetValueLocal()`, `MatSetValuesLocal()` 956 @*/ 957 static inline PetscErrorCode MatSetValue(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode) 958 { 959 return MatSetValues(mat, 1, &i, 1, &j, &va, mode); 960 } 961 962 /*@C 963 MatGetValue - Gets a single value from a matrix 964 965 Not Collective; can only return a value owned by the given process 966 967 Input Parameters: 968 + mat - the matrix 969 . row - the row location of the entry 970 - col - the column location of the entry 971 972 Output Parameter: 973 . va - the value 974 975 Level: advanced 976 977 Notes: 978 The matrix must have been assembled with `MatAssemblyBegin()` and `MatAssemblyEnd()` before this call 979 980 For efficiency one should use `MatGetValues()` and get several values simultaneously. 981 982 See notes for `MatGetValues()`. 983 984 .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `MatSetValue()`, `MatGetValueLocal()`, `MatGetValues()` 985 @*/ 986 static inline PetscErrorCode MatGetValue(Mat mat, PetscInt row, PetscInt col, PetscScalar *va) 987 { 988 return MatGetValues(mat, 1, &row, 1, &col, va); 989 } 990 991 /*@C 992 MatSetValueLocal - Inserts or adds a single value into a matrix, using a local numbering of the nodes. 993 994 Not Collective 995 996 Input Parameters: 997 + mat - the matrix 998 . i - the row location of the entry 999 . j - the column location of the entry 1000 . va - the value to insert 1001 - mode - either `INSERT_VALUES` or `ADD_VALUES` 1002 1003 Level: intermediate 1004 1005 Notes: 1006 For efficiency one should use `MatSetValuesLocal()` and set several values simultaneously. 1007 1008 See notes for `MatSetValuesLocal()` for additional information on when and how this function can be used. 1009 1010 .seealso: [](ch_matrices), `MatSetValue()`, `MatSetValuesLocal()` 1011 @*/ 1012 static inline PetscErrorCode MatSetValueLocal(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode) 1013 { 1014 return MatSetValuesLocal(mat, 1, &i, 1, &j, &va, mode); 1015 } 1016 1017 /*MC 1018 MatPreallocateBegin - Begins the block of code that will count the number of nonzeros per 1019 row in a matrix providing the data that one can use to correctly preallocate the matrix. 1020 1021 Synopsis: 1022 #include <petscmat.h> 1023 PetscErrorCode MatPreallocateBegin(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz) 1024 1025 Collective 1026 1027 Input Parameters: 1028 + comm - the communicator that will share the eventually allocated matrix 1029 . nrows - the number of LOCAL rows in the matrix 1030 - ncols - the number of LOCAL columns in the matrix 1031 1032 Output Parameters: 1033 + dnz - the array that will be passed to the matrix preallocation routines 1034 - onz - the other array passed to the matrix preallocation routines 1035 1036 Level: deprecated (since v3.19) 1037 1038 Notes: 1039 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1040 the use of this routine 1041 1042 This is a macro that handles its own error checking, it does not return an error code. 1043 1044 Do not malloc or free `dnz` and `onz`, that is handled internally by these routines 1045 1046 Developer Note: 1047 This is a MACRO, not a function, because it has a leading { that is closed by `PetscPreallocateFinalize()`. 1048 1049 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`, 1050 `MatPreallocateSymmetricSetLocalBlock()` 1051 M*/ 1052 #define MatPreallocateBegin(comm, nrows, ncols, dnz, onz) \ 1053 do { \ 1054 PetscInt __nrows = (nrows), __ncols = (ncols), __rstart, __end = 0; \ 1055 PetscInt PETSC_UNUSED __start; \ 1056 PetscCall(PetscCalloc2(__nrows, &(dnz), __nrows, &(onz))); \ 1057 PetscCallMPI(MPI_Scan(&__ncols, &__end, 1, MPIU_INT, MPI_SUM, comm)); \ 1058 __start = __end - __ncols; \ 1059 (void)__start; \ 1060 PetscCallMPI(MPI_Scan(&__nrows, &__rstart, 1, MPIU_INT, MPI_SUM, comm)); \ 1061 __rstart -= __nrows 1062 1063 #define MatPreallocateInitialize(...) PETSC_DEPRECATED_MACRO(3, 18, 0, "MatPreallocateBegin()", ) MatPreallocateBegin(__VA_ARGS__) 1064 1065 /*MC 1066 MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1067 inserted using a local number of the rows and columns 1068 1069 Synopsis: 1070 #include <petscmat.h> 1071 PetscErrorCode MatPreallocateSetLocal(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1072 1073 Not Collective 1074 1075 Input Parameters: 1076 + map - the row mapping from local numbering to global numbering 1077 . nrows - the number of rows indicated 1078 . rows - the indices of the rows 1079 . cmap - the column mapping from local to global numbering 1080 . ncols - the number of columns in the matrix 1081 . cols - the columns indicated 1082 . dnz - the array that will be passed to the matrix preallocation routines 1083 - onz - the other array passed to the matrix preallocation routines 1084 1085 Level: deprecated (since v3.19) 1086 1087 Notes: 1088 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1089 the use of this routine 1090 1091 Do not malloc or free `dnz` and `onz`, that is handled internally by these routines 1092 1093 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()` 1094 `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocalRemoveDups()` 1095 M*/ 1096 #define MatPreallocateSetLocal(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \ 1097 PetscMacroReturnStandard(PetscCall(ISLocalToGlobalMappingApply(rmap, nrows, rows, rows)); PetscCall(ISLocalToGlobalMappingApply(cmap, ncols, cols, cols)); for (PetscInt __l = 0; __l < nrows; __l++) PetscCall(MatPreallocateSet((rows)[__l], ncols, cols, dnz, onz));) 1098 1099 /*MC 1100 MatPreallocateSetLocalRemoveDups - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1101 inserted using a local number of the rows and columns. This version removes any duplicate columns in cols 1102 1103 Synopsis: 1104 #include <petscmat.h> 1105 PetscErrorCode MatPreallocateSetLocalRemoveDups(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1106 1107 Not Collective 1108 1109 Input Parameters: 1110 + map - the row mapping from local numbering to global numbering 1111 . nrows - the number of rows indicated 1112 . rows - the indices of the rows (these values are mapped to the global values) 1113 . cmap - the column mapping from local to global numbering 1114 . ncols - the number of columns in the matrix (this value will be changed if duplicate columns are found) 1115 . cols - the columns indicated (these values are mapped to the global values, they are then sorted and duplicates removed) 1116 . dnz - the array that will be passed to the matrix preallocation routines 1117 - onz - the other array passed to the matrix preallocation routines 1118 1119 Level: deprecated (since v3.19) 1120 1121 Notes: 1122 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1123 the use of this routine 1124 1125 Do not malloc or free `dnz` and `onz`, that is handled internally by these routines 1126 1127 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()` 1128 `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocal()` 1129 M*/ 1130 #define MatPreallocateSetLocalRemoveDups(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \ 1131 PetscMacroReturnStandard(PetscCall(ISLocalToGlobalMappingApply(rmap, nrows, rows, rows)); PetscCall(ISLocalToGlobalMappingApply(cmap, ncols, cols, cols)); PetscCall(PetscSortRemoveDupsInt(&ncols, cols)); for (PetscInt __l = 0; __l < nrows; __l++) PetscCall(MatPreallocateSet((rows)[__l], ncols, cols, dnz, onz));) 1132 1133 /*MC 1134 MatPreallocateSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1135 inserted using a local number of the rows and columns 1136 1137 Synopsis: 1138 #include <petscmat.h> 1139 PetscErrorCode MatPreallocateSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1140 1141 Not Collective 1142 1143 Input Parameters: 1144 + map - the row mapping from local numbering to global numbering 1145 . nrows - the number of rows indicated 1146 . rows - the indices of the rows 1147 . cmap - the column mapping from local to global numbering 1148 . ncols - the number of columns in the matrix 1149 . cols - the columns indicated 1150 . dnz - the array that will be passed to the matrix preallocation routines 1151 - onz - the other array passed to the matrix preallocation routines 1152 1153 Level: deprecated (since v3.19) 1154 1155 Notes: 1156 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1157 the use of this routine 1158 1159 Do not malloc or free `dnz` and `onz`, that is handled internally by these routines 1160 1161 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()` 1162 `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()` 1163 M*/ 1164 #define MatPreallocateSetLocalBlock(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \ 1165 PetscMacroReturnStandard(PetscCall(ISLocalToGlobalMappingApplyBlock(rmap, nrows, rows, rows)); PetscCall(ISLocalToGlobalMappingApplyBlock(cmap, ncols, cols, cols)); for (PetscInt __l = 0; __l < nrows; __l++) PetscCall(MatPreallocateSet((rows)[__l], ncols, cols, dnz, onz));) 1166 1167 /*MC 1168 MatPreallocateSymmetricSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1169 inserted using a local number of the rows and columns 1170 1171 Synopsis: 1172 #include <petscmat.h> 1173 PetscErrorCode MatPreallocateSymmetricSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1174 1175 Not Collective 1176 1177 Input Parameters: 1178 + map - the mapping between local numbering and global numbering 1179 . nrows - the number of rows indicated 1180 . rows - the indices of the rows 1181 . ncols - the number of columns in the matrix 1182 . cols - the columns indicated 1183 . dnz - the array that will be passed to the matrix preallocation routines 1184 - onz - the other array passed to the matrix preallocation routines 1185 1186 Level: deprecated (since v3.19) 1187 1188 Notes: 1189 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1190 the use of this routine 1191 1192 Do not malloc or free `dnz` and `onz` that is handled internally by these routines 1193 1194 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()` 1195 `MatPreallocateBegin()`, `MatPreallocateSetLocal()` 1196 M*/ 1197 #define MatPreallocateSymmetricSetLocalBlock(map, nrows, rows, ncols, cols, dnz, onz) \ 1198 PetscMacroReturnStandard(PetscCall(ISLocalToGlobalMappingApplyBlock(map, nrows, rows, rows)); PetscCall(ISLocalToGlobalMappingApplyBlock(map, ncols, cols, cols)); for (PetscInt __l = 0; __l < nrows; __l++) PetscCall(MatPreallocateSymmetricSetBlock((rows)[__l], ncols, cols, dnz, onz));) 1199 1200 /*MC 1201 MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1202 inserted using a local number of the rows and columns 1203 1204 Synopsis: 1205 #include <petscmat.h> 1206 PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1207 1208 Not Collective 1209 1210 Input Parameters: 1211 + row - the row 1212 . ncols - the number of columns in the matrix 1213 - cols - the columns indicated 1214 1215 Output Parameters: 1216 + dnz - the array that will be passed to the matrix preallocation routines 1217 - onz - the other array passed to the matrix preallocation routines 1218 1219 Level: deprecated (since v3.19) 1220 1221 Notes: 1222 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1223 the use of this routine 1224 1225 Do not malloc or free `dnz` and `onz` that is handled internally by these routines 1226 1227 This is a MACRO, not a function, because it uses variables declared in MatPreallocateBegin(). 1228 1229 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()` 1230 `MatPreallocateBegin()`, `MatPreallocateSetLocal()` 1231 M*/ 1232 #define MatPreallocateSet(row, nc, cols, dnz, onz) \ 1233 PetscMacroReturnStandard(PetscCheck(row >= __rstart, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Trying to set preallocation for row %" PetscInt_FMT " less than first local row %" PetscInt_FMT, row, __rstart); PetscCheck(row < __rstart + __nrows, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Trying to set preallocation for row %" PetscInt_FMT " greater than last local row %" PetscInt_FMT, row, __rstart + __nrows - 1); for (PetscInt __i = 0; __i < nc; ++__i) { \ 1234 if ((cols)[__i] < __start || (cols)[__i] >= __end) onz[row - __rstart]++; \ 1235 else if (dnz[row - __rstart] < __ncols) dnz[row - __rstart]++; \ 1236 }) 1237 1238 /*MC 1239 MatPreallocateSymmetricSetBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be 1240 inserted using a local number of the rows and columns 1241 1242 Synopsis: 1243 #include <petscmat.h> 1244 PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz) 1245 1246 Not Collective 1247 1248 Input Parameters: 1249 + nrows - the number of rows indicated 1250 . rows - the indices of the rows 1251 . ncols - the number of columns in the matrix 1252 . cols - the columns indicated 1253 . dnz - the array that will be passed to the matrix preallocation routines 1254 - onz - the other array passed to the matrix preallocation routines 1255 1256 Level: deprecated (since v3.19) 1257 1258 Notes: 1259 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1260 the use of this routine 1261 1262 Do not malloc or free `dnz` and `onz` that is handled internally by these routines 1263 1264 This is a MACRO, not a function, because it uses variables declared in MatPreallocateBegin(). 1265 1266 .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateBegin()`, 1267 `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocal()` 1268 M*/ 1269 #define MatPreallocateSymmetricSetBlock(row, nc, cols, dnz, onz) \ 1270 PetscMacroReturnStandard(for (PetscInt __i = 0; __i < nc; __i++) { \ 1271 if (cols[__i] >= __end) onz[row - __rstart]++; \ 1272 else if (cols[__i] >= row && dnz[row - __rstart] < __ncols) dnz[row - __rstart]++; \ 1273 }) 1274 1275 /*MC 1276 MatPreallocateLocation - An alternative to MatPreallocateSet() that puts the nonzero locations into the matrix if it exists 1277 1278 Synopsis: 1279 #include <petscmat.h> 1280 PetscErrorCode MatPreallocateLocations(Mat A,PetscInt row,PetscInt ncols,PetscInt *cols,PetscInt *dnz,PetscInt *onz) 1281 1282 Not Collective 1283 1284 Input Parameters: 1285 + A - matrix 1286 . row - row where values exist (must be local to this process) 1287 . ncols - number of columns 1288 . cols - columns with nonzeros 1289 . dnz - the array that will be passed to the matrix preallocation routines 1290 - onz - the other array passed to the matrix preallocation routines 1291 1292 Level: deprecated (since v3.19) 1293 1294 Notes: 1295 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1296 the use of this routine 1297 1298 Do not malloc or free `dnz` and `onz` that is handled internally by these routines 1299 1300 Developer Note: 1301 This is a MACRO, not a function, because it uses a bunch of variables private to the MatPreallocation.... routines. 1302 1303 .seealso: [](ch_matrices), `MatPreallocateBegin()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`, 1304 `MatPreallocateSymmetricSetLocalBlock()` 1305 M*/ 1306 #define MatPreallocateLocation(A, row, ncols, cols, dnz, onz) (A ? MatSetValues(A, 1, &row, ncols, cols, NULL, INSERT_VALUES) : MatPreallocateSet(row, ncols, cols, dnz, onz)) 1307 1308 /*MC 1309 MatPreallocateEnd - Ends the block of code that will count the number of nonzeros per 1310 row in a matrix providing the data that one can use to correctly preallocate the matrix. 1311 1312 Synopsis: 1313 #include <petscmat.h> 1314 PetscErrorCode MatPreallocateEnd(PetscInt *dnz, PetscInt *onz) 1315 1316 Collective 1317 1318 Input Parameters: 1319 + dnz - the array that was be passed to the matrix preallocation routines 1320 - onz - the other array passed to the matrix preallocation routines 1321 1322 Level: deprecated (since v3.19) 1323 1324 Notes: 1325 This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than 1326 the use of this routine 1327 1328 Do not malloc or free `dnz` and `onz`, that is handled internally by these routines 1329 1330 Developer Note: 1331 This is a MACRO, not a function, because it closes the { started in MatPreallocateBegin(). 1332 1333 .seealso: [](ch_matrices), `MatPreallocateBegin()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`, 1334 `MatPreallocateSymmetricSetLocalBlock()` 1335 M*/ 1336 #define MatPreallocateEnd(dnz, onz) \ 1337 PetscCall(PetscFree2(dnz, onz)); \ 1338 } \ 1339 while (0) 1340 1341 #define MatPreallocateFinalize(...) PETSC_DEPRECATED_MACRO(3, 18, 0, "MatPreallocateEnd()", ) MatPreallocateEnd(__VA_ARGS__) 1342 1343 /* Routines unique to particular data structures */ 1344 PETSC_EXTERN PetscErrorCode MatShellGetContext(Mat, void *); 1345 1346 PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat, IS *, IS *); 1347 PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat, PetscInt *, PetscInt *[], PetscInt *); 1348 1349 PETSC_EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat, PetscInt[]); 1350 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat, PetscInt[]); 1351 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *); 1352 PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *); 1353 PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *); 1354 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJFromTriple(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *, PetscInt, PetscBool); 1355 1356 #define MAT_SKIP_ALLOCATION -4 1357 1358 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]); 1359 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]); 1360 PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat, PetscInt, const PetscInt[]); 1361 PETSC_EXTERN PetscErrorCode MatSeqAIJSetTotalPreallocation(Mat, PetscInt); 1362 1363 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 1364 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 1365 PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 1366 PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]); 1367 PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]); 1368 PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]); 1369 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]); 1370 PETSC_EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat, PetscInt[], PetscInt[], PetscInt[]); 1371 PETSC_EXTERN PetscErrorCode MatMPIAdjToSeq(Mat, Mat *); 1372 PETSC_EXTERN PetscErrorCode MatMPIAdjToSeqRankZero(Mat, Mat *); 1373 PETSC_EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat, PetscScalar[]); 1374 PETSC_EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat, PetscScalar[]); 1375 PETSC_EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat, Mat *, Mat *, const PetscInt *[]); 1376 PETSC_EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat, Mat *, Mat *, const PetscInt *[]); 1377 PETSC_EXTERN PetscErrorCode MatMPIAdjCreateNonemptySubcommMat(Mat, Mat *); 1378 1379 PETSC_EXTERN PetscErrorCode MatDenseGetLDA(Mat, PetscInt *); 1380 PETSC_EXTERN PetscErrorCode MatDenseSetLDA(Mat, PetscInt); 1381 PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatDenseSetLDA()", ) static inline PetscErrorCode MatSeqDenseSetLDA(Mat A, PetscInt lda) 1382 { 1383 return MatDenseSetLDA(A, lda); 1384 } 1385 PETSC_EXTERN PetscErrorCode MatDenseGetLocalMatrix(Mat, Mat *); 1386 1387 PETSC_EXTERN PetscErrorCode MatBlockMatSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]); 1388 1389 PETSC_EXTERN PetscErrorCode MatStoreValues(Mat); 1390 PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat); 1391 1392 PETSC_EXTERN PetscErrorCode MatFindNonzeroRows(Mat, IS *); 1393 PETSC_EXTERN PetscErrorCode MatFindZeroRows(Mat, IS *); 1394 /* 1395 These routines are not usually accessed directly, rather solving is 1396 done through the KSP and PC interfaces. 1397 */ 1398 1399 /*J 1400 MatOrderingType - String with the name of a PETSc matrix ordering. These orderings are most commonly used 1401 to reduce fill in sparse factorizations. 1402 1403 Level: beginner 1404 1405 Notes: 1406 If `MATORDERINGEXTERNAL` is used then PETSc does not compute an ordering and instead the external factorization solver package called utilizes one 1407 of its own. 1408 1409 There is no `MatOrdering` object, the ordering is obtained directly from the matrix with `MatGetOrdering()` 1410 1411 Developer Note: 1412 This API should be converted to an API similar to those for `MatColoring` and `MatPartitioning` 1413 1414 .seealso: [](ch_matrices), [](sec_graph), `MatGetFactor()`, `MatGetOrdering()`, `MatColoringType`, `MatPartitioningType`, `MatCoarsenType`, `MatCoarsenType`, 1415 `PCFactorSetOrderingType()` 1416 J*/ 1417 typedef const char *MatOrderingType; 1418 #define MATORDERINGNATURAL "natural" 1419 #define MATORDERINGND "nd" 1420 #define MATORDERING1WD "1wd" 1421 #define MATORDERINGRCM "rcm" 1422 #define MATORDERINGQMD "qmd" 1423 #define MATORDERINGROWLENGTH "rowlength" 1424 #define MATORDERINGWBM "wbm" 1425 #define MATORDERINGSPECTRAL "spectral" 1426 #define MATORDERINGAMD "amd" /* only works if UMFPACK is installed with PETSc */ 1427 #define MATORDERINGMETISND "metisnd" /* only works if METIS is installed with PETSc */ 1428 #define MATORDERINGNATURAL_OR_ND "natural_or_nd" /* special coase used for Cholesky and ICC, allows ND when AIJ matrix is used but Natural when SBAIJ is used */ 1429 #define MATORDERINGEXTERNAL "external" /* uses an ordering type internal to the factorization package */ 1430 1431 PETSC_EXTERN PetscErrorCode MatGetOrdering(Mat, MatOrderingType, IS *, IS *); 1432 PETSC_EXTERN PetscErrorCode MatGetOrderingList(PetscFunctionList *); 1433 PETSC_EXTERN PetscErrorCode MatOrderingRegister(const char[], PetscErrorCode (*)(Mat, MatOrderingType, IS *, IS *)); 1434 PETSC_EXTERN PetscFunctionList MatOrderingList; 1435 1436 #include "petscmatcoarsen.h" 1437 1438 PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat, PetscReal, IS, IS); 1439 PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat, PetscReal, PetscBool, Mat *); 1440 1441 PETSC_EXTERN PetscErrorCode MatFactorGetPreferredOrdering(Mat, MatFactorType, MatOrderingType *); 1442 1443 /*S 1444 MatFactorShiftType - Type of numeric shift used for factorizations 1445 1446 Values: 1447 + `MAT_SHIFT_NONE` - do not shift the matrix diagonal entries 1448 . `MAT_SHIFT_NONZERO` - shift the entries to be non-zero 1449 . `MAT_SHIFT_POSITIVE_DEFINITE` - shift the entries to force the factorization to be positive definite 1450 - `MAT_SHIFT_INBLOCKS` - only shift the factors inside the small dense diagonal blocks of the matrix, for example with `MATBAIJ` 1451 1452 Level: intermediate 1453 1454 .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `PCFactorSetShiftType()` 1455 S*/ 1456 typedef enum { 1457 MAT_SHIFT_NONE, 1458 MAT_SHIFT_NONZERO, 1459 MAT_SHIFT_POSITIVE_DEFINITE, 1460 MAT_SHIFT_INBLOCKS 1461 } MatFactorShiftType; 1462 PETSC_EXTERN const char *const MatFactorShiftTypes[]; 1463 PETSC_EXTERN const char *const MatFactorShiftTypesDetail[]; 1464 1465 /*S 1466 MatFactorError - indicates what type of error was generated in a matrix factorization 1467 1468 Values: 1469 + `MAT_FACTOR_NOERROR` - there was no error during the factorization 1470 . `MAT_FACTOR_STRUCT_ZEROPIVOT` - there was a missing entry in a diagonal location of the matrix 1471 . `MAT_FACTOR_NUMERIC_ZEROPIVOT` - there was a (near) zero pivot during the factorization 1472 . `MAT_FACTOR_OUTMEMORY` - the factorization has run out of memory 1473 - `MAT_FACTOR_OTHER` - some other error has occurred. 1474 1475 Level: intermediate 1476 1477 Note: 1478 When a factorization is done in a preconditioner `PC` the error may be propagated up to a `PCFailedReason` or a `KSPConvergedReason` 1479 1480 .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `MatFactorGetError()`, `MatFactorGetErrorZeroPivot()`, `MatFactorClearError()`, 1481 `PCFailedReason`, `PCGetFailedReason()`, `KSPConvergedReason` 1482 S*/ 1483 typedef enum { 1484 MAT_FACTOR_NOERROR, 1485 MAT_FACTOR_STRUCT_ZEROPIVOT, 1486 MAT_FACTOR_NUMERIC_ZEROPIVOT, 1487 MAT_FACTOR_OUTMEMORY, 1488 MAT_FACTOR_OTHER 1489 } MatFactorError; 1490 1491 PETSC_EXTERN PetscErrorCode MatFactorGetError(Mat, MatFactorError *); 1492 PETSC_EXTERN PetscErrorCode MatFactorClearError(Mat); 1493 PETSC_EXTERN PetscErrorCode MatFactorGetErrorZeroPivot(Mat, PetscReal *, PetscInt *); 1494 1495 /*S 1496 MatFactorInfo - Data passed into the matrix factorization routines, and information about the resulting factorization 1497 1498 Level: developer 1499 1500 Note: 1501 You can use `MatFactorInfoInitialize()` to set default values. 1502 1503 Fortran Note: 1504 The data is available in a double precision arrays of size `MAT_FACTORINFO_SIZE` 1505 1506 .seealso: [](ch_matrices), `Mat`, `MatInfo`, `MatGetFactor()`, `MatLUFactorSymbolic()`, `MatILUFactorSymbolic()`, `MatCholeskyFactorSymbolic()`, 1507 `MatICCFactorSymbolic()`, `MatICCFactor()`, `MatFactorInfoInitialize()` 1508 S*/ 1509 typedef struct { 1510 PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */ 1511 PetscReal usedt; 1512 PetscReal dt; /* drop tolerance */ 1513 PetscReal dtcol; /* tolerance for pivoting */ 1514 PetscReal dtcount; /* maximum nonzeros to be allowed per row */ 1515 PetscReal fill; /* expected fill, nonzeros in factored matrix/nonzeros in original matrix */ 1516 PetscReal levels; /* ICC/ILU(levels) */ 1517 PetscReal pivotinblocks; /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0 1518 factorization may be faster if do not pivot */ 1519 PetscReal zeropivot; /* pivot is called zero if less than this */ 1520 PetscReal shifttype; /* type of shift added to matrix factor to prevent zero pivots */ 1521 PetscReal shiftamount; /* how large the shift is */ 1522 } MatFactorInfo; 1523 1524 PETSC_EXTERN PetscErrorCode MatFactorInfoInitialize(MatFactorInfo *); 1525 PETSC_EXTERN PetscErrorCode MatCholeskyFactor(Mat, IS, const MatFactorInfo *); 1526 PETSC_EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *); 1527 PETSC_EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat, Mat, const MatFactorInfo *); 1528 PETSC_EXTERN PetscErrorCode MatLUFactor(Mat, IS, IS, const MatFactorInfo *); 1529 PETSC_EXTERN PetscErrorCode MatILUFactor(Mat, IS, IS, const MatFactorInfo *); 1530 PETSC_EXTERN PetscErrorCode MatLUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *); 1531 PETSC_EXTERN PetscErrorCode MatILUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *); 1532 PETSC_EXTERN PetscErrorCode MatICCFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *); 1533 PETSC_EXTERN PetscErrorCode MatICCFactor(Mat, IS, const MatFactorInfo *); 1534 PETSC_EXTERN PetscErrorCode MatLUFactorNumeric(Mat, Mat, const MatFactorInfo *); 1535 PETSC_EXTERN PetscErrorCode MatQRFactor(Mat, IS, const MatFactorInfo *); 1536 PETSC_EXTERN PetscErrorCode MatQRFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *); 1537 PETSC_EXTERN PetscErrorCode MatQRFactorNumeric(Mat, Mat, const MatFactorInfo *); 1538 PETSC_EXTERN PetscErrorCode MatGetInertia(Mat, PetscInt *, PetscInt *, PetscInt *); 1539 PETSC_EXTERN PetscErrorCode MatSolve(Mat, Vec, Vec); 1540 PETSC_EXTERN PetscErrorCode MatForwardSolve(Mat, Vec, Vec); 1541 PETSC_EXTERN PetscErrorCode MatBackwardSolve(Mat, Vec, Vec); 1542 PETSC_EXTERN PetscErrorCode MatSolveAdd(Mat, Vec, Vec, Vec); 1543 PETSC_EXTERN PetscErrorCode MatSolveTranspose(Mat, Vec, Vec); 1544 PETSC_EXTERN PetscErrorCode MatSolveTransposeAdd(Mat, Vec, Vec, Vec); 1545 PETSC_EXTERN PetscErrorCode MatSolves(Mat, Vecs, Vecs); 1546 PETSC_EXTERN PetscErrorCode MatSetUnfactored(Mat); 1547 1548 typedef enum { 1549 MAT_FACTOR_SCHUR_UNFACTORED, 1550 MAT_FACTOR_SCHUR_FACTORED, 1551 MAT_FACTOR_SCHUR_INVERTED 1552 } MatFactorSchurStatus; 1553 PETSC_EXTERN PetscErrorCode MatFactorSetSchurIS(Mat, IS); 1554 PETSC_EXTERN PetscErrorCode MatFactorGetSchurComplement(Mat, Mat *, MatFactorSchurStatus *); 1555 PETSC_EXTERN PetscErrorCode MatFactorRestoreSchurComplement(Mat, Mat *, MatFactorSchurStatus); 1556 PETSC_EXTERN PetscErrorCode MatFactorInvertSchurComplement(Mat); 1557 PETSC_EXTERN PetscErrorCode MatFactorCreateSchurComplement(Mat, Mat *, MatFactorSchurStatus *); 1558 PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplement(Mat, Vec, Vec); 1559 PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplementTranspose(Mat, Vec, Vec); 1560 PETSC_EXTERN PetscErrorCode MatFactorFactorizeSchurComplement(Mat); 1561 1562 PETSC_EXTERN PetscErrorCode MatSeqDenseInvert(Mat); 1563 /*E 1564 MatSORType - What type of (S)SOR to perform 1565 1566 Values: 1567 + `SOR_FORWARD_SWEEP` - do a sweep from the first row of the matrix to the last 1568 . `SOR_BACKWARD_SWEEP` - do a sweep from the last row to the first 1569 . `SOR_SYMMETRIC_SWEEP` - do a sweep from the first row to the last and then back to the first 1570 . `SOR_LOCAL_FORWARD_SWEEP` - each MPI process does its own forward sweep with no communication 1571 . `SOR_LOCAL_BACKWARD_SWEEP` - each MPI process does its own backward sweep with no communication 1572 . `SOR_LOCAL_SYMMETRIC_SWEEP` - each MPI process does its own symmetric sweep with no communication 1573 . `SOR_ZERO_INITIAL_GUESS` - indicates the initial solution is zero so the sweep can avoid unneeded computation 1574 . `SOR_EISENSTAT` - apply the Eisentat application of SOR, see `PCEISENSTAT` 1575 . `SOR_APPLY_UPPER` - multiply by the upper triangular portion of the matrix 1576 - `SOR_APPLY_LOWER` - multiply by the lower triangular portion of the matrix 1577 1578 Level: beginner 1579 1580 Note: 1581 These may be bitwise ORd together 1582 1583 Developer Note: 1584 Since `MatSORType` may be bitwise ORd together, so do not change the numerical values below 1585 1586 .seealso: [](ch_matrices), `MatSOR()` 1587 E*/ 1588 typedef enum { 1589 SOR_FORWARD_SWEEP = 1, 1590 SOR_BACKWARD_SWEEP = 2, 1591 SOR_SYMMETRIC_SWEEP = 3, 1592 SOR_LOCAL_FORWARD_SWEEP = 4, 1593 SOR_LOCAL_BACKWARD_SWEEP = 8, 1594 SOR_LOCAL_SYMMETRIC_SWEEP = 12, 1595 SOR_ZERO_INITIAL_GUESS = 16, 1596 SOR_EISENSTAT = 32, 1597 SOR_APPLY_UPPER = 64, 1598 SOR_APPLY_LOWER = 128 1599 } MatSORType; 1600 PETSC_EXTERN PetscErrorCode MatSOR(Mat, Vec, PetscReal, MatSORType, PetscReal, PetscInt, PetscInt, Vec); 1601 1602 /*S 1603 MatColoring - Object for managing the coloring of matrices. 1604 1605 Level: beginner 1606 1607 Notes: 1608 Coloring of matrices can be computed directly from the sparse matrix nonzero structure via the `MatColoring` object or from the mesh from which the 1609 matrix comes from via `DMCreateColoring()`. In general using the mesh produces a more optimal coloring (fewer colors). 1610 1611 Once a coloring is available `MatFDColoringCreate()` creates an object that can be used to efficiently compute Jacobians using that coloring. This 1612 same object can also be used to efficiently convert data created by Automatic Differentiation tools to PETSc sparse matrices. 1613 1614 .seealso: [](ch_matrices), [](sec_graph), `MatFDColoringCreate()`, `MatColoringWeightType`, `ISColoring`, `MatFDColoring`, `DMCreateColoring()`, `MatColoringCreate()`, 1615 `MatPartitioning`, `MatColoringType`, `MatPartitioningType`, `MatOrderingType`, `MatColoringSetWeightType()`, 1616 `MatColoringSetWeights()`, `MatCoarsenType`, `MatCoarsen` 1617 S*/ 1618 typedef struct _p_MatColoring *MatColoring; 1619 1620 /*J 1621 MatColoringType - String with the name of a PETSc matrix coloring 1622 1623 Level: beginner 1624 1625 .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatFDColoringCreate()`, `MatColoringSetType()`, `MatColoring` 1626 J*/ 1627 typedef const char *MatColoringType; 1628 #define MATCOLORINGJP "jp" 1629 #define MATCOLORINGPOWER "power" 1630 #define MATCOLORINGNATURAL "natural" 1631 #define MATCOLORINGSL "sl" 1632 #define MATCOLORINGLF "lf" 1633 #define MATCOLORINGID "id" 1634 #define MATCOLORINGGREEDY "greedy" 1635 1636 /*E 1637 MatColoringWeightType - Type of weight scheme used for the coloring algorithm 1638 1639 Values: 1640 + `MAT_COLORING_RANDOM` - Random weights 1641 . `MAT_COLORING_LEXICAL` - Lexical weighting based upon global numbering. 1642 - `MAT_COLORING_LF` - Last-first weighting. 1643 1644 Level: intermediate 1645 1646 .seealso: [](ch_matrices), `MatColoring`, `MatColoringCreate()`, `MatColoringSetWeightType()`, `MatColoringSetWeights()` 1647 E*/ 1648 typedef enum { 1649 MAT_COLORING_WEIGHT_RANDOM, 1650 MAT_COLORING_WEIGHT_LEXICAL, 1651 MAT_COLORING_WEIGHT_LF, 1652 MAT_COLORING_WEIGHT_SL 1653 } MatColoringWeightType; 1654 1655 PETSC_EXTERN PetscErrorCode MatColoringCreate(Mat, MatColoring *); 1656 PETSC_EXTERN PetscErrorCode MatColoringGetDegrees(Mat, PetscInt, PetscInt *); 1657 PETSC_EXTERN PetscErrorCode MatColoringDestroy(MatColoring *); 1658 PETSC_EXTERN PetscErrorCode MatColoringView(MatColoring, PetscViewer); 1659 PETSC_EXTERN PetscErrorCode MatColoringSetType(MatColoring, MatColoringType); 1660 PETSC_EXTERN PetscErrorCode MatColoringSetFromOptions(MatColoring); 1661 PETSC_EXTERN PetscErrorCode MatColoringSetDistance(MatColoring, PetscInt); 1662 PETSC_EXTERN PetscErrorCode MatColoringGetDistance(MatColoring, PetscInt *); 1663 PETSC_EXTERN PetscErrorCode MatColoringSetMaxColors(MatColoring, PetscInt); 1664 PETSC_EXTERN PetscErrorCode MatColoringGetMaxColors(MatColoring, PetscInt *); 1665 PETSC_EXTERN PetscErrorCode MatColoringApply(MatColoring, ISColoring *); 1666 PETSC_EXTERN PetscErrorCode MatColoringRegister(const char[], PetscErrorCode (*)(MatColoring)); 1667 PETSC_EXTERN PetscErrorCode MatColoringPatch(Mat, PetscInt, PetscInt, ISColoringValue[], ISColoring *); 1668 PETSC_EXTERN PetscErrorCode MatColoringSetWeightType(MatColoring, MatColoringWeightType); 1669 PETSC_EXTERN PetscErrorCode MatColoringSetWeights(MatColoring, PetscReal *, PetscInt *); 1670 PETSC_EXTERN PetscErrorCode MatColoringCreateWeights(MatColoring, PetscReal **, PetscInt **lperm); 1671 PETSC_EXTERN PetscErrorCode MatColoringTest(MatColoring, ISColoring); 1672 PETSC_DEPRECATED_FUNCTION(3, 10, 0, "MatColoringTest()", ) static inline PetscErrorCode MatColoringTestValid(MatColoring matcoloring, ISColoring iscoloring) 1673 { 1674 return MatColoringTest(matcoloring, iscoloring); 1675 } 1676 PETSC_EXTERN PetscErrorCode MatISColoringTest(Mat, ISColoring); 1677 1678 /*S 1679 MatFDColoring - Object for computing a sparse Jacobian via finite differences with coloring 1680 1681 Level: beginner 1682 1683 Notes: 1684 This object is creating utilizing a coloring provided by the `MatColoring` object or `DMCreateColoring()` 1685 1686 The `SNES` option `-snes_fd_coloring` will cause the Jacobian needed by `SNES` to be computed via a use of this object 1687 1688 .seealso: [](ch_matrices), `Mat`, `MatFDColoringCreate()`, `MatFDColoringSetFunction()`, `MatColoring`, `DMCreateColoring()` 1689 S*/ 1690 typedef struct _p_MatFDColoring *MatFDColoring; 1691 1692 PETSC_EXTERN PetscErrorCode MatFDColoringCreate(Mat, ISColoring, MatFDColoring *); 1693 PETSC_EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring *); 1694 PETSC_EXTERN PetscErrorCode MatFDColoringView(MatFDColoring, PetscViewer); 1695 PETSC_EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring, PetscErrorCode (*)(void), void *); 1696 PETSC_EXTERN PetscErrorCode MatFDColoringGetFunction(MatFDColoring, PetscErrorCode (**)(void), void **); 1697 PETSC_EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring, PetscReal, PetscReal); 1698 PETSC_EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring); 1699 PETSC_EXTERN PetscErrorCode MatFDColoringApply(Mat, MatFDColoring, Vec, void *); 1700 PETSC_EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring, Vec); 1701 PETSC_EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring, PetscInt *, const PetscInt *[]); 1702 PETSC_EXTERN PetscErrorCode MatFDColoringSetUp(Mat, ISColoring, MatFDColoring); 1703 PETSC_EXTERN PetscErrorCode MatFDColoringSetBlockSize(MatFDColoring, PetscInt, PetscInt); 1704 PETSC_EXTERN PetscErrorCode MatFDColoringSetValues(Mat, MatFDColoring, const PetscScalar *); 1705 1706 /*S 1707 MatTransposeColoring - Object for computing a sparse matrix product $C = A*B^T$ via coloring 1708 1709 Level: developer 1710 1711 .seealso: [](ch_matrices), `Mat`, `MatProductType`, `MatTransposeColoringCreate()` 1712 S*/ 1713 typedef struct _p_MatTransposeColoring *MatTransposeColoring; 1714 1715 PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat, ISColoring, MatTransposeColoring *); 1716 PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring, Mat, Mat); 1717 PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring, Mat, Mat); 1718 PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring *); 1719 1720 /*S 1721 MatPartitioning - Object for managing the partitioning of a matrix or graph 1722 1723 Level: beginner 1724 1725 Note: 1726 There is also a `PetscPartitioner` object that provides the same functionality. It can utilize the `MatPartitioning` operations 1727 via `PetscPartitionerSetType`(p,`PETSCPARTITIONERMATPARTITIONING`) 1728 1729 Developer Note: 1730 It is an extra maintenance and documentation cost to have two objects with the same functionality. `PetscPartitioner` should be removed 1731 1732 .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioningType`, `MatColoring`, `MatGetOrdering()`, `MatOrderingType`, 1733 `MatCoarsenType`, `MatCoarsenType` 1734 S*/ 1735 typedef struct _p_MatPartitioning *MatPartitioning; 1736 1737 /*J 1738 MatPartitioningType - String with the name of a PETSc matrix partitioning 1739 1740 Level: beginner 1741 dm 1742 .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioning`, `MatPartitioningSetType()`, `MatColoringType`, `MatOrderingType`, 1743 `MatCoarsenType`, `MatCoarsenType` 1744 J*/ 1745 typedef const char *MatPartitioningType; 1746 #define MATPARTITIONINGCURRENT "current" 1747 #define MATPARTITIONINGAVERAGE "average" 1748 #define MATPARTITIONINGSQUARE "square" 1749 #define MATPARTITIONINGPARMETIS "parmetis" 1750 #define MATPARTITIONINGCHACO "chaco" 1751 #define MATPARTITIONINGPARTY "party" 1752 #define MATPARTITIONINGPTSCOTCH "ptscotch" 1753 #define MATPARTITIONINGHIERARCH "hierarch" 1754 1755 PETSC_EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm, MatPartitioning *); 1756 PETSC_EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning, MatPartitioningType); 1757 PETSC_EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning, PetscInt); 1758 PETSC_EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning, Mat); 1759 PETSC_EXTERN PetscErrorCode MatPartitioningSetNumberVertexWeights(MatPartitioning, PetscInt); 1760 PETSC_EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning, const PetscInt[]); 1761 PETSC_EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning, const PetscReal[]); 1762 PETSC_EXTERN PetscErrorCode MatPartitioningSetUseEdgeWeights(MatPartitioning, PetscBool); 1763 PETSC_EXTERN PetscErrorCode MatPartitioningGetUseEdgeWeights(MatPartitioning, PetscBool *); 1764 PETSC_EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning, IS *); 1765 PETSC_EXTERN PetscErrorCode MatPartitioningImprove(MatPartitioning, IS *); 1766 PETSC_EXTERN PetscErrorCode MatPartitioningViewImbalance(MatPartitioning, IS); 1767 PETSC_EXTERN PetscErrorCode MatPartitioningApplyND(MatPartitioning, IS *); 1768 PETSC_EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning *); 1769 PETSC_EXTERN PetscErrorCode MatPartitioningRegister(const char[], PetscErrorCode (*)(MatPartitioning)); 1770 PETSC_EXTERN PetscErrorCode MatPartitioningView(MatPartitioning, PetscViewer); 1771 PETSC_EXTERN PetscErrorCode MatPartitioningViewFromOptions(MatPartitioning, PetscObject, const char[]); 1772 PETSC_EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning); 1773 PETSC_EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning, MatPartitioningType *); 1774 1775 PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetRepartition(MatPartitioning part); 1776 PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 1777 PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *); 1778 1779 typedef enum { 1780 MP_CHACO_MULTILEVEL = 1, 1781 MP_CHACO_SPECTRAL = 2, 1782 MP_CHACO_LINEAR = 4, 1783 MP_CHACO_RANDOM = 5, 1784 MP_CHACO_SCATTERED = 6 1785 } MPChacoGlobalType; 1786 PETSC_EXTERN const char *const MPChacoGlobalTypes[]; 1787 typedef enum { 1788 MP_CHACO_KERNIGHAN = 1, 1789 MP_CHACO_NONE = 2 1790 } MPChacoLocalType; 1791 PETSC_EXTERN const char *const MPChacoLocalTypes[]; 1792 typedef enum { 1793 MP_CHACO_LANCZOS = 0, 1794 MP_CHACO_RQI = 1 1795 } MPChacoEigenType; 1796 PETSC_EXTERN const char *const MPChacoEigenTypes[]; 1797 1798 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning, MPChacoGlobalType); 1799 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning, MPChacoGlobalType *); 1800 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning, MPChacoLocalType); 1801 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning, MPChacoLocalType *); 1802 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning, PetscReal); 1803 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning, MPChacoEigenType); 1804 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning, MPChacoEigenType *); 1805 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning, PetscReal); 1806 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning, PetscReal *); 1807 PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning, PetscInt); 1808 PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning, PetscInt *); 1809 1810 #define MP_PARTY_OPT "opt" 1811 #define MP_PARTY_LIN "lin" 1812 #define MP_PARTY_SCA "sca" 1813 #define MP_PARTY_RAN "ran" 1814 #define MP_PARTY_GBF "gbf" 1815 #define MP_PARTY_GCF "gcf" 1816 #define MP_PARTY_BUB "bub" 1817 #define MP_PARTY_DEF "def" 1818 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning, const char *); 1819 #define MP_PARTY_HELPFUL_SETS "hs" 1820 #define MP_PARTY_KERNIGHAN_LIN "kl" 1821 #define MP_PARTY_NONE "no" 1822 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning, const char *); 1823 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning, PetscReal); 1824 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning, PetscBool); 1825 PETSC_EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning, PetscBool); 1826 1827 typedef enum { 1828 MP_PTSCOTCH_DEFAULT, 1829 MP_PTSCOTCH_QUALITY, 1830 MP_PTSCOTCH_SPEED, 1831 MP_PTSCOTCH_BALANCE, 1832 MP_PTSCOTCH_SAFETY, 1833 MP_PTSCOTCH_SCALABILITY 1834 } MPPTScotchStrategyType; 1835 PETSC_EXTERN const char *const MPPTScotchStrategyTypes[]; 1836 1837 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning, PetscReal); 1838 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning, PetscReal *); 1839 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning, MPPTScotchStrategyType); 1840 PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning, MPPTScotchStrategyType *); 1841 1842 /* 1843 * hierarchical partitioning 1844 */ 1845 PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetFineparts(MatPartitioning, IS *); 1846 PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetCoarseparts(MatPartitioning, IS *); 1847 PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNcoarseparts(MatPartitioning, PetscInt); 1848 PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNfineparts(MatPartitioning, PetscInt); 1849 1850 PETSC_EXTERN PetscErrorCode MatMeshToCellGraph(Mat, PetscInt, Mat *); 1851 1852 /* 1853 If you add entries here you must also add them to src/mat/f90-mod/petscmat.h 1854 If any of the enum values are changed, also update dMatOps dict at src/binding/petsc4py/src/libpetsc4py/libpetsc4py.pyx 1855 */ 1856 typedef enum { 1857 MATOP_SET_VALUES = 0, 1858 MATOP_GET_ROW = 1, 1859 MATOP_RESTORE_ROW = 2, 1860 MATOP_MULT = 3, 1861 MATOP_MULT_ADD = 4, 1862 MATOP_MULT_TRANSPOSE = 5, 1863 MATOP_MULT_TRANSPOSE_ADD = 6, 1864 MATOP_SOLVE = 7, 1865 MATOP_SOLVE_ADD = 8, 1866 MATOP_SOLVE_TRANSPOSE = 9, 1867 MATOP_SOLVE_TRANSPOSE_ADD = 10, 1868 MATOP_LUFACTOR = 11, 1869 MATOP_CHOLESKYFACTOR = 12, 1870 MATOP_SOR = 13, 1871 MATOP_TRANSPOSE = 14, 1872 MATOP_GETINFO = 15, 1873 MATOP_EQUAL = 16, 1874 MATOP_GET_DIAGONAL = 17, 1875 MATOP_DIAGONAL_SCALE = 18, 1876 MATOP_NORM = 19, 1877 MATOP_ASSEMBLY_BEGIN = 20, 1878 MATOP_ASSEMBLY_END = 21, 1879 MATOP_SET_OPTION = 22, 1880 MATOP_ZERO_ENTRIES = 23, 1881 MATOP_ZERO_ROWS = 24, 1882 MATOP_LUFACTOR_SYMBOLIC = 25, 1883 MATOP_LUFACTOR_NUMERIC = 26, 1884 MATOP_CHOLESKY_FACTOR_SYMBOLIC = 27, 1885 MATOP_CHOLESKY_FACTOR_NUMERIC = 28, 1886 MATOP_SETUP = 29, 1887 MATOP_ILUFACTOR_SYMBOLIC = 30, 1888 MATOP_ICCFACTOR_SYMBOLIC = 31, 1889 MATOP_GET_DIAGONAL_BLOCK = 32, 1890 MATOP_SET_INF = 33, 1891 MATOP_DUPLICATE = 34, 1892 MATOP_FORWARD_SOLVE = 35, 1893 MATOP_BACKWARD_SOLVE = 36, 1894 MATOP_ILUFACTOR = 37, 1895 MATOP_ICCFACTOR = 38, 1896 MATOP_AXPY = 39, 1897 MATOP_CREATE_SUBMATRICES = 40, 1898 MATOP_INCREASE_OVERLAP = 41, 1899 MATOP_GET_VALUES = 42, 1900 MATOP_COPY = 43, 1901 MATOP_GET_ROW_MAX = 44, 1902 MATOP_SCALE = 45, 1903 MATOP_SHIFT = 46, 1904 MATOP_DIAGONAL_SET = 47, 1905 MATOP_ZERO_ROWS_COLUMNS = 48, 1906 MATOP_SET_RANDOM = 49, 1907 MATOP_GET_ROW_IJ = 50, 1908 MATOP_RESTORE_ROW_IJ = 51, 1909 MATOP_GET_COLUMN_IJ = 52, 1910 MATOP_RESTORE_COLUMN_IJ = 53, 1911 MATOP_FDCOLORING_CREATE = 54, 1912 MATOP_COLORING_PATCH = 55, 1913 MATOP_SET_UNFACTORED = 56, 1914 MATOP_PERMUTE = 57, 1915 MATOP_SET_VALUES_BLOCKED = 58, 1916 MATOP_CREATE_SUBMATRIX = 59, 1917 MATOP_DESTROY = 60, 1918 MATOP_VIEW = 61, 1919 MATOP_CONVERT_FROM = 62, 1920 /* MATOP_PLACEHOLDER_63=63 */ 1921 MATOP_MATMAT_MULT_SYMBOLIC = 64, 1922 MATOP_MATMAT_MULT_NUMERIC = 65, 1923 MATOP_SET_LOCAL_TO_GLOBAL_MAP = 66, 1924 MATOP_SET_VALUES_LOCAL = 67, 1925 MATOP_ZERO_ROWS_LOCAL = 68, 1926 MATOP_GET_ROW_MAX_ABS = 69, 1927 MATOP_GET_ROW_MIN_ABS = 70, 1928 MATOP_CONVERT = 71, 1929 MATOP_HAS_OPERATION = 72, 1930 /* MATOP_PLACEHOLDER_73=73, */ 1931 MATOP_SET_VALUES_ADIFOR = 74, 1932 MATOP_FD_COLORING_APPLY = 75, 1933 MATOP_SET_FROM_OPTIONS = 76, 1934 /* MATOP_PLACEHOLDER_77=77, */ 1935 /* MATOP_PLACEHOLDER_78=78, */ 1936 MATOP_FIND_ZERO_DIAGONALS = 79, 1937 MATOP_MULT_MULTIPLE = 80, 1938 MATOP_SOLVE_MULTIPLE = 81, 1939 MATOP_GET_INERTIA = 82, 1940 MATOP_LOAD = 83, 1941 MATOP_IS_SYMMETRIC = 84, 1942 MATOP_IS_HERMITIAN = 85, 1943 MATOP_IS_STRUCTURALLY_SYMMETRIC = 86, 1944 MATOP_SET_VALUES_BLOCKEDLOCAL = 87, 1945 MATOP_CREATE_VECS = 88, 1946 /* MATOP_PLACEHOLDER_89=89, */ 1947 MATOP_MAT_MULT_SYMBOLIC = 90, 1948 MATOP_MAT_MULT_NUMERIC = 91, 1949 /* MATOP_PLACEHOLDER_92=92, */ 1950 MATOP_PTAP_SYMBOLIC = 93, 1951 MATOP_PTAP_NUMERIC = 94, 1952 /* MATOP_PLACEHOLDER_95=95, */ 1953 MATOP_MAT_TRANSPOSE_MULT_SYMBO = 96, 1954 MATOP_MAT_TRANSPOSE_MULT_NUMER = 97, 1955 MATOP_BIND_TO_CPU = 98, 1956 MATOP_PRODUCTSETFROMOPTIONS = 99, 1957 MATOP_PRODUCTSYMBOLIC = 100, 1958 MATOP_PRODUCTNUMERIC = 101, 1959 MATOP_CONJUGATE = 102, 1960 MATOP_VIEW_NATIVE = 103, 1961 MATOP_SET_VALUES_ROW = 104, 1962 MATOP_REAL_PART = 105, 1963 MATOP_IMAGINARY_PART = 106, 1964 MATOP_GET_ROW_UPPER_TRIANGULAR = 107, 1965 MATOP_RESTORE_ROW_UPPER_TRIANG = 108, 1966 MATOP_MAT_SOLVE = 109, 1967 MATOP_MAT_SOLVE_TRANSPOSE = 110, 1968 MATOP_GET_ROW_MIN = 111, 1969 MATOP_GET_COLUMN_VECTOR = 112, 1970 MATOP_MISSING_DIAGONAL = 113, 1971 MATOP_GET_SEQ_NONZERO_STRUCTUR = 114, 1972 MATOP_CREATE = 115, 1973 MATOP_GET_GHOSTS = 116, 1974 MATOP_GET_LOCAL_SUB_MATRIX = 117, 1975 MATOP_RESTORE_LOCALSUB_MATRIX = 118, 1976 MATOP_MULT_DIAGONAL_BLOCK = 119, 1977 MATOP_HERMITIAN_TRANSPOSE = 120, 1978 MATOP_MULT_HERMITIAN_TRANSPOSE = 121, 1979 MATOP_MULT_HERMITIAN_TRANS_ADD = 122, 1980 MATOP_GET_MULTI_PROC_BLOCK = 123, 1981 MATOP_FIND_NONZERO_ROWS = 124, 1982 MATOP_GET_COLUMN_NORMS = 125, 1983 MATOP_INVERT_BLOCK_DIAGONAL = 126, 1984 MATOP_INVERT_VBLOCK_DIAGONAL = 127, 1985 MATOP_CREATE_SUB_MATRICES_MPI = 128, 1986 MATOP_SET_VALUES_BATCH = 129, 1987 /* MATOP_PLACEHOLDER_130=130, */ 1988 MATOP_TRANSPOSE_MAT_MULT_SYMBO = 131, 1989 MATOP_TRANSPOSE_MAT_MULT_NUMER = 132, 1990 MATOP_TRANSPOSE_COLORING_CREAT = 133, 1991 MATOP_TRANS_COLORING_APPLY_SPT = 134, 1992 MATOP_TRANS_COLORING_APPLY_DEN = 135, 1993 /* MATOP_PLACEHOLDER_136=136, */ 1994 MATOP_RART_SYMBOLIC = 137, 1995 MATOP_RART_NUMERIC = 138, 1996 MATOP_SET_BLOCK_SIZES = 139, 1997 MATOP_AYPX = 140, 1998 MATOP_RESIDUAL = 141, 1999 MATOP_FDCOLORING_SETUP = 142, 2000 MATOP_FIND_OFFBLOCK_ENTRIES = 143, 2001 MATOP_MPICONCATENATESEQ = 144, 2002 MATOP_DESTROYSUBMATRICES = 145, 2003 MATOP_TRANSPOSE_SOLVE = 146, 2004 MATOP_GET_VALUES_LOCAL = 147 2005 } MatOperation; 2006 PETSC_EXTERN PetscErrorCode MatSetOperation(Mat, MatOperation, void (*)(void)); 2007 PETSC_EXTERN PetscErrorCode MatGetOperation(Mat, MatOperation, void (**)(void)); 2008 PETSC_EXTERN PetscErrorCode MatHasOperation(Mat, MatOperation, PetscBool *); 2009 PETSC_EXTERN PetscErrorCode MatHasCongruentLayouts(Mat, PetscBool *); 2010 PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatProductClear()", ) static inline PetscErrorCode MatFreeIntermediateDataStructures(Mat A) 2011 { 2012 return MatProductClear(A); 2013 } 2014 PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat, MatOperation, void (*)(void)); 2015 PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat, MatOperation, void (**)(void)); 2016 PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat, void *); 2017 PETSC_EXTERN PetscErrorCode MatShellSetContextDestroy(Mat, PetscErrorCode (*)(void *)); 2018 PETSC_EXTERN PetscErrorCode MatShellSetVecType(Mat, VecType); 2019 PETSC_EXTERN PetscErrorCode MatShellTestMult(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *); 2020 PETSC_EXTERN PetscErrorCode MatShellTestMultTranspose(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *); 2021 PETSC_EXTERN PetscErrorCode MatShellSetManageScalingShifts(Mat); 2022 PETSC_EXTERN PetscErrorCode MatShellSetMatProductOperation(Mat, MatProductType, PetscErrorCode (*)(Mat, Mat, Mat, void **), PetscErrorCode (*)(Mat, Mat, Mat, void *), PetscErrorCode (*)(void *), MatType, MatType); 2023 PETSC_EXTERN PetscErrorCode MatIsShell(Mat, PetscBool *); 2024 2025 /* 2026 Codes for matrices stored on disk. By default they are 2027 stored in a universal format. By changing the format with 2028 PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will 2029 be stored in a way natural for the matrix, for example dense matrices 2030 would be stored as dense. Matrices stored this way may only be 2031 read into matrices of the same type. 2032 */ 2033 #define MATRIX_BINARY_FORMAT_DENSE -1 2034 2035 PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat, PetscReal); 2036 2037 PETSC_EXTERN PetscErrorCode MatISSetLocalMatType(Mat, MatType); 2038 PETSC_EXTERN PetscErrorCode MatISSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]); 2039 PETSC_EXTERN PetscErrorCode MatISStoreL2L(Mat, PetscBool); 2040 PETSC_EXTERN PetscErrorCode MatISFixLocalEmpty(Mat, PetscBool); 2041 PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat, Mat *); 2042 PETSC_EXTERN PetscErrorCode MatISRestoreLocalMat(Mat, Mat *); 2043 PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat, Mat); 2044 PETSC_EXTERN PetscErrorCode MatISGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *); 2045 PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 10, 0, "MatConvert()", ) PetscErrorCode MatISGetMPIXAIJ(Mat, MatReuse, Mat *); 2046 2047 /*S 2048 MatNullSpace - Object that removes a null space from a vector, i.e. 2049 orthogonalizes the vector to a subspace 2050 2051 Level: advanced 2052 2053 .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()` 2054 S*/ 2055 typedef struct _p_MatNullSpace *MatNullSpace; 2056 2057 PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm, PetscBool, PetscInt, const Vec[], MatNullSpace *); 2058 PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace, PetscErrorCode (*)(MatNullSpace, Vec, void *), void *); 2059 PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace *); 2060 PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace, Vec); 2061 PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *); 2062 PETSC_EXTERN PetscErrorCode MatGetTransposeNullSpace(Mat, MatNullSpace *); 2063 PETSC_EXTERN PetscErrorCode MatSetTransposeNullSpace(Mat, MatNullSpace); 2064 PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat, MatNullSpace); 2065 PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat, MatNullSpace); 2066 PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat, MatNullSpace *); 2067 PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace, Mat, PetscBool *); 2068 PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace, PetscViewer); 2069 PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace, PetscBool *, PetscInt *, const Vec **); 2070 PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec, MatNullSpace *); 2071 2072 PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat, IS); 2073 PETSC_EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat, PetscReal); 2074 PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat, PetscInt *); 2075 2076 PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat, PetscInt, Mat *); 2077 PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat, PetscInt, Mat *); 2078 PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat, Mat *); 2079 2080 PETSC_EXTERN PetscErrorCode MatComputeOperator(Mat, MatType, Mat *); 2081 PETSC_EXTERN PetscErrorCode MatComputeOperatorTranspose(Mat, MatType, Mat *); 2082 2083 PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperator()", ) static inline PetscErrorCode MatComputeExplicitOperator(Mat A, Mat *B) 2084 { 2085 return MatComputeOperator(A, PETSC_NULLPTR, B); 2086 } 2087 PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperatorTranspose()", ) static inline PetscErrorCode MatComputeExplicitOperatorTranspose(Mat A, Mat *B) 2088 { 2089 return MatComputeOperatorTranspose(A, PETSC_NULLPTR, B); 2090 } 2091 2092 PETSC_EXTERN PetscErrorCode MatCreateKAIJ(Mat, PetscInt, PetscInt, const PetscScalar[], const PetscScalar[], Mat *); 2093 PETSC_EXTERN PetscErrorCode MatKAIJGetAIJ(Mat, Mat *); 2094 PETSC_EXTERN PetscErrorCode MatKAIJGetS(Mat, PetscInt *, PetscInt *, PetscScalar **); 2095 PETSC_EXTERN PetscErrorCode MatKAIJGetSRead(Mat, PetscInt *, PetscInt *, const PetscScalar **); 2096 PETSC_EXTERN PetscErrorCode MatKAIJRestoreS(Mat, PetscScalar **); 2097 PETSC_EXTERN PetscErrorCode MatKAIJRestoreSRead(Mat, const PetscScalar **); 2098 PETSC_EXTERN PetscErrorCode MatKAIJGetT(Mat, PetscInt *, PetscInt *, PetscScalar **); 2099 PETSC_EXTERN PetscErrorCode MatKAIJGetTRead(Mat, PetscInt *, PetscInt *, const PetscScalar **); 2100 PETSC_EXTERN PetscErrorCode MatKAIJRestoreT(Mat, PetscScalar **); 2101 PETSC_EXTERN PetscErrorCode MatKAIJRestoreTRead(Mat, const PetscScalar **); 2102 PETSC_EXTERN PetscErrorCode MatKAIJSetAIJ(Mat, Mat); 2103 PETSC_EXTERN PetscErrorCode MatKAIJSetS(Mat, PetscInt, PetscInt, const PetscScalar[]); 2104 PETSC_EXTERN PetscErrorCode MatKAIJSetT(Mat, PetscInt, PetscInt, const PetscScalar[]); 2105 PETSC_EXTERN PetscErrorCode MatKAIJGetScaledIdentity(Mat, PetscBool *); 2106 2107 PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat, Vec); 2108 2109 PETSC_EXTERN PetscErrorCode MatMFFDInitializePackage(void); 2110 PETSC_EXTERN PetscErrorCode MatMFFDFinalizePackage(void); 2111 2112 PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, Mat *); 2113 PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat, Vec, Vec); 2114 PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat, PetscErrorCode (*)(void *, Vec, Vec), void *); 2115 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat, PetscErrorCode (*)(void *, PetscInt, Vec, PetscScalar *)); 2116 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat, PetscErrorCode (*)(void *, Vec)); 2117 PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat, PetscScalar[], PetscInt); 2118 PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat); 2119 PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat, PetscReal); 2120 PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat, PetscInt); 2121 PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat, PetscScalar *); 2122 PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat, const char[]); 2123 PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void *, Vec, Vec, PetscScalar *); 2124 PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat, PetscErrorCode (*)(void *, Vec, Vec, PetscScalar *), void *); 2125 2126 /*S 2127 MatMFFD - A data structured used to manage the computation of the h differencing parameter for matrix-free 2128 Jacobian vector products 2129 2130 Level: developer 2131 2132 Notes: 2133 `MATMFFD` is a specific `MatType` which uses the `MatMFFD` data structure 2134 2135 MatMFFD*() methods actually take the `Mat` as their first argument. Not a `MatMFFD` data structure 2136 2137 This functionality is often obtained using `MatCreateSNESMF()` or with `SNES` solvers using `-snes_mf` or `-snes_mf_operator` 2138 2139 .seealso: [](ch_matrices), `MatMFFDType`, `MATMFFD`, `MatCreateMFFD()`, `MatMFFDSetFuction()`, `MatMFFDSetType()`, `MatMFFDRegister()`, 2140 `MatCreateSNESMF()`, `SNES`, `-snes_mf`, `-snes_mf_operator` 2141 S*/ 2142 typedef struct _p_MatMFFD *MatMFFD; 2143 2144 /*J 2145 MatMFFDType - algorithm used to compute the `h` used in computing matrix-vector products via differencing of a function 2146 2147 Values: 2148 + `MATMFFD_DS` - an algorithm described by Dennis and Schnabel {cite}`dennis:83` 2149 - `MATMFFD_WP` - the Walker-Pernice {cite}`pw98` strategy. 2150 2151 Level: beginner 2152 2153 .seealso: [](ch_matrices), `MatMFFDSetType()`, `MatMFFDRegister()`, `MatMFFDSetFunction()`, `MatCreateMFFD()` 2154 J*/ 2155 typedef const char *MatMFFDType; 2156 #define MATMFFD_DS "ds" 2157 #define MATMFFD_WP "wp" 2158 2159 PETSC_EXTERN PetscErrorCode MatMFFDSetType(Mat, MatMFFDType); 2160 PETSC_EXTERN PetscErrorCode MatMFFDRegister(const char[], PetscErrorCode (*)(MatMFFD)); 2161 2162 PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat, PetscReal); 2163 PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat, PetscBool); 2164 2165 PETSC_EXTERN PetscErrorCode MatFDColoringSetType(MatFDColoring, MatMFFDType); 2166 2167 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *); 2168 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *); 2169 2170 #ifdef PETSC_HAVE_H2OPUS 2171 PETSC_EXTERN_TYPEDEF typedef PetscScalar (*MatH2OpusKernel)(PetscInt, PetscReal[], PetscReal[], void *); 2172 PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], PetscBool, MatH2OpusKernel, void *, PetscReal, PetscInt, PetscInt, Mat *); 2173 PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromMat(Mat, PetscInt, const PetscReal[], PetscBool, PetscReal, PetscInt, PetscInt, PetscInt, PetscReal, Mat *); 2174 PETSC_EXTERN PetscErrorCode MatH2OpusSetSamplingMat(Mat, Mat, PetscInt, PetscReal); 2175 PETSC_EXTERN PetscErrorCode MatH2OpusOrthogonalize(Mat); 2176 PETSC_EXTERN PetscErrorCode MatH2OpusCompress(Mat, PetscReal); 2177 PETSC_EXTERN PetscErrorCode MatH2OpusSetNativeMult(Mat, PetscBool); 2178 PETSC_EXTERN PetscErrorCode MatH2OpusGetNativeMult(Mat, PetscBool *); 2179 PETSC_EXTERN PetscErrorCode MatH2OpusGetIndexMap(Mat, IS *); 2180 PETSC_EXTERN PetscErrorCode MatH2OpusMapVec(Mat, PetscBool, Vec, Vec *); 2181 PETSC_EXTERN PetscErrorCode MatH2OpusLowRankUpdate(Mat, Mat, Mat, PetscScalar); 2182 #endif 2183 2184 #ifdef PETSC_HAVE_HTOOL 2185 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*MatHtoolKernel)(PetscInt, PetscInt, PetscInt, const PetscInt *, const PetscInt *, PetscScalar *, void *); 2186 PETSC_EXTERN PetscErrorCode MatCreateHtoolFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], const PetscReal[], MatHtoolKernel, void *, Mat *); 2187 PETSC_EXTERN PetscErrorCode MatHtoolSetKernel(Mat, MatHtoolKernel, void *); 2188 PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationSource(Mat, IS *); 2189 PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationTarget(Mat, IS *); 2190 PETSC_EXTERN PetscErrorCode MatHtoolUsePermutation(Mat, PetscBool); 2191 2192 /*E 2193 MatHtoolCompressorType - Indicates the type of compressor used by a `MATHTOOL` 2194 2195 Values: 2196 + `MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA` (default) - symmetric partial adaptive cross approximation 2197 . `MAT_HTOOL_COMPRESSOR_FULL_ACA` - full adaptive cross approximation 2198 - `MAT_HTOOL_COMPRESSOR_SVD` - singular value decomposition 2199 2200 Level: intermediate 2201 2202 .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolClusteringType` 2203 E*/ 2204 typedef enum { 2205 MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA, 2206 MAT_HTOOL_COMPRESSOR_FULL_ACA, 2207 MAT_HTOOL_COMPRESSOR_SVD 2208 } MatHtoolCompressorType; 2209 2210 /*E 2211 MatHtoolClusteringType - Indicates the type of clustering used by a `MATHTOOL` 2212 2213 Values: 2214 + `MAT_HTOOL_CLUSTERING_PCA_REGULAR` (default) - axis computed via principle component analysis, split uniformly 2215 . `MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC` - axis computed via principle component analysis, split barycentrically 2216 . `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR` - axis along the largest extent of the bounding box, split uniformly 2217 - `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC` - axis along the largest extent of the bounding box, split barycentrically 2218 2219 Level: intermediate 2220 2221 Note: 2222 Higher-dimensional clustering is not yet supported in Htool, but once it is, one should add BOUNDING_BOX_{2,3} types 2223 2224 .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolCompressorType` 2225 E*/ 2226 typedef enum { 2227 MAT_HTOOL_CLUSTERING_PCA_REGULAR, 2228 MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC, 2229 MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR, 2230 MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC 2231 } MatHtoolClusteringType; 2232 #endif 2233 2234 #ifdef PETSC_HAVE_MUMPS 2235 PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat, PetscInt, PetscInt); 2236 PETSC_EXTERN PetscErrorCode MatMumpsGetIcntl(Mat, PetscInt, PetscInt *); 2237 PETSC_EXTERN PetscErrorCode MatMumpsSetCntl(Mat, PetscInt, PetscReal); 2238 PETSC_EXTERN PetscErrorCode MatMumpsGetCntl(Mat, PetscInt, PetscReal *); 2239 2240 PETSC_EXTERN PetscErrorCode MatMumpsGetInfo(Mat, PetscInt, PetscInt *); 2241 PETSC_EXTERN PetscErrorCode MatMumpsGetInfog(Mat, PetscInt, PetscInt *); 2242 PETSC_EXTERN PetscErrorCode MatMumpsGetRinfo(Mat, PetscInt, PetscReal *); 2243 PETSC_EXTERN PetscErrorCode MatMumpsGetRinfog(Mat, PetscInt, PetscReal *); 2244 PETSC_EXTERN PetscErrorCode MatMumpsGetNullPivots(Mat, PetscInt *, PetscInt **); 2245 PETSC_EXTERN PetscErrorCode MatMumpsGetInverse(Mat, Mat); 2246 PETSC_EXTERN PetscErrorCode MatMumpsGetInverseTranspose(Mat, Mat); 2247 #endif 2248 2249 #ifdef PETSC_HAVE_MKL_PARDISO 2250 PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat, PetscInt, PetscInt); 2251 #endif 2252 2253 #ifdef PETSC_HAVE_MKL_CPARDISO 2254 PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat, PetscInt, PetscInt); 2255 #endif 2256 2257 #ifdef PETSC_HAVE_SUPERLU 2258 PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat, PetscReal); 2259 #endif 2260 2261 #ifdef PETSC_HAVE_SUPERLU_DIST 2262 PETSC_EXTERN PetscErrorCode MatSuperluDistGetDiagU(Mat, PetscScalar *); 2263 #endif 2264 2265 #ifdef PETSC_HAVE_STRUMPACK 2266 /*E 2267 MatSTRUMPACKReordering - sparsity reducing ordering to be used in `MATSOLVERSTRUMPACK` 2268 2269 Values: 2270 + `MAT_STRUMPACK_NATURAL` - use the current ordering 2271 . `MAT_STRUMPACK_METIS` - use MeTis to compute an ordering 2272 . `MAT_STRUMPACK_PARMETIS` - use ParMeTis to compute an ordering 2273 . `MAT_STRUMPACK_SCOTCH` - use Scotch to compute an ordering 2274 . `MAT_STRUMPACK_PTSCOTCH` - use parallel Scotch to compute an ordering 2275 . `MAT_STRUMPACK_RCM` - use an RCM ordering 2276 . `MAT_STRUMPACK_GEOMETRIC` - use a geometric ordering (needs mesh info from user) 2277 . `MAT_STRUMPACK_AMD` - approximate minimum degree 2278 . `MAT_STRUMPACK_MMD` - multiple minimum degree 2279 . `MAT_STRUMPACK_AND` - approximate nested dissection 2280 . `MAT_STRUMPACK_MLF` - minimum local fill 2281 - `MAT_STRUMPACK_SPECTRAL` - spectral nested dissection 2282 2283 Level: intermediate 2284 2285 Developer Note: 2286 Should be called `MatSTRUMPACKReorderingType` 2287 2288 .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetReordering()` 2289 E*/ 2290 typedef enum { 2291 MAT_STRUMPACK_NATURAL, 2292 MAT_STRUMPACK_METIS, 2293 MAT_STRUMPACK_PARMETIS, 2294 MAT_STRUMPACK_SCOTCH, 2295 MAT_STRUMPACK_PTSCOTCH, 2296 MAT_STRUMPACK_RCM, 2297 MAT_STRUMPACK_GEOMETRIC, 2298 MAT_STRUMPACK_AMD, 2299 MAT_STRUMPACK_MMD, 2300 MAT_STRUMPACK_AND, 2301 MAT_STRUMPACK_MLF, 2302 MAT_STRUMPACK_SPECTRAL 2303 } MatSTRUMPACKReordering; 2304 2305 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetReordering(Mat, MatSTRUMPACKReordering); 2306 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetReordering(Mat, MatSTRUMPACKReordering *); 2307 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricNxyz(Mat, PetscInt, PetscInt, PetscInt); 2308 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricComponents(Mat, PetscInt); 2309 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricWidth(Mat, PetscInt); 2310 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetColPerm(Mat, PetscBool); 2311 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetColPerm(Mat, PetscBool *); 2312 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGPU(Mat, PetscBool); 2313 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetGPU(Mat, PetscBool *); 2314 2315 /*E 2316 MatSTRUMPACKCompressionType - Compression used in the approximate sparse factorization solver `MATSOLVERSTRUMPACK` 2317 2318 Values: 2319 + `MAT_STRUMPACK_COMPRESSION_TYPE_NONE` - no compression, direct solver 2320 . `MAT_STRUMPACK_COMPRESSION_TYPE_HSS` - hierarchically semi-separable 2321 . `MAT_STRUMPACK_COMPRESSION_TYPE_BLR` - block low rank 2322 . `MAT_STRUMPACK_COMPRESSION_TYPE_HODLR` - hierarchically off-diagonal low rank (requires ButterfyPACK support, configure with --download-butterflypack) 2323 . `MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR` - hybrid of BLR and HODLR (requires ButterfyPACK support, configure with --download-butterflypack) 2324 . `MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR` - hybrid of lossy (ZFP), BLR and HODLR (requires ButterfyPACK and ZFP support, configure with --download-butterflypack --download-zfp) 2325 . `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS` - lossless compression (requires ZFP support, configure with --download-zfp) 2326 - `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY` - lossy compression (requires ZFP support, configure with --download-zfp) 2327 2328 Level: intermediate 2329 2330 .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompression()` 2331 E*/ 2332 typedef enum { 2333 MAT_STRUMPACK_COMPRESSION_TYPE_NONE, 2334 MAT_STRUMPACK_COMPRESSION_TYPE_HSS, 2335 MAT_STRUMPACK_COMPRESSION_TYPE_BLR, 2336 MAT_STRUMPACK_COMPRESSION_TYPE_HODLR, 2337 MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR, 2338 MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR, 2339 MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS, 2340 MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY 2341 } MatSTRUMPACKCompressionType; 2342 2343 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompression(Mat, MatSTRUMPACKCompressionType); 2344 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompression(Mat, MatSTRUMPACKCompressionType *); 2345 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompRelTol(Mat, PetscReal); 2346 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompRelTol(Mat, PetscReal *); 2347 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompAbsTol(Mat, PetscReal); 2348 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompAbsTol(Mat, PetscReal *); 2349 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompMinSepSize(Mat, PetscInt); 2350 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompMinSepSize(Mat, PetscInt *); 2351 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLeafSize(Mat, PetscInt); 2352 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLeafSize(Mat, PetscInt *); 2353 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLossyPrecision(Mat, PetscInt); 2354 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLossyPrecision(Mat, PetscInt *); 2355 PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompButterflyLevels(Mat, PetscInt); 2356 PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompButterflyLevels(Mat, PetscInt *); 2357 #endif 2358 2359 PETSC_EXTERN PetscErrorCode MatBindToCPU(Mat, PetscBool); 2360 PETSC_EXTERN PetscErrorCode MatBoundToCPU(Mat, PetscBool *); 2361 PETSC_DEPRECATED_FUNCTION(3, 13, 0, "MatBindToCPU()", ) static inline PetscErrorCode MatPinToCPU(Mat A, PetscBool flg) 2362 { 2363 return MatBindToCPU(A, flg); 2364 } 2365 PETSC_EXTERN PetscErrorCode MatSetBindingPropagates(Mat, PetscBool); 2366 PETSC_EXTERN PetscErrorCode MatGetBindingPropagates(Mat, PetscBool *); 2367 2368 #ifdef PETSC_HAVE_CUDA 2369 /*E 2370 MatCUSPARSEStorageFormat - indicates the storage format for `MATAIJCUSPARSE` (GPU) 2371 matrices. 2372 2373 Values: 2374 + `MAT_CUSPARSE_CSR` - Compressed Sparse Row 2375 . `MAT_CUSPARSE_ELL` - Ellpack (requires CUDA 4.2 or later). 2376 - `MAT_CUSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format (requires CUDA 4.2 or later). 2377 2378 Level: intermediate 2379 2380 .seealso: [](ch_matrices), `MATAIJCUSPARSE`, `MatCUSPARSESetFormat()`, `MatCUSPARSEFormatOperation` 2381 E*/ 2382 2383 typedef enum { 2384 MAT_CUSPARSE_CSR, 2385 MAT_CUSPARSE_ELL, 2386 MAT_CUSPARSE_HYB 2387 } MatCUSPARSEStorageFormat; 2388 2389 /* these will be strings associated with enumerated type defined above */ 2390 PETSC_EXTERN const char *const MatCUSPARSEStorageFormats[]; 2391 2392 /*E 2393 MatCUSPARSEFormatOperation - indicates the operation of `MATAIJCUSPARSE` (GPU) 2394 matrices whose operation should use a particular storage format. 2395 2396 Values: 2397 + `MAT_CUSPARSE_MULT_DIAG` - sets the storage format for the diagonal matrix in the parallel `MatMult()` 2398 . `MAT_CUSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()` 2399 . `MAT_CUSPARSE_MULT` - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()` 2400 - `MAT_CUSPARSE_ALL` - sets the storage format for all `MATAIJCUSPARSE` (GPU) matrices 2401 2402 Level: intermediate 2403 2404 .seealso: [](ch_matrices), `MatCUSPARSESetFormat()`, `MatCUSPARSEStorageFormat` 2405 E*/ 2406 typedef enum { 2407 MAT_CUSPARSE_MULT_DIAG, 2408 MAT_CUSPARSE_MULT_OFFDIAG, 2409 MAT_CUSPARSE_MULT, 2410 MAT_CUSPARSE_ALL 2411 } MatCUSPARSEFormatOperation; 2412 2413 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 2414 PETSC_EXTERN PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 2415 PETSC_EXTERN PetscErrorCode MatCUSPARSESetFormat(Mat, MatCUSPARSEFormatOperation, MatCUSPARSEStorageFormat); 2416 PETSC_EXTERN PetscErrorCode MatCUSPARSESetUseCPUSolve(Mat, PetscBool); 2417 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetIJ(Mat, PetscBool, const int **, const int **); 2418 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreIJ(Mat, PetscBool, const int **, const int **); 2419 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayRead(Mat, const PetscScalar **); 2420 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayRead(Mat, const PetscScalar **); 2421 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayWrite(Mat, PetscScalar **); 2422 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayWrite(Mat, PetscScalar **); 2423 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArray(Mat, PetscScalar **); 2424 PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArray(Mat, PetscScalar **); 2425 2426 PETSC_EXTERN PetscErrorCode MatCreateDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *); 2427 PETSC_EXTERN PetscErrorCode MatCreateSeqDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *); 2428 PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayWrite(Mat, PetscScalar **); 2429 PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayRead(Mat, const PetscScalar **); 2430 PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArray(Mat, PetscScalar **); 2431 PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayWrite(Mat, PetscScalar **); 2432 PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayRead(Mat, const PetscScalar **); 2433 PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArray(Mat, PetscScalar **); 2434 PETSC_EXTERN PetscErrorCode MatDenseCUDAPlaceArray(Mat, const PetscScalar *); 2435 PETSC_EXTERN PetscErrorCode MatDenseCUDAReplaceArray(Mat, const PetscScalar *); 2436 PETSC_EXTERN PetscErrorCode MatDenseCUDAResetArray(Mat); 2437 PETSC_EXTERN PetscErrorCode MatDenseCUDASetPreallocation(Mat, PetscScalar *); 2438 2439 PETSC_EXTERN PetscErrorCode MatCreateSeqSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 2440 PETSC_EXTERN PetscErrorCode MatCreateSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 2441 #endif 2442 2443 #ifdef PETSC_HAVE_HIP 2444 /*E 2445 MatHIPSPARSEStorageFormat - indicates the storage format for `MATAIJHIPSPARSE` (GPU) 2446 matrices. 2447 2448 Values: 2449 + `MAT_HIPSPARSE_CSR` - Compressed Sparse Row 2450 . `MAT_HIPSPARSE_ELL` - Ellpack 2451 - `MAT_HIPSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format 2452 2453 Level: intermediate 2454 2455 .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEFormatOperation` 2456 E*/ 2457 2458 typedef enum { 2459 MAT_HIPSPARSE_CSR, 2460 MAT_HIPSPARSE_ELL, 2461 MAT_HIPSPARSE_HYB 2462 } MatHIPSPARSEStorageFormat; 2463 2464 /* these will be strings associated with enumerated type defined above */ 2465 PETSC_EXTERN const char *const MatHIPSPARSEStorageFormats[]; 2466 2467 /*E 2468 MatHIPSPARSEFormatOperation - indicates the operation of `MATAIJHIPSPARSE` (GPU) 2469 matrices whose operation should use a particular storage format. 2470 2471 Values: 2472 + `MAT_HIPSPARSE_MULT_DIAG` - sets the storage format for the diagonal matrix in the parallel `MatMult()` 2473 . `MAT_HIPSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()` 2474 . `MAT_HIPSPARSE_MULT` - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()` 2475 - `MAT_HIPSPARSE_ALL` - sets the storage format for all HIPSPARSE (GPU) matrices 2476 2477 Level: intermediate 2478 2479 .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEStorageFormat` 2480 E*/ 2481 typedef enum { 2482 MAT_HIPSPARSE_MULT_DIAG, 2483 MAT_HIPSPARSE_MULT_OFFDIAG, 2484 MAT_HIPSPARSE_MULT, 2485 MAT_HIPSPARSE_ALL 2486 } MatHIPSPARSEFormatOperation; 2487 2488 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 2489 PETSC_EXTERN PetscErrorCode MatCreateAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 2490 PETSC_EXTERN PetscErrorCode MatHIPSPARSESetFormat(Mat, MatHIPSPARSEFormatOperation, MatHIPSPARSEStorageFormat); 2491 PETSC_EXTERN PetscErrorCode MatHIPSPARSESetUseCPUSolve(Mat, PetscBool); 2492 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetIJ(Mat, PetscBool, const int **, const int **); 2493 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreIJ(Mat, PetscBool, const int **, const int **); 2494 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayRead(Mat, const PetscScalar **); 2495 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayRead(Mat, const PetscScalar **); 2496 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayWrite(Mat, PetscScalar **); 2497 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayWrite(Mat, PetscScalar **); 2498 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArray(Mat, PetscScalar **); 2499 PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArray(Mat, PetscScalar **); 2500 2501 PETSC_EXTERN PetscErrorCode MatCreateDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *); 2502 PETSC_EXTERN PetscErrorCode MatCreateSeqDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *); 2503 PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayWrite(Mat, PetscScalar **); 2504 PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayRead(Mat, const PetscScalar **); 2505 PETSC_EXTERN PetscErrorCode MatDenseHIPGetArray(Mat, PetscScalar **); 2506 PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayWrite(Mat, PetscScalar **); 2507 PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayRead(Mat, const PetscScalar **); 2508 PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArray(Mat, PetscScalar **); 2509 PETSC_EXTERN PetscErrorCode MatDenseHIPPlaceArray(Mat, const PetscScalar *); 2510 PETSC_EXTERN PetscErrorCode MatDenseHIPReplaceArray(Mat, const PetscScalar *); 2511 PETSC_EXTERN PetscErrorCode MatDenseHIPResetArray(Mat); 2512 PETSC_EXTERN PetscErrorCode MatDenseHIPSetPreallocation(Mat, PetscScalar *); 2513 #endif 2514 2515 #if defined(PETSC_HAVE_VIENNACL) 2516 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 2517 PETSC_EXTERN PetscErrorCode MatCreateAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 2518 #endif 2519 2520 #if PetscDefined(HAVE_KOKKOS) 2521 PETSC_EXTERN PetscErrorCode MatCreateAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *); 2522 PETSC_EXTERN PetscErrorCode MatCreateSeqAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *); 2523 #endif 2524 2525 #if defined(PETSC_HAVE_FFTW) 2526 PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat, Vec, Vec); 2527 PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat, Vec, Vec); 2528 PETSC_EXTERN PetscErrorCode MatCreateVecsFFTW(Mat, Vec *, Vec *, Vec *); 2529 #endif 2530 2531 #if defined(PETSC_HAVE_SCALAPACK) 2532 PETSC_EXTERN PetscErrorCode MatCreateScaLAPACK(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *); 2533 PETSC_EXTERN PetscErrorCode MatScaLAPACKSetBlockSizes(Mat, PetscInt, PetscInt); 2534 PETSC_EXTERN PetscErrorCode MatScaLAPACKGetBlockSizes(Mat, PetscInt *, PetscInt *); 2535 #endif 2536 2537 PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm, PetscInt, const IS[], PetscInt, const IS[], const Mat[], Mat *); 2538 PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat, PetscInt *, PetscInt *); 2539 PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat, IS[], IS[]); 2540 PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat, IS[], IS[]); 2541 PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat, PetscInt *, PetscInt *, Mat ***); 2542 PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat, PetscInt, PetscInt, Mat *); 2543 PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat, VecType); 2544 PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat, PetscInt, const IS[], PetscInt, const IS[], const Mat[]); 2545 PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat, PetscInt, PetscInt, Mat); 2546 2547 PETSC_EXTERN PetscErrorCode MatFilter(Mat, PetscReal, PetscBool, PetscBool); 2548 PETSC_DEPRECATED_FUNCTION(3, 20, 0, "MatFilter()", ) static inline PetscErrorCode MatChop(Mat A, PetscReal tol) 2549 { 2550 return MatFilter(A, tol, PETSC_FALSE, PETSC_FALSE); 2551 } 2552 PETSC_EXTERN PetscErrorCode MatComputeBandwidth(Mat, PetscReal, PetscInt *); 2553 2554 PETSC_EXTERN PetscErrorCode MatSubdomainsCreateCoalesce(Mat, PetscInt, PetscInt *, IS **); 2555 2556 PETSC_EXTERN PetscErrorCode MatPreallocatorPreallocate(Mat, PetscBool, Mat); 2557 2558 PETSC_EXTERN PetscErrorCode MatHeaderMerge(Mat, Mat *); 2559 PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat, Mat *); 2560 2561 PETSC_EXTERN PetscErrorCode MatSeqAIJGetCSRAndMemType(Mat, const PetscInt **, const PetscInt **, PetscScalar **, PetscMemType *); 2562 2563 PETSC_EXTERN PetscErrorCode MatCreateGraph(Mat, PetscBool, PetscBool, PetscReal, PetscInt, PetscInt[], Mat *); 2564 PETSC_EXTERN PetscErrorCode MatEliminateZeros(Mat, PetscBool); 2565 2566 PETSC_EXTERN PetscErrorCode MatCreateDenseFromVecType(MPI_Comm, VecType, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar *, Mat *); 2567 2568 PETSC_EXTERN PetscErrorCode MatSetHPL(Mat, int); 2569 #define PETSCBMHPL "hpl" 2570