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