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