xref: /petsc/include/petscsystypes.h (revision 6a210b70a61472cf8733db59e8a3fa68f6578c01)
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 
304   #define PetscInt_FMT "d"
305 #endif
306 
307 #define PETSC_MIN_INT    PETSC_INT_MIN
308 #define PETSC_MAX_INT    PETSC_INT_MAX
309 #define PETSC_MAX_UINT16 65535
310 
311 #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 */
312   #define MPIU_INT64     MPI_INT64_T
313   #define PetscInt64_FMT PRId64
314 #elif (PETSC_SIZEOF_LONG_LONG == 8)
315   #define MPIU_INT64     MPI_LONG_LONG_INT
316   #define PetscInt64_FMT "lld"
317 #elif defined(PETSC_HAVE___INT64)
318   #define MPIU_INT64     MPI_INT64_T
319   #define PetscInt64_FMT "ld"
320 #else
321   #error "cannot determine PetscInt64 type"
322 #endif
323 
324 #define MPIU_INT32     MPI_INT32_T
325 #define PetscInt32_FMT PRId32
326 
327 /*MC
328    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
329 
330    Level: intermediate
331 
332    Notes:
333    Usually this is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
334    standard C/Fortran integers are 32-bit then this may not be the same as `PetscInt`,
335    except on some BLAS/LAPACK implementations that support 64-bit integers see the notes below.
336 
337    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
338     generates a `PETSC_ERR_ARG_OUTOFRANGE` error
339 
340    Installation Notes\:
341    ./configure automatically determines the size of the integers used by BLAS/LAPACK except when `--with-batch` is used
342    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`
343 
344    MATLAB ships with BLAS and LAPACK that use 64-bit integers, for example if you run ./configure with, the option
345     `--with-blaslapack-lib`=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
346 
347    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
348    against the 64-bit version, otherwise it uses the 32-bit version
349 
350    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
351 
352    External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64-bit integers to BLAS/LAPACK so cannot
353    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
354    these external libraries while using 64-bit integer BLAS/LAPACK.
355 
356 .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
357 M*/
358 #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
359 typedef PetscInt64 PetscBLASInt;
360 
361   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
362   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
363   #define PetscBLASInt_FMT   PetscInt64_FMT
364 #else
365 typedef int PetscBLASInt;
366 
367 enum {
368   PETSC_BLAS_INT_MIN = INT_MIN,
369   PETSC_BLAS_INT_MAX = INT_MAX
370 };
371 
372   #define PetscBLASInt_FMT "d"
373 #endif
374 
375 /*MC
376    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
377 
378    Level: intermediate
379 
380    Notes:
381    As of this writing `PetscCuBLASInt` is always the system `int`.
382 
383   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
384    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
385 
386 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
387 M*/
388 typedef int PetscCuBLASInt;
389 
390 enum {
391   PETSC_CUBLAS_INT_MIN = INT_MIN,
392   PETSC_CUBLAS_INT_MAX = INT_MAX
393 };
394 
395 /*MC
396    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
397 
398    Level: intermediate
399 
400    Notes:
401    `PetscHipBLASInt` is always the system `int`.
402 
403    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
404    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
405 
406 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscHipBLASIntCast()
407 M*/
408 typedef int PetscHipBLASInt;
409 
410 enum {
411   PETSC_HIPBLAS_INT_MIN = INT_MIN,
412   PETSC_HIPBLAS_INT_MAX = INT_MAX
413 };
414 
415 /*E
416    PetscBool  - Logical variable. Actually an enum in C and a logical in Fortran.
417 
418    Level: beginner
419 
420    Developer Note:
421    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
422    Boolean values. It is not easy to have a simple macro that will work properly in all circumstances with all three mechanisms.
423 
424 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
425 E*/
426 typedef enum {
427   PETSC_FALSE,
428   PETSC_TRUE
429 } PetscBool;
430 PETSC_EXTERN const char *const PetscBools[];
431 
432 /*E
433    PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
434 
435    Level: beginner
436 
437    Note:
438    Should not be used with the if (flg) or if (!flg) syntax.
439 
440 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
441 E*/
442 typedef enum {
443   PETSC_BOOL3_FALSE,
444   PETSC_BOOL3_TRUE,
445   PETSC_BOOL3_UNKNOWN = -1
446 } PetscBool3;
447 
448 #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
449 #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
450 
451 /*MC
452    PetscReal - PETSc type that represents a real number version of `PetscScalar`
453 
454    Level: beginner
455 
456    Notes:
457    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
458    They will automatically work correctly regardless of the size of `PetscReal`.
459 
460    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
461 
462 .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
463 M*/
464 
465 #if defined(PETSC_USE_REAL_SINGLE)
466 typedef float PetscReal;
467 #elif defined(PETSC_USE_REAL_DOUBLE)
468 typedef double PetscReal;
469 #elif defined(PETSC_USE_REAL___FLOAT128)
470   #if defined(__cplusplus)
471 extern "C" {
472   #endif
473   #include <quadmath.h>
474   #if defined(__cplusplus)
475 }
476   #endif
477 typedef __float128 PetscReal;
478 #elif defined(PETSC_USE_REAL___FP16)
479 typedef __fp16 PetscReal;
480 #endif /* PETSC_USE_REAL_* */
481 
482 /*MC
483    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
484 
485    Synopsis:
486    #include <petscsys.h>
487    PetscComplex number = 1. + 2.*PETSC_i;
488 
489    Level: beginner
490 
491    Notes:
492    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
493    They will automatically work correctly regardless of the size of `PetscComplex`.
494 
495    See `PetscScalar` for details on how to ./configure the size of `PetscReal`
496 
497    Complex numbers are automatically available if PETSc was able to find a working complex implementation
498 
499     PETSc has a 'fix' for complex numbers to support expressions such as `std::complex<PetscReal>` + `PetscInt`, which are not supported by the standard
500     C++ library, but are convenient for petsc users. If the C++ compiler is able to compile code in `petsccxxcomplexfix.h` (This is checked by
501     configure), we include `petsccxxcomplexfix.h` to provide this convenience.
502 
503     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`
504     at the beginning of the C++ file to skip the fix.
505 
506 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
507 M*/
508 #if !defined(PETSC_SKIP_COMPLEX)
509   #if defined(PETSC_CLANGUAGE_CXX)
510     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
511       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
512         #define PETSC_HAVE_COMPLEX 1
513       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
514         #define PETSC_HAVE_COMPLEX 1
515       #endif
516     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
517       #define PETSC_HAVE_COMPLEX 1
518     #endif
519   #else /* !PETSC_CLANGUAGE_CXX */
520     #if !defined(PETSC_USE_REAL___FP16)
521       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
522         #define PETSC_HAVE_COMPLEX 1
523       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
524         #define PETSC_HAVE_COMPLEX 1
525       #endif
526     #endif
527   #endif /* PETSC_CLANGUAGE_CXX */
528 #endif   /* !PETSC_SKIP_COMPLEX */
529 
530 #if defined(PETSC_HAVE_COMPLEX)
531   #if defined(__cplusplus) /* C++ complex support */
532     /* Locate a C++ complex template library */
533     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
534       #define petsccomplexlib Kokkos
535       #include <Kokkos_Complex.hpp>
536     #elif defined(__CUDACC__) || defined(__HIPCC__)
537       #define petsccomplexlib thrust
538       #include <thrust/complex.h>
539     #elif defined(PETSC_USE_REAL___FLOAT128)
540       #include <complex.h>
541     #else
542       #define petsccomplexlib std
543       #include <complex>
544     #endif
545 
546     /* Define PetscComplex based on the precision */
547     #if defined(PETSC_USE_REAL_SINGLE)
548 typedef petsccomplexlib::complex<float> PetscComplex;
549     #elif defined(PETSC_USE_REAL_DOUBLE)
550 typedef petsccomplexlib::complex<double> PetscComplex;
551     #elif defined(PETSC_USE_REAL___FLOAT128)
552 typedef __complex128 PetscComplex;
553     #endif
554 
555     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
556     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
557       #include <petsccxxcomplexfix.h>
558     #endif
559   #else /* c99 complex support */
560     #include <complex.h>
561     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
562 typedef float _Complex PetscComplex;
563     #elif defined(PETSC_USE_REAL_DOUBLE)
564 typedef double _Complex PetscComplex;
565     #elif defined(PETSC_USE_REAL___FLOAT128)
566 typedef __complex128 PetscComplex;
567     #endif /* PETSC_USE_REAL_* */
568   #endif   /* !__cplusplus */
569 #endif     /* PETSC_HAVE_COMPLEX */
570 
571 /*MC
572    PetscScalar - PETSc type that represents either a double precision real number, a double precision
573                  complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
574                  with `--with-scalar-type`=real,complex `--with-precision`=single,double,__float128,__fp16
575 
576    Level: beginner
577 
578    Note:
579    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`.
580 
581 .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
582 M*/
583 
584 #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
585 typedef PetscComplex PetscScalar;
586 #else  /* PETSC_USE_COMPLEX */
587 typedef PetscReal PetscScalar;
588 #endif /* PETSC_USE_COMPLEX */
589 
590 /*E
591     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
592 
593    Values for array input:
594 +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
595 .   `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
596                           delete the array. The array MUST have been obtained with `PetscMalloc()`. Hence this mode cannot be used in Fortran.
597 -   `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
598                           the array but the user must delete the array after the object is destroyed.
599 
600    Values for PetscObject:
601 +   `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.
602 .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
603                           increases its reference count).
604 -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
605 
606    Level: beginner
607 
608 .seealso: `PetscInsertMode`
609 E*/
610 typedef enum {
611   PETSC_COPY_VALUES,
612   PETSC_OWN_POINTER,
613   PETSC_USE_POINTER
614 } PetscCopyMode;
615 PETSC_EXTERN const char *const PetscCopyModes[];
616 
617 /*MC
618     PETSC_FALSE - False value of `PetscBool`
619 
620     Level: beginner
621 
622     Note:
623     Zero integer
624 
625 .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
626 M*/
627 
628 /*MC
629     PETSC_TRUE - True value of `PetscBool`
630 
631     Level: beginner
632 
633     Note:
634     Nonzero integer
635 
636 .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
637 M*/
638 
639 /*MC
640     PetscLogDouble - Used for logging times
641 
642   Level: developer
643 
644   Note:
645   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
646 
647 .seealso: `PetscBool`, `PetscDataType`
648 M*/
649 typedef double PetscLogDouble;
650 
651 /*E
652     PetscDataType - Used for handling different basic data types.
653 
654    Level: beginner
655 
656    Notes:
657    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
658 
659    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
660    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
661 
662    Developer Notes:
663    It would be nice if we could always just use MPI Datatypes, why can we not?
664 
665    If you change any values in `PetscDatatype` make sure you update their usage in
666    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
667 
668    TODO:
669    Remove use of improper `PETSC_ENUM`
670 
671 .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
672           `PetscDataTypeGetSize()`
673 E*/
674 typedef enum {
675   PETSC_DATATYPE_UNKNOWN = 0,
676   PETSC_DOUBLE           = 1,
677   PETSC_COMPLEX          = 2,
678   PETSC_LONG             = 3,
679   PETSC_SHORT            = 4,
680   PETSC_FLOAT            = 5,
681   PETSC_CHAR             = 6,
682   PETSC_BIT_LOGICAL      = 7,
683   PETSC_ENUM             = 8,
684   PETSC_BOOL             = 9,
685   PETSC___FLOAT128       = 10,
686   PETSC_OBJECT           = 11,
687   PETSC_FUNCTION         = 12,
688   PETSC_STRING           = 13,
689   PETSC___FP16           = 14,
690   PETSC_STRUCT           = 15,
691   PETSC_INT              = 16,
692   PETSC_INT64            = 17,
693   PETSC_COUNT            = 18,
694   PETSC_INT32            = 19,
695 } PetscDataType;
696 PETSC_EXTERN const char *const PetscDataTypes[];
697 
698 #if defined(PETSC_USE_REAL_SINGLE)
699   #define PETSC_REAL PETSC_FLOAT
700 #elif defined(PETSC_USE_REAL_DOUBLE)
701   #define PETSC_REAL PETSC_DOUBLE
702 #elif defined(PETSC_USE_REAL___FLOAT128)
703   #define PETSC_REAL PETSC___FLOAT128
704 #elif defined(PETSC_USE_REAL___FP16)
705   #define PETSC_REAL PETSC___FP16
706 #else
707   #define PETSC_REAL PETSC_DOUBLE
708 #endif
709 
710 #if defined(PETSC_USE_COMPLEX)
711   #define PETSC_SCALAR PETSC_COMPLEX
712 #else
713   #define PETSC_SCALAR PETSC_REAL
714 #endif
715 
716 #define PETSC_FORTRANADDR PETSC_LONG
717 
718 /*S
719   PetscToken - 'Token' used for managing tokenizing strings
720 
721   Level: intermediate
722 
723 .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
724 S*/
725 typedef struct _p_PetscToken *PetscToken;
726 
727 /*S
728    PetscObject - any PETSc object, `PetscViewer`, `Mat`, `Vec`, `KSP` etc
729 
730    Level: beginner
731 
732    Notes:
733    This is the base class from which all PETSc objects are derived from.
734 
735    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
736 
737 .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
738 S*/
739 typedef struct _p_PetscObject *PetscObject;
740 
741 /*MC
742     PetscObjectId - unique integer Id for a `PetscObject`
743 
744     Level: developer
745 
746     Note:
747     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
748     if the objects are the same. Never compare two object pointer values.
749 
750 .seealso: `PetscObjectState`, `PetscObjectGetId()`
751 M*/
752 typedef PetscInt64 PetscObjectId;
753 
754 /*MC
755     PetscObjectState - integer state for a `PetscObject`
756 
757     Level: developer
758 
759     Note:
760     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
761     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.
762 
763 .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
764 M*/
765 typedef PetscInt64 PetscObjectState;
766 
767 /*S
768      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
769       by string name
770 
771    Level: advanced
772 
773 .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
774 S*/
775 typedef struct _n_PetscFunctionList *PetscFunctionList;
776 
777 /*E
778   PetscFileMode - Access mode for a file.
779 
780   Values:
781 +  `FILE_MODE_UNDEFINED`     - initial invalid value
782 .  `FILE_MODE_READ`          - open a file at its beginning for reading
783 .  `FILE_MODE_WRITE`         - open a file at its beginning for writing (will create if the file does not exist)
784 .  `FILE_MODE_APPEND`        - open a file at end for writing
785 .  `FILE_MODE_UPDATE`        - open a file for updating, meaning for reading and writing
786 -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
787 
788   Level: beginner
789 
790 .seealso: `PetscViewerFileSetMode()`
791 E*/
792 typedef enum {
793   FILE_MODE_UNDEFINED = -1,
794   FILE_MODE_READ      = 0,
795   FILE_MODE_WRITE,
796   FILE_MODE_APPEND,
797   FILE_MODE_UPDATE,
798   FILE_MODE_APPEND_UPDATE
799 } PetscFileMode;
800 PETSC_EXTERN const char *const PetscFileModes[];
801 
802 typedef void *PetscDLHandle;
803 typedef enum {
804   PETSC_DL_DECIDE = 0,
805   PETSC_DL_NOW    = 1,
806   PETSC_DL_LOCAL  = 2
807 } PetscDLMode;
808 
809 /*S
810    PetscObjectList - Linked list of PETSc objects, each accessible by string name
811 
812    Level: developer
813 
814    Note:
815    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
816 
817 .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
818 S*/
819 typedef struct _n_PetscObjectList *PetscObjectList;
820 
821 /*S
822    PetscDLLibrary - Linked list of dynamic libraries to search for functions
823 
824    Level: developer
825 
826 .seealso: `PetscDLLibraryOpen()`
827 S*/
828 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
829 
830 /*S
831    PetscContainer - Simple PETSc object that contains a pointer to any required data
832 
833    Level: advanced
834 
835    Note:
836    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
837 
838 .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
839 S*/
840 typedef struct _p_PetscContainer *PetscContainer;
841 
842 /*S
843    PetscRandom - Abstract PETSc object that manages generating random numbers
844 
845    Level: intermediate
846 
847 .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
848 S*/
849 typedef struct _p_PetscRandom *PetscRandom;
850 
851 /*
852    In binary files variables are stored using the following lengths,
853   regardless of how they are stored in memory on any one particular
854   machine. Use these rather than sizeof() in computing sizes for
855   PetscBinarySeek().
856 */
857 #define PETSC_BINARY_INT_SIZE    (32 / 8)
858 #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
859 #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
860 #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
861 #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
862 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
863 
864 /*E
865   PetscBinarySeekType - argument to `PetscBinarySeek()`
866 
867   Values:
868 +  `PETSC_BINARY_SEEK_SET` - offset is an absolute location in the file
869 .  `PETSC_BINARY_SEEK_CUR` - offset is an offset from the current location of the file pointer
870 -  `PETSC_BINARY_SEEK_END` - offset is an offset from the end of the file
871 
872   Level: advanced
873 
874 .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
875 E*/
876 typedef enum {
877   PETSC_BINARY_SEEK_SET = 0,
878   PETSC_BINARY_SEEK_CUR = 1,
879   PETSC_BINARY_SEEK_END = 2
880 } PetscBinarySeekType;
881 
882 /*E
883    PetscBuildTwoSidedType - algorithm for setting up two-sided communication for use with `PetscSF`
884 
885    Values:
886 +  `PETSC_BUILDTWOSIDED_ALLREDUCE`  - classical algorithm using an `MPI_Allreduce()` with
887                                       a buffer of length equal to the communicator size. Not memory-scalable due to
888                                       the large reduction size. Requires only an MPI-1 implementation.
889 .  `PETSC_BUILDTWOSIDED_IBARRIER`   - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
890                                       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires an MPI-3 implementation.
891 -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
892                                       that only communicates the part of the reduction that is necessary.  Requires an MPI-2 implementation.
893 
894    Level: developer
895 
896 .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
897 E*/
898 typedef enum {
899   PETSC_BUILDTWOSIDED_NOTSET     = -1,
900   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
901   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
902   PETSC_BUILDTWOSIDED_REDSCATTER = 2
903   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
904 } PetscBuildTwoSidedType;
905 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
906 
907 /* NOTE: If you change this, you must also change the values in src/vec/f90-mod/petscvec.h */
908 /*E
909   InsertMode - How the entries are combined with the current values in the vectors or matrices
910 
911   Values:
912 +  `NOT_SET_VALUES`    - do not actually use the values
913 .  `INSERT_VALUES`     - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
914 .  `ADD_VALUES`        - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
915 .  `MAX_VALUES`        - use the maximum of each current value and provided value
916 .  `MIN_VALUES`        - use the minimum of each current value and provided value
917 .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
918 .  `ADD_ALL_VALUES`    - add, even if indices that are not marked as constrained by the `PetscSection`
919 .  `INSERT_BC_VALUES`  - insert, but ignore indices that are not marked as constrained by the `PetscSection`
920 -  `ADD_BC_VALUES`     - add, but ignore indices that are not marked as constrained by the `PetscSection`
921 
922   Level: beginner
923 
924   Note:
925   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
926   and `DMGetLocalSection()`.
927 
928   Not all options are supported for all operations or PETSc object types.
929 
930 .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
931           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
932           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
933 E*/
934 typedef enum {
935   NOT_SET_VALUES,
936   INSERT_VALUES,
937   ADD_VALUES,
938   MAX_VALUES,
939   MIN_VALUES,
940   INSERT_ALL_VALUES,
941   ADD_ALL_VALUES,
942   INSERT_BC_VALUES,
943   ADD_BC_VALUES
944 } InsertMode;
945 
946 /*MC
947     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
948 
949     Level: beginner
950 
951 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
952           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
953           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
954 M*/
955 
956 /*MC
957     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
958                  value into that location
959 
960     Level: beginner
961 
962 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
963           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
964           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
965 M*/
966 
967 /*MC
968     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
969 
970     Level: beginner
971 
972 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
973 M*/
974 
975 /*MC
976     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
977 
978     Level: beginner
979 
980 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
981 M*/
982 
983 /*S
984    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
985 
986    Values:
987 +   `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
988 .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
989 -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
990 
991    Sample Usage:
992 .vb
993        PetscSubcommCreate()
994        PetscSubcommSetNumber()
995        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
996        ccomm = PetscSubcommChild()
997        PetscSubcommDestroy()
998 .ve
999 
1000    Example:
1001    Consider a communicator with six processes split into 3 subcommunicators.
1002 .vb
1003    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
1004    PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
1005 .ve
1006 
1007    Level: advanced
1008 
1009    Note:
1010    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
1011 .vb
1012      PetscSubcommChild() returns the associated subcommunicator on this process
1013      PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
1014 .ve
1015 
1016    Developer Note:
1017    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
1018    are performed.
1019 
1020 .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
1021 S*/
1022 typedef struct _n_PetscSubcomm *PetscSubcomm;
1023 typedef enum {
1024   PETSC_SUBCOMM_GENERAL    = 0,
1025   PETSC_SUBCOMM_CONTIGUOUS = 1,
1026   PETSC_SUBCOMM_INTERLACED = 2
1027 } PetscSubcommType;
1028 PETSC_EXTERN const char *const PetscSubcommTypes[];
1029 
1030 /*S
1031    PetscHeap - A simple class for managing heaps
1032 
1033    Level: intermediate
1034 
1035 .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1036 S*/
1037 typedef struct _PetscHeap *PetscHeap;
1038 
1039 typedef struct _n_PetscShmComm *PetscShmComm;
1040 typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
1041 
1042 /*S
1043    PetscSegBuffer - a segmented extendable buffer
1044 
1045    Level: developer
1046 
1047 .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1048 S*/
1049 typedef struct _n_PetscSegBuffer *PetscSegBuffer;
1050 
1051 typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
1052 
1053 /*S
1054      PetscBT - PETSc bitarrays, efficient storage of arrays of boolean values
1055 
1056      Level: advanced
1057 
1058      Notes:
1059      The following routines do not have their own manual pages
1060 
1061 .vb
1062      PetscBTCreate(m,&bt)         - creates a bit array with enough room to hold m values
1063      PetscBTDestroy(&bt)          - destroys the bit array
1064      PetscBTMemzero(m,bt)         - zeros the entire bit array (sets all values to false)
1065      PetscBTSet(bt,index)         - sets a particular entry as true
1066      PetscBTClear(bt,index)       - sets a particular entry as false
1067      PetscBTLookup(bt,index)      - returns the value
1068      PetscBTLookupSet(bt,index)   - returns the value and then sets it true
1069      PetscBTLookupClear(bt,index) - returns the value and then sets it false
1070      PetscBTLength(m)             - returns number of bytes in array with m bits
1071      PetscBTView(m,bt,viewer)     - prints all the entries in a bit array
1072 .ve
1073 
1074     PETSc does not check error flags on `PetscBTLookup()`, `PetcBTLookupSet()`, `PetscBTLength()` because error checking
1075     would cost hundreds more cycles then the operation.
1076 
1077 S*/
1078 typedef char *PetscBT;
1079 
1080 /* The number of bits in a byte */
1081 #define PETSC_BITS_PER_BYTE CHAR_BIT
1082