xref: /petsc/include/petscsystypes.h (revision b2ccae6bdc8edea944f1c160ca3b2eb32c69ecb2)
1 /* Portions of this code are under:
2    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
3 */
4 
5 #pragma once
6 
7 #include <petscconf.h>
8 #include <petscconf_poison.h>
9 #include <petscfix.h>
10 #include <petscmacros.h> // PETSC_NODISCARD, PETSC_CPP_VERSION
11 #include <stddef.h>
12 #include <stdbool.h>
13 
14 /* SUBMANSEC = Sys */
15 
16 #include <limits.h> // INT_MIN, INT_MAX, CHAR_BIT
17 
18 #if defined(__clang__) || (PETSC_CPP_VERSION >= 17)
19   // clang allows both [[nodiscard]] and __attribute__((warn_unused_result)) on type
20   // definitions. GCC, however, does not, so check that we are using C++17 [[nodiscard]]
21   // instead of __attribute__((warn_unused_result))
22   #define PETSC_ERROR_CODE_NODISCARD PETSC_NODISCARD
23 #else
24   #define PETSC_ERROR_CODE_NODISCARD
25 #endif
26 
27 #ifdef PETSC_CLANG_STATIC_ANALYZER
28   #undef PETSC_USE_STRICT_PETSCERRORCODE
29 #endif
30 
31 #ifdef PETSC_USE_STRICT_PETSCERRORCODE
32   #define PETSC_ERROR_CODE_TYPEDEF   typedef
33   #define PETSC_ERROR_CODE_ENUM_NAME PetscErrorCode
34 #else
35   #define PETSC_ERROR_CODE_TYPEDEF
36   #define PETSC_ERROR_CODE_ENUM_NAME
37 #endif
38 
39 /*E
40   PetscErrorCode - Datatype used to return PETSc error codes.
41 
42   Level: beginner
43 
44   Notes:
45   Virtually all PETSc functions return an error code. It is the callers responsibility to check
46   the value of the returned error code after each PETSc call to determine if any errors
47   occurred. A set of convenience macros (e.g. `PetscCall()`, `PetscCallVoid()`) are provided
48   for this purpose. Failing to properly check for errors is not supported, as errors may leave
49   PETSc in an undetermined state.
50 
51   One can retrieve the error string corresponding to a particular error code using
52   `PetscErrorMessage()`.
53 
54   The user can also configure PETSc with the `--with-strict-petscerrorcode` option to enable
55   compiler warnings when the returned error codes are not captured and checked. Users are
56   *heavily* encouraged to opt-in to this option, as it will become enabled by default in a
57   future release.
58 
59   Developer Notes:
60   These are the generic error codes. These error codes are used in many different places in the
61   PETSc source code. The C-string versions are at defined in `PetscErrorStrings[]` in
62   `src/sys/error/err.c`, while the Fortran versions are defined in
63   `src/sys/ftn-mod/petscerror.h`. Any changes here must also be made in both locations.
64 
65 .seealso: `PetscErrorMessage()`, `PetscCall()`, `SETERRQ()`
66 E*/
67 PETSC_ERROR_CODE_TYPEDEF enum PETSC_ERROR_CODE_NODISCARD {
68   PETSC_SUCCESS                   = 0,
69   PETSC_ERR_BOOLEAN_MACRO_FAILURE = 1, /* do not use */
70 
71   PETSC_ERR_MIN_VALUE = 54, /* should always be one less than the smallest value */
72 
73   PETSC_ERR_MEM            = 55, /* unable to allocate requested memory */
74   PETSC_ERR_SUP            = 56, /* no support for requested operation */
75   PETSC_ERR_SUP_SYS        = 57, /* no support for requested operation on this computer system */
76   PETSC_ERR_ORDER          = 58, /* operation done in wrong order */
77   PETSC_ERR_SIG            = 59, /* signal received */
78   PETSC_ERR_FP             = 72, /* floating point exception */
79   PETSC_ERR_COR            = 74, /* corrupted PETSc object */
80   PETSC_ERR_LIB            = 76, /* error in library called by PETSc */
81   PETSC_ERR_PLIB           = 77, /* PETSc library generated inconsistent data */
82   PETSC_ERR_MEMC           = 78, /* memory corruption */
83   PETSC_ERR_CONV_FAILED    = 82, /* iterative method (KSP or SNES) failed */
84   PETSC_ERR_USER           = 83, /* user has not provided needed function */
85   PETSC_ERR_SYS            = 88, /* error in system call */
86   PETSC_ERR_POINTER        = 70, /* pointer does not point to valid address */
87   PETSC_ERR_MPI_LIB_INCOMP = 87, /* MPI library at runtime is not compatible with MPI user compiled with */
88 
89   PETSC_ERR_ARG_SIZ          = 60, /* nonconforming object sizes used in operation */
90   PETSC_ERR_ARG_IDN          = 61, /* two arguments not allowed to be the same */
91   PETSC_ERR_ARG_WRONG        = 62, /* wrong argument (but object probably ok) */
92   PETSC_ERR_ARG_CORRUPT      = 64, /* null or corrupted PETSc object as argument */
93   PETSC_ERR_ARG_OUTOFRANGE   = 63, /* input argument, out of range */
94   PETSC_ERR_ARG_BADPTR       = 68, /* invalid pointer argument */
95   PETSC_ERR_ARG_NOTSAMETYPE  = 69, /* two args must be same object type */
96   PETSC_ERR_ARG_NOTSAMECOMM  = 80, /* two args must be same communicators */
97   PETSC_ERR_ARG_WRONGSTATE   = 73, /* object in argument is in wrong state, e.g. unassembled mat */
98   PETSC_ERR_ARG_TYPENOTSET   = 89, /* the type of the object has not yet been set */
99   PETSC_ERR_ARG_INCOMP       = 75, /* two arguments are incompatible */
100   PETSC_ERR_ARG_NULL         = 85, /* argument is null that should not be */
101   PETSC_ERR_ARG_UNKNOWN_TYPE = 86, /* type name doesn't match any registered type */
102 
103   PETSC_ERR_FILE_OPEN       = 65, /* unable to open file */
104   PETSC_ERR_FILE_READ       = 66, /* unable to read from file */
105   PETSC_ERR_FILE_WRITE      = 67, /* unable to write to file */
106   PETSC_ERR_FILE_UNEXPECTED = 79, /* unexpected data in file */
107 
108   PETSC_ERR_MAT_LU_ZRPVT = 71, /* detected a zero pivot during LU factorization */
109   PETSC_ERR_MAT_CH_ZRPVT = 81, /* detected a zero pivot during Cholesky factorization */
110 
111   PETSC_ERR_INT_OVERFLOW   = 84,
112   PETSC_ERR_FLOP_COUNT     = 90,
113   PETSC_ERR_NOT_CONVERGED  = 91,  /* solver did not converge */
114   PETSC_ERR_MISSING_FACTOR = 92,  /* MatGetFactor() failed */
115   PETSC_ERR_OPT_OVERWRITE  = 93,  /* attempted to over write options which should not be changed */
116   PETSC_ERR_WRONG_MPI_SIZE = 94,  /* example/application run with number of MPI ranks it does not support */
117   PETSC_ERR_USER_INPUT     = 95,  /* missing or incorrect user input */
118   PETSC_ERR_GPU_RESOURCE   = 96,  /* unable to load a GPU resource, for example cuBLAS */
119   PETSC_ERR_GPU            = 97,  /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */
120   PETSC_ERR_MPI            = 98,  /* general MPI error */
121   PETSC_ERR_RETURN         = 99,  /* PetscError() incorrectly returned an error code of 0 */
122   PETSC_ERR_MEM_LEAK       = 100, /* memory alloc/free imbalance */
123   PETSC_ERR_PYTHON         = 101, /* Exception in Python */
124   PETSC_ERR_MAX_VALUE      = 102, /* this is always the one more than the largest error code */
125 
126   /*
127     do not use, exist purely to make the enum bounds equal that of a regular int (so conversion
128     to int in main() is not undefined behavior)
129   */
130   PETSC_ERR_MIN_SIGNED_BOUND_DO_NOT_USE = INT_MIN,
131   PETSC_ERR_MAX_SIGNED_BOUND_DO_NOT_USE = INT_MAX
132 } PETSC_ERROR_CODE_ENUM_NAME;
133 
134 #ifndef PETSC_USE_STRICT_PETSCERRORCODE
135 typedef int PetscErrorCode;
136 
137   /*
138   Needed so that C++ lambdas can deduce the return type as PetscErrorCode from
139   PetscFunctionReturn(PETSC_SUCCESS). Otherwise we get
140 
141   error: return type '(unnamed enum at include/petscsystypes.h:50:1)' must match previous
142   return type 'int' when lambda expression has unspecified explicit return type
143   PetscFunctionReturn(PETSC_SUCCESS);
144   ^
145 */
146   #define PETSC_SUCCESS ((PetscErrorCode)0)
147 #endif
148 
149 #undef PETSC_ERROR_CODE_NODISCARD
150 #undef PETSC_ERROR_CODE_TYPEDEF
151 #undef PETSC_ERROR_CODE_ENUM_NAME
152 
153 /*MC
154     PetscClassId - A unique id used to identify each PETSc class.
155 
156     Level: developer
157 
158     Note:
159     Use `PetscClassIdRegister()` to obtain a new value for a new class being created. Usually
160     XXXInitializePackage() calls it for each class it defines.
161 
162     Developer Note:
163     Internal integer stored in the `_p_PetscObject` data structure. These are all computed by an offset from the lowest one, `PETSC_SMALLEST_CLASSID`.
164 
165 .seealso: `PetscClassIdRegister()`, `PetscLogEventRegister()`, `PetscHeaderCreate()`
166 M*/
167 typedef int PetscClassId;
168 
169 /*MC
170     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
171 
172     Level: intermediate
173 
174     Notes:
175     This is always a 32-bit integer, sometimes it is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
176     standard C/Fortran integers are 32-bit then this is NOT the same as `PetscInt`; it remains 32-bit.
177 
178     `PetscMPIIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscMPIInt`, if not it
179     generates a `PETSC_ERR_ARG_OUTOFRANGE` error.
180 
181 .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscInt`, `PetscMPIIntCast()`
182 M*/
183 typedef int PetscMPIInt;
184 
185 /* Limit MPI to 32-bits */
186 enum {
187   PETSC_MPI_INT_MIN = INT_MIN,
188   PETSC_MPI_INT_MAX = INT_MAX
189 };
190 
191 /*MC
192     PetscSizeT - datatype used to represent sizes in memory (like `size_t`)
193 
194     Level: intermediate
195 
196     Notes:
197     This is equivalent to `size_t`, but defined for consistency with Fortran, which lacks a native equivalent of `size_t`.
198 
199 .seealso: `PetscInt`, `PetscInt64`, `PetscCount`
200 M*/
201 typedef size_t PetscSizeT;
202 
203 /*MC
204     PetscCount - signed datatype used to represent counts
205 
206     Level: intermediate
207 
208     Notes:
209     This is equivalent to `ptrdiff_t`, but defined for consistency with Fortran, which lacks a native equivalent of `ptrdiff_t`.
210 
211     Use `PetscCount_FMT` to format with `PetscPrintf()`, `printf()`, and related functions.
212 
213 .seealso: [](stylePetscCount), `PetscInt`, `PetscInt64`, `PetscSizeT`
214 M*/
215 typedef ptrdiff_t PetscCount;
216 #define PetscCount_FMT "td"
217 
218 /*MC
219     PetscEnum - datatype used to pass enum types within PETSc functions.
220 
221     Level: intermediate
222 
223 .seealso: `PetscOptionsGetEnum()`, `PetscOptionsEnum()`, `PetscBagRegisterEnum()`
224 M*/
225 typedef enum {
226   ENUM_DUMMY
227 } PetscEnum;
228 
229 typedef short PetscShort;
230 typedef float PetscFloat;
231 
232 /*MC
233   PetscInt - PETSc type that represents an integer, used primarily to
234              represent size of arrays and indexing into arrays. Its size can be configured with the option `--with-64-bit-indices` to be either 32-bit (default) or 64-bit.
235 
236   Level: beginner
237 
238   Notes:
239   For MPI calls that require datatypes, use `MPIU_INT` as the datatype for `PetscInt`. It will automatically work correctly regardless of the size of `PetscInt`.
240 
241 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscIntCast()`
242 M*/
243 
244 #if defined(PETSC_HAVE_STDINT_H)
245   #include <stdint.h>
246 #endif
247 #if defined(PETSC_HAVE_INTTYPES_H)
248   #if !defined(__STDC_FORMAT_MACROS)
249     #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
250   #endif
251   #include <inttypes.h>
252   #if !defined(PRId64)
253     #define PRId64 "ld"
254   #endif
255 #endif
256 
257 #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && (defined(PETSC_HAVE_MPIUNI) || defined(PETSC_HAVE_MPI_INT64_T)) /* MPI_INT64_T is not guaranteed to be a macro */
258 typedef int64_t PetscInt64;
259 
260   #define PETSC_INT64_MIN INT64_MIN
261   #define PETSC_INT64_MAX INT64_MAX
262 
263 #elif (PETSC_SIZEOF_LONG_LONG == 8)
264 typedef long long PetscInt64;
265 
266   #define PETSC_INT64_MIN LLONG_MIN
267   #define PETSC_INT64_MAX LLONG_MAX
268 
269 #elif defined(PETSC_HAVE___INT64)
270 typedef __int64 PetscInt64;
271 
272   #define PETSC_INT64_MIN INT64_MIN
273   #define PETSC_INT64_MAX INT64_MAX
274 
275 #else
276   #error "cannot determine PetscInt64 type"
277 #endif
278 
279 #if PETSC_SIZEOF_SIZE_T == 4
280   #define PETSC_COUNT_MIN INT_MIN
281   #define PETSC_COUNT_MAX INT_MAX
282 #else
283   #define PETSC_COUNT_MIN PETSC_INT64_MIN
284   #define PETSC_COUNT_MAX PETSC_INT64_MAX
285 #endif
286 
287 typedef int32_t PetscInt32;
288 #define PETSC_INT32_MIN INT32_MIN
289 #define PETSC_INT32_MAX INT32_MAX
290 
291 #if defined(PETSC_USE_64BIT_INDICES)
292 typedef PetscInt64 PetscInt;
293 
294   #define PETSC_INT_MIN PETSC_INT64_MIN
295   #define PETSC_INT_MAX PETSC_INT64_MAX
296   #define PetscInt_FMT  PetscInt64_FMT
297 #else
298 typedef int PetscInt;
299 
300 enum {
301   PETSC_INT_MIN = INT_MIN,
302   PETSC_INT_MAX = INT_MAX
303 };
304   #define PetscInt_FMT "d"
305 #endif
306 
307 #define PETSC_UINT16_MAX 65535
308 
309 /* deprecated */
310 #define PETSC_MIN_INT    PETSC_INT_MIN
311 #define PETSC_MAX_INT    PETSC_INT_MAX
312 #define PETSC_MAX_UINT16 PETSC_UINT16_MAX
313 
314 #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && (defined(PETSC_HAVE_MPIUNI) || defined(PETSC_HAVE_MPI_INT64_T)) /* MPI_INT64_T is not guaranteed to be a macro */
315   #define MPIU_INT64     MPI_INT64_T
316   #define PetscInt64_FMT PRId64
317 #elif (PETSC_SIZEOF_LONG_LONG == 8)
318   #define MPIU_INT64     MPI_LONG_LONG_INT
319   #define PetscInt64_FMT "lld"
320 #elif defined(PETSC_HAVE___INT64)
321   #define MPIU_INT64     MPI_INT64_T
322   #define PetscInt64_FMT "ld"
323 #else
324   #error "cannot determine PetscInt64 type"
325 #endif
326 
327 #define MPIU_INT32     MPI_INT32_T
328 #define PetscInt32_FMT PRId32
329 
330 /*MC
331    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
332 
333    Level: intermediate
334 
335    Notes:
336    Usually this is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
337    standard C/Fortran integers are 32-bit then this may not be the same as `PetscInt`,
338    except on some BLAS/LAPACK implementations that support 64-bit integers see the notes below.
339 
340    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
341     generates a `PETSC_ERR_ARG_OUTOFRANGE` error
342 
343    Installation Notes\:
344    ./configure automatically determines the size of the integers used by BLAS/LAPACK except when `--with-batch` is used
345    in that situation one must know (by some other means) if the integers used by BLAS/LAPACK are 64-bit and if so pass the flag `--known-64-bit-blas-indices`
346 
347    MATLAB ships with BLAS and LAPACK that use 64-bit integers, for example if you run ./configure with, the option
348     `--with-blaslapack-lib`=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
349 
350    MKL ships with both 32 and 64-bit integer versions of the BLAS and LAPACK. If you pass the flag `-with-64-bit-blas-indices` PETSc will link
351    against the 64-bit version, otherwise it uses the 32-bit version
352 
353    OpenBLAS can be built to use 64-bit integers. The ./configure options `--download-openblas` `-with-64-bit-blas-indices` will build a 64-bit integer version
354 
355    External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64-bit integers to BLAS/LAPACK so cannot
356    be used with PETSc when PETSc links against 64-bit integer BLAS/LAPACK. ./configure will generate an error if you attempt to link PETSc against any of
357    these external libraries while using 64-bit integer BLAS/LAPACK.
358 
359 .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
360 M*/
361 #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
362 typedef PetscInt64 PetscBLASInt;
363 
364   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
365   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
366   #define PetscBLASInt_FMT   PetscInt64_FMT
367 #else
368 typedef int PetscBLASInt;
369 
370 enum {
371   PETSC_BLAS_INT_MIN = INT_MIN,
372   PETSC_BLAS_INT_MAX = INT_MAX
373 };
374 
375   #define PetscBLASInt_FMT "d"
376 #endif
377 
378 /*MC
379    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
380 
381    Level: intermediate
382 
383    Notes:
384    As of this writing `PetscCuBLASInt` is always the system `int`.
385 
386   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
387    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
388 
389 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
390 M*/
391 typedef int PetscCuBLASInt;
392 
393 enum {
394   PETSC_CUBLAS_INT_MIN = INT_MIN,
395   PETSC_CUBLAS_INT_MAX = INT_MAX
396 };
397 
398 /*MC
399    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
400 
401    Level: intermediate
402 
403    Notes:
404    `PetscHipBLASInt` is always the system `int`.
405 
406    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
407    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
408 
409 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscHipBLASIntCast()`
410 M*/
411 typedef int PetscHipBLASInt;
412 
413 enum {
414   PETSC_HIPBLAS_INT_MIN = INT_MIN,
415   PETSC_HIPBLAS_INT_MAX = INT_MAX
416 };
417 
418 /*MC
419    PetscExodusIIInt - datatype used to represent 'int' parameters to ExodusII functions.
420 
421    Level: intermediate
422 
423    Notes:
424    This is the same as `int`
425 
426 .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIFloat`, `PetscBLASIntCast()`
427 M*/
428 typedef int PetscExodusIIInt;
429 #define PetscExodusIIInt_FMT "d"
430 
431 /*MC
432    PetscExodusIIFloat - datatype used to represent 'float' parameters to ExodusII functions.
433 
434    Level: intermediate
435 
436    Notes:
437    This is the same as `float`
438 
439 .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIInt`, `PetscBLASIntCast()`
440 M*/
441 typedef float PetscExodusIIFloat;
442 
443 /*E
444    PetscBool  - Logical variable.
445 
446    Level: beginner
447 
448    Notes:
449    This is a C bool.
450 
451    Use `MPI_C_BOOL` for communicating with MPI calls in C, C++, and Fortran.
452 
453    Fortran Note:
454    This is a `logical(C_BOOL)`.
455 
456    Developer Note:
457    We should deprecate this definition since there is a native representation in all the languages.
458 
459 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
460 E*/
461 typedef bool PetscBool;
462 #define PETSC_FALSE false
463 #define PETSC_TRUE  true
464 PETSC_EXTERN const char *const PetscBools[];
465 
466 /*E
467    PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
468 
469    Level: beginner
470 
471    Note:
472    Should not be used with the if (flg) or if (!flg) syntax.
473 
474 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
475 E*/
476 typedef enum {
477   PETSC_BOOL3_FALSE   = 0,
478   PETSC_BOOL3_TRUE    = 1,
479   PETSC_BOOL3_UNKNOWN = -1 /* the value is unknown at the time of query, but might be determined later */
480 } PetscBool3;
481 PETSC_EXTERN const char *const PetscBool3s[];
482 
483 #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
484 #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
485 
486 /*MC
487    PetscReal - PETSc type that represents a real number version of `PetscScalar`
488 
489    Level: beginner
490 
491    Notes:
492    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
493    They will automatically work correctly regardless of the size of `PetscReal`.
494 
495    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
496 
497 .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
498 M*/
499 
500 #if defined(PETSC_USE_REAL_SINGLE)
501 typedef float PetscReal;
502 #elif defined(PETSC_USE_REAL_DOUBLE)
503 typedef double PetscReal;
504 #elif defined(PETSC_USE_REAL___FLOAT128)
505   #if defined(__cplusplus)
506 extern "C" {
507   #endif
508   #include <quadmath.h>
509   #if defined(__cplusplus)
510 }
511   #endif
512 typedef __float128 PetscReal;
513 #elif defined(PETSC_USE_REAL___FP16)
514 typedef __fp16 PetscReal;
515 #endif /* PETSC_USE_REAL_* */
516 
517 /*MC
518    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
519 
520    Synopsis:
521    #include <petscsys.h>
522    PetscComplex number = 1. + 2.*PETSC_i;
523 
524    Level: beginner
525 
526    Notes:
527    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
528    They will automatically work correctly regardless of the size of `PetscComplex`.
529 
530    See `PetscScalar` for details on how to ./configure the size of `PetscReal`
531 
532    Complex numbers are automatically available if PETSc was able to find a working complex implementation
533 
534     PETSc has a 'fix' for complex numbers to support expressions such as `std::complex<PetscReal>` + `PetscInt`, which are not supported by the standard
535     C++ library, but are convenient for PETSc users. If the C++ compiler is able to compile code in `petsccxxcomplexfix.h` (This is checked by
536     configure), we include `petsccxxcomplexfix.h` to provide this convenience.
537 
538     If the fix causes conflicts, or one really does not want this fix for a particular C++ file, one can define `PETSC_SKIP_CXX_COMPLEX_FIX`
539     at the beginning of the C++ file to skip the fix.
540 
541 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
542 M*/
543 #if !defined(PETSC_SKIP_COMPLEX)
544   #if defined(PETSC_CLANGUAGE_CXX)
545     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
546       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
547         #define PETSC_HAVE_COMPLEX 1
548       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
549         #define PETSC_HAVE_COMPLEX 1
550       #endif
551     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
552       #define PETSC_HAVE_COMPLEX 1
553     #endif
554   #else /* !PETSC_CLANGUAGE_CXX */
555     #if !defined(PETSC_USE_REAL___FP16)
556       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
557         #define PETSC_HAVE_COMPLEX 1
558       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
559         #define PETSC_HAVE_COMPLEX 1
560       #endif
561     #endif
562   #endif /* PETSC_CLANGUAGE_CXX */
563 #endif   /* !PETSC_SKIP_COMPLEX */
564 
565 #if defined(PETSC_HAVE_COMPLEX)
566   #if defined(__cplusplus) /* C++ complex support */
567     /* Locate a C++ complex template library */
568     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
569       #define petsccomplexlib Kokkos
570       #include <Kokkos_Complex.hpp>
571     #elif (defined(__CUDACC__) && defined(PETSC_HAVE_CUDA)) || (defined(__HIPCC__) && defined(PETSC_HAVE_HIP))
572       #define petsccomplexlib thrust
573       #include <thrust/complex.h>
574     #elif defined(PETSC_USE_REAL___FLOAT128)
575       #include <complex.h>
576     #else
577       #define petsccomplexlib std
578       #include <complex>
579     #endif
580 
581     /* Define PetscComplex based on the precision */
582     #if defined(PETSC_USE_REAL_SINGLE)
583 typedef petsccomplexlib::complex<float> PetscComplex;
584     #elif defined(PETSC_USE_REAL_DOUBLE)
585 typedef petsccomplexlib::complex<double> PetscComplex;
586     #elif defined(PETSC_USE_REAL___FLOAT128)
587 typedef __complex128 PetscComplex;
588     #endif
589 
590     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
591     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
592       #include <petsccxxcomplexfix.h>
593     #endif
594   #else /* c99 complex support */
595     #include <complex.h>
596     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
597 typedef float _Complex PetscComplex;
598     #elif defined(PETSC_USE_REAL_DOUBLE)
599 typedef double _Complex PetscComplex;
600     #elif defined(PETSC_USE_REAL___FLOAT128)
601 typedef __complex128 PetscComplex;
602     #endif /* PETSC_USE_REAL_* */
603   #endif   /* !__cplusplus */
604 #endif     /* PETSC_HAVE_COMPLEX */
605 
606 /*MC
607    PetscScalar - PETSc type that represents either a double precision real number, a double precision
608                  complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
609                  with `--with-scalar-type`=real,complex `--with-precision`=single,double,__float128,__fp16
610 
611    Level: beginner
612 
613    Note:
614    For MPI calls that require datatypes, use `MPIU_SCALAR` as the datatype for `PetscScalar` and `MPIU_SUM`, etc for operations. They will automatically work correctly regardless of the size of `PetscScalar`.
615 
616 .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
617 M*/
618 
619 #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
620 typedef PetscComplex PetscScalar;
621 #else  /* PETSC_USE_COMPLEX */
622 typedef PetscReal PetscScalar;
623 #endif /* PETSC_USE_COMPLEX */
624 
625 /*E
626     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
627 
628    Values for array input:
629 +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
630 .   `PETSC_OWN_POINTER` - the array values are NOT copied, the object takes ownership of the array and will free it later, the user cannot change or
631                           delete the array. The array MUST have been obtained with `PetscMalloc()`. Hence this mode cannot be used in Fortran.
632 -   `PETSC_USE_POINTER` - the array values are NOT copied, the object uses the array but does NOT take ownership of the array. The user cannot use
633                           the array but the user must delete the array after the object is destroyed.
634 
635    Values for PetscObject:
636 +   `PETSC_COPY_VALUES` - the input `PetscObject` is cloned into the aggregate `PetscObject`; the user is free to reuse/modify the input `PetscObject` without side effects.
637 .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
638                           increases its reference count).
639 -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
640 
641    Level: beginner
642 
643 .seealso: `PetscInsertMode`
644 E*/
645 typedef enum {
646   PETSC_COPY_VALUES,
647   PETSC_OWN_POINTER,
648   PETSC_USE_POINTER
649 } PetscCopyMode;
650 PETSC_EXTERN const char *const PetscCopyModes[];
651 
652 /*MC
653     PETSC_FALSE - False value of `PetscBool`
654 
655     Level: beginner
656 
657     Note:
658     Zero integer
659 
660 .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
661 M*/
662 
663 /*MC
664     PETSC_TRUE - True value of `PetscBool`
665 
666     Level: beginner
667 
668     Note:
669     Nonzero integer
670 
671 .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
672 M*/
673 
674 /*MC
675     PetscLogDouble - Used for logging times
676 
677   Level: developer
678 
679   Note:
680   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
681 
682 .seealso: `PetscBool`, `PetscDataType`
683 M*/
684 typedef double PetscLogDouble;
685 
686 /*E
687     PetscDataType - Used for handling different basic data types.
688 
689    Level: beginner
690 
691    Notes:
692    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
693 
694    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
695    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
696 
697    Developer Notes:
698    It would be nice if we could always just use MPI Datatypes, why can we not?
699 
700    If you change any values in `PetscDatatype` make sure you update their usage in
701    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
702 
703    TODO:
704    Remove use of improper `PETSC_ENUM`
705 
706 .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
707           `PetscDataTypeGetSize()`
708 E*/
709 typedef enum {
710   PETSC_DATATYPE_UNKNOWN = 0,
711   PETSC_DOUBLE           = 1,
712   PETSC_COMPLEX          = 2,
713   PETSC_LONG             = 3,
714   PETSC_SHORT            = 4,
715   PETSC_FLOAT            = 5,
716   PETSC_CHAR             = 6,
717   PETSC_BIT_LOGICAL      = 7,
718   PETSC_ENUM             = 8,
719   PETSC_BOOL             = 9,
720   PETSC___FLOAT128       = 10,
721   PETSC_OBJECT           = 11,
722   PETSC_FUNCTION         = 12,
723   PETSC_STRING           = 13,
724   PETSC___FP16           = 14,
725   PETSC_STRUCT           = 15,
726   PETSC_INT              = 16,
727   PETSC_INT64            = 17,
728   PETSC_COUNT            = 18,
729   PETSC_INT32            = 19,
730 } PetscDataType;
731 PETSC_EXTERN const char *const PetscDataTypes[];
732 
733 #if defined(PETSC_USE_REAL_SINGLE)
734   #define PETSC_REAL PETSC_FLOAT
735 #elif defined(PETSC_USE_REAL_DOUBLE)
736   #define PETSC_REAL PETSC_DOUBLE
737 #elif defined(PETSC_USE_REAL___FLOAT128)
738   #define PETSC_REAL PETSC___FLOAT128
739 #elif defined(PETSC_USE_REAL___FP16)
740   #define PETSC_REAL PETSC___FP16
741 #else
742   #define PETSC_REAL PETSC_DOUBLE
743 #endif
744 
745 #if defined(PETSC_USE_COMPLEX)
746   #define PETSC_SCALAR PETSC_COMPLEX
747 #else
748   #define PETSC_SCALAR PETSC_REAL
749 #endif
750 
751 #define PETSC_FORTRANADDR PETSC_LONG
752 
753 /*S
754   PetscToken - 'Token' used for managing tokenizing strings
755 
756   Level: intermediate
757 
758 .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
759 S*/
760 typedef struct _n_PetscToken *PetscToken;
761 
762 /*S
763    PetscObject - any PETSc object, for example: `PetscViewer`, `Mat`, `Vec`, `KSP`, `DM`
764 
765    Level: beginner
766 
767    Notes:
768    This is the base class from which all PETSc objects are derived.
769 
770    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
771 
772 .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
773 S*/
774 typedef struct _p_PetscObject *PetscObject;
775 
776 /*MC
777     PetscObjectId - unique integer Id for a `PetscObject`
778 
779     Level: developer
780 
781     Note:
782     Unlike pointer values, object ids are never reused so one may save a `PetscObjectId` and compare it to one obtained later from a `PetscObject` to determine
783     if the objects are the same. Never compare two object pointer values.
784 
785 .seealso: `PetscObjectState`, `PetscObjectGetId()`
786 M*/
787 typedef PetscInt64 PetscObjectId;
788 
789 /*MC
790     PetscObjectState - integer state for a `PetscObject`
791 
792     Level: developer
793 
794     Note:
795     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
796     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.
797 
798 .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
799 M*/
800 typedef PetscInt64 PetscObjectState;
801 
802 /*S
803      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
804       by string name
805 
806    Level: advanced
807 
808 .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
809 S*/
810 typedef struct _n_PetscFunctionList *PetscFunctionList;
811 
812 /*E
813   PetscFileMode - Access mode for a file.
814 
815   Values:
816 +  `FILE_MODE_UNDEFINED`     - initial invalid value
817 .  `FILE_MODE_READ`          - open a file at its beginning for reading
818 .  `FILE_MODE_WRITE`         - open a file at its beginning for writing (will create if the file does not exist)
819 .  `FILE_MODE_APPEND`        - open a file at end for writing
820 .  `FILE_MODE_UPDATE`        - open a file for updating, meaning for reading and writing
821 -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
822 
823   Level: beginner
824 
825 .seealso: `PetscViewerFileSetMode()`
826 E*/
827 typedef enum {
828   FILE_MODE_UNDEFINED     = -1,
829   FILE_MODE_READ          = 0,
830   FILE_MODE_WRITE         = 1,
831   FILE_MODE_APPEND        = 2,
832   FILE_MODE_UPDATE        = 3,
833   FILE_MODE_APPEND_UPDATE = 4
834 } PetscFileMode;
835 PETSC_EXTERN const char *const PetscFileModes[];
836 
837 typedef void *PetscDLHandle;
838 typedef enum {
839   PETSC_DL_DECIDE = 0,
840   PETSC_DL_NOW    = 1,
841   PETSC_DL_LOCAL  = 2
842 } PetscDLMode;
843 
844 /*S
845    PetscObjectList - Linked list of PETSc objects, each accessible by string name
846 
847    Level: developer
848 
849    Note:
850    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
851 
852 .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
853 S*/
854 typedef struct _n_PetscObjectList *PetscObjectList;
855 
856 /*S
857    PetscDLLibrary - Linked list of dynamic libraries to search for functions
858 
859    Level: developer
860 
861 .seealso: `PetscDLLibraryOpen()`
862 S*/
863 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
864 
865 /*S
866    PetscContainer - Simple PETSc object that contains a pointer to any required data
867 
868    Level: advanced
869 
870    Note:
871    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
872 
873 .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
874 S*/
875 typedef struct _p_PetscContainer *PetscContainer;
876 
877 /*S
878    PetscRandom - Abstract PETSc object that manages generating random numbers
879 
880    Level: intermediate
881 
882 .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
883 S*/
884 typedef struct _p_PetscRandom *PetscRandom;
885 
886 /*
887    In binary files variables are stored using the following lengths,
888   regardless of how they are stored in memory on any one particular
889   machine. Use these rather than sizeof() in computing sizes for
890   PetscBinarySeek().
891 */
892 #define PETSC_BINARY_INT_SIZE    (32 / 8)
893 #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
894 #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
895 #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
896 #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
897 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
898 
899 /*E
900   PetscBinarySeekType - argument to `PetscBinarySeek()`
901 
902   Values:
903 +  `PETSC_BINARY_SEEK_SET` - offset is an absolute location in the file
904 .  `PETSC_BINARY_SEEK_CUR` - offset is an offset from the current location of the file pointer
905 -  `PETSC_BINARY_SEEK_END` - offset is an offset from the end of the file
906 
907   Level: advanced
908 
909 .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
910 E*/
911 typedef enum {
912   PETSC_BINARY_SEEK_SET = 0,
913   PETSC_BINARY_SEEK_CUR = 1,
914   PETSC_BINARY_SEEK_END = 2
915 } PetscBinarySeekType;
916 
917 /*E
918    PetscBuildTwoSidedType - algorithm for setting up two-sided communication for use with `PetscSF`
919 
920    Values:
921 +  `PETSC_BUILDTWOSIDED_ALLREDUCE`  - classical algorithm using an `MPI_Allreduce()` with
922                                       a buffer of length equal to the communicator size. Not memory-scalable due to
923                                       the large reduction size. Requires only an MPI-1 implementation.
924 .  `PETSC_BUILDTWOSIDED_IBARRIER`   - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
925                                       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires an MPI-3 implementation.
926 -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
927                                       that only communicates the part of the reduction that is necessary.  Requires an MPI-2 implementation.
928 
929    Level: developer
930 
931 .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
932 E*/
933 typedef enum {
934   PETSC_BUILDTWOSIDED_NOTSET     = -1,
935   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
936   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
937   PETSC_BUILDTWOSIDED_REDSCATTER = 2
938   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
939 } PetscBuildTwoSidedType;
940 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
941 
942 /*E
943   InsertMode - How the entries are combined with the current values in the vectors or matrices
944 
945   Values:
946 +  `NOT_SET_VALUES`    - do not actually use the values
947 .  `INSERT_VALUES`     - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
948 .  `ADD_VALUES`        - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
949 .  `MAX_VALUES`        - use the maximum of each current value and provided value
950 .  `MIN_VALUES`        - use the minimum of each current value and provided value
951 .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
952 .  `ADD_ALL_VALUES`    - add, even if indices that are not marked as constrained by the `PetscSection`
953 .  `INSERT_BC_VALUES`  - insert, but ignore indices that are not marked as constrained by the `PetscSection`
954 -  `ADD_BC_VALUES`     - add, but ignore indices that are not marked as constrained by the `PetscSection`
955 
956   Level: beginner
957 
958   Note:
959   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
960   and `DMGetLocalSection()`.
961 
962   Not all options are supported for all operations or PETSc object types.
963 
964 .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
965           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
966           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
967 E*/
968 typedef enum {
969   NOT_SET_VALUES,
970   INSERT_VALUES,
971   ADD_VALUES,
972   MAX_VALUES,
973   MIN_VALUES,
974   INSERT_ALL_VALUES,
975   ADD_ALL_VALUES,
976   INSERT_BC_VALUES,
977   ADD_BC_VALUES
978 } InsertMode;
979 
980 /*MC
981     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
982 
983     Level: beginner
984 
985 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
986           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
987           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
988 M*/
989 
990 /*MC
991     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
992                  value into that location
993 
994     Level: beginner
995 
996 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
997           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
998           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
999 M*/
1000 
1001 /*MC
1002     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
1003 
1004     Level: beginner
1005 
1006 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1007 M*/
1008 
1009 /*MC
1010     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
1011 
1012     Level: beginner
1013 
1014 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1015 M*/
1016 
1017 /*S
1018    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
1019 
1020    Values:
1021 +   `PETSC_SUBCOMM_GENERAL`    - similar to `MPI_Comm_split()` each process sets the new communicator (color) they will belong to and the order within that communicator
1022 .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
1023 -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
1024 
1025    Sample Usage:
1026 .vb
1027        PetscSubcommCreate()
1028        PetscSubcommSetNumber()
1029        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
1030        ccomm = PetscSubcommChild()
1031        PetscSubcommDestroy()
1032 .ve
1033 
1034    Example:
1035    Consider a communicator with six processes split into 3 subcommunicators.
1036 .vb
1037    PETSC_SUBCOMM_CONTIGUOUS - the first communicator contains rank 0,1  the second rank 2,3 and the third rank 4,5 in the original ordering of the original communicator
1038    PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
1039 .ve
1040 
1041    Level: advanced
1042 
1043    Note:
1044    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
1045 .vb
1046      PetscSubcommChild() returns the associated subcommunicator on this process
1047      PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
1048 .ve
1049 
1050    Developer Note:
1051    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
1052    are performed.
1053 
1054 .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
1055 S*/
1056 typedef struct _n_PetscSubcomm *PetscSubcomm;
1057 typedef enum {
1058   PETSC_SUBCOMM_GENERAL    = 0,
1059   PETSC_SUBCOMM_CONTIGUOUS = 1,
1060   PETSC_SUBCOMM_INTERLACED = 2
1061 } PetscSubcommType;
1062 PETSC_EXTERN const char *const PetscSubcommTypes[];
1063 
1064 /*S
1065    PetscHeap - A simple class for managing heaps
1066 
1067    Level: intermediate
1068 
1069 .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1070 S*/
1071 typedef struct _n_PetscHeap *PetscHeap;
1072 
1073 typedef struct _n_PetscShmComm *PetscShmComm;
1074 typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
1075 
1076 /*S
1077    PetscSegBuffer - a segmented extendable buffer
1078 
1079    Level: developer
1080 
1081 .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1082 S*/
1083 typedef struct _n_PetscSegBuffer *PetscSegBuffer;
1084 
1085 typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
1086 
1087 /*S
1088      PetscBT - PETSc bitarrays, efficient storage of arrays of boolean values
1089 
1090      Level: advanced
1091 
1092      Notes:
1093      The following routines do not have their own manual pages
1094 
1095 .vb
1096      PetscBTCreate(m,&bt)         - creates a bit array with enough room to hold m values
1097      PetscBTDestroy(&bt)          - destroys the bit array
1098      PetscBTMemzero(m,bt)         - zeros the entire bit array (sets all values to false)
1099      PetscBTSet(bt,index)         - sets a particular entry as true
1100      PetscBTClear(bt,index)       - sets a particular entry as false
1101      PetscBTLookup(bt,index)      - returns the value
1102      PetscBTLookupSet(bt,index)   - returns the value and then sets it true
1103      PetscBTLookupClear(bt,index) - returns the value and then sets it false
1104      PetscBTLength(m)             - returns number of bytes in array with m bits
1105      PetscBTView(m,bt,viewer)     - prints all the entries in a bit array
1106 .ve
1107 
1108     PETSc does not check error flags on `PetscBTLookup()`, `PetscBTLookupSet()`, `PetscBTLength()` because error checking
1109     would cost hundreds more cycles then the operation.
1110 
1111 S*/
1112 typedef char *PetscBT;
1113 
1114 /* The number of bits in a byte */
1115 #define PETSC_BITS_PER_BYTE CHAR_BIT
1116