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 MATBAIJLIBXSMM               "baijlibxsmm"
 92: #define MATSEQBAIJLIBXSMM            "seqbaijlibxsmm"
 93: #define MATMPIBAIJLIBXSMM            "mpibaijlibxsmm"
 94: #define MATMPIADJ                    "mpiadj"
 95: #define MATSBAIJ                     "sbaij"
 96: #define MATSEQSBAIJ                  "seqsbaij"
 97: #define MATMPISBAIJ                  "mpisbaij"
 98: #define MATMFFD                      "mffd"
 99: #define MATNORMAL                    "normal"
100: #define MATNORMALHERMITIAN           "normalh"
101: #define MATLRC                       "lrc"
102: #define MATSCATTER                   "scatter"
103: #define MATBLOCKMAT                  "blockmat"
104: #define MATCOMPOSITE                 "composite"
105: #define MATFFT                       "fft"
106: #define MATFFTW                      "fftw"
107: #define MATSEQCUFFT                  "seqcufft"
108: #define MATSEQHIPFFT                 "seqhipfft"
109: #define MATTRANSPOSEMAT              PETSC_DEPRECATED_MACRO(3, 18, 0, "MATTRANSPOSEVIRTUAL", ) "transpose"
110: #define MATTRANSPOSEVIRTUAL          "transpose"
111: #define MATHERMITIANTRANSPOSEVIRTUAL "hermitiantranspose"
112: #define MATSCHURCOMPLEMENT           "schurcomplement"
113: #define MATPYTHON                    "python"
114: #define MATHYPRE                     "hypre"
115: #define MATHYPRESTRUCT               "hyprestruct"
116: #define MATHYPRESSTRUCT              "hypresstruct"
117: #define MATSUBMATRIX                 "submatrix"
118: #define MATLOCALREF                  "localref"
119: #define MATNEST                      "nest"
120: #define MATPREALLOCATOR              "preallocator"
121: #define MATSELL                      "sell"
122: #define MATSEQSELL                   "seqsell"
123: #define MATMPISELL                   "mpisell"
124: #define MATSELLCUDA                  "sellcuda"
125: #define MATSEQSELLCUDA               "seqsellcuda"
126: #define MATMPISELLCUDA               "mpisellcuda"
127: #define MATSELLHIP                   "sellhip"
128: #define MATSEQSELLHIP                "seqsellhip"
129: #define MATMPISELLHIP                "mpisellhip"
130: #define MATDUMMY                     "dummy"
131: #define MATLMVM                      "lmvm"
132: #define MATLMVMDFP                   "lmvmdfp"
133: #define MATLMVMDDFP                  "lmvmddfp"
134: #define MATLMVMBFGS                  "lmvmbfgs"
135: #define MATLMVMDBFGS                 "lmvmdbfgs"
136: #define MATLMVMDQN                   "lmvmdqn"
137: #define MATLMVMSR1                   "lmvmsr1"
138: #define MATLMVMBROYDEN               "lmvmbroyden"
139: #define MATLMVMBADBROYDEN            "lmvmbadbroyden"
140: #define MATLMVMSYMBROYDEN            "lmvmsymbroyden"
141: #define MATLMVMSYMBADBROYDEN         "lmvmsymbadbroyden"
142: #define MATLMVMDIAGBROYDEN           "lmvmdiagbroyden"
143: #define MATCONSTANTDIAGONAL          "constantdiagonal"
144: #define MATDIAGONAL                  "diagonal"
145: #define MATHTOOL                     "htool"
146: #define MATH2OPUS                    "h2opus"

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

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

153:    Level: beginner

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

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

187: /*E
188:     MatFactorType - indicates what type of factorization is requested

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

198:     Level: beginner

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

214: PETSC_EXTERN PetscErrorCode MatGetFactor(Mat, MatSolverType, MatFactorType, Mat *);
215: PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat, MatSolverType, MatFactorType, PetscBool *);
216: PETSC_EXTERN PetscErrorCode MatFactorGetCanUseOrdering(Mat, PetscBool *);
217: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "MatFactorGetCanUseOrdering()", ) static inline PetscErrorCode MatFactorGetUseOrdering(Mat A, PetscBool *b)
218: {
219:   return MatFactorGetCanUseOrdering(A, b);
220: }
221: PETSC_EXTERN PetscErrorCode MatFactorGetSolverType(Mat, MatSolverType *);
222: PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat, MatFactorType *);
223: PETSC_EXTERN PetscErrorCode MatSetFactorType(Mat, MatFactorType);
224: /*S
225:   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`

227:   Synopsis:
228: #include <petscmat.h>
229:   PetscErrorCode MatSolverFn(Mat A, MatFactorType ftype, Mat *F)

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

236:   Level: developer

238: .seealso: `Mat`, `MatGetFactor()`, `MatSolverType`, `MatFactorType`, `MatSolverTypeRegister()`, `MatSolverTypeGet()`
239: S*/
240: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatSolverFn(Mat, MatFactorType, Mat *);
241: PETSC_EXTERN_TYPEDEF typedef MatSolverFn   *MatSolverFunction;

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

255: /*E
256:     MatProductType - indicates what type of matrix product to compute

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

266:     Level: beginner

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

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

284:    Level: beginner

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

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

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

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

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

347:     Level: beginner

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

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

362:     Values:
363: +  `MAT_DO_NOT_GET_VALUES` - do not copy the matrix values
364: -  `MAT_GET_VALUES`        - copy the matrix values

366:     Level: developer

368:     Developer Note:
369:     Why is not just a boolean used for this information?

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

378: PETSC_EXTERN PetscErrorCode MatInitializePackage(void);
379: PETSC_EXTERN PetscErrorCode MatFinalizePackage(void);

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

399: PETSC_EXTERN PetscFunctionList MatList;
400: PETSC_EXTERN PetscFunctionList MatColoringList;
401: PETSC_EXTERN PetscFunctionList MatPartitioningList;
402: PETSC_EXTERN PetscFunctionList MatMeshToCellGraphList;

404: /*E
405:    MatStructure - Indicates if two matrices have the same nonzero structure

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

414:    Level: beginner

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

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

431: #if PetscDefined(HAVE_MKL_SPARSE)
432: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
433: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
434: PETSC_EXTERN PetscErrorCode MatCreateBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
435: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
436: #endif

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

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

451: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
452: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
453: PETSC_EXTERN PetscErrorCode MatMPISELLGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *);
454: PETSC_EXTERN PetscErrorCode MatMPISELLGetSeqSELL(Mat, Mat *, Mat *, const PetscInt *[]);

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

466: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
467: PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
468: PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);

470: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOO(Mat, PetscCount, PetscInt[], PetscInt[]);
471: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOOLocal(Mat, PetscCount, PetscInt[], PetscInt[]);
472: PETSC_EXTERN PetscErrorCode MatSetValuesCOO(Mat, const PetscScalar[], InsertMode);

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

477: PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
478: PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);
479: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
480: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
481: PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscInt[], const PetscInt[]);

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

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

503:    Values:
504: +   `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)
505: -   `MAT_COMPOSITE_MERGE_LEFT`  - merge into a single matrix starting from the leftmost matrix

507:    Level: advanced

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

520:     Values:
521: +  `MAT_COMPOSITE_ADDITIVE`       - sum of matrices (default)
522: -  `MAT_COMPOSITE_MULTIPLICATIVE` - product of matrices

524:     Level: beginner

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

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

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

562: #if PetscDefined(HAVE_HYPRE)
563: PETSC_EXTERN PetscErrorCode MatHYPRESetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
564: #endif

566: PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat, const char[]);
567: PETSC_EXTERN PetscErrorCode MatPythonGetType(Mat, const char *[]);
568: PETSC_EXTERN PetscErrorCode MatPythonCreate(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const char[], Mat *);

570: PETSC_EXTERN PetscErrorCode MatResetPreallocation(Mat);
571: PETSC_EXTERN PetscErrorCode MatResetHash(Mat);
572: PETSC_EXTERN PetscErrorCode MatSetUp(Mat);
573: PETSC_EXTERN PetscErrorCode MatDestroy(Mat *);
574: PETSC_EXTERN PetscErrorCode MatGetNonzeroState(Mat, PetscObjectState *);

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

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

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

600:    Level: beginner

602:    Notes:
603:    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).
604:    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.

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

608:    For staggered grids, see `DMStagStencil`

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

617: PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
618: PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
619: PETSC_EXTERN PetscErrorCode MatSetStencil(Mat, PetscInt, const PetscInt[], const PetscInt[], PetscInt);

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

624:     Values:
625: +   `MAT_FLUSH_ASSEMBLY` - you will continue to put values into the matrix
626: -   `MAT_FINAL_ASSEMBLY` - you wish to use the matrix with the values currently inserted

628:     Level: beginner

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

637: PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat, MatAssemblyType);
638: PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat, MatAssemblyType);
639: PETSC_EXTERN PetscErrorCode MatAssembled(Mat, PetscBool *);

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

644:    Level: beginner

646:    Note:
647:    See `MatSetOption()` for the use of the options

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

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

687: PETSC_EXTERN const char *const *MatOptions;
688: PETSC_EXTERN PetscErrorCode     MatSetOption(Mat, MatOption, PetscBool);
689: PETSC_EXTERN PetscErrorCode     MatGetOption(Mat, MatOption, PetscBool *);
690: PETSC_EXTERN PetscErrorCode     MatPropagateSymmetryOptions(Mat, Mat);
691: PETSC_EXTERN PetscErrorCode     MatGetType(Mat, MatType *);

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

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

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

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

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

781:   Level: beginner

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

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

795: PETSC_EXTERN PetscErrorCode MatConvert(Mat, MatType, MatReuse, Mat *);
796: PETSC_EXTERN PetscErrorCode MatDuplicate(Mat, MatDuplicateOption, Mat *);

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

809: PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
810: PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
811: PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
812: PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);

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

817:    Level: intermediate

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

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

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

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

843:     Level: beginner

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

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

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

901: PETSC_EXTERN PetscErrorCode MatGetSize(Mat, PetscInt *, PetscInt *);
902: PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat, PetscInt *, PetscInt *);
903: PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat, PetscInt *, PetscInt *);
904: PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat, const PetscInt **);
905: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat, PetscInt *, PetscInt *);
906: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat, const PetscInt **);
907: PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat, IS *, IS *);

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

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

942: PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat, PetscInt, IS[], PetscInt);
943: PETSC_EXTERN PetscErrorCode MatIncreaseOverlapSplit(Mat, PetscInt, IS[], PetscInt);
944: PETSC_EXTERN PetscErrorCode MatMPIAIJSetUseScalableIncreaseOverlap(Mat, PetscBool);

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

948: PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);
949: PETSC_EXTERN PetscErrorCode MatGalerkin(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);

951: PETSC_EXTERN PetscErrorCode MatPtAP(Mat, Mat, MatReuse, PetscReal, Mat *);
952: PETSC_EXTERN PetscErrorCode MatRARt(Mat, Mat, MatReuse, PetscReal, Mat *);

954: PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat, Mat, MatReuse, PetscReal, Mat *);
955: PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat, Mat, MatReuse, PetscReal, Mat *);

957: PETSC_EXTERN PetscErrorCode MatAXPY(Mat, PetscScalar, Mat, MatStructure);
958: PETSC_EXTERN PetscErrorCode MatAYPX(Mat, PetscScalar, Mat, MatStructure);

960: PETSC_EXTERN PetscErrorCode MatScale(Mat, PetscScalar);
961: PETSC_EXTERN PetscErrorCode MatShift(Mat, PetscScalar);

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

975: PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat, PetscInt, PetscInt);
976: PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat, PetscInt *, PetscInt *, PetscInt *, PetscInt *);

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

995: PETSC_EXTERN PetscErrorCode MatCopyHashToXAIJ(Mat A, Mat B);
996: /*@
997:    MatSetValue - Set a single entry into a matrix.

999:    Not Collective

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

1008:    Level: beginner

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

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

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

1024: /*@
1025:    MatGetValue - Gets a single value from a matrix

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

1029:    Input Parameters:
1030: +  mat - the matrix
1031: .  row - the row location of the entry
1032: -  col - the column location of the entry

1034:    Output Parameter:
1035: .  va - the value

1037:    Level: advanced

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

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

1044:    See notes for `MatGetValues()`.

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

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

1056:    Not Collective

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

1065:    Level: intermediate

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

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

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

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

1083:    Synopsis:
1084: #include <petscmat.h>
1085:    PetscErrorCode MatPreallocateBegin(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)

1087:    Collective

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

1094:    Output Parameters:
1095: +  dnz - the array that will be passed to the matrix preallocation routines
1096: -  onz - the other array passed to the matrix preallocation routines

1098:    Level: deprecated (since v3.19)

1100:    Notes:
1101:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1102:    the use of this routine

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

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

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

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

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

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

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

1135:    Not Collective

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

1147:    Level: deprecated (since v3.19)

1149:    Notes:
1150:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1151:    the use of this routine

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

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

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

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

1169:    Not Collective

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

1181:    Level: deprecated (since v3.19)

1183:    Notes:
1184:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1185:    the use of this routine

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

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

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

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

1203:    Not Collective

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

1215:    Level: deprecated (since v3.19)

1217:    Notes:
1218:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1219:    the use of this routine

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

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

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

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

1237:    Not Collective

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

1248:    Level: deprecated (since v3.19)

1250:    Notes:
1251:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1252:    the use of this routine

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

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

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

1266:    Synopsis:
1267: #include <petscmat.h>
1268:    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1270:    Not Collective

1272:    Input Parameters:
1273: +  row   - the row
1274: .  ncols - the number of columns in the matrix
1275: -  cols  - the columns indicated

1277:    Output Parameters:
1278: +  dnz - the array that will be passed to the matrix preallocation routines
1279: -  onz - the other array passed to the matrix preallocation routines

1281:    Level: deprecated (since v3.19)

1283:    Notes:
1284:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1285:    the use of this routine

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

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

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

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

1304:    Synopsis:
1305: #include <petscmat.h>
1306:    PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1308:    Not Collective

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

1318:    Level: deprecated (since v3.19)

1320:    Notes:
1321:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1322:    the use of this routine

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

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

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

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

1340:    Synopsis:
1341: #include <petscmat.h>
1342:    PetscErrorCode MatPreallocateLocations(Mat A, PetscInt row, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1344:    Not Collective

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

1354:    Level: deprecated (since v3.19)

1356:    Notes:
1357:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1358:    the use of this routine

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

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

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

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

1374:    Synopsis:
1375: #include <petscmat.h>
1376:    PetscErrorCode MatPreallocateEnd(PetscInt *dnz, PetscInt *onz)

1378:    Collective

1380:    Input Parameters:
1381: +  dnz - the array that was be passed to the matrix preallocation routines
1382: -  onz - the other array passed to the matrix preallocation routines

1384:    Level: deprecated (since v3.19)

1386:    Notes:
1387:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1388:    the use of this routine

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

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

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

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

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

1408: PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat, IS *, IS *);
1409: PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat, PetscInt *, PetscInt *[], PetscInt *);

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

1418: #define MAT_SKIP_ALLOCATION -4

1420: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1421: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1422: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat, PetscInt, const PetscInt[]);
1423: PETSC_EXTERN PetscErrorCode MatSeqAIJSetTotalPreallocation(Mat, PetscInt);

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

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

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

1451: PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
1452: PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);

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

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

1465:    Level: beginner

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

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

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

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

1492: PETSC_EXTERN PetscErrorCode    MatGetOrdering(Mat, MatOrderingType, IS *, IS *);
1493: PETSC_EXTERN PetscErrorCode    MatGetOrderingList(PetscFunctionList *);
1494: PETSC_EXTERN PetscErrorCode    MatOrderingRegister(const char[], PetscErrorCode (*)(Mat, MatOrderingType, IS *, IS *));
1495: PETSC_EXTERN PetscFunctionList MatOrderingList;

1497: #include "petscmatcoarsen.h"

1499: PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat, PetscReal, IS, IS);
1500: PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat, PetscReal, PetscBool, Mat *);

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

1504: /*S
1505:    MatFactorShiftType - Type of numeric shift used for factorizations

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

1513:    Level: intermediate

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

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

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

1536:     Level: intermediate

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

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

1552: PETSC_EXTERN PetscErrorCode MatFactorGetError(Mat, MatFactorError *);
1553: PETSC_EXTERN PetscErrorCode MatFactorClearError(Mat);
1554: PETSC_EXTERN PetscErrorCode MatFactorGetErrorZeroPivot(Mat, PetscReal *, PetscInt *);

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

1559:    Level: developer

1561:    Note:
1562:    You can use `MatFactorInfoInitialize()` to set default values.

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

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

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

1610: /*E
1611:    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()`

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

1618:    Level: advanced

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

1637: PETSC_EXTERN PetscErrorCode MatSeqDenseInvert(Mat);
1638: /*E
1639:    MatSORType - What type of (S)SOR to perform

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

1653:    Level: beginner

1655:    Note:
1656:    These may be bitwise ORd together

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

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

1677: /*S
1678:    MatColoring - Object for managing the coloring of matrices.

1680:    Level: beginner

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

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

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

1695: /*J
1696:    MatColoringType - String with the name of a PETSc matrix coloring

1698:    Level: beginner

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

1711: /*E
1712:    MatColoringWeightType - Type of weight scheme used for the coloring algorithm

1714:    Values:
1715: +  `MAT_COLORING_RANDOM`  - Random weights
1716: .  `MAT_COLORING_LEXICAL` - Lexical weighting based upon global numbering.
1717: -  `MAT_COLORING_LF`      - Last-first weighting.

1719:     Level: intermediate

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

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

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

1756:    Level: beginner

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

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

1764: .seealso: [](ch_matrices), `Mat`, `MatFDColoringCreate()`, `MatFDColoringSetFunction()`, `MatColoring`, `DMCreateColoring()`
1765: S*/
1766: typedef struct _p_MatFDColoring *MatFDColoring;

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

1771:   Level: advanced

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

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

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

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

1800:    Level: developer

1802: .seealso: [](ch_matrices), `Mat`, `MatProductType`, `MatTransposeColoringCreate()`
1803: S*/
1804: typedef struct _p_MatTransposeColoring *MatTransposeColoring;

1806: PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat, ISColoring, MatTransposeColoring *);
1807: PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring, Mat, Mat);
1808: PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring, Mat, Mat);
1809: PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring *);

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

1814:    Level: beginner

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

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

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

1828: /*J
1829:     MatPartitioningType - String with the name of a PETSc matrix partitioning

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

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

1866: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetRepartition(MatPartitioning);
1867: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1868: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *);

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

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

1880:    Level: intermediate

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

1896:    Values:
1897: +   `MP_CHACO_KERNIGHAN` - apply Kernighan--Lin local refinement to improve the partition
1898: -   `MP_CHACO_NONE`      - no local refinement

1900:    Level: intermediate

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

1913:    Values:
1914: +   `MP_CHACO_LANCZOS` - Lanczos algorithm
1915: -   `MP_CHACO_RQI`     - Rayleigh quotient iteration

1917:    Level: intermediate

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

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

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

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

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

1968:    Level: intermediate

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

1982: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning, PetscReal);
1983: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning, PetscReal *);
1984: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning, MPPTScotchStrategyType);
1985: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning, MPPTScotchStrategyType *);

1987: /*
1988:  * hierarchical partitioning
1989:  */
1990: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetFineparts(MatPartitioning, IS *);
1991: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetCoarseparts(MatPartitioning, IS *);
1992: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNcoarseparts(MatPartitioning, PetscInt);
1993: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNfineparts(MatPartitioning, PetscInt);

1995: typedef const char *MatMeshToCellGraphType;
1996: #define MATMESHTOCELLGRAPHMETIS    "metis"
1997: #define MATMESHTOCELLGRAPHPARMETIS "parmetis"

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

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

2005:    Level: developer

2007:    Notes:
2008:    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.

2010:    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.

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

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

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

2195: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat, PetscReal);

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

2208: /*S
2209:    MatNullSpace - Object that removes a null space from a vector, i.e.
2210:                   orthogonalizes the vector to a subspace

2212:    Level: advanced

2214: .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()`
2215: S*/
2216: typedef struct _p_MatNullSpace *MatNullSpace;

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

2221:   Level: advanced

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

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

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

2249: PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat, IS);
2250: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat, PetscInt *);

2252: PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat, PetscInt, Mat *);
2253: PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat, PetscInt, Mat *);
2254: PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat, Mat *);

2256: PETSC_EXTERN PetscErrorCode MatComputeOperator(Mat, MatType, Mat *);
2257: PETSC_EXTERN PetscErrorCode MatComputeOperatorTranspose(Mat, MatType, Mat *);

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

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

2283: PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat, Vec);

2285: PETSC_EXTERN PetscErrorCode MatMFFDInitializePackage(void);
2286: PETSC_EXTERN PetscErrorCode MatMFFDFinalizePackage(void);

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

2291:   Level: advanced

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

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

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

2305:   Level: advanced

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

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

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

2321:   Level: advanced

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

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

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

2335:   Level: advanced

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

2343:   Note:
2344:   `MatMFFDCheckPositivity()` is one such function

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

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

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

2368:     Level: developer

2370:     Notes:
2371:     `MATMFFD` is a specific `MatType` which uses the `MatMFFD` data structure

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

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

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

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

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

2389:    Level: beginner

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

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

2400: PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat, PetscReal);
2401: PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat, PetscBool);

2403: PETSC_EXTERN PetscErrorCode MatFDColoringSetType(MatFDColoring, MatMFFDType);

2405: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
2406: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);

2408: #if PetscDefined(HAVE_H2OPUS)
2409: PETSC_EXTERN_TYPEDEF typedef PetscScalar(MatH2OpusKernelFn)(PetscInt, PetscReal[], PetscReal[], void *);
2410: PETSC_EXTERN_TYPEDEF typedef MatH2OpusKernelFn *MatH2OpusKernel;

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

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

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

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

2440:   Level: intermediate

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

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

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

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

2474:    Level: intermediate

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

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

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

2493:    Level: intermediate

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

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

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

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

2525: PETSC_EXTERN PetscErrorCode MatMumpsSetOocTmpDir(Mat, const char *);
2526: PETSC_EXTERN PetscErrorCode MatMumpsGetOocTmpDir(Mat, const char *[]);

2528: #if PetscDefined(HAVE_MKL_PARDISO)
2529: PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat, PetscInt, PetscInt);
2530: #endif

2532: #if PetscDefined(HAVE_MKL_CPARDISO)
2533: PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat, PetscInt, PetscInt);
2534: #endif

2536: #if PetscDefined(HAVE_SUPERLU)
2537: PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat, PetscReal);
2538: #endif

2540: #if PetscDefined(HAVE_SUPERLU_DIST)
2541: PETSC_EXTERN PetscErrorCode MatSuperluDistGetDiagU(Mat, PetscScalar *);
2542: #endif

2544: /*E
2545:     MatSTRUMPACKReordering - sparsity reducing ordering to be used in `MATSOLVERSTRUMPACK`

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

2561:     Level: intermediate

2563:     Developer Note:
2564:     Should be called `MatSTRUMPACKReorderingType`

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

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

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

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

2607:     Level: intermediate

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

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

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

2647: #if PetscDefined(HAVE_CUDA)
2648: /*E
2649:     MatCUSPARSEStorageFormat - indicates the storage format for `MATAIJCUSPARSE` (GPU)
2650:     matrices.

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

2657:     Level: intermediate

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

2662: typedef enum {
2663:   MAT_CUSPARSE_CSR,
2664:   MAT_CUSPARSE_ELL,
2665:   MAT_CUSPARSE_HYB
2666: } MatCUSPARSEStorageFormat;

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

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

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

2681:     Level: intermediate

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

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

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

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

2721: #if PetscDefined(HAVE_HIP)
2722: /*E
2723:     MatHIPSPARSEStorageFormat - indicates the storage format for `MATAIJHIPSPARSE` (GPU)
2724:     matrices.

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

2731:     Level: intermediate

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

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

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

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

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

2755:     Level: intermediate

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

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

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

2794: #if PetscDefined(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 PetscDefined(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 PetscDefined(HAVE_SCALAPACK) && (PetscDefined(USE_REAL_SINGLE) || PetscDefined(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);