Actual source code: petscsystypes.h

  1: /* Portions of this code are under:
  2:    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
  3: */

  5: #pragma once

  7: #include <petscconf.h>
  8: #include <petscconf_poison.h>
  9: #include <petscfix.h>
 10: #include <petscmacros.h>
 11: #include <stddef.h>

 13: /* SUBMANSEC = Sys */

 15: #include <limits.h> // INT_MIN, INT_MAX, CHAR_BIT

 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

 26: #ifdef PETSC_CLANG_STATIC_ANALYZER
 27:   #undef PETSC_USE_STRICT_PETSCERRORCODE
 28: #endif

 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

 38: /*E
 39:   PetscErrorCode - Datatype used to return PETSc error codes.

 41:   Level: beginner

 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.

 50:   One can retrieve the error string corresponding to a particular error code using
 51:   `PetscErrorMessage()`.

 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.

 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.

 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 */

 70:   PETSC_ERR_MIN_VALUE = 54, /* should always be one less than the smallest value */

 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 */

 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 */

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 */

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 */

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_PYTHON         = 101, /* Exception in Python */
123:   PETSC_ERR_MAX_VALUE      = 102, /* this is always the one more than the largest error code */

125:   /*
126:     do not use, exist purely to make the enum bounds equal that of a regular int (so conversion
127:     to int in main() is not undefined behavior)
128:   */
129:   PETSC_ERR_MIN_SIGNED_BOUND_DO_NOT_USE = INT_MIN,
130:   PETSC_ERR_MAX_SIGNED_BOUND_DO_NOT_USE = INT_MAX
131: } PETSC_ERROR_CODE_ENUM_NAME;

133: #ifndef PETSC_USE_STRICT_PETSCERRORCODE
134: typedef int PetscErrorCode;

136:   /*
137:   Needed so that C++ lambdas can deduce the return type as PetscErrorCode from
138:   PetscFunctionReturn(PETSC_SUCCESS). Otherwise we get

140:   error: return type '(unnamed enum at include/petscsystypes.h:50:1)' must match previous
141:   return type 'int' when lambda expression has unspecified explicit return type
142:   PetscFunctionReturn(PETSC_SUCCESS);
143:   ^
144: */
145:   #define PETSC_SUCCESS ((PetscErrorCode)0)
146: #endif

148: #undef PETSC_ERROR_CODE_NODISCARD
149: #undef PETSC_ERROR_CODE_TYPEDEF
150: #undef PETSC_ERROR_CODE_ENUM_NAME

152: /*MC
153:     PetscClassId - A unique id used to identify each PETSc class.

155:     Level: developer

157:     Note:
158:     Use `PetscClassIdRegister()` to obtain a new value for a new class being created. Usually
159:     XXXInitializePackage() calls it for each class it defines.

161:     Developer Note:
162:     Internal integer stored in the `_p_PetscObject` data structure. These are all computed by an offset from the lowest one, `PETSC_SMALLEST_CLASSID`.

164: .seealso: `PetscClassIdRegister()`, `PetscLogEventRegister()`, `PetscHeaderCreate()`
165: M*/
166: typedef int PetscClassId;

168: /*MC
169:     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.

171:     Level: intermediate

173:     Notes:
174:     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
175:     standard C/Fortran integers are 32-bit then this is NOT the same as `PetscInt`; it remains 32-bit.

177:     `PetscMPIIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscMPIInt`, if not it
178:     generates a `PETSC_ERR_ARG_OUTOFRANGE` error.

180: .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscInt`, `PetscMPIIntCast()`
181: M*/
182: typedef int PetscMPIInt;

184: /* Limit MPI to 32-bits */
185: enum {
186:   PETSC_MPI_INT_MIN = INT_MIN,
187:   PETSC_MPI_INT_MAX = INT_MAX
188: };

190: /*MC
191:     PetscSizeT - datatype used to represent sizes in memory (like `size_t`)

193:     Level: intermediate

195:     Notes:
196:     This is equivalent to `size_t`, but defined for consistency with Fortran, which lacks a native equivalent of `size_t`.

198: .seealso: `PetscInt`, `PetscInt64`, `PetscCount`
199: M*/
200: typedef size_t PetscSizeT;

202: /*MC
203:     PetscCount - signed datatype used to represent counts

205:     Level: intermediate

207:     Notes:
208:     This is equivalent to `ptrdiff_t`, but defined for consistency with Fortran, which lacks a native equivalent of `ptrdiff_t`.

210:     Use `PetscCount_FMT` to format with `PetscPrintf()`, `printf()`, and related functions.

212: .seealso: [](stylePetscCount), `PetscInt`, `PetscInt64`, `PetscSizeT`
213: M*/
214: typedef ptrdiff_t PetscCount;
215: #define PetscCount_FMT "td"

217: /*MC
218:     PetscEnum - datatype used to pass enum types within PETSc functions.

220:     Level: intermediate

222: .seealso: `PetscOptionsGetEnum()`, `PetscOptionsEnum()`, `PetscBagRegisterEnum()`
223: M*/
224: typedef enum {
225:   ENUM_DUMMY
226: } PetscEnum;

228: typedef short PetscShort;
229: typedef char  PetscChar;
230: typedef float PetscFloat;

232: /*MC
233:   PetscInt - PETSc type that represents an integer, used primarily to
234:              represent size of arrays and indexing into arrays. Its size can be configured with the option `--with-64-bit-indices` to be either 32-bit (default) or 64-bit.

236:   Level: beginner

238:   Notes:
239:   For MPI calls that require datatypes, use `MPIU_INT` as the datatype for `PetscInt`. It will automatically work correctly regardless of the size of `PetscInt`.

241: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscIntCast()`
242: M*/

244: #if defined(PETSC_HAVE_STDINT_H)
245:   #include <stdint.h>
246: #endif
247: #if defined(PETSC_HAVE_INTTYPES_H)
250:   #endif
251:   #include <inttypes.h>
252:   #if !defined(PRId64)
253:     #define PRId64 "ld"
254:   #endif
255: #endif

257: #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && (defined(PETSC_HAVE_MPIUNI) || defined(PETSC_HAVE_MPI_INT64_T)) /* MPI_INT64_T is not guaranteed to be a macro */
258: typedef int64_t PetscInt64;

260:   #define PETSC_INT64_MIN INT64_MIN
261:   #define PETSC_INT64_MAX INT64_MAX

263: #elif (PETSC_SIZEOF_LONG_LONG == 8)
264: typedef long long PetscInt64;

266:   #define PETSC_INT64_MIN LLONG_MIN
267:   #define PETSC_INT64_MAX LLONG_MAX

269: #elif defined(PETSC_HAVE___INT64)
270: typedef __int64 PetscInt64;

272:   #define PETSC_INT64_MIN INT64_MIN
273:   #define PETSC_INT64_MAX INT64_MAX

275: #else
276:   #error "cannot determine PetscInt64 type"
277: #endif

279: #if PETSC_SIZEOF_SIZE_T == 4
280:   #define PETSC_COUNT_MIN INT_MIN
281:   #define PETSC_COUNT_MAX INT_MAX
282: #else
283:   #define PETSC_COUNT_MIN PETSC_INT64_MIN
284:   #define PETSC_COUNT_MAX PETSC_INT64_MAX
285: #endif

287: typedef int32_t PetscInt32;
288: #define PETSC_INT32_MIN INT32_MIN
289: #define PETSC_INT32_MAX INT32_MAX

291: #if defined(PETSC_USE_64BIT_INDICES)
292: typedef PetscInt64 PetscInt;

294:   #define PETSC_INT_MIN PETSC_INT64_MIN
295:   #define PETSC_INT_MAX PETSC_INT64_MAX
296:   #define PetscInt_FMT  PetscInt64_FMT
297: #else
298: typedef int PetscInt;

300: enum {
301:   PETSC_INT_MIN = INT_MIN,
302:   PETSC_INT_MAX = INT_MAX
303: };
304:   #define PetscInt_FMT "d"
305: #endif

307: #define PETSC_UINT16_MAX 65535

309: /* deprecated */
310: #define PETSC_MIN_INT    PETSC_INT_MIN
311: #define PETSC_MAX_INT    PETSC_INT_MAX
312: #define PETSC_MAX_UINT16 PETSC_UINT16_MAX

314: #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && (defined(PETSC_HAVE_MPIUNI) || defined(PETSC_HAVE_MPI_INT64_T)) /* MPI_INT64_T is not guaranteed to be a macro */
315:   #define MPIU_INT64     MPI_INT64_T
316:   #define PetscInt64_FMT PRId64
317: #elif (PETSC_SIZEOF_LONG_LONG == 8)
318:   #define MPIU_INT64     MPI_LONG_LONG_INT
319:   #define PetscInt64_FMT "lld"
320: #elif defined(PETSC_HAVE___INT64)
321:   #define MPIU_INT64     MPI_INT64_T
322:   #define PetscInt64_FMT "ld"
323: #else
324:   #error "cannot determine PetscInt64 type"
325: #endif

327: #define MPIU_INT32     MPI_INT32_T
328: #define PetscInt32_FMT PRId32

330: /*MC
331:    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.

333:    Level: intermediate

335:    Notes:
336:    Usually this is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
337:    standard C/Fortran integers are 32-bit then this may not be the same as `PetscInt`,
338:    except on some BLAS/LAPACK implementations that support 64-bit integers see the notes below.

340:    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
341:     generates a `PETSC_ERR_ARG_OUTOFRANGE` error

343:    Installation Notes\:
344:    ./configure automatically determines the size of the integers used by BLAS/LAPACK except when `--with-batch` is used
345:    in that situation one must know (by some other means) if the integers used by BLAS/LAPACK are 64-bit and if so pass the flag `--known-64-bit-blas-indices`

347:    MATLAB ships with BLAS and LAPACK that use 64-bit integers, for example if you run ./configure with, the option
348:     `--with-blaslapack-lib`=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]

350:    MKL ships with both 32 and 64-bit integer versions of the BLAS and LAPACK. If you pass the flag `-with-64-bit-blas-indices` PETSc will link
351:    against the 64-bit version, otherwise it uses the 32-bit version

353:    OpenBLAS can be built to use 64-bit integers. The ./configure options `--download-openblas` `-with-64-bit-blas-indices` will build a 64-bit integer version

355:    External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64-bit integers to BLAS/LAPACK so cannot
356:    be used with PETSc when PETSc links against 64-bit integer BLAS/LAPACK. ./configure will generate an error if you attempt to link PETSc against any of
357:    these external libraries while using 64-bit integer BLAS/LAPACK.

359: .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
360: M*/
361: #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
362: typedef PetscInt64 PetscBLASInt;

364:   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
365:   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
366:   #define PetscBLASInt_FMT   PetscInt64_FMT
367: #else
368: typedef int PetscBLASInt;

370: enum {
371:   PETSC_BLAS_INT_MIN = INT_MIN,
372:   PETSC_BLAS_INT_MAX = INT_MAX
373: };

375:   #define PetscBLASInt_FMT "d"
376: #endif

378: /*MC
379:    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.

381:    Level: intermediate

383:    Notes:
384:    As of this writing `PetscCuBLASInt` is always the system `int`.

386:   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
387:    generates a `PETSC_ERR_ARG_OUTOFRANGE` error

389: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
390: M*/
391: typedef int PetscCuBLASInt;

393: enum {
394:   PETSC_CUBLAS_INT_MIN = INT_MIN,
395:   PETSC_CUBLAS_INT_MAX = INT_MAX
396: };

398: /*MC
399:    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.

401:    Level: intermediate

403:    Notes:
404:    `PetscHipBLASInt` is always the system `int`.

406:    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
407:    generates a `PETSC_ERR_ARG_OUTOFRANGE` error

409: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscHipBLASIntCast()`
410: M*/
411: typedef int PetscHipBLASInt;

413: enum {
414:   PETSC_HIPBLAS_INT_MIN = INT_MIN,
415:   PETSC_HIPBLAS_INT_MAX = INT_MAX
416: };

418: /*MC
419:    PetscExodusIIInt - datatype used to represent 'int' parameters to ExodusII functions.

421:    Level: intermediate

423:    Notes:
424:    This is the same as `int`

426: .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIFloat`, `PetscBLASIntCast()`
427: M*/
428: typedef int PetscExodusIIInt;
429: #define PetscExodusIIInt_FMT "d"

431: /*MC
432:    PetscExodusIIFloat - datatype used to represent 'float' parameters to ExodusII functions.

434:    Level: intermediate

436:    Notes:
437:    This is the same as `float`

439: .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIInt`, `PetscBLASIntCast()`
440: M*/
441: typedef float PetscExodusIIFloat;

443: /*E
444:    PetscBool  - Logical variable. Actually an enum in C and a logical in Fortran.

446:    Level: beginner

448:    Developer Note:
449:    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
450:    Boolean values. It is not easy to have a simple macro that will work properly in all circumstances with all three mechanisms.

452: .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
453: E*/
454: typedef enum {
455:   PETSC_FALSE,
456:   PETSC_TRUE
457: } PetscBool;
458: PETSC_EXTERN const char *const PetscBools[];

460: /*E
461:    PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.

463:    Level: beginner

465:    Note:
466:    Should not be used with the if (flg) or if (!flg) syntax.

468: .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
469: E*/
470: typedef enum {
471:   PETSC_BOOL3_FALSE,
472:   PETSC_BOOL3_TRUE,
473:   PETSC_BOOL3_UNKNOWN = -1 /* the value is unknown at the time of query, but might be determined later */
474: } PetscBool3;

476: #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
477: #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)

479: /*MC
480:    PetscReal - PETSc type that represents a real number version of `PetscScalar`

482:    Level: beginner

484:    Notes:
485:    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
486:    They will automatically work correctly regardless of the size of `PetscReal`.

488:    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.

490: .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
491: M*/

493: #if defined(PETSC_USE_REAL_SINGLE)
494: typedef float PetscReal;
495: #elif defined(PETSC_USE_REAL_DOUBLE)
496: typedef double PetscReal;
497: #elif defined(PETSC_USE_REAL___FLOAT128)
498:   #if defined(__cplusplus)
499: extern "C" {
500:   #endif
501:   #include <quadmath.h>
502:   #if defined(__cplusplus)
503: }
504:   #endif
505: typedef __float128 PetscReal;
506: #elif defined(PETSC_USE_REAL___FP16)
507: typedef __fp16 PetscReal;
508: #endif /* PETSC_USE_REAL_* */

510: /*MC
511:    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.

513:    Synopsis:
514: #include <petscsys.h>
515:    PetscComplex number = 1. + 2.*PETSC_i;

517:    Level: beginner

519:    Notes:
520:    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
521:    They will automatically work correctly regardless of the size of `PetscComplex`.

523:    See `PetscScalar` for details on how to ./configure the size of `PetscReal`

525:    Complex numbers are automatically available if PETSc was able to find a working complex implementation

527:     PETSc has a 'fix' for complex numbers to support expressions such as `std::complex<PetscReal>` + `PetscInt`, which are not supported by the standard
528:     C++ library, but are convenient for petsc users. If the C++ compiler is able to compile code in `petsccxxcomplexfix.h` (This is checked by
529:     configure), we include `petsccxxcomplexfix.h` to provide this convenience.

531:     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`
532:     at the beginning of the C++ file to skip the fix.

534: .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
535: M*/
536: #if !defined(PETSC_SKIP_COMPLEX)
537:   #if defined(PETSC_CLANGUAGE_CXX)
538:     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
539:       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
540:         #define PETSC_HAVE_COMPLEX 1
541:       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
542:         #define PETSC_HAVE_COMPLEX 1
543:       #endif
544:     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
545:       #define PETSC_HAVE_COMPLEX 1
546:     #endif
547:   #else /* !PETSC_CLANGUAGE_CXX */
548:     #if !defined(PETSC_USE_REAL___FP16)
550:         #define PETSC_HAVE_COMPLEX 1
551:       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
552:         #define PETSC_HAVE_COMPLEX 1
553:       #endif
554:     #endif
555:   #endif /* PETSC_CLANGUAGE_CXX */
556: #endif   /* !PETSC_SKIP_COMPLEX */

558: #if defined(PETSC_HAVE_COMPLEX)
559:   #if defined(__cplusplus) /* C++ complex support */
560:     /* Locate a C++ complex template library */
561:     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
562:       #define petsccomplexlib Kokkos
563:       #include <Kokkos_Complex.hpp>
564:     #elif (defined(__CUDACC__) && defined(PETSC_HAVE_CUDA)) || (defined(__HIPCC__) && defined(PETSC_HAVE_HIP))
565:       #define petsccomplexlib thrust
566:       #include <thrust/complex.h>
567:     #elif defined(PETSC_USE_REAL___FLOAT128)
568:       #include <complex.h>
569:     #else
570:       #define petsccomplexlib std
571:       #include <complex>
572:     #endif

574:     /* Define PetscComplex based on the precision */
575:     #if defined(PETSC_USE_REAL_SINGLE)
576: typedef petsccomplexlib::complex<float> PetscComplex;
577:     #elif defined(PETSC_USE_REAL_DOUBLE)
578: typedef petsccomplexlib::complex<double> PetscComplex;
579:     #elif defined(PETSC_USE_REAL___FLOAT128)
580: typedef __complex128 PetscComplex;
581:     #endif

583:     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
584:     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
585: #include <petsccxxcomplexfix.h>
586:     #endif
587:   #else /* c99 complex support */
588:     #include <complex.h>
589:     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
590: typedef float _Complex PetscComplex;
591:     #elif defined(PETSC_USE_REAL_DOUBLE)
592: typedef double _Complex PetscComplex;
593:     #elif defined(PETSC_USE_REAL___FLOAT128)
594: typedef __complex128 PetscComplex;
595:     #endif /* PETSC_USE_REAL_* */
596:   #endif   /* !__cplusplus */
597: #endif     /* PETSC_HAVE_COMPLEX */

599: /*MC
600:    PetscScalar - PETSc type that represents either a double precision real number, a double precision
601:                  complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
602:                  with `--with-scalar-type`=real,complex `--with-precision`=single,double,__float128,__fp16

604:    Level: beginner

606:    Note:
607:    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`.

609: .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
610: M*/

612: #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
613: typedef PetscComplex PetscScalar;
614: #else  /* PETSC_USE_COMPLEX */
615: typedef PetscReal PetscScalar;
616: #endif /* PETSC_USE_COMPLEX */

618: /*E
619:     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`

621:    Values for array input:
622: +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
623: .   `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
624:                           delete the array. The array MUST have been obtained with `PetscMalloc()`. Hence this mode cannot be used in Fortran.
625: -   `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
626:                           the array but the user must delete the array after the object is destroyed.

628:    Values for PetscObject:
629: +   `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.
630: .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
631:                           increases its reference count).
632: -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.

634:    Level: beginner

636: .seealso: `PetscInsertMode`
637: E*/
638: typedef enum {
639:   PETSC_COPY_VALUES,
640:   PETSC_OWN_POINTER,
641:   PETSC_USE_POINTER
642: } PetscCopyMode;
643: PETSC_EXTERN const char *const PetscCopyModes[];

645: /*MC
646:     PETSC_FALSE - False value of `PetscBool`

648:     Level: beginner

650:     Note:
651:     Zero integer

653: .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
654: M*/

656: /*MC
657:     PETSC_TRUE - True value of `PetscBool`

659:     Level: beginner

661:     Note:
662:     Nonzero integer

664: .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
665: M*/

667: /*MC
668:     PetscLogDouble - Used for logging times

670:   Level: developer

672:   Note:
673:   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.

675: .seealso: `PetscBool`, `PetscDataType`
676: M*/
677: typedef double PetscLogDouble;

679: /*E
680:     PetscDataType - Used for handling different basic data types.

682:    Level: beginner

684:    Notes:
685:    Use of this should be avoided if one can directly use `MPI_Datatype` instead.

687:    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
688:    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.

690:    Developer Notes:
691:    It would be nice if we could always just use MPI Datatypes, why can we not?

693:    If you change any values in `PetscDatatype` make sure you update their usage in
694:    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m

696:    TODO:
697:    Remove use of improper `PETSC_ENUM`

699: .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
700:           `PetscDataTypeGetSize()`
701: E*/
702: typedef enum {
703:   PETSC_DATATYPE_UNKNOWN = 0,
704:   PETSC_DOUBLE           = 1,
705:   PETSC_COMPLEX          = 2,
706:   PETSC_LONG             = 3,
707:   PETSC_SHORT            = 4,
708:   PETSC_FLOAT            = 5,
709:   PETSC_CHAR             = 6,
710:   PETSC_BIT_LOGICAL      = 7,
711:   PETSC_ENUM             = 8,
712:   PETSC_BOOL             = 9,
713:   PETSC___FLOAT128       = 10,
714:   PETSC_OBJECT           = 11,
715:   PETSC_FUNCTION         = 12,
716:   PETSC_STRING           = 13,
717:   PETSC___FP16           = 14,
718:   PETSC_STRUCT           = 15,
719:   PETSC_INT              = 16,
720:   PETSC_INT64            = 17,
721:   PETSC_COUNT            = 18,
722:   PETSC_INT32            = 19,
723: } PetscDataType;
724: PETSC_EXTERN const char *const PetscDataTypes[];

726: #if defined(PETSC_USE_REAL_SINGLE)
727:   #define PETSC_REAL PETSC_FLOAT
728: #elif defined(PETSC_USE_REAL_DOUBLE)
729:   #define PETSC_REAL PETSC_DOUBLE
730: #elif defined(PETSC_USE_REAL___FLOAT128)
731:   #define PETSC_REAL PETSC___FLOAT128
732: #elif defined(PETSC_USE_REAL___FP16)
733:   #define PETSC_REAL PETSC___FP16
734: #else
735:   #define PETSC_REAL PETSC_DOUBLE
736: #endif

738: #if defined(PETSC_USE_COMPLEX)
739:   #define PETSC_SCALAR PETSC_COMPLEX
740: #else
741:   #define PETSC_SCALAR PETSC_REAL
742: #endif

744: #define PETSC_FORTRANADDR PETSC_LONG

746: /*S
747:   PetscToken - 'Token' used for managing tokenizing strings

749:   Level: intermediate

751: .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
752: S*/
753: typedef struct _p_PetscToken *PetscToken;

755: /*S
756:    PetscObject - any PETSc object, `PetscViewer`, `Mat`, `Vec`, `KSP` etc

758:    Level: beginner

760:    Notes:
761:    This is the base class from which all PETSc objects are derived from.

763:    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec

765: .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
766: S*/
767: typedef struct _p_PetscObject *PetscObject;

769: /*MC
770:     PetscObjectId - unique integer Id for a `PetscObject`

772:     Level: developer

774:     Note:
775:     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
776:     if the objects are the same. Never compare two object pointer values.

778: .seealso: `PetscObjectState`, `PetscObjectGetId()`
779: M*/
780: typedef PetscInt64 PetscObjectId;

782: /*MC
783:     PetscObjectState - integer state for a `PetscObject`

785:     Level: developer

787:     Note:
788:     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
789:     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.

791: .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
792: M*/
793: typedef PetscInt64 PetscObjectState;

795: /*S
796:      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
797:       by string name

799:    Level: advanced

801: .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
802: S*/
803: typedef struct _n_PetscFunctionList *PetscFunctionList;

805: /*E
806:   PetscFileMode - Access mode for a file.

808:   Values:
809: +  `FILE_MODE_UNDEFINED`     - initial invalid value
810: .  `FILE_MODE_READ`          - open a file at its beginning for reading
811: .  `FILE_MODE_WRITE`         - open a file at its beginning for writing (will create if the file does not exist)
812: .  `FILE_MODE_APPEND`        - open a file at end for writing
813: .  `FILE_MODE_UPDATE`        - open a file for updating, meaning for reading and writing
814: -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end

816:   Level: beginner

818: .seealso: `PetscViewerFileSetMode()`
819: E*/
820: typedef enum {
821:   FILE_MODE_UNDEFINED = -1,
822:   FILE_MODE_READ      = 0,
823:   FILE_MODE_WRITE,
824:   FILE_MODE_APPEND,
825:   FILE_MODE_UPDATE,
826:   FILE_MODE_APPEND_UPDATE
827: } PetscFileMode;
828: PETSC_EXTERN const char *const PetscFileModes[];

830: typedef void *PetscDLHandle;
831: typedef enum {
832:   PETSC_DL_DECIDE = 0,
833:   PETSC_DL_NOW    = 1,
834:   PETSC_DL_LOCAL  = 2
835: } PetscDLMode;

837: /*S
838:    PetscObjectList - Linked list of PETSc objects, each accessible by string name

840:    Level: developer

842:    Note:
843:    Used by `PetscObjectCompose()` and `PetscObjectQuery()`

845: .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
846: S*/
847: typedef struct _n_PetscObjectList *PetscObjectList;

849: /*S
850:    PetscDLLibrary - Linked list of dynamic libraries to search for functions

852:    Level: developer

854: .seealso: `PetscDLLibraryOpen()`
855: S*/
856: typedef struct _n_PetscDLLibrary *PetscDLLibrary;

858: /*S
859:    PetscContainer - Simple PETSc object that contains a pointer to any required data

861:    Level: advanced

863:    Note:
864:    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`

866: .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
867: S*/
868: typedef struct _p_PetscContainer *PetscContainer;

870: /*S
871:    PetscRandom - Abstract PETSc object that manages generating random numbers

873:    Level: intermediate

875: .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
876: S*/
877: typedef struct _p_PetscRandom *PetscRandom;

879: /*
880:    In binary files variables are stored using the following lengths,
881:   regardless of how they are stored in memory on any one particular
882:   machine. Use these rather than sizeof() in computing sizes for
883:   PetscBinarySeek().
884: */
885: #define PETSC_BINARY_INT_SIZE    (32 / 8)
886: #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
887: #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
888: #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
889: #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
890: #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)

892: /*E
893:   PetscBinarySeekType - argument to `PetscBinarySeek()`

895:   Values:
896: +  `PETSC_BINARY_SEEK_SET` - offset is an absolute location in the file
897: .  `PETSC_BINARY_SEEK_CUR` - offset is an offset from the current location of the file pointer
898: -  `PETSC_BINARY_SEEK_END` - offset is an offset from the end of the file

900:   Level: advanced

902: .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
903: E*/
904: typedef enum {
905:   PETSC_BINARY_SEEK_SET = 0,
906:   PETSC_BINARY_SEEK_CUR = 1,
907:   PETSC_BINARY_SEEK_END = 2
908: } PetscBinarySeekType;

910: /*E
911:    PetscBuildTwoSidedType - algorithm for setting up two-sided communication for use with `PetscSF`

913:    Values:
914: +  `PETSC_BUILDTWOSIDED_ALLREDUCE`  - classical algorithm using an `MPI_Allreduce()` with
915:                                       a buffer of length equal to the communicator size. Not memory-scalable due to
916:                                       the large reduction size. Requires only an MPI-1 implementation.
917: .  `PETSC_BUILDTWOSIDED_IBARRIER`   - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
918:                                       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires an MPI-3 implementation.
919: -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
920:                                       that only communicates the part of the reduction that is necessary.  Requires an MPI-2 implementation.

922:    Level: developer

924: .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
925: E*/
926: typedef enum {
927:   PETSC_BUILDTWOSIDED_NOTSET     = -1,
928:   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
929:   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
930:   PETSC_BUILDTWOSIDED_REDSCATTER = 2
931:   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
932: } PetscBuildTwoSidedType;
933: PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];

935: /* NOTE: If you change this, you must also change the values in src/vec/f90-mod/petscvec.h */
936: /*E
937:   InsertMode - How the entries are combined with the current values in the vectors or matrices

939:   Values:
940: +  `NOT_SET_VALUES`    - do not actually use the values
941: .  `INSERT_VALUES`     - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
942: .  `ADD_VALUES`        - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
943: .  `MAX_VALUES`        - use the maximum of each current value and provided value
944: .  `MIN_VALUES`        - use the minimum of each current value and provided value
945: .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
946: .  `ADD_ALL_VALUES`    - add, even if indices that are not marked as constrained by the `PetscSection`
947: .  `INSERT_BC_VALUES`  - insert, but ignore indices that are not marked as constrained by the `PetscSection`
948: -  `ADD_BC_VALUES`     - add, but ignore indices that are not marked as constrained by the `PetscSection`

950:   Level: beginner

952:   Note:
953:   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
954:   and `DMGetLocalSection()`.

956:   Not all options are supported for all operations or PETSc object types.

958: .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
959:           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
960:           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
961: E*/
962: typedef enum {
963:   NOT_SET_VALUES,
964:   INSERT_VALUES,
965:   ADD_VALUES,
966:   MAX_VALUES,
967:   MIN_VALUES,
968:   INSERT_ALL_VALUES,
969:   ADD_ALL_VALUES,
970:   INSERT_BC_VALUES,
971:   ADD_BC_VALUES
972: } InsertMode;

974: /*MC
975:     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value

977:     Level: beginner

979: .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
980:           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
981:           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
982: M*/

984: /*MC
985:     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
986:                  value into that location

988:     Level: beginner

990: .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
991:           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
992:           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
993: M*/

995: /*MC
996:     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location

998:     Level: beginner

1000: .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1001: M*/

1003: /*MC
1004:     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location

1006:     Level: beginner

1008: .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1009: M*/

1011: /*S
1012:    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators

1014:    Values:
1015: +   `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
1016: .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
1017: -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator

1019:    Sample Usage:
1020: .vb
1021:        PetscSubcommCreate()
1022:        PetscSubcommSetNumber()
1023:        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
1024:        ccomm = PetscSubcommChild()
1025:        PetscSubcommDestroy()
1026: .ve

1028:    Example:
1029:    Consider a communicator with six processes split into 3 subcommunicators.
1030: .vb
1031:    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
1032:    PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
1033: .ve

1035:    Level: advanced

1037:    Note:
1038:    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
1039: .vb
1040:      PetscSubcommChild() returns the associated subcommunicator on this process
1041:      PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
1042: .ve

1044:    Developer Note:
1045:    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
1046:    are performed.

1048: .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
1049: S*/
1050: typedef struct _n_PetscSubcomm *PetscSubcomm;
1051: typedef enum {
1052:   PETSC_SUBCOMM_GENERAL    = 0,
1053:   PETSC_SUBCOMM_CONTIGUOUS = 1,
1054:   PETSC_SUBCOMM_INTERLACED = 2
1055: } PetscSubcommType;
1056: PETSC_EXTERN const char *const PetscSubcommTypes[];

1058: /*S
1059:    PetscHeap - A simple class for managing heaps

1061:    Level: intermediate

1063: .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1064: S*/
1065: typedef struct _PetscHeap *PetscHeap;

1067: typedef struct _n_PetscShmComm *PetscShmComm;
1068: typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;

1070: /*S
1071:    PetscSegBuffer - a segmented extendable buffer

1073:    Level: developer

1075: .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1076: S*/
1077: typedef struct _n_PetscSegBuffer *PetscSegBuffer;

1079: typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;

1081: /*S
1082:      PetscBT - PETSc bitarrays, efficient storage of arrays of boolean values

1084:      Level: advanced

1086:      Notes:
1087:      The following routines do not have their own manual pages

1089: .vb
1090:      PetscBTCreate(m,&bt)         - creates a bit array with enough room to hold m values
1091:      PetscBTDestroy(&bt)          - destroys the bit array
1092:      PetscBTMemzero(m,bt)         - zeros the entire bit array (sets all values to false)
1093:      PetscBTSet(bt,index)         - sets a particular entry as true
1094:      PetscBTClear(bt,index)       - sets a particular entry as false
1095:      PetscBTLookup(bt,index)      - returns the value
1096:      PetscBTLookupSet(bt,index)   - returns the value and then sets it true
1097:      PetscBTLookupClear(bt,index) - returns the value and then sets it false
1098:      PetscBTLength(m)             - returns number of bytes in array with m bits
1099:      PetscBTView(m,bt,viewer)     - prints all the entries in a bit array
1100: .ve

1102:     PETSc does not check error flags on `PetscBTLookup()`, `PetcBTLookupSet()`, `PetscBTLength()` because error checking
1103:     would cost hundreds more cycles then the operation.

1105: S*/
1106: typedef char *PetscBT;

1108: /* The number of bits in a byte */
1109: #define PETSC_BITS_PER_BYTE CHAR_BIT