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: /*S
 25:    MatState - Snapshot of the state of a `Mat`

 27:    Level: developer

 29:    Note:
 30:    A `MatState` records the object id, state, and nonzero state of a `Mat`.

 32: .seealso: [](ch_matrices), `Mat`, `MatGetState()`, `MatStateCompare()`, `MatStateCompareUpdate()`, `MatStateInvalidate()`, `PetscObjectGetId()`, `PetscObjectStateGet()`
 33: S*/
 34: typedef struct {
 35:   PetscObjectId    id;
 36:   PetscObjectState state;
 37:   PetscObjectState nonzerostate;
 38: } MatState;

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

 43:    Level: beginner

 45:    Notes:
 46:    [](doc_matrix) for a table of available matrix types

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

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

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

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

169:    Level: beginner

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

175: .seealso: [](sec_matfactor), [](ch_matrices), `MatGetFactor()`, `PCFactorSetMatSolverType()`, `PCFactorGetMatSolverType()`
176: J*/
177: typedef const char *MatSolverType;
178: #define MATSOLVERSUPERLU      "superlu"
179: #define MATSOLVERSUPERLU_DIST "superlu_dist"
180: #define MATSOLVERSTRUMPACK    "strumpack"
181: #define MATSOLVERUMFPACK      "umfpack"
182: #define MATSOLVERCHOLMOD      "cholmod"
183: #define MATSOLVERKLU          "klu"
184: #define MATSOLVERELEMENTAL    "elemental"
185: #define MATSOLVERSCALAPACK    "scalapack"
186: #define MATSOLVERESSL         "essl"
187: #define MATSOLVERLUSOL        "lusol"
188: #define MATSOLVERMUMPS        "mumps"
189: #define MATSOLVERMKL_PARDISO  "mkl_pardiso"
190: #define MATSOLVERMKL_CPARDISO "mkl_cpardiso"
191: #define MATSOLVERPASTIX       "pastix"
192: #define MATSOLVERMATLAB       "matlab"
193: #define MATSOLVERPETSC        "petsc"
194: #define MATSOLVERBAS          "bas"
195: #define MATSOLVERCUSPARSE     "cusparse"
196: #define MATSOLVERCUDA         "cuda"
197: #define MATSOLVERHIPSPARSE    "hipsparse"
198: #define MATSOLVERHIP          "hip"
199: #define MATSOLVERKOKKOS       "kokkos"
200: #define MATSOLVERSPQR         "spqr"
201: #define MATSOLVERHTOOL        "htool"
202: #define MATSOLVERCUDSS        "cudss"

204: /*E
205:     MatFactorType - indicates what type of factorization is requested

207:     Values:
208: +  `MAT_FACTOR_LU`       - LU factorization
209: .  `MAT_FACTOR_CHOLESKY` - Cholesky factorization
210: .  `MAT_FACTOR_ILU`      - ILU factorization
211: .  `MAT_FACTOR_ICC`      - incomplete Cholesky factorization
212: .  `MAT_FACTOR_ILUDT`    - ILU factorization with drop tolerance
213: -  `MAT_FACTOR_QR`       - QR factorization

215:     Level: beginner

217: .seealso: [](ch_matrices), `MatSolverType`, `MatGetFactor()`, `MatGetFactorAvailable()`, `MatSolverTypeRegister()`
218: E*/
219: typedef enum {
220:   MAT_FACTOR_NONE,
221:   MAT_FACTOR_LU,
222:   MAT_FACTOR_CHOLESKY,
223:   MAT_FACTOR_ILU,
224:   MAT_FACTOR_ICC,
225:   MAT_FACTOR_ILUDT,
226:   MAT_FACTOR_QR,
227:   MAT_FACTOR_NUM_TYPES
228: } MatFactorType;
229: PETSC_EXTERN const char *const MatFactorTypes[];

231: PETSC_EXTERN PetscErrorCode MatGetFactor(Mat, MatSolverType, MatFactorType, Mat *);
232: PETSC_EXTERN PetscErrorCode MatGetFactorAvailable(Mat, MatSolverType, MatFactorType, PetscBool *);
233: PETSC_EXTERN PetscErrorCode MatFactorGetCanUseOrdering(Mat, PetscBool *);
234: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "MatFactorGetCanUseOrdering()", ) static inline PetscErrorCode MatFactorGetUseOrdering(Mat A, PetscBool *b)
235: {
236:   return MatFactorGetCanUseOrdering(A, b);
237: }
238: PETSC_EXTERN PetscErrorCode MatFactorGetSolverType(Mat, MatSolverType *);
239: PETSC_EXTERN PetscErrorCode MatGetFactorType(Mat, MatFactorType *);
240: PETSC_EXTERN PetscErrorCode MatSetFactorType(Mat, MatFactorType);
241: /*S
242:   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`

244:   Synopsis:
245: #include <petscmat.h>
246:   PetscErrorCode MatSolverFn(Mat A, MatFactorType ftype, Mat *F)

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

253:   Level: developer

255: .seealso: `Mat`, `MatGetFactor()`, `MatSolverType`, `MatFactorType`, `MatSolverTypeRegister()`, `MatSolverTypeGet()`
256: S*/
257: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode MatSolverFn(Mat, MatFactorType, Mat *);
258: PETSC_EXTERN_TYPEDEF typedef MatSolverFn   *MatSolverFunction PETSC_DEPRECATED_TYPEDEF(3, 26, 0, "MatSolverFn*", );

260: PETSC_EXTERN PetscErrorCode MatSolverTypeRegister(MatSolverType, MatType, MatFactorType, MatSolverFn *);
261: PETSC_EXTERN PetscErrorCode MatSolverTypeGet(MatSolverType, MatType, MatFactorType, PetscBool *, PetscBool *, MatSolverFn **);
262: typedef MatSolverType       MatSolverPackage PETSC_DEPRECATED_TYPEDEF(3, 9, 0, "MatSolverType", );
263: PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeRegister()", ) static inline PetscErrorCode MatSolverPackageRegister(MatSolverType stype, MatType mtype, MatFactorType ftype, MatSolverFn *f)
264: {
265:   return MatSolverTypeRegister(stype, mtype, ftype, f);
266: }
267: PETSC_DEPRECATED_FUNCTION(3, 9, 0, "MatSolverTypeGet()", ) static inline PetscErrorCode MatSolverPackageGet(MatSolverType stype, MatType mtype, MatFactorType ftype, PetscBool *foundmtype, PetscBool *foundstype, MatSolverFn **f)
268: {
269:   return MatSolverTypeGet(stype, mtype, ftype, foundmtype, foundstype, f);
270: }

272: /*E
273:     MatProductType - indicates what type of matrix product to compute

275:     Values:
276: +  `MATPRODUCT_AB`   - product of two matrices
277: .  `MATPRODUCT_AtB`  - product of the transpose of a given matrix with a matrix
278: .  `MATPRODUCT_ABt`  - product of a matrix with the transpose of another given matrix
279: .  `MATPRODUCT_PtAP` - the triple product of the transpose of a matrix with another matrix and itself
280: .  `MATPRODUCT_RARt` - the triple product of a matrix, another matrix and the transpose of the first matrix
281: -  `MATPRODUCT_ABC`  - the product of three matrices

283:     Level: beginner

285: .seealso: [](sec_matmatproduct), [](ch_matrices), `MatProductSetType()`
286: E*/
287: typedef enum {
288:   MATPRODUCT_UNSPECIFIED,
289:   MATPRODUCT_AB,
290:   MATPRODUCT_AtB,
291:   MATPRODUCT_ABt,
292:   MATPRODUCT_PtAP,
293:   MATPRODUCT_RARt,
294:   MATPRODUCT_ABC
295: } MatProductType;
296: PETSC_EXTERN const char *const MatProductTypes[];

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

301:    Level: beginner

303: .seealso: [](sec_matmatproduct), [](ch_matrices), `MatSetType()`, `Mat`, `MatProductSetAlgorithm()`, `MatProductType`
304: J*/
305: typedef const char *MatProductAlgorithm;
306: #define MATPRODUCTALGORITHMDEFAULT         "default"
307: #define MATPRODUCTALGORITHMSORTED          "sorted"
308: #define MATPRODUCTALGORITHMSCALABLE        "scalable"
309: #define MATPRODUCTALGORITHMSCALABLEFAST    "scalable_fast"
310: #define MATPRODUCTALGORITHMHEAP            "heap"
311: #define MATPRODUCTALGORITHMBHEAP           "btheap"
312: #define MATPRODUCTALGORITHMLLCONDENSED     "llcondensed"
313: #define MATPRODUCTALGORITHMROWMERGE        "rowmerge"
314: #define MATPRODUCTALGORITHMOUTERPRODUCT    "outerproduct"
315: #define MATPRODUCTALGORITHMATB             "at*b"
316: #define MATPRODUCTALGORITHMRAP             "rap"
317: #define MATPRODUCTALGORITHMNONSCALABLE     "nonscalable"
318: #define MATPRODUCTALGORITHMSEQMPI          "seqmpi"
319: #define MATPRODUCTALGORITHMBACKEND         "backend"
320: #define MATPRODUCTALGORITHMOVERLAPPING     "overlapping"
321: #define MATPRODUCTALGORITHMMERGED          "merged"
322: #define MATPRODUCTALGORITHMALLATONCE       "allatonce"
323: #define MATPRODUCTALGORITHMALLATONCEMERGED "allatonce_merged"
324: #define MATPRODUCTALGORITHMALLGATHERV      "allgatherv"
325: #define MATPRODUCTALGORITHMCYCLIC          "cyclic"
326: #define MATPRODUCTALGORITHMHYPRE           "hypre"

328: PETSC_EXTERN PetscErrorCode MatProductCreate(Mat, Mat, Mat, Mat *);
329: PETSC_EXTERN PetscErrorCode MatProductCreateWithMat(Mat, Mat, Mat, Mat);
330: PETSC_EXTERN PetscErrorCode MatProductSetType(Mat, MatProductType);
331: PETSC_EXTERN PetscErrorCode MatProductSetAlgorithm(Mat, MatProductAlgorithm);
332: PETSC_EXTERN PetscErrorCode MatProductGetAlgorithm(Mat, MatProductAlgorithm *);
333: PETSC_EXTERN PetscErrorCode MatProductSetFill(Mat, PetscReal);
334: PETSC_EXTERN PetscErrorCode MatProductSetFromOptions(Mat);
335: PETSC_EXTERN PetscErrorCode MatProductSymbolic(Mat);
336: PETSC_EXTERN PetscErrorCode MatProductNumeric(Mat);
337: PETSC_EXTERN PetscErrorCode MatProductReplaceMats(Mat, Mat, Mat, Mat);
338: PETSC_EXTERN PetscErrorCode MatProductClear(Mat);
339: PETSC_EXTERN PetscErrorCode MatProductView(Mat, PetscViewer);
340: PETSC_EXTERN PetscErrorCode MatProductGetType(Mat, MatProductType *);
341: PETSC_EXTERN PetscErrorCode MatProductGetMats(Mat, Mat *, Mat *, Mat *);

343: /* Logging support */
344: #define MAT_FILE_CLASSID 1211216 /* used to indicate matrices in binary files */
345: PETSC_EXTERN PetscClassId MAT_CLASSID;
346: PETSC_EXTERN PetscClassId MAT_COLORING_CLASSID;
347: PETSC_EXTERN PetscClassId MAT_FDCOLORING_CLASSID;
348: PETSC_EXTERN PetscClassId MAT_TRANSPOSECOLORING_CLASSID;
349: PETSC_EXTERN PetscClassId MAT_PARTITIONING_CLASSID;
350: PETSC_EXTERN PetscClassId MAT_COARSEN_CLASSID;
351: #define MAT_NULLSPACE_FILE_CLASSID 1211220
352: PETSC_EXTERN PetscClassId MAT_NULLSPACE_CLASSID;
353: PETSC_EXTERN PetscClassId MATMFFD_CLASSID;

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

359:    Values:
360: +  `MAT_INITIAL_MATRIX` - create a new matrix
361: .  `MAT_REUSE_MATRIX`   - reuse the matrix created with a previous call that used `MAT_INITIAL_MATRIX`
362: .  `MAT_INPLACE_MATRIX` - replace the first input matrix with the new matrix (not applicable to all functions)
363: -  `MAT_IGNORE_MATRIX`  - do not create a new matrix or reuse a given matrix, just ignore that matrix argument (not applicable to all functions)

365:     Level: beginner

367: .seealso: [](ch_matrices), `Mat`, `MatCreateSubMatrices()`, `MatCreateSubMatrix()`, `MatDestroyMatrices()`, `MatConvert()`
368: E*/
369: typedef enum {
370:   MAT_INITIAL_MATRIX,
371:   MAT_REUSE_MATRIX,
372:   MAT_IGNORE_MATRIX,
373:   MAT_INPLACE_MATRIX
374: } MatReuse;

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

380:     Values:
381: +  `MAT_DO_NOT_GET_VALUES` - do not copy the matrix values
382: -  `MAT_GET_VALUES`        - copy the matrix values

384:     Level: developer

386:     Developer Note:
387:     Why is not just a boolean used for this information?

389: .seealso: [](ch_matrices), `Mat`, `MatDuplicateOption`, `PetscCopyMode`, `MatGetSeqNonzeroStructure()`
390: E*/
391: typedef enum {
392:   MAT_DO_NOT_GET_VALUES,
393:   MAT_GET_VALUES
394: } MatCreateSubMatrixOption;

396: PETSC_EXTERN PetscErrorCode MatInitializePackage(void);
397: PETSC_EXTERN PetscErrorCode MatFinalizePackage(void);

399: PETSC_EXTERN PetscErrorCode MatCreate(MPI_Comm, Mat *);
400: PETSC_EXTERN PetscErrorCode MatCreateFromOptions(MPI_Comm, const char *, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
401: PETSC_EXTERN PetscErrorCode MatSetSizes(Mat, PetscInt, PetscInt, PetscInt, PetscInt);
402: PETSC_EXTERN PetscErrorCode MatSetType(Mat, MatType);
403: PETSC_EXTERN PetscErrorCode MatGetVecType(Mat, VecType *);
404: PETSC_EXTERN PetscErrorCode MatSetVecType(Mat, VecType);
405: PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat);
406: PETSC_EXTERN PetscErrorCode MatViewFromOptions(Mat, PetscObject, const char[]);
407: PETSC_EXTERN PetscErrorCode MatRegister(const char[], PetscErrorCode (*)(Mat));
408: PETSC_EXTERN PetscErrorCode MatRegisterRootName(const char[], const char[], const char[]);
409: PETSC_EXTERN PetscErrorCode MatSetOptionsPrefix(Mat, const char[]);
410: PETSC_EXTERN PetscErrorCode MatSetOptionsPrefixFactor(Mat, const char[]);
411: PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefixFactor(Mat, const char[]);
412: PETSC_EXTERN PetscErrorCode MatAppendOptionsPrefix(Mat, const char[]);
413: PETSC_EXTERN PetscErrorCode MatGetOptionsPrefix(Mat, const char *[]);
414: PETSC_EXTERN PetscErrorCode MatGetState(Mat, MatState *);
415: PETSC_EXTERN PetscErrorCode MatStateCompare(MatState, MatState, PetscBool *);
416: PETSC_EXTERN PetscErrorCode MatStateCompareUpdate(Mat, MatState *, PetscBool *);
417: /*MC
418:   MatStateInvalidate - Invalidates a matrix state snapshot

420:   Synopsis:
421: #include <petscmat.h>
422:   PetscErrorCode MatStateInvalidate(MatState state)

424:   Not Collective

426:   Input/Output Parameter:
427: . state - the matrix state

429:   Level: developer

431: .seealso: [](ch_matrices), `Mat`, `MatState`, `MatGetState()`, `MatStateCompare()`, `MatStateCompareUpdate()`
432: M*/
433: #define MatStateInvalidate(s) ((s).id = 0, (s).state = -1, (s).nonzerostate = -1, PETSC_SUCCESS)
434: PETSC_EXTERN PetscErrorCode MatSetErrorIfFailure(Mat, PetscBool);

436: PETSC_EXTERN PetscFunctionList MatList;
437: PETSC_EXTERN PetscFunctionList MatColoringList;
438: PETSC_EXTERN PetscFunctionList MatPartitioningList;
439: PETSC_EXTERN PetscFunctionList MatMeshToCellGraphList;

441: /*E
442:    MatStructure - Indicates if two matrices have the same nonzero structure

444:    Values:
445: +  `SAME_NONZERO_PATTERN`      - the two matrices have identical nonzero patterns
446: .  `DIFFERENT_NONZERO_PATTERN` - the two matrices may have different nonzero patterns
447: .  `SUBSET_NONZERO_PATTERN`    - the nonzero pattern of the second matrix is a subset of the nonzero pattern of the first matrix
448: -  `UNKNOWN_NONZERO_PATTERN`   - there is no known relationship between the nonzero patterns. In this case the implementations
449:                                  may try to detect a relationship to optimize the operation

451:    Level: beginner

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

458: .seealso: [](ch_matrices), `Mat`, `MatCopy()`, `MatAXPY()`, `MatAYPX()`
459: E*/
460: typedef enum {
461:   DIFFERENT_NONZERO_PATTERN,
462:   SUBSET_NONZERO_PATTERN,
463:   SAME_NONZERO_PATTERN,
464:   UNKNOWN_NONZERO_PATTERN
465: } MatStructure;
466: PETSC_EXTERN const char *const MatStructures[];

468: #if PetscDefined(HAVE_MKL_SPARSE)
469: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
470: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
471: PETSC_EXTERN PetscErrorCode MatCreateBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
472: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJMKL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
473: #endif

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

478: PETSC_EXTERN PetscErrorCode MatCreateSeqSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
479: PETSC_EXTERN PetscErrorCode MatCreateSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
480: PETSC_EXTERN PetscErrorCode MatSeqSELLSetPreallocation(Mat, PetscInt, const PetscInt[]);
481: PETSC_EXTERN PetscErrorCode MatMPISELLSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
482: PETSC_EXTERN PetscErrorCode MatSeqSELLGetFillRatio(Mat, PetscReal *);
483: PETSC_EXTERN PetscErrorCode MatSeqSELLGetMaxSliceWidth(Mat, PetscInt *);
484: PETSC_EXTERN PetscErrorCode MatSeqSELLGetAvgSliceWidth(Mat, PetscReal *);
485: PETSC_EXTERN PetscErrorCode MatSeqSELLSetSliceHeight(Mat, PetscInt);
486: PETSC_EXTERN PetscErrorCode MatSeqSELLGetVarSliceSize(Mat, PetscReal *);

488: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
489: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSELL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
490: PETSC_EXTERN PetscErrorCode MatMPISELLGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *);
491: PETSC_EXTERN PetscErrorCode MatMPISELLGetSeqSELL(Mat, Mat *, Mat *, const PetscInt *[]);

493: PETSC_EXTERN PetscErrorCode MatCreateSeqDense(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
494: PETSC_EXTERN PetscErrorCode MatCreateDense(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
495: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
496: PETSC_EXTERN PetscErrorCode MatCreateAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
497: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);
498: PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArrays(Mat, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
499: PETSC_EXTERN PetscErrorCode MatUpdateMPIAIJWithArray(Mat, const PetscScalar[]);
500: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSplitArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], PetscInt[], PetscInt[], PetscScalar[], Mat *);
501: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJWithSeqAIJ(MPI_Comm, PetscInt, PetscInt, Mat, Mat, PetscInt *, Mat *);

503: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
504: PETSC_EXTERN PetscErrorCode MatCreateBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
505: PETSC_EXTERN PetscErrorCode MatCreateMPIBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);

507: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOO(Mat, PetscCount, PetscInt[], PetscInt[]);
508: PETSC_EXTERN PetscErrorCode MatSetPreallocationCOOLocal(Mat, PetscCount, PetscInt[], PetscInt[]);
509: PETSC_EXTERN PetscErrorCode MatSetValuesCOO(Mat, const PetscScalar[], InsertMode);

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

514: PETSC_EXTERN PetscErrorCode MatCreateSBAIJ(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
515: PETSC_EXTERN PetscErrorCode MatCreateMPISBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], Mat *);
516: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
517: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
518: PETSC_EXTERN PetscErrorCode MatXAIJSetPreallocation(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscInt[], const PetscInt[]);

520: PETSC_EXTERN PetscErrorCode MatCreateShell(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscCtx, Mat *);
521: PETSC_EXTERN PetscErrorCode MatCreateCentering(MPI_Comm, PetscInt, PetscInt, Mat *);
522: PETSC_EXTERN PetscErrorCode MatCreateNormal(Mat, Mat *);
523: PETSC_EXTERN PetscErrorCode MatCreateNormalHermitian(Mat, Mat *);
524: PETSC_EXTERN PetscErrorCode MatCreateLRC(Mat, Mat, Vec, Mat, Mat *);
525: PETSC_EXTERN PetscErrorCode MatLRCGetMats(Mat, Mat *, Mat *, Vec *, Mat *);
526: PETSC_EXTERN PetscErrorCode MatLRCSetMats(Mat, Mat, Mat, Vec, Mat);
527: PETSC_EXTERN PetscErrorCode MatCreateIS(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, ISLocalToGlobalMapping, ISLocalToGlobalMapping, Mat *);
528: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
529: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJCRL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);

531: PETSC_EXTERN PetscErrorCode MatCreateScatter(MPI_Comm, VecScatter, Mat *);
532: PETSC_EXTERN PetscErrorCode MatScatterSetVecScatter(Mat, VecScatter);
533: PETSC_EXTERN PetscErrorCode MatScatterGetVecScatter(Mat, VecScatter *);
534: PETSC_EXTERN PetscErrorCode MatCreateBlockMat(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt *, Mat *);
535: PETSC_EXTERN PetscErrorCode MatCompositeAddMat(Mat, Mat);
536: PETSC_EXTERN PetscErrorCode MatCompositeMerge(Mat);
537: /*E
538:    MatCompositeMergeType - Selects the order in which the matrices held by a `MATCOMPOSITE` are combined when `MatCompositeMerge()` is called

540:    Values:
541: +   `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)
542: -   `MAT_COMPOSITE_MERGE_LEFT`  - merge into a single matrix starting from the leftmost matrix

544:    Level: advanced

546: .seealso: [](ch_matrices), `Mat`, `MATCOMPOSITE`, `MatCompositeMerge()`, `MatCompositeSetMergeType()`, `MatCompositeType`
547: E*/
548: typedef enum {
549:   MAT_COMPOSITE_MERGE_RIGHT,
550:   MAT_COMPOSITE_MERGE_LEFT
551: } MatCompositeMergeType;
552: PETSC_EXTERN PetscErrorCode MatCompositeSetMergeType(Mat, MatCompositeMergeType);
553: PETSC_EXTERN PetscErrorCode MatCreateComposite(MPI_Comm, PetscInt, const Mat *, Mat *);
554: /*E
555:     MatCompositeType - indicates what type of `MATCOMPOSITE` is used

557:     Values:
558: +  `MAT_COMPOSITE_ADDITIVE`       - sum of matrices (default)
559: -  `MAT_COMPOSITE_MULTIPLICATIVE` - product of matrices

561:     Level: beginner

563: .seealso: [](ch_matrices), `MATCOMPOSITE`, `MatCompositeSetType()`, `MatCompositeGetType()`
564: E*/
565: typedef enum {
566:   MAT_COMPOSITE_ADDITIVE,
567:   MAT_COMPOSITE_MULTIPLICATIVE
568: } MatCompositeType;
569: PETSC_EXTERN PetscErrorCode MatCompositeSetType(Mat, MatCompositeType);
570: PETSC_EXTERN PetscErrorCode MatCompositeGetType(Mat, MatCompositeType *);
571: PETSC_EXTERN PetscErrorCode MatCompositeSetMatStructure(Mat, MatStructure);
572: PETSC_EXTERN PetscErrorCode MatCompositeGetMatStructure(Mat, MatStructure *);
573: PETSC_EXTERN PetscErrorCode MatCompositeGetNumberMat(Mat, PetscInt *);
574: PETSC_EXTERN PetscErrorCode MatCompositeGetMat(Mat, PetscInt, Mat *);
575: PETSC_EXTERN PetscErrorCode MatCompositeSetScalings(Mat, const PetscScalar *);

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

580: PETSC_EXTERN PetscErrorCode MatCreateTranspose(Mat, Mat *);
581: PETSC_EXTERN PetscErrorCode MatTransposeGetMat(Mat, Mat *);
582: PETSC_EXTERN PetscErrorCode MatCreateHermitianTranspose(Mat, Mat *);
583: PETSC_EXTERN PetscErrorCode MatHermitianTransposeGetMat(Mat, Mat *);
584: PETSC_EXTERN PetscErrorCode MatNormalGetMat(Mat, Mat *);
585: PETSC_EXTERN PetscErrorCode MatNormalHermitianGetMat(Mat, Mat *);
586: PETSC_EXTERN PetscErrorCode MatCreateSubMatrixVirtual(Mat, IS, IS, Mat *);
587: PETSC_EXTERN PetscErrorCode MatSubMatrixVirtualUpdate(Mat, Mat, IS, IS);
588: PETSC_EXTERN PetscErrorCode MatCreateLocalRef(Mat, IS, IS, Mat *);
589: PETSC_EXTERN PetscErrorCode MatCreateConstantDiagonal(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar, Mat *);
590: PETSC_EXTERN PetscErrorCode MatCreateDiagonal(Vec, Mat *);
591: PETSC_EXTERN PetscErrorCode MatDiagonalSetDiagonal(Mat, Vec);
592: PETSC_EXTERN PetscErrorCode MatDiagonalGetDiagonal(Mat, Vec *);
593: PETSC_EXTERN PetscErrorCode MatDiagonalRestoreDiagonal(Mat, Vec *);
594: PETSC_EXTERN PetscErrorCode MatDiagonalGetInverseDiagonal(Mat, Vec *);
595: PETSC_EXTERN PetscErrorCode MatDiagonalRestoreInverseDiagonal(Mat, Vec *);
596: PETSC_EXTERN PetscErrorCode MatConstantDiagonalGetConstant(Mat, PetscScalar *);
597: PETSC_EXTERN PetscErrorCode MatGetCurrentMemType(Mat, PetscMemType *);

599: #if PetscDefined(HAVE_HYPRE)
600: PETSC_EXTERN PetscErrorCode MatHYPRESetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
601: #endif

603: PETSC_EXTERN PetscErrorCode MatPythonSetType(Mat, const char[]);
604: PETSC_EXTERN PetscErrorCode MatPythonGetType(Mat, const char *[]);
605: PETSC_EXTERN PetscErrorCode MatPythonCreate(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const char[], Mat *);

607: PETSC_EXTERN PetscErrorCode MatResetPreallocation(Mat);
608: PETSC_EXTERN PetscErrorCode MatResetHash(Mat);
609: PETSC_EXTERN PetscErrorCode MatSetUp(Mat);
610: PETSC_EXTERN PetscErrorCode MatDestroy(Mat *);
611: PETSC_EXTERN PetscErrorCode MatGetNonzeroState(Mat, PetscObjectState *);

613: PETSC_EXTERN PetscErrorCode MatConjugate(Mat);
614: PETSC_EXTERN PetscErrorCode MatRealPart(Mat);
615: PETSC_EXTERN PetscErrorCode MatImaginaryPart(Mat);
616: PETSC_EXTERN PetscErrorCode MatGetDiagonalBlock(Mat, Mat *);
617: PETSC_EXTERN PetscErrorCode MatGetMultPetscSF(Mat, PetscSF *);
618: PETSC_EXTERN PetscErrorCode MatGetTrace(Mat, PetscScalar *);
619: PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonal(Mat, const PetscScalar **);
620: PETSC_EXTERN PetscErrorCode MatInvertVariableBlockDiagonal(Mat, PetscInt, const PetscInt *, PetscScalar *);
621: PETSC_EXTERN PetscErrorCode MatInvertBlockDiagonalMat(Mat, Mat);
622: PETSC_EXTERN PetscErrorCode MatInvertVariableBlockEnvelope(Mat, MatReuse, Mat *);
623: PETSC_EXTERN PetscErrorCode MatComputeVariableBlockEnvelope(Mat);

625: PETSC_EXTERN PetscErrorCode MatSetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
626: PETSC_EXTERN PetscErrorCode MatSetValuesIS(Mat, IS, IS, const PetscScalar[], InsertMode);
627: PETSC_EXTERN PetscErrorCode MatSetValuesBlocked(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
628: PETSC_EXTERN PetscErrorCode MatSetValuesRow(Mat, PetscInt, const PetscScalar[]);
629: PETSC_EXTERN PetscErrorCode MatSetValuesRowLocal(Mat, PetscInt, const PetscScalar[]);
630: PETSC_EXTERN PetscErrorCode MatSetValuesBatch(Mat, PetscInt, PetscInt, PetscInt[], const PetscScalar[]);
631: PETSC_EXTERN PetscErrorCode MatSetRandom(Mat, PetscRandom);

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

637:    Level: beginner

639:    Notes:
640:    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).
641:    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.

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

645:    For staggered grids, see `DMStagStencil`

647: .seealso: [](ch_matrices), `Mat`, `MatSetValuesStencil()`, `MatSetStencil()`, `MatSetValuesBlockedStencil()`, `DMDAVecGetArray()`,
648:           `DMStagStencil`
649: S*/
650: typedef struct {
651:   PetscInt k, j, i, c;
652: } MatStencil;

654: PETSC_EXTERN PetscErrorCode MatSetValuesStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
655: PETSC_EXTERN PetscErrorCode MatSetValuesBlockedStencil(Mat, PetscInt, const MatStencil[], PetscInt, const MatStencil[], const PetscScalar[], InsertMode);
656: PETSC_EXTERN PetscErrorCode MatSetStencil(Mat, PetscInt, const PetscInt[], const PetscInt[], PetscInt);

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

661:     Values:
662: +   `MAT_FLUSH_ASSEMBLY` - you will continue to put values into the matrix
663: -   `MAT_FINAL_ASSEMBLY` - you wish to use the matrix with the values currently inserted

665:     Level: beginner

667: .seealso: [](ch_matrices), `Mat`, `MatSetValues`, `MatAssemblyBegin()`, `MatAssemblyEnd()`
668: E*/
669: typedef enum {
670:   MAT_FLUSH_ASSEMBLY = 1,
671:   MAT_FINAL_ASSEMBLY = 0
672: } MatAssemblyType;

674: PETSC_EXTERN PetscErrorCode MatAssemblyBegin(Mat, MatAssemblyType);
675: PETSC_EXTERN PetscErrorCode MatAssemblyEnd(Mat, MatAssemblyType);
676: PETSC_EXTERN PetscErrorCode MatAssembled(Mat, PetscBool *);

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

681:    Level: beginner

683:    Note:
684:    See `MatSetOption()` for the use of the options

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

689: .seealso: [](ch_matrices), `Mat`, `MatSetOption()`, `VecOption`
690: E*/
691: typedef enum {
692:   MAT_OPTION_MIN                  = -3,
693:   MAT_UNUSED_NONZERO_LOCATION_ERR = -2,
694:   MAT_ROW_ORIENTED                = -1,
695:   MAT_SYMMETRIC                   = 1,
696:   MAT_STRUCTURALLY_SYMMETRIC      = 2,
697:   MAT_FORCE_DIAGONAL_ENTRIES      = 3,
698:   MAT_IGNORE_OFF_PROC_ENTRIES     = 4,
699:   MAT_USE_HASH_TABLE              = 5,
700:   MAT_KEEP_NONZERO_PATTERN        = 6,
701:   MAT_IGNORE_ZERO_ENTRIES         = 7,
702:   MAT_USE_INODES                  = 8,
703:   MAT_HERMITIAN                   = 9,
704:   MAT_SYMMETRY_ETERNAL            = 10,
705:   MAT_NEW_NONZERO_LOCATION_ERR    = 11,
706:   MAT_IGNORE_LOWER_TRIANGULAR     = 12,
707:   MAT_ERROR_LOWER_TRIANGULAR      = 13,
708:   MAT_GETROW_UPPERTRIANGULAR      = 14,
709:   MAT_SPD                         = 15,
710:   MAT_NO_OFF_PROC_ZERO_ROWS       = 16,
711:   MAT_NO_OFF_PROC_ENTRIES         = 17,
712:   MAT_NEW_NONZERO_LOCATIONS       = 18,
713:   MAT_NEW_NONZERO_ALLOCATION_ERR  = 19,
714:   MAT_SUBSET_OFF_PROC_ENTRIES     = 20,
715:   MAT_SUBMAT_SINGLEIS             = 21,
716:   MAT_STRUCTURE_ONLY              = 22,
717:   MAT_SORTED_FULL                 = 23,
718:   MAT_FORM_EXPLICIT_TRANSPOSE     = 24,
719:   MAT_STRUCTURAL_SYMMETRY_ETERNAL = 25,
720:   MAT_SPD_ETERNAL                 = 26,
721:   MAT_OPTION_MAX                  = 27
722: } MatOption;

724: PETSC_EXTERN const char *const *MatOptions;
725: PETSC_EXTERN PetscErrorCode     MatSetOption(Mat, MatOption, PetscBool);
726: PETSC_EXTERN PetscErrorCode     MatGetOption(Mat, MatOption, PetscBool *);
727: PETSC_EXTERN PetscErrorCode     MatPropagateSymmetryOptions(Mat, Mat);
728: PETSC_EXTERN PetscErrorCode     MatGetType(Mat, MatType *);

730: PETSC_EXTERN PetscErrorCode    MatGetValues(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]);
731: PETSC_EXTERN PetscErrorCode    MatGetRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]);
732: PETSC_EXTERN PetscErrorCode    MatRestoreRow(Mat, PetscInt, PetscInt *, const PetscInt *[], const PetscScalar *[]);
733: PETSC_EXTERN PetscErrorCode    MatGetRowUpperTriangular(Mat);
734: PETSC_EXTERN PetscErrorCode    MatRestoreRowUpperTriangular(Mat);
735: PETSC_EXTERN PetscErrorCode    MatGetColumnVector(Mat, Vec, PetscInt);
736: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArray(Mat, PetscScalar *[]);
737: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArrayRead(Mat, const PetscScalar *[]);
738: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetArrayWrite(Mat, PetscScalar *[]);
739: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArray(Mat, PetscScalar *[]);
740: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArrayRead(Mat, const PetscScalar *[]);
741: PETSC_EXTERN PetscErrorCode    MatSeqAIJRestoreArrayWrite(Mat, PetscScalar *[]);
742: PETSC_EXTERN PetscErrorCode    MatSeqAIJGetMaxRowNonzeros(Mat, PetscInt *);
743: PETSC_EXTERN PetscErrorCode    MatSeqAIJSetValuesLocalFast(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
744: PETSC_EXTERN PetscErrorCode    MatSeqAIJSetType(Mat, MatType);
745: PETSC_EXTERN PetscErrorCode    MatSeqAIJKron(Mat, Mat, MatReuse, Mat *);
746: PETSC_EXTERN PetscErrorCode    MatSeqAIJRegister(const char[], PetscErrorCode (*)(Mat, MatType, MatReuse, Mat *));
747: PETSC_EXTERN PetscFunctionList MatSeqAIJList;
748: PETSC_EXTERN PetscErrorCode    MatSeqBAIJGetArray(Mat, PetscScalar *[]);
749: PETSC_EXTERN PetscErrorCode    MatSeqBAIJRestoreArray(Mat, PetscScalar *[]);
750: PETSC_EXTERN PetscErrorCode    MatSeqSBAIJGetArray(Mat, PetscScalar *[]);
751: PETSC_EXTERN PetscErrorCode    MatSeqSBAIJRestoreArray(Mat, PetscScalar *[]);
752: PETSC_EXTERN PetscErrorCode    MatDenseGetArray(Mat, PetscScalar *[]);
753: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArray(Mat, PetscScalar *[]);
754: PETSC_EXTERN PetscErrorCode    MatDensePlaceArray(Mat, const PetscScalar[]);
755: PETSC_EXTERN PetscErrorCode    MatDensePlaceArrayWithMemType(Mat, PetscMemType, const PetscScalar[]);
756: PETSC_EXTERN PetscErrorCode    MatDenseReplaceArray(Mat, const PetscScalar[]);
757: PETSC_EXTERN PetscErrorCode    MatDenseReplaceArrayWithMemType(Mat, PetscMemType, const PetscScalar[]);
758: PETSC_EXTERN PetscErrorCode    MatDenseResetArray(Mat);
759: PETSC_EXTERN PetscErrorCode    MatDenseResetArrayWithMemType(Mat, PetscMemType);
760: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayRead(Mat, const PetscScalar *[]);
761: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayRead(Mat, const PetscScalar *[]);
762: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayWrite(Mat, PetscScalar *[]);
763: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayWrite(Mat, PetscScalar *[]);
764: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayAndMemType(Mat, PetscScalar *[], PetscMemType *);
765: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayAndMemType(Mat, PetscScalar *[]);
766: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayReadAndMemType(Mat, const PetscScalar *[], PetscMemType *);
767: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayReadAndMemType(Mat, const PetscScalar *[]);
768: PETSC_EXTERN PetscErrorCode    MatDenseGetArrayWriteAndMemType(Mat, PetscScalar *[], PetscMemType *);
769: PETSC_EXTERN PetscErrorCode    MatDenseRestoreArrayWriteAndMemType(Mat, PetscScalar *[]);
770: PETSC_EXTERN PetscErrorCode    MatGetBlockSize(Mat, PetscInt *);
771: PETSC_EXTERN PetscErrorCode    MatSetBlockSize(Mat, PetscInt);
772: PETSC_EXTERN PetscErrorCode    MatGetBlockSizes(Mat, PetscInt *, PetscInt *);
773: PETSC_EXTERN PetscErrorCode    MatSetBlockSizes(Mat, PetscInt, PetscInt);
774: PETSC_EXTERN PetscErrorCode    MatSetBlockSizesFromMats(Mat, Mat, Mat);
775: PETSC_EXTERN PetscErrorCode    MatSetVariableBlockSizes(Mat, PetscInt, const PetscInt[]);
776: PETSC_EXTERN PetscErrorCode    MatGetVariableBlockSizes(Mat, PetscInt *, const PetscInt *[]);
777: PETSC_EXTERN PetscErrorCode    MatSelectVariableBlockSizes(Mat, Mat, IS);

779: PETSC_EXTERN PetscErrorCode MatDenseGetColumn(Mat, PetscInt, PetscScalar *[]);
780: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumn(Mat, PetscScalar *[]);
781: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVec(Mat, PetscInt, Vec *);
782: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVec(Mat, PetscInt, Vec *);
783: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecRead(Mat, PetscInt, Vec *);
784: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecRead(Mat, PetscInt, Vec *);
785: PETSC_EXTERN PetscErrorCode MatDenseGetColumnVecWrite(Mat, PetscInt, Vec *);
786: PETSC_EXTERN PetscErrorCode MatDenseRestoreColumnVecWrite(Mat, PetscInt, Vec *);
787: PETSC_EXTERN PetscErrorCode MatDenseGetSubMatrix(Mat, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
788: PETSC_EXTERN PetscErrorCode MatDenseRestoreSubMatrix(Mat, Mat *);
789: PETSC_EXTERN PetscErrorCode MatDenseUpdateColumnLayout(Mat, PetscLayout);

791: PETSC_EXTERN PetscErrorCode MatMult(Mat, Vec, Vec);
792: PETSC_EXTERN PetscErrorCode MatMultDiagonalBlock(Mat, Vec, Vec);
793: PETSC_EXTERN PetscErrorCode MatMultAdd(Mat, Vec, Vec, Vec);
794: PETSC_EXTERN PetscErrorCode MatMultTranspose(Mat, Vec, Vec);
795: PETSC_EXTERN PetscErrorCode MatMultHermitianTranspose(Mat, Vec, Vec);
796: PETSC_EXTERN PetscErrorCode MatADot(Mat, Vec, Vec, PetscScalar *);
797: PETSC_EXTERN PetscErrorCode MatANorm(Mat, Vec, PetscReal *);
798: PETSC_EXTERN PetscErrorCode MatIsTranspose(Mat, Mat, PetscReal, PetscBool *);
799: PETSC_EXTERN PetscErrorCode MatIsHermitianTranspose(Mat, Mat, PetscReal, PetscBool *);
800: PETSC_EXTERN PetscErrorCode MatMultTransposeAdd(Mat, Vec, Vec, Vec);
801: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAdd(Mat, Vec, Vec, Vec);
802: PETSC_EXTERN PetscErrorCode MatMatSolve(Mat, Mat, Mat);
803: PETSC_EXTERN PetscErrorCode MatMatSolveTranspose(Mat, Mat, Mat);
804: PETSC_EXTERN PetscErrorCode MatMatTransposeSolve(Mat, Mat, Mat);
805: PETSC_EXTERN PetscErrorCode MatResidual(Mat, Vec, Vec, Vec);

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

811:   Values:
812: + `MAT_DO_NOT_COPY_VALUES`    - Create a matrix using the same nonzero pattern as the original matrix,
813:                                 with zeros for the numerical values
814: . `MAT_COPY_VALUES`           - Create a matrix with the same nonzero pattern as the original matrix
815:                                 and with the same numerical values.
816: - `MAT_SHARE_NONZERO_PATTERN` - Create a matrix that shares the nonzero structure with the previous matrix
817:                                 and does not copy it, using zeros for the numerical values. The parent and
818:                                 child matrices will share their index (i and j) arrays, and you cannot
819:                                 insert new nonzero entries into either matrix

821:   Level: beginner

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

827: .seealso: [](ch_matrices), `Mat`, `MatDuplicate()`
828: E*/
829: typedef enum {
830:   MAT_DO_NOT_COPY_VALUES,
831:   MAT_COPY_VALUES,
832:   MAT_SHARE_NONZERO_PATTERN
833: } MatDuplicateOption;

835: PETSC_EXTERN PetscErrorCode MatConvert(Mat, MatType, MatReuse, Mat *);
836: PETSC_EXTERN PetscErrorCode MatDuplicate(Mat, MatDuplicateOption, Mat *);

838: PETSC_EXTERN PetscErrorCode MatCopy(Mat, Mat, MatStructure);
839: PETSC_EXTERN PetscErrorCode MatView(Mat, PetscViewer);
840: PETSC_EXTERN PetscErrorCode MatIsSymmetric(Mat, PetscReal, PetscBool *);
841: PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetric(Mat, PetscBool *);
842: PETSC_EXTERN PetscErrorCode MatIsHermitian(Mat, PetscReal, PetscBool *);
843: PETSC_EXTERN PetscErrorCode MatIsSymmetricKnown(Mat, PetscBool *, PetscBool *);
844: PETSC_EXTERN PetscErrorCode MatIsHermitianKnown(Mat, PetscBool *, PetscBool *);
845: PETSC_EXTERN PetscErrorCode MatIsStructurallySymmetricKnown(Mat, PetscBool *, PetscBool *);
846: PETSC_EXTERN PetscErrorCode MatIsSPDKnown(Mat, PetscBool *, PetscBool *);
847: PETSC_EXTERN PetscErrorCode MatLoad(Mat, PetscViewer);

849: PETSC_EXTERN PetscErrorCode MatGetRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
850: PETSC_EXTERN PetscErrorCode MatRestoreRowIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
851: PETSC_EXTERN PetscErrorCode MatGetColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);
852: PETSC_EXTERN PetscErrorCode MatRestoreColumnIJ(Mat, PetscInt, PetscBool, PetscBool, PetscInt *, const PetscInt *[], const PetscInt *[], PetscBool *);

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

857:    Level: intermediate

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

862: .seealso: [](ch_matrices), `Mat`, `MatGetInfo()`, `MatInfoType`
863: S*/
864: typedef struct {
865:   PetscLogDouble block_size;                          /* block size */
866:   PetscLogDouble nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
867:   PetscLogDouble memory;                              /* memory allocated */
868:   PetscLogDouble assemblies;                          /* number of matrix assemblies called */
869:   PetscLogDouble mallocs;                             /* number of mallocs during MatSetValues() */
870:   PetscLogDouble fill_ratio_given, fill_ratio_needed; /* fill ratio for LU/ILU */
871:   PetscLogDouble factor_mallocs;                      /* number of mallocs during factorization */
872: } MatInfo;

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

878:     Values:
879: +   `MAT_LOCAL`      - values for each MPI process part of the matrix
880: .   `MAT_GLOBAL_MAX` - maximum of each value over all MPI processes
881: -   `MAT_GLOBAL_SUM` - sum of each value over all MPI processes

883:     Level: beginner

885: .seealso: [](ch_matrices), `MatGetInfo()`, `MatInfo`
886: E*/
887: typedef enum {
888:   MAT_LOCAL      = 1,
889:   MAT_GLOBAL_MAX = 2,
890:   MAT_GLOBAL_SUM = 3
891: } MatInfoType;
892: PETSC_EXTERN PetscErrorCode MatGetInfo(Mat, MatInfoType, MatInfo *);
893: PETSC_EXTERN PetscErrorCode MatGetDiagonal(Mat, Vec);
894: PETSC_EXTERN PetscErrorCode MatGetRowMax(Mat, Vec, PetscInt[]);
895: PETSC_EXTERN PetscErrorCode MatGetRowMin(Mat, Vec, PetscInt[]);
896: PETSC_EXTERN PetscErrorCode MatGetRowMaxAbs(Mat, Vec, PetscInt[]);
897: PETSC_EXTERN PetscErrorCode MatGetRowSumAbs(Mat, Vec);
898: PETSC_EXTERN PetscErrorCode MatGetRowMinAbs(Mat, Vec, PetscInt[]);
899: PETSC_EXTERN PetscErrorCode MatGetRowSum(Mat, Vec);
900: PETSC_EXTERN PetscErrorCode MatTranspose(Mat, MatReuse, Mat *);
901: PETSC_EXTERN PetscErrorCode MatTransposeSymbolic(Mat, Mat *);
902: PETSC_EXTERN PetscErrorCode MatTransposeSetPrecursor(Mat, Mat);
903: PETSC_EXTERN PetscErrorCode MatHermitianTranspose(Mat, MatReuse, Mat *);
904: PETSC_EXTERN PetscErrorCode MatPermute(Mat, IS, IS, Mat *);
905: PETSC_EXTERN PetscErrorCode MatDiagonalScale(Mat, Vec, Vec);
906: PETSC_EXTERN PetscErrorCode MatDiagonalSet(Mat, Vec, InsertMode);

908: PETSC_EXTERN PetscErrorCode MatEqual(Mat, Mat, PetscBool *);
909: PETSC_EXTERN PetscErrorCode MatMultEqual(Mat, Mat, PetscInt, PetscBool *);
910: PETSC_EXTERN PetscErrorCode MatMultAddEqual(Mat, Mat, PetscInt, PetscBool *);
911: PETSC_EXTERN PetscErrorCode MatMultTransposeEqual(Mat, Mat, PetscInt, PetscBool *);
912: PETSC_EXTERN PetscErrorCode MatMultTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *);
913: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeEqual(Mat, Mat, PetscInt, PetscBool *);
914: PETSC_EXTERN PetscErrorCode MatMultHermitianTransposeAddEqual(Mat, Mat, PetscInt, PetscBool *);
915: PETSC_EXTERN PetscErrorCode MatMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
916: PETSC_EXTERN PetscErrorCode MatTransposeMatMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
917: PETSC_EXTERN PetscErrorCode MatMatTransposeMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
918: PETSC_EXTERN PetscErrorCode MatPtAPMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
919: PETSC_EXTERN PetscErrorCode MatRARtMultEqual(Mat, Mat, Mat, PetscInt, PetscBool *);
920: PETSC_EXTERN PetscErrorCode MatIsLinear(Mat, PetscInt, PetscBool *);

922: PETSC_EXTERN PetscErrorCode MatNorm(Mat, NormType, PetscReal *);
923: PETSC_EXTERN PetscErrorCode MatNormApproximate(Mat, NormType, PetscInt, PetscReal *);
924: PETSC_EXTERN PetscErrorCode MatGetColumnNorms(Mat, NormType, PetscReal *);
925: PETSC_EXTERN PetscErrorCode MatGetColumnSums(Mat, PetscScalar *);
926: PETSC_EXTERN PetscErrorCode MatGetColumnSumsRealPart(Mat, PetscReal *);
927: PETSC_EXTERN PetscErrorCode MatGetColumnSumsImaginaryPart(Mat, PetscReal *);
928: PETSC_EXTERN PetscErrorCode MatGetColumnMeans(Mat, PetscScalar *);
929: PETSC_EXTERN PetscErrorCode MatGetColumnMeansRealPart(Mat, PetscReal *);
930: PETSC_EXTERN PetscErrorCode MatGetColumnMeansImaginaryPart(Mat, PetscReal *);
931: PETSC_EXTERN PetscErrorCode MatGetColumnReductions(Mat, PetscInt, PetscReal *);
932: PETSC_EXTERN PetscErrorCode MatZeroEntries(Mat);
933: PETSC_EXTERN PetscErrorCode MatFlag(Mat, PetscInt);
934: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "MatFlag()", ) static inline PetscErrorCode MatSetInf(Mat A)
935: {
936:   return MatFlag(A, 1);
937: }
938: PETSC_EXTERN PetscErrorCode MatZeroRows(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
939: PETSC_EXTERN PetscErrorCode MatZeroRowsIS(Mat, IS, PetscScalar, Vec, Vec);
940: PETSC_EXTERN PetscErrorCode MatZeroRowsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec);
941: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsStencil(Mat, PetscInt, const MatStencil[], PetscScalar, Vec, Vec);
942: PETSC_EXTERN PetscErrorCode MatZeroRowsColumns(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
943: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsIS(Mat, IS, PetscScalar, Vec, Vec);

945: PETSC_EXTERN PetscErrorCode MatGetSize(Mat, PetscInt *, PetscInt *);
946: PETSC_EXTERN PetscErrorCode MatGetLocalSize(Mat, PetscInt *, PetscInt *);
947: PETSC_EXTERN PetscErrorCode MatGetOwnershipRange(Mat, PetscInt *, PetscInt *);
948: PETSC_EXTERN PetscErrorCode MatGetOwnershipRanges(Mat, const PetscInt **);
949: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangeColumn(Mat, PetscInt *, PetscInt *);
950: PETSC_EXTERN PetscErrorCode MatGetOwnershipRangesColumn(Mat, const PetscInt **);
951: PETSC_EXTERN PetscErrorCode MatGetOwnershipIS(Mat, IS *, IS *);

953: PETSC_EXTERN PetscErrorCode MatCreateSubMatrices(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]);
954: 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[])
955: {
956:   return MatCreateSubMatrices(mat, n, irow, icol, scall, submat);
957: }
958: PETSC_EXTERN PetscErrorCode MatCreateSubMatricesMPI(Mat, PetscInt, const IS[], const IS[], MatReuse, Mat *[]);
959: 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[])
960: {
961:   return MatCreateSubMatricesMPI(mat, n, irow, icol, scall, submat);
962: }
963: PETSC_EXTERN PetscErrorCode MatDestroyMatrices(PetscInt, Mat *[]);
964: PETSC_EXTERN PetscErrorCode MatDestroySubMatrices(PetscInt, Mat *[]);
965: PETSC_EXTERN PetscErrorCode MatCreateSubMatrix(Mat, IS, IS, MatReuse, Mat *);
966: PETSC_DEPRECATED_FUNCTION(3, 8, 0, "MatCreateSubMatrix()", ) static inline PetscErrorCode MatGetSubMatrix(Mat mat, IS isrow, IS iscol, MatReuse cll, Mat *newmat)
967: {
968:   return MatCreateSubMatrix(mat, isrow, iscol, cll, newmat);
969: }
970: PETSC_EXTERN PetscErrorCode MatGetLocalSubMatrix(Mat, IS, IS, Mat *);
971: PETSC_EXTERN PetscErrorCode MatRestoreLocalSubMatrix(Mat, IS, IS, Mat *);
972: PETSC_EXTERN PetscErrorCode MatGetSeqNonzeroStructure(Mat, Mat *);
973: PETSC_EXTERN PetscErrorCode MatDestroySeqNonzeroStructure(Mat *);

975: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJ(MPI_Comm, Mat, PetscInt, PetscInt, MatReuse, Mat *);
976: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJSymbolic(MPI_Comm, Mat, PetscInt, PetscInt, Mat *);
977: PETSC_EXTERN PetscErrorCode MatCreateMPIAIJSumSeqAIJNumeric(Mat, Mat);
978: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMat(Mat, MatReuse, Mat *);
979: PETSC_EXTERN PetscErrorCode MatAIJGetLocalMat(Mat, Mat *);
980: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatCondensed(Mat, MatReuse, IS *, IS *, Mat *);
981: PETSC_EXTERN PetscErrorCode MatMPIAIJGetLocalMatMerge(Mat, MatReuse, IS *, Mat *);
982: PETSC_EXTERN PetscErrorCode MatMPIAIJGetNumberNonzeros(Mat, PetscCount *);
983: PETSC_EXTERN PetscErrorCode MatGetBrowsOfAcols(Mat, Mat, MatReuse, IS *, IS *, Mat *);
984: PETSC_EXTERN PetscErrorCode MatGetGhosts(Mat, PetscInt *, const PetscInt *[]);

986: PETSC_EXTERN PetscErrorCode MatIncreaseOverlap(Mat, PetscInt, IS[], PetscInt);
987: PETSC_EXTERN PetscErrorCode MatIncreaseOverlapSplit(Mat, PetscInt, IS[], PetscInt);
988: PETSC_EXTERN PetscErrorCode MatMPIAIJSetUseScalableIncreaseOverlap(Mat, PetscBool);

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

992: PETSC_EXTERN PetscErrorCode MatMatMatMult(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);
993: PETSC_EXTERN PetscErrorCode MatGalerkin(Mat, Mat, Mat, MatReuse, PetscReal, Mat *);

995: PETSC_EXTERN PetscErrorCode MatPtAP(Mat, Mat, MatReuse, PetscReal, Mat *);
996: PETSC_EXTERN PetscErrorCode MatRARt(Mat, Mat, MatReuse, PetscReal, Mat *);

998: PETSC_EXTERN PetscErrorCode MatTransposeMatMult(Mat, Mat, MatReuse, PetscReal, Mat *);
999: PETSC_EXTERN PetscErrorCode MatMatTransposeMult(Mat, Mat, MatReuse, PetscReal, Mat *);

1001: PETSC_EXTERN PetscErrorCode MatAXPY(Mat, PetscScalar, Mat, MatStructure);
1002: PETSC_EXTERN PetscErrorCode MatAYPX(Mat, PetscScalar, Mat, MatStructure);

1004: PETSC_EXTERN PetscErrorCode MatScale(Mat, PetscScalar);
1005: PETSC_EXTERN PetscErrorCode MatShift(Mat, PetscScalar);

1007: PETSC_EXTERN PetscErrorCode MatSetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping, ISLocalToGlobalMapping);
1008: PETSC_EXTERN PetscErrorCode MatGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *);
1009: PETSC_EXTERN PetscErrorCode MatGetLayouts(Mat, PetscLayout *, PetscLayout *);
1010: PETSC_EXTERN PetscErrorCode MatSetLayouts(Mat, PetscLayout, PetscLayout);
1011: PETSC_EXTERN PetscErrorCode MatZeroRowsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
1012: PETSC_EXTERN PetscErrorCode MatZeroRowsLocalIS(Mat, IS, PetscScalar, Vec, Vec);
1013: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocal(Mat, PetscInt, const PetscInt[], PetscScalar, Vec, Vec);
1014: PETSC_EXTERN PetscErrorCode MatZeroRowsColumnsLocalIS(Mat, IS, PetscScalar, Vec, Vec);
1015: PETSC_EXTERN PetscErrorCode MatGetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscScalar[]);
1016: PETSC_EXTERN PetscErrorCode MatSetValuesLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
1017: PETSC_EXTERN PetscErrorCode MatSetValuesBlockedLocal(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], InsertMode);

1019: PETSC_EXTERN PetscErrorCode MatStashSetInitialSize(Mat, PetscInt, PetscInt);
1020: PETSC_EXTERN PetscErrorCode MatStashGetInfo(Mat, PetscInt *, PetscInt *, PetscInt *, PetscInt *);

1022: PETSC_EXTERN PetscErrorCode MatInterpolate(Mat, Vec, Vec);
1023: PETSC_EXTERN PetscErrorCode MatInterpolateAdd(Mat, Vec, Vec, Vec);
1024: PETSC_EXTERN PetscErrorCode MatRestrict(Mat, Vec, Vec);
1025: PETSC_EXTERN PetscErrorCode MatMatInterpolate(Mat, Mat, Mat *);
1026: PETSC_EXTERN PetscErrorCode MatMatInterpolateAdd(Mat, Mat, Mat, Mat *);
1027: PETSC_EXTERN PetscErrorCode MatMatRestrict(Mat, Mat, Mat *);
1028: PETSC_EXTERN PetscErrorCode MatCreateVecs(Mat, Vec *, Vec *);
1029: PETSC_DEPRECATED_FUNCTION(3, 6, 0, "MatCreateVecs()", ) static inline PetscErrorCode MatGetVecs(Mat mat, Vec *x, Vec *y)
1030: {
1031:   return MatCreateVecs(mat, x, y);
1032: }
1033: PETSC_EXTERN PetscErrorCode MatCreateRedundantMatrix(Mat, PetscInt, MPI_Comm, MatReuse, Mat *);
1034: PETSC_EXTERN PetscErrorCode MatGetMultiProcBlock(Mat, MPI_Comm, MatReuse, Mat *);
1035: PETSC_EXTERN PetscErrorCode MatFindZeroDiagonals(Mat, IS *);
1036: PETSC_EXTERN PetscErrorCode MatFindOffBlockDiagonalEntries(Mat, IS *);
1037: PETSC_EXTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat(MPI_Comm, Mat, PetscInt, MatReuse, Mat *);

1039: PETSC_EXTERN PetscErrorCode MatCopyHashToXAIJ(Mat A, Mat B);
1040: /*@
1041:   MatSetValue - Set a single entry into a matrix.

1043:   Not Collective

1045:   Input Parameters:
1046: + mat  - the matrix
1047: . i    - the row location of the entry
1048: . j    - the column location of the entry
1049: . va   - the value to insert
1050: - mode - either `INSERT_VALUES` or `ADD_VALUES`

1052:   Level: beginner

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

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

1060: .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `InsertMode`, `MatGetValue()`, `MatSetValues()`,
1061:   `MatSetValueLocal()`, `MatSetValuesLocal()`
1062: @*/
1063: static inline PetscErrorCode MatSetValue(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode)
1064: {
1065:   return MatSetValues(mat, 1, &i, 1, &j, &va, mode);
1066: }

1068: /*@
1069:   MatGetValue - Gets a single value from a matrix

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

1073:   Input Parameters:
1074: + mat - the matrix
1075: . row - the row location of the entry
1076: - col - the column location of the entry

1078:   Output Parameter:
1079: . va - the value

1081:   Level: advanced

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

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

1088:   See notes for `MatGetValues()`.

1090: .seealso: [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `MatSetValue()`, `MatGetValuesLocal()`, `MatGetValues()`
1091: @*/
1092: static inline PetscErrorCode MatGetValue(Mat mat, PetscInt row, PetscInt col, PetscScalar *va)
1093: {
1094:   return MatGetValues(mat, 1, &row, 1, &col, va);
1095: }

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

1100:   Not Collective

1102:   Input Parameters:
1103: + mat  - the matrix
1104: . i    - the row location of the entry
1105: . j    - the column location of the entry
1106: . va   - the value to insert
1107: - mode - either `INSERT_VALUES` or `ADD_VALUES`

1109:   Level: intermediate

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

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

1116: .seealso: [](ch_matrices), `MatSetValue()`, `MatSetValuesLocal()`
1117: @*/
1118: static inline PetscErrorCode MatSetValueLocal(Mat mat, PetscInt i, PetscInt j, PetscScalar va, InsertMode mode)
1119: {
1120:   return MatSetValuesLocal(mat, 1, &i, 1, &j, &va, mode);
1121: }

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

1127:    Synopsis:
1128: #include <petscmat.h>
1129:    PetscErrorCode MatPreallocateBegin(MPI_Comm comm, PetscInt nrows, PetscInt ncols, PetscInt *dnz, PetscInt *onz)

1131:    Collective

1133:    Input Parameters:
1134: +  comm  - the communicator that will share the eventually allocated matrix
1135: .  nrows - the number of LOCAL rows in the matrix
1136: -  ncols - the number of LOCAL columns in the matrix

1138:    Output Parameters:
1139: +  dnz - the array that will be passed to the matrix preallocation routines
1140: -  onz - the other array passed to the matrix preallocation routines

1142:    Level: deprecated (since v3.19)

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

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

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

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

1155: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`,
1156:           `MatPreallocateSymmetricSetLocalBlock()`
1157: M*/
1158: #define MatPreallocateBegin(comm, nrows, ncols, dnz, onz) \
1159:   do { \
1160:     PetscInt              __nrows = (nrows), __ncols = (ncols), __rstart, __end = 0; \
1161:     PetscInt PETSC_UNUSED __start; \
1162:     PetscCall(PetscCalloc2(__nrows, &(dnz), __nrows, &(onz))); \
1163:     PetscCallMPI(MPI_Scan(&__ncols, &__end, 1, MPIU_INT, MPI_SUM, comm)); \
1164:     __start = __end - __ncols; \
1165:     (void)__start; \
1166:     PetscCallMPI(MPI_Scan(&__nrows, &__rstart, 1, MPIU_INT, MPI_SUM, comm)); \
1167:   __rstart -= __nrows

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

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

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

1179:    Not Collective

1181:    Input Parameters:
1182: +  map   - the row mapping from local numbering to global numbering
1183: .  nrows - the number of rows indicated
1184: .  rows  - the indices of the rows
1185: .  cmap  - the column mapping from local to global numbering
1186: .  ncols - the number of columns in the matrix
1187: .  cols  - the columns indicated
1188: .  dnz   - the array that will be passed to the matrix preallocation routines
1189: -  onz   - the other array passed to the matrix preallocation routines

1191:    Level: deprecated (since v3.19)

1193:    Notes:
1194:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1195:    the use of this routine

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

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

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

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

1213:    Not Collective

1215:    Input Parameters:
1216: +  map   - the row mapping from local numbering to global numbering
1217: .  nrows - the number of rows indicated
1218: .  rows  - the indices of the rows (these values are mapped to the global values)
1219: .  cmap  - the column mapping from local to global numbering
1220: .  ncols - the number of columns in the matrix   (this value will be changed if duplicate columns are found)
1221: .  cols  - the columns indicated (these values are mapped to the global values, they are then sorted and duplicates removed)
1222: .  dnz   - the array that will be passed to the matrix preallocation routines
1223: -  onz   - the other array passed to the matrix preallocation routines

1225:    Level: deprecated (since v3.19)

1227:    Notes:
1228:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1229:    the use of this routine

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

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

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

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

1247:    Not Collective

1249:    Input Parameters:
1250: +  map   - the row mapping from local numbering to global numbering
1251: .  nrows - the number of rows indicated
1252: .  rows  - the indices of the rows
1253: .  cmap  - the column mapping from local to global numbering
1254: .  ncols - the number of columns in the matrix
1255: .  cols  - the columns indicated
1256: .  dnz   - the array that will be passed to the matrix preallocation routines
1257: -  onz   - the other array passed to the matrix preallocation routines

1259:    Level: deprecated (since v3.19)

1261:    Notes:
1262:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1263:    the use of this routine

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

1267: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1268:           `MatPreallocateBegin()`, `MatPreallocateSymmetricSetLocalBlock()`
1269: M*/
1270: #define MatPreallocateSetLocalBlock(rmap, nrows, rows, cmap, ncols, cols, dnz, onz) \
1271:   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));)

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

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

1281:    Not Collective

1283:    Input Parameters:
1284: +  map   - the mapping between local numbering and global numbering
1285: .  nrows - the number of rows indicated
1286: .  rows  - the indices of the rows
1287: .  ncols - the number of columns in the matrix
1288: .  cols  - the columns indicated
1289: .  dnz   - the array that will be passed to the matrix preallocation routines
1290: -  onz   - the other array passed to the matrix preallocation routines

1292:    Level: deprecated (since v3.19)

1294:    Notes:
1295:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1296:    the use of this routine

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

1300: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`,
1301:           `MatPreallocateBegin()`, `MatPreallocateSetLocal()`
1302: M*/
1303: #define MatPreallocateSymmetricSetLocalBlock(map, nrows, rows, ncols, cols, dnz, onz) \
1304:   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));)

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

1310:    Synopsis:
1311: #include <petscmat.h>
1312:    PetscErrorCode MatPreallocateSet(PetscInt nrows, PetscInt *rows, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1314:    Not Collective

1316:    Input Parameters:
1317: +  row   - the row
1318: .  ncols - the number of columns in the matrix
1319: -  cols  - the columns indicated

1321:    Output Parameters:
1322: +  dnz - the array that will be passed to the matrix preallocation routines
1323: -  onz - the other array passed to the matrix preallocation routines

1325:    Level: deprecated (since v3.19)

1327:    Notes:
1328:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1329:    the use of this routine

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

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

1335: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`,
1336:           `MatPreallocateBegin()`, `MatPreallocateSetLocal()`
1337: M*/
1338: #define MatPreallocateSet(row, nc, cols, dnz, onz) \
1339:   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) { \
1340:       if ((cols)[__i] < __start || (cols)[__i] >= __end) (onz)[(row) - __rstart]++; \
1341:       else if ((dnz)[(row) - __rstart] < __ncols) (dnz)[(row) - __rstart]++; \
1342:   })

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

1348:    Synopsis:
1349: #include <petscmat.h>
1350:    PetscErrorCode MatPreallocateSymmetricSetBlock(PetscInt nrows, PetscInt *rows, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1352:    Not Collective

1354:    Input Parameters:
1355: +  nrows - the number of rows indicated
1356: .  rows  - the indices of the rows
1357: .  ncols - the number of columns in the matrix
1358: .  cols  - the columns indicated
1359: .  dnz   - the array that will be passed to the matrix preallocation routines
1360: -  onz   - the other array passed to the matrix preallocation routines

1362:    Level: deprecated (since v3.19)

1364:    Notes:
1365:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1366:    the use of this routine

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

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

1372: .seealso: [](ch_matrices), `MatPreallocateEnd()`, `MatPreallocateSet()`, `MatPreallocateBegin()`,
1373:           `MatPreallocateSymmetricSetLocalBlock()`, `MatPreallocateSetLocal()`
1374: M*/
1375: #define MatPreallocateSymmetricSetBlock(row, nc, cols, dnz, onz) \
1376:   PetscMacroReturnStandard(for (PetscInt __i = 0; __i < (nc); __i++) {  \
1377:       if ((cols)[__i] >= __end) (onz)[(row) - __rstart]++;              \
1378:       else if ((cols)[__i] >= (row) && (dnz)[(row) - __rstart] < __ncols) (dnz)[(row) - __rstart]++; \
1379:   })

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

1384:    Synopsis:
1385: #include <petscmat.h>
1386:    PetscErrorCode MatPreallocateLocations(Mat A, PetscInt row, PetscInt ncols, PetscInt *cols, PetscInt *dnz, PetscInt *onz)

1388:    Not Collective

1390:    Input Parameters:
1391: +  A     - matrix
1392: .  row   - row where values exist (must be local to this process)
1393: .  ncols - number of columns
1394: .  cols  - columns with nonzeros
1395: .  dnz   - the array that will be passed to the matrix preallocation routines
1396: -  onz   - the other array passed to the matrix preallocation routines

1398:    Level: deprecated (since v3.19)

1400:    Notes:
1401:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1402:    the use of this routine

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

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

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

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

1418:    Synopsis:
1419: #include <petscmat.h>
1420:    PetscErrorCode MatPreallocateEnd(PetscInt *dnz, PetscInt *onz)

1422:    Collective

1424:    Input Parameters:
1425: +  dnz - the array that was be passed to the matrix preallocation routines
1426: -  onz - the other array passed to the matrix preallocation routines

1428:    Level: deprecated (since v3.19)

1430:    Notes:
1431:    This routine is no longer needed since assembling matrices without explicit preallocation will not be slower than
1432:    the use of this routine

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

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

1439: .seealso: [](ch_matrices), `MatPreallocateBegin()`, `MatPreallocateSet()`, `MatPreallocateSymmetricSetBlock()`, `MatPreallocateSetLocal()`,
1440:           `MatPreallocateSymmetricSetLocalBlock()`
1441: M*/
1442: #define MatPreallocateEnd(dnz, onz) \
1443:   PetscCall(PetscFree2(dnz, onz)); \
1444:   } \
1445:   while (0)

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

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

1452: PETSC_EXTERN PetscErrorCode MatInodeAdjustForInodes(Mat, IS *, IS *);
1453: PETSC_EXTERN PetscErrorCode MatInodeGetInodeSizes(Mat, PetscInt *, PetscInt *[], PetscInt *);

1455: PETSC_EXTERN PetscErrorCode MatSeqAIJSetColumnIndices(Mat, PetscInt[]);
1456: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetColumnIndices(Mat, PetscInt[]);
1457: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1458: PETSC_EXTERN PetscErrorCode MatCreateSeqBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1459: PETSC_EXTERN PetscErrorCode MatCreateSeqSBAIJWithArrays(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *);
1460: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJFromTriple(MPI_Comm, PetscInt, PetscInt, PetscInt[], PetscInt[], PetscScalar[], Mat *, PetscCount, PetscBool);

1462: #define MAT_SKIP_ALLOCATION -4

1464: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1465: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[]);
1466: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation(Mat, PetscInt, const PetscInt[]);
1467: PETSC_EXTERN PetscErrorCode MatSeqAIJSetTotalPreallocation(Mat, PetscInt);

1469: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1470: PETSC_EXTERN PetscErrorCode MatMPISBAIJSetPreallocation(Mat, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1471: PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1472: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]);
1473: PETSC_EXTERN PetscErrorCode MatSeqBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
1474: PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat, const PetscInt[], const PetscInt[], const PetscScalar[]);
1475: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetPreallocationCSR(Mat, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[]);
1476: PETSC_EXTERN PetscErrorCode MatMPIAdjSetPreallocation(Mat, PetscInt[], PetscInt[], PetscInt[]);
1477: PETSC_EXTERN PetscErrorCode MatMPIAdjToSeq(Mat, Mat *);
1478: PETSC_EXTERN PetscErrorCode MatMPIAdjToSeqRankZero(Mat, Mat *);
1479: PETSC_EXTERN PetscErrorCode MatMPIDenseSetPreallocation(Mat, PetscScalar[]);
1480: PETSC_EXTERN PetscErrorCode MatSeqDenseSetPreallocation(Mat, PetscScalar[]);
1481: PETSC_EXTERN PetscErrorCode MatMPIAIJGetSeqAIJ(Mat, Mat *, Mat *, const PetscInt *[]);
1482: PETSC_EXTERN PetscErrorCode MatMPIBAIJGetSeqBAIJ(Mat, Mat *, Mat *, const PetscInt *[]);
1483: PETSC_EXTERN PetscErrorCode MatMPIAdjCreateNonemptySubcommMat(Mat, Mat *);

1485: PETSC_EXTERN PetscErrorCode MatDenseGetLDA(Mat, PetscInt *);
1486: PETSC_EXTERN PetscErrorCode MatDenseSetLDA(Mat, PetscInt);
1487: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatDenseSetLDA()", ) static inline PetscErrorCode MatSeqDenseSetLDA(Mat A, PetscInt lda)
1488: {
1489:   return MatDenseSetLDA(A, lda);
1490: }
1491: PETSC_EXTERN PetscErrorCode MatDenseGetLocalMatrix(Mat, Mat *);

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

1495: PETSC_EXTERN PetscErrorCode MatStoreValues(Mat);
1496: PETSC_EXTERN PetscErrorCode MatRetrieveValues(Mat);

1498: PETSC_EXTERN PetscErrorCode MatFindNonzeroRows(Mat, IS *);
1499: PETSC_EXTERN PetscErrorCode MatFindZeroRows(Mat, IS *);
1500: /*
1501:   These routines are not usually accessed directly, rather solving is
1502:   done through the KSP and PC interfaces.
1503: */

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

1509:    Level: beginner

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

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

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

1520: .seealso: [](ch_matrices), [](sec_graph), `MatGetFactor()`, `MatGetOrdering()`, `MatColoringType`, `MatPartitioningType`, `MatCoarsenType`, `PCFactorSetOrderingType()`
1521: J*/
1522: typedef const char *MatOrderingType;
1523: #define MATORDERINGNATURAL       "natural"
1524: #define MATORDERINGND            "nd"
1525: #define MATORDERING1WD           "1wd"
1526: #define MATORDERINGRCM           "rcm"
1527: #define MATORDERINGQMD           "qmd"
1528: #define MATORDERINGROWLENGTH     "rowlength"
1529: #define MATORDERINGWBM           "wbm"
1530: #define MATORDERINGSPECTRAL      "spectral"
1531: #define MATORDERINGAMD           "amd"           /* only works if UMFPACK is installed with PETSc */
1532: #define MATORDERINGMETISND       "metisnd"       /* only works if METIS is installed with PETSc */
1533: #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 */
1534: #define MATORDERINGEXTERNAL      "external"      /* uses an ordering type internal to the factorization package */

1536: PETSC_EXTERN PetscErrorCode    MatGetOrdering(Mat, MatOrderingType, IS *, IS *);
1537: PETSC_EXTERN PetscErrorCode    MatGetOrderingList(PetscFunctionList *);
1538: PETSC_EXTERN PetscErrorCode    MatOrderingRegister(const char[], PetscErrorCode (*)(Mat, MatOrderingType, IS *, IS *));
1539: PETSC_EXTERN PetscFunctionList MatOrderingList;

1541: #include "petscmatcoarsen.h"

1543: PETSC_EXTERN PetscErrorCode MatReorderForNonzeroDiagonal(Mat, PetscReal, IS, IS);
1544: PETSC_EXTERN PetscErrorCode MatCreateLaplacian(Mat, PetscReal, PetscBool, Mat *);

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

1548: /*S
1549:    MatFactorShiftType - Type of numeric shift used for factorizations

1551:    Values:
1552: +  `MAT_SHIFT_NONE`              - do not shift the matrix diagonal entries
1553: .  `MAT_SHIFT_NONZERO`           - shift the entries to be non-zero
1554: .  `MAT_SHIFT_POSITIVE_DEFINITE` - shift the entries to force the factorization to be positive definite
1555: -  `MAT_SHIFT_INBLOCKS`          - only shift the factors inside the small dense diagonal blocks of the matrix, for example with `MATBAIJ`

1557:    Level: intermediate

1559: .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `PCFactorSetShiftType()`
1560: S*/
1561: typedef enum {
1562:   MAT_SHIFT_NONE,
1563:   MAT_SHIFT_NONZERO,
1564:   MAT_SHIFT_POSITIVE_DEFINITE,
1565:   MAT_SHIFT_INBLOCKS
1566: } MatFactorShiftType;
1567: PETSC_EXTERN const char *const MatFactorShiftTypes[];
1568: PETSC_EXTERN const char *const MatFactorShiftTypesDetail[];

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

1573:     Values:
1574: +   `MAT_FACTOR_NOERROR`           - there was no error during the factorization
1575: .   `MAT_FACTOR_STRUCT_ZEROPIVOT`  - there was a missing entry in a diagonal location of the matrix
1576: .   `MAT_FACTOR_NUMERIC_ZEROPIVOT` - there was a (near) zero pivot during the factorization
1577: .   `MAT_FACTOR_OUTMEMORY`         - the factorization has run out of memory
1578: -   `MAT_FACTOR_OTHER`             - some other error has occurred.

1580:     Level: intermediate

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

1585: .seealso: [](ch_matrices), `Mat`, `MatGetFactor()`, `MatFactorGetError()`, `MatFactorGetErrorZeroPivot()`, `MatFactorClearError()`,
1586:           `PCFailedReason`, `PCGetFailedReason()`, `KSPConvergedReason`
1587: S*/
1588: typedef enum {
1589:   MAT_FACTOR_NOERROR,
1590:   MAT_FACTOR_STRUCT_ZEROPIVOT,
1591:   MAT_FACTOR_NUMERIC_ZEROPIVOT,
1592:   MAT_FACTOR_OUTMEMORY,
1593:   MAT_FACTOR_OTHER
1594: } MatFactorError;

1596: PETSC_EXTERN PetscErrorCode MatFactorGetError(Mat, MatFactorError *);
1597: PETSC_EXTERN PetscErrorCode MatFactorClearError(Mat);
1598: PETSC_EXTERN PetscErrorCode MatFactorGetErrorZeroPivot(Mat, PetscReal *, PetscInt *);

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

1603:    Level: developer

1605:    Note:
1606:    You can use `MatFactorInfoInitialize()` to set default values.

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

1611: .seealso: [](ch_matrices), `Mat`, `MatInfo`, `MatGetFactor()`, `MatLUFactorSymbolic()`, `MatILUFactorSymbolic()`, `MatCholeskyFactorSymbolic()`,
1612:           `MatICCFactorSymbolic()`, `MatICCFactor()`, `MatFactorInfoInitialize()`
1613: S*/
1614: typedef struct {
1615:   PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */
1616:   PetscReal usedt;
1617:   PetscReal dt;            /* drop tolerance */
1618:   PetscReal dtcol;         /* tolerance for pivoting */
1619:   PetscReal dtcount;       /* maximum nonzeros to be allowed per row */
1620:   PetscReal fill;          /* expected fill, nonzeros in factored matrix/nonzeros in original matrix */
1621:   PetscReal levels;        /* ICC/ILU(levels) */
1622:   PetscReal pivotinblocks; /* BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0 factorization may be faster if do not pivot */
1623:   PetscReal zeropivot;     /* pivot is called zero if less than this */
1624:   PetscReal shifttype;     /* type of shift added to matrix factor to prevent zero pivots */
1625:   PetscReal shiftamount;   /* how large the shift is */
1626:   PetscBool factoronhost;  /* do factorization on host instead of device (for device matrix types) */
1627:   PetscBool solveonhost;   /* do mat solve on host with the factor (for device matrix types) */
1628: } MatFactorInfo;

1630: PETSC_EXTERN PetscErrorCode MatFactorInfoInitialize(MatFactorInfo *);
1631: PETSC_EXTERN PetscErrorCode MatCholeskyFactor(Mat, IS, const MatFactorInfo *);
1632: PETSC_EXTERN PetscErrorCode MatCholeskyFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1633: PETSC_EXTERN PetscErrorCode MatCholeskyFactorNumeric(Mat, Mat, const MatFactorInfo *);
1634: PETSC_EXTERN PetscErrorCode MatLUFactor(Mat, IS, IS, const MatFactorInfo *);
1635: PETSC_EXTERN PetscErrorCode MatILUFactor(Mat, IS, IS, const MatFactorInfo *);
1636: PETSC_EXTERN PetscErrorCode MatLUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *);
1637: PETSC_EXTERN PetscErrorCode MatILUFactorSymbolic(Mat, Mat, IS, IS, const MatFactorInfo *);
1638: PETSC_EXTERN PetscErrorCode MatICCFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1639: PETSC_EXTERN PetscErrorCode MatICCFactor(Mat, IS, const MatFactorInfo *);
1640: PETSC_EXTERN PetscErrorCode MatLUFactorNumeric(Mat, Mat, const MatFactorInfo *);
1641: PETSC_EXTERN PetscErrorCode MatQRFactor(Mat, IS, const MatFactorInfo *);
1642: PETSC_EXTERN PetscErrorCode MatQRFactorSymbolic(Mat, Mat, IS, const MatFactorInfo *);
1643: PETSC_EXTERN PetscErrorCode MatQRFactorNumeric(Mat, Mat, const MatFactorInfo *);
1644: PETSC_EXTERN PetscErrorCode MatGetInertia(Mat, PetscInt *, PetscInt *, PetscInt *);
1645: PETSC_EXTERN PetscErrorCode MatSolve(Mat, Vec, Vec);
1646: PETSC_EXTERN PetscErrorCode MatForwardSolve(Mat, Vec, Vec);
1647: PETSC_EXTERN PetscErrorCode MatBackwardSolve(Mat, Vec, Vec);
1648: PETSC_EXTERN PetscErrorCode MatSolveAdd(Mat, Vec, Vec, Vec);
1649: PETSC_EXTERN PetscErrorCode MatSolveTranspose(Mat, Vec, Vec);
1650: PETSC_EXTERN PetscErrorCode MatSolveTransposeAdd(Mat, Vec, Vec, Vec);
1651: PETSC_EXTERN PetscErrorCode MatSolves(Mat, Vecs, Vecs);
1652: PETSC_EXTERN PetscErrorCode MatSetUnfactored(Mat);

1654: /*E
1655:    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()`

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

1662:    Level: advanced

1664: .seealso: [](ch_matrices), `Mat`, `MatFactorSetSchurIS()`, `MatFactorGetSchurComplement()`, `MatFactorRestoreSchurComplement()`,
1665:           `MatFactorInvertSchurComplement()`, `MatFactorCreateSchurComplement()`
1666: E*/
1667: typedef enum {
1668:   MAT_FACTOR_SCHUR_UNFACTORED,
1669:   MAT_FACTOR_SCHUR_FACTORED,
1670:   MAT_FACTOR_SCHUR_INVERTED
1671: } MatFactorSchurStatus;
1672: PETSC_EXTERN PetscErrorCode MatFactorSetSchurIS(Mat, IS);
1673: PETSC_EXTERN PetscErrorCode MatFactorGetSchurComplement(Mat, Mat *, MatFactorSchurStatus *);
1674: PETSC_EXTERN PetscErrorCode MatFactorRestoreSchurComplement(Mat, Mat *, MatFactorSchurStatus);
1675: PETSC_EXTERN PetscErrorCode MatFactorInvertSchurComplement(Mat);
1676: PETSC_EXTERN PetscErrorCode MatFactorCreateSchurComplement(Mat, Mat *, MatFactorSchurStatus *);
1677: PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplement(Mat, Vec, Vec);
1678: PETSC_EXTERN PetscErrorCode MatFactorSolveSchurComplementTranspose(Mat, Vec, Vec);
1679: PETSC_EXTERN PetscErrorCode MatFactorFactorizeSchurComplement(Mat);

1681: PETSC_EXTERN PetscErrorCode MatSeqDenseInvert(Mat);
1682: /*E
1683:    MatSORType - What type of (S)SOR to perform

1685:    Values:
1686: +  `SOR_FORWARD_SWEEP`         - do a sweep from the first row of the matrix to the last
1687: .  `SOR_BACKWARD_SWEEP`        - do a sweep from the last row to the first
1688: .  `SOR_SYMMETRIC_SWEEP`       - do a sweep from the first row to the last and then back to the first
1689: .  `SOR_LOCAL_FORWARD_SWEEP`   - each MPI process does its own forward sweep with no communication
1690: .  `SOR_LOCAL_BACKWARD_SWEEP`  - each MPI process does its own backward sweep with no communication
1691: .  `SOR_LOCAL_SYMMETRIC_SWEEP` - each MPI process does its own symmetric sweep with no communication
1692: .  `SOR_ZERO_INITIAL_GUESS`    - indicates the initial solution is zero so the sweep can avoid unneeded computation
1693: .  `SOR_EISENSTAT`             - apply the Eisentat application of SOR, see `PCEISENSTAT`
1694: .  `SOR_APPLY_UPPER`           - multiply by the upper triangular portion of the matrix
1695: -  `SOR_APPLY_LOWER`           - multiply by the lower triangular portion of the matrix

1697:    Level: beginner

1699:    Note:
1700:    These may be bitwise ORd together

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

1705: .seealso: [](ch_matrices), `MatSOR()`
1706: E*/
1707: typedef enum {
1708:   SOR_FORWARD_SWEEP         = 1,
1709:   SOR_BACKWARD_SWEEP        = 2,
1710:   SOR_SYMMETRIC_SWEEP       = 3,
1711:   SOR_LOCAL_FORWARD_SWEEP   = 4,
1712:   SOR_LOCAL_BACKWARD_SWEEP  = 8,
1713:   SOR_LOCAL_SYMMETRIC_SWEEP = 12,
1714:   SOR_ZERO_INITIAL_GUESS    = 16,
1715:   SOR_EISENSTAT             = 32,
1716:   SOR_APPLY_UPPER           = 64,
1717:   SOR_APPLY_LOWER           = 128
1718: } MatSORType;
1719: PETSC_EXTERN PetscErrorCode MatSOR(Mat, Vec, PetscReal, MatSORType, PetscReal, PetscInt, PetscInt, Vec);

1721: /*S
1722:    MatColoring - Object for managing the coloring of matrices.

1724:    Level: beginner

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

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

1733: .seealso: [](ch_matrices), [](sec_graph), `MatFDColoringCreate()`, `MatColoringWeightType`, `ISColoring`, `MatFDColoring`, `DMCreateColoring()`, `MatColoringCreate()`,
1734:           `MatPartitioning`, `MatColoringType`, `MatPartitioningType`, `MatOrderingType`, `MatColoringSetWeightType()`,
1735:           `MatColoringSetWeights()`, `MatCoarsenType`, `MatCoarsen`
1736: S*/
1737: typedef struct _p_MatColoring *MatColoring;

1739: /*J
1740:    MatColoringType - String with the name of a PETSc matrix coloring

1742:    Level: beginner

1744: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatFDColoringCreate()`, `MatColoringSetType()`, `MatColoring`
1745: J*/
1746: typedef const char *MatColoringType;
1747: #define MATCOLORINGJP      "jp"
1748: #define MATCOLORINGPOWER   "power"
1749: #define MATCOLORINGNATURAL "natural"
1750: #define MATCOLORINGSL      "sl"
1751: #define MATCOLORINGLF      "lf"
1752: #define MATCOLORINGID      "id"
1753: #define MATCOLORINGGREEDY  "greedy"

1755: /*E
1756:    MatColoringWeightType - Type of weight scheme used for the coloring algorithm

1758:    Values:
1759: +  `MAT_COLORING_RANDOM`  - Random weights
1760: .  `MAT_COLORING_LEXICAL` - Lexical weighting based upon global numbering.
1761: -  `MAT_COLORING_LF`      - Last-first weighting.

1763:     Level: intermediate

1765: .seealso: [](ch_matrices), `MatColoring`, `MatColoringCreate()`, `MatColoringSetWeightType()`, `MatColoringSetWeights()`
1766: E*/
1767: typedef enum {
1768:   MAT_COLORING_WEIGHT_RANDOM,
1769:   MAT_COLORING_WEIGHT_LEXICAL,
1770:   MAT_COLORING_WEIGHT_LF,
1771:   MAT_COLORING_WEIGHT_SL
1772: } MatColoringWeightType;

1774: PETSC_EXTERN PetscErrorCode MatColoringCreate(Mat, MatColoring *);
1775: PETSC_EXTERN PetscErrorCode MatColoringGetDegrees(Mat, PetscInt, PetscInt *);
1776: PETSC_EXTERN PetscErrorCode MatColoringDestroy(MatColoring *);
1777: PETSC_EXTERN PetscErrorCode MatColoringView(MatColoring, PetscViewer);
1778: PETSC_EXTERN PetscErrorCode MatColoringSetType(MatColoring, MatColoringType);
1779: PETSC_EXTERN PetscErrorCode MatColoringSetFromOptions(MatColoring);
1780: PETSC_EXTERN PetscErrorCode MatColoringSetDistance(MatColoring, PetscInt);
1781: PETSC_EXTERN PetscErrorCode MatColoringGetDistance(MatColoring, PetscInt *);
1782: PETSC_EXTERN PetscErrorCode MatColoringSetMaxColors(MatColoring, PetscInt);
1783: PETSC_EXTERN PetscErrorCode MatColoringGetMaxColors(MatColoring, PetscInt *);
1784: PETSC_EXTERN PetscErrorCode MatColoringApply(MatColoring, ISColoring *);
1785: PETSC_EXTERN PetscErrorCode MatColoringRegister(const char[], PetscErrorCode (*)(MatColoring));
1786: PETSC_EXTERN PetscErrorCode MatColoringPatch(Mat, PetscInt, PetscInt, ISColoringValue[], ISColoring *);
1787: PETSC_EXTERN PetscErrorCode MatColoringSetWeightType(MatColoring, MatColoringWeightType);
1788: PETSC_EXTERN PetscErrorCode MatColoringSetWeights(MatColoring, PetscReal *, PetscInt *);
1789: PETSC_EXTERN PetscErrorCode MatColoringCreateWeights(MatColoring, PetscReal **, PetscInt **lperm);
1790: PETSC_EXTERN PetscErrorCode MatColoringTest(MatColoring, ISColoring);
1791: PETSC_DEPRECATED_FUNCTION(3, 10, 0, "MatColoringTest()", ) static inline PetscErrorCode MatColoringTestValid(MatColoring matcoloring, ISColoring iscoloring)
1792: {
1793:   return MatColoringTest(matcoloring, iscoloring);
1794: }
1795: PETSC_EXTERN PetscErrorCode MatISColoringTest(Mat, ISColoring);

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

1800:    Level: beginner

1802:    Options Database Key:
1803: .  -snes_fd_color (true|false) - cause the Jacobian needed by `SNES` to be computed via a use of this object

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

1808: .seealso: [](ch_matrices), `Mat`, `MatFDColoringCreate()`, `MatFDColoringSetFunction()`, `MatColoring`, `DMCreateColoring()`
1809: S*/
1810: typedef struct _p_MatFDColoring *MatFDColoring;

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

1815:   Level: advanced

1817:   Calling Sequence:
1818: + snes - either a `SNES` object if used within `SNES` otherwise an unused parameter
1819: . in   - the location where the Jacobian is to be computed
1820: . out  - the location to put the computed function value
1821: - fctx - the function context passed into `MatFDColoringSetFunction()`

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

1827: PETSC_EXTERN PetscErrorCode MatFDColoringCreate(Mat, ISColoring, MatFDColoring *);
1828: PETSC_EXTERN PetscErrorCode MatFDColoringDestroy(MatFDColoring *);
1829: PETSC_EXTERN PetscErrorCode MatFDColoringView(MatFDColoring, PetscViewer);
1830: PETSC_EXTERN PetscErrorCode MatFDColoringSetFunction(MatFDColoring, MatFDColoringFn *, void *);
1831: PETSC_EXTERN PetscErrorCode MatFDColoringGetFunction(MatFDColoring, MatFDColoringFn **, void **);
1832: PETSC_EXTERN PetscErrorCode MatFDColoringSetParameters(MatFDColoring, PetscReal, PetscReal);
1833: PETSC_EXTERN PetscErrorCode MatFDColoringSetFromOptions(MatFDColoring);
1834: PETSC_EXTERN PetscErrorCode MatFDColoringApply(Mat, MatFDColoring, Vec, void *);
1835: PETSC_EXTERN PetscErrorCode MatFDColoringSetF(MatFDColoring, Vec);
1836: PETSC_EXTERN PetscErrorCode MatFDColoringGetPerturbedColumns(MatFDColoring, PetscInt *, const PetscInt *[]);
1837: PETSC_EXTERN PetscErrorCode MatFDColoringSetUp(Mat, ISColoring, MatFDColoring);
1838: PETSC_EXTERN PetscErrorCode MatFDColoringSetBlockSize(MatFDColoring, PetscInt, PetscInt);
1839: PETSC_EXTERN PetscErrorCode MatFDColoringSetValues(Mat, MatFDColoring, const PetscScalar *);

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

1844:    Level: developer

1846: .seealso: [](ch_matrices), `Mat`, `MatProductType`, `MatTransposeColoringCreate()`
1847: S*/
1848: typedef struct _p_MatTransposeColoring *MatTransposeColoring;

1850: PETSC_EXTERN PetscErrorCode MatTransposeColoringCreate(Mat, ISColoring, MatTransposeColoring *);
1851: PETSC_EXTERN PetscErrorCode MatTransColoringApplySpToDen(MatTransposeColoring, Mat, Mat);
1852: PETSC_EXTERN PetscErrorCode MatTransColoringApplyDenToSp(MatTransposeColoring, Mat, Mat);
1853: PETSC_EXTERN PetscErrorCode MatTransposeColoringDestroy(MatTransposeColoring *);

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

1858:    Level: beginner

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

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

1867: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioningType`, `MatColoring`, `MatGetOrdering()`, `MatOrderingType`,
1868:           `MatCoarsenType`
1869: S*/
1870: typedef struct _p_MatPartitioning *MatPartitioning;

1872: /*J
1873:     MatPartitioningType - String with the name of a PETSc matrix partitioning

1875:    Level: beginner
1876: dm
1877: .seealso: [](ch_matrices), [](sec_graph), `Mat`, `MatPartitioningCreate()`, `MatPartitioning`, `MatPartitioningSetType()`, `MatColoringType`, `MatOrderingType`,
1878:           `MatCoarsenType`
1879: J*/
1880: typedef const char *MatPartitioningType;
1881: #define MATPARTITIONINGCURRENT  "current"
1882: #define MATPARTITIONINGAVERAGE  "average"
1883: #define MATPARTITIONINGSQUARE   "square"
1884: #define MATPARTITIONINGPARMETIS "parmetis"
1885: #define MATPARTITIONINGCHACO    "chaco"
1886: #define MATPARTITIONINGPARTY    "party"
1887: #define MATPARTITIONINGPTSCOTCH "ptscotch"
1888: #define MATPARTITIONINGHIERARCH "hierarch"

1890: PETSC_EXTERN PetscErrorCode MatPartitioningCreate(MPI_Comm, MatPartitioning *);
1891: PETSC_EXTERN PetscErrorCode MatPartitioningSetType(MatPartitioning, MatPartitioningType);
1892: PETSC_EXTERN PetscErrorCode MatPartitioningSetNParts(MatPartitioning, PetscInt);
1893: PETSC_EXTERN PetscErrorCode MatPartitioningSetAdjacency(MatPartitioning, Mat);
1894: PETSC_EXTERN PetscErrorCode MatPartitioningSetNumberVertexWeights(MatPartitioning, PetscInt);
1895: PETSC_EXTERN PetscErrorCode MatPartitioningSetVertexWeights(MatPartitioning, const PetscInt[]);
1896: PETSC_EXTERN PetscErrorCode MatPartitioningSetPartitionWeights(MatPartitioning, const PetscReal[]);
1897: PETSC_EXTERN PetscErrorCode MatPartitioningSetUseEdgeWeights(MatPartitioning, PetscBool);
1898: PETSC_EXTERN PetscErrorCode MatPartitioningGetUseEdgeWeights(MatPartitioning, PetscBool *);
1899: PETSC_EXTERN PetscErrorCode MatPartitioningApply(MatPartitioning, IS *);
1900: PETSC_EXTERN PetscErrorCode MatPartitioningImprove(MatPartitioning, IS *);
1901: PETSC_EXTERN PetscErrorCode MatPartitioningViewImbalance(MatPartitioning, IS);
1902: PETSC_EXTERN PetscErrorCode MatPartitioningApplyND(MatPartitioning, IS *);
1903: PETSC_EXTERN PetscErrorCode MatPartitioningDestroy(MatPartitioning *);
1904: PETSC_EXTERN PetscErrorCode MatPartitioningRegister(const char[], PetscErrorCode (*)(MatPartitioning));
1905: PETSC_EXTERN PetscErrorCode MatPartitioningView(MatPartitioning, PetscViewer);
1906: PETSC_EXTERN PetscErrorCode MatPartitioningViewFromOptions(MatPartitioning, PetscObject, const char[]);
1907: PETSC_EXTERN PetscErrorCode MatPartitioningSetFromOptions(MatPartitioning);
1908: PETSC_EXTERN PetscErrorCode MatPartitioningGetType(MatPartitioning, MatPartitioningType *);

1910: PETSC_EXTERN PetscErrorCode MatPartitioningParMETISSetRepartition(MatPartitioning);
1911: PETSC_EXTERN PetscErrorCode MatPartitioningParMETISSetCoarseSequential(MatPartitioning);
1912: PETSC_EXTERN PetscErrorCode MatPartitioningParMETISGetEdgeCut(MatPartitioning, PetscInt *);

1914: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "MatPartitioningParMETISSetRepartition()", ) static inline PetscErrorCode MatPartitioningParmetisSetRepartition(MatPartitioning part)
1915: {
1916:   return MatPartitioningParMETISSetRepartition(part);
1917: }
1918: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "MatPartitioningParMETISSetCoarseSequential()", ) static inline PetscErrorCode MatPartitioningParmetisSetCoarseSequential(MatPartitioning part)
1919: {
1920:   return MatPartitioningParMETISSetCoarseSequential(part);
1921: }
1922: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "MatPartitioningParMETISGetEdgeCut()", ) static inline PetscErrorCode MatPartitioningParmetisGetEdgeCut(MatPartitioning part, PetscInt *cut)
1923: {
1924:   return MatPartitioningParMETISGetEdgeCut(part, cut);
1925: }

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

1930:    Values:
1931: +   `MP_CHACO_MULTILEVEL` - multilevel-Kernighan--Lin style partitioning
1932: .   `MP_CHACO_SPECTRAL`   - spectral partitioning using Lanczos or RQI eigensolvers
1933: .   `MP_CHACO_LINEAR`     - linear (rank-order) initial partition
1934: .   `MP_CHACO_RANDOM`     - random initial partition
1935: -   `MP_CHACO_SCATTERED`  - scattered (round-robin) initial partition

1937:    Level: intermediate

1939: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetGlobal()`, `MatPartitioningChacoGetGlobal()`,
1940:           `MPChacoLocalType`, `MPChacoEigenType`
1941: E*/
1942: typedef enum {
1943:   MP_CHACO_MULTILEVEL = 1,
1944:   MP_CHACO_SPECTRAL   = 2,
1945:   MP_CHACO_LINEAR     = 4,
1946:   MP_CHACO_RANDOM     = 5,
1947:   MP_CHACO_SCATTERED  = 6
1948: } MPChacoGlobalType;
1949: PETSC_EXTERN const char *const MPChacoGlobalTypes[];
1950: /*E
1951:    MPChacoLocalType - Local refinement method used by `MATPARTITIONINGCHACO` after the global partition has been chosen

1953:    Values:
1954: +   `MP_CHACO_KERNIGHAN` - apply Kernighan--Lin local refinement to improve the partition
1955: -   `MP_CHACO_NONE`      - no local refinement

1957:    Level: intermediate

1959: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetLocal()`, `MatPartitioningChacoGetLocal()`,
1960:           `MPChacoGlobalType`
1961: E*/
1962: typedef enum {
1963:   MP_CHACO_KERNIGHAN = 1,
1964:   MP_CHACO_NONE      = 2
1965: } MPChacoLocalType;
1966: PETSC_EXTERN const char *const MPChacoLocalTypes[];
1967: /*E
1968:    MPChacoEigenType - Eigensolver used by `MATPARTITIONINGCHACO` when the global partitioning method is `MP_CHACO_SPECTRAL`

1970:    Values:
1971: +   `MP_CHACO_LANCZOS` - Lanczos algorithm
1972: -   `MP_CHACO_RQI`     - Rayleigh quotient iteration

1974:    Level: intermediate

1976: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenSolver()`, `MatPartitioningChacoGetEigenSolver()`,
1977:           `MPChacoGlobalType`
1978: E*/
1979: typedef enum {
1980:   MP_CHACO_LANCZOS = 0,
1981:   MP_CHACO_RQI     = 1
1982: } MPChacoEigenType;
1983: PETSC_EXTERN const char *const MPChacoEigenTypes[];

1985: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning, MPChacoGlobalType);
1986: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning, MPChacoGlobalType *);
1987: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning, MPChacoLocalType);
1988: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning, MPChacoLocalType *);
1989: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning, PetscReal);
1990: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning, MPChacoEigenType);
1991: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning, MPChacoEigenType *);
1992: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning, PetscReal);
1993: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning, PetscReal *);
1994: PETSC_EXTERN PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning, PetscInt);
1995: PETSC_EXTERN PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning, PetscInt *);

1997: #define MP_PARTY_OPT "opt"
1998: #define MP_PARTY_LIN "lin"
1999: #define MP_PARTY_SCA "sca"
2000: #define MP_PARTY_RAN "ran"
2001: #define MP_PARTY_GBF "gbf"
2002: #define MP_PARTY_GCF "gcf"
2003: #define MP_PARTY_BUB "bub"
2004: #define MP_PARTY_DEF "def"
2005: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetGlobal(MatPartitioning, const char *);
2006: #define MP_PARTY_HELPFUL_SETS  "hs"
2007: #define MP_PARTY_KERNIGHAN_LIN "kl"
2008: #define MP_PARTY_NONE          "no"
2009: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetLocal(MatPartitioning, const char *);
2010: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetCoarseLevel(MatPartitioning, PetscReal);
2011: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetBipart(MatPartitioning, PetscBool);
2012: PETSC_EXTERN PetscErrorCode MatPartitioningPartySetMatchOptimization(MatPartitioning, PetscBool);

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

2017:    Values:
2018: +   `MP_PTSCOTCH_DEFAULT`     - the default PT-Scotch strategy
2019: .   `MP_PTSCOTCH_QUALITY`     - focus on partition quality at the expense of time
2020: .   `MP_PTSCOTCH_SPEED`       - focus on time to compute the partition
2021: .   `MP_PTSCOTCH_BALANCE`     - favor load balance
2022: .   `MP_PTSCOTCH_SAFETY`      - use the most reliable internal heuristics
2023: -   `MP_PTSCOTCH_SCALABILITY` - favor scalability at large process counts

2025:    Level: intermediate

2027: .seealso: [](ch_matrices), `MatPartitioning`, `MATPARTITIONINGPTSCOTCH`, `MatPartitioningPTScotchSetStrategy()`, `MatPartitioningPTScotchGetStrategy()`
2028: E*/
2029: typedef enum {
2030:   MP_PTSCOTCH_DEFAULT,
2031:   MP_PTSCOTCH_QUALITY,
2032:   MP_PTSCOTCH_SPEED,
2033:   MP_PTSCOTCH_BALANCE,
2034:   MP_PTSCOTCH_SAFETY,
2035:   MP_PTSCOTCH_SCALABILITY
2036: } MPPTScotchStrategyType;
2037: PETSC_EXTERN const char *const MPPTScotchStrategyTypes[];

2039: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetImbalance(MatPartitioning, PetscReal);
2040: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetImbalance(MatPartitioning, PetscReal *);
2041: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchSetStrategy(MatPartitioning, MPPTScotchStrategyType);
2042: PETSC_EXTERN PetscErrorCode MatPartitioningPTScotchGetStrategy(MatPartitioning, MPPTScotchStrategyType *);

2044: /*
2045:  * hierarchical partitioning
2046:  */
2047: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetFineparts(MatPartitioning, IS *);
2048: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalGetCoarseparts(MatPartitioning, IS *);
2049: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNcoarseparts(MatPartitioning, PetscInt);
2050: PETSC_EXTERN PetscErrorCode MatPartitioningHierarchicalSetNfineparts(MatPartitioning, PetscInt);

2052: /*J
2053:   MatMeshToCellGraphType - String with the name of registered algorithm that computes a cell graph from a mesh (graph containing
2054:   the coupling of vertices) representation.

2056:   Options Database Key:
2057: . -mat_mesh_to_cell_graph_type (parmetis|metis) - the conversion package to use; default is ParMETIS if available, otherwise METIS

2059:   Level: beginner

2061: .seealso: `Mat`, `MatMeshToCellGraph()`, `MatMeshToCellGraphRegister()`
2062: J*/
2063: typedef const char *MatMeshToCellGraphType;
2064: #define MATMESHTOCELLGRAPHMETIS    "metis"
2065: #define MATMESHTOCELLGRAPHPARMETIS "parmetis"

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

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

2073:    Level: developer

2075:    Notes:
2076:    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.

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

2080: .seealso: [](ch_matrices), `Mat`, `MATSHELL`, `MatSetOperation()`, `MatGetOperation()`, `MatHasOperation()`,
2081:           `MatShellSetOperation()`, `MatShellGetOperation()`
2082: E*/
2083: typedef enum {
2084:   MATOP_SET_VALUES                = 0,
2085:   MATOP_GET_ROW                   = 1,
2086:   MATOP_RESTORE_ROW               = 2,
2087:   MATOP_MULT                      = 3,
2088:   MATOP_MULT_ADD                  = 4,
2089:   MATOP_MULT_TRANSPOSE            = 5,
2090:   MATOP_MULT_TRANSPOSE_ADD        = 6,
2091:   MATOP_SOLVE                     = 7,
2092:   MATOP_SOLVE_ADD                 = 8,
2093:   MATOP_SOLVE_TRANSPOSE           = 9,
2094:   MATOP_SOLVE_TRANSPOSE_ADD       = 10,
2095:   MATOP_LUFACTOR                  = 11,
2096:   MATOP_CHOLESKYFACTOR            = 12,
2097:   MATOP_SOR                       = 13,
2098:   MATOP_TRANSPOSE                 = 14,
2099:   MATOP_GETINFO                   = 15,
2100:   MATOP_EQUAL                     = 16,
2101:   MATOP_GET_DIAGONAL              = 17,
2102:   MATOP_DIAGONAL_SCALE            = 18,
2103:   MATOP_NORM                      = 19,
2104:   MATOP_ASSEMBLY_BEGIN            = 20,
2105:   MATOP_ASSEMBLY_END              = 21,
2106:   MATOP_SET_OPTION                = 22,
2107:   MATOP_ZERO_ENTRIES              = 23,
2108:   MATOP_ZERO_ROWS                 = 24,
2109:   MATOP_LUFACTOR_SYMBOLIC         = 25,
2110:   MATOP_LUFACTOR_NUMERIC          = 26,
2111:   MATOP_CHOLESKY_FACTOR_SYMBOLIC  = 27,
2112:   MATOP_CHOLESKY_FACTOR_NUMERIC   = 28,
2113:   MATOP_SETUP                     = 29,
2114:   MATOP_ILUFACTOR_SYMBOLIC        = 30,
2115:   MATOP_ICCFACTOR_SYMBOLIC        = 31,
2116:   MATOP_GET_DIAGONAL_BLOCK        = 32,
2117:   MATOP_SET_INF                   = 33,
2118:   MATOP_DUPLICATE                 = 34,
2119:   MATOP_FORWARD_SOLVE             = 35,
2120:   MATOP_BACKWARD_SOLVE            = 36,
2121:   MATOP_ILUFACTOR                 = 37,
2122:   MATOP_ICCFACTOR                 = 38,
2123:   MATOP_AXPY                      = 39,
2124:   MATOP_CREATE_SUBMATRICES        = 40,
2125:   MATOP_INCREASE_OVERLAP          = 41,
2126:   MATOP_GET_VALUES                = 42,
2127:   MATOP_COPY                      = 43,
2128:   MATOP_GET_ROW_MAX               = 44,
2129:   MATOP_SCALE                     = 45,
2130:   MATOP_SHIFT                     = 46,
2131:   MATOP_DIAGONAL_SET              = 47,
2132:   MATOP_ZERO_ROWS_COLUMNS         = 48,
2133:   MATOP_SET_RANDOM                = 49,
2134:   MATOP_GET_ROW_IJ                = 50,
2135:   MATOP_RESTORE_ROW_IJ            = 51,
2136:   MATOP_GET_COLUMN_IJ             = 52,
2137:   MATOP_RESTORE_COLUMN_IJ         = 53,
2138:   MATOP_FDCOLORING_CREATE         = 54,
2139:   MATOP_COLORING_PATCH            = 55,
2140:   MATOP_SET_UNFACTORED            = 56,
2141:   MATOP_PERMUTE                   = 57,
2142:   MATOP_SET_VALUES_BLOCKED        = 58,
2143:   MATOP_CREATE_SUBMATRIX          = 59,
2144:   MATOP_DESTROY                   = 60,
2145:   MATOP_VIEW                      = 61,
2146:   MATOP_CONVERT_FROM              = 62,
2147:   MATOP_MATMAT_MULT_SYMBOLIC      = 63,
2148:   MATOP_MATMAT_MULT_NUMERIC       = 64,
2149:   MATOP_SET_LOCAL_TO_GLOBAL_MAP   = 65,
2150:   MATOP_SET_VALUES_LOCAL          = 66,
2151:   MATOP_ZERO_ROWS_LOCAL           = 67,
2152:   MATOP_GET_ROW_MAX_ABS           = 68,
2153:   MATOP_GET_ROW_MIN_ABS           = 69,
2154:   MATOP_CONVERT                   = 70,
2155:   MATOP_HAS_OPERATION             = 71,
2156:   MATOP_FD_COLORING_APPLY         = 72,
2157:   MATOP_SET_FROM_OPTIONS          = 73,
2158:   MATOP_FIND_ZERO_DIAGONALS       = 74,
2159:   MATOP_MULT_MULTIPLE             = 75,
2160:   MATOP_SOLVE_MULTIPLE            = 76,
2161:   MATOP_GET_INERTIA               = 77,
2162:   MATOP_LOAD                      = 78,
2163:   MATOP_IS_SYMMETRIC              = 79,
2164:   MATOP_IS_HERMITIAN              = 80,
2165:   MATOP_IS_STRUCTURALLY_SYMMETRIC = 81,
2166:   MATOP_SET_VALUES_BLOCKEDLOCAL   = 82,
2167:   MATOP_CREATE_VECS               = 83,
2168:   MATOP_MAT_MULT_SYMBOLIC         = 84,
2169:   MATOP_MAT_MULT_NUMERIC          = 85,
2170:   MATOP_PTAP_NUMERIC              = 86,
2171:   MATOP_MAT_TRANSPOSE_MULT_SYMBO  = 87,
2172:   MATOP_MAT_TRANSPOSE_MULT_NUMER  = 88,
2173:   MATOP_BIND_TO_CPU               = 89,
2174:   MATOP_PRODUCTSETFROMOPTIONS     = 90,
2175:   MATOP_PRODUCTSYMBOLIC           = 91,
2176:   MATOP_PRODUCTNUMERIC            = 92,
2177:   MATOP_CONJUGATE                 = 93,
2178:   MATOP_VIEW_NATIVE               = 94,
2179:   MATOP_SET_VALUES_ROW            = 95,
2180:   MATOP_REAL_PART                 = 96,
2181:   MATOP_IMAGINARY_PART            = 97,
2182:   MATOP_GET_ROW_UPPER_TRIANGULAR  = 98,
2183:   MATOP_RESTORE_ROW_UPPER_TRIANG  = 99,
2184:   MATOP_MAT_SOLVE                 = 100,
2185:   MATOP_MAT_SOLVE_TRANSPOSE       = 101,
2186:   MATOP_GET_ROW_MIN               = 102,
2187:   MATOP_GET_COLUMN_VECTOR         = 103,
2188:   MATOP_GET_SEQ_NONZERO_STRUCTUR  = 104,
2189:   MATOP_CREATE                    = 105,
2190:   MATOP_GET_GHOSTS                = 106,
2191:   MATOP_GET_LOCAL_SUB_MATRIX      = 107,
2192:   MATOP_RESTORE_LOCALSUB_MATRIX   = 108,
2193:   MATOP_MULT_DIAGONAL_BLOCK       = 109,
2194:   MATOP_HERMITIAN_TRANSPOSE       = 110,
2195:   MATOP_MULT_HERMITIAN_TRANSPOSE  = 111,
2196:   MATOP_MULT_HERMITIAN_TRANS_ADD  = 112,
2197:   MATOP_GET_MULTI_PROC_BLOCK      = 113,
2198:   MATOP_FIND_NONZERO_ROWS         = 114,
2199:   MATOP_GET_COLUMN_NORMS          = 115,
2200:   MATOP_INVERT_BLOCK_DIAGONAL     = 116,
2201:   MATOP_INVERT_VBLOCK_DIAGONAL    = 117,
2202:   MATOP_CREATE_SUB_MATRICES_MPI   = 118,
2203:   MATOP_TRANSPOSE_MAT_MULT_SYMBO  = 119,
2204:   MATOP_TRANSPOSE_MAT_MULT_NUMER  = 120,
2205:   MATOP_TRANSPOSE_COLORING_CREAT  = 121,
2206:   MATOP_TRANS_COLORING_APPLY_SPT  = 122,
2207:   MATOP_TRANS_COLORING_APPLY_DEN  = 123,
2208:   MATOP_RART_NUMERIC              = 124,
2209:   MATOP_SET_BLOCK_SIZES           = 125,
2210:   MATOP_RESIDUAL                  = 126,
2211:   MATOP_FDCOLORING_SETUP          = 127,
2212:   MATOP_FIND_OFFBLOCK_ENTRIES     = 128,
2213:   MATOP_MPICONCATENATESEQ         = 129,
2214:   MATOP_DESTROYSUBMATRICES        = 130,
2215:   MATOP_MAT_TRANSPOSE_SOLVE       = 131,
2216:   MATOP_GET_VALUES_LOCAL          = 132,
2217:   MATOP_CREATE_GRAPH              = 133,
2218:   MATOP_TRANSPOSE_SYMBOLIC        = 134,
2219:   MATOP_ELIMINATE_ZEROS           = 135,
2220:   MATOP_GET_ROW_SUM_ABS           = 136,
2221:   MATOP_GET_FACTOR                = 137,
2222:   MATOP_GET_BLOCK_DIAGONAL        = 138, /* NOTE: caller of the two op functions owns the returned matrix */
2223:   MATOP_GET_VBLOCK_DIAGONAL       = 139, /* and need to destroy it after use. */
2224:   MATOP_COPY_HASH_TO_XAIJ         = 140,
2225:   MATOP_GET_CURRENT_MEM_TYPE      = 141,
2226:   MATOP_ZERO_ROWS_COLUMNS_LOCAL   = 142,
2227:   MATOP_ADOT                      = 143,
2228:   MATOP_ANORM                     = 144,
2229:   MATOP_ADOT_LOCAL                = 145,
2230:   MATOP_ANORM_LOCAL               = 146,
2231:   MATOP_GET_ORDERING              = 147
2232: } MatOperation;

2234: PETSC_EXTERN PetscErrorCode MatSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2235: PETSC_EXTERN PetscErrorCode MatGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2236: PETSC_EXTERN PetscErrorCode MatHasOperation(Mat, MatOperation, PetscBool *);
2237: PETSC_EXTERN PetscErrorCode MatHasCongruentLayouts(Mat, PetscBool *);
2238: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "MatProductClear()", ) static inline PetscErrorCode MatFreeIntermediateDataStructures(Mat A)
2239: {
2240:   return MatProductClear(A);
2241: }
2242: PETSC_EXTERN PetscErrorCode MatShellSetOperation(Mat, MatOperation, PetscErrorCodeFn *);
2243: PETSC_EXTERN PetscErrorCode MatShellGetOperation(Mat, MatOperation, PetscErrorCodeFn **);
2244: PETSC_EXTERN PetscErrorCode MatShellSetContext(Mat, PetscCtx);
2245: PETSC_EXTERN PetscErrorCode MatShellSetContextDestroy(Mat, PetscCtxDestroyFn *);
2246: PETSC_EXTERN PetscErrorCode MatShellSetVecType(Mat, VecType);
2247: PETSC_EXTERN PetscErrorCode MatShellTestMult(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2248: PETSC_EXTERN PetscErrorCode MatShellTestMultTranspose(Mat, PetscErrorCode (*)(void *, Vec, Vec), Vec, void *, PetscBool *);
2249: PETSC_EXTERN PetscErrorCode MatShellSetManageScalingShifts(Mat);
2250: PETSC_EXTERN PetscErrorCode MatShellSetMatProductOperation(Mat, MatProductType, PetscErrorCode (*)(Mat, Mat, Mat, void **), PetscErrorCode (*)(Mat, Mat, Mat, void *), PetscCtxDestroyFn *, MatType, MatType);
2251: PETSC_EXTERN PetscErrorCode MatIsShell(Mat, PetscBool *);

2253: /*
2254:    Codes for matrices stored on disk. By default they are
2255:    stored in a universal format. By changing the format with
2256:    PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE); the matrices will
2257:    be stored in a way natural for the matrix, for example dense matrices
2258:    would be stored as dense. Matrices stored this way may only be
2259:    read into matrices of the same type.
2260: */
2261: #define MATRIX_BINARY_FORMAT_DENSE -1

2263: PETSC_EXTERN PetscErrorCode MatMPIBAIJSetHashTableFactor(Mat, PetscReal);

2265: PETSC_EXTERN PetscErrorCode MatISSetLocalMatType(Mat, MatType);
2266: PETSC_EXTERN PetscErrorCode MatISSetPreallocation(Mat, PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
2267: PETSC_EXTERN PetscErrorCode MatISSetAllowRepeated(Mat, PetscBool);
2268: PETSC_EXTERN PetscErrorCode MatISGetAllowRepeated(Mat, PetscBool *);
2269: PETSC_EXTERN PetscErrorCode MatISStoreL2L(Mat, PetscBool);
2270: PETSC_EXTERN PetscErrorCode MatISFixLocalEmpty(Mat, PetscBool);
2271: PETSC_EXTERN PetscErrorCode MatISGetLocalMat(Mat, Mat *);
2272: PETSC_EXTERN PetscErrorCode MatISRestoreLocalMat(Mat, Mat *);
2273: PETSC_EXTERN PetscErrorCode MatISSetLocalMat(Mat, Mat);
2274: PETSC_EXTERN PetscErrorCode MatISGetLocalToGlobalMapping(Mat, ISLocalToGlobalMapping *, ISLocalToGlobalMapping *);

2276: /*S
2277:    MatNullSpace - Object that removes a null space from a vector, i.e.
2278:                   orthogonalizes the vector to a subspace

2280:    Level: advanced

2282: .seealso: [](ch_matrices), `Mat`, `MatNullSpaceCreate()`, `MatNullSpaceSetFunction()`, `MatGetNullSpace()`, `MatSetNullSpace()`
2283: S*/
2284: typedef struct _p_MatNullSpace *MatNullSpace;

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

2289:   Level: advanced

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

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

2300: PETSC_EXTERN PetscErrorCode MatNullSpaceCreate(MPI_Comm, PetscBool, PetscInt, const Vec[], MatNullSpace *);
2301: PETSC_EXTERN PetscErrorCode MatNullSpaceSetFunction(MatNullSpace, MatNullSpaceRemoveFn *, void *);
2302: PETSC_EXTERN PetscErrorCode MatNullSpaceDestroy(MatNullSpace *);
2303: PETSC_EXTERN PetscErrorCode MatNullSpaceRemove(MatNullSpace, Vec);
2304: PETSC_EXTERN PetscErrorCode MatGetNullSpace(Mat, MatNullSpace *);
2305: PETSC_EXTERN PetscErrorCode MatGetTransposeNullSpace(Mat, MatNullSpace *);
2306: PETSC_EXTERN PetscErrorCode MatSetTransposeNullSpace(Mat, MatNullSpace);
2307: PETSC_EXTERN PetscErrorCode MatSetNullSpace(Mat, MatNullSpace);
2308: PETSC_EXTERN PetscErrorCode MatSetNearNullSpace(Mat, MatNullSpace);
2309: PETSC_EXTERN PetscErrorCode MatGetNearNullSpace(Mat, MatNullSpace *);
2310: PETSC_EXTERN PetscErrorCode MatGetNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2311: PETSC_EXTERN PetscErrorCode MatRestoreNullSpaces(PetscInt, Mat[], MatNullSpace *[]);
2312: PETSC_EXTERN PetscErrorCode MatNullSpaceTest(MatNullSpace, Mat, PetscBool *);
2313: PETSC_EXTERN PetscErrorCode MatNullSpaceView(MatNullSpace, PetscViewer);
2314: PETSC_EXTERN PetscErrorCode MatNullSpaceLoad(PetscViewer, MatNullSpace *);
2315: PETSC_EXTERN PetscErrorCode MatNullSpaceGetVecs(MatNullSpace, PetscBool *, PetscInt *, const Vec **);
2316: PETSC_EXTERN PetscErrorCode MatNullSpaceCreateRigidBody(Vec, MatNullSpace *);

2318: PETSC_EXTERN PetscErrorCode MatReorderingSeqSBAIJ(Mat, IS);
2319: PETSC_EXTERN PetscErrorCode MatSeqSBAIJSetColumnIndices(Mat, PetscInt *);

2321: PETSC_EXTERN PetscErrorCode MatCreateMAIJ(Mat, PetscInt, Mat *);
2322: PETSC_EXTERN PetscErrorCode MatMAIJRedimension(Mat, PetscInt, Mat *);
2323: PETSC_EXTERN PetscErrorCode MatMAIJGetAIJ(Mat, Mat *);

2325: PETSC_EXTERN PetscErrorCode MatComputeOperator(Mat, MatType, Mat *);
2326: PETSC_EXTERN PetscErrorCode MatComputeOperatorTranspose(Mat, MatType, Mat *);

2328: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperator()", ) static inline PetscErrorCode MatComputeExplicitOperator(Mat A, Mat *B)
2329: {
2330:   return MatComputeOperator(A, PETSC_NULLPTR, B);
2331: }
2332: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "MatComputeOperatorTranspose()", ) static inline PetscErrorCode MatComputeExplicitOperatorTranspose(Mat A, Mat *B)
2333: {
2334:   return MatComputeOperatorTranspose(A, PETSC_NULLPTR, B);
2335: }

2337: PETSC_EXTERN PetscErrorCode MatCreateKAIJ(Mat, PetscInt, PetscInt, const PetscScalar[], const PetscScalar[], Mat *);
2338: PETSC_EXTERN PetscErrorCode MatCreateKAIJAB(Mat, Mat, PetscInt, PetscInt, const PetscScalar[], const PetscScalar[], Mat *);
2339: PETSC_EXTERN PetscErrorCode MatKAIJGetA(Mat, Mat *);
2340: PETSC_EXTERN PetscErrorCode MatKAIJGetB(Mat, Mat *);
2341: PETSC_EXTERN PetscErrorCode MatKAIJGetS(Mat, PetscInt *, PetscInt *, PetscScalar **);
2342: PETSC_EXTERN PetscErrorCode MatKAIJGetSRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2343: PETSC_EXTERN PetscErrorCode MatKAIJRestoreS(Mat, PetscScalar **);
2344: PETSC_EXTERN PetscErrorCode MatKAIJRestoreSRead(Mat, const PetscScalar **);
2345: PETSC_EXTERN PetscErrorCode MatKAIJGetT(Mat, PetscInt *, PetscInt *, PetscScalar **);
2346: PETSC_EXTERN PetscErrorCode MatKAIJGetTRead(Mat, PetscInt *, PetscInt *, const PetscScalar **);
2347: PETSC_EXTERN PetscErrorCode MatKAIJRestoreT(Mat, PetscScalar **);
2348: PETSC_EXTERN PetscErrorCode MatKAIJRestoreTRead(Mat, const PetscScalar **);
2349: PETSC_EXTERN PetscErrorCode MatKAIJSetA(Mat, Mat);
2350: PETSC_EXTERN PetscErrorCode MatKAIJSetB(Mat, Mat);
2351: PETSC_EXTERN PetscErrorCode MatKAIJSetS(Mat, PetscInt, PetscInt, const PetscScalar[]);
2352: PETSC_EXTERN PetscErrorCode MatKAIJSetT(Mat, PetscInt, PetscInt, const PetscScalar[]);
2353: PETSC_EXTERN PetscErrorCode MatKAIJGetScaledIdentity(Mat, PetscBool *);

2355: PETSC_DEPRECATED_FUNCTION(3, 27, 0, "MatKAIJGetA()", ) static inline PetscErrorCode MatKAIJGetAIJ(Mat A, Mat *a)
2356: {
2357:   return MatKAIJGetA(A, a);
2358: }
2359: PETSC_DEPRECATED_FUNCTION(3, 27, 0, "MatKAIJSetA()", ) static inline PetscErrorCode MatKAIJSetAIJ(Mat A, Mat a)
2360: {
2361:   return MatKAIJSetA(A, a);
2362: }

2364: PETSC_EXTERN PetscErrorCode MatDiagonalScaleLocal(Mat, Vec);

2366: PETSC_EXTERN PetscErrorCode MatMFFDInitializePackage(void);
2367: PETSC_EXTERN PetscErrorCode MatMFFDFinalizePackage(void);

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

2372:   Level: advanced

2374:   Calling Sequence:
2375: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2376: . x   - input vector
2377: - y   - output vector

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

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

2386:   Level: advanced

2388:   Calling Sequence:
2389: + ctx    - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2390: . i      - the component of the vector to compute
2391: . x      - input vector
2392: - result - the value of the function at that component (output)

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

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

2402:   Level: advanced

2404:   Calling Sequence:
2405: + ctx - [optional] user-defined function context provided with `MatMFFDSetFunction()`
2406: - x   - input base vector

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

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

2416:   Level: advanced

2418:   Calling Sequence:
2419: + ctx - [optional] user-defined function context provided with `MatMFFDSetCheckh()`
2420: . x   - input base vector
2421: . y   - input step vector that the product is computed with
2422: - h   - input tentative step, output possibly adjusted step

2424:   Note:
2425:   `MatMFFDCheckPositivity()` is one such function

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

2431: PETSC_EXTERN PetscErrorCode MatCreateMFFD(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2432: PETSC_EXTERN PetscErrorCode MatMFFDSetBase(Mat, Vec, Vec);
2433: PETSC_EXTERN PetscErrorCode MatMFFDSetFunction(Mat, MatMFFDFn *, void *);
2434: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioni(Mat, MatMFFDiFn *);
2435: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctioniBase(Mat, MatMFFDiBaseFn *);
2436: PETSC_EXTERN PetscErrorCode MatMFFDSetHHistory(Mat, PetscScalar[], PetscInt);
2437: PETSC_EXTERN PetscErrorCode MatMFFDResetHHistory(Mat);
2438: PETSC_EXTERN PetscErrorCode MatMFFDSetFunctionError(Mat, PetscReal);
2439: PETSC_EXTERN PetscErrorCode MatMFFDSetPeriod(Mat, PetscInt);
2440: PETSC_EXTERN PetscErrorCode MatMFFDGetH(Mat, PetscScalar *);
2441: PETSC_EXTERN PetscErrorCode MatMFFDSetOptionsPrefix(Mat, const char[]);
2442: PETSC_EXTERN PetscErrorCode MatMFFDCheckPositivity(void *, Vec, Vec, PetscScalar *);
2443: PETSC_EXTERN PetscErrorCode MatMFFDSetCheckh(Mat, MatMFFDCheckhFn *, void *);

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

2449:     Level: developer

2451:     Notes:
2452:     `MATMFFD` is a specific `MatType` which uses the `MatMFFD` data structure

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

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

2458: .seealso: [](ch_matrices), `MatMFFDType`, `MATMFFD`, `MatCreateMFFD()`, `MatMFFDSetFuction()`, `MatMFFDSetType()`, `MatMFFDRegister()`,
2459:           `MatCreateSNESMF()`, `SNES`, `-snes_mf`, `-snes_mf_operator`
2460: S*/
2461: typedef struct _p_MatMFFD *MatMFFD;

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

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

2470:    Level: beginner

2472: .seealso: [](ch_matrices), `MatMFFDSetType()`, `MatMFFDRegister()`, `MatMFFDSetFunction()`, `MatCreateMFFD()`
2473: J*/
2474: typedef const char *MatMFFDType;
2475: #define MATMFFD_DS "ds"
2476: #define MATMFFD_WP "wp"

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

2481: PETSC_EXTERN PetscErrorCode MatMFFDDSSetUmin(Mat, PetscReal);
2482: PETSC_EXTERN PetscErrorCode MatMFFDWPSetComputeNormU(Mat, PetscBool);

2484: PETSC_EXTERN PetscErrorCode MatFDColoringSetType(MatFDColoring, MatMFFDType);

2486: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutMatrix(PetscViewer, PetscInt, PetscInt, PetscReal *);
2487: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutCSRMatrix(PetscViewer, PetscInt, PetscInt, PetscInt *, PetscInt *, PetscReal *);

2489: #if PetscDefined(HAVE_H2OPUS)
2490: /*S
2491:   MatH2OpusKernelFn - Function type for the user-supplied kernel callback used by `MATH2OPUS` (see `MatCreateH2OpusFromKernel()`)
2492:   to evaluate the dense matrix entries on demand

2494:   Synopsis:
2495: #include <petscmat.h>
2496:   PetscScalar MatH2OpusKernelFn(PetscInt spacedim, PetscReal target[], PetscReal source[], PetscCtx ctx)

2498:   Calling Sequence:
2499: + spacedim - spatial dimension, either 1, 2, or 3
2500: . target   - spatial coordinate of the target point, its length is `spacedim`
2501: . source   - spatial coordinate of the source point, its length is `spacedim`
2502: - ctx      - the optional application context passed with `MatCreateH2OpusFromKernel()`

2504:   Level: intermediate

2506:   Note:
2507:   Returns the matrix entry coupling the target and source points

2509: .seealso: `Mat`, `MATH2OPUS`, `MATHTOOL`, `MatCreateH2OpusFromKernel()`
2510: S*/
2511: PETSC_EXTERN_TYPEDEF typedef PetscScalar MatH2OpusKernelFn(PetscInt spacedim, PetscReal target[], PetscReal source[], PetscCtx ctx);

2513: PETSC_EXTERN_TYPEDEF typedef MatH2OpusKernelFn *MatH2OpusKernel PETSC_DEPRECATED_TYPEDEF(3, 26, 0, "MatH2OpusKernelFn*", );

2515: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], PetscBool, MatH2OpusKernelFn *, PetscCtx, PetscReal, PetscInt, PetscInt, Mat *);
2516: PETSC_EXTERN PetscErrorCode MatCreateH2OpusFromMat(Mat, PetscInt, const PetscReal[], PetscBool, PetscReal, PetscInt, PetscInt, PetscInt, PetscReal, Mat *);
2517: PETSC_EXTERN PetscErrorCode MatH2OpusSetSamplingMat(Mat, Mat, PetscInt, PetscReal);
2518: PETSC_EXTERN PetscErrorCode MatH2OpusOrthogonalize(Mat);
2519: PETSC_EXTERN PetscErrorCode MatH2OpusCompress(Mat, PetscReal);
2520: PETSC_EXTERN PetscErrorCode MatH2OpusSetNativeMult(Mat, PetscBool);
2521: PETSC_EXTERN PetscErrorCode MatH2OpusGetNativeMult(Mat, PetscBool *);
2522: PETSC_EXTERN PetscErrorCode MatH2OpusGetIndexMap(Mat, IS *);
2523: PETSC_EXTERN PetscErrorCode MatH2OpusMapVec(Mat, PetscBool, Vec, Vec *);
2524: PETSC_EXTERN PetscErrorCode MatH2OpusLowRankUpdate(Mat, Mat, Mat, PetscScalar);
2525: #endif

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

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

2534:   Calling Sequence:
2535: + sdim - the spatial dimension of the source/target geometries
2536: . M    - the number of target points
2537: . N    - the number of source points
2538: . J    - array of `M` target point indices into the user's target coordinate array
2539: . K    - array of `N` source point indices into the user's source coordinate array
2540: . ptr  - column-major output buffer of length `M*N` to fill with kernel values
2541: - ctx  - the optional application context passed at registration

2543:   Level: intermediate

2545: .seealso: `Mat`, `MATHTOOL`, `MatCreateHtoolFromKernel()`, `MatHtoolSetKernel()`
2546: S*/
2547: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode    MatHtoolKernelFn(PetscInt, PetscInt, PetscInt, const PetscInt *, const PetscInt *, PetscScalar *, void *);
2548: PETSC_EXTERN_TYPEDEF typedef MatHtoolKernelFn *MatHtoolKernel PETSC_DEPRECATED_TYPEDEF(3, 26, 0, "MatHtoolKernelFn*", );

2550: PETSC_EXTERN PetscErrorCode MatCreateHtoolFromKernel(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscReal[], const PetscReal[], MatHtoolKernelFn *, void *, Mat *);
2551: PETSC_EXTERN PetscErrorCode MatHtoolSetKernel(Mat, MatHtoolKernelFn *, void *);
2552: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationSource(Mat, IS *);
2553: PETSC_EXTERN PetscErrorCode MatHtoolGetPermutationTarget(Mat, IS *);
2554: PETSC_EXTERN PetscErrorCode MatHtoolUsePermutation(Mat, PetscBool);
2555: PETSC_EXTERN PetscErrorCode MatHtoolUseRecompression(Mat, PetscBool);
2556: PETSC_EXTERN PetscErrorCode MatHtoolGetEpsilon(Mat, PetscReal *);
2557: PETSC_EXTERN PetscErrorCode MatHtoolSetEpsilon(Mat, PetscReal);
2558: PETSC_EXTERN PetscErrorCode MatHtoolGetEta(Mat, PetscReal *);
2559: PETSC_EXTERN PetscErrorCode MatHtoolSetEta(Mat, PetscReal);
2560: PETSC_EXTERN PetscErrorCode MatHtoolGetMaxClusterLeafSize(Mat, PetscInt *);
2561: PETSC_EXTERN PetscErrorCode MatHtoolSetMaxClusterLeafSize(Mat, PetscInt);
2562: PETSC_EXTERN PetscErrorCode MatHtoolGetMinTargetDepth(Mat, PetscInt *);
2563: PETSC_EXTERN PetscErrorCode MatHtoolSetMinTargetDepth(Mat, PetscInt);
2564: PETSC_EXTERN PetscErrorCode MatHtoolGetMinSourceDepth(Mat, PetscInt *);
2565: PETSC_EXTERN PetscErrorCode MatHtoolSetMinSourceDepth(Mat, PetscInt);
2566: PETSC_EXTERN PetscErrorCode MatHtoolGetBlockTreeConsistency(Mat, PetscBool *);
2567: PETSC_EXTERN PetscErrorCode MatHtoolSetBlockTreeConsistency(Mat, PetscBool);

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

2572:    Values:
2573: +  `MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA` (default) - symmetric partial adaptive cross approximation
2574: .  `MAT_HTOOL_COMPRESSOR_FULL_ACA`                 - full adaptive cross approximation
2575: -  `MAT_HTOOL_COMPRESSOR_SVD`                      - singular value decomposition

2577:    Level: intermediate

2579: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolClusteringType`, `MatHtoolGetCompressorType()`, `MatHtoolSetCompressorType()`
2580: E*/
2581: typedef enum {
2582:   MAT_HTOOL_COMPRESSOR_SYMPARTIAL_ACA,
2583:   MAT_HTOOL_COMPRESSOR_FULL_ACA,
2584:   MAT_HTOOL_COMPRESSOR_SVD
2585: } MatHtoolCompressorType;

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

2590:    Values:
2591: +  `MAT_HTOOL_CLUSTERING_PCA_REGULAR` (default)    - axis computed via principle component analysis, split uniformly
2592: .  `MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC`            - axis computed via principle component analysis, split barycentrically
2593: .  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR`   - axis along the largest extent of the bounding box, split uniformly
2594: -  `MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC` - axis along the largest extent of the bounding box, split barycentrically

2596:    Level: intermediate

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

2601: .seealso: [](ch_matrices), `Mat`, `MatCreateHtoolFromKernel()`, `MATHTOOL`, `MatHtoolCompressorType`, `MatHtoolGetClusteringType()`, `MatHtoolSetClusteringType()`
2602: E*/
2603: typedef enum {
2604:   MAT_HTOOL_CLUSTERING_PCA_REGULAR,
2605:   MAT_HTOOL_CLUSTERING_PCA_GEOMETRIC,
2606:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_REGULAR,
2607:   MAT_HTOOL_CLUSTERING_BOUNDING_BOX_1_GEOMETRIC
2608: } MatHtoolClusteringType;
2609: PETSC_EXTERN PetscErrorCode MatHtoolGetCompressorType(Mat, MatHtoolCompressorType *);
2610: PETSC_EXTERN PetscErrorCode MatHtoolSetCompressorType(Mat, MatHtoolCompressorType);
2611: PETSC_EXTERN PetscErrorCode MatHtoolGetClusteringType(Mat, MatHtoolClusteringType *);
2612: PETSC_EXTERN PetscErrorCode MatHtoolSetClusteringType(Mat, MatHtoolClusteringType);

2614: PETSC_EXTERN PetscErrorCode MatMumpsSetIcntl(Mat, PetscInt, PetscInt);
2615: PETSC_EXTERN PetscErrorCode MatMumpsGetIcntl(Mat, PetscInt, PetscInt *);
2616: PETSC_EXTERN PetscErrorCode MatMumpsSetCntl(Mat, PetscInt, PetscReal);
2617: PETSC_EXTERN PetscErrorCode MatMumpsGetCntl(Mat, PetscInt, PetscReal *);

2619: PETSC_EXTERN PetscErrorCode MatMumpsGetInfo(Mat, PetscInt, PetscInt *);
2620: PETSC_EXTERN PetscErrorCode MatMumpsGetInfog(Mat, PetscInt, PetscInt *);
2621: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfo(Mat, PetscInt, PetscReal *);
2622: PETSC_EXTERN PetscErrorCode MatMumpsGetRinfog(Mat, PetscInt, PetscReal *);
2623: PETSC_EXTERN PetscErrorCode MatMumpsGetNullPivots(Mat, PetscInt *, PetscInt **);
2624: PETSC_EXTERN PetscErrorCode MatMumpsGetInverse(Mat, Mat);
2625: PETSC_EXTERN PetscErrorCode MatMumpsGetInverseTranspose(Mat, Mat);
2626: PETSC_EXTERN PetscErrorCode MatMumpsSetBlk(Mat, PetscInt, const PetscInt[], const PetscInt[]);

2628: PETSC_EXTERN PetscErrorCode MatMumpsSetOocTmpDir(Mat, const char *);
2629: PETSC_EXTERN PetscErrorCode MatMumpsGetOocTmpDir(Mat, const char *[]);

2631: #if PetscDefined(HAVE_MKL_PARDISO)
2632: PETSC_EXTERN PetscErrorCode MatMkl_PardisoSetCntl(Mat, PetscInt, PetscInt);
2633: #endif

2635: #if PetscDefined(HAVE_MKL_CPARDISO)
2636: PETSC_EXTERN PetscErrorCode MatMkl_CPardisoSetCntl(Mat, PetscInt, PetscInt);
2637: #endif

2639: #if PetscDefined(HAVE_SUPERLU)
2640: PETSC_EXTERN PetscErrorCode MatSuperluSetILUDropTol(Mat, PetscReal);
2641: #endif

2643: #if PetscDefined(HAVE_SUPERLU_DIST)
2644: PETSC_EXTERN PetscErrorCode MatSuperluDistGetDiagU(Mat, PetscScalar *);
2645: #endif

2647: /*E
2648:     MatSTRUMPACKReordering - sparsity reducing ordering to be used in `MATSOLVERSTRUMPACK`

2650:     Values:
2651: +  `MAT_STRUMPACK_NATURAL`   - use the current ordering
2652: .  `MAT_STRUMPACK_METIS`     - use MeTis to compute an ordering
2653: .  `MAT_STRUMPACK_PARMETIS`  - use ParMeTis to compute an ordering
2654: .  `MAT_STRUMPACK_SCOTCH`    - use Scotch to compute an ordering
2655: .  `MAT_STRUMPACK_PTSCOTCH`  - use parallel Scotch to compute an ordering
2656: .  `MAT_STRUMPACK_RCM`       - use an RCM ordering
2657: .  `MAT_STRUMPACK_GEOMETRIC` - use a geometric ordering (needs mesh info from user)
2658: .  `MAT_STRUMPACK_AMD`       - approximate minimum degree
2659: .  `MAT_STRUMPACK_MMD`       - multiple minimum degree
2660: .  `MAT_STRUMPACK_AND`       - approximate nested dissection
2661: .  `MAT_STRUMPACK_MLF`       - minimum local fill
2662: -  `MAT_STRUMPACK_SPECTRAL`  - spectral nested dissection

2664:     Level: intermediate

2666:     Developer Note:
2667:     Should be called `MatSTRUMPACKReorderingType`

2669: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetReordering()`
2670: E*/
2671: typedef enum {
2672:   MAT_STRUMPACK_NATURAL,
2673:   MAT_STRUMPACK_METIS,
2674:   MAT_STRUMPACK_PARMETIS,
2675:   MAT_STRUMPACK_SCOTCH,
2676:   MAT_STRUMPACK_PTSCOTCH,
2677:   MAT_STRUMPACK_RCM,
2678:   MAT_STRUMPACK_GEOMETRIC,
2679:   MAT_STRUMPACK_AMD,
2680:   MAT_STRUMPACK_MMD,
2681:   MAT_STRUMPACK_AND,
2682:   MAT_STRUMPACK_MLF,
2683:   MAT_STRUMPACK_SPECTRAL
2684: } MatSTRUMPACKReordering;
2685: PETSC_EXTERN const char *const MatSTRUMPACKReorderingTypes[];

2687: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetReordering(Mat, MatSTRUMPACKReordering);
2688: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetReordering(Mat, MatSTRUMPACKReordering *);
2689: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricNxyz(Mat, PetscInt, PetscInt, PetscInt);
2690: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricComponents(Mat, PetscInt);
2691: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGeometricWidth(Mat, PetscInt);
2692: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetColPerm(Mat, PetscBool);
2693: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetColPerm(Mat, PetscBool *);
2694: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetGPU(Mat, PetscBool);
2695: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetGPU(Mat, PetscBool *);

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

2700:     Values:
2701: +  `MAT_STRUMPACK_COMPRESSION_TYPE_NONE`          - no compression, direct solver
2702: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HSS`           - hierarchically semi-separable
2703: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR`           - block low rank
2704: .  `MAT_STRUMPACK_COMPRESSION_TYPE_HODLR`         - hierarchically off-diagonal low rank (requires ButterflyPACK support, configure with `--download-butterflypack`)
2705: .  `MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR`     - hybrid of BLR and HODLR (requires ButterflyPACK support, configure with `--download-butterflypack`)
2706: .  `MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR` - hybrid of lossy (ZFP), BLR and HODLR (requires ButterflyPACK and ZFP support, configure with `--download-butterflypack --download-zfp`)
2707: .  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS`      - lossless compression (requires ZFP support, configure with `--download-zfp`)
2708: -  `MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY`         - lossy compression (requires ZFP support, configure with `--download-zfp`)

2710:     Level: intermediate

2712: .seealso: `Mat`, `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompression()`
2713: E*/
2714: typedef enum {
2715:   MAT_STRUMPACK_COMPRESSION_TYPE_NONE,
2716:   MAT_STRUMPACK_COMPRESSION_TYPE_HSS,
2717:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR,
2718:   MAT_STRUMPACK_COMPRESSION_TYPE_HODLR,
2719:   MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR,
2720:   MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR,
2721:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS,
2722:   MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY
2723: } MatSTRUMPACKCompressionType;
2724: PETSC_EXTERN const char *const MatSTRUMPACKCompressionTypes[];

2726: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompression(Mat, MatSTRUMPACKCompressionType);
2727: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompression(Mat, MatSTRUMPACKCompressionType *);
2728: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompRelTol(Mat, PetscReal);
2729: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompRelTol(Mat, PetscReal *);
2730: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompAbsTol(Mat, PetscReal);
2731: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompAbsTol(Mat, PetscReal *);
2732: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompMinSepSize(Mat, PetscInt);
2733: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompMinSepSize(Mat, PetscInt *);
2734: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLeafSize(Mat, PetscInt);
2735: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLeafSize(Mat, PetscInt *);
2736: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompLossyPrecision(Mat, PetscInt);
2737: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompLossyPrecision(Mat, PetscInt *);
2738: PETSC_EXTERN PetscErrorCode MatSTRUMPACKSetCompButterflyLevels(Mat, PetscInt);
2739: PETSC_EXTERN PetscErrorCode MatSTRUMPACKGetCompButterflyLevels(Mat, PetscInt *);

2741: PETSC_EXTERN PetscErrorCode MatBindToCPU(Mat, PetscBool);
2742: PETSC_EXTERN PetscErrorCode MatBoundToCPU(Mat, PetscBool *);
2743: PETSC_DEPRECATED_FUNCTION(3, 13, 0, "MatBindToCPU()", ) static inline PetscErrorCode MatPinToCPU(Mat A, PetscBool flg)
2744: {
2745:   return MatBindToCPU(A, flg);
2746: }
2747: PETSC_EXTERN PetscErrorCode MatSetBindingPropagates(Mat, PetscBool);
2748: PETSC_EXTERN PetscErrorCode MatGetBindingPropagates(Mat, PetscBool *);

2750: #if PetscDefined(HAVE_CUDA)
2751: /*E
2752:     MatCUSPARSEStorageFormat - indicates the storage format for `MATAIJCUSPARSE` (GPU)
2753:     matrices.

2755:     Values:
2756: +   `MAT_CUSPARSE_CSR` - Compressed Sparse Row
2757: .   `MAT_CUSPARSE_ELL` - Ellpack (requires CUDA 4.2 or later).
2758: -   `MAT_CUSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format (requires CUDA 4.2 or later).

2760:     Level: intermediate

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

2765: typedef enum {
2766:   MAT_CUSPARSE_CSR,
2767:   MAT_CUSPARSE_ELL,
2768:   MAT_CUSPARSE_HYB
2769: } MatCUSPARSEStorageFormat;

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

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

2778:     Values:
2779: +   `MAT_CUSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2780: .   `MAT_CUSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2781: .   `MAT_CUSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2782: -   `MAT_CUSPARSE_ALL`          - sets the storage format for all `MATAIJCUSPARSE` (GPU) matrices

2784:     Level: intermediate

2786: .seealso: [](ch_matrices), `MatCUSPARSESetFormat()`, `MatCUSPARSEStorageFormat`
2787: E*/
2788: typedef enum {
2789:   MAT_CUSPARSE_MULT_DIAG,
2790:   MAT_CUSPARSE_MULT_OFFDIAG,
2791:   MAT_CUSPARSE_MULT,
2792:   MAT_CUSPARSE_ALL
2793: } MatCUSPARSEFormatOperation;

2795: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2796: PETSC_EXTERN PetscErrorCode MatCreateAIJCUSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2797: PETSC_EXTERN PetscErrorCode MatCUSPARSESetFormat(Mat, MatCUSPARSEFormatOperation, MatCUSPARSEStorageFormat);
2798: PETSC_EXTERN PetscErrorCode MatCUSPARSESetUseCPUSolve(Mat, PetscBool);
2799: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2800: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2801: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayRead(Mat, const PetscScalar **);
2802: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayRead(Mat, const PetscScalar **);
2803: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArrayWrite(Mat, PetscScalar **);
2804: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArrayWrite(Mat, PetscScalar **);
2805: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSEGetArray(Mat, PetscScalar **);
2806: PETSC_EXTERN PetscErrorCode MatSeqAIJCUSPARSERestoreArray(Mat, PetscScalar **);

2808: PETSC_EXTERN PetscErrorCode MatCreateDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2809: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseCUDA(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2810: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayWrite(Mat, PetscScalar **);
2811: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArrayRead(Mat, const PetscScalar **);
2812: PETSC_EXTERN PetscErrorCode MatDenseCUDAGetArray(Mat, PetscScalar **);
2813: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayWrite(Mat, PetscScalar **);
2814: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArrayRead(Mat, const PetscScalar **);
2815: PETSC_EXTERN PetscErrorCode MatDenseCUDARestoreArray(Mat, PetscScalar **);
2816: PETSC_EXTERN PetscErrorCode MatDenseCUDAPlaceArray(Mat, const PetscScalar *);
2817: PETSC_EXTERN PetscErrorCode MatDenseCUDAReplaceArray(Mat, const PetscScalar *);
2818: PETSC_EXTERN PetscErrorCode MatDenseCUDAResetArray(Mat);
2819: PETSC_EXTERN PetscErrorCode MatDenseCUDASetPreallocation(Mat, PetscScalar *);

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

2824: #if PetscDefined(HAVE_HIP)
2825: /*E
2826:     MatHIPSPARSEStorageFormat - indicates the storage format for `MATAIJHIPSPARSE` (GPU)
2827:     matrices.

2829:     Values:
2830: +   `MAT_HIPSPARSE_CSR` - Compressed Sparse Row
2831: .   `MAT_HIPSPARSE_ELL` - Ellpack
2832: -   `MAT_HIPSPARSE_HYB` - Hybrid, a combination of Ellpack and Coordinate format

2834:     Level: intermediate

2836: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEFormatOperation`
2837: E*/

2839: typedef enum {
2840:   MAT_HIPSPARSE_CSR,
2841:   MAT_HIPSPARSE_ELL,
2842:   MAT_HIPSPARSE_HYB
2843: } MatHIPSPARSEStorageFormat;

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

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

2852:     Values:
2853: +   `MAT_HIPSPARSE_MULT_DIAG`    - sets the storage format for the diagonal matrix in the parallel `MatMult()`
2854: .   `MAT_HIPSPARSE_MULT_OFFDIAG` - sets the storage format for the off-diagonal matrix in the parallel `MatMult()`
2855: .   `MAT_HIPSPARSE_MULT`         - sets the storage format for the entire matrix in the serial (single GPU) `MatMult()`
2856: -   `MAT_HIPSPARSE_ALL`          - sets the storage format for all HIPSPARSE (GPU) matrices

2858:     Level: intermediate

2860: .seealso: [](ch_matrices), `MatHIPSPARSESetFormat()`, `MatHIPSPARSEStorageFormat`
2861: E*/
2862: typedef enum {
2863:   MAT_HIPSPARSE_MULT_DIAG,
2864:   MAT_HIPSPARSE_MULT_OFFDIAG,
2865:   MAT_HIPSPARSE_MULT,
2866:   MAT_HIPSPARSE_ALL
2867: } MatHIPSPARSEFormatOperation;

2869: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2870: PETSC_EXTERN PetscErrorCode MatCreateAIJHIPSPARSE(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2871: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetFormat(Mat, MatHIPSPARSEFormatOperation, MatHIPSPARSEStorageFormat);
2872: PETSC_EXTERN PetscErrorCode MatHIPSPARSESetUseCPUSolve(Mat, PetscBool);
2873: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2874: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreIJ(Mat, PetscBool, const PetscInt *[], const PetscInt *[]);
2875: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayRead(Mat, const PetscScalar **);
2876: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayRead(Mat, const PetscScalar **);
2877: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArrayWrite(Mat, PetscScalar **);
2878: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArrayWrite(Mat, PetscScalar **);
2879: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSEGetArray(Mat, PetscScalar **);
2880: PETSC_EXTERN PetscErrorCode MatSeqAIJHIPSPARSERestoreArray(Mat, PetscScalar **);

2882: PETSC_EXTERN PetscErrorCode MatCreateDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar[], Mat *);
2883: PETSC_EXTERN PetscErrorCode MatCreateSeqDenseHIP(MPI_Comm, PetscInt, PetscInt, PetscScalar[], Mat *);
2884: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayWrite(Mat, PetscScalar **);
2885: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArrayRead(Mat, const PetscScalar **);
2886: PETSC_EXTERN PetscErrorCode MatDenseHIPGetArray(Mat, PetscScalar **);
2887: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayWrite(Mat, PetscScalar **);
2888: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArrayRead(Mat, const PetscScalar **);
2889: PETSC_EXTERN PetscErrorCode MatDenseHIPRestoreArray(Mat, PetscScalar **);
2890: PETSC_EXTERN PetscErrorCode MatDenseHIPPlaceArray(Mat, const PetscScalar *);
2891: PETSC_EXTERN PetscErrorCode MatDenseHIPReplaceArray(Mat, const PetscScalar *);
2892: PETSC_EXTERN PetscErrorCode MatDenseHIPResetArray(Mat);
2893: PETSC_EXTERN PetscErrorCode MatDenseHIPSetPreallocation(Mat, PetscScalar *);
2894: PETSC_EXTERN PetscErrorCode MatCreateSELLHIP(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2895: #endif

2897: #if PetscDefined(HAVE_VIENNACL)
2898: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2899: PETSC_EXTERN PetscErrorCode MatCreateAIJViennaCL(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2900: #endif

2902: #if PetscDefined(HAVE_KOKKOS)
2903: PETSC_EXTERN PetscErrorCode MatCreateAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], PetscInt, const PetscInt[], Mat *);
2904: PETSC_EXTERN PetscErrorCode MatCreateSeqAIJKokkos(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Mat *);
2905: #endif

2907: #if PetscDefined(HAVE_FFTW)
2908: PETSC_EXTERN PetscErrorCode VecScatterPetscToFFTW(Mat, Vec, Vec);
2909: PETSC_EXTERN PetscErrorCode VecScatterFFTWToPetsc(Mat, Vec, Vec);
2910: PETSC_EXTERN PetscErrorCode MatCreateVecsFFTW(Mat, Vec *, Vec *, Vec *);
2911: #endif

2913: #if PetscDefined(HAVE_SCALAPACK) && (PetscDefined(USE_REAL_SINGLE) || PetscDefined(USE_REAL_DOUBLE))
2914: PETSC_EXTERN PetscErrorCode MatCreateScaLAPACK(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, Mat *);
2915: PETSC_EXTERN PetscErrorCode MatScaLAPACKSetBlockSizes(Mat, PetscInt, PetscInt);
2916: PETSC_EXTERN PetscErrorCode MatScaLAPACKGetBlockSizes(Mat, PetscInt *, PetscInt *);
2917: #endif

2919: PETSC_EXTERN PetscErrorCode MatCreateNest(MPI_Comm, PetscInt, const IS[], PetscInt, const IS[], const Mat[], Mat *);
2920: PETSC_EXTERN PetscErrorCode MatNestGetSize(Mat, PetscInt *, PetscInt *);
2921: PETSC_EXTERN PetscErrorCode MatNestGetISs(Mat, IS[], IS[]);
2922: PETSC_EXTERN PetscErrorCode MatNestGetLocalISs(Mat, IS[], IS[]);
2923: PETSC_EXTERN PetscErrorCode MatNestGetSubMats(Mat, PetscInt *, PetscInt *, Mat ***);
2924: PETSC_EXTERN PetscErrorCode MatNestGetSubMat(Mat, PetscInt, PetscInt, Mat *);
2925: PETSC_EXTERN PetscErrorCode MatNestSetVecType(Mat, VecType);
2926: PETSC_EXTERN PetscErrorCode MatNestSetSubMats(Mat, PetscInt, const IS[], PetscInt, const IS[], const Mat[]);
2927: PETSC_EXTERN PetscErrorCode MatNestSetSubMat(Mat, PetscInt, PetscInt, Mat);

2929: PETSC_EXTERN PetscErrorCode MatCreateNestFromMultipleShifts(Mat, PetscInt, const PetscScalar[], const PetscScalar[], Mat, PetscBool, MatStructure, Mat *);
2930: PETSC_EXTERN PetscErrorCode MatCreateVecNestFromMultipleShifts(Mat, Vec, Vec *);

2932: PETSC_EXTERN PetscErrorCode MatFilter(Mat, PetscReal, PetscBool, PetscBool);
2933: PETSC_DEPRECATED_FUNCTION(3, 20, 0, "MatFilter()", ) static inline PetscErrorCode MatChop(Mat A, PetscReal tol)
2934: {
2935:   return MatFilter(A, tol, PETSC_FALSE, PETSC_FALSE);
2936: }
2937: PETSC_EXTERN PetscErrorCode MatComputeBandwidth(Mat, PetscReal, PetscInt *);

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

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

2943: PETSC_EXTERN PetscErrorCode MatHeaderMerge(Mat, Mat *);
2944: PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat, Mat *);

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

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

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

2954: PETSC_EXTERN PetscErrorCode MatSetHPL(Mat, int);
2955: #define PETSCBMHPL "hpl"

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