Actual source code: petscmat.h

  1: /*
  2:      Include file for the matrix component of PETSc
  3: */
  4: #pragma once

  6: #include <petscvec.h>

  8: /* SUBMANSEC = Mat */

 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()`

 15:    Level: beginner

 17:    Note:
 18:    See [](doc_matrix), [](ch_matrices) and `MatType` for available matrix types

 20: .seealso: [](doc_matrix), [](ch_matrices), `MatCreate()`, `MatType`, `MatSetType()`, `MatDestroy()`
 21: S*/
 22: typedef struct _p_Mat *Mat;

 24: /*J
 25:    MatType - String with the name of a PETSc matrix type. These are all the matrix formats that PETSc provides.

 27:    Level: beginner

 29:    Notes:
 30:    [](doc_matrix) for a table of available matrix types

 32:    Use `MatSetType()` or the options database keys `-mat_type` or `-dm_mat_type` to set the matrix format to use for a given `Mat`

 34: .seealso: [](doc_matrix), [](ch_matrices), `MatSetType()`, `Mat`, `MatSolverType`, `MatRegister()`
 35: J*/
 36: typedef const char *MatType;
 37: #define MATSAME                      "same"
 38: #define MATMAIJ                      "maij"
 39: #define MATSEQMAIJ                   "seqmaij"
 40: #define MATMPIMAIJ                   "mpimaij"
 41: #define MATKAIJ                      "kaij"
 42: #define MATSEQKAIJ                   "seqkaij"
 43: #define MATMPIKAIJ                   "mpikaij"
 44: #define MATIS                        "is"
 45: #define MATAIJ                       "aij"
 46: #define MATSEQAIJ                    "seqaij"
 47: #define MATMPIAIJ                    "mpiaij"
 48: #define MATAIJCRL                    "aijcrl"
 49: #define MATSEQAIJCRL                 "seqaijcrl"
 50: #define MATMPIAIJCRL                 "mpiaijcrl"
 51: #define MATAIJCUSPARSE               "aijcusparse"
 52: #define MATSEQAIJCUSPARSE            "seqaijcusparse"
 53: #define MATMPIAIJCUSPARSE            "mpiaijcusparse"
 54: #define MATAIJHIPSPARSE              "aijhipsparse"
 55: #define MATSEQAIJHIPSPARSE           "seqaijhipsparse"
 56: #define MATMPIAIJHIPSPARSE           "mpiaijhipsparse"
 57: #define MATAIJKOKKOS                 "aijkokkos"
 58: #define MATSEQAIJKOKKOS              "seqaijkokkos"
 59: #define MATMPIAIJKOKKOS              "mpiaijkokkos"
 60: #define MATAIJVIENNACL               "aijviennacl"
 61: #define MATSEQAIJVIENNACL            "seqaijviennacl"
 62: #define MATMPIAIJVIENNACL            "mpiaijviennacl"
 63: #define MATAIJPERM                   "aijperm"
 64: #define MATSEQAIJPERM                "seqaijperm"
 65: #define MATMPIAIJPERM                "mpiaijperm"
 66: #define MATAIJSELL                   "aijsell"
 67: #define MATSEQAIJSELL                "seqaijsell"
 68: #define MATMPIAIJSELL                "mpiaijsell"
 69: #define MATAIJMKL                    "aijmkl"
 70: #define MATSEQAIJMKL                 "seqaijmkl"
 71: #define MATMPIAIJMKL                 "mpiaijmkl"
 72: #define MATBAIJMKL                   "baijmkl"
 73: #define MATSEQBAIJMKL                "seqbaijmkl"
 74: #define MATMPIBAIJMKL                "mpibaijmkl"
 75: #define MATSHELL                     "shell"
 76: #define MATCENTERING                 "centering"
 77: #define MATDENSE                     "dense"
 78: #define MATDENSECUDA                 "densecuda"
 79: #define MATDENSEHIP                  "densehip"
 80: #define MATSEQDENSE                  "seqdense"
 81: #define MATSEQDENSECUDA              "seqdensecuda"
 82: #define MATSEQDENSEHIP               "seqdensehip"
 83: #define MATMPIDENSE                  "mpidense"
 84: #define MATMPIDENSECUDA              "mpidensecuda"
 85: #define MATMPIDENSEHIP               "mpidensehip"
 86: #define MATELEMENTAL                 "elemental"
 87: #define MATSCALAPACK                 "scalapack"
 88: #define MATBAIJ                      "baij"
 89: #define MATSEQBAIJ                   "seqbaij"
 90: #define MATMPIBAIJ                   "mpibaij"
 91: #define MATMPIADJ                    "mpiadj"
 92: #define MATSBAIJ                     "sbaij"
 93: #define MATSEQSBAIJ                  "seqsbaij"
 94: #define MATMPISBAIJ                  "mpisbaij"
 95: #define MATMFFD                      "mffd"
 96: #define MATNORMAL                    "normal"
 97: #define MATNORMALHERMITIAN           "normalh"
 98: #define MATLRC                       "lrc"
 99: #define MATSCATTER                   "scatter"
100: #define MATBLOCKMAT                  "blockmat"
101: #define MATCOMPOSITE                 "composite"
102: #define MATFFT                       "fft"
103: #define MATFFTW                      "fftw"
104: #define MATSEQCUFFT                  "seqcufft"
105: #define MATSEQHIPFFT                 "seqhipfft"
106: #define MATTRANSPOSEMAT              PETSC_DEPRECATED_MACRO(3, 18, 0, "MATTRANSPOSEVIRTUAL", ) "transpose"
107: #define MATTRANSPOSEVIRTUAL          "transpose"
108: #define MATHERMITIANTRANSPOSEVIRTUAL "hermitiantranspose"
109: #define MATSCHURCOMPLEMENT           "schurcomplement"
110: #define MATPYTHON                    "python"
111: #define MATHYPRE                     "hypre"
112: #define MATHYPRESTRUCT               "hyprestruct"
113: #define MATHYPRESSTRUCT              "hypresstruct"
114: #define MATSUBMATRIX                 "submatrix"
115: #define MATLOCALREF                  "localref"
116: #define MATNEST                      "nest"
117: #define MATPREALLOCATOR              "preallocator"
118: #define MATSELL                      "sell"
119: #define MATSEQSELL                   "seqsell"
120: #define MATMPISELL                   "mpisell"
121: #define MATSELLCUDA                  "sellcuda"
122: #define MATSEQSELLCUDA               "seqsellcuda"
123: #define MATMPISELLCUDA               "mpisellcuda"
124: #define MATSELLHIP                   "sellhip"
125: #define MATSEQSELLHIP                "seqsellhip"
126: #define MATMPISELLHIP                "mpisellhip"
127: #define MATDUMMY                     "dummy"
128: #define MATLMVM                      "lmvm"
129: #define MATLMVMDFP                   "lmvmdfp"
130: #define MATLMVMDDFP                  "lmvmddfp"
131: #define MATLMVMBFGS                  "lmvmbfgs"
132: #define MATLMVMDBFGS                 "lmvmdbfgs"
133: #define MATLMVMDQN                   "lmvmdqn"
134: #define MATLMVMSR1                   "lmvmsr1"
135: #define MATLMVMBROYDEN               "lmvmbroyden"
136: #define MATLMVMBADBROYDEN            "lmvmbadbroyden"
137: #define MATLMVMSYMBROYDEN            "lmvmsymbroyden"
138: #define MATLMVMSYMBADBROYDEN         "lmvmsymbadbroyden"
139: #define MATLMVMDIAGBROYDEN           "lmvmdiagbroyden"
140: #define MATCONSTANTDIAGONAL          "constantdiagonal"
141: #define MATDIAGONAL                  "diagonal"
142: #define MATHTOOL                     "htool"
143: #define MATH2OPUS                    "h2opus"

145: /*J
146:    MatSolverType - String with the name of a PETSc factorization-based matrix solver type.

148:    For example: "petsc" indicates what PETSc provides, "superlu_dist" the parallel SuperLU_DIST package etc

150:    Level: beginner

152:    Note:
153:    `MATSOLVERUMFPACK`, `MATSOLVERCHOLMOD`, `MATSOLVERKLU`, `MATSOLVERSPQR` form the SuiteSparse package; you can use `--download-suitesparse` as
154:    a ./configure option to install them

156: .seealso: [](sec_matfactor), [](ch_matrices), `MatGetFactor()`, `PCFactorSetMatSolverType()`, `PCFactorGetMatSolverType()`
157: J*/
158: typedef const char *MatSolverType;
159: #define MATSOLVERSUPERLU      "superlu"
160: #define MATSOLVERSUPERLU_DIST "superlu_dist"
161: #define MATSOLVERSTRUMPACK    "strumpack"
162: #define MATSOLVERUMFPACK      "umfpack"
163: #define MATSOLVERCHOLMOD      "cholmod"
164: #define MATSOLVERKLU          "klu"
165: #define MATSOLVERELEMENTAL    "elemental"
166: #define MATSOLVERSCALAPACK    "scalapack"
167: #define MATSOLVERESSL         "essl"
168: #define MATSOLVERLUSOL        "lusol"
169: #define MATSOLVERMUMPS        "mumps"
170: #define MATSOLVERMKL_PARDISO  "mkl_pardiso"
171: #define MATSOLVERMKL_CPARDISO "mkl_cpardiso"
172: #define MATSOLVERPASTIX       "pastix"
173: #define MATSOLVERMATLAB       "matlab"
174: #define MATSOLVERPETSC        "petsc"
175: #define MATSOLVERBAS          "bas"
176: #define MATSOLVERCUSPARSE     "cusparse"
177: #define MATSOLVERCUDA         "cuda"
178: #define MATSOLVERHIPSPARSE    "hipsparse"
179: #define MATSOLVERHIP          "hip"
180: #define MATSOLVERKOKKOS       "kokkos"
181: #define MATSOLVERSPQR         "spqr"
182: #define MATSOLVERHTOOL        "htool"

184: /*E
185:     MatFactorType - indicates what type of factorization is requested

187:     Values:
188: +  `MAT_FACTOR_LU`       - LU factorization
189: .  `MAT_FACTOR_CHOLESKY` - Cholesky factorization
190: .  `MAT_FACTOR_ILU`      - ILU factorization
191: .  `MAT_FACTOR_ICC`      - incomplete Cholesky factorization
192: .  `MAT_FACTOR_ILUDT`    - ILU factorization with drop tolerance
193: -  `MAT_FACTOR_QR`       - QR factorization

195:     Level: beginner

197: .seealso: [](ch_matrices), `MatSolverType`, `MatGetFactor()`, `MatGetFactorAvailable()`, `MatSolverTypeRegister()`
198: E*/
199: typedef enum {
200:   MAT_FACTOR_NONE,
201:   MAT_FACTOR_LU,
202:   MAT_FACTOR_CHOLESKY,
203:   MAT_FACTOR_ILU,
204:   MAT_FACTOR_ICC,
205:   MAT_FACTOR_ILUDT,
206:   MAT_FACTOR_QR,
207:   MAT_FACTOR_NUM_TYPES
208: } MatFactorType;
209: PETSC_EXTERN const char *const MatFactorTypes[];

211: PETSC_EXTERN PetscErrorCode MatGetFactor(Mat, MatSolverType, MatFactorType, Mat *);
212: PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat, MatSolverType, MatFactorType, PetscBool *);
213: PETSC_EXTERN PetscErrorCode MatFactorGetCanUseOrdering(Mat, PetscBool *);
214: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "MatFactorGetCanUseOrdering()", ) static inline PetscErrorCode MatFactorGetUseOrdering(Mat A, PetscBool *b)
215: {
216:   return MatFactorGetCanUseOrdering(A, b);
217: }
218: PETSC_EXTERN PetscErrorCode MatFactorGetSolverType(Mat, MatSolverType *);
219: PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat, MatFactorType *);
220: PETSC_EXTERN PetscErrorCode MatSetFactorType(Mat, MatFactorType);
221: /*S
222:   MatSolverFn - Function type for the factor-creation callback registered with `MatSolverTypeRegister()`, used by `MatGetFactor()` to allocate a factored matrix of a particular `MatSolverType` and `MatFactorType`

224:   Synopsis:
225: #include <petscmat.h>
226:   PetscErrorCode MatSolverFn(Mat A, MatFactorType ftype, Mat *F)

228:   Calling Sequence:
229: + A     - the matrix to be factored
230: . ftype - the kind of factorization requested (e.g. `MAT_FACTOR_LU`, `MAT_FACTOR_CHOLESKY`)
231: - F     - on output, the newly created factor `Mat` of the appropriate `MatType` for the solver

233:   Level: developer

235: .seealso: `Mat`, `MatGetFactor()`, `MatSolverType`, `MatFactorType`, `MatSolverTypeRegister()`, `MatSolverTypeGet()`
236: S*/
237: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatSolverFn(Mat, MatFactorType, Mat *);
238: PETSC_EXTERN_TYPEDEF typedef MatSolverFn   *MatSolverFunction;

240: PETSC_EXTERN PetscErrorCode MatSolverTypeRegister(MatSolverType, MatType, MatFactorType, MatSolverFn *);
241: PETSC_EXTERN PetscErrorCode MatSolverTypeGet(MatSolverType, MatType, MatFactorType, PetscBool *, PetscBool *, MatSolverFn **);
242: typedef MatSolverType       MatSolverPackage PETSC_DEPRECATED_TYPEDEF(3, 9, 0, "MatSolverType", );
243: PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeRegister()", ) static inline PetscErrorCode MatSolverPackageRegister(MatSolverType stype, MatType mtype, MatFactorType ftype, MatSolverFn *f)
244: {
245:   return MatSolverTypeRegister(stype, mtype, ftype, f);
246: }
247: PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeGet()", ) static inline PetscErrorCode MatSolverPackageGet(MatSolverType stype, MatType mtype, MatFactorType ftype, PetscBool *foundmtype, PetscBool *foundstype, MatSolverFn **f)
248: {
249:   return MatSolverTypeGet(stype, mtype, ftype, foundmtype, foundstype, f);
250: }

252: /*E
253:     MatProductType - indicates what type of matrix product to compute

255:     Values:
256: +  `MATPRODUCT_AB`   - product of two matrices
257: .  `MATPRODUCT_AtB`  - product of the transpose of a given matrix with a matrix
258: .  `MATPRODUCT_ABt`  - product of a matrix with the transpose of another given matrix
259: .  `MATPRODUCT_PtAP` - the triple product of the transpose of a matrix with another matrix and itself
260: .  `MATPRODUCT_RARt` - the triple product of a matrix, another matrix and the transpose of the first matrix
261: -  `MATPRODUCT_ABC`  - the product of three matrices

263:     Level: beginner

265: .seealso: [](sec_matmatproduct), [](ch_matrices), `MatProductSetType()`
266: E*/
267: typedef enum {
268:   MATPRODUCT_UNSPECIFIED,
269:   MATPRODUCT_AB,
270:   MATPRODUCT_AtB,
271:   MATPRODUCT_ABt,
272:   MATPRODUCT_PtAP,
273:   MATPRODUCT_RARt,
274:   MATPRODUCT_ABC
275: } MatProductType;
276: PETSC_EXTERN const char *const MatProductTypes[];

278: /*J
279:     MatProductAlgorithm - String with the name of an algorithm for a PETSc matrix product implementation

281:    Level: beginner

283: .seealso: [](sec_matmatproduct), [](ch_matrices), `MatSetType()`, `Mat`, `MatProductSetAlgorithm()`, `MatProductType`
284: J*/
285: typedef const char *MatProductAlgorithm;
286: #define MATPRODUCTALGORITHMDEFAULT         "default"
287: #define MATPRODUCTALGORITHMSORTED          "sorted"
288: #define MATPRODUCTALGORITHMSCALABLE        "scalable"
289: #define MATPRODUCTALGORITHMSCALABLEFAST    "scalable_fast"
290: #define MATPRODUCTALGORITHMHEAP            "heap"
291: #define MATPRODUCTALGORITHMBHEAP           "btheap"
292: #define MATPRODUCTALGORITHMLLCONDENSED     "llcondensed"
293: #define MATPRODUCTALGORITHMROWMERGE        "rowmerge"
294: #define MATPRODUCTALGORITHMOUTERPRODUCT    "outerproduct"
295: #define MATPRODUCTALGORITHMATB             "at*b"
296: #define MATPRODUCTALGORITHMRAP             "rap"
297: #define MATPRODUCTALGORITHMNONSCALABLE     "nonscalable"
298: #define MATPRODUCTALGORITHMSEQMPI          "seqmpi"
299: #define MATPRODUCTALGORITHMBACKEND         "backend"
300: #define MATPRODUCTALGORITHMOVERLAPPING     "overlapping"
301: #define MATPRODUCTALGORITHMMERGED          "merged"
302: #define MATPRODUCTALGORITHMALLATONCE       "allatonce"
303: #define MATPRODUCTALGORITHMALLATONCEMERGED "allatonce_merged"
304: #define MATPRODUCTALGORITHMALLGATHERV      "allgatherv"
305: #define MATPRODUCTALGORITHMCYCLIC          "cyclic"
306: #define MATPRODUCTALGORITHMHYPRE           "hypre"

308: PETSC_EXTERN PetscErrorCode MatProductCreate(Mat, Mat, Mat, Mat *);
309: PETSC_EXTERN PetscErrorCode MatProductCreateWithMat(Mat, Mat, Mat, Mat);
310: PETSC_EXTERN PetscErrorCode MatProductSetType(Mat, MatProductType);
311: PETSC_EXTERN PetscErrorCode MatProductSetAlgorithm(Mat, MatProductAlgorithm);
312: PETSC_EXTERN PetscErrorCode MatProductGetAlgorithm(Mat, MatProductAlgorithm *);
313: PETSC_EXTERN PetscErrorCode MatProductSetFill(Mat, PetscReal);
314: PETSC_EXTERN PetscErrorCode MatProductSetFromOptions(Mat);
315: PETSC_EXTERN PetscErrorCode MatProductSymbolic(Mat);
316: PETSC_EXTERN PetscErrorCode MatProductNumeric(Mat);
317: PETSC_EXTERN PetscErrorCode MatProductReplaceMats(Mat, Mat, Mat, Mat);
318: PETSC_EXTERN PetscErrorCode MatProductClear(Mat);
319: PETSC_EXTERN PetscErrorCode MatProductView(Mat, PetscViewer);
320: PETSC_EXTERN PetscErrorCode MatProductGetType(Mat, MatProductType *);
321: PETSC_EXTERN PetscErrorCode MatProductGetMats(Mat, Mat *, Mat *, Mat *);

323: /* Logging support */
324: #define MAT_FILE_CLASSID 1211216 /* used to indicate matrices in binary files */
325: PETSC_EXTERN PetscClassId MAT_CLASSID;
326: PETSC_EXTERN PetscClassId MAT_COLORING_CLASSID;
327: PETSC_EXTERN PetscClassId MAT_FDCOLORING_CLASSID;
328: PETSC_EXTERN PetscClassId MAT_TRANSPOSECOLORING_CLASSID;
329: PETSC_EXTERN PetscClassId MAT_PARTITIONING_CLASSID;
330: PETSC_EXTERN PetscClassId MAT_COARSEN_CLASSID;
331: PETSC_EXTERN PetscClassId MAT_NULLSPACE_CLASSID;
332: PETSC_EXTERN PetscClassId MATMFFD_CLASSID;

334: /*E
335:    MatReuse - Indicates if matrices obtained from a previous call to `MatCreateSubMatrices()`, `MatCreateSubMatrix()`, `MatConvert()` or several other functions
336:    are to be reused to store the new matrix values.

338:    Values:
339: +  `MAT_INITIAL_MATRIX` - create a new matrix
340: .  `MAT_REUSE_MATRIX`   - reuse the matrix created with a previous call that used `MAT_INITIAL_MATRIX`
341: .  `MAT_INPLACE_MATRIX` - replace the first input matrix with the new matrix (not applicable to all functions)
342: -  `MAT_IGNORE_MATRIX`  - do not create a new matrix or reuse a given matrix, just ignore that matrix argument (not applicable to all functions)

344:     Level: beginner

346: .seealso: [](ch_matrices), `Mat`, `MatCreateSubMatrices()`, `MatCreateSubMatrix()`, `MatDestroyMatrices()`, `MatConvert()`
347: E*/
348: typedef enum {
349:   MAT_INITIAL_MATRIX,
350:   MAT_REUSE_MATRIX,
351:   MAT_IGNORE_MATRIX,
352:   MAT_INPLACE_MATRIX
353: } MatReuse;

355: /*E
356:     MatCreateSubMatrixOption - Indicates if matrices obtained from a call to `MatCreateSubMatrices()`
357:     include the matrix values. Currently it is only used by `MatGetSeqNonzeroStructure()`.

359:     Values:
360: +  `MAT_DO_NOT_GET_VALUES` - do not copy the matrix values
361: -  `MAT_GET_VALUES`        - copy the matrix values

363:     Level: developer

365:     Developer Note:
366:     Why is not just a boolean used for this information?

368: .seealso: [](ch_matrices), `Mat`, `MatDuplicateOption`, `PetscCopyMode`, `MatGetSeqNonzeroStructure()`
369: E*/
370: typedef enum {
371:   MAT_DO_NOT_GET_VALUES,
372:   MAT_GET_VALUES
373: } MatCreateSubMatrixOption;

375: PETSC_EXTERN PetscErrorCode MatInitializePackage(void);
376: PETSC_EXTERN PetscErrorCode MatFinalizePackage(void);

378: PETSC_EXTERN PetscErrorCode MatCreate(MPI_Comm, Mat *);
379: PETSC_EXTERN PetscErrorCode MatCreateFromOptions(MPI_Comm, const char *, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
380: PETSC_EXTERN PetscErrorCode MatSetSizes(Mat, PetscInt, PetscInt, PetscInt, PetscInt);
381: PETSC_EXTERN PetscErrorCode MatSetType(Mat, MatType);
382: PETSC_EXTERN PetscErrorCode MatGetVecType(Mat, VecType *);
383: PETSC_EXTERN PetscErrorCode MatSetVecType(Mat, VecType);
384: PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat);
385: PETSC_EXTERN PetscErrorCode MatViewFromOptions(Mat, PetscObject, const char[]);
386: PETSC_EXTERN PetscErrorCode MatRegister(const char[], PetscErrorCode (*)(Mat));
387: PETSC_EXTERN PetscErrorCode MatRegisterRootName(const char[], const char[], const char[]);
388: PETSC_EXTERN PetscErrorCode MatSetOptionsPrefix(Mat, const char[]);
389: PETSC_EXTERN PetscErrorCode MatSetOptionsPrefixFactor(Mat, const char[]);
390: PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefixFactor(Mat, const char[]);
391: PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefix(Mat, const char[]);
392: PETSC_EXTERN PetscErrorCode MatGetOptionsPrefix(Mat, const char *[]);
393: PETSC_EXTERN PetscErrorCode MatGetState(Mat, PetscObjectState *);
394: PETSC_EXTERN PetscErrorCode MatSetErrorIfFailure(Mat, PetscBool);

396: PETSC_EXTERN PetscFunctionList MatList;
397: PETSC_EXTERN PetscFunctionList MatColoringList;
398: PETSC_EXTERN PetscFunctionList MatPartitioningList;
399: PETSC_EXTERN PetscFunctionList MatMeshToCellGraphList;

401: /*E
402:    MatStructure - Indicates if two matrices have the same nonzero structure

404:    Values:
405: +  `SAME_NONZERO_PATTERN`      - the two matrices have identical nonzero patterns
406: .  `DIFFERENT_NONZERO_PATTERN` - the two matrices may have different nonzero patterns
407: .  `SUBSET_NONZERO_PATTERN`    - the nonzero pattern of the second matrix is a subset of the nonzero pattern of the first matrix
408: -  `UNKNOWN_NONZERO_PATTERN`   - there is no known relationship between the nonzero patterns. In this case the implementations
409:                                  may try to detect a relationship to optimize the operation

411:    Level: beginner

413:    Note:
414:    Certain matrix operations (such as `MatAXPY()`) can run much faster if the sparsity pattern of the matrices are the same. But actually determining if
415:    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
416:    to certain PETSc routines.

418: .seealso: [](ch_matrices), `Mat`, `MatCopy()`, `MatAXPY()`, `MatAYPX()`
419: E*/
420: typedef enum {
421:   DIFFERENT_NONZERO_PATTERN,
422:   SUBSET_NONZERO_PATTERN,
423:   SAME_NONZERO_PATTERN,
424:   UNKNOWN_NONZERO_PATTERN
425: } MatStructure;
426: PETSC_EXTERN const char *const MatStructures[];

428: #if defined(PETSC_HAVE_MKL_SPARSE)
429: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
430: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
431: PETSC_EXTERN PetscErrorCode MatCreateBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
432: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
433: #endif

435: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJPERM(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
436: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJPERM(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);

438: PETSC_EXTERN PetscErrorCode MatCreateSeqSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
439: PETSC_EXTERN PetscErrorCode MatCreateSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
440: PETSC_EXTERN PetscErrorCode MatSeqSELLSetPreallocation(Mat, PetscInt, const PetscInt[]);
441: PETSC_EXTERN PetscErrorCode MatMPISELLSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
442: PETSC_EXTERN PetscErrorCode MatSeqSELLGetFillRatio(Mat, PetscReal *);
443: PETSC_EXTERN PetscErrorCode MatSeqSELLGetMaxSliceWidth(Mat, PetscInt *);
444: PETSC_EXTERN PetscErrorCode MatSeqSELLGetAvgSliceWidth(Mat, PetscReal *);
445: PETSC_EXTERN PetscErrorCode MatSeqSELLSetSliceHeight(Mat, PetscInt);
446: PETSC_EXTERN PetscErrorCode MatSeqSELLGetVarSliceSize(Mat, PetscReal *);

448: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
449: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
450: PETSC_EXTERN PetscErrorCode MatMPISELLGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *);
451: PETSC_EXTERN PetscErrorCode MatMPISELLGetSeqSELL(Mat, Mat *, Mat *, const PetscInt *[]);

453: PETSC_EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
454: PETSC_EXTERN PetscErrorCode MatCreateDense(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
455: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
456: PETSC_EXTERN PetscErrorCode MatCreateAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
457: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);
458: PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArrays(Mat, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
459: PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArray(Mat, const PetscScalar[]);
460: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSplitArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], PetscInt[], PetscInt[], PetscScalar[], Mat *);
461: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSeqAIJ(MPI_Comm, PetscInt, PetscInt, Mat, Mat, PetscInt *, Mat *);

463: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
464: PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
465: PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);

467: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOO(Mat, PetscCount, PetscInt[], PetscInt[]);
468: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOOLocal(Mat, PetscCount, PetscInt[], PetscInt[]);
469: PETSC_EXTERN PetscErrorCode MatSetValuesCOO(Mat, const PetscScalar[], InsertMode);

471: PETSC_EXTERN PetscErrorCode MatCreateMPIAdj(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscInt[], Mat *);
472: PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);

474: PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
475: PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);
476: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
477: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
478: PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscInt[], const PetscInt[]);

480: PETSC_EXTERN PetscErrorCode MatCreateShell(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscCtx, Mat *);
481: PETSC_EXTERN PetscErrorCode MatCreateCentering(MPI_Comm, PetscInt, PetscInt, Mat *);
482: PETSC_EXTERN PetscErrorCode MatCreateNormal(Mat, Mat *);
483: PETSC_EXTERN PetscErrorCode MatCreateNormalHermitian(Mat, Mat *);
484: PETSC_EXTERN PetscErrorCode MatCreateLRC(Mat, Mat, Vec, Mat, Mat *);
485: PETSC_EXTERN PetscErrorCode MatLRCGetMats(Mat, Mat *, Mat *, Vec *, Mat *);
486: PETSC_EXTERN PetscErrorCode MatLRCSetMats(Mat, Mat, Mat, Vec, Mat);
487: PETSC_EXTERN PetscErrorCode MatCreateIS(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, ISLocalToGlobalMapping, ISLocalToGlobalMapping, Mat *);
488: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
489: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);

491: PETSC_EXTERN PetscErrorCode MatCreateScatter(MPI_Comm, VecScatter, Mat *);
492: PETSC_EXTERN PetscErrorCode MatScatterSetVecScatter(Mat, VecScatter);
493: PETSC_EXTERN PetscErrorCode MatScatterGetVecScatter(Mat, VecScatter *);
494: PETSC_EXTERN PetscErrorCode MatCreateBlockMat(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt *, Mat *);
495: PETSC_EXTERN PetscErrorCode MatCompositeAddMat(Mat, Mat);
496: PETSC_EXTERN PetscErrorCode MatCompositeMerge(Mat);
497: /*E
498:    MatCompositeMergeType - Selects the order in which the matrices held by a `MATCOMPOSITE` are combined when `MatCompositeMerge()` is called

500:    Values:
501: +   `MAT_COMPOSITE_MERGE_RIGHT` - merge into a single matrix starting from the rightmost matrix (multiplicative compositions use this to preserve the natural left-to-right application order)
502: -   `MAT_COMPOSITE_MERGE_LEFT`  - merge into a single matrix starting from the leftmost matrix

504:    Level: advanced

506: .seealso: [](ch_matrices), `Mat`, `MATCOMPOSITE`, `MatCompositeMerge()`, `MatCompositeSetMergeType()`, `MatCompositeType`
507: E*/
508: typedef enum {
509:   MAT_COMPOSITE_MERGE_RIGHT,
510:   MAT_COMPOSITE_MERGE_LEFT
511: } MatCompositeMergeType;
512: PETSC_EXTERN PetscErrorCode MatCompositeSetMergeType(Mat, MatCompositeMergeType);
513: PETSC_EXTERN PetscErrorCode MatCreateComposite(MPI_Comm, PetscInt, const Mat *, Mat *);
514: /*E
515:     MatCompositeType - indicates what type of `MATCOMPOSITE` is used

517:     Values:
518: +  `MAT_COMPOSITE_ADDITIVE`       - sum of matrices (default)
519: -  `MAT_COMPOSITE_MULTIPLICATIVE` - product of matrices

521:     Level: beginner

523: .seealso: [](ch_matrices), `MATCOMPOSITE`, `MatCompositeSetType()`, `MatCompositeGetType()`
524: E*/
525: typedef enum {
526:   MAT_COMPOSITE_ADDITIVE,
527:   MAT_COMPOSITE_MULTIPLICATIVE
528: } MatCompositeType;
529: PETSC_EXTERN PetscErrorCode MatCompositeSetType(Mat, MatCompositeType);
530: PETSC_EXTERN PetscErrorCode MatCompositeGetType(Mat, MatCompositeType *);
531: PETSC_EXTERN PetscErrorCode MatCompositeSetMatStructure(Mat, MatStructure);
532: PETSC_EXTERN PetscErrorCode MatCompositeGetMatStructure(Mat, MatStructure *);
533: PETSC_EXTERN PetscErrorCode MatCompositeGetNumberMat(Mat, PetscInt *);
534: PETSC_EXTERN PetscErrorCode MatCompositeGetMat(Mat, PetscInt, Mat *);
535: PETSC_EXTERN PetscErrorCode MatCompositeSetScalings(Mat, const PetscScalar *);

537: PETSC_EXTERN PetscErrorCode MatCreateFFT(MPI_Comm, PetscInt, const PetscInt[], MatType, Mat *);
538: PETSC_EXTERN PetscErrorCode MatCreateSeqCUFFT(MPI_Comm, PetscInt, const PetscInt[], Mat *);

540: PETSC_EXTERN PetscErrorCode MatCreateTranspose(Mat, Mat *);
541: PETSC_EXTERN PetscErrorCode MatTransposeGetMat(Mat, Mat *);
542: PETSC_EXTERN PetscErrorCode MatCreateHermitianTranspose(Mat, Mat *);
543: PETSC_EXTERN PetscErrorCode MatHermitianTransposeGetMat(Mat, Mat *);
544: PETSC_EXTERN PetscErrorCode MatNormalGetMat(Mat, Mat *);
545: PETSC_EXTERN PetscErrorCode MatNormalHermitianGetMat(Mat, Mat *);
546: PETSC_EXTERN PetscErrorCode MatCreateSubMatrixVirtual(Mat, IS, IS, Mat *);
547: PETSC_EXTERN PetscErrorCode MatSubMatrixVirtualUpdate(Mat, Mat, IS, IS);
548: PETSC_EXTERN PetscErrorCode MatCreateLocalRef(Mat, IS, IS, Mat *);
549: PETSC_EXTERN PetscErrorCode MatCreateConstantDiagonal(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar, Mat *);
550: PETSC_EXTERN PetscErrorCode MatCreateDiagonal(Vec, Mat *);
551: PETSC_EXTERN PetscErrorCode MatDiagonalSetDiagonal(Mat, Vec);
552: PETSC_EXTERN PetscErrorCode MatDiagonalGetDiagonal(Mat, Vec *);
553: PETSC_EXTERN PetscErrorCode MatDiagonalRestoreDiagonal(Mat, Vec *);
554: PETSC_EXTERN PetscErrorCode MatDiagonalGetInverseDiagonal(Mat, Vec *);
555: PETSC_EXTERN PetscErrorCode MatDiagonalRestoreInverseDiagonal(Mat, Vec *);
556: PETSC_EXTERN PetscErrorCode MatConstantDiagonalGetConstant(Mat, PetscScalar *);
557: PETSC_EXTERN PetscErrorCode MatGetCurrentMemType(Mat, PetscMemType *);

559: #if defined(PETSC_HAVE_HYPRE)
560: PETSC_EXTERN PetscErrorCode MatHYPRESetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
561: #endif

563: PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat, const char[]);
564: PETSC_EXTERN PetscErrorCode MatPythonGetType(Mat, const char *[]);
565: PETSC_EXTERN PetscErrorCode MatPythonCreate(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const char[], Mat *);

567: PETSC_EXTERN PetscErrorCode MatResetPreallocation(Mat);
568: PETSC_EXTERN PetscErrorCode MatResetHash(Mat);
569: PETSC_EXTERN PetscErrorCode MatSetUp(Mat);
570: PETSC_EXTERN PetscErrorCode MatDestroy(Mat *);
571: PETSC_EXTERN PetscErrorCode MatGetNonzeroState(Mat, PetscObjectState *);

573: PETSC_EXTERN PetscErrorCode MatConjugate(Mat);
574: PETSC_EXTERN PetscErrorCode MatRealPart(Mat);
575: PETSC_EXTERN PetscErrorCode MatImaginaryPart(Mat);
576: PETSC_EXTERN PetscErrorCode MatGetDiagonalBlock(Mat, Mat *);
577: PETSC_EXTERN PetscErrorCode MatGetMultPetscSF(Mat, PetscSF *);
578: PETSC_EXTERN PetscErrorCode MatGetTrace(Mat, PetscScalar *);
579: PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonal(Mat, const PetscScalar **);
580: PETSC_EXTERN PetscErrorCode MatInvertVariableBlockDiagonal(Mat, PetscInt, const PetscInt *, PetscScalar *);
581: PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonalMat(Mat, Mat);
582: PETSC_EXTERN PetscErrorCode MatInvertVariableBlockEnvelope(Mat, MatReuse, Mat *);
583: PETSC_EXTERN PetscErrorCode MatComputeVariableBlockEnvelope(Mat);

585: PETSC_EXTERN PetscErrorCode MatSetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
586: PETSC_EXTERN PetscErrorCode MatSetValuesIS(Mat, IS, IS, const PetscScalar[], InsertMode);
587: PETSC_EXTERN PetscErrorCode MatSetValuesBlocked(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
588: PETSC_EXTERN PetscErrorCode MatSetValuesRow(Mat, PetscInt, const PetscScalar[]);
589: PETSC_EXTERN PetscErrorCode MatSetValuesRowLocal(Mat, PetscInt, const PetscScalar[]);
590: PETSC_EXTERN PetscErrorCode MatSetValuesBatch(Mat, PetscInt, PetscInt, PetscInt[], const PetscScalar[]);
591: PETSC_EXTERN PetscErrorCode MatSetRandom(Mat, PetscRandom);

593: /*S
594:    MatStencil - Data structure (C struct) for storing information about rows and
595:    columns of a matrix as indexed on an associated grid. These are arguments to `MatSetStencil()` and `MatSetBlockStencil()`

597:    Level: beginner

599:    Notes:
600:    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).
601:    The c represents the degrees of freedom at each grid point (the dof argument to `DMDASetDOF()`). If dof is 1 then this entry is ignored.

603:    For stencil access to vectors see `DMDAVecGetArray()`

605:    For staggered grids, see `DMStagStencil`

607: .seealso: [](ch_matrices), `Mat`, `MatSetValuesStencil()`, `MatSetStencil()`, `MatSetValuesBlockedStencil()`, `DMDAVecGetArray()`,
608:           `DMStagStencil`
609: S*/
610: typedef struct {
611:   PetscInt k, j, i, c;
612: } MatStencil;

614: PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
615: PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
616: PETSC_EXTERN PetscErrorCode MatSetStencil(Mat, PetscInt, const PetscInt[], const PetscInt[], PetscInt);

618: /*E
619:     MatAssemblyType - Indicates if the process of setting values into the matrix is complete, and the matrix is ready for use

621:     Values:
622: +   `MAT_FLUSH_ASSEMBLY` - you will continue to put values into the matrix
623: -   `MAT_FINAL_ASSEMBLY` - you wish to use the matrix with the values currently inserted

625:     Level: beginner

627: .seealso: [](ch_matrices), `Mat`, `MatSetValues`, `MatAssemblyBegin()`, `MatAssemblyEnd()`
628: E*/
629: typedef enum {
630:   MAT_FLUSH_ASSEMBLY = 1,
631:   MAT_FINAL_ASSEMBLY = 0
632: } MatAssemblyType;

634: PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat, MatAssemblyType);
635: PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat, MatAssemblyType);
636: PETSC_EXTERN PetscErrorCode MatAssembled(Mat, PetscBool *);

638: /*E
639:    MatOption - Options that may be set for a matrix that indicate properties of the matrix or affect its behavior or storage

641:    Level: beginner

643:    Note:
644:    See `MatSetOption()` for the use of the options

646:    Developer Note:
647:    Entries that are negative need not be called collectively by all processes.

649: .seealso: [](ch_matrices), `Mat`, `MatSetOption()`, `VecOption`
650: E*/
651: typedef enum {
652:   MAT_OPTION_MIN                  = -3,
653:   MAT_UNUSED_NONZERO_LOCATION_ERR = -2,
654:   MAT_ROW_ORIENTED                = -1,
655:   MAT_SYMMETRIC                   = 1,
656:   MAT_STRUCTURALLY_SYMMETRIC      = 2,
657:   MAT_FORCE_DIAGONAL_ENTRIES      = 3,
658:   MAT_IGNORE_OFF_PROC_ENTRIES     = 4,
659:   MAT_USE_HASH_TABLE              = 5,
660:   MAT_KEEP_NONZERO_PATTERN        = 6,
661:   MAT_IGNORE_ZERO_ENTRIES         = 7,
662:   MAT_USE_INODES                  = 8,
663:   MAT_HERMITIAN                   = 9,
664:   MAT_SYMMETRY_ETERNAL            = 10,
665:   MAT_NEW_NONZERO_LOCATION_ERR    = 11,
666:   MAT_IGNORE_LOWER_TRIANGULAR     = 12,
667:   MAT_ERROR_LOWER_TRIANGULAR      = 13,
668:   MAT_GETROW_UPPERTRIANGULAR      = 14,
669:   MAT_SPD                         = 15,
670:   MAT_NO_OFF_PROC_ZERO_ROWS       = 16,
671:   MAT_NO_OFF_PROC_ENTRIES         = 17,
672:   MAT_NEW_NONZERO_LOCATIONS       = 18,
673:   MAT_NEW_NONZERO_ALLOCATION_ERR  = 19,
674:   MAT_SUBSET_OFF_PROC_ENTRIES     = 20,
675:   MAT_SUBMAT_SINGLEIS             = 21,
676:   MAT_STRUCTURE_ONLY              = 22,
677:   MAT_SORTED_FULL                 = 23,
678:   MAT_FORM_EXPLICIT_TRANSPOSE     = 24,
679:   MAT_STRUCTURAL_SYMMETRY_ETERNAL = 25,
680:   MAT_SPD_ETERNAL                 = 26,
681:   MAT_OPTION_MAX                  = 27
682: } MatOption;

684: PETSC_EXTERN const char *const *MatOptions;
685: PETSC_EXTERN PetscErrorCode     MatSetOption(Mat, MatOption, PetscBool);
686: PETSC_EXTERN PetscErrorCode     MatGetOption(Mat, MatOption, PetscBool *);
687: PETSC_EXTERN PetscErrorCode     MatPropagateSymmetryOptions(Mat, Mat);
688: PETSC_EXTERN PetscErrorCode     MatGetType(Mat, MatType *);

690: PETSC_EXTERN PetscErrorCode    MatGetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]);
691: PETSC_EXTERN PetscErrorCode    MatGetRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]);
692: PETSC_EXTERN PetscErrorCode    MatRestoreRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]);
693: PETSC_EXTERN PetscErrorCode    MatGetRowUpperTriangular(Mat);
694: PETSC_EXTERN PetscErrorCode    MatRestoreRowUpperTriangular(Mat);
695: PETSC_EXTERN PetscErrorCode    MatGetColumnVector(Mat, Vec, PetscInt);
696: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArray(Mat, PetscScalar *[]);
697: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArrayRead(Mat, const PetscScalar *[]);
698: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArrayWrite(Mat, PetscScalar *[]);
699: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArray(Mat, PetscScalar *[]);
700: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArrayRead(Mat, const PetscScalar *[]);
701: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArrayWrite(Mat, PetscScalar *[]);
702: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetMaxRowNonzeros(Mat, PetscInt *);
703: PETSC_EXTERN PetscErrorCode    MatSeqAIJSetValuesLocalFast(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
704: PETSC_EXTERN PetscErrorCode    MatSeqAIJSetType(Mat, MatType);
705: PETSC_EXTERN PetscErrorCode    MatSeqAIJKron(Mat, Mat, MatReuse, Mat *);
706: PETSC_EXTERN PetscErrorCode    MatSeqAIJRegister(const char[], PetscErrorCode (*)(Mat, MatType, MatReuse, Mat *));
707: PETSC_EXTERN PetscFunctionList MatSeqAIJList;
708: PETSC_EXTERN PetscErrorCode    MatSeqBAIJGetArray(Mat, PetscScalar *[]);
709: PETSC_EXTERN PetscErrorCode    MatSeqBAIJRestoreArray(Mat, PetscScalar *[]);
710: PETSC_EXTERN PetscErrorCode    MatSeqSBAIJGetArray(Mat, PetscScalar *[]);
711: PETSC_EXTERN PetscErrorCode    MatSeqSBAIJRestoreArray(Mat, PetscScalar *[]);
712: PETSC_EXTERN PetscErrorCode    MatDenseGetArray(Mat, PetscScalar *[]);
713: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArray(Mat, PetscScalar *[]);
714: PETSC_EXTERN PetscErrorCode    MatDensePlaceArray(Mat, const PetscScalar[]);
715: PETSC_EXTERN PetscErrorCode    MatDenseReplaceArray(Mat, const PetscScalar[]);
716: PETSC_EXTERN PetscErrorCode    MatDenseReplaceArrayWithMemType(Mat, PetscMemType, const PetscScalar[]);
717: PETSC_EXTERN PetscErrorCode    MatDenseResetArray(Mat);
718: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayRead(Mat, const PetscScalar *[]);
719: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayRead(Mat, const PetscScalar *[]);
720: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayWrite(Mat, PetscScalar *[]);
721: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayWrite(Mat, PetscScalar *[]);
722: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayAndMemType(Mat, PetscScalar *[], PetscMemType *);
723: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayAndMemType(Mat, PetscScalar *[]);
724: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayReadAndMemType(Mat, const PetscScalar *[], PetscMemType *);
725: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayReadAndMemType(Mat, const PetscScalar *[]);
726: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayWriteAndMemType(Mat, PetscScalar *[], PetscMemType *);
727: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayWriteAndMemType(Mat, PetscScalar *[]);
728: PETSC_EXTERN PetscErrorCode    MatGetBlockSize(Mat, PetscInt *);
729: PETSC_EXTERN PetscErrorCode    MatSetBlockSize(Mat, PetscInt);
730: PETSC_EXTERN PetscErrorCode    MatGetBlockSizes(Mat, PetscInt *, PetscInt *);
731: PETSC_EXTERN PetscErrorCode    MatSetBlockSizes(Mat, PetscInt, PetscInt);
732: PETSC_EXTERN PetscErrorCode    MatSetBlockSizesFromMats(Mat, Mat, Mat);
733: PETSC_EXTERN PetscErrorCode    MatSetVariableBlockSizes(Mat, PetscInt, const PetscInt[]);
734: PETSC_EXTERN PetscErrorCode    MatGetVariableBlockSizes(Mat, PetscInt *, const PetscInt *[]);
735: PETSC_EXTERN PetscErrorCode    MatSelectVariableBlockSizes(Mat, Mat, IS);

737: PETSC_EXTERN PetscErrorCode MatDenseGetColumn(Mat, PetscInt, PetscScalar *[]);
738: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumn(Mat, PetscScalar *[]);
739: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVec(Mat, PetscInt, Vec *);
740: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVec(Mat, PetscInt, Vec *);
741: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecRead(Mat, PetscInt, Vec *);
742: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecRead(Mat, PetscInt, Vec *);
743: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecWrite(Mat, PetscInt, Vec *);
744: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecWrite(Mat, PetscInt, Vec *);
745: PETSC_EXTERN PetscErrorCode MatDenseGetSubMatrix(Mat, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
746: PETSC_EXTERN PetscErrorCode MatDenseRestoreSubMatrix(Mat, Mat *);

748: PETSC_EXTERN PetscErrorCode MatMult(Mat, Vec, Vec);
749: PETSC_EXTERN PetscErrorCode MatMultDiagonalBlock(Mat, Vec, Vec);
750: PETSC_EXTERN PetscErrorCode MatMultAdd(Mat, Vec, Vec, Vec);
751: PETSC_EXTERN PetscErrorCode MatMultTranspose(Mat, Vec, Vec);
752: PETSC_EXTERN PetscErrorCode MatMultHermitianTranspose(Mat, Vec, Vec);
753: PETSC_EXTERN PetscErrorCode MatADot(Mat, Vec, Vec, PetscScalar *);
754: PETSC_EXTERN PetscErrorCode MatANorm(Mat, Vec, PetscReal *);
755: PETSC_EXTERN PetscErrorCode MatIsTranspose(Mat, Mat, PetscReal, PetscBool *);
756: PETSC_EXTERN PetscErrorCode MatIsHermitianTranspose(Mat, Mat, PetscReal, PetscBool *);
757: PETSC_EXTERN PetscErrorCode MatMultTransposeAdd(Mat, Vec, Vec, Vec);
758: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAdd(Mat, Vec, Vec, Vec);
759: PETSC_EXTERN PetscErrorCode MatMatSolve(Mat, Mat, Mat);
760: PETSC_EXTERN PetscErrorCode MatMatSolveTranspose(Mat, Mat, Mat);
761: PETSC_EXTERN PetscErrorCode MatMatTransposeSolve(Mat, Mat, Mat);
762: PETSC_EXTERN PetscErrorCode MatResidual(Mat, Vec, Vec, Vec);

764: /*E
765:   MatDuplicateOption - Indicates if a duplicated sparse matrix should have
766:   its numerical values copied over or just its nonzero structure.

768:   Values:
769: + `MAT_DO_NOT_COPY_VALUES`    - Create a matrix using the same nonzero pattern as the original matrix,
770:                                 with zeros for the numerical values
771: . `MAT_COPY_VALUES`           - Create a matrix with the same nonzero pattern as the original matrix
772:                                 and with the same numerical values.
773: - `MAT_SHARE_NONZERO_PATTERN` - Create a matrix that shares the nonzero structure with the previous matrix
774:                                 and does not copy it, using zeros for the numerical values. The parent and
775:                                 child matrices will share their index (i and j) arrays, and you cannot
776:                                 insert new nonzero entries into either matrix

778:   Level: beginner

780:   Note:
781:   Many matrix types (including `MATSEQAIJ`) do not support the `MAT_SHARE_NONZERO_PATTERN` optimization; in
782:   this case the behavior is as if `MAT_DO_NOT_COPY_VALUES` has been specified.

784: .seealso: [](ch_matrices), `Mat`, `MatDuplicate()`
785: E*/
786: typedef enum {
787:   MAT_DO_NOT_COPY_VALUES,
788:   MAT_COPY_VALUES,
789:   MAT_SHARE_NONZERO_PATTERN
790: } MatDuplicateOption;

792: PETSC_EXTERN PetscErrorCode MatConvert(Mat, MatType, MatReuse, Mat *);
793: PETSC_EXTERN PetscErrorCode MatDuplicate(Mat, MatDuplicateOption, Mat *);

795: PETSC_EXTERN PetscErrorCode MatCopy(Mat, Mat, MatStructure);
796: PETSC_EXTERN PetscErrorCode MatView(Mat, PetscViewer);
797: PETSC_EXTERN PetscErrorCode MatIsSymmetric(Mat, PetscReal, PetscBool *);
798: PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetric(Mat, PetscBool *);
799: PETSC_EXTERN PetscErrorCode MatIsHermitian(Mat, PetscReal, PetscBool *);
800: PETSC_EXTERN PetscErrorCode MatIsSymmetricKnown(Mat, PetscBool *, PetscBool *);
801: PETSC_EXTERN PetscErrorCode MatIsHermitianKnown(Mat, PetscBool *, PetscBool *);
802: PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetricKnown(Mat, PetscBool *, PetscBool *);
803: PETSC_EXTERN PetscErrorCode MatIsSPDKnown(Mat, PetscBool *, PetscBool *);
804: PETSC_EXTERN PetscErrorCode MatLoad(Mat, PetscViewer);

806: PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
807: PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
808: PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
809: PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);

811: /*S
812:    MatInfo - Context of matrix information, used with `MatGetInfo()`

814:    Level: intermediate

816:    Fortran Note:
817:    `MatInfo` is a derived type, use e.g. `matinfo%nz_allocated` to access its components.

819: .seealso: [](ch_matrices), `Mat`, `MatGetInfo()`, `MatInfoType`
820: S*/
821: typedef struct {
822:   PetscLogDouble block_size;                          /* block size */
823:   PetscLogDouble nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
824:   PetscLogDouble memory;                              /* memory allocated */
825:   PetscLogDouble assemblies;                          /* number of matrix assemblies called */
826:   PetscLogDouble mallocs;                             /* number of mallocs during MatSetValues() */
827:   PetscLogDouble fill_ratio_given, fill_ratio_needed; /* fill ratio for LU/ILU */
828:   PetscLogDouble factor_mallocs;                      /* number of mallocs during factorization */
829: } MatInfo;

831: /*E
832:     MatInfoType - Indicates if you want information about the local part of the matrix,
833:     the entire parallel matrix or the maximum over all the local parts.

835:     Values:
836: +   `MAT_LOCAL`      - values for each MPI process part of the matrix
837: .   `MAT_GLOBAL_MAX` - maximum of each value over all MPI processes
838: -   `MAT_GLOBAL_SUM` - sum of each value over all MPI processes

840:     Level: beginner

842: .seealso: [](ch_matrices), `MatGetInfo()`, `MatInfo`
843: E*/
844: typedef enum {
845:   MAT_LOCAL      = 1,
846:   MAT_GLOBAL_MAX = 2,
847:   MAT_GLOBAL_SUM = 3
848: } MatInfoType;
849: PETSC_EXTERN PetscErrorCode MatGetInfo(Mat, MatInfoType, MatInfo *);
850: PETSC_EXTERN PetscErrorCode MatGetDiagonal(Mat, Vec);
851: PETSC_EXTERN PetscErrorCode MatGetRowMax(Mat, Vec, PetscInt[]);
852: PETSC_EXTERN PetscErrorCode MatGetRowMin(Mat, Vec, PetscInt[]);
853: PETSC_EXTERN PetscErrorCode MatGetRowMaxAbs(Mat, Vec, PetscInt[]);
854: PETSC_EXTERN PetscErrorCode MatGetRowSumAbs(Mat, Vec);
855: PETSC_EXTERN PetscErrorCode MatGetRowMinAbs(Mat, Vec, PetscInt[]);
856: PETSC_EXTERN PetscErrorCode MatGetRowSum(Mat, Vec);
857: PETSC_EXTERN PetscErrorCode MatTranspose(Mat, MatReuse, Mat *);
858: PETSC_EXTERN PetscErrorCode MatTransposeSymbolic(Mat, Mat *);
859: PETSC_EXTERN PetscErrorCode MatTransposeSetPrecursor(Mat, Mat);
860: PETSC_EXTERN PetscErrorCode MatHermitianTranspose(Mat, MatReuse, Mat *);
861: PETSC_EXTERN PetscErrorCode MatPermute(Mat, IS, IS, Mat *);
862: PETSC_EXTERN PetscErrorCode MatDiagonalScale(Mat, Vec, Vec);
863: PETSC_EXTERN PetscErrorCode MatDiagonalSet(Mat, Vec, InsertMode);

865: PETSC_EXTERN PetscErrorCode MatEqual(Mat, Mat, PetscBool *);
866: PETSC_EXTERN PetscErrorCode MatMultEqual(Mat, Mat, PetscInt, PetscBool *);
867: PETSC_EXTERN PetscErrorCode MatMultAddEqual(Mat, Mat, PetscInt, PetscBool *);
868: PETSC_EXTERN PetscErrorCode MatMultTransposeEqual(Mat, Mat, PetscInt, PetscBool *);
869: PETSC_EXTERN PetscErrorCode MatMultTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *);
870: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeEqual(Mat, Mat, PetscInt, PetscBool *);
871: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *);
872: PETSC_EXTERN PetscErrorCode MatMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
873: PETSC_EXTERN PetscErrorCode MatTransposeMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
874: PETSC_EXTERN PetscErrorCode MatMatTransposeMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
875: PETSC_EXTERN PetscErrorCode MatPtAPMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
876: PETSC_EXTERN PetscErrorCode MatRARtMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
877: PETSC_EXTERN PetscErrorCode MatIsLinear(Mat, PetscInt, PetscBool *);

879: PETSC_EXTERN PetscErrorCode MatNorm(Mat, NormType, PetscReal *);
880: PETSC_EXTERN PetscErrorCode MatNormApproximate(Mat, NormType, PetscInt, PetscReal *);
881: PETSC_EXTERN PetscErrorCode MatGetColumnNorms(Mat, NormType, PetscReal *);
882: PETSC_EXTERN PetscErrorCode MatGetColumnSums(Mat, PetscScalar *);
883: PETSC_EXTERN PetscErrorCode MatGetColumnSumsRealPart(Mat, PetscReal *);
884: PETSC_EXTERN PetscErrorCode MatGetColumnSumsImaginaryPart(Mat, PetscReal *);
885: PETSC_EXTERN PetscErrorCode MatGetColumnMeans(Mat, PetscScalar *);
886: PETSC_EXTERN PetscErrorCode MatGetColumnMeansRealPart(Mat, PetscReal *);
887: PETSC_EXTERN PetscErrorCode MatGetColumnMeansImaginaryPart(Mat, PetscReal *);
888: PETSC_EXTERN PetscErrorCode MatGetColumnReductions(Mat, PetscInt, PetscReal *);
889: PETSC_EXTERN PetscErrorCode MatZeroEntries(Mat);
890: PETSC_EXTERN PetscErrorCode MatSetInf(Mat);
891: PETSC_EXTERN PetscErrorCode MatZeroRows(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
892: PETSC_EXTERN PetscErrorCode MatZeroRowsIS(Mat, IS, PetscScalar, Vec, Vec);
893: PETSC_EXTERN PetscErrorCode MatZeroRowsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec);
894: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec);
895: PETSC_EXTERN PetscErrorCode MatZeroRowsColumns(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
896: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsIS(Mat, IS, PetscScalar, Vec, Vec);

898: PETSC_EXTERN PetscErrorCode MatGetSize(Mat, PetscInt *, PetscInt *);
899: PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat, PetscInt *, PetscInt *);
900: PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat, PetscInt *, PetscInt *);
901: PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat, const PetscInt **);
902: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat, PetscInt *, PetscInt *);
903: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat, const PetscInt **);
904: PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat, IS *, IS *);

906: PETSC_EXTERN PetscErrorCode MatCreateSubMatrices(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]);
907: 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[])
908: {
909:   return MatCreateSubMatrices(mat, n, irow, icol, scall, submat);
910: }
911: PETSC_EXTERN PetscErrorCode MatCreateSubMatricesMPI(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]);
912: 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[])
913: {
914:   return MatCreateSubMatricesMPI(mat, n, irow, icol, scall, submat);
915: }
916: PETSC_EXTERN PetscErrorCode MatDestroyMatrices(PetscInt, Mat *[]);
917: PETSC_EXTERN PetscErrorCode MatDestroySubMatrices(PetscInt, Mat *[]);
918: PETSC_EXTERN PetscErrorCode MatCreateSubMatrix(Mat, IS, IS, MatReuse, Mat *);
919: PETSC_DEPRECATED_FUNCTION(3, 8, 0, "MatCreateSubMatrix()", ) static inline PetscErrorCode MatGetSubMatrix(Mat mat, IS isrow, IS iscol, MatReuse cll, Mat *newmat)
920: {
921:   return MatCreateSubMatrix(mat, isrow, iscol, cll, newmat);
922: }
923: PETSC_EXTERN PetscErrorCode MatGetLocalSubMatrix(Mat, IS, IS, Mat *);
924: PETSC_EXTERN PetscErrorCode MatRestoreLocalSubMatrix(Mat, IS, IS, Mat *);
925: PETSC_EXTERN PetscErrorCode MatGetSeqNonzeroStructure(Mat, Mat *);
926: PETSC_EXTERN PetscErrorCode MatDestroySeqNonzeroStructure(Mat *);

928: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJ(MPI_Comm, Mat, PetscInt, PetscInt, MatReuse, Mat *);
929: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJSymbolic(MPI_Comm, Mat, PetscInt, PetscInt, Mat *);
930: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJNumeric(Mat, Mat);
931: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMat(Mat, MatReuse, Mat *);
932: PETSC_EXTERN PetscErrorCode MatAIJGetLocalMat(Mat, Mat *);
933: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *);
934: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatMerge(Mat, MatReuse, IS *, Mat *);
935: PETSC_EXTERN PetscErrorCode MatMPIAIJGetNumberNonzeros(Mat, PetscCount *);
936: PETSC_EXTERN PetscErrorCode MatGetBrowsOfAcols(Mat, Mat, MatReuse, IS *, IS *, Mat *);
937: PETSC_EXTERN PetscErrorCode MatGetGhosts(Mat, PetscInt *, const PetscInt *[]);

939: PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat, PetscInt, IS[], PetscInt);
940: PETSC_EXTERN PetscErrorCode MatIncreaseOverlapSplit(Mat, PetscInt, IS[], PetscInt);
941: PETSC_EXTERN PetscErrorCode MatMPIAIJSetUseScalableIncreaseOverlap(Mat, PetscBool);

943: PETSC_EXTERN PetscErrorCode MatMatMult(Mat, Mat, MatReuse, PetscReal, Mat *);

945: PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);
946: PETSC_EXTERN PetscErrorCode MatGalerkin(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);

948: PETSC_EXTERN PetscErrorCode MatPtAP(Mat, Mat, MatReuse, PetscReal, Mat *);
949: PETSC_EXTERN PetscErrorCode MatRARt(Mat, Mat, MatReuse, PetscReal, Mat *);

951: PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat, Mat, MatReuse, PetscReal, Mat *);
952: PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat, Mat, MatReuse, PetscReal, Mat *);

954: PETSC_EXTERN PetscErrorCode MatAXPY(Mat, PetscScalar, Mat, MatStructure);
955: PETSC_EXTERN PetscErrorCode MatAYPX(Mat, PetscScalar, Mat, MatStructure);

957: PETSC_EXTERN PetscErrorCode MatScale(Mat, PetscScalar);
958: PETSC_EXTERN PetscErrorCode MatShift(Mat, PetscScalar);

960: PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping, ISLocalToGlobalMapping);
961: PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *);
962: PETSC_EXTERN PetscErrorCode MatGetLayouts(Mat, PetscLayout *, PetscLayout *);
963: PETSC_EXTERN PetscErrorCode MatSetLayouts(Mat, PetscLayout, PetscLayout);
964: PETSC_EXTERN PetscErrorCode MatZeroRowsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
965: PETSC_EXTERN PetscErrorCode MatZeroRowsLocalIS(Mat, IS, PetscScalar, Vec, Vec);
966: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
967: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocalIS(Mat, IS, PetscScalar, Vec, Vec);
968: PETSC_EXTERN PetscErrorCode MatGetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]);
969: PETSC_EXTERN PetscErrorCode MatSetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
970: PETSC_EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);

972: PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat, PetscInt, PetscInt);
973: PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat, PetscInt *, PetscInt *, PetscInt *, PetscInt *);

975: PETSC_EXTERN PetscErrorCode MatInterpolate(Mat, Vec, Vec);
976: PETSC_EXTERN PetscErrorCode MatInterpolateAdd(Mat, Vec, Vec, Vec);
977: PETSC_EXTERN PetscErrorCode MatRestrict(Mat, Vec, Vec);
978: PETSC_EXTERN PetscErrorCode MatMatInterpolate(Mat, Mat, Mat *);
979: PETSC_EXTERN PetscErrorCode MatMatInterpolateAdd(Mat, Mat, Mat, Mat *);
980: PETSC_EXTERN PetscErrorCode MatMatRestrict(Mat, Mat, Mat *);
981: PETSC_EXTERN PetscErrorCode MatCreateVecs(Mat, Vec *, Vec *);
982: PETSC_DEPRECATED_FUNCTION(3, 6, 0, "MatCreateVecs()", ) static inline PetscErrorCode MatGetVecs(Mat mat, Vec *x, Vec *y)
983: {
984:   return MatCreateVecs(mat, x, y);
985: }
986: PETSC_EXTERN PetscErrorCode MatCreateRedundantMatrix(Mat, PetscInt, MPI_Comm, MatReuse, Mat *);
987: PETSC_EXTERN PetscErrorCode MatGetMultiProcBlock(Mat, MPI_Comm, MatReuse, Mat *);
988: PETSC_EXTERN PetscErrorCode MatFindZeroDiagonals(Mat, IS *);
989: PETSC_EXTERN PetscErrorCode MatFindOffBlockDiagonalEntries(Mat, IS *);
990: PETSC_EXTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat(MPI_Comm, Mat, PetscInt, MatReuse, Mat *);

992: PETSC_EXTERN PetscErrorCode MatCopyHashToXAIJ(Mat A, Mat B);
993: /*@C
994:    MatSetValue - Set a single entry into a matrix.

996:    Not Collective

998:    Input Parameters:
999: +  mat  - the matrix
1000: .  i    - the row location of the entry
1001: .  j    - the column location of the entry
1002: .  va   - the value to insert
1003: -  mode - either `INSERT_VALUES` or `ADD_VALUES`

1005:    Level: beginner

1007:    Notes:
1008:    This value may be cached, so `MatAssemblyBegin()` and `MatAssemblyEnd()`
1009:    MUST be called after all calls to `MatSetValue()` have been completed.

1011:    For efficiency one should use `MatSetValues()` and set several values simultaneously.

1013: .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `InsertMode`, `MatGetValue()`, `MatSetValues()`,
1014:           `MatSetValueLocal()`, `MatSetValuesLocal()`
1015: @*/
1016: static inline PetscErrorCode MatSetValue(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode)
1017: {
1018:   return MatSetValues(mat, 1, &i, 1, &j, &va, mode);
1019: }

1021: /*@C
1022:    MatGetValue - Gets a single value from a matrix

1024:    Not Collective; can only return a value owned by the given process

1026:    Input Parameters:
1027: +  mat - the matrix
1028: .  row - the row location of the entry
1029: -  col - the column location of the entry

1031:    Output Parameter:
1032: .  va - the value

1034:    Level: advanced

1036:    Notes:
1037:    The matrix must have been assembled with `MatAssemblyBegin()` and `MatAssemblyEnd()` before this call

1039:    For efficiency one should use `MatGetValues()` and get several values simultaneously.

1041:    See notes for `MatGetValues()`.

1043: .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `MatSetValue()`, `MatGetValuesLocal()`, `MatGetValues()`
1044: @*/
1045: static inline PetscErrorCode MatGetValue(Mat mat, PetscInt row, PetscInt col, PetscScalar *va)
1046: {
1047:   return MatGetValues(mat, 1, &row, 1, &col, va);
1048: }

1050: /*@C
1051:    MatSetValueLocal - Inserts or adds a single value into a matrix, using a local numbering of the nodes.

1053:    Not Collective

1055:    Input Parameters:
1056: +  mat  - the matrix
1057: .  i    - the row location of the entry
1058: .  j    - the column location of the entry
1059: .  va   - the value to insert
1060: -  mode - either `INSERT_VALUES` or `ADD_VALUES`

1062:    Level: intermediate

1064:    Notes:
1065:    For efficiency one should use `MatSetValuesLocal()` and set several values simultaneously.

1067:    See notes for `MatSetValuesLocal()` for additional information on when and how this function can be used.

1069: .seealso: [](ch_matrices), `MatSetValue()`, `MatSetValuesLocal()`
1070: @*/
1071: static inline PetscErrorCode MatSetValueLocal(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode)
1072: {
1073:   return MatSetValuesLocal(mat, 1, &i, 1, &j, &va, mode);
1074: }

1076: /*MC
1077:    MatPreallocateBegin - Begins the block of code that will count the number of nonzeros per
1078:    row in a matrix providing the data that one can use to correctly preallocate the matrix.

1080:    Synopsis:
1081: #include <petscmat.h>
1082:    PetscErrorCode MatPreallocateBegin(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)

1084:    Collective

1086:    Input Parameters:
1087: +  comm  - the communicator that will share the eventually allocated matrix
1088: .  nrows - the number of LOCAL rows in the matrix
1089: -  ncols - the number of LOCAL columns in the matrix

1091:    Output Parameters:
1092: +  dnz - the array that will be passed to the matrix preallocation routines
1093: -  onz - the other array passed to the matrix preallocation routines

1095:    Level: deprecated (since v3.19)

1097:    Notes:
1098:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1099:    the use of this routine

1101:    This is a macro that handles its own error checking, it does not return an error code.

1103:    Do not malloc or free `dnz` and `onz`, that is handled internally by these routines

1105:    Developer Note:
1106:    This is a MACRO, not a function, because it has a leading { that is closed by `PetscPreallocateFinalize()`.

1108: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`,
1109:           `MatPreallocateSymmetricSetLocalBlock()`
1110: M*/
1111: #define MatPreallocateBegin(comm, nrows, ncols, dnz, onz) \
1112:   do { \
1113:     PetscInt              __nrows = (nrows), __ncols = (ncols), __rstart, __end = 0; \
1114:     PetscInt PETSC_UNUSED __start; \
1115:     PetscCall(PetscCalloc2(__nrows, &(dnz), __nrows, &(onz))); \
1116:     PetscCallMPI(MPI_Scan(&__ncols, &__end, 1, MPIU_INT, MPI_SUM, comm)); \
1117:     __start = __end - __ncols; \
1118:     (void)__start; \
1119:     PetscCallMPI(MPI_Scan(&__nrows, &__rstart, 1, MPIU_INT, MPI_SUM, comm)); \
1120:   __rstart -= __nrows

1122: #define MatPreallocateInitialize(...) PETSC_DEPRECATED_MACRO(3, 18, 0, "MatPreallocateBegin()", ) MatPreallocateBegin(__VA_ARGS__)

1124: /*MC
1125:    MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1126:    inserted using a local number of the rows and columns

1128:    Synopsis:
1129: #include <petscmat.h>
1130:    PetscErrorCode MatPreallocateSetLocal(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1132:    Not Collective

1134:    Input Parameters:
1135: +  map   - the row mapping from local numbering to global numbering
1136: .  nrows - the number of rows indicated
1137: .  rows  - the indices of the rows
1138: .  cmap  - the column mapping from local to global numbering
1139: .  ncols - the number of columns in the matrix
1140: .  cols  - the columns indicated
1141: .  dnz   - the array that will be passed to the matrix preallocation routines
1142: -  onz   - the other array passed to the matrix preallocation routines

1144:    Level: deprecated (since v3.19)

1146:    Notes:
1147:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1148:    the use of this routine

1150:    Do not malloc or free `dnz` and `onz`, that is handled internally by these routines

1152: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1153:           `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocalRemoveDups()`
1154: M*/
1155: #define MatPreallocateSetLocal(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \
1156:   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));)

1158: /*MC
1159:    MatPreallocateSetLocalRemoveDups - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1160:    inserted using a local number of the rows and columns. This version removes any duplicate columns in cols

1162:    Synopsis:
1163: #include <petscmat.h>
1164:    PetscErrorCode MatPreallocateSetLocalRemoveDups(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1166:    Not Collective

1168:    Input Parameters:
1169: +  map   - the row mapping from local numbering to global numbering
1170: .  nrows - the number of rows indicated
1171: .  rows  - the indices of the rows (these values are mapped to the global values)
1172: .  cmap  - the column mapping from local to global numbering
1173: .  ncols - the number of columns in the matrix   (this value will be changed if duplicate columns are found)
1174: .  cols  - the columns indicated (these values are mapped to the global values, they are then sorted and duplicates removed)
1175: .  dnz   - the array that will be passed to the matrix preallocation routines
1176: -  onz   - the other array passed to the matrix preallocation routines

1178:    Level: deprecated (since v3.19)

1180:    Notes:
1181:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1182:    the use of this routine

1184:    Do not malloc or free `dnz` and `onz`, that is handled internally by these routines

1186: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1187:           `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocal()`
1188: M*/
1189: #define MatPreallocateSetLocalRemoveDups(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \
1190:   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));)

1192: /*MC
1193:    MatPreallocateSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1194:    inserted using a local number of the rows and columns

1196:    Synopsis:
1197: #include <petscmat.h>
1198:    PetscErrorCode MatPreallocateSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1200:    Not Collective

1202:    Input Parameters:
1203: +  map   - the row mapping from local numbering to global numbering
1204: .  nrows - the number of rows indicated
1205: .  rows  - the indices of the rows
1206: .  cmap  - the column mapping from local to global numbering
1207: .  ncols - the number of columns in the matrix
1208: .  cols  - the columns indicated
1209: .  dnz   - the array that will be passed to the matrix preallocation routines
1210: -  onz   - the other array passed to the matrix preallocation routines

1212:    Level: deprecated (since v3.19)

1214:    Notes:
1215:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1216:    the use of this routine

1218:    Do not malloc or free `dnz` and `onz`, that is handled internally by these routines

1220: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1221:           `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`
1222: M*/
1223: #define MatPreallocateSetLocalBlock(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \
1224:   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));)

1226: /*MC
1227:    MatPreallocateSymmetricSetLocalBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1228:    inserted using a local number of the rows and columns

1230:    Synopsis:
1231: #include <petscmat.h>
1232:    PetscErrorCode MatPreallocateSymmetricSetLocalBlock(ISLocalToGlobalMappping map,PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1234:    Not Collective

1236:    Input Parameters:
1237: +  map   - the mapping between local numbering and global numbering
1238: .  nrows - the number of rows indicated
1239: .  rows  - the indices of the rows
1240: .  ncols - the number of columns in the matrix
1241: .  cols  - the columns indicated
1242: .  dnz   - the array that will be passed to the matrix preallocation routines
1243: -  onz   - the other array passed to the matrix preallocation routines

1245:    Level: deprecated (since v3.19)

1247:    Notes:
1248:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1249:    the use of this routine

1251:    Do not malloc or free `dnz` and `onz` that is handled internally by these routines

1253: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`,
1254:           `MatPreallocateBegin()`, `MatPreallocateSetLocal()`
1255: M*/
1256: #define MatPreallocateSymmetricSetLocalBlock(map, nrows, rows, ncols, cols, dnz, onz) \
1257:   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));)

1259: /*MC
1260:    MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1261:    inserted using a local number of the rows and columns

1263:    Synopsis:
1264: #include <petscmat.h>
1265:    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1267:    Not Collective

1269:    Input Parameters:
1270: +  row   - the row
1271: .  ncols - the number of columns in the matrix
1272: -  cols  - the columns indicated

1274:    Output Parameters:
1275: +  dnz - the array that will be passed to the matrix preallocation routines
1276: -  onz - the other array passed to the matrix preallocation routines

1278:    Level: deprecated (since v3.19)

1280:    Notes:
1281:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1282:    the use of this routine

1284:    Do not malloc or free `dnz` and `onz` that is handled internally by these routines

1286:    This is a MACRO, not a function, because it uses variables declared in MatPreallocateBegin().

1288: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1289:           `MatPreallocateBegin()`, `MatPreallocateSetLocal()`
1290: M*/
1291: #define MatPreallocateSet(row, nc, cols, dnz, onz) \
1292:   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) { \
1293:     if ((cols)[__i] < __start || (cols)[__i] >= __end) onz[row - __rstart]++; \
1294:     else if (dnz[row - __rstart] < __ncols) dnz[row - __rstart]++; \
1295:   })

1297: /*MC
1298:    MatPreallocateSymmetricSetBlock - Indicates the locations (rows and columns) in the matrix where nonzeros will be
1299:    inserted using a local number of the rows and columns

1301:    Synopsis:
1302: #include <petscmat.h>
1303:    PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1305:    Not Collective

1307:    Input Parameters:
1308: +  nrows - the number of rows indicated
1309: .  rows  - the indices of the rows
1310: .  ncols - the number of columns in the matrix
1311: .  cols  - the columns indicated
1312: .  dnz   - the array that will be passed to the matrix preallocation routines
1313: -  onz   - the other array passed to the matrix preallocation routines

1315:    Level: deprecated (since v3.19)

1317:    Notes:
1318:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1319:    the use of this routine

1321:    Do not malloc or free `dnz` and `onz` that is handled internally by these routines

1323:    This is a MACRO, not a function, because it uses variables declared in MatPreallocateBegin().

1325: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateBegin()`,
1326:           `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocal()`
1327: M*/
1328: #define MatPreallocateSymmetricSetBlock(row, nc, cols, dnz, onz) \
1329:   PetscMacroReturnStandard(for (PetscInt __i = 0; __i < nc; __i++) { \
1330:     if (cols[__i] >= __end) onz[row - __rstart]++; \
1331:     else if (cols[__i] >= row && dnz[row - __rstart] < __ncols) dnz[row - __rstart]++; \
1332:   })

1334: /*MC
1335:    MatPreallocateLocation -  An alternative to MatPreallocateSet() that puts the nonzero locations into the matrix if it exists

1337:    Synopsis:
1338: #include <petscmat.h>
1339:    PetscErrorCode MatPreallocateLocations(Mat A,PetscInt row,PetscInt ncols,PetscInt *cols,PetscInt *dnz,PetscInt *onz)

1341:    Not Collective

1343:    Input Parameters:
1344: +  A     - matrix
1345: .  row   - row where values exist (must be local to this process)
1346: .  ncols - number of columns
1347: .  cols  - columns with nonzeros
1348: .  dnz   - the array that will be passed to the matrix preallocation routines
1349: -  onz   - the other array passed to the matrix preallocation routines

1351:    Level: deprecated (since v3.19)

1353:    Notes:
1354:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1355:    the use of this routine

1357:    Do not malloc or free `dnz` and `onz` that is handled internally by these routines

1359:    Developer Note:
1360:    This is a MACRO, not a function, because it uses a bunch of variables private to the MatPreallocation.... routines.

1362: .seealso: [](ch_matrices), `MatPreallocateBegin()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`,
1363:           `MatPreallocateSymmetricSetLocalBlock()`
1364: M*/
1365: #define MatPreallocateLocation(A, row, ncols, cols, dnz, onz) (A ? MatSetValues(A, 1, &row, ncols, cols, NULL, INSERT_VALUES) : MatPreallocateSet(row, ncols, cols, dnz, onz))

1367: /*MC
1368:    MatPreallocateEnd - Ends the block of code that will count the number of nonzeros per
1369:    row in a matrix providing the data that one can use to correctly preallocate the matrix.

1371:    Synopsis:
1372: #include <petscmat.h>
1373:    PetscErrorCode MatPreallocateEnd(PetscInt *dnz, PetscInt *onz)

1375:    Collective

1377:    Input Parameters:
1378: +  dnz - the array that was be passed to the matrix preallocation routines
1379: -  onz - the other array passed to the matrix preallocation routines

1381:    Level: deprecated (since v3.19)

1383:    Notes:
1384:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1385:    the use of this routine

1387:    Do not malloc or free `dnz` and `onz`, that is handled internally by these routines

1389:    Developer Note:
1390:    This is a MACRO, not a function, because it closes the { started in MatPreallocateBegin().

1392: .seealso: [](ch_matrices), `MatPreallocateBegin()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`,
1393:           `MatPreallocateSymmetricSetLocalBlock()`
1394: M*/
1395: #define MatPreallocateEnd(dnz, onz) \
1396:   PetscCall(PetscFree2(dnz, onz)); \
1397:   } \
1398:   while (0)

1400: #define MatPreallocateFinalize(...) PETSC_DEPRECATED_MACRO(3, 18, 0, "MatPreallocateEnd()", ) MatPreallocateEnd(__VA_ARGS__)

1402: /* Routines unique to particular data structures */
1403: PETSC_EXTERN PetscErrorCode MatShellGetContext(Mat, PetscCtxRt);

1405: PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat, IS *, IS *);
1406: PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat, PetscInt *, PetscInt *[], PetscInt *);

1408: PETSC_EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat, PetscInt[]);
1409: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat, PetscInt[]);
1410: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1411: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1412: PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1413: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJFromTriple(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *, PetscCount, PetscBool);

1415: #define MAT_SKIP_ALLOCATION -4

1417: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1418: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1419: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat, PetscInt, const PetscInt[]);
1420: PETSC_EXTERN PetscErrorCode MatSeqAIJSetTotalPreallocation(Mat, PetscInt);

1422: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1423: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1424: PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1425: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]);
1426: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
1427: PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]);
1428: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
1429: PETSC_EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat, PetscInt[], PetscInt[], PetscInt[]);
1430: PETSC_EXTERN PetscErrorCode MatMPIAdjToSeq(Mat, Mat *);
1431: PETSC_EXTERN PetscErrorCode MatMPIAdjToSeqRankZero(Mat, Mat *);
1432: PETSC_EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat, PetscScalar[]);
1433: PETSC_EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat, PetscScalar[]);
1434: PETSC_EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat, Mat *, Mat *, const PetscInt *[]);
1435: PETSC_EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat, Mat *, Mat *, const PetscInt *[]);
1436: PETSC_EXTERN PetscErrorCode MatMPIAdjCreateNonemptySubcommMat(Mat, Mat *);

1438: PETSC_EXTERN PetscErrorCode MatDenseGetLDA(Mat, PetscInt *);
1439: PETSC_EXTERN PetscErrorCode MatDenseSetLDA(Mat, PetscInt);
1440: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatDenseSetLDA()", ) static inline PetscErrorCode MatSeqDenseSetLDA(Mat A, PetscInt lda)
1441: {
1442:   return MatDenseSetLDA(A, lda);
1443: }
1444: PETSC_EXTERN PetscErrorCode MatDenseGetLocalMatrix(Mat, Mat *);

1446: PETSC_EXTERN PetscErrorCode MatBlockMatSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);

1448: PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
1449: PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);

1451: PETSC_EXTERN PetscErrorCode MatFindNonzeroRows(Mat, IS *);
1452: PETSC_EXTERN PetscErrorCode MatFindZeroRows(Mat, IS *);
1453: /*
1454:   These routines are not usually accessed directly, rather solving is
1455:   done through the KSP and PC interfaces.
1456: */

1458: /*J
1459:    MatOrderingType - String with the name of a PETSc matrix ordering. These orderings are most commonly used
1460:    to reduce fill in sparse factorizations.

1462:    Level: beginner

1464:    Notes:
1465:    If `MATORDERINGEXTERNAL` is used then PETSc does not compute an ordering and instead the external factorization solver package called utilizes one
1466:    of its own.

1468:    There is no `MatOrdering` object, the ordering is obtained directly from the matrix with `MatGetOrdering()`

1470:    Developer Note:
1471:    This API should be converted to an API similar to those for `MatColoring` and `MatPartitioning`

1473: .seealso: [](ch_matrices), [](sec_graph), `MatGetFactor()`, `MatGetOrdering()`, `MatColoringType`, `MatPartitioningType`, `MatCoarsenType`, `PCFactorSetOrderingType()`
1474: J*/
1475: typedef const char *MatOrderingType;
1476: #define MATORDERINGNATURAL       "natural"
1477: #define MATORDERINGND            "nd"
1478: #define MATORDERING1WD           "1wd"
1479: #define MATORDERINGRCM           "rcm"
1480: #define MATORDERINGQMD           "qmd"
1481: #define MATORDERINGROWLENGTH     "rowlength"
1482: #define MATORDERINGWBM           "wbm"
1483: #define MATORDERINGSPECTRAL      "spectral"
1484: #define MATORDERINGAMD           "amd"           /* only works if UMFPACK is installed with PETSc */
1485: #define MATORDERINGMETISND       "metisnd"       /* only works if METIS is installed with PETSc */
1486: #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 */
1487: #define MATORDERINGEXTERNAL      "external"      /* uses an ordering type internal to the factorization package */

1489: PETSC_EXTERN PetscErrorCode    MatGetOrdering(Mat, MatOrderingType, IS *, IS *);
1490: PETSC_EXTERN PetscErrorCode    MatGetOrderingList(PetscFunctionList *);
1491: PETSC_EXTERN PetscErrorCode    MatOrderingRegister(const char[], PetscErrorCode (*)(Mat, MatOrderingType, IS *, IS *));
1492: PETSC_EXTERN PetscFunctionList MatOrderingList;

1494: #include "petscmatcoarsen.h"

1496: PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat, PetscReal, IS, IS);
1497: PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat, PetscReal, PetscBool, Mat *);

1499: PETSC_EXTERN PetscErrorCode MatFactorGetPreferredOrdering(Mat, MatFactorType, MatOrderingType *);

1501: /*S
1502:    MatFactorShiftType - Type of numeric shift used for factorizations

1504:    Values:
1505: +  `MAT_SHIFT_NONE`              - do not shift the matrix diagonal entries
1506: .  `MAT_SHIFT_NONZERO`           - shift the entries to be non-zero
1507: .  `MAT_SHIFT_POSITIVE_DEFINITE` - shift the entries to force the factorization to be positive definite
1508: -  `MAT_SHIFT_INBLOCKS`          - only shift the factors inside the small dense diagonal blocks of the matrix, for example with `MATBAIJ`

1510:    Level: intermediate

1512: .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `PCFactorSetShiftType()`
1513: S*/
1514: typedef enum {
1515:   MAT_SHIFT_NONE,
1516:   MAT_SHIFT_NONZERO,
1517:   MAT_SHIFT_POSITIVE_DEFINITE,
1518:   MAT_SHIFT_INBLOCKS
1519: } MatFactorShiftType;
1520: PETSC_EXTERN const char *const MatFactorShiftTypes[];
1521: PETSC_EXTERN const char *const MatFactorShiftTypesDetail[];

1523: /*S
1524:     MatFactorError - indicates what type of error was generated in a matrix factorization

1526:     Values:
1527: +   `MAT_FACTOR_NOERROR`           - there was no error during the factorization
1528: .   `MAT_FACTOR_STRUCT_ZEROPIVOT`  - there was a missing entry in a diagonal location of the matrix
1529: .   `MAT_FACTOR_NUMERIC_ZEROPIVOT` - there was a (near) zero pivot during the factorization
1530: .   `MAT_FACTOR_OUTMEMORY`         - the factorization has run out of memory
1531: -   `MAT_FACTOR_OTHER`             - some other error has occurred.

1533:     Level: intermediate

1535:     Note:
1536:     When a factorization is done in a preconditioner `PC` the error may be propagated up to a `PCFailedReason` or a `KSPConvergedReason`

1538: .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `MatFactorGetError()`, `MatFactorGetErrorZeroPivot()`, `MatFactorClearError()`,
1539:           `PCFailedReason`, `PCGetFailedReason()`, `KSPConvergedReason`
1540: S*/
1541: typedef enum {
1542:   MAT_FACTOR_NOERROR,
1543:   MAT_FACTOR_STRUCT_ZEROPIVOT,
1544:   MAT_FACTOR_NUMERIC_ZEROPIVOT,
1545:   MAT_FACTOR_OUTMEMORY,
1546:   MAT_FACTOR_OTHER
1547: } MatFactorError;

1549: PETSC_EXTERN PetscErrorCode MatFactorGetError(Mat, MatFactorError *);
1550: PETSC_EXTERN PetscErrorCode MatFactorClearError(Mat);
1551: PETSC_EXTERN PetscErrorCode MatFactorGetErrorZeroPivot(Mat, PetscReal *, PetscInt *);

1553: /*S
1554:    MatFactorInfo - Data passed into the matrix factorization routines, and information about the resulting factorization

1556:    Level: developer

1558:    Note:
1559:    You can use `MatFactorInfoInitialize()` to set default values.

1561:    Fortran Note:
1562:    `MatFactorInfo` is a derived type, use e.g. `matfactorinfo%dt` to access its components.

1564: .seealso: [](ch_matrices), `Mat`, `MatInfo`, `MatGetFactor()`, `MatLUFactorSymbolic()`, `MatILUFactorSymbolic()`, `MatCholeskyFactorSymbolic()`,
1565:           `MatICCFactorSymbolic()`, `MatICCFactor()`, `MatFactorInfoInitialize()`
1566: S*/
1567: typedef struct {
1568:   PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */
1569:   PetscReal usedt;
1570:   PetscReal dt;            /* drop tolerance */
1571:   PetscReal dtcol;         /* tolerance for pivoting */
1572:   PetscReal dtcount;       /* maximum nonzeros to be allowed per row */
1573:   PetscReal fill;          /* expected fill, nonzeros in factored matrix/nonzeros in original matrix */
1574:   PetscReal levels;        /* ICC/ILU(levels) */
1575:   PetscReal pivotinblocks; /* BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0 factorization may be faster if do not pivot */
1576:   PetscReal zeropivot;     /* pivot is called zero if less than this */
1577:   PetscReal shifttype;     /* type of shift added to matrix factor to prevent zero pivots */
1578:   PetscReal shiftamount;   /* how large the shift is */
1579:   PetscBool factoronhost;  /* do factorization on host instead of device (for device matrix types) */
1580:   PetscBool solveonhost;   /* do mat solve on host with the factor (for device matrix types) */
1581: } MatFactorInfo;

1583: PETSC_EXTERN PetscErrorCode MatFactorInfoInitialize(MatFactorInfo *);
1584: PETSC_EXTERN PetscErrorCode MatCholeskyFactor(Mat, IS, const MatFactorInfo *);
1585: PETSC_EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1586: PETSC_EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat, Mat, const MatFactorInfo *);
1587: PETSC_EXTERN PetscErrorCode MatLUFactor(Mat, IS, IS, const MatFactorInfo *);
1588: PETSC_EXTERN PetscErrorCode MatILUFactor(Mat, IS, IS, const MatFactorInfo *);
1589: PETSC_EXTERN PetscErrorCode MatLUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *);
1590: PETSC_EXTERN PetscErrorCode MatILUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *);
1591: PETSC_EXTERN PetscErrorCode MatICCFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1592: PETSC_EXTERN PetscErrorCode MatICCFactor(Mat, IS, const MatFactorInfo *);
1593: PETSC_EXTERN PetscErrorCode MatLUFactorNumeric(Mat, Mat, const MatFactorInfo *);
1594: PETSC_EXTERN PetscErrorCode MatQRFactor(Mat, IS, const MatFactorInfo *);
1595: PETSC_EXTERN PetscErrorCode MatQRFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1596: PETSC_EXTERN PetscErrorCode MatQRFactorNumeric(Mat, Mat, const MatFactorInfo *);
1597: PETSC_EXTERN PetscErrorCode MatGetInertia(Mat, PetscInt *, PetscInt *, PetscInt *);
1598: PETSC_EXTERN PetscErrorCode MatSolve(Mat, Vec, Vec);
1599: PETSC_EXTERN PetscErrorCode MatForwardSolve(Mat, Vec, Vec);
1600: PETSC_EXTERN PetscErrorCode MatBackwardSolve(Mat, Vec, Vec);
1601: PETSC_EXTERN PetscErrorCode MatSolveAdd(Mat, Vec, Vec, Vec);
1602: PETSC_EXTERN PetscErrorCode MatSolveTranspose(Mat, Vec, Vec);
1603: PETSC_EXTERN PetscErrorCode MatSolveTransposeAdd(Mat, Vec, Vec, Vec);
1604: PETSC_EXTERN PetscErrorCode MatSolves(Mat, Vecs, Vecs);
1605: PETSC_EXTERN PetscErrorCode MatSetUnfactored(Mat);

1607: /*E
1608:    MatFactorSchurStatus - Records the current state of the dense Schur complement that is maintained by a factored matrix when a user has requested its formation with `MatFactorSetSchurIS()`

1610:    Values:
1611: +   `MAT_FACTOR_SCHUR_UNFACTORED` - the Schur complement has been assembled but has not yet been factored or inverted
1612: .   `MAT_FACTOR_SCHUR_FACTORED`   - the Schur complement has been factored (for example via dense LU) and can be used to solve via `MatFactorSolveSchurComplement()`
1613: -   `MAT_FACTOR_SCHUR_INVERTED`   - the Schur complement has been explicitly inverted in place; subsequent solves multiply by the dense inverse

1615:    Level: advanced

1617: .seealso: [](ch_matrices), `Mat`, `MatFactorSetSchurIS()`, `MatFactorGetSchurComplement()`, `MatFactorRestoreSchurComplement()`,
1618:           `MatFactorInvertSchurComplement()`, `MatFactorCreateSchurComplement()`
1619: E*/
1620: typedef enum {
1621:   MAT_FACTOR_SCHUR_UNFACTORED,
1622:   MAT_FACTOR_SCHUR_FACTORED,
1623:   MAT_FACTOR_SCHUR_INVERTED
1624: } MatFactorSchurStatus;
1625: PETSC_EXTERN PetscErrorCode MatFactorSetSchurIS(Mat, IS);
1626: PETSC_EXTERN PetscErrorCode MatFactorGetSchurComplement(Mat, Mat *, MatFactorSchurStatus *);
1627: PETSC_EXTERN PetscErrorCode MatFactorRestoreSchurComplement(Mat, Mat *, MatFactorSchurStatus);
1628: PETSC_EXTERN PetscErrorCode MatFactorInvertSchurComplement(Mat);
1629: PETSC_EXTERN PetscErrorCode MatFactorCreateSchurComplement(Mat, Mat *, MatFactorSchurStatus *);
1630: PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplement(Mat, Vec, Vec);
1631: PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplementTranspose(Mat, Vec, Vec);
1632: PETSC_EXTERN PetscErrorCode MatFactorFactorizeSchurComplement(Mat);

1634: PETSC_EXTERN PetscErrorCode MatSeqDenseInvert(Mat);
1635: /*E
1636:    MatSORType - What type of (S)SOR to perform

1638:    Values:
1639: +  `SOR_FORWARD_SWEEP`         - do a sweep from the first row of the matrix to the last
1640: .  `SOR_BACKWARD_SWEEP`        - do a sweep from the last row to the first
1641: .  `SOR_SYMMETRIC_SWEEP`       - do a sweep from the first row to the last and then back to the first
1642: .  `SOR_LOCAL_FORWARD_SWEEP`   - each MPI process does its own forward sweep with no communication
1643: .  `SOR_LOCAL_BACKWARD_SWEEP`  - each MPI process does its own backward sweep with no communication
1644: .  `SOR_LOCAL_SYMMETRIC_SWEEP` - each MPI process does its own symmetric sweep with no communication
1645: .  `SOR_ZERO_INITIAL_GUESS`    - indicates the initial solution is zero so the sweep can avoid unneeded computation
1646: .  `SOR_EISENSTAT`             - apply the Eisentat application of SOR, see `PCEISENSTAT`
1647: .  `SOR_APPLY_UPPER`           - multiply by the upper triangular portion of the matrix
1648: -  `SOR_APPLY_LOWER`           - multiply by the lower triangular portion of the matrix

1650:    Level: beginner

1652:    Note:
1653:    These may be bitwise ORd together

1655:    Developer Note:
1656:    Since `MatSORType` may be bitwise ORd together, so do not change the numerical values below

1658: .seealso: [](ch_matrices), `MatSOR()`
1659: E*/
1660: typedef enum {
1661:   SOR_FORWARD_SWEEP         = 1,
1662:   SOR_BACKWARD_SWEEP        = 2,
1663:   SOR_SYMMETRIC_SWEEP       = 3,
1664:   SOR_LOCAL_FORWARD_SWEEP   = 4,
1665:   SOR_LOCAL_BACKWARD_SWEEP  = 8,
1666:   SOR_LOCAL_SYMMETRIC_SWEEP = 12,
1667:   SOR_ZERO_INITIAL_GUESS    = 16,
1668:   SOR_EISENSTAT             = 32,
1669:   SOR_APPLY_UPPER           = 64,
1670:   SOR_APPLY_LOWER           = 128
1671: } MatSORType;
1672: PETSC_EXTERN PetscErrorCode MatSOR(Mat, Vec, PetscReal, MatSORType, PetscReal, PetscInt, PetscInt, Vec);

1674: /*S
1675:    MatColoring - Object for managing the coloring of matrices.

1677:    Level: beginner

1679:    Notes:
1680:    Coloring of matrices can be computed directly from the sparse matrix nonzero structure via the `MatColoring` object or from the mesh from which the
1681:    matrix comes from via `DMCreateColoring()`. In general using the mesh produces a more optimal coloring (fewer colors).

1683:    Once a coloring is available `MatFDColoringCreate()` creates an object that can be used to efficiently compute Jacobians using that coloring. This
1684:    same object can also be used to efficiently convert data created by Automatic Differentiation tools to PETSc sparse matrices.

1686: .seealso: [](ch_matrices), [](sec_graph), `MatFDColoringCreate()`, `MatColoringWeightType`, `ISColoring`, `MatFDColoring`, `DMCreateColoring()`, `MatColoringCreate()`,
1687:           `MatPartitioning`, `MatColoringType`, `MatPartitioningType`, `MatOrderingType`, `MatColoringSetWeightType()`,
1688:           `MatColoringSetWeights()`, `MatCoarsenType`, `MatCoarsen`
1689: S*/
1690: typedef struct _p_MatColoring *MatColoring;

1692: /*J
1693:    MatColoringType - String with the name of a PETSc matrix coloring

1695:    Level: beginner

1697: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatFDColoringCreate()`, `MatColoringSetType()`, `MatColoring`
1698: J*/
1699: typedef const char *MatColoringType;
1700: #define MATCOLORINGJP      "jp"
1701: #define MATCOLORINGPOWER   "power"
1702: #define MATCOLORINGNATURAL "natural"
1703: #define MATCOLORINGSL      "sl"
1704: #define MATCOLORINGLF      "lf"
1705: #define MATCOLORINGID      "id"
1706: #define MATCOLORINGGREEDY  "greedy"

1708: /*E
1709:    MatColoringWeightType - Type of weight scheme used for the coloring algorithm

1711:    Values:
1712: +  `MAT_COLORING_RANDOM`  - Random weights
1713: .  `MAT_COLORING_LEXICAL` - Lexical weighting based upon global numbering.
1714: -  `MAT_COLORING_LF`      - Last-first weighting.

1716:     Level: intermediate

1718: .seealso: [](ch_matrices), `MatColoring`, `MatColoringCreate()`, `MatColoringSetWeightType()`, `MatColoringSetWeights()`
1719: E*/
1720: typedef enum {
1721:   MAT_COLORING_WEIGHT_RANDOM,
1722:   MAT_COLORING_WEIGHT_LEXICAL,
1723:   MAT_COLORING_WEIGHT_LF,
1724:   MAT_COLORING_WEIGHT_SL
1725: } MatColoringWeightType;

1727: PETSC_EXTERN PetscErrorCode MatColoringCreate(Mat, MatColoring *);
1728: PETSC_EXTERN PetscErrorCode MatColoringGetDegrees(Mat, PetscInt, PetscInt *);
1729: PETSC_EXTERN PetscErrorCode MatColoringDestroy(MatColoring *);
1730: PETSC_EXTERN PetscErrorCode MatColoringView(MatColoring, PetscViewer);
1731: PETSC_EXTERN PetscErrorCode MatColoringSetType(MatColoring, MatColoringType);
1732: PETSC_EXTERN PetscErrorCode MatColoringSetFromOptions(MatColoring);
1733: PETSC_EXTERN PetscErrorCode MatColoringSetDistance(MatColoring, PetscInt);
1734: PETSC_EXTERN PetscErrorCode MatColoringGetDistance(MatColoring, PetscInt *);
1735: PETSC_EXTERN PetscErrorCode MatColoringSetMaxColors(MatColoring, PetscInt);
1736: PETSC_EXTERN PetscErrorCode MatColoringGetMaxColors(MatColoring, PetscInt *);
1737: PETSC_EXTERN PetscErrorCode MatColoringApply(MatColoring, ISColoring *);
1738: PETSC_EXTERN PetscErrorCode MatColoringRegister(const char[], PetscErrorCode (*)(MatColoring));
1739: PETSC_EXTERN PetscErrorCode MatColoringPatch(Mat, PetscInt, PetscInt, ISColoringValue[], ISColoring *);
1740: PETSC_EXTERN PetscErrorCode MatColoringSetWeightType(MatColoring, MatColoringWeightType);
1741: PETSC_EXTERN PetscErrorCode MatColoringSetWeights(MatColoring, PetscReal *, PetscInt *);
1742: PETSC_EXTERN PetscErrorCode MatColoringCreateWeights(MatColoring, PetscReal **, PetscInt **lperm);
1743: PETSC_EXTERN PetscErrorCode MatColoringTest(MatColoring, ISColoring);
1744: PETSC_DEPRECATED_FUNCTION(3, 10, 0, "MatColoringTest()", ) static inline PetscErrorCode MatColoringTestValid(MatColoring matcoloring, ISColoring iscoloring)
1745: {
1746:   return MatColoringTest(matcoloring, iscoloring);
1747: }
1748: PETSC_EXTERN PetscErrorCode MatISColoringTest(Mat, ISColoring);

1750: /*S
1751:    MatFDColoring - Object for computing a sparse Jacobian via finite differences with coloring

1753:    Level: beginner

1755:    Options Database Key:
1756: .  -snes_fd_coloring - cause the Jacobian needed by `SNES` to be computed via a use of this object

1758:    Note:
1759:    This object is created utilizing a coloring provided by the `MatColoring` object or `DMCreateColoring()`

1761: .seealso: [](ch_matrices), `Mat`, `MatFDColoringCreate()`, `MatFDColoringSetFunction()`, `MatColoring`, `DMCreateColoring()`
1762: S*/
1763: typedef struct _p_MatFDColoring *MatFDColoring;

1765: /*S
1766:   MatFDColoringFn - Function provided to `MatFDColoringSetFunction()` that computes the function being differenced

1768:   Level: advanced

1770:   Calling Sequence:
1771: + snes - either a `SNES` object if used within `SNES` otherwise an unused parameter
1772: . in   - the location where the Jacobian is to be computed
1773: . out  - the location to put the computed function value
1774: - fctx - the function context passed into `MatFDColoringSetFunction()`

1776: .seealso: [](ch_matrices), `Mat`, `MatCreateMFFD()`, `MatMFFDSetFunction()`, `MatMFFDiFn`, `MatMFFDiBaseFn`
1777: S*/
1778: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatFDColoringFn(void *snes, Vec x, Vec y, void *fctx);

1780: PETSC_EXTERN PetscErrorCode MatFDColoringCreate(Mat, ISColoring, MatFDColoring *);
1781: PETSC_EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring *);
1782: PETSC_EXTERN PetscErrorCode MatFDColoringView(MatFDColoring, PetscViewer);
1783: PETSC_EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring, MatFDColoringFn *, void *);
1784: PETSC_EXTERN PetscErrorCode MatFDColoringGetFunction(MatFDColoring, MatFDColoringFn **, void **);
1785: PETSC_EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring, PetscReal, PetscReal);
1786: PETSC_EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring);
1787: PETSC_EXTERN PetscErrorCode MatFDColoringApply(Mat, MatFDColoring, Vec, void *);
1788: PETSC_EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring, Vec);
1789: PETSC_EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring, PetscInt *, const PetscInt *[]);
1790: PETSC_EXTERN PetscErrorCode MatFDColoringSetUp(Mat, ISColoring, MatFDColoring);
1791: PETSC_EXTERN PetscErrorCode MatFDColoringSetBlockSize(MatFDColoring, PetscInt, PetscInt);
1792: PETSC_EXTERN PetscErrorCode MatFDColoringSetValues(Mat, MatFDColoring, const PetscScalar *);

1794: /*S
1795:    MatTransposeColoring - Object for computing a sparse matrix product $C = A*B^T$ via coloring

1797:    Level: developer

1799: .seealso: [](ch_matrices), `Mat`, `MatProductType`, `MatTransposeColoringCreate()`
1800: S*/
1801: typedef struct _p_MatTransposeColoring *MatTransposeColoring;

1803: PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat, ISColoring, MatTransposeColoring *);
1804: PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring, Mat, Mat);
1805: PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring, Mat, Mat);
1806: PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring *);

1808: /*S
1809:    MatPartitioning - Object for managing the partitioning of a matrix or graph

1811:    Level: beginner

1813:    Note:
1814:    There is also a `PetscPartitioner` object that provides the same functionality. It can utilize the `MatPartitioning` operations
1815:    via `PetscPartitionerSetType`(p,`PETSCPARTITIONERMATPARTITIONING`)

1817:    Developer Note:
1818:    It is an extra maintenance and documentation cost to have two objects with the same functionality. `PetscPartitioner` should be removed

1820: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioningType`, `MatColoring`, `MatGetOrdering()`, `MatOrderingType`,
1821:           `MatCoarsenType`
1822: S*/
1823: typedef struct _p_MatPartitioning *MatPartitioning;

1825: /*J
1826:     MatPartitioningType - String with the name of a PETSc matrix partitioning

1828:    Level: beginner
1829: dm
1830: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioning`, `MatPartitioningSetType()`, `MatColoringType`, `MatOrderingType`,
1831:           `MatCoarsenType`
1832: J*/
1833: typedef const char *MatPartitioningType;
1834: #define MATPARTITIONINGCURRENT  "current"
1835: #define MATPARTITIONINGAVERAGE  "average"
1836: #define MATPARTITIONINGSQUARE   "square"
1837: #define MATPARTITIONINGPARMETIS "parmetis"
1838: #define MATPARTITIONINGCHACO    "chaco"
1839: #define MATPARTITIONINGPARTY    "party"
1840: #define MATPARTITIONINGPTSCOTCH "ptscotch"
1841: #define MATPARTITIONINGHIERARCH "hierarch"

1843: PETSC_EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm, MatPartitioning *);
1844: PETSC_EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning, MatPartitioningType);
1845: PETSC_EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning, PetscInt);
1846: PETSC_EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning, Mat);
1847: PETSC_EXTERN PetscErrorCode MatPartitioningSetNumberVertexWeights(MatPartitioning, PetscInt);
1848: PETSC_EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning, const PetscInt[]);
1849: PETSC_EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning, const PetscReal[]);
1850: PETSC_EXTERN PetscErrorCode MatPartitioningSetUseEdgeWeights(MatPartitioning, PetscBool);
1851: PETSC_EXTERN PetscErrorCode MatPartitioningGetUseEdgeWeights(MatPartitioning, PetscBool *);
1852: PETSC_EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning, IS *);
1853: PETSC_EXTERN PetscErrorCode MatPartitioningImprove(MatPartitioning, IS *);
1854: PETSC_EXTERN PetscErrorCode MatPartitioningViewImbalance(MatPartitioning, IS);
1855: PETSC_EXTERN PetscErrorCode MatPartitioningApplyND(MatPartitioning, IS *);
1856: PETSC_EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning *);
1857: PETSC_EXTERN PetscErrorCode MatPartitioningRegister(const char[], PetscErrorCode (*)(MatPartitioning));
1858: PETSC_EXTERN PetscErrorCode MatPartitioningView(MatPartitioning, PetscViewer);
1859: PETSC_EXTERN PetscErrorCode MatPartitioningViewFromOptions(MatPartitioning, PetscObject, const char[]);
1860: PETSC_EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning);
1861: PETSC_EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning, MatPartitioningType *);

1863: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetRepartition(MatPartitioning);
1864: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1865: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *);

1867: /*E
1868:    MPChacoGlobalType - Global partitioning method used by `MATPARTITIONINGCHACO` when delegating to the Chaco library

1870:    Values:
1871: +   `MP_CHACO_MULTILEVEL` - multilevel-Kernighan--Lin style partitioning
1872: .   `MP_CHACO_SPECTRAL`   - spectral partitioning using Lanczos or RQI eigensolvers
1873: .   `MP_CHACO_LINEAR`     - linear (rank-order) initial partition
1874: .   `MP_CHACO_RANDOM`     - random initial partition
1875: -   `MP_CHACO_SCATTERED`  - scattered (round-robin) initial partition

1877:    Level: intermediate

1879: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetGlobal()`, `MatPartitioningChacoGetGlobal()`,
1880:           `MPChacoLocalType`, `MPChacoEigenType`
1881: E*/
1882: typedef enum {
1883:   MP_CHACO_MULTILEVEL = 1,
1884:   MP_CHACO_SPECTRAL   = 2,
1885:   MP_CHACO_LINEAR     = 4,
1886:   MP_CHACO_RANDOM     = 5,
1887:   MP_CHACO_SCATTERED  = 6
1888: } MPChacoGlobalType;
1889: PETSC_EXTERN const char *const MPChacoGlobalTypes[];
1890: /*E
1891:    MPChacoLocalType - Local refinement method used by `MATPARTITIONINGCHACO` after the global partition has been chosen

1893:    Values:
1894: +   `MP_CHACO_KERNIGHAN` - apply Kernighan--Lin local refinement to improve the partition
1895: -   `MP_CHACO_NONE`      - no local refinement

1897:    Level: intermediate

1899: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetLocal()`, `MatPartitioningChacoGetLocal()`,
1900:           `MPChacoGlobalType`
1901: E*/
1902: typedef enum {
1903:   MP_CHACO_KERNIGHAN = 1,
1904:   MP_CHACO_NONE      = 2
1905: } MPChacoLocalType;
1906: PETSC_EXTERN const char *const MPChacoLocalTypes[];
1907: /*E
1908:    MPChacoEigenType - Eigensolver used by `MATPARTITIONINGCHACO` when the global partitioning method is `MP_CHACO_SPECTRAL`

1910:    Values:
1911: +   `MP_CHACO_LANCZOS` - Lanczos algorithm
1912: -   `MP_CHACO_RQI`     - Rayleigh quotient iteration

1914:    Level: intermediate

1916: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenSolver()`, `MatPartitioningChacoGetEigenSolver()`,
1917:           `MPChacoGlobalType`
1918: E*/
1919: typedef enum {
1920:   MP_CHACO_LANCZOS = 0,
1921:   MP_CHACO_RQI     = 1
1922: } MPChacoEigenType;
1923: PETSC_EXTERN const char *const MPChacoEigenTypes[];

1925: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning, MPChacoGlobalType);
1926: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning, MPChacoGlobalType *);
1927: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning, MPChacoLocalType);
1928: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning, MPChacoLocalType *);
1929: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning, PetscReal);
1930: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning, MPChacoEigenType);
1931: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning, MPChacoEigenType *);
1932: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning, PetscReal);
1933: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning, PetscReal *);
1934: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning, PetscInt);
1935: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning, PetscInt *);

1937: #define MP_PARTY_OPT "opt"
1938: #define MP_PARTY_LIN "lin"
1939: #define MP_PARTY_SCA "sca"
1940: #define MP_PARTY_RAN "ran"
1941: #define MP_PARTY_GBF "gbf"
1942: #define MP_PARTY_GCF "gcf"
1943: #define MP_PARTY_BUB "bub"
1944: #define MP_PARTY_DEF "def"
1945: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning, const char *);
1946: #define MP_PARTY_HELPFUL_SETS  "hs"
1947: #define MP_PARTY_KERNIGHAN_LIN "kl"
1948: #define MP_PARTY_NONE          "no"
1949: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning, const char *);
1950: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning, PetscReal);
1951: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning, PetscBool);
1952: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning, PetscBool);

1954: /*E
1955:    MPPTScotchStrategyType - Pre-defined strategy used by `MATPARTITIONINGPTSCOTCH` when delegating to the PT-Scotch library

1957:    Values:
1958: +   `MP_PTSCOTCH_DEFAULT`     - the default PT-Scotch strategy
1959: .   `MP_PTSCOTCH_QUALITY`     - focus on partition quality at the expense of time
1960: .   `MP_PTSCOTCH_SPEED`       - focus on time to compute the partition
1961: .   `MP_PTSCOTCH_BALANCE`     - favor load balance
1962: .   `MP_PTSCOTCH_SAFETY`      - use the most reliable internal heuristics
1963: -   `MP_PTSCOTCH_SCALABILITY` - favor scalability at large process counts

1965:    Level: intermediate

1967: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGPTSCOTCH`, `MatPartitioningPTScotchSetStrategy()`, `MatPartitioningPTScotchGetStrategy()`
1968: E*/
1969: typedef enum {
1970:   MP_PTSCOTCH_DEFAULT,
1971:   MP_PTSCOTCH_QUALITY,
1972:   MP_PTSCOTCH_SPEED,
1973:   MP_PTSCOTCH_BALANCE,
1974:   MP_PTSCOTCH_SAFETY,
1975:   MP_PTSCOTCH_SCALABILITY
1976: } MPPTScotchStrategyType;
1977: PETSC_EXTERN const char *const MPPTScotchStrategyTypes[];

1979: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning, PetscReal);
1980: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning, PetscReal *);
1981: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning, MPPTScotchStrategyType);
1982: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning, MPPTScotchStrategyType *);

1984: /*
1985:  * hierarchical partitioning
1986:  */
1987: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetFineparts(MatPartitioning, IS *);
1988: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetCoarseparts(MatPartitioning, IS *);
1989: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNcoarseparts(MatPartitioning, PetscInt);
1990: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNfineparts(MatPartitioning, PetscInt);

1992: typedef const char *MatMeshToCellGraphType;
1993: #define MATMESHTOCELLGRAPHMETIS    "metis"
1994: #define MATMESHTOCELLGRAPHPARMETIS "parmetis"

1996: PETSC_EXTERN PetscErrorCode MatMeshToCellGraph(Mat, PetscInt, Mat *);
1997: PETSC_EXTERN PetscErrorCode MatMeshToCellGraphRegister(const char[], PetscErrorCode (*)(Mat, PetscInt, Mat *));

1999: /*E
2000:    MatOperation - Identifies one of the operations stored in a `Mat`'s function table, for example `MATOP_MULT` or `MATOP_LUFACTOR`

2002:    Level: developer

2004:    Notes:
2005:    Use `MatSetOperation()` to install a custom implementation of a given operation on a `Mat` (typically a `MATSHELL`), `MatGetOperation()` to retrieve the currently installed implementation, and `MatHasOperation()` to test whether one is installed.

2007:    The numeric values are part of the binary interface used by the petsc4py bindings; if any of these enum values are changed, the `dMatOps` dictionary in `src/binding/petsc4py/src/petsc4py/PETSc/libpetsc4py.pyx` must be updated to match.

2009: .seealso: [](ch_matrices), `Mat`, `MATSHELL`, `MatSetOperation()`, `MatGetOperation()`, `MatHasOperation()`,
2010:           `MatShellSetOperation()`, `MatShellGetOperation()`
2011: E*/
2012: typedef enum {
2013:   MATOP_SET_VALUES                = 0,
2014:   MATOP_GET_ROW                   = 1,
2015:   MATOP_RESTORE_ROW               = 2,
2016:   MATOP_MULT                      = 3,
2017:   MATOP_MULT_ADD                  = 4,
2018:   MATOP_MULT_TRANSPOSE            = 5,
2019:   MATOP_MULT_TRANSPOSE_ADD        = 6,
2020:   MATOP_SOLVE                     = 7,
2021:   MATOP_SOLVE_ADD                 = 8,
2022:   MATOP_SOLVE_TRANSPOSE           = 9,
2023:   MATOP_SOLVE_TRANSPOSE_ADD       = 10,
2024:   MATOP_LUFACTOR                  = 11,
2025:   MATOP_CHOLESKYFACTOR            = 12,
2026:   MATOP_SOR                       = 13,
2027:   MATOP_TRANSPOSE                 = 14,
2028:   MATOP_GETINFO                   = 15,
2029:   MATOP_EQUAL                     = 16,
2030:   MATOP_GET_DIAGONAL              = 17,
2031:   MATOP_DIAGONAL_SCALE            = 18,
2032:   MATOP_NORM                      = 19,
2033:   MATOP_ASSEMBLY_BEGIN            = 20,
2034:   MATOP_ASSEMBLY_END              = 21,
2035:   MATOP_SET_OPTION                = 22,
2036:   MATOP_ZERO_ENTRIES              = 23,
2037:   MATOP_ZERO_ROWS                 = 24,
2038:   MATOP_LUFACTOR_SYMBOLIC         = 25,
2039:   MATOP_LUFACTOR_NUMERIC          = 26,
2040:   MATOP_CHOLESKY_FACTOR_SYMBOLIC  = 27,
2041:   MATOP_CHOLESKY_FACTOR_NUMERIC   = 28,
2042:   MATOP_SETUP                     = 29,
2043:   MATOP_ILUFACTOR_SYMBOLIC        = 30,
2044:   MATOP_ICCFACTOR_SYMBOLIC        = 31,
2045:   MATOP_GET_DIAGONAL_BLOCK        = 32,
2046:   MATOP_SET_INF                   = 33,
2047:   MATOP_DUPLICATE                 = 34,
2048:   MATOP_FORWARD_SOLVE             = 35,
2049:   MATOP_BACKWARD_SOLVE            = 36,
2050:   MATOP_ILUFACTOR                 = 37,
2051:   MATOP_ICCFACTOR                 = 38,
2052:   MATOP_AXPY                      = 39,
2053:   MATOP_CREATE_SUBMATRICES        = 40,
2054:   MATOP_INCREASE_OVERLAP          = 41,
2055:   MATOP_GET_VALUES                = 42,
2056:   MATOP_COPY                      = 43,
2057:   MATOP_GET_ROW_MAX               = 44,
2058:   MATOP_SCALE                     = 45,
2059:   MATOP_SHIFT                     = 46,
2060:   MATOP_DIAGONAL_SET              = 47,
2061:   MATOP_ZERO_ROWS_COLUMNS         = 48,
2062:   MATOP_SET_RANDOM                = 49,
2063:   MATOP_GET_ROW_IJ                = 50,
2064:   MATOP_RESTORE_ROW_IJ            = 51,
2065:   MATOP_GET_COLUMN_IJ             = 52,
2066:   MATOP_RESTORE_COLUMN_IJ         = 53,
2067:   MATOP_FDCOLORING_CREATE         = 54,
2068:   MATOP_COLORING_PATCH            = 55,
2069:   MATOP_SET_UNFACTORED            = 56,
2070:   MATOP_PERMUTE                   = 57,
2071:   MATOP_SET_VALUES_BLOCKED        = 58,
2072:   MATOP_CREATE_SUBMATRIX          = 59,
2073:   MATOP_DESTROY                   = 60,
2074:   MATOP_VIEW                      = 61,
2075:   MATOP_CONVERT_FROM              = 62,
2076:   MATOP_MATMAT_MULT_SYMBOLIC      = 63,
2077:   MATOP_MATMAT_MULT_NUMERIC       = 64,
2078:   MATOP_SET_LOCAL_TO_GLOBAL_MAP   = 65,
2079:   MATOP_SET_VALUES_LOCAL          = 66,
2080:   MATOP_ZERO_ROWS_LOCAL           = 67,
2081:   MATOP_GET_ROW_MAX_ABS           = 68,
2082:   MATOP_GET_ROW_MIN_ABS           = 69,
2083:   MATOP_CONVERT                   = 70,
2084:   MATOP_HAS_OPERATION             = 71,
2085:   MATOP_FD_COLORING_APPLY         = 72,
2086:   MATOP_SET_FROM_OPTIONS          = 73,
2087:   MATOP_FIND_ZERO_DIAGONALS       = 74,
2088:   MATOP_MULT_MULTIPLE             = 75,
2089:   MATOP_SOLVE_MULTIPLE            = 76,
2090:   MATOP_GET_INERTIA               = 77,
2091:   MATOP_LOAD                      = 78,
2092:   MATOP_IS_SYMMETRIC              = 79,
2093:   MATOP_IS_HERMITIAN              = 80,
2094:   MATOP_IS_STRUCTURALLY_SYMMETRIC = 81,
2095:   MATOP_SET_VALUES_BLOCKEDLOCAL   = 82,
2096:   MATOP_CREATE_VECS               = 83,
2097:   MATOP_MAT_MULT_SYMBOLIC         = 84,
2098:   MATOP_MAT_MULT_NUMERIC          = 85,
2099:   MATOP_PTAP_NUMERIC              = 86,
2100:   MATOP_MAT_TRANSPOSE_MULT_SYMBO  = 87,
2101:   MATOP_MAT_TRANSPOSE_MULT_NUMER  = 88,
2102:   MATOP_BIND_TO_CPU               = 89,
2103:   MATOP_PRODUCTSETFROMOPTIONS     = 90,
2104:   MATOP_PRODUCTSYMBOLIC           = 91,
2105:   MATOP_PRODUCTNUMERIC            = 92,
2106:   MATOP_CONJUGATE                 = 93,
2107:   MATOP_VIEW_NATIVE               = 94,
2108:   MATOP_SET_VALUES_ROW            = 95,
2109:   MATOP_REAL_PART                 = 96,
2110:   MATOP_IMAGINARY_PART            = 97,
2111:   MATOP_GET_ROW_UPPER_TRIANGULAR  = 98,
2112:   MATOP_RESTORE_ROW_UPPER_TRIANG  = 99,
2113:   MATOP_MAT_SOLVE                 = 100,
2114:   MATOP_MAT_SOLVE_TRANSPOSE       = 101,
2115:   MATOP_GET_ROW_MIN               = 102,
2116:   MATOP_GET_COLUMN_VECTOR         = 103,
2117:   MATOP_GET_SEQ_NONZERO_STRUCTUR  = 104,
2118:   MATOP_CREATE                    = 105,
2119:   MATOP_GET_GHOSTS                = 106,
2120:   MATOP_GET_LOCAL_SUB_MATRIX      = 107,
2121:   MATOP_RESTORE_LOCALSUB_MATRIX   = 108,
2122:   MATOP_MULT_DIAGONAL_BLOCK       = 109,
2123:   MATOP_HERMITIAN_TRANSPOSE       = 110,
2124:   MATOP_MULT_HERMITIAN_TRANSPOSE  = 111,
2125:   MATOP_MULT_HERMITIAN_TRANS_ADD  = 112,
2126:   MATOP_GET_MULTI_PROC_BLOCK      = 113,
2127:   MATOP_FIND_NONZERO_ROWS         = 114,
2128:   MATOP_GET_COLUMN_NORMS          = 115,
2129:   MATOP_INVERT_BLOCK_DIAGONAL     = 116,
2130:   MATOP_INVERT_VBLOCK_DIAGONAL    = 117,
2131:   MATOP_CREATE_SUB_MATRICES_MPI   = 118,
2132:   MATOP_TRANSPOSE_MAT_MULT_SYMBO  = 119,
2133:   MATOP_TRANSPOSE_MAT_MULT_NUMER  = 120,
2134:   MATOP_TRANSPOSE_COLORING_CREAT  = 121,
2135:   MATOP_TRANS_COLORING_APPLY_SPT  = 122,
2136:   MATOP_TRANS_COLORING_APPLY_DEN  = 123,
2137:   MATOP_RART_NUMERIC              = 124,
2138:   MATOP_SET_BLOCK_SIZES           = 125,
2139:   MATOP_RESIDUAL                  = 126,
2140:   MATOP_FDCOLORING_SETUP          = 127,
2141:   MATOP_FIND_OFFBLOCK_ENTRIES     = 128,
2142:   MATOP_MPICONCATENATESEQ         = 129,
2143:   MATOP_DESTROYSUBMATRICES        = 130,
2144:   MATOP_MAT_TRANSPOSE_SOLVE       = 131,
2145:   MATOP_GET_VALUES_LOCAL          = 132,
2146:   MATOP_CREATE_GRAPH              = 133,
2147:   MATOP_TRANSPOSE_SYMBOLIC        = 134,
2148:   MATOP_ELIMINATE_ZEROS           = 135,
2149:   MATOP_GET_ROW_SUM_ABS           = 136,
2150:   MATOP_GET_FACTOR                = 137,
2151:   MATOP_GET_BLOCK_DIAGONAL        = 138, /* NOTE: caller of the two op functions owns the returned matrix */
2152:   MATOP_GET_VBLOCK_DIAGONAL       = 139, /* and need to destroy it after use. */
2153:   MATOP_COPY_HASH_TO_XAIJ         = 140,
2154:   MATOP_GET_CURRENT_MEM_TYPE      = 141,
2155:   MATOP_ZERO_ROWS_COLUMNS_LOCAL   = 142,
2156:   MATOP_ADOT                      = 143,
2157:   MATOP_ANORM                     = 144,
2158:   MATOP_ADOT_LOCAL                = 145,
2159:   MATOP_ANORM_LOCAL               = 146,
2160:   MATOP_GET_ORDERING              = 147
2161: } MatOperation;

2163: PETSC_EXTERN PetscErrorCode MatSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2164: PETSC_EXTERN PetscErrorCode MatGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2165: PETSC_EXTERN PetscErrorCode MatHasOperation(Mat, MatOperation, PetscBool *);
2166: PETSC_EXTERN PetscErrorCode MatHasCongruentLayouts(Mat, PetscBool *);
2167: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatProductClear()", ) static inline PetscErrorCode MatFreeIntermediateDataStructures(Mat A)
2168: {
2169:   return MatProductClear(A);
2170: }
2171: PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2172: PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2173: PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat, PetscCtx);
2174: PETSC_EXTERN PetscErrorCode MatShellSetContextDestroy(Mat, PetscCtxDestroyFn *);
2175: PETSC_EXTERN PetscErrorCode MatShellSetVecType(Mat, VecType);
2176: PETSC_EXTERN PetscErrorCode MatShellTestMult(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2177: PETSC_EXTERN PetscErrorCode MatShellTestMultTranspose(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2178: PETSC_EXTERN PetscErrorCode MatShellSetManageScalingShifts(Mat);
2179: PETSC_EXTERN PetscErrorCode MatShellSetMatProductOperation(Mat, MatProductType, PetscErrorCode (*)(Mat, Mat, Mat, void **), PetscErrorCode (*)(Mat, Mat, Mat, void *), PetscCtxDestroyFn *, MatType, MatType);
2180: PETSC_EXTERN PetscErrorCode MatIsShell(Mat, PetscBool *);

2182: /*
2183:    Codes for matrices stored on disk. By default they are
2184:    stored in a universal format. By changing the format with
2185:    PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will
2186:    be stored in a way natural for the matrix, for example dense matrices
2187:    would be stored as dense. Matrices stored this way may only be
2188:    read into matrices of the same type.
2189: */
2190: #define MATRIX_BINARY_FORMAT_DENSE -1

2192: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat, PetscReal);

2194: PETSC_EXTERN PetscErrorCode MatISSetLocalMatType(Mat, MatType);
2195: PETSC_EXTERN PetscErrorCode MatISSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
2196: PETSC_EXTERN PetscErrorCode MatISSetAllowRepeated(Mat, PetscBool);
2197: PETSC_EXTERN PetscErrorCode MatISGetAllowRepeated(Mat, PetscBool *);
2198: PETSC_EXTERN PetscErrorCode MatISStoreL2L(Mat, PetscBool);
2199: PETSC_EXTERN PetscErrorCode MatISFixLocalEmpty(Mat, PetscBool);
2200: PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat, Mat *);
2201: PETSC_EXTERN PetscErrorCode MatISRestoreLocalMat(Mat, Mat *);
2202: PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat, Mat);
2203: PETSC_EXTERN PetscErrorCode MatISGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *);

2205: /*S
2206:    MatNullSpace - Object that removes a null space from a vector, i.e.
2207:                   orthogonalizes the vector to a subspace

2209:    Level: advanced

2211: .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()`
2212: S*/
2213: typedef struct _p_MatNullSpace *MatNullSpace;

2215: /*S
2216:   MatNullSpaceRemoveFn - Function provided to `MatNullSpaceSetFunction()` that removes the null space from a vector

2218:   Level: advanced

2220:   Calling Sequence:
2221: + nsp - the `MatNullSpace` object
2222: . x   - the vector from which to remove the null space
2223: - ctx - [optional] user-defined function context provided with `MatNullSpaceSetFunction()`

2225: .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()`
2226: S*/
2227: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatNullSpaceRemoveFn(MatNullSpace nsp, Vec x, PetscCtx ctx);

2229: PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm, PetscBool, PetscInt, const Vec[], MatNullSpace *);
2230: PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace, MatNullSpaceRemoveFn *, void *);
2231: PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace *);
2232: PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace, Vec);
2233: PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *);
2234: PETSC_EXTERN PetscErrorCode MatGetTransposeNullSpace(Mat, MatNullSpace *);
2235: PETSC_EXTERN PetscErrorCode MatSetTransposeNullSpace(Mat, MatNullSpace);
2236: PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat, MatNullSpace);
2237: PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat, MatNullSpace);
2238: PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat, MatNullSpace *);
2239: PETSC_EXTERN PetscErrorCode MatGetNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2240: PETSC_EXTERN PetscErrorCode MatRestoreNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2241: PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace, Mat, PetscBool *);
2242: PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace, PetscViewer);
2243: PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace, PetscBool *, PetscInt *, const Vec **);
2244: PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec, MatNullSpace *);

2246: PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat, IS);
2247: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat, PetscReal);
2248: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat, PetscInt *);

2250: PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat, PetscInt, Mat *);
2251: PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat, PetscInt, Mat *);
2252: PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat, Mat *);

2254: PETSC_EXTERN PetscErrorCode MatComputeOperator(Mat, MatType, Mat *);
2255: PETSC_EXTERN PetscErrorCode MatComputeOperatorTranspose(Mat, MatType, Mat *);

2257: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperator()", ) static inline PetscErrorCode MatComputeExplicitOperator(Mat A, Mat *B)
2258: {
2259:   return MatComputeOperator(A, PETSC_NULLPTR, B);
2260: }
2261: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperatorTranspose()", ) static inline PetscErrorCode MatComputeExplicitOperatorTranspose(Mat A, Mat *B)
2262: {
2263:   return MatComputeOperatorTranspose(A, PETSC_NULLPTR, B);
2264: }

2266: PETSC_EXTERN PetscErrorCode MatCreateKAIJ(Mat, PetscInt, PetscInt, const PetscScalar[], const PetscScalar[], Mat *);
2267: PETSC_EXTERN PetscErrorCode MatKAIJGetAIJ(Mat, Mat *);
2268: PETSC_EXTERN PetscErrorCode MatKAIJGetS(Mat, PetscInt *, PetscInt *, PetscScalar **);
2269: PETSC_EXTERN PetscErrorCode MatKAIJGetSRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2270: PETSC_EXTERN PetscErrorCode MatKAIJRestoreS(Mat, PetscScalar **);
2271: PETSC_EXTERN PetscErrorCode MatKAIJRestoreSRead(Mat, const PetscScalar **);
2272: PETSC_EXTERN PetscErrorCode MatKAIJGetT(Mat, PetscInt *, PetscInt *, PetscScalar **);
2273: PETSC_EXTERN PetscErrorCode MatKAIJGetTRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2274: PETSC_EXTERN PetscErrorCode MatKAIJRestoreT(Mat, PetscScalar **);
2275: PETSC_EXTERN PetscErrorCode MatKAIJRestoreTRead(Mat, const PetscScalar **);
2276: PETSC_EXTERN PetscErrorCode MatKAIJSetAIJ(Mat, Mat);
2277: PETSC_EXTERN PetscErrorCode MatKAIJSetS(Mat, PetscInt, PetscInt, const PetscScalar[]);
2278: PETSC_EXTERN PetscErrorCode MatKAIJSetT(Mat, PetscInt, PetscInt, const PetscScalar[]);
2279: PETSC_EXTERN PetscErrorCode MatKAIJGetScaledIdentity(Mat, PetscBool *);

2281: PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat, Vec);

2283: PETSC_EXTERN PetscErrorCode MatMFFDInitializePackage(void);
2284: PETSC_EXTERN PetscErrorCode MatMFFDFinalizePackage(void);

2286: /*S
2287:   MatMFFDFn - Function provided to `MatMFFDSetFunction()` that computes the function being differenced

2289:   Level: advanced

2291:   Calling Sequence:
2292: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2293: . x   - input vector
2294: - y   - output vector

2296: .seealso: [](ch_matrices), `Mat`, `MatCreateMFFD()`, `MatMFFDSetFunction()`, `MatMFFDiFn`, `MatMFFDiBaseFn`
2297: S*/
2298: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatMFFDFn(PetscCtx ctx, Vec x, Vec y);

2300: /*S
2301:   MatMFFDiFn - Function provided to `MatMFFDSetFunctioni()` that computes the function being differenced at a single point

2303:   Level: advanced

2305:   Calling Sequence:
2306: + ctx    - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2307: . i      - the component of the vector to compute
2308: . x      - input vector
2309: - result - the value of the function at that component (output)

2311: .seealso: [](ch_matrices), `Mat`, `MatCreateMFFD()`, `MatMFFDSetFunction()`, `MatMFFDFn`, `MatMFFDiBaseFn`
2312: S*/
2313: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatMFFDiFn(PetscCtx ctx, PetscInt i, Vec x, PetscScalar *result);

2315: /*S
2316:   MatMFFDiBaseFn - Function provided to `MatMFFDSetFunctioniBase()` that computes the base of the function evaluations
2317:   that will be used for differencing

2319:   Level: advanced

2321:   Calling Sequence:
2322: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2323: - x   - input base vector

2325: .seealso: [](ch_matrices), `Mat`, `MatCreateMFFD()`, `MatMFFDSetFunction()`, `MatMFFDSetFunctioniBase()`, `MatMFFDFn`, `MatMFFDiFn`
2326: S*/
2327: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatMFFDiBaseFn(PetscCtx ctx, Vec x);

2329: /*S
2330:   MatMFFDCheckhFn - Function provided to `MatMFFDSetCheckh()` that checks and possibly adjusts the value of `h` to ensure some property.
2331:   that will be used for differencing

2333:   Level: advanced

2335:   Calling Sequence:
2336: + ctx - [optional] user-defined function context provided with `MatMFFDSetCheckh()`
2337: . x   - input base vector
2338: . y   - input step vector that the product is computed with
2339: - h   - input tentative step, output possibly adjusted step

2341:   Note:
2342:   `MatMFFDCheckPositivity()` is one such function

2344: .seealso: [](ch_matrices), `Mat`, `MatCreateMFFD()`, `MatMFFDSetCheckh()`, `MatMFFDCheckPositivity()`
2345: S*/
2346: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatMFFDCheckhFn(PetscCtx ctx, Vec x, Vec y, PetscScalar *h);

2348: PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2349: PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat, Vec, Vec);
2350: PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat, MatMFFDFn *, void *);
2351: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat, MatMFFDiFn *);
2352: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat, MatMFFDiBaseFn *);
2353: PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat, PetscScalar[], PetscInt);
2354: PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat);
2355: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat, PetscReal);
2356: PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat, PetscInt);
2357: PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat, PetscScalar *);
2358: PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat, const char[]);
2359: PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void *, Vec, Vec, PetscScalar *);
2360: PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat, MatMFFDCheckhFn *, void *);

2362: /*S
2363:     MatMFFD - A data structured used to manage the computation of the h differencing parameter for matrix-free
2364:               Jacobian vector products

2366:     Level: developer

2368:     Notes:
2369:     `MATMFFD` is a specific `MatType` which uses the `MatMFFD` data structure

2371:      MatMFFD*() methods actually take the `Mat` as their first argument. Not a `MatMFFD` data structure

2373:     This functionality is often obtained using `MatCreateSNESMF()` or with `SNES` solvers using `-snes_mf` or `-snes_mf_operator`

2375: .seealso: [](ch_matrices), `MatMFFDType`, `MATMFFD`, `MatCreateMFFD()`, `MatMFFDSetFuction()`, `MatMFFDSetType()`, `MatMFFDRegister()`,
2376:           `MatCreateSNESMF()`, `SNES`, `-snes_mf`, `-snes_mf_operator`
2377: S*/
2378: typedef struct _p_MatMFFD *MatMFFD;

2380: /*J
2381:    MatMFFDType - algorithm used to compute the `h` used in computing matrix-vector products via differencing of a function

2383:    Values:
2384: +   `MATMFFD_DS` - an algorithm described by Dennis and Schnabel {cite}`dennis:83`
2385: -   `MATMFFD_WP` - the Walker-Pernice {cite}`pw98` strategy.

2387:    Level: beginner

2389: .seealso: [](ch_matrices), `MatMFFDSetType()`, `MatMFFDRegister()`, `MatMFFDSetFunction()`, `MatCreateMFFD()`
2390: J*/
2391: typedef const char *MatMFFDType;
2392: #define MATMFFD_DS "ds"
2393: #define MATMFFD_WP "wp"

2395: PETSC_EXTERN PetscErrorCode MatMFFDSetType(Mat, MatMFFDType);
2396: PETSC_EXTERN PetscErrorCode MatMFFDRegister(const char[], PetscErrorCode (*)(MatMFFD));

2398: PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat, PetscReal);
2399: PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat, PetscBool);

2401: PETSC_EXTERN PetscErrorCode MatFDColoringSetType(MatFDColoring, MatMFFDType);

2403: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
2404: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);

2406: #ifdef PETSC_HAVE_H2OPUS
2407: PETSC_EXTERN_TYPEDEF typedef PetscScalar(MatH2OpusKernelFn)(PetscInt, PetscReal[], PetscReal[], void *);
2408: PETSC_EXTERN_TYPEDEF typedef MatH2OpusKernelFn *MatH2OpusKernel;

2410: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], PetscBool, MatH2OpusKernelFn *, void *, PetscReal, PetscInt, PetscInt, Mat *);
2411: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromMat(Mat, PetscInt, const PetscReal[], PetscBool, PetscReal, PetscInt, PetscInt, PetscInt, PetscReal, Mat *);
2412: PETSC_EXTERN PetscErrorCode MatH2OpusSetSamplingMat(Mat, Mat, PetscInt, PetscReal);
2413: PETSC_EXTERN PetscErrorCode MatH2OpusOrthogonalize(Mat);
2414: PETSC_EXTERN PetscErrorCode MatH2OpusCompress(Mat, PetscReal);
2415: PETSC_EXTERN PetscErrorCode MatH2OpusSetNativeMult(Mat, PetscBool);
2416: PETSC_EXTERN PetscErrorCode MatH2OpusGetNativeMult(Mat, PetscBool *);
2417: PETSC_EXTERN PetscErrorCode MatH2OpusGetIndexMap(Mat, IS *);
2418: PETSC_EXTERN PetscErrorCode MatH2OpusMapVec(Mat, PetscBool, Vec, Vec *);
2419: PETSC_EXTERN PetscErrorCode MatH2OpusLowRankUpdate(Mat, Mat, Mat, PetscScalar);
2420: #endif

2422: /*S
2423:   MatHtoolKernelFn - Function type for the user-supplied kernel callback used by `MATHTOOL` (`MatCreateHtoolFromKernel()`, `MatHtoolSetKernel()`) to evaluate the dense matrix entries on demand

2425:   Synopsis:
2426: #include <petscmat.h>
2427:   PetscErrorCode MatHtoolKernelFn(PetscInt sdim, PetscInt M, PetscInt N, const PetscInt *J, const PetscInt *K, PetscScalar *ptr, void *ctx)

2429:   Calling Sequence:
2430: + sdim - the spatial dimension of the source/target geometries
2431: . M    - the number of target points
2432: . N    - the number of source points
2433: . J    - array of `M` target point indices into the user's target coordinate array
2434: . K    - array of `N` source point indices into the user's source coordinate array
2435: . ptr  - column-major output buffer of length `M*N` to fill with kernel values
2436: - ctx  - the optional user context passed at registration

2438:   Level: intermediate

2440: .seealso: `Mat`, `MATHTOOL`, `MatCreateHtoolFromKernel()`, `MatHtoolSetKernel()`
2441: S*/
2442: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode    MatHtoolKernelFn(PetscInt, PetscInt, PetscInt, const PetscInt *, const PetscInt *, PetscScalar *, void *);
2443: PETSC_EXTERN_TYPEDEF typedef MatHtoolKernelFn *MatHtoolKernel;

2445: PETSC_EXTERN PetscErrorCode MatCreateHtoolFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], const PetscReal[], MatHtoolKernelFn *, void *, Mat *);
2446: PETSC_EXTERN PetscErrorCode MatHtoolSetKernel(Mat, MatHtoolKernelFn *, void *);
2447: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationSource(Mat, IS *);
2448: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationTarget(Mat, IS *);
2449: PETSC_EXTERN PetscErrorCode MatHtoolUsePermutation(Mat, PetscBool);
2450: PETSC_EXTERN PetscErrorCode MatHtoolUseRecompression(Mat, PetscBool);
2451: PETSC_EXTERN PetscErrorCode MatHtoolGetEpsilon(Mat, PetscReal *);
2452: PETSC_EXTERN PetscErrorCode MatHtoolSetEpsilon(Mat, PetscReal);
2453: PETSC_EXTERN PetscErrorCode MatHtoolGetEta(Mat, PetscReal *);
2454: PETSC_EXTERN PetscErrorCode MatHtoolSetEta(Mat, PetscReal);
2455: PETSC_EXTERN PetscErrorCode MatHtoolGetMaxClusterLeafSize(Mat, PetscInt *);
2456: PETSC_EXTERN PetscErrorCode MatHtoolSetMaxClusterLeafSize(Mat, PetscInt);
2457: PETSC_EXTERN PetscErrorCode MatHtoolGetMinTargetDepth(Mat, PetscInt *);
2458: PETSC_EXTERN PetscErrorCode MatHtoolSetMinTargetDepth(Mat, PetscInt);
2459: PETSC_EXTERN PetscErrorCode MatHtoolGetMinSourceDepth(Mat, PetscInt *);
2460: PETSC_EXTERN PetscErrorCode MatHtoolSetMinSourceDepth(Mat, PetscInt);
2461: PETSC_EXTERN PetscErrorCode MatHtoolGetBlockTreeConsistency(Mat, PetscBool *);
2462: PETSC_EXTERN PetscErrorCode MatHtoolSetBlockTreeConsistency(Mat, PetscBool);

2464: /*E
2465:    MatHtoolCompressorType - Indicates the type of compressor used by a `MATHTOOL`

2467:    Values:
2468: +  `MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA` (default) - symmetric partial adaptive cross approximation
2469: .  `MAT_HTOOL_COMPRESSOR_FULL_ACA`                 - full adaptive cross approximation
2470: -  `MAT_HTOOL_COMPRESSOR_SVD`                      - singular value decomposition

2472:    Level: intermediate

2474: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolClusteringType`, `MatHtoolGetCompressorType()`, `MatHtoolSetCompressorType()`
2475: E*/
2476: typedef enum {
2477:   MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA,
2478:   MAT_HTOOL_COMPRESSOR_FULL_ACA,
2479:   MAT_HTOOL_COMPRESSOR_SVD
2480: } MatHtoolCompressorType;

2482: /*E
2483:    MatHtoolClusteringType - Indicates the type of clustering used by a `MATHTOOL`

2485:    Values:
2486: +  `MAT_HTOOL_CLUSTERING_PCA_REGULAR` (default)    - axis computed via principle component analysis, split uniformly
2487: .  `MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC`            - axis computed via principle component analysis, split barycentrically
2488: .  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR`   - axis along the largest extent of the bounding box, split uniformly
2489: -  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC` - axis along the largest extent of the bounding box, split barycentrically

2491:    Level: intermediate

2493:    Note:
2494:    Higher-dimensional clustering is not yet supported in Htool, but once it is, one should add BOUNDING_BOX_{2,3} types

2496: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolCompressorType`, `MatHtoolGetClusteringType()`, `MatHtoolSetClusteringType()`
2497: E*/
2498: typedef enum {
2499:   MAT_HTOOL_CLUSTERING_PCA_REGULAR,
2500:   MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC,
2501:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR,
2502:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC
2503: } MatHtoolClusteringType;
2504: PETSC_EXTERN PetscErrorCode MatHtoolGetCompressorType(Mat, MatHtoolCompressorType *);
2505: PETSC_EXTERN PetscErrorCode MatHtoolSetCompressorType(Mat, MatHtoolCompressorType);
2506: PETSC_EXTERN PetscErrorCode MatHtoolGetClusteringType(Mat, MatHtoolClusteringType *);
2507: PETSC_EXTERN PetscErrorCode MatHtoolSetClusteringType(Mat, MatHtoolClusteringType);

2509: PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat, PetscInt, PetscInt);
2510: PETSC_EXTERN PetscErrorCode MatMumpsGetIcntl(Mat, PetscInt, PetscInt *);
2511: PETSC_EXTERN PetscErrorCode MatMumpsSetCntl(Mat, PetscInt, PetscReal);
2512: PETSC_EXTERN PetscErrorCode MatMumpsGetCntl(Mat, PetscInt, PetscReal *);

2514: PETSC_EXTERN PetscErrorCode MatMumpsGetInfo(Mat, PetscInt, PetscInt *);
2515: PETSC_EXTERN PetscErrorCode MatMumpsGetInfog(Mat, PetscInt, PetscInt *);
2516: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfo(Mat, PetscInt, PetscReal *);
2517: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfog(Mat, PetscInt, PetscReal *);
2518: PETSC_EXTERN PetscErrorCode MatMumpsGetNullPivots(Mat, PetscInt *, PetscInt **);
2519: PETSC_EXTERN PetscErrorCode MatMumpsGetInverse(Mat, Mat);
2520: PETSC_EXTERN PetscErrorCode MatMumpsGetInverseTranspose(Mat, Mat);
2521: PETSC_EXTERN PetscErrorCode MatMumpsSetBlk(Mat, PetscInt, const PetscInt[], const PetscInt[]);

2523: PETSC_EXTERN PetscErrorCode MatMumpsSetOocTmpDir(Mat, const char *);
2524: PETSC_EXTERN PetscErrorCode MatMumpsGetOocTmpDir(Mat, const char *[]);

2526: #ifdef PETSC_HAVE_MKL_PARDISO
2527: PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat, PetscInt, PetscInt);
2528: #endif

2530: #ifdef PETSC_HAVE_MKL_CPARDISO
2531: PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat, PetscInt, PetscInt);
2532: #endif

2534: #ifdef PETSC_HAVE_SUPERLU
2535: PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat, PetscReal);
2536: #endif

2538: #ifdef PETSC_HAVE_SUPERLU_DIST
2539: PETSC_EXTERN PetscErrorCode MatSuperluDistGetDiagU(Mat, PetscScalar *);
2540: #endif

2542: /*E
2543:     MatSTRUMPACKReordering - sparsity reducing ordering to be used in `MATSOLVERSTRUMPACK`

2545:     Values:
2546: +  `MAT_STRUMPACK_NATURAL`   - use the current ordering
2547: .  `MAT_STRUMPACK_METIS`     - use MeTis to compute an ordering
2548: .  `MAT_STRUMPACK_PARMETIS`  - use ParMeTis to compute an ordering
2549: .  `MAT_STRUMPACK_SCOTCH`    - use Scotch to compute an ordering
2550: .  `MAT_STRUMPACK_PTSCOTCH`  - use parallel Scotch to compute an ordering
2551: .  `MAT_STRUMPACK_RCM`       - use an RCM ordering
2552: .  `MAT_STRUMPACK_GEOMETRIC` - use a geometric ordering (needs mesh info from user)
2553: .  `MAT_STRUMPACK_AMD`       - approximate minimum degree
2554: .  `MAT_STRUMPACK_MMD`       - multiple minimum degree
2555: .  `MAT_STRUMPACK_AND`       - approximate nested dissection
2556: .  `MAT_STRUMPACK_MLF`       - minimum local fill
2557: -  `MAT_STRUMPACK_SPECTRAL`  - spectral nested dissection

2559:     Level: intermediate

2561:     Developer Note:
2562:     Should be called `MatSTRUMPACKReorderingType`

2564: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetReordering()`
2565: E*/
2566: typedef enum {
2567:   MAT_STRUMPACK_NATURAL,
2568:   MAT_STRUMPACK_METIS,
2569:   MAT_STRUMPACK_PARMETIS,
2570:   MAT_STRUMPACK_SCOTCH,
2571:   MAT_STRUMPACK_PTSCOTCH,
2572:   MAT_STRUMPACK_RCM,
2573:   MAT_STRUMPACK_GEOMETRIC,
2574:   MAT_STRUMPACK_AMD,
2575:   MAT_STRUMPACK_MMD,
2576:   MAT_STRUMPACK_AND,
2577:   MAT_STRUMPACK_MLF,
2578:   MAT_STRUMPACK_SPECTRAL
2579: } MatSTRUMPACKReordering;
2580: PETSC_EXTERN const char *const MatSTRUMPACKReorderingTypes[];

2582: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetReordering(Mat, MatSTRUMPACKReordering);
2583: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetReordering(Mat, MatSTRUMPACKReordering *);
2584: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricNxyz(Mat, PetscInt, PetscInt, PetscInt);
2585: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricComponents(Mat, PetscInt);
2586: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricWidth(Mat, PetscInt);
2587: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetColPerm(Mat, PetscBool);
2588: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetColPerm(Mat, PetscBool *);
2589: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGPU(Mat, PetscBool);
2590: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetGPU(Mat, PetscBool *);

2592: /*E
2593:     MatSTRUMPACKCompressionType - Compression used in the approximate sparse factorization solver `MATSOLVERSTRUMPACK`

2595:     Values:
2596: +  `MAT_STRUMPACK_COMPRESSION_TYPE_NONE`          - no compression, direct solver
2597: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HSS`           - hierarchically semi-separable
2598: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR`           - block low rank
2599: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HODLR`         - hierarchically off-diagonal low rank (requires ButterflyPACK support, configure with `--download-butterflypack`)
2600: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR`     - hybrid of BLR and HODLR (requires ButterflyPACK support, configure with `--download-butterflypack`)
2601: .  `MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR` - hybrid of lossy (ZFP), BLR and HODLR (requires ButterflyPACK and ZFP support, configure with `--download-butterflypack --download-zfp`)
2602: .  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS`      - lossless compression (requires ZFP support, configure with `--download-zfp`)
2603: -  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY`         - lossy compression (requires ZFP support, configure with `--download-zfp`)

2605:     Level: intermediate

2607: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompression()`
2608: E*/
2609: typedef enum {
2610:   MAT_STRUMPACK_COMPRESSION_TYPE_NONE,
2611:   MAT_STRUMPACK_COMPRESSION_TYPE_HSS,
2612:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR,
2613:   MAT_STRUMPACK_COMPRESSION_TYPE_HODLR,
2614:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR,
2615:   MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR,
2616:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS,
2617:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY
2618: } MatSTRUMPACKCompressionType;
2619: PETSC_EXTERN const char *const MatSTRUMPACKCompressionTypes[];

2621: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompression(Mat, MatSTRUMPACKCompressionType);
2622: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompression(Mat, MatSTRUMPACKCompressionType *);
2623: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompRelTol(Mat, PetscReal);
2624: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompRelTol(Mat, PetscReal *);
2625: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompAbsTol(Mat, PetscReal);
2626: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompAbsTol(Mat, PetscReal *);
2627: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompMinSepSize(Mat, PetscInt);
2628: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompMinSepSize(Mat, PetscInt *);
2629: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLeafSize(Mat, PetscInt);
2630: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLeafSize(Mat, PetscInt *);
2631: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLossyPrecision(Mat, PetscInt);
2632: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLossyPrecision(Mat, PetscInt *);
2633: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompButterflyLevels(Mat, PetscInt);
2634: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompButterflyLevels(Mat, PetscInt *);

2636: PETSC_EXTERN PetscErrorCode MatBindToCPU(Mat, PetscBool);
2637: PETSC_EXTERN PetscErrorCode MatBoundToCPU(Mat, PetscBool *);
2638: PETSC_DEPRECATED_FUNCTION(3, 13, 0, "MatBindToCPU()", ) static inline PetscErrorCode MatPinToCPU(Mat A, PetscBool flg)
2639: {
2640:   return MatBindToCPU(A, flg);
2641: }
2642: PETSC_EXTERN PetscErrorCode MatSetBindingPropagates(Mat, PetscBool);
2643: PETSC_EXTERN PetscErrorCode MatGetBindingPropagates(Mat, PetscBool *);

2645: #ifdef PETSC_HAVE_CUDA
2646: /*E
2647:     MatCUSPARSEStorageFormat - indicates the storage format for `MATAIJCUSPARSE` (GPU)
2648:     matrices.

2650:     Values:
2651: +   `MAT_CUSPARSE_CSR` - Compressed Sparse Row
2652: .   `MAT_CUSPARSE_ELL` - Ellpack (requires CUDA 4.2 or later).
2653: -   `MAT_CUSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format (requires CUDA 4.2 or later).

2655:     Level: intermediate

2657: .seealso: [](ch_matrices), `MATAIJCUSPARSE`, `MatCUSPARSESetFormat()`, `MatCUSPARSEFormatOperation`
2658: E*/

2660: typedef enum {
2661:   MAT_CUSPARSE_CSR,
2662:   MAT_CUSPARSE_ELL,
2663:   MAT_CUSPARSE_HYB
2664: } MatCUSPARSEStorageFormat;

2666: /* these will be strings associated with enumerated type defined above */
2667: PETSC_EXTERN const char *const MatCUSPARSEStorageFormats[];

2669: /*E
2670:     MatCUSPARSEFormatOperation - indicates the operation of `MATAIJCUSPARSE` (GPU)
2671:     matrices whose operation should use a particular storage format.

2673:     Values:
2674: +   `MAT_CUSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2675: .   `MAT_CUSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2676: .   `MAT_CUSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2677: -   `MAT_CUSPARSE_ALL`          - sets the storage format for all `MATAIJCUSPARSE` (GPU) matrices

2679:     Level: intermediate

2681: .seealso: [](ch_matrices), `MatCUSPARSESetFormat()`, `MatCUSPARSEStorageFormat`
2682: E*/
2683: typedef enum {
2684:   MAT_CUSPARSE_MULT_DIAG,
2685:   MAT_CUSPARSE_MULT_OFFDIAG,
2686:   MAT_CUSPARSE_MULT,
2687:   MAT_CUSPARSE_ALL
2688: } MatCUSPARSEFormatOperation;

2690: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2691: PETSC_EXTERN PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2692: PETSC_EXTERN PetscErrorCode MatCUSPARSESetFormat(Mat, MatCUSPARSEFormatOperation, MatCUSPARSEStorageFormat);
2693: PETSC_EXTERN PetscErrorCode MatCUSPARSESetUseCPUSolve(Mat, PetscBool);
2694: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2695: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2696: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayRead(Mat, const PetscScalar **);
2697: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayRead(Mat, const PetscScalar **);
2698: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayWrite(Mat, PetscScalar **);
2699: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayWrite(Mat, PetscScalar **);
2700: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArray(Mat, PetscScalar **);
2701: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArray(Mat, PetscScalar **);

2703: PETSC_EXTERN PetscErrorCode MatCreateDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2704: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2705: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayWrite(Mat, PetscScalar **);
2706: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayRead(Mat, const PetscScalar **);
2707: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArray(Mat, PetscScalar **);
2708: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayWrite(Mat, PetscScalar **);
2709: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayRead(Mat, const PetscScalar **);
2710: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArray(Mat, PetscScalar **);
2711: PETSC_EXTERN PetscErrorCode MatDenseCUDAPlaceArray(Mat, const PetscScalar *);
2712: PETSC_EXTERN PetscErrorCode MatDenseCUDAReplaceArray(Mat, const PetscScalar *);
2713: PETSC_EXTERN PetscErrorCode MatDenseCUDAResetArray(Mat);
2714: PETSC_EXTERN PetscErrorCode MatDenseCUDASetPreallocation(Mat, PetscScalar *);

2716: PETSC_EXTERN PetscErrorCode MatCreateSeqSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2717: PETSC_EXTERN PetscErrorCode MatCreateSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2718: #endif

2720: #ifdef PETSC_HAVE_HIP
2721: /*E
2722:     MatHIPSPARSEStorageFormat - indicates the storage format for `MATAIJHIPSPARSE` (GPU)
2723:     matrices.

2725:     Values:
2726: +   `MAT_HIPSPARSE_CSR` - Compressed Sparse Row
2727: .   `MAT_HIPSPARSE_ELL` - Ellpack
2728: -   `MAT_HIPSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format

2730:     Level: intermediate

2732: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEFormatOperation`
2733: E*/

2735: typedef enum {
2736:   MAT_HIPSPARSE_CSR,
2737:   MAT_HIPSPARSE_ELL,
2738:   MAT_HIPSPARSE_HYB
2739: } MatHIPSPARSEStorageFormat;

2741: /* these will be strings associated with enumerated type defined above */
2742: PETSC_EXTERN const char *const MatHIPSPARSEStorageFormats[];

2744: /*E
2745:     MatHIPSPARSEFormatOperation - indicates the operation of `MATAIJHIPSPARSE` (GPU)
2746:     matrices whose operation should use a particular storage format.

2748:     Values:
2749: +   `MAT_HIPSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2750: .   `MAT_HIPSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2751: .   `MAT_HIPSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2752: -   `MAT_HIPSPARSE_ALL`          - sets the storage format for all HIPSPARSE (GPU) matrices

2754:     Level: intermediate

2756: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEStorageFormat`
2757: E*/
2758: typedef enum {
2759:   MAT_HIPSPARSE_MULT_DIAG,
2760:   MAT_HIPSPARSE_MULT_OFFDIAG,
2761:   MAT_HIPSPARSE_MULT,
2762:   MAT_HIPSPARSE_ALL
2763: } MatHIPSPARSEFormatOperation;

2765: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2766: PETSC_EXTERN PetscErrorCode MatCreateAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2767: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetFormat(Mat, MatHIPSPARSEFormatOperation, MatHIPSPARSEStorageFormat);
2768: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetUseCPUSolve(Mat, PetscBool);
2769: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2770: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2771: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayRead(Mat, const PetscScalar **);
2772: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayRead(Mat, const PetscScalar **);
2773: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayWrite(Mat, PetscScalar **);
2774: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayWrite(Mat, PetscScalar **);
2775: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArray(Mat, PetscScalar **);
2776: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArray(Mat, PetscScalar **);

2778: PETSC_EXTERN PetscErrorCode MatCreateDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2779: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2780: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayWrite(Mat, PetscScalar **);
2781: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayRead(Mat, const PetscScalar **);
2782: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArray(Mat, PetscScalar **);
2783: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayWrite(Mat, PetscScalar **);
2784: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayRead(Mat, const PetscScalar **);
2785: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArray(Mat, PetscScalar **);
2786: PETSC_EXTERN PetscErrorCode MatDenseHIPPlaceArray(Mat, const PetscScalar *);
2787: PETSC_EXTERN PetscErrorCode MatDenseHIPReplaceArray(Mat, const PetscScalar *);
2788: PETSC_EXTERN PetscErrorCode MatDenseHIPResetArray(Mat);
2789: PETSC_EXTERN PetscErrorCode MatDenseHIPSetPreallocation(Mat, PetscScalar *);
2790: PETSC_EXTERN PetscErrorCode MatCreateSeqSELLHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2791: PETSC_EXTERN PetscErrorCode MatCreateSELLHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2792: #endif

2794: #if defined(PETSC_HAVE_VIENNACL)
2795: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2796: PETSC_EXTERN PetscErrorCode MatCreateAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2797: #endif

2799: #if PetscDefined(HAVE_KOKKOS)
2800: PETSC_EXTERN PetscErrorCode MatCreateAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2801: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2802: #endif

2804: #if defined(PETSC_HAVE_FFTW)
2805: PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat, Vec, Vec);
2806: PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat, Vec, Vec);
2807: PETSC_EXTERN PetscErrorCode MatCreateVecsFFTW(Mat, Vec *, Vec *, Vec *);
2808: #endif

2810: #if defined(PETSC_HAVE_SCALAPACK) && (defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL_DOUBLE))
2811: PETSC_EXTERN PetscErrorCode MatCreateScaLAPACK(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2812: PETSC_EXTERN PetscErrorCode MatScaLAPACKSetBlockSizes(Mat, PetscInt, PetscInt);
2813: PETSC_EXTERN PetscErrorCode MatScaLAPACKGetBlockSizes(Mat, PetscInt *, PetscInt *);
2814: #endif

2816: PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm, PetscInt, const IS[], PetscInt, const IS[], const Mat[], Mat *);
2817: PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat, PetscInt *, PetscInt *);
2818: PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat, IS[], IS[]);
2819: PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat, IS[], IS[]);
2820: PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat, PetscInt *, PetscInt *, Mat ***);
2821: PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat, PetscInt, PetscInt, Mat *);
2822: PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat, VecType);
2823: PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat, PetscInt, const IS[], PetscInt, const IS[], const Mat[]);
2824: PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat, PetscInt, PetscInt, Mat);

2826: PETSC_EXTERN PetscErrorCode MatFilter(Mat, PetscReal, PetscBool, PetscBool);
2827: PETSC_DEPRECATED_FUNCTION(3, 20, 0, "MatFilter()", ) static inline PetscErrorCode MatChop(Mat A, PetscReal tol)
2828: {
2829:   return MatFilter(A, tol, PETSC_FALSE, PETSC_FALSE);
2830: }
2831: PETSC_EXTERN PetscErrorCode MatComputeBandwidth(Mat, PetscReal, PetscInt *);

2833: PETSC_EXTERN PetscErrorCode MatSubdomainsCreateCoalesce(Mat, PetscInt, PetscInt *, IS **);

2835: PETSC_EXTERN PetscErrorCode MatPreallocatorPreallocate(Mat, PetscBool, Mat);

2837: PETSC_EXTERN PetscErrorCode MatHeaderMerge(Mat, Mat *);
2838: PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat, Mat *);

2840: PETSC_EXTERN PetscErrorCode MatSeqAIJGetCSRAndMemType(Mat, const PetscInt **, const PetscInt **, PetscScalar **, PetscMemType *);

2842: PETSC_EXTERN PetscErrorCode MatCreateGraph(Mat, PetscBool, PetscBool, PetscReal, PetscInt, PetscInt[], Mat *);
2843: PETSC_EXTERN PetscErrorCode MatEliminateZeros(Mat, PetscBool);

2845: PETSC_EXTERN PetscErrorCode MatCreateDenseFromVecType(MPI_Comm, VecType, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar *, Mat *);
2846: PETSC_EXTERN PetscErrorCode MatCreateDenseWithMemType(MPI_Comm, PetscMemType, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar *, Mat *);

2848: PETSC_EXTERN PetscErrorCode MatSetHPL(Mat, int);
2849: #define PETSCBMHPL "hpl"

2851: PETSC_EXTERN PetscErrorCode MatDFischer(Mat, Vec, Vec, Vec, Vec, Vec, Vec, Vec, Vec);