xref: /petsc/include/petscsystypes.h (revision 6a210b70a61472cf8733db59e8a3fa68f6578c01)
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>
12df4397b0SStefano Zampini 
13ac09b921SBarry Smith /* SUBMANSEC = Sys */
14ac09b921SBarry Smith 
15778ae69aSToby Isaac #include <limits.h> // INT_MIN, INT_MAX, CHAR_BIT
163ba16761SJacob Faibussowitsch 
173ba16761SJacob Faibussowitsch #if defined(__clang__) || (PETSC_CPP_VERSION >= 17)
183ba16761SJacob Faibussowitsch   // clang allows both [[nodiscard]] and __attribute__((warn_unused_result)) on type
193ba16761SJacob Faibussowitsch   // definitions. GCC, however, does not, so check that we are using C++17 [[nodiscard]]
203ba16761SJacob Faibussowitsch   // instead of __attribute__((warn_unused_result))
213ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_NODISCARD PETSC_NODISCARD
223ba16761SJacob Faibussowitsch #else
233ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_NODISCARD
243ba16761SJacob Faibussowitsch #endif
253ba16761SJacob Faibussowitsch 
268a7d4faaSJacob Faibussowitsch #ifdef PETSC_CLANG_STATIC_ANALYZER
278a7d4faaSJacob Faibussowitsch   #undef PETSC_USE_STRICT_PETSCERRORCODE
288a7d4faaSJacob Faibussowitsch #endif
298a7d4faaSJacob Faibussowitsch 
303ba16761SJacob Faibussowitsch #ifdef PETSC_USE_STRICT_PETSCERRORCODE
313ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_TYPEDEF   typedef
323ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_ENUM_NAME PetscErrorCode
333ba16761SJacob Faibussowitsch #else
343ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_TYPEDEF
353ba16761SJacob Faibussowitsch   #define PETSC_ERROR_CODE_ENUM_NAME
363ba16761SJacob Faibussowitsch #endif
373ba16761SJacob Faibussowitsch 
383ba16761SJacob Faibussowitsch /*E
393ba16761SJacob Faibussowitsch   PetscErrorCode - Datatype used to return PETSc error codes.
40df4397b0SStefano Zampini 
41df4397b0SStefano Zampini   Level: beginner
42df4397b0SStefano Zampini 
433ba16761SJacob Faibussowitsch   Notes:
443ba16761SJacob Faibussowitsch   Virtually all PETSc functions return an error code. It is the callers responsibility to check
453ba16761SJacob Faibussowitsch   the value of the returned error code after each PETSc call to determine if any errors
463ba16761SJacob Faibussowitsch   occurred. A set of convenience macros (e.g. `PetscCall()`, `PetscCallVoid()`) are provided
473ba16761SJacob Faibussowitsch   for this purpose. Failing to properly check for errors is not supported, as errors may leave
483ba16761SJacob Faibussowitsch   PETSc in an undetermined state.
493ba16761SJacob Faibussowitsch 
503ba16761SJacob Faibussowitsch   One can retrieve the error string corresponding to a particular error code using
513ba16761SJacob Faibussowitsch   `PetscErrorMessage()`.
523ba16761SJacob Faibussowitsch 
533ba16761SJacob Faibussowitsch   The user can also configure PETSc with the `--with-strict-petscerrorcode` option to enable
543ba16761SJacob Faibussowitsch   compiler warnings when the returned error codes are not captured and checked. Users are
553ba16761SJacob Faibussowitsch   *heavily* encouraged to opt-in to this option, as it will become enabled by default in a
563ba16761SJacob Faibussowitsch   future release.
573ba16761SJacob Faibussowitsch 
583ba16761SJacob Faibussowitsch   Developer Notes:
593ba16761SJacob Faibussowitsch   These are the generic error codes. These error codes are used in many different places in the
603ba16761SJacob Faibussowitsch   PETSc source code. The C-string versions are at defined in `PetscErrorStrings[]` in
6116a05f60SBarry Smith   `src/sys/error/err.c`, while the Fortran versions are defined in
623ba16761SJacob Faibussowitsch   `src/sys/f90-mod/petscerror.h`. Any changes here must also be made in both locations.
633ba16761SJacob Faibussowitsch 
643ba16761SJacob Faibussowitsch .seealso: `PetscErrorMessage()`, `PetscCall()`, `SETERRQ()`
653ba16761SJacob Faibussowitsch E*/
663ba16761SJacob Faibussowitsch PETSC_ERROR_CODE_TYPEDEF enum PETSC_ERROR_CODE_NODISCARD {
673ba16761SJacob Faibussowitsch   PETSC_SUCCESS                   = 0,
683ba16761SJacob Faibussowitsch   PETSC_ERR_BOOLEAN_MACRO_FAILURE = 1, /* do not use */
693ba16761SJacob Faibussowitsch 
70467446fbSPierre Jolivet   PETSC_ERR_MIN_VALUE = 54, /* should always be one less than the smallest value */
713ba16761SJacob Faibussowitsch 
723ba16761SJacob Faibussowitsch   PETSC_ERR_MEM            = 55, /* unable to allocate requested memory */
733ba16761SJacob Faibussowitsch   PETSC_ERR_SUP            = 56, /* no support for requested operation */
743ba16761SJacob Faibussowitsch   PETSC_ERR_SUP_SYS        = 57, /* no support for requested operation on this computer system */
753ba16761SJacob Faibussowitsch   PETSC_ERR_ORDER          = 58, /* operation done in wrong order */
763ba16761SJacob Faibussowitsch   PETSC_ERR_SIG            = 59, /* signal received */
773ba16761SJacob Faibussowitsch   PETSC_ERR_FP             = 72, /* floating point exception */
783ba16761SJacob Faibussowitsch   PETSC_ERR_COR            = 74, /* corrupted PETSc object */
793ba16761SJacob Faibussowitsch   PETSC_ERR_LIB            = 76, /* error in library called by PETSc */
803ba16761SJacob Faibussowitsch   PETSC_ERR_PLIB           = 77, /* PETSc library generated inconsistent data */
813ba16761SJacob Faibussowitsch   PETSC_ERR_MEMC           = 78, /* memory corruption */
823ba16761SJacob Faibussowitsch   PETSC_ERR_CONV_FAILED    = 82, /* iterative method (KSP or SNES) failed */
833ba16761SJacob Faibussowitsch   PETSC_ERR_USER           = 83, /* user has not provided needed function */
843ba16761SJacob Faibussowitsch   PETSC_ERR_SYS            = 88, /* error in system call */
853ba16761SJacob Faibussowitsch   PETSC_ERR_POINTER        = 70, /* pointer does not point to valid address */
863ba16761SJacob Faibussowitsch   PETSC_ERR_MPI_LIB_INCOMP = 87, /* MPI library at runtime is not compatible with MPI user compiled with */
873ba16761SJacob Faibussowitsch 
883ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_SIZ          = 60, /* nonconforming object sizes used in operation */
893ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_IDN          = 61, /* two arguments not allowed to be the same */
903ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONG        = 62, /* wrong argument (but object probably ok) */
913ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_CORRUPT      = 64, /* null or corrupted PETSc object as argument */
923ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_OUTOFRANGE   = 63, /* input argument, out of range */
933ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_BADPTR       = 68, /* invalid pointer argument */
943ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMETYPE  = 69, /* two args must be same object type */
953ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMECOMM  = 80, /* two args must be same communicators */
963ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONGSTATE   = 73, /* object in argument is in wrong state, e.g. unassembled mat */
973ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_TYPENOTSET   = 89, /* the type of the object has not yet been set */
983ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_INCOMP       = 75, /* two arguments are incompatible */
993ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NULL         = 85, /* argument is null that should not be */
1003ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_UNKNOWN_TYPE = 86, /* type name doesn't match any registered type */
1013ba16761SJacob Faibussowitsch 
1023ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_OPEN       = 65, /* unable to open file */
1033ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_READ       = 66, /* unable to read from file */
1043ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_WRITE      = 67, /* unable to write to file */
1053ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_UNEXPECTED = 79, /* unexpected data in file */
1063ba16761SJacob Faibussowitsch 
1073ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_LU_ZRPVT = 71, /* detected a zero pivot during LU factorization */
1083ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_CH_ZRPVT = 81, /* detected a zero pivot during Cholesky factorization */
1093ba16761SJacob Faibussowitsch 
1103ba16761SJacob Faibussowitsch   PETSC_ERR_INT_OVERFLOW   = 84,
1113ba16761SJacob Faibussowitsch   PETSC_ERR_FLOP_COUNT     = 90,
1123ba16761SJacob Faibussowitsch   PETSC_ERR_NOT_CONVERGED  = 91,  /* solver did not converge */
1133ba16761SJacob Faibussowitsch   PETSC_ERR_MISSING_FACTOR = 92,  /* MatGetFactor() failed */
1143ba16761SJacob Faibussowitsch   PETSC_ERR_OPT_OVERWRITE  = 93,  /* attempted to over write options which should not be changed */
1153ba16761SJacob Faibussowitsch   PETSC_ERR_WRONG_MPI_SIZE = 94,  /* example/application run with number of MPI ranks it does not support */
1163ba16761SJacob Faibussowitsch   PETSC_ERR_USER_INPUT     = 95,  /* missing or incorrect user input */
1173ba16761SJacob Faibussowitsch   PETSC_ERR_GPU_RESOURCE   = 96,  /* unable to load a GPU resource, for example cuBLAS */
1183ba16761SJacob 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 */
1193ba16761SJacob Faibussowitsch   PETSC_ERR_MPI            = 98,  /* general MPI error */
1203ba16761SJacob Faibussowitsch   PETSC_ERR_RETURN         = 99,  /* PetscError() incorrectly returned an error code of 0 */
1219beb8f72SToby Isaac   PETSC_ERR_MEM_LEAK       = 100, /* memory alloc/free imbalance */
1229beb8f72SToby Isaac   PETSC_ERR_MAX_VALUE      = 101, /* this is always the one more than the largest error code */
1233ba16761SJacob Faibussowitsch 
1243ba16761SJacob Faibussowitsch   /*
1253ba16761SJacob Faibussowitsch     do not use, exist purely to make the enum bounds equal that of a regular int (so conversion
1263ba16761SJacob Faibussowitsch     to int in main() is not undefined behavior)
1273ba16761SJacob Faibussowitsch   */
1283ba16761SJacob Faibussowitsch   PETSC_ERR_MIN_SIGNED_BOUND_DO_NOT_USE = INT_MIN,
1293ba16761SJacob Faibussowitsch   PETSC_ERR_MAX_SIGNED_BOUND_DO_NOT_USE = INT_MAX
1303ba16761SJacob Faibussowitsch } PETSC_ERROR_CODE_ENUM_NAME;
1313ba16761SJacob Faibussowitsch 
1323ba16761SJacob Faibussowitsch #ifndef PETSC_USE_STRICT_PETSCERRORCODE
133df4397b0SStefano Zampini typedef int PetscErrorCode;
134df4397b0SStefano Zampini 
1353ba16761SJacob Faibussowitsch   /*
1363ba16761SJacob Faibussowitsch   Needed so that C++ lambdas can deduce the return type as PetscErrorCode from
1373ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS). Otherwise we get
1383ba16761SJacob Faibussowitsch 
1393ba16761SJacob Faibussowitsch   error: return type '(unnamed enum at include/petscsystypes.h:50:1)' must match previous
1403ba16761SJacob Faibussowitsch   return type 'int' when lambda expression has unspecified explicit return type
1413ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1423ba16761SJacob Faibussowitsch   ^
1433ba16761SJacob Faibussowitsch */
1443ba16761SJacob Faibussowitsch   #define PETSC_SUCCESS ((PetscErrorCode)0)
1453ba16761SJacob Faibussowitsch #endif
1463ba16761SJacob Faibussowitsch 
1473ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_NODISCARD
1483ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_TYPEDEF
1493ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_ENUM_NAME
1503ba16761SJacob Faibussowitsch 
151df4397b0SStefano Zampini /*MC
152df4397b0SStefano Zampini     PetscClassId - A unique id used to identify each PETSc class.
153df4397b0SStefano Zampini 
15416a05f60SBarry Smith     Level: developer
15516a05f60SBarry Smith 
15616a05f60SBarry Smith     Note:
15787497f52SBarry Smith     Use `PetscClassIdRegister()` to obtain a new value for a new class being created. Usually
158df4397b0SStefano Zampini     XXXInitializePackage() calls it for each class it defines.
159df4397b0SStefano Zampini 
16016a05f60SBarry Smith     Developer Note:
161667f096bSBarry Smith     Internal integer stored in the `_p_PetscObject` data structure. These are all computed by an offset from the lowest one, `PETSC_SMALLEST_CLASSID`.
162df4397b0SStefano Zampini 
163db781477SPatrick Sanan .seealso: `PetscClassIdRegister()`, `PetscLogEventRegister()`, `PetscHeaderCreate()`
164df4397b0SStefano Zampini M*/
165df4397b0SStefano Zampini typedef int PetscClassId;
166df4397b0SStefano Zampini 
167df4397b0SStefano Zampini /*MC
168df4397b0SStefano Zampini     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
169df4397b0SStefano Zampini 
170df4397b0SStefano Zampini     Level: intermediate
171df4397b0SStefano Zampini 
172df4397b0SStefano Zampini     Notes:
1737de69702SBarry 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
1747de69702SBarry Smith     standard C/Fortran integers are 32-bit then this is NOT the same as `PetscInt`; it remains 32-bit.
175df4397b0SStefano Zampini 
17687497f52SBarry Smith     `PetscMPIIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscMPIInt`, if not it
17787497f52SBarry Smith     generates a `PETSC_ERR_ARG_OUTOFRANGE` error.
178df4397b0SStefano Zampini 
179*6a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscInt`, `PetscMPIIntCast()`
180df4397b0SStefano Zampini M*/
181df4397b0SStefano Zampini typedef int PetscMPIInt;
182df4397b0SStefano Zampini 
183bf491261SJacob Faibussowitsch /* Limit MPI to 32-bits */
184bf491261SJacob Faibussowitsch enum {
185bf491261SJacob Faibussowitsch   PETSC_MPI_INT_MIN = INT_MIN,
186bf491261SJacob Faibussowitsch   PETSC_MPI_INT_MAX = INT_MAX
187bf491261SJacob Faibussowitsch };
188bf491261SJacob Faibussowitsch 
189df4397b0SStefano Zampini /*MC
19016a05f60SBarry Smith     PetscSizeT - datatype used to represent sizes in memory (like `size_t`)
1913edda6a2SJed Brown 
1923edda6a2SJed Brown     Level: intermediate
1933edda6a2SJed Brown 
1943edda6a2SJed Brown     Notes:
19516a05f60SBarry Smith     This is equivalent to `size_t`, but defined for consistency with Fortran, which lacks a native equivalent of `size_t`.
1963edda6a2SJed Brown 
197db781477SPatrick Sanan .seealso: `PetscInt`, `PetscInt64`, `PetscCount`
1983edda6a2SJed Brown M*/
1993edda6a2SJed Brown typedef size_t PetscSizeT;
2003edda6a2SJed Brown 
2013edda6a2SJed Brown /*MC
20282a78a4eSJed Brown     PetscCount - signed datatype used to represent counts
20382a78a4eSJed Brown 
20482a78a4eSJed Brown     Level: intermediate
20582a78a4eSJed Brown 
20682a78a4eSJed Brown     Notes:
20716a05f60SBarry Smith     This is equivalent to `ptrdiff_t`, but defined for consistency with Fortran, which lacks a native equivalent of `ptrdiff_t`.
20882a78a4eSJed Brown 
20987497f52SBarry Smith     Use `PetscCount_FMT` to format with `PetscPrintf()`, `printf()`, and related functions.
21082a78a4eSJed Brown 
211*6a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscInt`, `PetscInt64`, `PetscSizeT`
21282a78a4eSJed Brown M*/
21382a78a4eSJed Brown typedef ptrdiff_t PetscCount;
21463a3b9bcSJacob Faibussowitsch #define PetscCount_FMT "td"
21582a78a4eSJed Brown 
21682a78a4eSJed Brown /*MC
217df4397b0SStefano Zampini     PetscEnum - datatype used to pass enum types within PETSc functions.
218df4397b0SStefano Zampini 
219df4397b0SStefano Zampini     Level: intermediate
220df4397b0SStefano Zampini 
221db781477SPatrick Sanan .seealso: `PetscOptionsGetEnum()`, `PetscOptionsEnum()`, `PetscBagRegisterEnum()`
222df4397b0SStefano Zampini M*/
2239371c9d4SSatish Balay typedef enum {
2249371c9d4SSatish Balay   ENUM_DUMMY
2259371c9d4SSatish Balay } PetscEnum;
226df4397b0SStefano Zampini 
227df4397b0SStefano Zampini typedef short PetscShort;
228df4397b0SStefano Zampini typedef char  PetscChar;
229df4397b0SStefano Zampini typedef float PetscFloat;
230df4397b0SStefano Zampini 
231df4397b0SStefano Zampini /*MC
232df4397b0SStefano Zampini   PetscInt - PETSc type that represents an integer, used primarily to
23316a05f60SBarry 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.
234df4397b0SStefano Zampini 
235667f096bSBarry Smith   Level: beginner
236667f096bSBarry Smith 
237df4397b0SStefano Zampini   Notes:
23816a05f60SBarry 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`.
239df4397b0SStefano Zampini 
24016a05f60SBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscIntCast()`
241df4397b0SStefano Zampini M*/
242df4397b0SStefano Zampini 
243df4397b0SStefano Zampini #if defined(PETSC_HAVE_STDINT_H)
244df4397b0SStefano Zampini   #include <stdint.h>
245df4397b0SStefano Zampini #endif
246df4397b0SStefano Zampini #if defined(PETSC_HAVE_INTTYPES_H)
247df4397b0SStefano Zampini   #if !defined(__STDC_FORMAT_MACROS)
248df4397b0SStefano Zampini     #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
249df4397b0SStefano Zampini   #endif
250df4397b0SStefano Zampini   #include <inttypes.h>
251df4397b0SStefano Zampini   #if !defined(PRId64)
252df4397b0SStefano Zampini     #define PRId64 "ld"
253df4397b0SStefano Zampini   #endif
254df4397b0SStefano Zampini #endif
255df4397b0SStefano Zampini 
256ab86aa04SSatish 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 */
257df4397b0SStefano Zampini typedef int64_t PetscInt64;
258bf491261SJacob Faibussowitsch 
259bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
260bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
261bf491261SJacob Faibussowitsch 
262df4397b0SStefano Zampini #elif (PETSC_SIZEOF_LONG_LONG == 8)
263df4397b0SStefano Zampini typedef long long PetscInt64;
264bf491261SJacob Faibussowitsch 
265bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN LLONG_MIN
266bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX LLONG_MAX
267bf491261SJacob Faibussowitsch 
268df4397b0SStefano Zampini #elif defined(PETSC_HAVE___INT64)
269df4397b0SStefano Zampini typedef __int64 PetscInt64;
270bf491261SJacob Faibussowitsch 
271bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
272bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
273bf491261SJacob Faibussowitsch 
274df4397b0SStefano Zampini #else
275df4397b0SStefano Zampini   #error "cannot determine PetscInt64 type"
276df4397b0SStefano Zampini #endif
277df4397b0SStefano Zampini 
2786497c311SBarry Smith #if PETSC_SIZEOF_SIZE_T == 4
2796497c311SBarry Smith   #define PETSC_COUNT_MIN INT_MIN
2806497c311SBarry Smith   #define PETSC_COUNT_MAX INT_MAX
2816497c311SBarry Smith #else
2826497c311SBarry Smith   #define PETSC_COUNT_MIN PETSC_INT64_MIN
2836497c311SBarry Smith   #define PETSC_COUNT_MAX PETSC_INT64_MAX
2846497c311SBarry Smith #endif
2856497c311SBarry Smith 
2863321ca25SJames Wright typedef int32_t PetscInt32;
2873321ca25SJames Wright #define PETSC_INT32_MIN INT32_MIN
2883321ca25SJames Wright #define PETSC_INT32_MAX INT32_MAX
2893321ca25SJames Wright 
290df4397b0SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
291df4397b0SStefano Zampini typedef PetscInt64 PetscInt;
292bf491261SJacob Faibussowitsch 
293bf491261SJacob Faibussowitsch   #define PETSC_INT_MIN PETSC_INT64_MIN
294bf491261SJacob Faibussowitsch   #define PETSC_INT_MAX PETSC_INT64_MAX
295bf491261SJacob Faibussowitsch   #define PetscInt_FMT  PetscInt64_FMT
296df4397b0SStefano Zampini #else
297df4397b0SStefano Zampini typedef int PetscInt;
298bf491261SJacob Faibussowitsch 
299bf491261SJacob Faibussowitsch enum {
300bf491261SJacob Faibussowitsch   PETSC_INT_MIN = INT_MIN,
301bf491261SJacob Faibussowitsch   PETSC_INT_MAX = INT_MAX
302bf491261SJacob Faibussowitsch };
303bf491261SJacob Faibussowitsch 
304bf491261SJacob Faibussowitsch   #define PetscInt_FMT "d"
305df4397b0SStefano Zampini #endif
306df4397b0SStefano Zampini 
307bf491261SJacob Faibussowitsch #define PETSC_MIN_INT    PETSC_INT_MIN
308bf491261SJacob Faibussowitsch #define PETSC_MAX_INT    PETSC_INT_MAX
309bf491261SJacob Faibussowitsch #define PETSC_MAX_UINT16 65535
310bf491261SJacob Faibussowitsch 
311ab86aa04SSatish 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 */
312c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
313c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT PRId64
314c93fae50SJacob Faibussowitsch #elif (PETSC_SIZEOF_LONG_LONG == 8)
315c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_LONG_LONG_INT
316c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "lld"
317c93fae50SJacob Faibussowitsch #elif defined(PETSC_HAVE___INT64)
318c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
319c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "ld"
320c93fae50SJacob Faibussowitsch #else
321c93fae50SJacob Faibussowitsch   #error "cannot determine PetscInt64 type"
322c93fae50SJacob Faibussowitsch #endif
323c93fae50SJacob Faibussowitsch 
3243321ca25SJames Wright #define MPIU_INT32     MPI_INT32_T
3253321ca25SJames Wright #define PetscInt32_FMT PRId32
3263321ca25SJames Wright 
327df4397b0SStefano Zampini /*MC
328df4397b0SStefano Zampini    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
329df4397b0SStefano Zampini 
330667f096bSBarry Smith    Level: intermediate
331667f096bSBarry Smith 
332df4397b0SStefano Zampini    Notes:
33316a05f60SBarry Smith    Usually this is the same as `PetscInt`, but if PETSc was built with `--with-64-bit-indices` but
3347de69702SBarry Smith    standard C/Fortran integers are 32-bit then this may not be the same as `PetscInt`,
3357de69702SBarry Smith    except on some BLAS/LAPACK implementations that support 64-bit integers see the notes below.
336df4397b0SStefano Zampini 
33787497f52SBarry Smith    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
33887497f52SBarry Smith     generates a `PETSC_ERR_ARG_OUTOFRANGE` error
339df4397b0SStefano Zampini 
340af27ebaaSBarry Smith    Installation Notes\:
34116a05f60SBarry Smith    ./configure automatically determines the size of the integers used by BLAS/LAPACK except when `--with-batch` is used
3427de69702SBarry 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`
343cdc6ee08SBarry Smith 
3447de69702SBarry Smith    MATLAB ships with BLAS and LAPACK that use 64-bit integers, for example if you run ./configure with, the option
34516a05f60SBarry Smith     `--with-blaslapack-lib`=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
346df4397b0SStefano Zampini 
3477de69702SBarry 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
3487de69702SBarry Smith    against the 64-bit version, otherwise it uses the 32-bit version
349df4397b0SStefano Zampini 
3507de69702SBarry 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
351df4397b0SStefano Zampini 
3527de69702SBarry Smith    External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64-bit integers to BLAS/LAPACK so cannot
3537de69702SBarry 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
3547de69702SBarry Smith    these external libraries while using 64-bit integer BLAS/LAPACK.
355df4397b0SStefano Zampini 
356db781477SPatrick Sanan .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
357df4397b0SStefano Zampini M*/
358df4397b0SStefano Zampini #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
359df4397b0SStefano Zampini typedef PetscInt64 PetscBLASInt;
360bf491261SJacob Faibussowitsch 
361bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
362bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
363bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT   PetscInt64_FMT
364df4397b0SStefano Zampini #else
365df4397b0SStefano Zampini typedef int PetscBLASInt;
366bf491261SJacob Faibussowitsch 
367bf491261SJacob Faibussowitsch enum {
368bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MIN = INT_MIN,
369bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MAX = INT_MAX
370bf491261SJacob Faibussowitsch };
371bf491261SJacob Faibussowitsch 
372bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT "d"
373df4397b0SStefano Zampini #endif
374df4397b0SStefano Zampini 
375eee0c0a6SToby Isaac /*MC
376eee0c0a6SToby Isaac    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
377eee0c0a6SToby Isaac 
378667f096bSBarry Smith    Level: intermediate
379667f096bSBarry Smith 
380eee0c0a6SToby Isaac    Notes:
381667f096bSBarry Smith    As of this writing `PetscCuBLASInt` is always the system `int`.
382eee0c0a6SToby Isaac 
38387497f52SBarry Smith   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
38487497f52SBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
385eee0c0a6SToby Isaac 
386db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
387eee0c0a6SToby Isaac M*/
388eee0c0a6SToby Isaac typedef int PetscCuBLASInt;
389eee0c0a6SToby Isaac 
390bf491261SJacob Faibussowitsch enum {
391bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MIN = INT_MIN,
392bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MAX = INT_MAX
393bf491261SJacob Faibussowitsch };
394bf491261SJacob Faibussowitsch 
39547d993e7Ssuyashtn /*MC
39647d993e7Ssuyashtn    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
39747d993e7Ssuyashtn 
39847d993e7Ssuyashtn    Level: intermediate
39947d993e7Ssuyashtn 
400667f096bSBarry Smith    Notes:
40195bd0b28SBarry Smith    `PetscHipBLASInt` is always the system `int`.
40247d993e7Ssuyashtn 
403667f096bSBarry Smith    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
404667f096bSBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
405667f096bSBarry Smith 
406667f096bSBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscHipBLASIntCast()
40747d993e7Ssuyashtn M*/
40847d993e7Ssuyashtn typedef int PetscHipBLASInt;
40947d993e7Ssuyashtn 
410bf491261SJacob Faibussowitsch enum {
411bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MIN = INT_MIN,
412bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MAX = INT_MAX
413bf491261SJacob Faibussowitsch };
414bf491261SJacob Faibussowitsch 
415df4397b0SStefano Zampini /*E
416b94d7dedSBarry Smith    PetscBool  - Logical variable. Actually an enum in C and a logical in Fortran.
417df4397b0SStefano Zampini 
418df4397b0SStefano Zampini    Level: beginner
419df4397b0SStefano Zampini 
420df4397b0SStefano Zampini    Developer Note:
42187497f52SBarry Smith    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
42215229ffcSPierre Jolivet    Boolean values. It is not easy to have a simple macro that will work properly in all circumstances with all three mechanisms.
423df4397b0SStefano Zampini 
424b94d7dedSBarry Smith .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
425df4397b0SStefano Zampini E*/
4269371c9d4SSatish Balay typedef enum {
4279371c9d4SSatish Balay   PETSC_FALSE,
4289371c9d4SSatish Balay   PETSC_TRUE
4299371c9d4SSatish Balay } PetscBool;
4303b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBools[];
431df4397b0SStefano Zampini 
432b94d7dedSBarry Smith /*E
433b94d7dedSBarry Smith    PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
434b94d7dedSBarry Smith 
435b94d7dedSBarry Smith    Level: beginner
436b94d7dedSBarry Smith 
43787497f52SBarry Smith    Note:
438b94d7dedSBarry Smith    Should not be used with the if (flg) or if (!flg) syntax.
439b94d7dedSBarry Smith 
44090dd7910SPierre Jolivet .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
441b94d7dedSBarry Smith E*/
4429371c9d4SSatish Balay typedef enum {
4439371c9d4SSatish Balay   PETSC_BOOL3_FALSE,
4449371c9d4SSatish Balay   PETSC_BOOL3_TRUE,
4459371c9d4SSatish Balay   PETSC_BOOL3_UNKNOWN = -1
4469371c9d4SSatish Balay } PetscBool3;
447b94d7dedSBarry Smith 
448b94d7dedSBarry Smith #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
449b94d7dedSBarry Smith #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
450b94d7dedSBarry Smith 
451df4397b0SStefano Zampini /*MC
45287497f52SBarry Smith    PetscReal - PETSc type that represents a real number version of `PetscScalar`
453df4397b0SStefano Zampini 
454667f096bSBarry Smith    Level: beginner
455667f096bSBarry Smith 
456df4397b0SStefano Zampini    Notes:
45787497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
45887497f52SBarry Smith    They will automatically work correctly regardless of the size of `PetscReal`.
459df4397b0SStefano Zampini 
46087497f52SBarry Smith    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
461df4397b0SStefano Zampini 
462db781477SPatrick Sanan .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
463df4397b0SStefano Zampini M*/
464df4397b0SStefano Zampini 
465df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
466df4397b0SStefano Zampini typedef float PetscReal;
467df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL_DOUBLE)
468df4397b0SStefano Zampini typedef double PetscReal;
469df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
470df4397b0SStefano Zampini   #if defined(__cplusplus)
471df4397b0SStefano Zampini extern "C" {
472df4397b0SStefano Zampini   #endif
473df4397b0SStefano Zampini   #include <quadmath.h>
474df4397b0SStefano Zampini   #if defined(__cplusplus)
475df4397b0SStefano Zampini }
476df4397b0SStefano Zampini   #endif
477df4397b0SStefano Zampini typedef __float128 PetscReal;
478df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
479df4397b0SStefano Zampini typedef __fp16 PetscReal;
480df4397b0SStefano Zampini #endif /* PETSC_USE_REAL_* */
481df4397b0SStefano Zampini 
482df4397b0SStefano Zampini /*MC
48387497f52SBarry Smith    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
484df4397b0SStefano Zampini 
485df4397b0SStefano Zampini    Synopsis:
486df4397b0SStefano Zampini    #include <petscsys.h>
487df4397b0SStefano Zampini    PetscComplex number = 1. + 2.*PETSC_i;
488df4397b0SStefano Zampini 
489667f096bSBarry Smith    Level: beginner
490667f096bSBarry Smith 
491df4397b0SStefano Zampini    Notes:
49287497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
49387497f52SBarry Smith    They will automatically work correctly regardless of the size of `PetscComplex`.
494df4397b0SStefano Zampini 
49516a05f60SBarry Smith    See `PetscScalar` for details on how to ./configure the size of `PetscReal`
496df4397b0SStefano Zampini 
497df4397b0SStefano Zampini    Complex numbers are automatically available if PETSc was able to find a working complex implementation
498df4397b0SStefano Zampini 
49916a05f60SBarry Smith     PETSc has a 'fix' for complex numbers to support expressions such as `std::complex<PetscReal>` + `PetscInt`, which are not supported by the standard
50016a05f60SBarry Smith     C++ library, but are convenient for petsc users. If the C++ compiler is able to compile code in `petsccxxcomplexfix.h` (This is checked by
50116a05f60SBarry Smith     configure), we include `petsccxxcomplexfix.h` to provide this convenience.
502a966371cSJunchao Zhang 
50387497f52SBarry 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`
504a966371cSJunchao Zhang     at the beginning of the C++ file to skip the fix.
505a966371cSJunchao Zhang 
506db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
507df4397b0SStefano Zampini M*/
508df4397b0SStefano Zampini #if !defined(PETSC_SKIP_COMPLEX)
5097a19d461SSatish Balay   #if defined(PETSC_CLANGUAGE_CXX)
5107a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
5117a19d461SSatish Balay       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
512df4397b0SStefano Zampini         #define PETSC_HAVE_COMPLEX 1
513d5b43468SJose E. Roman       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5147a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5157a19d461SSatish Balay       #endif
516450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
517450fc7c9SSatish Balay       #define PETSC_HAVE_COMPLEX 1
5187a19d461SSatish Balay     #endif
5197a19d461SSatish Balay   #else /* !PETSC_CLANGUAGE_CXX */
5207a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16)
5217a19d461SSatish Balay       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
5227a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
523d5b43468SJose E. Roman       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5247a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5257a19d461SSatish Balay       #endif
5267a19d461SSatish Balay     #endif
5277a19d461SSatish Balay   #endif /* PETSC_CLANGUAGE_CXX */
5287a19d461SSatish Balay #endif   /* !PETSC_SKIP_COMPLEX */
5297a19d461SSatish Balay 
5307a19d461SSatish Balay #if defined(PETSC_HAVE_COMPLEX)
5317a19d461SSatish Balay   #if defined(__cplusplus) /* C++ complex support */
53211d22bbfSJunchao Zhang     /* Locate a C++ complex template library */
53311d22bbfSJunchao Zhang     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
53411d22bbfSJunchao Zhang       #define petsccomplexlib Kokkos
53511d22bbfSJunchao Zhang       #include <Kokkos_Complex.hpp>
536022afdc5SJed Brown     #elif defined(__CUDACC__) || defined(__HIPCC__)
537df4397b0SStefano Zampini       #define petsccomplexlib thrust
538df4397b0SStefano Zampini       #include <thrust/complex.h>
539450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128)
540450fc7c9SSatish Balay       #include <complex.h>
541df4397b0SStefano Zampini     #else
542df4397b0SStefano Zampini       #define petsccomplexlib std
543df4397b0SStefano Zampini       #include <complex>
544df4397b0SStefano Zampini     #endif
54511d22bbfSJunchao Zhang 
54611d22bbfSJunchao Zhang     /* Define PetscComplex based on the precision */
547df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE)
548df4397b0SStefano Zampini typedef petsccomplexlib::complex<float> PetscComplex;
549df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
550df4397b0SStefano Zampini typedef petsccomplexlib::complex<double> PetscComplex;
551df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
552450fc7c9SSatish Balay typedef __complex128 PetscComplex;
55311d22bbfSJunchao Zhang     #endif
55411d22bbfSJunchao Zhang 
555a966371cSJunchao Zhang     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
556a966371cSJunchao Zhang     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
55739829747SLisandro Dalcin       #include <petsccxxcomplexfix.h>
55811d22bbfSJunchao Zhang     #endif
5597a19d461SSatish Balay   #else /* c99 complex support */
560df4397b0SStefano Zampini     #include <complex.h>
561df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
562df4397b0SStefano Zampini typedef float _Complex PetscComplex;
563df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
564df4397b0SStefano Zampini typedef double _Complex PetscComplex;
565df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
566df4397b0SStefano Zampini typedef __complex128 PetscComplex;
567df4397b0SStefano Zampini     #endif /* PETSC_USE_REAL_* */
5687a19d461SSatish Balay   #endif   /* !__cplusplus */
5697a19d461SSatish Balay #endif     /* PETSC_HAVE_COMPLEX */
570df4397b0SStefano Zampini 
571df4397b0SStefano Zampini /*MC
572df4397b0SStefano Zampini    PetscScalar - PETSc type that represents either a double precision real number, a double precision
573df4397b0SStefano Zampini                  complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
57416a05f60SBarry Smith                  with `--with-scalar-type`=real,complex `--with-precision`=single,double,__float128,__fp16
575df4397b0SStefano Zampini 
576df4397b0SStefano Zampini    Level: beginner
577df4397b0SStefano Zampini 
57816a05f60SBarry Smith    Note:
57916a05f60SBarry 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`.
58016a05f60SBarry Smith 
581db781477SPatrick Sanan .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
582df4397b0SStefano Zampini M*/
583df4397b0SStefano Zampini 
5847a19d461SSatish Balay #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
585df4397b0SStefano Zampini typedef PetscComplex PetscScalar;
586df4397b0SStefano Zampini #else  /* PETSC_USE_COMPLEX */
587df4397b0SStefano Zampini typedef PetscReal PetscScalar;
588df4397b0SStefano Zampini #endif /* PETSC_USE_COMPLEX */
589df4397b0SStefano Zampini 
590df4397b0SStefano Zampini /*E
59187497f52SBarry Smith     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
592df4397b0SStefano Zampini 
593667f096bSBarry Smith    Values for array input:
594667f096bSBarry Smith +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
595667f096bSBarry 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
59616a05f60SBarry Smith                           delete the array. The array MUST have been obtained with `PetscMalloc()`. Hence this mode cannot be used in Fortran.
597667f096bSBarry 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
598667f096bSBarry Smith                           the array but the user must delete the array after the object is destroyed.
5995d80c0bfSVaclav Hapla 
600667f096bSBarry Smith    Values for PetscObject:
601667f096bSBarry 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.
602667f096bSBarry Smith .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
603667f096bSBarry Smith                           increases its reference count).
604667f096bSBarry Smith -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
605bdedc06fSMatthew G. Knepley 
60695bd0b28SBarry Smith    Level: beginner
60795bd0b28SBarry Smith 
608097fc5b5SPierre Jolivet .seealso: `PetscInsertMode`
609df4397b0SStefano Zampini E*/
6109371c9d4SSatish Balay typedef enum {
6119371c9d4SSatish Balay   PETSC_COPY_VALUES,
6129371c9d4SSatish Balay   PETSC_OWN_POINTER,
6139371c9d4SSatish Balay   PETSC_USE_POINTER
6149371c9d4SSatish Balay } PetscCopyMode;
6153b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscCopyModes[];
616df4397b0SStefano Zampini 
617df4397b0SStefano Zampini /*MC
61887497f52SBarry Smith     PETSC_FALSE - False value of `PetscBool`
619df4397b0SStefano Zampini 
620df4397b0SStefano Zampini     Level: beginner
621df4397b0SStefano Zampini 
622df4397b0SStefano Zampini     Note:
623df4397b0SStefano Zampini     Zero integer
624df4397b0SStefano Zampini 
62587497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
626df4397b0SStefano Zampini M*/
627df4397b0SStefano Zampini 
628df4397b0SStefano Zampini /*MC
62987497f52SBarry Smith     PETSC_TRUE - True value of `PetscBool`
630df4397b0SStefano Zampini 
631df4397b0SStefano Zampini     Level: beginner
632df4397b0SStefano Zampini 
633df4397b0SStefano Zampini     Note:
634df4397b0SStefano Zampini     Nonzero integer
635df4397b0SStefano Zampini 
63687497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
637df4397b0SStefano Zampini M*/
638df4397b0SStefano Zampini 
639df4397b0SStefano Zampini /*MC
640df4397b0SStefano Zampini     PetscLogDouble - Used for logging times
641df4397b0SStefano Zampini 
6426b3bf505SPatrick Sanan   Level: developer
6436b3bf505SPatrick Sanan 
644667f096bSBarry Smith   Note:
645667f096bSBarry Smith   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
646667f096bSBarry Smith 
647bdedc06fSMatthew G. Knepley .seealso: `PetscBool`, `PetscDataType`
648df4397b0SStefano Zampini M*/
649df4397b0SStefano Zampini typedef double PetscLogDouble;
650df4397b0SStefano Zampini 
651df4397b0SStefano Zampini /*E
652df4397b0SStefano Zampini     PetscDataType - Used for handling different basic data types.
653df4397b0SStefano Zampini 
654df4397b0SStefano Zampini    Level: beginner
655df4397b0SStefano Zampini 
656df4397b0SStefano Zampini    Notes:
65787497f52SBarry Smith    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
658df4397b0SStefano Zampini 
65987497f52SBarry Smith    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
66087497f52SBarry Smith    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
661277f51e8SBarry Smith 
66287497f52SBarry Smith    Developer Notes:
663df4397b0SStefano Zampini    It would be nice if we could always just use MPI Datatypes, why can we not?
664df4397b0SStefano Zampini 
66587497f52SBarry Smith    If you change any values in `PetscDatatype` make sure you update their usage in
666fa131761SBarry Smith    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
66791e29162SBarry Smith 
668667f096bSBarry Smith    TODO:
6693321ca25SJames Wright    Remove use of improper `PETSC_ENUM`
670277f51e8SBarry Smith 
671db781477SPatrick Sanan .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
672db781477SPatrick Sanan           `PetscDataTypeGetSize()`
673df4397b0SStefano Zampini E*/
6749371c9d4SSatish Balay typedef enum {
6759371c9d4SSatish Balay   PETSC_DATATYPE_UNKNOWN = 0,
6769371c9d4SSatish Balay   PETSC_DOUBLE           = 1,
6779371c9d4SSatish Balay   PETSC_COMPLEX          = 2,
6789371c9d4SSatish Balay   PETSC_LONG             = 3,
6799371c9d4SSatish Balay   PETSC_SHORT            = 4,
6809371c9d4SSatish Balay   PETSC_FLOAT            = 5,
6819371c9d4SSatish Balay   PETSC_CHAR             = 6,
6829371c9d4SSatish Balay   PETSC_BIT_LOGICAL      = 7,
6839371c9d4SSatish Balay   PETSC_ENUM             = 8,
6849371c9d4SSatish Balay   PETSC_BOOL             = 9,
6859371c9d4SSatish Balay   PETSC___FLOAT128       = 10,
6869371c9d4SSatish Balay   PETSC_OBJECT           = 11,
6879371c9d4SSatish Balay   PETSC_FUNCTION         = 12,
6889371c9d4SSatish Balay   PETSC_STRING           = 13,
6899371c9d4SSatish Balay   PETSC___FP16           = 14,
6909371c9d4SSatish Balay   PETSC_STRUCT           = 15,
6919371c9d4SSatish Balay   PETSC_INT              = 16,
69262e5d2d2SJDBetteridge   PETSC_INT64            = 17,
6933321ca25SJames Wright   PETSC_COUNT            = 18,
6943321ca25SJames Wright   PETSC_INT32            = 19,
6959371c9d4SSatish Balay } PetscDataType;
6963b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscDataTypes[];
697df4397b0SStefano Zampini 
698df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
699df4397b0SStefano Zampini   #define PETSC_REAL PETSC_FLOAT
7005117d392SLisandro Dalcin #elif defined(PETSC_USE_REAL_DOUBLE)
7015117d392SLisandro Dalcin   #define PETSC_REAL PETSC_DOUBLE
702df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
703df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FLOAT128
704df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
705df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FP16
706df4397b0SStefano Zampini #else
707df4397b0SStefano Zampini   #define PETSC_REAL PETSC_DOUBLE
708df4397b0SStefano Zampini #endif
7095117d392SLisandro Dalcin 
7105117d392SLisandro Dalcin #if defined(PETSC_USE_COMPLEX)
7115117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_COMPLEX
7125117d392SLisandro Dalcin #else
7135117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_REAL
7145117d392SLisandro Dalcin #endif
7155117d392SLisandro Dalcin 
716df4397b0SStefano Zampini #define PETSC_FORTRANADDR PETSC_LONG
717df4397b0SStefano Zampini 
718df4397b0SStefano Zampini /*S
719df4397b0SStefano Zampini   PetscToken - 'Token' used for managing tokenizing strings
720df4397b0SStefano Zampini 
721df4397b0SStefano Zampini   Level: intermediate
722df4397b0SStefano Zampini 
723db781477SPatrick Sanan .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
724df4397b0SStefano Zampini S*/
725df4397b0SStefano Zampini typedef struct _p_PetscToken *PetscToken;
726df4397b0SStefano Zampini 
727df4397b0SStefano Zampini /*S
72887497f52SBarry Smith    PetscObject - any PETSc object, `PetscViewer`, `Mat`, `Vec`, `KSP` etc
729df4397b0SStefano Zampini 
730df4397b0SStefano Zampini    Level: beginner
731df4397b0SStefano Zampini 
73287497f52SBarry Smith    Notes:
733df4397b0SStefano Zampini    This is the base class from which all PETSc objects are derived from.
734df4397b0SStefano Zampini 
73587497f52SBarry Smith    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
73687497f52SBarry Smith 
737db781477SPatrick Sanan .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
738df4397b0SStefano Zampini S*/
739df4397b0SStefano Zampini typedef struct _p_PetscObject *PetscObject;
740df4397b0SStefano Zampini 
741df4397b0SStefano Zampini /*MC
74287497f52SBarry Smith     PetscObjectId - unique integer Id for a `PetscObject`
743df4397b0SStefano Zampini 
744df4397b0SStefano Zampini     Level: developer
745df4397b0SStefano Zampini 
74687497f52SBarry Smith     Note:
74787497f52SBarry 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
74887497f52SBarry Smith     if the objects are the same. Never compare two object pointer values.
749df4397b0SStefano Zampini 
750db781477SPatrick Sanan .seealso: `PetscObjectState`, `PetscObjectGetId()`
751df4397b0SStefano Zampini M*/
752df4397b0SStefano Zampini typedef PetscInt64 PetscObjectId;
753df4397b0SStefano Zampini 
754df4397b0SStefano Zampini /*MC
75587497f52SBarry Smith     PetscObjectState - integer state for a `PetscObject`
756df4397b0SStefano Zampini 
757df4397b0SStefano Zampini     Level: developer
758df4397b0SStefano Zampini 
75995bd0b28SBarry Smith     Note:
760df4397b0SStefano Zampini     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
761df4397b0SStefano 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.
762df4397b0SStefano Zampini 
763db781477SPatrick Sanan .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
764df4397b0SStefano Zampini M*/
765df4397b0SStefano Zampini typedef PetscInt64 PetscObjectState;
766df4397b0SStefano Zampini 
767df4397b0SStefano Zampini /*S
768df4397b0SStefano Zampini      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
769df4397b0SStefano Zampini       by string name
770df4397b0SStefano Zampini 
771df4397b0SStefano Zampini    Level: advanced
772df4397b0SStefano Zampini 
773db781477SPatrick Sanan .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
774df4397b0SStefano Zampini S*/
775df4397b0SStefano Zampini typedef struct _n_PetscFunctionList *PetscFunctionList;
776df4397b0SStefano Zampini 
777df4397b0SStefano Zampini /*E
778df4397b0SStefano Zampini   PetscFileMode - Access mode for a file.
779df4397b0SStefano Zampini 
780667f096bSBarry Smith   Values:
781667f096bSBarry Smith +  `FILE_MODE_UNDEFINED`     - initial invalid value
782667f096bSBarry Smith .  `FILE_MODE_READ`          - open a file at its beginning for reading
783667f096bSBarry Smith .  `FILE_MODE_WRITE`         - open a file at its beginning for writing (will create if the file does not exist)
784667f096bSBarry Smith .  `FILE_MODE_APPEND`        - open a file at end for writing
785667f096bSBarry Smith .  `FILE_MODE_UPDATE`        - open a file for updating, meaning for reading and writing
786667f096bSBarry Smith -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
787df4397b0SStefano Zampini 
78816a05f60SBarry Smith   Level: beginner
78916a05f60SBarry Smith 
790db781477SPatrick Sanan .seealso: `PetscViewerFileSetMode()`
791df4397b0SStefano Zampini E*/
7929371c9d4SSatish Balay typedef enum {
7939371c9d4SSatish Balay   FILE_MODE_UNDEFINED = -1,
7949371c9d4SSatish Balay   FILE_MODE_READ      = 0,
7959371c9d4SSatish Balay   FILE_MODE_WRITE,
7969371c9d4SSatish Balay   FILE_MODE_APPEND,
7979371c9d4SSatish Balay   FILE_MODE_UPDATE,
7989371c9d4SSatish Balay   FILE_MODE_APPEND_UPDATE
7999371c9d4SSatish Balay } PetscFileMode;
8003b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscFileModes[];
801df4397b0SStefano Zampini 
802df4397b0SStefano Zampini typedef void *PetscDLHandle;
8039371c9d4SSatish Balay typedef enum {
8049371c9d4SSatish Balay   PETSC_DL_DECIDE = 0,
8059371c9d4SSatish Balay   PETSC_DL_NOW    = 1,
8069371c9d4SSatish Balay   PETSC_DL_LOCAL  = 2
8079371c9d4SSatish Balay } PetscDLMode;
808df4397b0SStefano Zampini 
809df4397b0SStefano Zampini /*S
8107243573dSPierre Jolivet    PetscObjectList - Linked list of PETSc objects, each accessible by string name
811df4397b0SStefano Zampini 
812df4397b0SStefano Zampini    Level: developer
813df4397b0SStefano Zampini 
81487497f52SBarry Smith    Note:
81587497f52SBarry Smith    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
816df4397b0SStefano Zampini 
817db781477SPatrick Sanan .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
818df4397b0SStefano Zampini S*/
819df4397b0SStefano Zampini typedef struct _n_PetscObjectList *PetscObjectList;
820df4397b0SStefano Zampini 
821df4397b0SStefano Zampini /*S
822667f096bSBarry Smith    PetscDLLibrary - Linked list of dynamic libraries to search for functions
823df4397b0SStefano Zampini 
82416a05f60SBarry Smith    Level: developer
825df4397b0SStefano Zampini 
826db781477SPatrick Sanan .seealso: `PetscDLLibraryOpen()`
827df4397b0SStefano Zampini S*/
828df4397b0SStefano Zampini typedef struct _n_PetscDLLibrary *PetscDLLibrary;
829df4397b0SStefano Zampini 
830df4397b0SStefano Zampini /*S
831df4397b0SStefano Zampini    PetscContainer - Simple PETSc object that contains a pointer to any required data
832df4397b0SStefano Zampini 
833df4397b0SStefano Zampini    Level: advanced
834df4397b0SStefano Zampini 
83587497f52SBarry Smith    Note:
83687497f52SBarry Smith    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
83787497f52SBarry Smith 
83887497f52SBarry Smith .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
839df4397b0SStefano Zampini S*/
840df4397b0SStefano Zampini typedef struct _p_PetscContainer *PetscContainer;
841df4397b0SStefano Zampini 
842df4397b0SStefano Zampini /*S
843df4397b0SStefano Zampini    PetscRandom - Abstract PETSc object that manages generating random numbers
844df4397b0SStefano Zampini 
845df4397b0SStefano Zampini    Level: intermediate
846df4397b0SStefano Zampini 
847db781477SPatrick Sanan .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
848df4397b0SStefano Zampini S*/
849df4397b0SStefano Zampini typedef struct _p_PetscRandom *PetscRandom;
850df4397b0SStefano Zampini 
851df4397b0SStefano Zampini /*
852df4397b0SStefano Zampini    In binary files variables are stored using the following lengths,
853df4397b0SStefano Zampini   regardless of how they are stored in memory on any one particular
854467446fbSPierre Jolivet   machine. Use these rather than sizeof() in computing sizes for
855df4397b0SStefano Zampini   PetscBinarySeek().
856df4397b0SStefano Zampini */
857df4397b0SStefano Zampini #define PETSC_BINARY_INT_SIZE    (32 / 8)
858df4397b0SStefano Zampini #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
859df4397b0SStefano Zampini #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
860df4397b0SStefano Zampini #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
861df4397b0SStefano Zampini #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
862df4397b0SStefano Zampini #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
863df4397b0SStefano Zampini 
864df4397b0SStefano Zampini /*E
86587497f52SBarry Smith   PetscBinarySeekType - argument to `PetscBinarySeek()`
866df4397b0SStefano Zampini 
86716a05f60SBarry Smith   Values:
86816a05f60SBarry Smith +  `PETSC_BINARY_SEEK_SET` - offset is an absolute location in the file
86916a05f60SBarry Smith .  `PETSC_BINARY_SEEK_CUR` - offset is an offset from the current location of the file pointer
87016a05f60SBarry Smith -  `PETSC_BINARY_SEEK_END` - offset is an offset from the end of the file
87116a05f60SBarry Smith 
872df4397b0SStefano Zampini   Level: advanced
873df4397b0SStefano Zampini 
874db781477SPatrick Sanan .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
875df4397b0SStefano Zampini E*/
8769371c9d4SSatish Balay typedef enum {
8779371c9d4SSatish Balay   PETSC_BINARY_SEEK_SET = 0,
8789371c9d4SSatish Balay   PETSC_BINARY_SEEK_CUR = 1,
8799371c9d4SSatish Balay   PETSC_BINARY_SEEK_END = 2
8809371c9d4SSatish Balay } PetscBinarySeekType;
881df4397b0SStefano Zampini 
882df4397b0SStefano Zampini /*E
88316a05f60SBarry Smith    PetscBuildTwoSidedType - algorithm for setting up two-sided communication for use with `PetscSF`
884df4397b0SStefano Zampini 
885667f096bSBarry Smith    Values:
886667f096bSBarry Smith +  `PETSC_BUILDTWOSIDED_ALLREDUCE`  - classical algorithm using an `MPI_Allreduce()` with
887667f096bSBarry Smith                                       a buffer of length equal to the communicator size. Not memory-scalable due to
88816a05f60SBarry Smith                                       the large reduction size. Requires only an MPI-1 implementation.
889667f096bSBarry Smith .  `PETSC_BUILDTWOSIDED_IBARRIER`   - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
89016a05f60SBarry Smith                                       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires an MPI-3 implementation.
891667f096bSBarry Smith -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
89216a05f60SBarry Smith                                       that only communicates the part of the reduction that is necessary.  Requires an MPI-2 implementation.
893df4397b0SStefano Zampini 
894df4397b0SStefano Zampini    Level: developer
895df4397b0SStefano Zampini 
896db781477SPatrick Sanan .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
897df4397b0SStefano Zampini E*/
898df4397b0SStefano Zampini typedef enum {
899df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_NOTSET     = -1,
900df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
901df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
902df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_REDSCATTER = 2
903df4397b0SStefano Zampini   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
904df4397b0SStefano Zampini } PetscBuildTwoSidedType;
9053b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
906df4397b0SStefano Zampini 
907aa2d33c1SMatthew G. Knepley /* NOTE: If you change this, you must also change the values in src/vec/f90-mod/petscvec.h */
908df4397b0SStefano Zampini /*E
909667f096bSBarry Smith   InsertMode - How the entries are combined with the current values in the vectors or matrices
910df4397b0SStefano Zampini 
911667f096bSBarry Smith   Values:
912667f096bSBarry Smith +  `NOT_SET_VALUES`    - do not actually use the values
913667f096bSBarry Smith .  `INSERT_VALUES`     - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
914667f096bSBarry Smith .  `ADD_VALUES`        - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
915667f096bSBarry Smith .  `MAX_VALUES`        - use the maximum of each current value and provided value
916667f096bSBarry Smith .  `MIN_VALUES`        - use the minimum of each current value and provided value
917667f096bSBarry Smith .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
918667f096bSBarry Smith .  `ADD_ALL_VALUES`    - add, even if indices that are not marked as constrained by the `PetscSection`
919667f096bSBarry Smith .  `INSERT_BC_VALUES`  - insert, but ignore indices that are not marked as constrained by the `PetscSection`
920667f096bSBarry Smith -  `ADD_BC_VALUES`     - add, but ignore indices that are not marked as constrained by the `PetscSection`
921667f096bSBarry Smith 
92216a05f60SBarry Smith   Level: beginner
92316a05f60SBarry Smith 
924667f096bSBarry Smith   Note:
925667f096bSBarry Smith   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
926667f096bSBarry Smith   and `DMGetLocalSection()`.
927667f096bSBarry Smith 
928667f096bSBarry Smith   Not all options are supported for all operations or PETSc object types.
929667f096bSBarry Smith 
930db781477SPatrick Sanan .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
931db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
932db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
933df4397b0SStefano Zampini E*/
9349371c9d4SSatish Balay typedef enum {
9359371c9d4SSatish Balay   NOT_SET_VALUES,
9369371c9d4SSatish Balay   INSERT_VALUES,
9379371c9d4SSatish Balay   ADD_VALUES,
9389371c9d4SSatish Balay   MAX_VALUES,
9399371c9d4SSatish Balay   MIN_VALUES,
9409371c9d4SSatish Balay   INSERT_ALL_VALUES,
9419371c9d4SSatish Balay   ADD_ALL_VALUES,
9429371c9d4SSatish Balay   INSERT_BC_VALUES,
9439371c9d4SSatish Balay   ADD_BC_VALUES
9449371c9d4SSatish Balay } InsertMode;
945df4397b0SStefano Zampini 
946df4397b0SStefano Zampini /*MC
947df4397b0SStefano Zampini     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
948df4397b0SStefano Zampini 
949df4397b0SStefano Zampini     Level: beginner
950df4397b0SStefano Zampini 
951db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
952db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
953db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
954df4397b0SStefano Zampini M*/
955df4397b0SStefano Zampini 
956df4397b0SStefano Zampini /*MC
957df4397b0SStefano Zampini     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
958df4397b0SStefano Zampini                  value into that location
959df4397b0SStefano Zampini 
960df4397b0SStefano Zampini     Level: beginner
961df4397b0SStefano Zampini 
962db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
963db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
964db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
965df4397b0SStefano Zampini M*/
966df4397b0SStefano Zampini 
967df4397b0SStefano Zampini /*MC
968df4397b0SStefano Zampini     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
969df4397b0SStefano Zampini 
970df4397b0SStefano Zampini     Level: beginner
971df4397b0SStefano Zampini 
972db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
973df4397b0SStefano Zampini M*/
974df4397b0SStefano Zampini 
975421aa1e7SJunchao Zhang /*MC
976421aa1e7SJunchao Zhang     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
977421aa1e7SJunchao Zhang 
978421aa1e7SJunchao Zhang     Level: beginner
979421aa1e7SJunchao Zhang 
980db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
981421aa1e7SJunchao Zhang M*/
982421aa1e7SJunchao Zhang 
983df4397b0SStefano Zampini /*S
984df4397b0SStefano Zampini    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
985df4397b0SStefano Zampini 
986667f096bSBarry Smith    Values:
987667f096bSBarry 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
988667f096bSBarry Smith .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
989667f096bSBarry Smith -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
990667f096bSBarry Smith 
991df4397b0SStefano Zampini    Sample Usage:
99287497f52SBarry Smith .vb
99316a05f60SBarry Smith        PetscSubcommCreate()
99416a05f60SBarry Smith        PetscSubcommSetNumber()
99516a05f60SBarry Smith        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
99616a05f60SBarry Smith        ccomm = PetscSubcommChild()
99716a05f60SBarry Smith        PetscSubcommDestroy()
99887497f52SBarry Smith .ve
999df4397b0SStefano Zampini 
1000667f096bSBarry Smith    Example:
1001667f096bSBarry Smith    Consider a communicator with six processes split into 3 subcommunicators.
1002667f096bSBarry Smith .vb
100316a05f60SBarry 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
100416a05f60SBarry Smith    PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
1005667f096bSBarry Smith .ve
1006667f096bSBarry Smith 
1007df4397b0SStefano Zampini    Level: advanced
1008df4397b0SStefano Zampini 
100916a05f60SBarry Smith    Note:
101016a05f60SBarry Smith    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
101116a05f60SBarry Smith .vb
101216a05f60SBarry Smith      PetscSubcommChild() returns the associated subcommunicator on this process
101316a05f60SBarry Smith      PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
101416a05f60SBarry Smith .ve
101516a05f60SBarry Smith 
101687497f52SBarry Smith    Developer Note:
101787497f52SBarry Smith    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
1018df4397b0SStefano Zampini    are performed.
1019df4397b0SStefano Zampini 
1020db781477SPatrick Sanan .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
1021df4397b0SStefano Zampini S*/
1022df4397b0SStefano Zampini typedef struct _n_PetscSubcomm *PetscSubcomm;
10239371c9d4SSatish Balay typedef enum {
10249371c9d4SSatish Balay   PETSC_SUBCOMM_GENERAL    = 0,
10259371c9d4SSatish Balay   PETSC_SUBCOMM_CONTIGUOUS = 1,
10269371c9d4SSatish Balay   PETSC_SUBCOMM_INTERLACED = 2
10279371c9d4SSatish Balay } PetscSubcommType;
10283b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscSubcommTypes[];
1029df4397b0SStefano Zampini 
1030df4397b0SStefano Zampini /*S
1031df4397b0SStefano Zampini    PetscHeap - A simple class for managing heaps
1032df4397b0SStefano Zampini 
1033df4397b0SStefano Zampini    Level: intermediate
1034df4397b0SStefano Zampini 
1035db781477SPatrick Sanan .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1036df4397b0SStefano Zampini S*/
1037df4397b0SStefano Zampini typedef struct _PetscHeap *PetscHeap;
1038df4397b0SStefano Zampini 
1039df4397b0SStefano Zampini typedef struct _n_PetscShmComm *PetscShmComm;
1040df4397b0SStefano Zampini typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
1041df4397b0SStefano Zampini 
1042df4397b0SStefano Zampini /*S
1043df4397b0SStefano Zampini    PetscSegBuffer - a segmented extendable buffer
1044df4397b0SStefano Zampini 
1045df4397b0SStefano Zampini    Level: developer
1046df4397b0SStefano Zampini 
1047db781477SPatrick Sanan .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1048df4397b0SStefano Zampini S*/
1049df4397b0SStefano Zampini typedef struct _n_PetscSegBuffer *PetscSegBuffer;
1050df4397b0SStefano Zampini 
1051df4397b0SStefano Zampini typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
1052778ae69aSToby Isaac 
1053778ae69aSToby Isaac /*S
1054778ae69aSToby Isaac      PetscBT - PETSc bitarrays, efficient storage of arrays of boolean values
1055778ae69aSToby Isaac 
1056778ae69aSToby Isaac      Level: advanced
1057778ae69aSToby Isaac 
1058778ae69aSToby Isaac      Notes:
1059778ae69aSToby Isaac      The following routines do not have their own manual pages
1060778ae69aSToby Isaac 
1061778ae69aSToby Isaac .vb
1062778ae69aSToby Isaac      PetscBTCreate(m,&bt)         - creates a bit array with enough room to hold m values
1063778ae69aSToby Isaac      PetscBTDestroy(&bt)          - destroys the bit array
1064778ae69aSToby Isaac      PetscBTMemzero(m,bt)         - zeros the entire bit array (sets all values to false)
1065778ae69aSToby Isaac      PetscBTSet(bt,index)         - sets a particular entry as true
1066778ae69aSToby Isaac      PetscBTClear(bt,index)       - sets a particular entry as false
1067778ae69aSToby Isaac      PetscBTLookup(bt,index)      - returns the value
1068778ae69aSToby Isaac      PetscBTLookupSet(bt,index)   - returns the value and then sets it true
1069778ae69aSToby Isaac      PetscBTLookupClear(bt,index) - returns the value and then sets it false
1070778ae69aSToby Isaac      PetscBTLength(m)             - returns number of bytes in array with m bits
1071778ae69aSToby Isaac      PetscBTView(m,bt,viewer)     - prints all the entries in a bit array
1072778ae69aSToby Isaac .ve
1073778ae69aSToby Isaac 
1074778ae69aSToby Isaac     PETSc does not check error flags on `PetscBTLookup()`, `PetcBTLookupSet()`, `PetscBTLength()` because error checking
1075778ae69aSToby Isaac     would cost hundreds more cycles then the operation.
1076778ae69aSToby Isaac 
1077778ae69aSToby Isaac S*/
1078778ae69aSToby Isaac typedef char *PetscBT;
1079778ae69aSToby Isaac 
1080778ae69aSToby Isaac /* The number of bits in a byte */
1081778ae69aSToby Isaac #define PETSC_BITS_PER_BYTE CHAR_BIT
1082