Actual source code: petscmat.h

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

  6: #include <petscvec.h>

  8: /* SUBMANSEC = Mat */

 10: /*S
 11:    Mat - Abstract PETSc matrix object used to manage all linear operators in PETSc, even those without
 12:          an explicit sparse representation (such as matrix-free operators). Also used to hold representations of graphs
 13:          for graph operations such as coloring, `MatColoringCreate()`

 15:    Level: beginner

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

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

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

 27:    Level: beginner

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

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

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

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

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

150:    Level: beginner

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

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

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

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

195:     Level: beginner

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

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

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

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

233:   Level: developer

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

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

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

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

263:     Level: beginner

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

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

281:    Level: beginner

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

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

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

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

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

344:     Level: beginner

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

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

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

363:     Level: developer

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

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

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

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

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

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

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

410:    Level: beginner

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

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

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

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

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

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

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

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

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

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

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

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

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

499:    Values:
500: +   `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)
501: -   `MAT_COMPOSITE_MERGE_LEFT`  - merge into a single matrix starting from the leftmost matrix

503:    Level: advanced

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

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

520:     Level: beginner

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

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

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

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

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

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

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

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

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

595:    Level: beginner

597:    Notes:
598:    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).
599:    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.

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

603:    For staggered grids, see `DMStagStencil`

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

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

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

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

623:     Level: beginner

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

632: PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat, MatAssemblyType);
633: PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat, MatAssemblyType);
634: PETSC_EXTERN PetscErrorCode MatAssembled(Mat, PetscBool *);

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

639:    Level: beginner

641:    Note:
642:    See `MatSetOption()` for the use of the options

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

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

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

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

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

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

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

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

776:   Level: beginner

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

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

790: PETSC_EXTERN PetscErrorCode MatConvert(Mat, MatType, MatReuse, Mat *);
791: PETSC_EXTERN PetscErrorCode MatDuplicate(Mat, MatDuplicateOption, Mat *);

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

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

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

812:    Level: intermediate

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

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

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

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

838:     Level: beginner

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

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

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

895: PETSC_EXTERN PetscErrorCode MatGetSize(Mat, PetscInt *, PetscInt *);
896: PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat, PetscInt *, PetscInt *);
897: PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat, PetscInt *, PetscInt *);
898: PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat, const PetscInt **);
899: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat, PetscInt *, PetscInt *);
900: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat, const PetscInt **);
901: PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat, IS *, IS *);

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

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

936: PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat, PetscInt, IS[], PetscInt);
937: PETSC_EXTERN PetscErrorCode MatIncreaseOverlapSplit(Mat, PetscInt, IS[], PetscInt);
938: PETSC_EXTERN PetscErrorCode MatMPIAIJSetUseScalableIncreaseOverlap(Mat, PetscBool);

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

942: PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);
943: PETSC_EXTERN PetscErrorCode MatGalerkin(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);

945: PETSC_EXTERN PetscErrorCode MatPtAP(Mat, Mat, MatReuse, PetscReal, Mat *);
946: PETSC_EXTERN PetscErrorCode MatRARt(Mat, Mat, MatReuse, PetscReal, Mat *);

948: PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat, Mat, MatReuse, PetscReal, Mat *);
949: PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat, Mat, MatReuse, PetscReal, Mat *);

951: PETSC_EXTERN PetscErrorCode MatAXPY(Mat, PetscScalar, Mat, MatStructure);
952: PETSC_EXTERN PetscErrorCode MatAYPX(Mat, PetscScalar, Mat, MatStructure);

954: PETSC_EXTERN PetscErrorCode MatScale(Mat, PetscScalar);
955: PETSC_EXTERN PetscErrorCode MatShift(Mat, PetscScalar);

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

969: PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat, PetscInt, PetscInt);
970: PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat, PetscInt *, PetscInt *, PetscInt *, PetscInt *);

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

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

993:    Not Collective

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

1002:    Level: beginner

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

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

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

1018: /*@C
1019:    MatGetValue - Gets a single value from a matrix

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

1023:    Input Parameters:
1024: +  mat - the matrix
1025: .  row - the row location of the entry
1026: -  col - the column location of the entry

1028:    Output Parameter:
1029: .  va - the value

1031:    Level: advanced

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

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

1038:    See notes for `MatGetValues()`.

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

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

1050:    Not Collective

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

1059:    Level: intermediate

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

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

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

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

1077:    Synopsis:
1078: #include <petscmat.h>
1079:    PetscErrorCode MatPreallocateBegin(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)

1081:    Collective

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

1088:    Output Parameters:
1089: +  dnz - the array that will be passed to the matrix preallocation routines
1090: -  onz - the other array passed to the matrix preallocation routines

1092:    Level: deprecated (since v3.19)

1094:    Notes:
1095:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1096:    the use of this routine

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

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

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

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

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

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

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

1129:    Not Collective

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

1141:    Level: deprecated (since v3.19)

1143:    Notes:
1144:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1145:    the use of this routine

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

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

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

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

1163:    Not Collective

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

1175:    Level: deprecated (since v3.19)

1177:    Notes:
1178:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1179:    the use of this routine

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

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

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

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

1197:    Not Collective

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

1209:    Level: deprecated (since v3.19)

1211:    Notes:
1212:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1213:    the use of this routine

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

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

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

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

1231:    Not Collective

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

1242:    Level: deprecated (since v3.19)

1244:    Notes:
1245:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1246:    the use of this routine

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

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

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

1260:    Synopsis:
1261: #include <petscmat.h>
1262:    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1264:    Not Collective

1266:    Input Parameters:
1267: +  row   - the row
1268: .  ncols - the number of columns in the matrix
1269: -  cols  - the columns indicated

1271:    Output Parameters:
1272: +  dnz - the array that will be passed to the matrix preallocation routines
1273: -  onz - the other array passed to the matrix preallocation routines

1275:    Level: deprecated (since v3.19)

1277:    Notes:
1278:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1279:    the use of this routine

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

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

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

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

1298:    Synopsis:
1299: #include <petscmat.h>
1300:    PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows,PetscInt ncols, PetscInt *cols,PetscInt *dnz, PetscInt *onz)

1302:    Not Collective

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

1312:    Level: deprecated (since v3.19)

1314:    Notes:
1315:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1316:    the use of this routine

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

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

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

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

1334:    Synopsis:
1335: #include <petscmat.h>
1336:    PetscErrorCode MatPreallocateLocations(Mat A,PetscInt row,PetscInt ncols,PetscInt *cols,PetscInt *dnz,PetscInt *onz)

1338:    Not Collective

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

1348:    Level: deprecated (since v3.19)

1350:    Notes:
1351:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1352:    the use of this routine

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

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

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

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

1368:    Synopsis:
1369: #include <petscmat.h>
1370:    PetscErrorCode MatPreallocateEnd(PetscInt *dnz, PetscInt *onz)

1372:    Collective

1374:    Input Parameters:
1375: +  dnz - the array that was be passed to the matrix preallocation routines
1376: -  onz - the other array passed to the matrix preallocation routines

1378:    Level: deprecated (since v3.19)

1380:    Notes:
1381:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1382:    the use of this routine

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

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

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

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

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

1402: PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat, IS *, IS *);
1403: PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat, PetscInt *, PetscInt *[], PetscInt *);

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

1412: #define MAT_SKIP_ALLOCATION -4

1414: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1415: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1416: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat, PetscInt, const PetscInt[]);
1417: PETSC_EXTERN PetscErrorCode MatSeqAIJSetTotalPreallocation(Mat, PetscInt);

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

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

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

1445: PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
1446: PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);

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

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

1459:    Level: beginner

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

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

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

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

1486: PETSC_EXTERN PetscErrorCode    MatGetOrdering(Mat, MatOrderingType, IS *, IS *);
1487: PETSC_EXTERN PetscErrorCode    MatGetOrderingList(PetscFunctionList *);
1488: PETSC_EXTERN PetscErrorCode    MatOrderingRegister(const char[], PetscErrorCode (*)(Mat, MatOrderingType, IS *, IS *));
1489: PETSC_EXTERN PetscFunctionList MatOrderingList;

1491: #include "petscmatcoarsen.h"

1493: PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat, PetscReal, IS, IS);
1494: PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat, PetscReal, PetscBool, Mat *);

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

1498: /*S
1499:    MatFactorShiftType - Type of numeric shift used for factorizations

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

1507:    Level: intermediate

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

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

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

1530:     Level: intermediate

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

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

1546: PETSC_EXTERN PetscErrorCode MatFactorGetError(Mat, MatFactorError *);
1547: PETSC_EXTERN PetscErrorCode MatFactorClearError(Mat);
1548: PETSC_EXTERN PetscErrorCode MatFactorGetErrorZeroPivot(Mat, PetscReal *, PetscInt *);

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

1553:    Level: developer

1555:    Note:
1556:    You can use `MatFactorInfoInitialize()` to set default values.

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

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

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

1604: /*E
1605:    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()`

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

1612:    Level: advanced

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

1631: PETSC_EXTERN PetscErrorCode MatSeqDenseInvert(Mat);
1632: /*E
1633:    MatSORType - What type of (S)SOR to perform

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

1647:    Level: beginner

1649:    Note:
1650:    These may be bitwise ORd together

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

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

1671: /*S
1672:    MatColoring - Object for managing the coloring of matrices.

1674:    Level: beginner

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

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

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

1689: /*J
1690:    MatColoringType - String with the name of a PETSc matrix coloring

1692:    Level: beginner

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

1705: /*E
1706:    MatColoringWeightType - Type of weight scheme used for the coloring algorithm

1708:    Values:
1709: +  `MAT_COLORING_RANDOM`  - Random weights
1710: .  `MAT_COLORING_LEXICAL` - Lexical weighting based upon global numbering.
1711: -  `MAT_COLORING_LF`      - Last-first weighting.

1713:     Level: intermediate

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

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

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

1750:    Level: beginner

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

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

1758: .seealso: [](ch_matrices), `Mat`, `MatFDColoringCreate()`, `MatFDColoringSetFunction()`, `MatColoring`, `DMCreateColoring()`
1759: S*/
1760: typedef struct _p_MatFDColoring *MatFDColoring;

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

1765:   Level: advanced

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

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

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

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

1794:    Level: developer

1796: .seealso: [](ch_matrices), `Mat`, `MatProductType`, `MatTransposeColoringCreate()`
1797: S*/
1798: typedef struct _p_MatTransposeColoring *MatTransposeColoring;

1800: PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat, ISColoring, MatTransposeColoring *);
1801: PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring, Mat, Mat);
1802: PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring, Mat, Mat);
1803: PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring *);

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

1808:    Level: beginner

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

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

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

1822: /*J
1823:     MatPartitioningType - String with the name of a PETSc matrix partitioning

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

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

1860: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetRepartition(MatPartitioning);
1861: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
1862: PETSC_EXTERN PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning, PetscInt *);

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

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

1874:    Level: intermediate

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

1890:    Values:
1891: +   `MP_CHACO_KERNIGHAN` - apply Kernighan--Lin local refinement to improve the partition
1892: -   `MP_CHACO_NONE`      - no local refinement

1894:    Level: intermediate

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

1907:    Values:
1908: +   `MP_CHACO_LANCZOS` - Lanczos algorithm
1909: -   `MP_CHACO_RQI`     - Rayleigh quotient iteration

1911:    Level: intermediate

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

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

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

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

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

1962:    Level: intermediate

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

1976: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning, PetscReal);
1977: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning, PetscReal *);
1978: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning, MPPTScotchStrategyType);
1979: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning, MPPTScotchStrategyType *);

1981: /*
1982:  * hierarchical partitioning
1983:  */
1984: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetFineparts(MatPartitioning, IS *);
1985: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetCoarseparts(MatPartitioning, IS *);
1986: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNcoarseparts(MatPartitioning, PetscInt);
1987: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNfineparts(MatPartitioning, PetscInt);

1989: PETSC_EXTERN PetscErrorCode MatMeshToCellGraph(Mat, PetscInt, Mat *);

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

1994:    Level: developer

1996:    Notes:
1997:    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.

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

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

2155: PETSC_EXTERN PetscErrorCode MatSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2156: PETSC_EXTERN PetscErrorCode MatGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2157: PETSC_EXTERN PetscErrorCode MatHasOperation(Mat, MatOperation, PetscBool *);
2158: PETSC_EXTERN PetscErrorCode MatHasCongruentLayouts(Mat, PetscBool *);
2159: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatProductClear()", ) static inline PetscErrorCode MatFreeIntermediateDataStructures(Mat A)
2160: {
2161:   return MatProductClear(A);
2162: }
2163: PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2164: PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2165: PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat, PetscCtx);
2166: PETSC_EXTERN PetscErrorCode MatShellSetContextDestroy(Mat, PetscCtxDestroyFn *);
2167: PETSC_EXTERN PetscErrorCode MatShellSetVecType(Mat, VecType);
2168: PETSC_EXTERN PetscErrorCode MatShellTestMult(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2169: PETSC_EXTERN PetscErrorCode MatShellTestMultTranspose(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2170: PETSC_EXTERN PetscErrorCode MatShellSetManageScalingShifts(Mat);
2171: PETSC_EXTERN PetscErrorCode MatShellSetMatProductOperation(Mat, MatProductType, PetscErrorCode (*)(Mat, Mat, Mat, void **), PetscErrorCode (*)(Mat, Mat, Mat, void *), PetscCtxDestroyFn *, MatType, MatType);
2172: PETSC_EXTERN PetscErrorCode MatIsShell(Mat, PetscBool *);

2174: /*
2175:    Codes for matrices stored on disk. By default they are
2176:    stored in a universal format. By changing the format with
2177:    PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will
2178:    be stored in a way natural for the matrix, for example dense matrices
2179:    would be stored as dense. Matrices stored this way may only be
2180:    read into matrices of the same type.
2181: */
2182: #define MATRIX_BINARY_FORMAT_DENSE -1

2184: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat, PetscReal);

2186: PETSC_EXTERN PetscErrorCode MatISSetLocalMatType(Mat, MatType);
2187: PETSC_EXTERN PetscErrorCode MatISSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
2188: PETSC_EXTERN PetscErrorCode MatISSetAllowRepeated(Mat, PetscBool);
2189: PETSC_EXTERN PetscErrorCode MatISGetAllowRepeated(Mat, PetscBool *);
2190: PETSC_EXTERN PetscErrorCode MatISStoreL2L(Mat, PetscBool);
2191: PETSC_EXTERN PetscErrorCode MatISFixLocalEmpty(Mat, PetscBool);
2192: PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat, Mat *);
2193: PETSC_EXTERN PetscErrorCode MatISRestoreLocalMat(Mat, Mat *);
2194: PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat, Mat);
2195: PETSC_EXTERN PetscErrorCode MatISGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *);

2197: /*S
2198:    MatNullSpace - Object that removes a null space from a vector, i.e.
2199:                   orthogonalizes the vector to a subspace

2201:    Level: advanced

2203: .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()`
2204: S*/
2205: typedef struct _p_MatNullSpace *MatNullSpace;

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

2210:   Level: advanced

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

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

2221: PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm, PetscBool, PetscInt, const Vec[], MatNullSpace *);
2222: PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace, MatNullSpaceRemoveFn *, void *);
2223: PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace *);
2224: PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace, Vec);
2225: PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *);
2226: PETSC_EXTERN PetscErrorCode MatGetTransposeNullSpace(Mat, MatNullSpace *);
2227: PETSC_EXTERN PetscErrorCode MatSetTransposeNullSpace(Mat, MatNullSpace);
2228: PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat, MatNullSpace);
2229: PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat, MatNullSpace);
2230: PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat, MatNullSpace *);
2231: PETSC_EXTERN PetscErrorCode MatGetNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2232: PETSC_EXTERN PetscErrorCode MatRestoreNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2233: PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace, Mat, PetscBool *);
2234: PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace, PetscViewer);
2235: PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace, PetscBool *, PetscInt *, const Vec **);
2236: PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec, MatNullSpace *);

2238: PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat, IS);
2239: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetHashTableFactor(Mat, PetscReal);
2240: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat, PetscInt *);

2242: PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat, PetscInt, Mat *);
2243: PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat, PetscInt, Mat *);
2244: PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat, Mat *);

2246: PETSC_EXTERN PetscErrorCode MatComputeOperator(Mat, MatType, Mat *);
2247: PETSC_EXTERN PetscErrorCode MatComputeOperatorTranspose(Mat, MatType, Mat *);

2249: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperator()", ) static inline PetscErrorCode MatComputeExplicitOperator(Mat A, Mat *B)
2250: {
2251:   return MatComputeOperator(A, PETSC_NULLPTR, B);
2252: }
2253: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperatorTranspose()", ) static inline PetscErrorCode MatComputeExplicitOperatorTranspose(Mat A, Mat *B)
2254: {
2255:   return MatComputeOperatorTranspose(A, PETSC_NULLPTR, B);
2256: }

2258: PETSC_EXTERN PetscErrorCode MatCreateKAIJ(Mat, PetscInt, PetscInt, const PetscScalar[], const PetscScalar[], Mat *);
2259: PETSC_EXTERN PetscErrorCode MatKAIJGetAIJ(Mat, Mat *);
2260: PETSC_EXTERN PetscErrorCode MatKAIJGetS(Mat, PetscInt *, PetscInt *, PetscScalar **);
2261: PETSC_EXTERN PetscErrorCode MatKAIJGetSRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2262: PETSC_EXTERN PetscErrorCode MatKAIJRestoreS(Mat, PetscScalar **);
2263: PETSC_EXTERN PetscErrorCode MatKAIJRestoreSRead(Mat, const PetscScalar **);
2264: PETSC_EXTERN PetscErrorCode MatKAIJGetT(Mat, PetscInt *, PetscInt *, PetscScalar **);
2265: PETSC_EXTERN PetscErrorCode MatKAIJGetTRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2266: PETSC_EXTERN PetscErrorCode MatKAIJRestoreT(Mat, PetscScalar **);
2267: PETSC_EXTERN PetscErrorCode MatKAIJRestoreTRead(Mat, const PetscScalar **);
2268: PETSC_EXTERN PetscErrorCode MatKAIJSetAIJ(Mat, Mat);
2269: PETSC_EXTERN PetscErrorCode MatKAIJSetS(Mat, PetscInt, PetscInt, const PetscScalar[]);
2270: PETSC_EXTERN PetscErrorCode MatKAIJSetT(Mat, PetscInt, PetscInt, const PetscScalar[]);
2271: PETSC_EXTERN PetscErrorCode MatKAIJGetScaledIdentity(Mat, PetscBool *);

2273: PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat, Vec);

2275: PETSC_EXTERN PetscErrorCode MatMFFDInitializePackage(void);
2276: PETSC_EXTERN PetscErrorCode MatMFFDFinalizePackage(void);

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

2281:   Level: advanced

2283:   Calling Sequence:
2284: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2285: . x   - input vector
2286: - y   - output vector

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

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

2295:   Level: advanced

2297:   Calling Sequence:
2298: + ctx    - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2299: . i      - the component of the vector to compute
2300: . x      - input vector
2301: - result - the value of the function at that component (output)

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

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

2311:   Level: advanced

2313:   Calling Sequence:
2314: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2315: - x   - input base vector

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

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

2325:   Level: advanced

2327:   Calling Sequence:
2328: + ctx - [optional] user-defined function context provided with `MatMFFDSetCheckh()`
2329: . x   - input base vector
2330: . y   - input step vector that the product is computed with
2331: - h   - input tentative step, output possibly adjusted step

2333:   Note:
2334:   `MatMFFDCheckPositivity()` is one such function

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

2340: PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2341: PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat, Vec, Vec);
2342: PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat, MatMFFDFn *, void *);
2343: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat, MatMFFDiFn *);
2344: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat, MatMFFDiBaseFn *);
2345: PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat, PetscScalar[], PetscInt);
2346: PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat);
2347: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat, PetscReal);
2348: PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat, PetscInt);
2349: PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat, PetscScalar *);
2350: PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat, const char[]);
2351: PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void *, Vec, Vec, PetscScalar *);
2352: PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat, MatMFFDCheckhFn *, void *);

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

2358:     Level: developer

2360:     Notes:
2361:     `MATMFFD` is a specific `MatType` which uses the `MatMFFD` data structure

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

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

2367: .seealso: [](ch_matrices), `MatMFFDType`, `MATMFFD`, `MatCreateMFFD()`, `MatMFFDSetFuction()`, `MatMFFDSetType()`, `MatMFFDRegister()`,
2368:           `MatCreateSNESMF()`, `SNES`, `-snes_mf`, `-snes_mf_operator`
2369: S*/
2370: typedef struct _p_MatMFFD *MatMFFD;

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

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

2379:    Level: beginner

2381: .seealso: [](ch_matrices), `MatMFFDSetType()`, `MatMFFDRegister()`, `MatMFFDSetFunction()`, `MatCreateMFFD()`
2382: J*/
2383: typedef const char *MatMFFDType;
2384: #define MATMFFD_DS "ds"
2385: #define MATMFFD_WP "wp"

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

2390: PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat, PetscReal);
2391: PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat, PetscBool);

2393: PETSC_EXTERN PetscErrorCode MatFDColoringSetType(MatFDColoring, MatMFFDType);

2395: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
2396: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);

2398: #ifdef PETSC_HAVE_H2OPUS
2399: PETSC_EXTERN_TYPEDEF typedef PetscScalar(MatH2OpusKernelFn)(PetscInt, PetscReal[], PetscReal[], void *);
2400: PETSC_EXTERN_TYPEDEF typedef MatH2OpusKernelFn *MatH2OpusKernel;

2402: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], PetscBool, MatH2OpusKernelFn *, void *, PetscReal, PetscInt, PetscInt, Mat *);
2403: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromMat(Mat, PetscInt, const PetscReal[], PetscBool, PetscReal, PetscInt, PetscInt, PetscInt, PetscReal, Mat *);
2404: PETSC_EXTERN PetscErrorCode MatH2OpusSetSamplingMat(Mat, Mat, PetscInt, PetscReal);
2405: PETSC_EXTERN PetscErrorCode MatH2OpusOrthogonalize(Mat);
2406: PETSC_EXTERN PetscErrorCode MatH2OpusCompress(Mat, PetscReal);
2407: PETSC_EXTERN PetscErrorCode MatH2OpusSetNativeMult(Mat, PetscBool);
2408: PETSC_EXTERN PetscErrorCode MatH2OpusGetNativeMult(Mat, PetscBool *);
2409: PETSC_EXTERN PetscErrorCode MatH2OpusGetIndexMap(Mat, IS *);
2410: PETSC_EXTERN PetscErrorCode MatH2OpusMapVec(Mat, PetscBool, Vec, Vec *);
2411: PETSC_EXTERN PetscErrorCode MatH2OpusLowRankUpdate(Mat, Mat, Mat, PetscScalar);
2412: #endif

2414: #ifdef PETSC_HAVE_HTOOL
2415: /*S
2416:   MatHtoolKernelFn - Function type for the user-supplied kernel callback used by `MATHTOOL` (`MatCreateHtoolFromKernel()`, `MatHtoolSetKernel()`) to evaluate the dense matrix entries on demand

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

2422:   Calling Sequence:
2423: + sdim - the spatial dimension of the source/target geometries
2424: . M    - the number of target points
2425: . N    - the number of source points
2426: . J    - array of `M` target point indices into the user's target coordinate array
2427: . K    - array of `N` source point indices into the user's source coordinate array
2428: . ptr  - column-major output buffer of length `M*N` to fill with kernel values
2429: - ctx  - the optional user context passed at registration

2431:   Level: intermediate

2433: .seealso: `Mat`, `MATHTOOL`, `MatCreateHtoolFromKernel()`, `MatHtoolSetKernel()`
2434: S*/
2435: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode    MatHtoolKernelFn(PetscInt, PetscInt, PetscInt, const PetscInt *, const PetscInt *, PetscScalar *, void *);
2436: PETSC_EXTERN_TYPEDEF typedef MatHtoolKernelFn *MatHtoolKernel;

2438: PETSC_EXTERN PetscErrorCode MatCreateHtoolFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], const PetscReal[], MatHtoolKernelFn *, void *, Mat *);
2439: PETSC_EXTERN PetscErrorCode MatHtoolSetKernel(Mat, MatHtoolKernelFn *, void *);
2440: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationSource(Mat, IS *);
2441: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationTarget(Mat, IS *);
2442: PETSC_EXTERN PetscErrorCode MatHtoolUsePermutation(Mat, PetscBool);
2443: PETSC_EXTERN PetscErrorCode MatHtoolUseRecompression(Mat, PetscBool);

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

2448:    Values:
2449: +  `MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA` (default) - symmetric partial adaptive cross approximation
2450: .  `MAT_HTOOL_COMPRESSOR_FULL_ACA`                 - full adaptive cross approximation
2451: -  `MAT_HTOOL_COMPRESSOR_SVD`                      - singular value decomposition

2453:    Level: intermediate

2455: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolClusteringType`
2456: E*/
2457: typedef enum {
2458:   MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA,
2459:   MAT_HTOOL_COMPRESSOR_FULL_ACA,
2460:   MAT_HTOOL_COMPRESSOR_SVD
2461: } MatHtoolCompressorType;

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

2466:    Values:
2467: +  `MAT_HTOOL_CLUSTERING_PCA_REGULAR` (default)    - axis computed via principle component analysis, split uniformly
2468: .  `MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC`            - axis computed via principle component analysis, split barycentrically
2469: .  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR`   - axis along the largest extent of the bounding box, split uniformly
2470: -  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC` - axis along the largest extent of the bounding box, split barycentrically

2472:    Level: intermediate

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

2477: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolCompressorType`
2478: E*/
2479: typedef enum {
2480:   MAT_HTOOL_CLUSTERING_PCA_REGULAR,
2481:   MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC,
2482:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR,
2483:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC
2484: } MatHtoolClusteringType;
2485: #endif

2487: PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat, PetscInt, PetscInt);
2488: PETSC_EXTERN PetscErrorCode MatMumpsGetIcntl(Mat, PetscInt, PetscInt *);
2489: PETSC_EXTERN PetscErrorCode MatMumpsSetCntl(Mat, PetscInt, PetscReal);
2490: PETSC_EXTERN PetscErrorCode MatMumpsGetCntl(Mat, PetscInt, PetscReal *);

2492: PETSC_EXTERN PetscErrorCode MatMumpsGetInfo(Mat, PetscInt, PetscInt *);
2493: PETSC_EXTERN PetscErrorCode MatMumpsGetInfog(Mat, PetscInt, PetscInt *);
2494: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfo(Mat, PetscInt, PetscReal *);
2495: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfog(Mat, PetscInt, PetscReal *);
2496: PETSC_EXTERN PetscErrorCode MatMumpsGetNullPivots(Mat, PetscInt *, PetscInt **);
2497: PETSC_EXTERN PetscErrorCode MatMumpsGetInverse(Mat, Mat);
2498: PETSC_EXTERN PetscErrorCode MatMumpsGetInverseTranspose(Mat, Mat);
2499: PETSC_EXTERN PetscErrorCode MatMumpsSetBlk(Mat, PetscInt, const PetscInt[], const PetscInt[]);

2501: PETSC_EXTERN PetscErrorCode MatMumpsSetOocTmpDir(Mat, const char *);
2502: PETSC_EXTERN PetscErrorCode MatMumpsGetOocTmpDir(Mat, const char **);

2504: #ifdef PETSC_HAVE_MKL_PARDISO
2505: PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat, PetscInt, PetscInt);
2506: #endif

2508: #ifdef PETSC_HAVE_MKL_CPARDISO
2509: PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat, PetscInt, PetscInt);
2510: #endif

2512: #ifdef PETSC_HAVE_SUPERLU
2513: PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat, PetscReal);
2514: #endif

2516: #ifdef PETSC_HAVE_SUPERLU_DIST
2517: PETSC_EXTERN PetscErrorCode MatSuperluDistGetDiagU(Mat, PetscScalar *);
2518: #endif

2520: #ifdef PETSC_HAVE_STRUMPACK
2521: /*E
2522:     MatSTRUMPACKReordering - sparsity reducing ordering to be used in `MATSOLVERSTRUMPACK`

2524:     Values:
2525: +  `MAT_STRUMPACK_NATURAL`   - use the current ordering
2526: .  `MAT_STRUMPACK_METIS`     - use MeTis to compute an ordering
2527: .  `MAT_STRUMPACK_PARMETIS`  - use ParMeTis to compute an ordering
2528: .  `MAT_STRUMPACK_SCOTCH`    - use Scotch to compute an ordering
2529: .  `MAT_STRUMPACK_PTSCOTCH`  - use parallel Scotch to compute an ordering
2530: .  `MAT_STRUMPACK_RCM`       - use an RCM ordering
2531: .  `MAT_STRUMPACK_GEOMETRIC` - use a geometric ordering (needs mesh info from user)
2532: .  `MAT_STRUMPACK_AMD`       - approximate minimum degree
2533: .  `MAT_STRUMPACK_MMD`       - multiple minimum degree
2534: .  `MAT_STRUMPACK_AND`       - approximate nested dissection
2535: .  `MAT_STRUMPACK_MLF`       - minimum local fill
2536: -  `MAT_STRUMPACK_SPECTRAL`  - spectral nested dissection

2538:     Level: intermediate

2540:     Developer Note:
2541:     Should be called `MatSTRUMPACKReorderingType`

2543: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetReordering()`
2544: E*/
2545: typedef enum {
2546:   MAT_STRUMPACK_NATURAL,
2547:   MAT_STRUMPACK_METIS,
2548:   MAT_STRUMPACK_PARMETIS,
2549:   MAT_STRUMPACK_SCOTCH,
2550:   MAT_STRUMPACK_PTSCOTCH,
2551:   MAT_STRUMPACK_RCM,
2552:   MAT_STRUMPACK_GEOMETRIC,
2553:   MAT_STRUMPACK_AMD,
2554:   MAT_STRUMPACK_MMD,
2555:   MAT_STRUMPACK_AND,
2556:   MAT_STRUMPACK_MLF,
2557:   MAT_STRUMPACK_SPECTRAL
2558: } MatSTRUMPACKReordering;

2560: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetReordering(Mat, MatSTRUMPACKReordering);
2561: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetReordering(Mat, MatSTRUMPACKReordering *);
2562: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricNxyz(Mat, PetscInt, PetscInt, PetscInt);
2563: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricComponents(Mat, PetscInt);
2564: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricWidth(Mat, PetscInt);
2565: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetColPerm(Mat, PetscBool);
2566: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetColPerm(Mat, PetscBool *);
2567: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGPU(Mat, PetscBool);
2568: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetGPU(Mat, PetscBool *);

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

2573:     Values:
2574: +  `MAT_STRUMPACK_COMPRESSION_TYPE_NONE`          - no compression, direct solver
2575: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HSS`           - hierarchically semi-separable
2576: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR`           - block low rank
2577: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HODLR`         - hierarchically off-diagonal low rank (requires ButterfyPACK support, configure with --download-butterflypack)
2578: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR`     - hybrid of BLR and HODLR (requires ButterfyPACK support, configure with --download-butterflypack)
2579: .  `MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR` - hybrid of lossy (ZFP), BLR and HODLR (requires ButterfyPACK and ZFP support, configure with --download-butterflypack --download-zfp)
2580: .  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS`      - lossless compression (requires ZFP support, configure with --download-zfp)
2581: -  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY`         - lossy compression (requires ZFP support, configure with --download-zfp)

2583:     Level: intermediate

2585: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompression()`
2586: E*/
2587: typedef enum {
2588:   MAT_STRUMPACK_COMPRESSION_TYPE_NONE,
2589:   MAT_STRUMPACK_COMPRESSION_TYPE_HSS,
2590:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR,
2591:   MAT_STRUMPACK_COMPRESSION_TYPE_HODLR,
2592:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR,
2593:   MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR,
2594:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS,
2595:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY
2596: } MatSTRUMPACKCompressionType;

2598: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompression(Mat, MatSTRUMPACKCompressionType);
2599: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompression(Mat, MatSTRUMPACKCompressionType *);
2600: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompRelTol(Mat, PetscReal);
2601: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompRelTol(Mat, PetscReal *);
2602: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompAbsTol(Mat, PetscReal);
2603: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompAbsTol(Mat, PetscReal *);
2604: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompMinSepSize(Mat, PetscInt);
2605: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompMinSepSize(Mat, PetscInt *);
2606: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLeafSize(Mat, PetscInt);
2607: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLeafSize(Mat, PetscInt *);
2608: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLossyPrecision(Mat, PetscInt);
2609: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLossyPrecision(Mat, PetscInt *);
2610: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompButterflyLevels(Mat, PetscInt);
2611: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompButterflyLevels(Mat, PetscInt *);
2612: #endif

2614: PETSC_EXTERN PetscErrorCode MatBindToCPU(Mat, PetscBool);
2615: PETSC_EXTERN PetscErrorCode MatBoundToCPU(Mat, PetscBool *);
2616: PETSC_DEPRECATED_FUNCTION(3, 13, 0, "MatBindToCPU()", ) static inline PetscErrorCode MatPinToCPU(Mat A, PetscBool flg)
2617: {
2618:   return MatBindToCPU(A, flg);
2619: }
2620: PETSC_EXTERN PetscErrorCode MatSetBindingPropagates(Mat, PetscBool);
2621: PETSC_EXTERN PetscErrorCode MatGetBindingPropagates(Mat, PetscBool *);

2623: #ifdef PETSC_HAVE_CUDA
2624: /*E
2625:     MatCUSPARSEStorageFormat - indicates the storage format for `MATAIJCUSPARSE` (GPU)
2626:     matrices.

2628:     Values:
2629: +   `MAT_CUSPARSE_CSR` - Compressed Sparse Row
2630: .   `MAT_CUSPARSE_ELL` - Ellpack (requires CUDA 4.2 or later).
2631: -   `MAT_CUSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format (requires CUDA 4.2 or later).

2633:     Level: intermediate

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

2638: typedef enum {
2639:   MAT_CUSPARSE_CSR,
2640:   MAT_CUSPARSE_ELL,
2641:   MAT_CUSPARSE_HYB
2642: } MatCUSPARSEStorageFormat;

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

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

2651:     Values:
2652: +   `MAT_CUSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2653: .   `MAT_CUSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2654: .   `MAT_CUSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2655: -   `MAT_CUSPARSE_ALL`          - sets the storage format for all `MATAIJCUSPARSE` (GPU) matrices

2657:     Level: intermediate

2659: .seealso: [](ch_matrices), `MatCUSPARSESetFormat()`, `MatCUSPARSEStorageFormat`
2660: E*/
2661: typedef enum {
2662:   MAT_CUSPARSE_MULT_DIAG,
2663:   MAT_CUSPARSE_MULT_OFFDIAG,
2664:   MAT_CUSPARSE_MULT,
2665:   MAT_CUSPARSE_ALL
2666: } MatCUSPARSEFormatOperation;

2668: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2669: PETSC_EXTERN PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2670: PETSC_EXTERN PetscErrorCode MatCUSPARSESetFormat(Mat, MatCUSPARSEFormatOperation, MatCUSPARSEStorageFormat);
2671: PETSC_EXTERN PetscErrorCode MatCUSPARSESetUseCPUSolve(Mat, PetscBool);
2672: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetIJ(Mat, PetscBool, const int **, const int **);
2673: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreIJ(Mat, PetscBool, const int **, const int **);
2674: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayRead(Mat, const PetscScalar **);
2675: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayRead(Mat, const PetscScalar **);
2676: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayWrite(Mat, PetscScalar **);
2677: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayWrite(Mat, PetscScalar **);
2678: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArray(Mat, PetscScalar **);
2679: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArray(Mat, PetscScalar **);

2681: PETSC_EXTERN PetscErrorCode MatCreateDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2682: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2683: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayWrite(Mat, PetscScalar **);
2684: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayRead(Mat, const PetscScalar **);
2685: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArray(Mat, PetscScalar **);
2686: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayWrite(Mat, PetscScalar **);
2687: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayRead(Mat, const PetscScalar **);
2688: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArray(Mat, PetscScalar **);
2689: PETSC_EXTERN PetscErrorCode MatDenseCUDAPlaceArray(Mat, const PetscScalar *);
2690: PETSC_EXTERN PetscErrorCode MatDenseCUDAReplaceArray(Mat, const PetscScalar *);
2691: PETSC_EXTERN PetscErrorCode MatDenseCUDAResetArray(Mat);
2692: PETSC_EXTERN PetscErrorCode MatDenseCUDASetPreallocation(Mat, PetscScalar *);

2694: PETSC_EXTERN PetscErrorCode MatCreateSeqSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2695: PETSC_EXTERN PetscErrorCode MatCreateSELLCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2696: #endif

2698: #ifdef PETSC_HAVE_HIP
2699: /*E
2700:     MatHIPSPARSEStorageFormat - indicates the storage format for `MATAIJHIPSPARSE` (GPU)
2701:     matrices.

2703:     Values:
2704: +   `MAT_HIPSPARSE_CSR` - Compressed Sparse Row
2705: .   `MAT_HIPSPARSE_ELL` - Ellpack
2706: -   `MAT_HIPSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format

2708:     Level: intermediate

2710: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEFormatOperation`
2711: E*/

2713: typedef enum {
2714:   MAT_HIPSPARSE_CSR,
2715:   MAT_HIPSPARSE_ELL,
2716:   MAT_HIPSPARSE_HYB
2717: } MatHIPSPARSEStorageFormat;

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

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

2726:     Values:
2727: +   `MAT_HIPSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2728: .   `MAT_HIPSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2729: .   `MAT_HIPSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2730: -   `MAT_HIPSPARSE_ALL`          - sets the storage format for all HIPSPARSE (GPU) matrices

2732:     Level: intermediate

2734: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEStorageFormat`
2735: E*/
2736: typedef enum {
2737:   MAT_HIPSPARSE_MULT_DIAG,
2738:   MAT_HIPSPARSE_MULT_OFFDIAG,
2739:   MAT_HIPSPARSE_MULT,
2740:   MAT_HIPSPARSE_ALL
2741: } MatHIPSPARSEFormatOperation;

2743: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2744: PETSC_EXTERN PetscErrorCode MatCreateAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2745: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetFormat(Mat, MatHIPSPARSEFormatOperation, MatHIPSPARSEStorageFormat);
2746: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetUseCPUSolve(Mat, PetscBool);
2747: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetIJ(Mat, PetscBool, const int **, const int **);
2748: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreIJ(Mat, PetscBool, const int **, const int **);
2749: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayRead(Mat, const PetscScalar **);
2750: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayRead(Mat, const PetscScalar **);
2751: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayWrite(Mat, PetscScalar **);
2752: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayWrite(Mat, PetscScalar **);
2753: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArray(Mat, PetscScalar **);
2754: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArray(Mat, PetscScalar **);

2756: PETSC_EXTERN PetscErrorCode MatCreateDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2757: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2758: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayWrite(Mat, PetscScalar **);
2759: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayRead(Mat, const PetscScalar **);
2760: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArray(Mat, PetscScalar **);
2761: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayWrite(Mat, PetscScalar **);
2762: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayRead(Mat, const PetscScalar **);
2763: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArray(Mat, PetscScalar **);
2764: PETSC_EXTERN PetscErrorCode MatDenseHIPPlaceArray(Mat, const PetscScalar *);
2765: PETSC_EXTERN PetscErrorCode MatDenseHIPReplaceArray(Mat, const PetscScalar *);
2766: PETSC_EXTERN PetscErrorCode MatDenseHIPResetArray(Mat);
2767: PETSC_EXTERN PetscErrorCode MatDenseHIPSetPreallocation(Mat, PetscScalar *);
2768: PETSC_EXTERN PetscErrorCode MatCreateSeqSELLHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2769: PETSC_EXTERN PetscErrorCode MatCreateSELLHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2770: #endif

2772: #if defined(PETSC_HAVE_VIENNACL)
2773: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2774: PETSC_EXTERN PetscErrorCode MatCreateAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2775: #endif

2777: #if PetscDefined(HAVE_KOKKOS)
2778: PETSC_EXTERN PetscErrorCode MatCreateAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2779: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2780: #endif

2782: #if defined(PETSC_HAVE_FFTW)
2783: PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat, Vec, Vec);
2784: PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat, Vec, Vec);
2785: PETSC_EXTERN PetscErrorCode MatCreateVecsFFTW(Mat, Vec *, Vec *, Vec *);
2786: #endif

2788: #if defined(PETSC_HAVE_SCALAPACK) && (defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL_DOUBLE))
2789: PETSC_EXTERN PetscErrorCode MatCreateScaLAPACK(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2790: PETSC_EXTERN PetscErrorCode MatScaLAPACKSetBlockSizes(Mat, PetscInt, PetscInt);
2791: PETSC_EXTERN PetscErrorCode MatScaLAPACKGetBlockSizes(Mat, PetscInt *, PetscInt *);
2792: #endif

2794: PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm, PetscInt, const IS[], PetscInt, const IS[], const Mat[], Mat *);
2795: PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat, PetscInt *, PetscInt *);
2796: PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat, IS[], IS[]);
2797: PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat, IS[], IS[]);
2798: PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat, PetscInt *, PetscInt *, Mat ***);
2799: PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat, PetscInt, PetscInt, Mat *);
2800: PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat, VecType);
2801: PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat, PetscInt, const IS[], PetscInt, const IS[], const Mat[]);
2802: PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat, PetscInt, PetscInt, Mat);

2804: PETSC_EXTERN PetscErrorCode MatFilter(Mat, PetscReal, PetscBool, PetscBool);
2805: PETSC_DEPRECATED_FUNCTION(3, 20, 0, "MatFilter()", ) static inline PetscErrorCode MatChop(Mat A, PetscReal tol)
2806: {
2807:   return MatFilter(A, tol, PETSC_FALSE, PETSC_FALSE);
2808: }
2809: PETSC_EXTERN PetscErrorCode MatComputeBandwidth(Mat, PetscReal, PetscInt *);

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

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

2815: PETSC_EXTERN PetscErrorCode MatHeaderMerge(Mat, Mat *);
2816: PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat, Mat *);

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

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

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

2826: PETSC_EXTERN PetscErrorCode MatSetHPL(Mat, int);
2827: #define PETSCBMHPL "hpl"

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