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