xref: /petsc/include/petscsystypes.h (revision 5440e5dcf30153d9ab6dbf994494f40b7f9df88b)
147d993e7Ssuyashtn /* Portions of this code are under:
247d993e7Ssuyashtn    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
347d993e7Ssuyashtn */
447d993e7Ssuyashtn 
5a4963045SJacob Faibussowitsch #pragma once
6df4397b0SStefano Zampini 
7df4397b0SStefano Zampini #include <petscconf.h>
8e1bf4ed2SJacob Faibussowitsch #include <petscconf_poison.h>
9df4397b0SStefano Zampini #include <petscfix.h>
103ba16761SJacob Faibussowitsch #include <petscmacros.h> // PETSC_NODISCARD, PETSC_CPP_VERSION
113edda6a2SJed Brown #include <stddef.h>
121dc74096SMartin Diehl #include <stdbool.h>
13df4397b0SStefano Zampini 
14ac09b921SBarry Smith /* SUBMANSEC = Sys */
15ac09b921SBarry Smith 
16778ae69aSToby Isaac #include <limits.h> // INT_MIN, INT_MAX, CHAR_BIT
173ba16761SJacob Faibussowitsch 
183ba16761SJacob Faibussowitsch #if defined(__clang__) || (PETSC_CPP_VERSION >= 17)
193ba16761SJacob Faibussowitsch   // clang allows both [[nodiscard]] and __attribute__((warn_unused_result)) on type
203ba16761SJacob Faibussowitsch   // definitions. GCC, however, does not, so check that we are using C++17 [[nodiscard]]
213ba16761SJacob Faibussowitsch   // instead of __attribute__((warn_unused_result))
223ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_NODISCARD PETSC_NODISCARD
233ba16761SJacob Faibussowitsch #else
243ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_NODISCARD
253ba16761SJacob Faibussowitsch #endif
263ba16761SJacob Faibussowitsch 
278a7d4faaSJacob Faibussowitsch #ifdef PETSC_CLANG_STATIC_ANALYZER
288a7d4faaSJacob Faibussowitsch   #undef PETSC_USE_STRICT_PETSCERRORCODE
298a7d4faaSJacob Faibussowitsch #endif
308a7d4faaSJacob Faibussowitsch 
313ba16761SJacob Faibussowitsch #ifdef PETSC_USE_STRICT_PETSCERRORCODE
323ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_TYPEDEF   typedef
333ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_ENUM_NAME PetscErrorCode
343ba16761SJacob Faibussowitsch #else
353ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_TYPEDEF
363ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_ENUM_NAME
373ba16761SJacob Faibussowitsch #endif
383ba16761SJacob Faibussowitsch 
393ba16761SJacob Faibussowitsch /*E
403ba16761SJacob Faibussowitsch   PetscErrorCode - Datatype used to return PETSc error codes.
41df4397b0SStefano Zampini 
42df4397b0SStefano Zampini   Level: beginner
43df4397b0SStefano Zampini 
443ba16761SJacob Faibussowitsch   Notes:
453ba16761SJacob Faibussowitsch   Virtually all PETSc functions return an error code. It is the callers responsibility to check
463ba16761SJacob Faibussowitsch   the value of the returned error code after each PETSc call to determine if any errors
473ba16761SJacob Faibussowitsch   occurred. A set of convenience macros (e.g. `PetscCall()`, `PetscCallVoid()`) are provided
483ba16761SJacob Faibussowitsch   for this purpose. Failing to properly check for errors is not supported, as errors may leave
493ba16761SJacob Faibussowitsch   PETSc in an undetermined state.
503ba16761SJacob Faibussowitsch 
513ba16761SJacob Faibussowitsch   One can retrieve the error string corresponding to a particular error code using
523ba16761SJacob Faibussowitsch   `PetscErrorMessage()`.
533ba16761SJacob Faibussowitsch 
543ba16761SJacob Faibussowitsch   The user can also configure PETSc with the `--with-strict-petscerrorcode` option to enable
553ba16761SJacob Faibussowitsch   compiler warnings when the returned error codes are not captured and checked. Users are
563ba16761SJacob Faibussowitsch   *heavily* encouraged to opt-in to this option, as it will become enabled by default in a
573ba16761SJacob Faibussowitsch   future release.
583ba16761SJacob Faibussowitsch 
593ba16761SJacob Faibussowitsch   Developer Notes:
603ba16761SJacob Faibussowitsch   These are the generic error codes. These error codes are used in many different places in the
613ba16761SJacob Faibussowitsch   PETSc source code. The C-string versions are at defined in `PetscErrorStrings[]` in
6216a05f60SBarry Smith   `src/sys/error/err.c`, while the Fortran versions are defined in
636dd63270SBarry Smith   `src/sys/ftn-mod/petscerror.h`. Any changes here must also be made in both locations.
643ba16761SJacob Faibussowitsch 
653ba16761SJacob Faibussowitsch .seealso: `PetscErrorMessage()`, `PetscCall()`, `SETERRQ()`
663ba16761SJacob Faibussowitsch E*/
673ba16761SJacob Faibussowitsch PETSC_ERROR_CODE_TYPEDEF enum PETSC_ERROR_CODE_NODISCARD {
683ba16761SJacob Faibussowitsch   PETSC_SUCCESS                   = 0,
693ba16761SJacob Faibussowitsch   PETSC_ERR_BOOLEAN_MACRO_FAILURE = 1, /* do not use */
703ba16761SJacob Faibussowitsch 
71467446fbSPierre Jolivet   PETSC_ERR_MIN_VALUE = 54, /* should always be one less than the smallest value */
723ba16761SJacob Faibussowitsch 
733ba16761SJacob Faibussowitsch   PETSC_ERR_MEM            = 55, /* unable to allocate requested memory */
743ba16761SJacob Faibussowitsch   PETSC_ERR_SUP            = 56, /* no support for requested operation */
753ba16761SJacob Faibussowitsch   PETSC_ERR_SUP_SYS        = 57, /* no support for requested operation on this computer system */
763ba16761SJacob Faibussowitsch   PETSC_ERR_ORDER          = 58, /* operation done in wrong order */
773ba16761SJacob Faibussowitsch   PETSC_ERR_SIG            = 59, /* signal received */
783ba16761SJacob Faibussowitsch   PETSC_ERR_FP             = 72, /* floating point exception */
793ba16761SJacob Faibussowitsch   PETSC_ERR_COR            = 74, /* corrupted PETSc object */
803ba16761SJacob Faibussowitsch   PETSC_ERR_LIB            = 76, /* error in library called by PETSc */
813ba16761SJacob Faibussowitsch   PETSC_ERR_PLIB           = 77, /* PETSc library generated inconsistent data */
823ba16761SJacob Faibussowitsch   PETSC_ERR_MEMC           = 78, /* memory corruption */
833ba16761SJacob Faibussowitsch   PETSC_ERR_CONV_FAILED    = 82, /* iterative method (KSP or SNES) failed */
843ba16761SJacob Faibussowitsch   PETSC_ERR_USER           = 83, /* user has not provided needed function */
853ba16761SJacob Faibussowitsch   PETSC_ERR_SYS            = 88, /* error in system call */
863ba16761SJacob Faibussowitsch   PETSC_ERR_POINTER        = 70, /* pointer does not point to valid address */
873ba16761SJacob Faibussowitsch   PETSC_ERR_MPI_LIB_INCOMP = 87, /* MPI library at runtime is not compatible with MPI user compiled with */
883ba16761SJacob Faibussowitsch 
893ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_SIZ          = 60, /* nonconforming object sizes used in operation */
903ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_IDN          = 61, /* two arguments not allowed to be the same */
913ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONG        = 62, /* wrong argument (but object probably ok) */
923ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_CORRUPT      = 64, /* null or corrupted PETSc object as argument */
933ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_OUTOFRANGE   = 63, /* input argument, out of range */
943ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_BADPTR       = 68, /* invalid pointer argument */
953ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMETYPE  = 69, /* two args must be same object type */
963ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMECOMM  = 80, /* two args must be same communicators */
973ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONGSTATE   = 73, /* object in argument is in wrong state, e.g. unassembled mat */
983ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_TYPENOTSET   = 89, /* the type of the object has not yet been set */
993ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_INCOMP       = 75, /* two arguments are incompatible */
1003ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NULL         = 85, /* argument is null that should not be */
1013ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_UNKNOWN_TYPE = 86, /* type name doesn't match any registered type */
1023ba16761SJacob Faibussowitsch 
1033ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_OPEN       = 65, /* unable to open file */
1043ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_READ       = 66, /* unable to read from file */
1053ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_WRITE      = 67, /* unable to write to file */
1063ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_UNEXPECTED = 79, /* unexpected data in file */
1073ba16761SJacob Faibussowitsch 
1083ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_LU_ZRPVT = 71, /* detected a zero pivot during LU factorization */
1093ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_CH_ZRPVT = 81, /* detected a zero pivot during Cholesky factorization */
1103ba16761SJacob Faibussowitsch 
1113ba16761SJacob Faibussowitsch   PETSC_ERR_INT_OVERFLOW   = 84,
1123ba16761SJacob Faibussowitsch   PETSC_ERR_FLOP_COUNT     = 90,
1133ba16761SJacob Faibussowitsch   PETSC_ERR_NOT_CONVERGED  = 91,  /* solver did not converge */
1143ba16761SJacob Faibussowitsch   PETSC_ERR_MISSING_FACTOR = 92,  /* MatGetFactor() failed */
1153ba16761SJacob Faibussowitsch   PETSC_ERR_OPT_OVERWRITE  = 93,  /* attempted to over write options which should not be changed */
1163ba16761SJacob Faibussowitsch   PETSC_ERR_WRONG_MPI_SIZE = 94,  /* example/application run with number of MPI ranks it does not support */
1173ba16761SJacob Faibussowitsch   PETSC_ERR_USER_INPUT     = 95,  /* missing or incorrect user input */
1183ba16761SJacob Faibussowitsch   PETSC_ERR_GPU_RESOURCE   = 96,  /* unable to load a GPU resource, for example cuBLAS */
1193ba16761SJacob Faibussowitsch   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 */
1203ba16761SJacob Faibussowitsch   PETSC_ERR_MPI            = 98,  /* general MPI error */
1213ba16761SJacob Faibussowitsch   PETSC_ERR_RETURN         = 99,  /* PetscError() incorrectly returned an error code of 0 */
1229beb8f72SToby Isaac   PETSC_ERR_MEM_LEAK       = 100, /* memory alloc/free imbalance */
1234237731aSLisandro Dalcin   PETSC_ERR_PYTHON         = 101, /* Exception in Python */
1244237731aSLisandro Dalcin   PETSC_ERR_MAX_VALUE      = 102, /* this is always the one more than the largest error code */
1253ba16761SJacob Faibussowitsch 
1263ba16761SJacob Faibussowitsch   /*
1273ba16761SJacob Faibussowitsch     do not use, exist purely to make the enum bounds equal that of a regular int (so conversion
1283ba16761SJacob Faibussowitsch     to int in main() is not undefined behavior)
1293ba16761SJacob Faibussowitsch   */
1303ba16761SJacob Faibussowitsch   PETSC_ERR_MIN_SIGNED_BOUND_DO_NOT_USE = INT_MIN,
1313ba16761SJacob Faibussowitsch   PETSC_ERR_MAX_SIGNED_BOUND_DO_NOT_USE = INT_MAX
1323ba16761SJacob Faibussowitsch } PETSC_ERROR_CODE_ENUM_NAME;
1333ba16761SJacob Faibussowitsch 
1343ba16761SJacob Faibussowitsch #ifndef PETSC_USE_STRICT_PETSCERRORCODE
135df4397b0SStefano Zampini typedef int PetscErrorCode;
136df4397b0SStefano Zampini 
1373ba16761SJacob Faibussowitsch   /*
1383ba16761SJacob Faibussowitsch   Needed so that C++ lambdas can deduce the return type as PetscErrorCode from
1393ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS). Otherwise we get
1403ba16761SJacob Faibussowitsch 
1413ba16761SJacob Faibussowitsch   error: return type '(unnamed enum at include/petscsystypes.h:50:1)' must match previous
1423ba16761SJacob Faibussowitsch   return type 'int' when lambda expression has unspecified explicit return type
1433ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1443ba16761SJacob Faibussowitsch   ^
1453ba16761SJacob Faibussowitsch */
1463ba16761SJacob Faibussowitsch   #define PETSC_SUCCESS ((PetscErrorCode)0)
1473ba16761SJacob Faibussowitsch #endif
1483ba16761SJacob Faibussowitsch 
1493ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_NODISCARD
1503ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_TYPEDEF
1513ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_ENUM_NAME
1523ba16761SJacob Faibussowitsch 
153df4397b0SStefano Zampini /*MC
154df4397b0SStefano Zampini     PetscClassId - A unique id used to identify each PETSc class.
155df4397b0SStefano Zampini 
15616a05f60SBarry Smith     Level: developer
15716a05f60SBarry Smith 
15816a05f60SBarry Smith     Note:
15987497f52SBarry Smith     Use `PetscClassIdRegister()` to obtain a new value for a new class being created. Usually
160df4397b0SStefano Zampini     XXXInitializePackage() calls it for each class it defines.
161df4397b0SStefano Zampini 
16216a05f60SBarry Smith     Developer Note:
163667f096bSBarry Smith     Internal integer stored in the `_p_PetscObject` data structure. These are all computed by an offset from the lowest one, `PETSC_SMALLEST_CLASSID`.
164df4397b0SStefano Zampini 
165db781477SPatrick Sanan .seealso: `PetscClassIdRegister()`, `PetscLogEventRegister()`, `PetscHeaderCreate()`
166df4397b0SStefano Zampini M*/
167df4397b0SStefano Zampini typedef int PetscClassId;
168df4397b0SStefano Zampini 
169df4397b0SStefano Zampini /*MC
170df4397b0SStefano Zampini     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
171df4397b0SStefano Zampini 
172df4397b0SStefano Zampini     Level: intermediate
173df4397b0SStefano Zampini 
174df4397b0SStefano Zampini     Notes:
1757de69702SBarry Smith     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
1767de69702SBarry Smith     standard C/Fortran integers are 32-bit then this is NOT the same as `PetscInt`; it remains 32-bit.
177df4397b0SStefano Zampini 
17887497f52SBarry Smith     `PetscMPIIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscMPIInt`, if not it
17987497f52SBarry Smith     generates a `PETSC_ERR_ARG_OUTOFRANGE` error.
180df4397b0SStefano Zampini 
1816a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscInt`, `PetscMPIIntCast()`
182df4397b0SStefano Zampini M*/
183df4397b0SStefano Zampini typedef int PetscMPIInt;
184df4397b0SStefano Zampini 
185bf491261SJacob Faibussowitsch /* Limit MPI to 32-bits */
186bf491261SJacob Faibussowitsch enum {
187bf491261SJacob Faibussowitsch   PETSC_MPI_INT_MIN = INT_MIN,
188bf491261SJacob Faibussowitsch   PETSC_MPI_INT_MAX = INT_MAX
189bf491261SJacob Faibussowitsch };
190bf491261SJacob Faibussowitsch 
191df4397b0SStefano Zampini /*MC
19216a05f60SBarry Smith     PetscSizeT - datatype used to represent sizes in memory (like `size_t`)
1933edda6a2SJed Brown 
1943edda6a2SJed Brown     Level: intermediate
1953edda6a2SJed Brown 
1963edda6a2SJed Brown     Notes:
19716a05f60SBarry Smith     This is equivalent to `size_t`, but defined for consistency with Fortran, which lacks a native equivalent of `size_t`.
1983edda6a2SJed Brown 
199db781477SPatrick Sanan .seealso: `PetscInt`, `PetscInt64`, `PetscCount`
2003edda6a2SJed Brown M*/
2013edda6a2SJed Brown typedef size_t PetscSizeT;
2023edda6a2SJed Brown 
2033edda6a2SJed Brown /*MC
20482a78a4eSJed Brown     PetscCount - signed datatype used to represent counts
20582a78a4eSJed Brown 
20682a78a4eSJed Brown     Level: intermediate
20782a78a4eSJed Brown 
20882a78a4eSJed Brown     Notes:
20916a05f60SBarry Smith     This is equivalent to `ptrdiff_t`, but defined for consistency with Fortran, which lacks a native equivalent of `ptrdiff_t`.
21082a78a4eSJed Brown 
21187497f52SBarry Smith     Use `PetscCount_FMT` to format with `PetscPrintf()`, `printf()`, and related functions.
21282a78a4eSJed Brown 
2136a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscInt`, `PetscInt64`, `PetscSizeT`
21482a78a4eSJed Brown M*/
21582a78a4eSJed Brown typedef ptrdiff_t PetscCount;
21663a3b9bcSJacob Faibussowitsch #define PetscCount_FMT "td"
21782a78a4eSJed Brown 
21882a78a4eSJed Brown /*MC
219df4397b0SStefano Zampini     PetscEnum - datatype used to pass enum types within PETSc functions.
220df4397b0SStefano Zampini 
221df4397b0SStefano Zampini     Level: intermediate
222df4397b0SStefano Zampini 
223db781477SPatrick Sanan .seealso: `PetscOptionsGetEnum()`, `PetscOptionsEnum()`, `PetscBagRegisterEnum()`
224df4397b0SStefano Zampini M*/
2259371c9d4SSatish Balay typedef enum {
2269371c9d4SSatish Balay   ENUM_DUMMY
2279371c9d4SSatish Balay } PetscEnum;
228df4397b0SStefano Zampini 
229df4397b0SStefano Zampini typedef short PetscShort;
230df4397b0SStefano Zampini typedef float PetscFloat;
231df4397b0SStefano Zampini 
232df4397b0SStefano Zampini /*MC
233df4397b0SStefano Zampini   PetscInt - PETSc type that represents an integer, used primarily to
23416a05f60SBarry Smith              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.
235df4397b0SStefano Zampini 
236667f096bSBarry Smith   Level: beginner
237667f096bSBarry Smith 
238df4397b0SStefano Zampini   Notes:
23916a05f60SBarry Smith   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`.
240df4397b0SStefano Zampini 
24116a05f60SBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscIntCast()`
242df4397b0SStefano Zampini M*/
243df4397b0SStefano Zampini 
244df4397b0SStefano Zampini #if defined(PETSC_HAVE_STDINT_H)
245df4397b0SStefano Zampini   #include <stdint.h>
246df4397b0SStefano Zampini #endif
247df4397b0SStefano Zampini #if defined(PETSC_HAVE_INTTYPES_H)
248df4397b0SStefano Zampini   #if !defined(__STDC_FORMAT_MACROS)
249df4397b0SStefano Zampini     #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
250df4397b0SStefano Zampini   #endif
251df4397b0SStefano Zampini   #include <inttypes.h>
252df4397b0SStefano Zampini   #if !defined(PRId64)
253df4397b0SStefano Zampini     #define PRId64 "ld"
254df4397b0SStefano Zampini   #endif
255df4397b0SStefano Zampini #endif
256df4397b0SStefano Zampini 
257ab86aa04SSatish Balay #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 */
258df4397b0SStefano Zampini typedef int64_t PetscInt64;
259bf491261SJacob Faibussowitsch 
260bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
261bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
262bf491261SJacob Faibussowitsch 
263df4397b0SStefano Zampini #elif (PETSC_SIZEOF_LONG_LONG == 8)
264df4397b0SStefano Zampini typedef long long PetscInt64;
265bf491261SJacob Faibussowitsch 
266bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN LLONG_MIN
267bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX LLONG_MAX
268bf491261SJacob Faibussowitsch 
269df4397b0SStefano Zampini #elif defined(PETSC_HAVE___INT64)
270df4397b0SStefano Zampini typedef __int64 PetscInt64;
271bf491261SJacob Faibussowitsch 
272bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
273bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
274bf491261SJacob Faibussowitsch 
275df4397b0SStefano Zampini #else
276df4397b0SStefano Zampini   #error "cannot determine PetscInt64 type"
277df4397b0SStefano Zampini #endif
278df4397b0SStefano Zampini 
2796497c311SBarry Smith #if PETSC_SIZEOF_SIZE_T == 4
2806497c311SBarry Smith   #define PETSC_COUNT_MIN INT_MIN
2816497c311SBarry Smith   #define PETSC_COUNT_MAX INT_MAX
2826497c311SBarry Smith #else
2836497c311SBarry Smith   #define PETSC_COUNT_MIN PETSC_INT64_MIN
2846497c311SBarry Smith   #define PETSC_COUNT_MAX PETSC_INT64_MAX
2856497c311SBarry Smith #endif
2866497c311SBarry Smith 
2873321ca25SJames Wright typedef int32_t PetscInt32;
2883321ca25SJames Wright #define PETSC_INT32_MIN INT32_MIN
2893321ca25SJames Wright #define PETSC_INT32_MAX INT32_MAX
2903321ca25SJames Wright 
291df4397b0SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
292df4397b0SStefano Zampini typedef PetscInt64 PetscInt;
293bf491261SJacob Faibussowitsch 
294bf491261SJacob Faibussowitsch   #define PETSC_INT_MIN PETSC_INT64_MIN
295bf491261SJacob Faibussowitsch   #define PETSC_INT_MAX PETSC_INT64_MAX
296bf491261SJacob Faibussowitsch   #define PetscInt_FMT  PetscInt64_FMT
297df4397b0SStefano Zampini #else
298df4397b0SStefano Zampini typedef int PetscInt;
299bf491261SJacob Faibussowitsch 
300bf491261SJacob Faibussowitsch enum {
301bf491261SJacob Faibussowitsch   PETSC_INT_MIN = INT_MIN,
302bf491261SJacob Faibussowitsch   PETSC_INT_MAX = INT_MAX
303bf491261SJacob Faibussowitsch };
304bf491261SJacob Faibussowitsch   #define PetscInt_FMT "d"
305df4397b0SStefano Zampini #endif
306df4397b0SStefano Zampini 
3071690c2aeSBarry Smith #define PETSC_UINT16_MAX 65535
3081690c2aeSBarry Smith 
3091690c2aeSBarry Smith /* deprecated */
310bf491261SJacob Faibussowitsch #define PETSC_MIN_INT    PETSC_INT_MIN
311bf491261SJacob Faibussowitsch #define PETSC_MAX_INT    PETSC_INT_MAX
3121690c2aeSBarry Smith #define PETSC_MAX_UINT16 PETSC_UINT16_MAX
313bf491261SJacob Faibussowitsch 
314ab86aa04SSatish Balay #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 */
315c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
316c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT PRId64
317c93fae50SJacob Faibussowitsch #elif (PETSC_SIZEOF_LONG_LONG == 8)
318c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_LONG_LONG_INT
319c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "lld"
320c93fae50SJacob Faibussowitsch #elif defined(PETSC_HAVE___INT64)
321c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
322c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "ld"
323c93fae50SJacob Faibussowitsch #else
324c93fae50SJacob Faibussowitsch   #error "cannot determine PetscInt64 type"
325c93fae50SJacob Faibussowitsch #endif
326c93fae50SJacob Faibussowitsch 
3273321ca25SJames Wright #define MPIU_INT32     MPI_INT32_T
3283321ca25SJames Wright #define PetscInt32_FMT PRId32
3293321ca25SJames Wright 
330df4397b0SStefano Zampini /*MC
331df4397b0SStefano Zampini    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
332df4397b0SStefano Zampini 
333667f096bSBarry Smith    Level: intermediate
334667f096bSBarry Smith 
335df4397b0SStefano Zampini    Notes:
33616a05f60SBarry Smith    Usually this is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
3377de69702SBarry Smith    standard C/Fortran integers are 32-bit then this may not be the same as `PetscInt`,
3387de69702SBarry Smith    except on some BLAS/LAPACK implementations that support 64-bit integers see the notes below.
339df4397b0SStefano Zampini 
34087497f52SBarry Smith    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
34187497f52SBarry Smith     generates a `PETSC_ERR_ARG_OUTOFRANGE` error
342df4397b0SStefano Zampini 
343af27ebaaSBarry Smith    Installation Notes\:
34416a05f60SBarry Smith    ./configure automatically determines the size of the integers used by BLAS/LAPACK except when `--with-batch` is used
3457de69702SBarry Smith    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`
346cdc6ee08SBarry Smith 
3477de69702SBarry Smith    MATLAB ships with BLAS and LAPACK that use 64-bit integers, for example if you run ./configure with, the option
34816a05f60SBarry Smith     `--with-blaslapack-lib`=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
349df4397b0SStefano Zampini 
3507de69702SBarry Smith    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
3517de69702SBarry Smith    against the 64-bit version, otherwise it uses the 32-bit version
352df4397b0SStefano Zampini 
3537de69702SBarry Smith    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
354df4397b0SStefano Zampini 
3557de69702SBarry Smith    External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64-bit integers to BLAS/LAPACK so cannot
3567de69702SBarry Smith    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
3577de69702SBarry Smith    these external libraries while using 64-bit integer BLAS/LAPACK.
358df4397b0SStefano Zampini 
359db781477SPatrick Sanan .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
360df4397b0SStefano Zampini M*/
361df4397b0SStefano Zampini #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
362df4397b0SStefano Zampini typedef PetscInt64 PetscBLASInt;
363bf491261SJacob Faibussowitsch 
364bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
365bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
366bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT   PetscInt64_FMT
367df4397b0SStefano Zampini #else
368df4397b0SStefano Zampini typedef int PetscBLASInt;
369bf491261SJacob Faibussowitsch 
370bf491261SJacob Faibussowitsch enum {
371bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MIN = INT_MIN,
372bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MAX = INT_MAX
373bf491261SJacob Faibussowitsch };
374bf491261SJacob Faibussowitsch 
375bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT "d"
376df4397b0SStefano Zampini #endif
377df4397b0SStefano Zampini 
378eee0c0a6SToby Isaac /*MC
379eee0c0a6SToby Isaac    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
380eee0c0a6SToby Isaac 
381667f096bSBarry Smith    Level: intermediate
382667f096bSBarry Smith 
383eee0c0a6SToby Isaac    Notes:
384667f096bSBarry Smith    As of this writing `PetscCuBLASInt` is always the system `int`.
385eee0c0a6SToby Isaac 
38687497f52SBarry Smith   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
38787497f52SBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
388eee0c0a6SToby Isaac 
389db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
390eee0c0a6SToby Isaac M*/
391eee0c0a6SToby Isaac typedef int PetscCuBLASInt;
392eee0c0a6SToby Isaac 
393bf491261SJacob Faibussowitsch enum {
394bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MIN = INT_MIN,
395bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MAX = INT_MAX
396bf491261SJacob Faibussowitsch };
397bf491261SJacob Faibussowitsch 
39847d993e7Ssuyashtn /*MC
39947d993e7Ssuyashtn    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
40047d993e7Ssuyashtn 
40147d993e7Ssuyashtn    Level: intermediate
40247d993e7Ssuyashtn 
403667f096bSBarry Smith    Notes:
40495bd0b28SBarry Smith    `PetscHipBLASInt` is always the system `int`.
40547d993e7Ssuyashtn 
406667f096bSBarry Smith    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
407667f096bSBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
408667f096bSBarry Smith 
4090a5cf5d8SBlaise Bourdin .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscHipBLASIntCast()`
41047d993e7Ssuyashtn M*/
41147d993e7Ssuyashtn typedef int PetscHipBLASInt;
41247d993e7Ssuyashtn 
413bf491261SJacob Faibussowitsch enum {
414bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MIN = INT_MIN,
415bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MAX = INT_MAX
416bf491261SJacob Faibussowitsch };
417bf491261SJacob Faibussowitsch 
4180a5cf5d8SBlaise Bourdin /*MC
4190a5cf5d8SBlaise Bourdin    PetscExodusIIInt - datatype used to represent 'int' parameters to ExodusII functions.
4200a5cf5d8SBlaise Bourdin 
4210a5cf5d8SBlaise Bourdin    Level: intermediate
4220a5cf5d8SBlaise Bourdin 
4230a5cf5d8SBlaise Bourdin    Notes:
4240a5cf5d8SBlaise Bourdin    This is the same as `int`
4250a5cf5d8SBlaise Bourdin 
4260a5cf5d8SBlaise Bourdin .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIFloat`, `PetscBLASIntCast()`
4270a5cf5d8SBlaise Bourdin M*/
4280a5cf5d8SBlaise Bourdin typedef int PetscExodusIIInt;
4290a5cf5d8SBlaise Bourdin #define PetscExodusIIInt_FMT "d"
4300a5cf5d8SBlaise Bourdin 
4310a5cf5d8SBlaise Bourdin /*MC
4320a5cf5d8SBlaise Bourdin    PetscExodusIIFloat - datatype used to represent 'float' parameters to ExodusII functions.
4330a5cf5d8SBlaise Bourdin 
4340a5cf5d8SBlaise Bourdin    Level: intermediate
4350a5cf5d8SBlaise Bourdin 
4360a5cf5d8SBlaise Bourdin    Notes:
4370a5cf5d8SBlaise Bourdin    This is the same as `float`
4380a5cf5d8SBlaise Bourdin 
4390a5cf5d8SBlaise Bourdin .seealso: `PetscMPIInt`, `PetscInt`, `PetscExodusIIInt`, `PetscBLASIntCast()`
4400a5cf5d8SBlaise Bourdin M*/
4410a5cf5d8SBlaise Bourdin typedef float PetscExodusIIFloat;
4420a5cf5d8SBlaise Bourdin 
443df4397b0SStefano Zampini /*E
4441dc74096SMartin Diehl    PetscBool  - Logical variable.
445df4397b0SStefano Zampini 
446df4397b0SStefano Zampini    Level: beginner
447df4397b0SStefano Zampini 
448*5440e5dcSBarry Smith    Notes:
449*5440e5dcSBarry Smith    This is a C bool.
450*5440e5dcSBarry Smith 
451*5440e5dcSBarry Smith    Use `MPI_C_BOOL` for communicating with MPI calls in C, C++, and Fortran.
452*5440e5dcSBarry Smith 
453*5440e5dcSBarry Smith    Fortran Note:
454*5440e5dcSBarry Smith    This is a `logical(C_BOOL)`.
455*5440e5dcSBarry Smith 
456*5440e5dcSBarry Smith    Developer Note:
457*5440e5dcSBarry Smith    We should deprecate this definition since there is a native representation in all the languages.
458*5440e5dcSBarry Smith 
459b94d7dedSBarry Smith .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
460df4397b0SStefano Zampini E*/
4611dc74096SMartin Diehl typedef bool PetscBool;
4621dc74096SMartin Diehl #define PETSC_FALSE false
4631dc74096SMartin Diehl #define PETSC_TRUE  true
4643b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBools[];
465df4397b0SStefano Zampini 
466b94d7dedSBarry Smith /*E
467b94d7dedSBarry Smith    PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
468b94d7dedSBarry Smith 
469b94d7dedSBarry Smith    Level: beginner
470b94d7dedSBarry Smith 
47187497f52SBarry Smith    Note:
472b94d7dedSBarry Smith    Should not be used with the if (flg) or if (!flg) syntax.
473b94d7dedSBarry Smith 
47490dd7910SPierre Jolivet .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
475b94d7dedSBarry Smith E*/
4769371c9d4SSatish Balay typedef enum {
477ce78bad3SBarry Smith   PETSC_BOOL3_FALSE   = 0,
478ce78bad3SBarry Smith   PETSC_BOOL3_TRUE    = 1,
479d7c1f440SPierre Jolivet   PETSC_BOOL3_UNKNOWN = -1 /* the value is unknown at the time of query, but might be determined later */
4809371c9d4SSatish Balay } PetscBool3;
481b94d7dedSBarry Smith 
482b94d7dedSBarry Smith #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
483b94d7dedSBarry Smith #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
484b94d7dedSBarry Smith 
485df4397b0SStefano Zampini /*MC
48687497f52SBarry Smith    PetscReal - PETSc type that represents a real number version of `PetscScalar`
487df4397b0SStefano Zampini 
488667f096bSBarry Smith    Level: beginner
489667f096bSBarry Smith 
490df4397b0SStefano Zampini    Notes:
49187497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
49287497f52SBarry Smith    They will automatically work correctly regardless of the size of `PetscReal`.
493df4397b0SStefano Zampini 
49487497f52SBarry Smith    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
495df4397b0SStefano Zampini 
496db781477SPatrick Sanan .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
497df4397b0SStefano Zampini M*/
498df4397b0SStefano Zampini 
499df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
500df4397b0SStefano Zampini typedef float PetscReal;
501df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL_DOUBLE)
502df4397b0SStefano Zampini typedef double PetscReal;
503df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
504df4397b0SStefano Zampini   #if defined(__cplusplus)
505df4397b0SStefano Zampini extern "C" {
506df4397b0SStefano Zampini   #endif
507df4397b0SStefano Zampini   #include <quadmath.h>
508df4397b0SStefano Zampini   #if defined(__cplusplus)
509df4397b0SStefano Zampini }
510df4397b0SStefano Zampini   #endif
511df4397b0SStefano Zampini typedef __float128 PetscReal;
512df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
513df4397b0SStefano Zampini typedef __fp16 PetscReal;
514df4397b0SStefano Zampini #endif /* PETSC_USE_REAL_* */
515df4397b0SStefano Zampini 
516df4397b0SStefano Zampini /*MC
51787497f52SBarry Smith    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
518df4397b0SStefano Zampini 
519df4397b0SStefano Zampini    Synopsis:
520df4397b0SStefano Zampini    #include <petscsys.h>
521df4397b0SStefano Zampini    PetscComplex number = 1. + 2.*PETSC_i;
522df4397b0SStefano Zampini 
523667f096bSBarry Smith    Level: beginner
524667f096bSBarry Smith 
525df4397b0SStefano Zampini    Notes:
52687497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
52787497f52SBarry Smith    They will automatically work correctly regardless of the size of `PetscComplex`.
528df4397b0SStefano Zampini 
52916a05f60SBarry Smith    See `PetscScalar` for details on how to ./configure the size of `PetscReal`
530df4397b0SStefano Zampini 
531df4397b0SStefano Zampini    Complex numbers are automatically available if PETSc was able to find a working complex implementation
532df4397b0SStefano Zampini 
53316a05f60SBarry Smith     PETSc has a 'fix' for complex numbers to support expressions such as `std::complex<PetscReal>` + `PetscInt`, which are not supported by the standard
534f0b74427SPierre Jolivet     C++ library, but are convenient for PETSc users. If the C++ compiler is able to compile code in `petsccxxcomplexfix.h` (This is checked by
53516a05f60SBarry Smith     configure), we include `petsccxxcomplexfix.h` to provide this convenience.
536a966371cSJunchao Zhang 
53787497f52SBarry Smith     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`
538a966371cSJunchao Zhang     at the beginning of the C++ file to skip the fix.
539a966371cSJunchao Zhang 
540db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
541df4397b0SStefano Zampini M*/
542df4397b0SStefano Zampini #if !defined(PETSC_SKIP_COMPLEX)
5437a19d461SSatish Balay   #if defined(PETSC_CLANGUAGE_CXX)
5447a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
5457a19d461SSatish Balay       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
546df4397b0SStefano Zampini         #define PETSC_HAVE_COMPLEX 1
547d5b43468SJose E. Roman       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5487a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5497a19d461SSatish Balay       #endif
550450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
551450fc7c9SSatish Balay       #define PETSC_HAVE_COMPLEX 1
5527a19d461SSatish Balay     #endif
5537a19d461SSatish Balay   #else /* !PETSC_CLANGUAGE_CXX */
5547a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16)
5557a19d461SSatish Balay       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
5567a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
557d5b43468SJose E. Roman       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5587a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5597a19d461SSatish Balay       #endif
5607a19d461SSatish Balay     #endif
5617a19d461SSatish Balay   #endif /* PETSC_CLANGUAGE_CXX */
5627a19d461SSatish Balay #endif   /* !PETSC_SKIP_COMPLEX */
5637a19d461SSatish Balay 
5647a19d461SSatish Balay #if defined(PETSC_HAVE_COMPLEX)
5657a19d461SSatish Balay   #if defined(__cplusplus) /* C++ complex support */
56611d22bbfSJunchao Zhang     /* Locate a C++ complex template library */
56711d22bbfSJunchao Zhang     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
56811d22bbfSJunchao Zhang       #define petsccomplexlib Kokkos
56911d22bbfSJunchao Zhang       #include <Kokkos_Complex.hpp>
570840d638aSJunchao Zhang     #elif (defined(__CUDACC__) && defined(PETSC_HAVE_CUDA)) || (defined(__HIPCC__) && defined(PETSC_HAVE_HIP))
571df4397b0SStefano Zampini       #define petsccomplexlib thrust
572df4397b0SStefano Zampini       #include <thrust/complex.h>
573450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128)
574450fc7c9SSatish Balay       #include <complex.h>
575df4397b0SStefano Zampini     #else
576df4397b0SStefano Zampini       #define petsccomplexlib std
577df4397b0SStefano Zampini       #include <complex>
578df4397b0SStefano Zampini     #endif
57911d22bbfSJunchao Zhang 
58011d22bbfSJunchao Zhang     /* Define PetscComplex based on the precision */
581df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE)
582df4397b0SStefano Zampini typedef petsccomplexlib::complex<float> PetscComplex;
583df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
584df4397b0SStefano Zampini typedef petsccomplexlib::complex<double> PetscComplex;
585df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
586450fc7c9SSatish Balay typedef __complex128 PetscComplex;
58711d22bbfSJunchao Zhang     #endif
58811d22bbfSJunchao Zhang 
589a966371cSJunchao Zhang     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
590a966371cSJunchao Zhang     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
59139829747SLisandro Dalcin       #include <petsccxxcomplexfix.h>
59211d22bbfSJunchao Zhang     #endif
5937a19d461SSatish Balay   #else /* c99 complex support */
594df4397b0SStefano Zampini     #include <complex.h>
595df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
596df4397b0SStefano Zampini typedef float _Complex PetscComplex;
597df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
598df4397b0SStefano Zampini typedef double _Complex PetscComplex;
599df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
600df4397b0SStefano Zampini typedef __complex128 PetscComplex;
601df4397b0SStefano Zampini     #endif /* PETSC_USE_REAL_* */
6027a19d461SSatish Balay   #endif   /* !__cplusplus */
6037a19d461SSatish Balay #endif     /* PETSC_HAVE_COMPLEX */
604df4397b0SStefano Zampini 
605df4397b0SStefano Zampini /*MC
606df4397b0SStefano Zampini    PetscScalar - PETSc type that represents either a double precision real number, a double precision
607df4397b0SStefano Zampini                  complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
60816a05f60SBarry Smith                  with `--with-scalar-type`=real,complex `--with-precision`=single,double,__float128,__fp16
609df4397b0SStefano Zampini 
610df4397b0SStefano Zampini    Level: beginner
611df4397b0SStefano Zampini 
61216a05f60SBarry Smith    Note:
61316a05f60SBarry Smith    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`.
61416a05f60SBarry Smith 
615db781477SPatrick Sanan .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
616df4397b0SStefano Zampini M*/
617df4397b0SStefano Zampini 
6187a19d461SSatish Balay #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
619df4397b0SStefano Zampini typedef PetscComplex PetscScalar;
620df4397b0SStefano Zampini #else  /* PETSC_USE_COMPLEX */
621df4397b0SStefano Zampini typedef PetscReal PetscScalar;
622df4397b0SStefano Zampini #endif /* PETSC_USE_COMPLEX */
623df4397b0SStefano Zampini 
624df4397b0SStefano Zampini /*E
62587497f52SBarry Smith     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
626df4397b0SStefano Zampini 
627667f096bSBarry Smith    Values for array input:
628667f096bSBarry Smith +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
629667f096bSBarry Smith .   `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
63016a05f60SBarry Smith                           delete the array. The array MUST have been obtained with `PetscMalloc()`. Hence this mode cannot be used in Fortran.
631667f096bSBarry Smith -   `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
632667f096bSBarry Smith                           the array but the user must delete the array after the object is destroyed.
6335d80c0bfSVaclav Hapla 
634667f096bSBarry Smith    Values for PetscObject:
635667f096bSBarry Smith +   `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.
636667f096bSBarry Smith .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
637667f096bSBarry Smith                           increases its reference count).
638667f096bSBarry Smith -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
639bdedc06fSMatthew G. Knepley 
64095bd0b28SBarry Smith    Level: beginner
64195bd0b28SBarry Smith 
642097fc5b5SPierre Jolivet .seealso: `PetscInsertMode`
643df4397b0SStefano Zampini E*/
6449371c9d4SSatish Balay typedef enum {
6459371c9d4SSatish Balay   PETSC_COPY_VALUES,
6469371c9d4SSatish Balay   PETSC_OWN_POINTER,
6479371c9d4SSatish Balay   PETSC_USE_POINTER
6489371c9d4SSatish Balay } PetscCopyMode;
6493b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscCopyModes[];
650df4397b0SStefano Zampini 
651df4397b0SStefano Zampini /*MC
65287497f52SBarry Smith     PETSC_FALSE - False value of `PetscBool`
653df4397b0SStefano Zampini 
654df4397b0SStefano Zampini     Level: beginner
655df4397b0SStefano Zampini 
656df4397b0SStefano Zampini     Note:
657df4397b0SStefano Zampini     Zero integer
658df4397b0SStefano Zampini 
65987497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
660df4397b0SStefano Zampini M*/
661df4397b0SStefano Zampini 
662df4397b0SStefano Zampini /*MC
66387497f52SBarry Smith     PETSC_TRUE - True value of `PetscBool`
664df4397b0SStefano Zampini 
665df4397b0SStefano Zampini     Level: beginner
666df4397b0SStefano Zampini 
667df4397b0SStefano Zampini     Note:
668df4397b0SStefano Zampini     Nonzero integer
669df4397b0SStefano Zampini 
67087497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
671df4397b0SStefano Zampini M*/
672df4397b0SStefano Zampini 
673df4397b0SStefano Zampini /*MC
674df4397b0SStefano Zampini     PetscLogDouble - Used for logging times
675df4397b0SStefano Zampini 
6766b3bf505SPatrick Sanan   Level: developer
6776b3bf505SPatrick Sanan 
678667f096bSBarry Smith   Note:
679667f096bSBarry Smith   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
680667f096bSBarry Smith 
681bdedc06fSMatthew G. Knepley .seealso: `PetscBool`, `PetscDataType`
682df4397b0SStefano Zampini M*/
683df4397b0SStefano Zampini typedef double PetscLogDouble;
684df4397b0SStefano Zampini 
685df4397b0SStefano Zampini /*E
686df4397b0SStefano Zampini     PetscDataType - Used for handling different basic data types.
687df4397b0SStefano Zampini 
688df4397b0SStefano Zampini    Level: beginner
689df4397b0SStefano Zampini 
690df4397b0SStefano Zampini    Notes:
69187497f52SBarry Smith    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
692df4397b0SStefano Zampini 
69387497f52SBarry Smith    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
69487497f52SBarry Smith    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
695277f51e8SBarry Smith 
69687497f52SBarry Smith    Developer Notes:
697df4397b0SStefano Zampini    It would be nice if we could always just use MPI Datatypes, why can we not?
698df4397b0SStefano Zampini 
69987497f52SBarry Smith    If you change any values in `PetscDatatype` make sure you update their usage in
700fa131761SBarry Smith    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
70191e29162SBarry Smith 
702667f096bSBarry Smith    TODO:
7033321ca25SJames Wright    Remove use of improper `PETSC_ENUM`
704277f51e8SBarry Smith 
705db781477SPatrick Sanan .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
706db781477SPatrick Sanan           `PetscDataTypeGetSize()`
707df4397b0SStefano Zampini E*/
7089371c9d4SSatish Balay typedef enum {
7099371c9d4SSatish Balay   PETSC_DATATYPE_UNKNOWN = 0,
7109371c9d4SSatish Balay   PETSC_DOUBLE           = 1,
7119371c9d4SSatish Balay   PETSC_COMPLEX          = 2,
7129371c9d4SSatish Balay   PETSC_LONG             = 3,
7139371c9d4SSatish Balay   PETSC_SHORT            = 4,
7149371c9d4SSatish Balay   PETSC_FLOAT            = 5,
7159371c9d4SSatish Balay   PETSC_CHAR             = 6,
7169371c9d4SSatish Balay   PETSC_BIT_LOGICAL      = 7,
7179371c9d4SSatish Balay   PETSC_ENUM             = 8,
7189371c9d4SSatish Balay   PETSC_BOOL             = 9,
7199371c9d4SSatish Balay   PETSC___FLOAT128       = 10,
7209371c9d4SSatish Balay   PETSC_OBJECT           = 11,
7219371c9d4SSatish Balay   PETSC_FUNCTION         = 12,
7229371c9d4SSatish Balay   PETSC_STRING           = 13,
7239371c9d4SSatish Balay   PETSC___FP16           = 14,
7249371c9d4SSatish Balay   PETSC_STRUCT           = 15,
7259371c9d4SSatish Balay   PETSC_INT              = 16,
72662e5d2d2SJDBetteridge   PETSC_INT64            = 17,
7273321ca25SJames Wright   PETSC_COUNT            = 18,
7283321ca25SJames Wright   PETSC_INT32            = 19,
7299371c9d4SSatish Balay } PetscDataType;
7303b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscDataTypes[];
731df4397b0SStefano Zampini 
732df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
733df4397b0SStefano Zampini   #define PETSC_REAL PETSC_FLOAT
7345117d392SLisandro Dalcin #elif defined(PETSC_USE_REAL_DOUBLE)
7355117d392SLisandro Dalcin   #define PETSC_REAL PETSC_DOUBLE
736df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
737df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FLOAT128
738df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
739df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FP16
740df4397b0SStefano Zampini #else
741df4397b0SStefano Zampini   #define PETSC_REAL PETSC_DOUBLE
742df4397b0SStefano Zampini #endif
7435117d392SLisandro Dalcin 
7445117d392SLisandro Dalcin #if defined(PETSC_USE_COMPLEX)
7455117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_COMPLEX
7465117d392SLisandro Dalcin #else
7475117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_REAL
7485117d392SLisandro Dalcin #endif
7495117d392SLisandro Dalcin 
750df4397b0SStefano Zampini #define PETSC_FORTRANADDR PETSC_LONG
751df4397b0SStefano Zampini 
752df4397b0SStefano Zampini /*S
753df4397b0SStefano Zampini   PetscToken - 'Token' used for managing tokenizing strings
754df4397b0SStefano Zampini 
755df4397b0SStefano Zampini   Level: intermediate
756df4397b0SStefano Zampini 
757db781477SPatrick Sanan .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
758df4397b0SStefano Zampini S*/
759ce78bad3SBarry Smith typedef struct _n_PetscToken *PetscToken;
760df4397b0SStefano Zampini 
761df4397b0SStefano Zampini /*S
7620b4b7b1cSBarry Smith    PetscObject - any PETSc object, for example: `PetscViewer`, `Mat`, `Vec`, `KSP`, `DM`
763df4397b0SStefano Zampini 
764df4397b0SStefano Zampini    Level: beginner
765df4397b0SStefano Zampini 
76687497f52SBarry Smith    Notes:
7670b4b7b1cSBarry Smith    This is the base class from which all PETSc objects are derived.
768df4397b0SStefano Zampini 
76987497f52SBarry Smith    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
77087497f52SBarry Smith 
771db781477SPatrick Sanan .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
772df4397b0SStefano Zampini S*/
773df4397b0SStefano Zampini typedef struct _p_PetscObject *PetscObject;
774df4397b0SStefano Zampini 
775df4397b0SStefano Zampini /*MC
77687497f52SBarry Smith     PetscObjectId - unique integer Id for a `PetscObject`
777df4397b0SStefano Zampini 
778df4397b0SStefano Zampini     Level: developer
779df4397b0SStefano Zampini 
78087497f52SBarry Smith     Note:
78187497f52SBarry Smith     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
78287497f52SBarry Smith     if the objects are the same. Never compare two object pointer values.
783df4397b0SStefano Zampini 
784db781477SPatrick Sanan .seealso: `PetscObjectState`, `PetscObjectGetId()`
785df4397b0SStefano Zampini M*/
786df4397b0SStefano Zampini typedef PetscInt64 PetscObjectId;
787df4397b0SStefano Zampini 
788df4397b0SStefano Zampini /*MC
78987497f52SBarry Smith     PetscObjectState - integer state for a `PetscObject`
790df4397b0SStefano Zampini 
791df4397b0SStefano Zampini     Level: developer
792df4397b0SStefano Zampini 
79395bd0b28SBarry Smith     Note:
794df4397b0SStefano Zampini     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
795df4397b0SStefano Zampini     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.
796df4397b0SStefano Zampini 
797db781477SPatrick Sanan .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
798df4397b0SStefano Zampini M*/
799df4397b0SStefano Zampini typedef PetscInt64 PetscObjectState;
800df4397b0SStefano Zampini 
801df4397b0SStefano Zampini /*S
802df4397b0SStefano Zampini      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
803df4397b0SStefano Zampini       by string name
804df4397b0SStefano Zampini 
805df4397b0SStefano Zampini    Level: advanced
806df4397b0SStefano Zampini 
807db781477SPatrick Sanan .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
808df4397b0SStefano Zampini S*/
809df4397b0SStefano Zampini typedef struct _n_PetscFunctionList *PetscFunctionList;
810df4397b0SStefano Zampini 
811df4397b0SStefano Zampini /*E
812df4397b0SStefano Zampini   PetscFileMode - Access mode for a file.
813df4397b0SStefano Zampini 
814667f096bSBarry Smith   Values:
815667f096bSBarry Smith +  `FILE_MODE_UNDEFINED`     - initial invalid value
816667f096bSBarry Smith .  `FILE_MODE_READ`          - open a file at its beginning for reading
817667f096bSBarry Smith .  `FILE_MODE_WRITE`         - open a file at its beginning for writing (will create if the file does not exist)
818667f096bSBarry Smith .  `FILE_MODE_APPEND`        - open a file at end for writing
819667f096bSBarry Smith .  `FILE_MODE_UPDATE`        - open a file for updating, meaning for reading and writing
820667f096bSBarry Smith -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
821df4397b0SStefano Zampini 
82216a05f60SBarry Smith   Level: beginner
82316a05f60SBarry Smith 
824db781477SPatrick Sanan .seealso: `PetscViewerFileSetMode()`
825df4397b0SStefano Zampini E*/
8269371c9d4SSatish Balay typedef enum {
8279371c9d4SSatish Balay   FILE_MODE_UNDEFINED     = -1,
8289371c9d4SSatish Balay   FILE_MODE_READ          = 0,
829ce78bad3SBarry Smith   FILE_MODE_WRITE         = 1,
830ce78bad3SBarry Smith   FILE_MODE_APPEND        = 2,
831ce78bad3SBarry Smith   FILE_MODE_UPDATE        = 3,
832ce78bad3SBarry Smith   FILE_MODE_APPEND_UPDATE = 4
8339371c9d4SSatish Balay } PetscFileMode;
8343b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscFileModes[];
835df4397b0SStefano Zampini 
836df4397b0SStefano Zampini typedef void *PetscDLHandle;
8379371c9d4SSatish Balay typedef enum {
8389371c9d4SSatish Balay   PETSC_DL_DECIDE = 0,
8399371c9d4SSatish Balay   PETSC_DL_NOW    = 1,
8409371c9d4SSatish Balay   PETSC_DL_LOCAL  = 2
8419371c9d4SSatish Balay } PetscDLMode;
842df4397b0SStefano Zampini 
843df4397b0SStefano Zampini /*S
8447243573dSPierre Jolivet    PetscObjectList - Linked list of PETSc objects, each accessible by string name
845df4397b0SStefano Zampini 
846df4397b0SStefano Zampini    Level: developer
847df4397b0SStefano Zampini 
84887497f52SBarry Smith    Note:
84987497f52SBarry Smith    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
850df4397b0SStefano Zampini 
851db781477SPatrick Sanan .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
852df4397b0SStefano Zampini S*/
853df4397b0SStefano Zampini typedef struct _n_PetscObjectList *PetscObjectList;
854df4397b0SStefano Zampini 
855df4397b0SStefano Zampini /*S
856667f096bSBarry Smith    PetscDLLibrary - Linked list of dynamic libraries to search for functions
857df4397b0SStefano Zampini 
85816a05f60SBarry Smith    Level: developer
859df4397b0SStefano Zampini 
860db781477SPatrick Sanan .seealso: `PetscDLLibraryOpen()`
861df4397b0SStefano Zampini S*/
862df4397b0SStefano Zampini typedef struct _n_PetscDLLibrary *PetscDLLibrary;
863df4397b0SStefano Zampini 
864df4397b0SStefano Zampini /*S
865df4397b0SStefano Zampini    PetscContainer - Simple PETSc object that contains a pointer to any required data
866df4397b0SStefano Zampini 
867df4397b0SStefano Zampini    Level: advanced
868df4397b0SStefano Zampini 
86987497f52SBarry Smith    Note:
87087497f52SBarry Smith    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
87187497f52SBarry Smith 
87287497f52SBarry Smith .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
873df4397b0SStefano Zampini S*/
874df4397b0SStefano Zampini typedef struct _p_PetscContainer *PetscContainer;
875df4397b0SStefano Zampini 
876df4397b0SStefano Zampini /*S
877df4397b0SStefano Zampini    PetscRandom - Abstract PETSc object that manages generating random numbers
878df4397b0SStefano Zampini 
879df4397b0SStefano Zampini    Level: intermediate
880df4397b0SStefano Zampini 
881db781477SPatrick Sanan .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
882df4397b0SStefano Zampini S*/
883df4397b0SStefano Zampini typedef struct _p_PetscRandom *PetscRandom;
884df4397b0SStefano Zampini 
885df4397b0SStefano Zampini /*
886df4397b0SStefano Zampini    In binary files variables are stored using the following lengths,
887df4397b0SStefano Zampini   regardless of how they are stored in memory on any one particular
888467446fbSPierre Jolivet   machine. Use these rather than sizeof() in computing sizes for
889df4397b0SStefano Zampini   PetscBinarySeek().
890df4397b0SStefano Zampini */
891df4397b0SStefano Zampini #define PETSC_BINARY_INT_SIZE    (32 / 8)
892df4397b0SStefano Zampini #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
893df4397b0SStefano Zampini #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
894df4397b0SStefano Zampini #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
895df4397b0SStefano Zampini #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
896df4397b0SStefano Zampini #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
897df4397b0SStefano Zampini 
898df4397b0SStefano Zampini /*E
89987497f52SBarry Smith   PetscBinarySeekType - argument to `PetscBinarySeek()`
900df4397b0SStefano Zampini 
90116a05f60SBarry Smith   Values:
90216a05f60SBarry Smith +  `PETSC_BINARY_SEEK_SET` - offset is an absolute location in the file
90316a05f60SBarry Smith .  `PETSC_BINARY_SEEK_CUR` - offset is an offset from the current location of the file pointer
90416a05f60SBarry Smith -  `PETSC_BINARY_SEEK_END` - offset is an offset from the end of the file
90516a05f60SBarry Smith 
906df4397b0SStefano Zampini   Level: advanced
907df4397b0SStefano Zampini 
908db781477SPatrick Sanan .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
909df4397b0SStefano Zampini E*/
9109371c9d4SSatish Balay typedef enum {
9119371c9d4SSatish Balay   PETSC_BINARY_SEEK_SET = 0,
9129371c9d4SSatish Balay   PETSC_BINARY_SEEK_CUR = 1,
9139371c9d4SSatish Balay   PETSC_BINARY_SEEK_END = 2
9149371c9d4SSatish Balay } PetscBinarySeekType;
915df4397b0SStefano Zampini 
916df4397b0SStefano Zampini /*E
91716a05f60SBarry Smith    PetscBuildTwoSidedType - algorithm for setting up two-sided communication for use with `PetscSF`
918df4397b0SStefano Zampini 
919667f096bSBarry Smith    Values:
920667f096bSBarry Smith +  `PETSC_BUILDTWOSIDED_ALLREDUCE`  - classical algorithm using an `MPI_Allreduce()` with
921667f096bSBarry Smith                                       a buffer of length equal to the communicator size. Not memory-scalable due to
92216a05f60SBarry Smith                                       the large reduction size. Requires only an MPI-1 implementation.
923667f096bSBarry Smith .  `PETSC_BUILDTWOSIDED_IBARRIER`   - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
92416a05f60SBarry Smith                                       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires an MPI-3 implementation.
925667f096bSBarry Smith -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
92616a05f60SBarry Smith                                       that only communicates the part of the reduction that is necessary.  Requires an MPI-2 implementation.
927df4397b0SStefano Zampini 
928df4397b0SStefano Zampini    Level: developer
929df4397b0SStefano Zampini 
930db781477SPatrick Sanan .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
931df4397b0SStefano Zampini E*/
932df4397b0SStefano Zampini typedef enum {
933df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_NOTSET     = -1,
934df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
935df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
936df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_REDSCATTER = 2
937df4397b0SStefano Zampini   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
938df4397b0SStefano Zampini } PetscBuildTwoSidedType;
9393b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
940df4397b0SStefano Zampini 
941df4397b0SStefano Zampini /*E
942667f096bSBarry Smith   InsertMode - How the entries are combined with the current values in the vectors or matrices
943df4397b0SStefano Zampini 
944667f096bSBarry Smith   Values:
945667f096bSBarry Smith +  `NOT_SET_VALUES`    - do not actually use the values
946667f096bSBarry Smith .  `INSERT_VALUES`     - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
947667f096bSBarry Smith .  `ADD_VALUES`        - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
948667f096bSBarry Smith .  `MAX_VALUES`        - use the maximum of each current value and provided value
949667f096bSBarry Smith .  `MIN_VALUES`        - use the minimum of each current value and provided value
950667f096bSBarry Smith .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
951667f096bSBarry Smith .  `ADD_ALL_VALUES`    - add, even if indices that are not marked as constrained by the `PetscSection`
952667f096bSBarry Smith .  `INSERT_BC_VALUES`  - insert, but ignore indices that are not marked as constrained by the `PetscSection`
953667f096bSBarry Smith -  `ADD_BC_VALUES`     - add, but ignore indices that are not marked as constrained by the `PetscSection`
954667f096bSBarry Smith 
95516a05f60SBarry Smith   Level: beginner
95616a05f60SBarry Smith 
957667f096bSBarry Smith   Note:
958667f096bSBarry Smith   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
959667f096bSBarry Smith   and `DMGetLocalSection()`.
960667f096bSBarry Smith 
961667f096bSBarry Smith   Not all options are supported for all operations or PETSc object types.
962667f096bSBarry Smith 
963db781477SPatrick Sanan .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
964db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
965db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
966df4397b0SStefano Zampini E*/
9679371c9d4SSatish Balay typedef enum {
9689371c9d4SSatish Balay   NOT_SET_VALUES,
9699371c9d4SSatish Balay   INSERT_VALUES,
9709371c9d4SSatish Balay   ADD_VALUES,
9719371c9d4SSatish Balay   MAX_VALUES,
9729371c9d4SSatish Balay   MIN_VALUES,
9739371c9d4SSatish Balay   INSERT_ALL_VALUES,
9749371c9d4SSatish Balay   ADD_ALL_VALUES,
9759371c9d4SSatish Balay   INSERT_BC_VALUES,
9769371c9d4SSatish Balay   ADD_BC_VALUES
9779371c9d4SSatish Balay } InsertMode;
978df4397b0SStefano Zampini 
979df4397b0SStefano Zampini /*MC
980df4397b0SStefano Zampini     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
981df4397b0SStefano Zampini 
982df4397b0SStefano Zampini     Level: beginner
983df4397b0SStefano Zampini 
984db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
985db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
986db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
987df4397b0SStefano Zampini M*/
988df4397b0SStefano Zampini 
989df4397b0SStefano Zampini /*MC
990df4397b0SStefano Zampini     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
991df4397b0SStefano Zampini                  value into that location
992df4397b0SStefano Zampini 
993df4397b0SStefano Zampini     Level: beginner
994df4397b0SStefano Zampini 
995db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
996db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
997db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
998df4397b0SStefano Zampini M*/
999df4397b0SStefano Zampini 
1000df4397b0SStefano Zampini /*MC
1001df4397b0SStefano Zampini     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
1002df4397b0SStefano Zampini 
1003df4397b0SStefano Zampini     Level: beginner
1004df4397b0SStefano Zampini 
1005db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1006df4397b0SStefano Zampini M*/
1007df4397b0SStefano Zampini 
1008421aa1e7SJunchao Zhang /*MC
1009421aa1e7SJunchao Zhang     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
1010421aa1e7SJunchao Zhang 
1011421aa1e7SJunchao Zhang     Level: beginner
1012421aa1e7SJunchao Zhang 
1013db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
1014421aa1e7SJunchao Zhang M*/
1015421aa1e7SJunchao Zhang 
1016df4397b0SStefano Zampini /*S
1017df4397b0SStefano Zampini    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
1018df4397b0SStefano Zampini 
1019667f096bSBarry Smith    Values:
1020667f096bSBarry Smith +   `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
1021667f096bSBarry Smith .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
1022667f096bSBarry Smith -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
1023667f096bSBarry Smith 
1024df4397b0SStefano Zampini    Sample Usage:
102587497f52SBarry Smith .vb
102616a05f60SBarry Smith        PetscSubcommCreate()
102716a05f60SBarry Smith        PetscSubcommSetNumber()
102816a05f60SBarry Smith        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
102916a05f60SBarry Smith        ccomm = PetscSubcommChild()
103016a05f60SBarry Smith        PetscSubcommDestroy()
103187497f52SBarry Smith .ve
1032df4397b0SStefano Zampini 
1033667f096bSBarry Smith    Example:
1034667f096bSBarry Smith    Consider a communicator with six processes split into 3 subcommunicators.
1035667f096bSBarry Smith .vb
103616a05f60SBarry Smith    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
103716a05f60SBarry Smith    PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
1038667f096bSBarry Smith .ve
1039667f096bSBarry Smith 
1040df4397b0SStefano Zampini    Level: advanced
1041df4397b0SStefano Zampini 
104216a05f60SBarry Smith    Note:
104316a05f60SBarry Smith    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
104416a05f60SBarry Smith .vb
104516a05f60SBarry Smith      PetscSubcommChild() returns the associated subcommunicator on this process
104616a05f60SBarry Smith      PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
104716a05f60SBarry Smith .ve
104816a05f60SBarry Smith 
104987497f52SBarry Smith    Developer Note:
105087497f52SBarry Smith    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
1051df4397b0SStefano Zampini    are performed.
1052df4397b0SStefano Zampini 
1053db781477SPatrick Sanan .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
1054df4397b0SStefano Zampini S*/
1055df4397b0SStefano Zampini typedef struct _n_PetscSubcomm *PetscSubcomm;
10569371c9d4SSatish Balay typedef enum {
10579371c9d4SSatish Balay   PETSC_SUBCOMM_GENERAL    = 0,
10589371c9d4SSatish Balay   PETSC_SUBCOMM_CONTIGUOUS = 1,
10599371c9d4SSatish Balay   PETSC_SUBCOMM_INTERLACED = 2
10609371c9d4SSatish Balay } PetscSubcommType;
10613b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscSubcommTypes[];
1062df4397b0SStefano Zampini 
1063df4397b0SStefano Zampini /*S
1064df4397b0SStefano Zampini    PetscHeap - A simple class for managing heaps
1065df4397b0SStefano Zampini 
1066df4397b0SStefano Zampini    Level: intermediate
1067df4397b0SStefano Zampini 
1068db781477SPatrick Sanan .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1069df4397b0SStefano Zampini S*/
1070ce78bad3SBarry Smith typedef struct _n_PetscHeap *PetscHeap;
1071df4397b0SStefano Zampini 
1072df4397b0SStefano Zampini typedef struct _n_PetscShmComm *PetscShmComm;
1073df4397b0SStefano Zampini typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
1074df4397b0SStefano Zampini 
1075df4397b0SStefano Zampini /*S
1076df4397b0SStefano Zampini    PetscSegBuffer - a segmented extendable buffer
1077df4397b0SStefano Zampini 
1078df4397b0SStefano Zampini    Level: developer
1079df4397b0SStefano Zampini 
1080db781477SPatrick Sanan .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1081df4397b0SStefano Zampini S*/
1082df4397b0SStefano Zampini typedef struct _n_PetscSegBuffer *PetscSegBuffer;
1083df4397b0SStefano Zampini 
1084df4397b0SStefano Zampini typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
1085778ae69aSToby Isaac 
1086778ae69aSToby Isaac /*S
1087778ae69aSToby Isaac      PetscBT - PETSc bitarrays, efficient storage of arrays of boolean values
1088778ae69aSToby Isaac 
1089778ae69aSToby Isaac      Level: advanced
1090778ae69aSToby Isaac 
1091778ae69aSToby Isaac      Notes:
1092778ae69aSToby Isaac      The following routines do not have their own manual pages
1093778ae69aSToby Isaac 
1094778ae69aSToby Isaac .vb
1095778ae69aSToby Isaac      PetscBTCreate(m,&bt)         - creates a bit array with enough room to hold m values
1096778ae69aSToby Isaac      PetscBTDestroy(&bt)          - destroys the bit array
1097778ae69aSToby Isaac      PetscBTMemzero(m,bt)         - zeros the entire bit array (sets all values to false)
1098778ae69aSToby Isaac      PetscBTSet(bt,index)         - sets a particular entry as true
1099778ae69aSToby Isaac      PetscBTClear(bt,index)       - sets a particular entry as false
1100778ae69aSToby Isaac      PetscBTLookup(bt,index)      - returns the value
1101778ae69aSToby Isaac      PetscBTLookupSet(bt,index)   - returns the value and then sets it true
1102778ae69aSToby Isaac      PetscBTLookupClear(bt,index) - returns the value and then sets it false
1103778ae69aSToby Isaac      PetscBTLength(m)             - returns number of bytes in array with m bits
1104778ae69aSToby Isaac      PetscBTView(m,bt,viewer)     - prints all the entries in a bit array
1105778ae69aSToby Isaac .ve
1106778ae69aSToby Isaac 
110754c05997SPierre Jolivet     PETSc does not check error flags on `PetscBTLookup()`, `PetscBTLookupSet()`, `PetscBTLength()` because error checking
1108778ae69aSToby Isaac     would cost hundreds more cycles then the operation.
1109778ae69aSToby Isaac 
1110778ae69aSToby Isaac S*/
1111778ae69aSToby Isaac typedef char *PetscBT;
1112778ae69aSToby Isaac 
1113778ae69aSToby Isaac /* The number of bits in a byte */
1114778ae69aSToby Isaac #define PETSC_BITS_PER_BYTE CHAR_BIT
1115