xref: /petsc/include/petscsystypes.h (revision 667f096b64435359363023126684d9e3b3f4431e)
147d993e7Ssuyashtn /* Portions of this code are under:
247d993e7Ssuyashtn    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
347d993e7Ssuyashtn */
447d993e7Ssuyashtn 
56524c165SJacob Faibussowitsch #ifndef PETSCSYSTYPES_H
626bd1501SBarry Smith #define PETSCSYSTYPES_H
7df4397b0SStefano Zampini 
8df4397b0SStefano Zampini #include <petscconf.h>
9e1bf4ed2SJacob Faibussowitsch #include <petscconf_poison.h>
10df4397b0SStefano Zampini #include <petscfix.h>
113ba16761SJacob Faibussowitsch #include <petscmacros.h> // PETSC_NODISCARD, PETSC_CPP_VERSION
123edda6a2SJed Brown #include <stddef.h>
13df4397b0SStefano Zampini 
14ac09b921SBarry Smith /* SUBMANSEC = Sys */
15ac09b921SBarry Smith 
163ba16761SJacob Faibussowitsch #include <limits.h> // INT_MIN, INT_MAX
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 
613ba16761SJacob Faibussowitsch   These are the generic error codes. These error codes are used in many different places in the
623ba16761SJacob Faibussowitsch   PETSc source code. The C-string versions are at defined in `PetscErrorStrings[]` in
633ba16761SJacob Faibussowitsch   `src/sys/error/err.c`, while the fortran versions are defined in
643ba16761SJacob Faibussowitsch   `src/sys/f90-mod/petscerror.h`. Any changes here must also be made in both locations.
653ba16761SJacob Faibussowitsch 
663ba16761SJacob Faibussowitsch .seealso: `PetscErrorMessage()`, `PetscCall()`, `SETERRQ()`
673ba16761SJacob Faibussowitsch E*/
683ba16761SJacob Faibussowitsch PETSC_ERROR_CODE_TYPEDEF enum PETSC_ERROR_CODE_NODISCARD {
693ba16761SJacob Faibussowitsch   PETSC_SUCCESS                   = 0,
703ba16761SJacob Faibussowitsch   PETSC_ERR_BOOLEAN_MACRO_FAILURE = 1, /* do not use */
713ba16761SJacob Faibussowitsch 
723ba16761SJacob Faibussowitsch   PETSC_ERR_MIN_VALUE = 54, /* should always be one less then the smallest value */
733ba16761SJacob Faibussowitsch 
743ba16761SJacob Faibussowitsch   PETSC_ERR_MEM            = 55, /* unable to allocate requested memory */
753ba16761SJacob Faibussowitsch   PETSC_ERR_SUP            = 56, /* no support for requested operation */
763ba16761SJacob Faibussowitsch   PETSC_ERR_SUP_SYS        = 57, /* no support for requested operation on this computer system */
773ba16761SJacob Faibussowitsch   PETSC_ERR_ORDER          = 58, /* operation done in wrong order */
783ba16761SJacob Faibussowitsch   PETSC_ERR_SIG            = 59, /* signal received */
793ba16761SJacob Faibussowitsch   PETSC_ERR_FP             = 72, /* floating point exception */
803ba16761SJacob Faibussowitsch   PETSC_ERR_COR            = 74, /* corrupted PETSc object */
813ba16761SJacob Faibussowitsch   PETSC_ERR_LIB            = 76, /* error in library called by PETSc */
823ba16761SJacob Faibussowitsch   PETSC_ERR_PLIB           = 77, /* PETSc library generated inconsistent data */
833ba16761SJacob Faibussowitsch   PETSC_ERR_MEMC           = 78, /* memory corruption */
843ba16761SJacob Faibussowitsch   PETSC_ERR_CONV_FAILED    = 82, /* iterative method (KSP or SNES) failed */
853ba16761SJacob Faibussowitsch   PETSC_ERR_USER           = 83, /* user has not provided needed function */
863ba16761SJacob Faibussowitsch   PETSC_ERR_SYS            = 88, /* error in system call */
873ba16761SJacob Faibussowitsch   PETSC_ERR_POINTER        = 70, /* pointer does not point to valid address */
883ba16761SJacob Faibussowitsch   PETSC_ERR_MPI_LIB_INCOMP = 87, /* MPI library at runtime is not compatible with MPI user compiled with */
893ba16761SJacob Faibussowitsch 
903ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_SIZ          = 60, /* nonconforming object sizes used in operation */
913ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_IDN          = 61, /* two arguments not allowed to be the same */
923ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONG        = 62, /* wrong argument (but object probably ok) */
933ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_CORRUPT      = 64, /* null or corrupted PETSc object as argument */
943ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_OUTOFRANGE   = 63, /* input argument, out of range */
953ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_BADPTR       = 68, /* invalid pointer argument */
963ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMETYPE  = 69, /* two args must be same object type */
973ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NOTSAMECOMM  = 80, /* two args must be same communicators */
983ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_WRONGSTATE   = 73, /* object in argument is in wrong state, e.g. unassembled mat */
993ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_TYPENOTSET   = 89, /* the type of the object has not yet been set */
1003ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_INCOMP       = 75, /* two arguments are incompatible */
1013ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_NULL         = 85, /* argument is null that should not be */
1023ba16761SJacob Faibussowitsch   PETSC_ERR_ARG_UNKNOWN_TYPE = 86, /* type name doesn't match any registered type */
1033ba16761SJacob Faibussowitsch 
1043ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_OPEN       = 65, /* unable to open file */
1053ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_READ       = 66, /* unable to read from file */
1063ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_WRITE      = 67, /* unable to write to file */
1073ba16761SJacob Faibussowitsch   PETSC_ERR_FILE_UNEXPECTED = 79, /* unexpected data in file */
1083ba16761SJacob Faibussowitsch 
1093ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_LU_ZRPVT = 71, /* detected a zero pivot during LU factorization */
1103ba16761SJacob Faibussowitsch   PETSC_ERR_MAT_CH_ZRPVT = 81, /* detected a zero pivot during Cholesky factorization */
1113ba16761SJacob Faibussowitsch 
1123ba16761SJacob Faibussowitsch   PETSC_ERR_INT_OVERFLOW   = 84,
1133ba16761SJacob Faibussowitsch   PETSC_ERR_FLOP_COUNT     = 90,
1143ba16761SJacob Faibussowitsch   PETSC_ERR_NOT_CONVERGED  = 91,  /* solver did not converge */
1153ba16761SJacob Faibussowitsch   PETSC_ERR_MISSING_FACTOR = 92,  /* MatGetFactor() failed */
1163ba16761SJacob Faibussowitsch   PETSC_ERR_OPT_OVERWRITE  = 93,  /* attempted to over write options which should not be changed */
1173ba16761SJacob Faibussowitsch   PETSC_ERR_WRONG_MPI_SIZE = 94,  /* example/application run with number of MPI ranks it does not support */
1183ba16761SJacob Faibussowitsch   PETSC_ERR_USER_INPUT     = 95,  /* missing or incorrect user input */
1193ba16761SJacob Faibussowitsch   PETSC_ERR_GPU_RESOURCE   = 96,  /* unable to load a GPU resource, for example cuBLAS */
1203ba16761SJacob 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 */
1213ba16761SJacob Faibussowitsch   PETSC_ERR_MPI            = 98,  /* general MPI error */
1223ba16761SJacob Faibussowitsch   PETSC_ERR_RETURN         = 99,  /* PetscError() incorrectly returned an error code of 0 */
1233ba16761SJacob Faibussowitsch   PETSC_ERR_MAX_VALUE      = 100, /* this is always the one more than the largest error code */
1243ba16761SJacob Faibussowitsch 
1253ba16761SJacob Faibussowitsch   /*
1263ba16761SJacob Faibussowitsch     do not use, exist purely to make the enum bounds equal that of a regular int (so conversion
1273ba16761SJacob Faibussowitsch     to int in main() is not undefined behavior)
1283ba16761SJacob Faibussowitsch   */
1293ba16761SJacob Faibussowitsch   PETSC_ERR_MIN_SIGNED_BOUND_DO_NOT_USE = INT_MIN,
1303ba16761SJacob Faibussowitsch   PETSC_ERR_MAX_SIGNED_BOUND_DO_NOT_USE = INT_MAX
1313ba16761SJacob Faibussowitsch } PETSC_ERROR_CODE_ENUM_NAME;
1323ba16761SJacob Faibussowitsch 
1333ba16761SJacob Faibussowitsch #ifndef PETSC_USE_STRICT_PETSCERRORCODE
134df4397b0SStefano Zampini typedef int PetscErrorCode;
135df4397b0SStefano Zampini 
1363ba16761SJacob Faibussowitsch   /*
1373ba16761SJacob Faibussowitsch   Needed so that C++ lambdas can deduce the return type as PetscErrorCode from
1383ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS). Otherwise we get
1393ba16761SJacob Faibussowitsch 
1403ba16761SJacob Faibussowitsch   error: return type '(unnamed enum at include/petscsystypes.h:50:1)' must match previous
1413ba16761SJacob Faibussowitsch   return type 'int' when lambda expression has unspecified explicit return type
1423ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1433ba16761SJacob Faibussowitsch   ^
1443ba16761SJacob Faibussowitsch */
1453ba16761SJacob Faibussowitsch   #define PETSC_SUCCESS ((PetscErrorCode)0)
1463ba16761SJacob Faibussowitsch #endif
1473ba16761SJacob Faibussowitsch 
1483ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_NODISCARD
1493ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_TYPEDEF
1503ba16761SJacob Faibussowitsch #undef PETSC_ERROR_CODE_ENUM_NAME
1513ba16761SJacob Faibussowitsch 
152df4397b0SStefano Zampini /*MC
153df4397b0SStefano Zampini 
154df4397b0SStefano Zampini     PetscClassId - A unique id used to identify each PETSc class.
155df4397b0SStefano Zampini 
156df4397b0SStefano Zampini     Notes:
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 
160df4397b0SStefano Zampini     Developer Notes:
161*667f096bSBarry 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 
163df4397b0SStefano Zampini     Level: developer
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:
17587497f52SBarry 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
17687497f52SBarry 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 
181db781477SPatrick Sanan .seealso: `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
1923edda6a2SJed Brown     PetscSizeT - datatype used to represent sizes in memory (like size_t)
1933edda6a2SJed Brown 
1943edda6a2SJed Brown     Level: intermediate
1953edda6a2SJed Brown 
1963edda6a2SJed Brown     Notes:
1973edda6a2SJed Brown     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:
20982a78a4eSJed Brown     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 
213db781477SPatrick Sanan .seealso: `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 char  PetscChar;
231df4397b0SStefano Zampini typedef float PetscFloat;
232df4397b0SStefano Zampini 
233df4397b0SStefano Zampini /*MC
234df4397b0SStefano Zampini   PetscInt - PETSc type that represents an integer, used primarily to
235df4397b0SStefano Zampini       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.
236df4397b0SStefano Zampini 
237*667f096bSBarry Smith   Level: beginner
238*667f096bSBarry Smith 
239df4397b0SStefano Zampini   Notes:
24087497f52SBarry 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.
241df4397b0SStefano Zampini 
242db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
243df4397b0SStefano Zampini M*/
244df4397b0SStefano Zampini 
245df4397b0SStefano Zampini #if defined(PETSC_HAVE_STDINT_H)
246df4397b0SStefano Zampini   #include <stdint.h>
247df4397b0SStefano Zampini #endif
248df4397b0SStefano Zampini #if defined(PETSC_HAVE_INTTYPES_H)
249df4397b0SStefano Zampini   #if !defined(__STDC_FORMAT_MACROS)
250df4397b0SStefano Zampini     #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
251df4397b0SStefano Zampini   #endif
252df4397b0SStefano Zampini   #include <inttypes.h>
253df4397b0SStefano Zampini   #if !defined(PRId64)
254df4397b0SStefano Zampini     #define PRId64 "ld"
255df4397b0SStefano Zampini   #endif
256df4397b0SStefano Zampini #endif
257df4397b0SStefano Zampini 
258df4397b0SStefano Zampini #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && defined(PETSC_HAVE_MPI_INT64_T) /* MPI_INT64_T is not guaranteed to be a macro */
259df4397b0SStefano Zampini typedef int64_t PetscInt64;
260bf491261SJacob Faibussowitsch 
261bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
262bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
263bf491261SJacob Faibussowitsch 
264df4397b0SStefano Zampini #elif (PETSC_SIZEOF_LONG_LONG == 8)
265df4397b0SStefano Zampini typedef long long PetscInt64;
266bf491261SJacob Faibussowitsch 
267bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN LLONG_MIN
268bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX LLONG_MAX
269bf491261SJacob Faibussowitsch 
270df4397b0SStefano Zampini #elif defined(PETSC_HAVE___INT64)
271df4397b0SStefano Zampini typedef __int64 PetscInt64;
272bf491261SJacob Faibussowitsch 
273bf491261SJacob Faibussowitsch   #define PETSC_INT64_MIN INT64_MIN
274bf491261SJacob Faibussowitsch   #define PETSC_INT64_MAX INT64_MAX
275bf491261SJacob Faibussowitsch 
276df4397b0SStefano Zampini #else
277df4397b0SStefano Zampini   #error "cannot determine PetscInt64 type"
278df4397b0SStefano Zampini #endif
279df4397b0SStefano Zampini 
280df4397b0SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
281df4397b0SStefano Zampini typedef PetscInt64 PetscInt;
282bf491261SJacob Faibussowitsch 
283bf491261SJacob Faibussowitsch   #define PETSC_INT_MIN PETSC_INT64_MIN
284bf491261SJacob Faibussowitsch   #define PETSC_INT_MAX PETSC_INT64_MAX
285bf491261SJacob Faibussowitsch   #define PetscInt_FMT  PetscInt64_FMT
286df4397b0SStefano Zampini #else
287df4397b0SStefano Zampini typedef int       PetscInt;
288bf491261SJacob Faibussowitsch 
289bf491261SJacob Faibussowitsch enum {
290bf491261SJacob Faibussowitsch   PETSC_INT_MIN = INT_MIN,
291bf491261SJacob Faibussowitsch   PETSC_INT_MAX = INT_MAX
292bf491261SJacob Faibussowitsch };
293bf491261SJacob Faibussowitsch 
294bf491261SJacob Faibussowitsch   #define PetscInt_FMT "d"
295df4397b0SStefano Zampini #endif
296df4397b0SStefano Zampini 
297bf491261SJacob Faibussowitsch #define PETSC_MIN_INT    PETSC_INT_MIN
298bf491261SJacob Faibussowitsch #define PETSC_MAX_INT    PETSC_INT_MAX
299bf491261SJacob Faibussowitsch #define PETSC_MAX_UINT16 65535
300bf491261SJacob Faibussowitsch 
301c93fae50SJacob Faibussowitsch #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && defined(PETSC_HAVE_MPI_INT64_T) /* MPI_INT64_T is not guaranteed to be a macro */
302c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
303c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT PRId64
304c93fae50SJacob Faibussowitsch #elif (PETSC_SIZEOF_LONG_LONG == 8)
305c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_LONG_LONG_INT
306c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "lld"
307c93fae50SJacob Faibussowitsch #elif defined(PETSC_HAVE___INT64)
308c93fae50SJacob Faibussowitsch   #define MPIU_INT64     MPI_INT64_T
309c93fae50SJacob Faibussowitsch   #define PetscInt64_FMT "ld"
310c93fae50SJacob Faibussowitsch #else
311c93fae50SJacob Faibussowitsch   #error "cannot determine PetscInt64 type"
312c93fae50SJacob Faibussowitsch #endif
313c93fae50SJacob Faibussowitsch 
314df4397b0SStefano Zampini /*MC
315df4397b0SStefano Zampini    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
316df4397b0SStefano Zampini 
317*667f096bSBarry Smith    Level: intermediate
318*667f096bSBarry Smith 
319df4397b0SStefano Zampini    Notes:
320*667f096bSBarry Smith    Usually this is the same as `PetscInt`, but if PETSc was built with --with-64-bit-indices but
32187497f52SBarry Smith    standard C/Fortran integers are 32 bit then this may not be the same as `PetscInt`,
32287497f52SBarry Smith    except on some BLAS/LAPACK implementations that support 64 bit integers see the notes below.
323df4397b0SStefano Zampini 
32487497f52SBarry Smith    `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
32587497f52SBarry Smith     generates a `PETSC_ERR_ARG_OUTOFRANGE` error
326df4397b0SStefano Zampini 
327df4397b0SStefano Zampini    Installation Notes:
328cdc6ee08SBarry Smith     ./configure automatically determines the size of the integers used by BLAS/LAPACK except when --with-batch is used
329cdc6ee08SBarry 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-indice
330cdc6ee08SBarry Smith 
331cdc6ee08SBarry Smith     MATLAB ships with BLAS and LAPACK that use 64 bit integers, for example if you run ./configure with, the option
332df4397b0SStefano Zampini      --with-blaslapack-lib=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
333df4397b0SStefano Zampini 
334cdc6ee08SBarry 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
335cdc6ee08SBarry Smith     against the 64 bit version, otherwise it use the 32 bit version
336df4397b0SStefano Zampini 
337cdc6ee08SBarry 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
338df4397b0SStefano Zampini 
339df4397b0SStefano Zampini     External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64 bit integers to BLAS/LAPACK so cannot
340cdc6ee08SBarry 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
341cdc6ee08SBarry Smith     these external libraries while using 64 bit integer BLAS/LAPACK.
342df4397b0SStefano Zampini 
343db781477SPatrick Sanan .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
344df4397b0SStefano Zampini M*/
345df4397b0SStefano Zampini #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
346df4397b0SStefano Zampini typedef PetscInt64 PetscBLASInt;
347bf491261SJacob Faibussowitsch 
348bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
349bf491261SJacob Faibussowitsch   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
350bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT   PetscInt64_FMT
351df4397b0SStefano Zampini #else
352df4397b0SStefano Zampini typedef int PetscBLASInt;
353bf491261SJacob Faibussowitsch 
354bf491261SJacob Faibussowitsch enum {
355bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MIN = INT_MIN,
356bf491261SJacob Faibussowitsch   PETSC_BLAS_INT_MAX = INT_MAX
357bf491261SJacob Faibussowitsch };
358bf491261SJacob Faibussowitsch 
359bf491261SJacob Faibussowitsch   #define PetscBLASInt_FMT "d"
360df4397b0SStefano Zampini #endif
361df4397b0SStefano Zampini 
362eee0c0a6SToby Isaac /*MC
363eee0c0a6SToby Isaac    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
364eee0c0a6SToby Isaac 
365*667f096bSBarry Smith    Level: intermediate
366*667f096bSBarry Smith 
367eee0c0a6SToby Isaac    Notes:
368*667f096bSBarry Smith    As of this writing `PetscCuBLASInt` is always the system `int`.
369eee0c0a6SToby Isaac 
37087497f52SBarry Smith   `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
37187497f52SBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
372eee0c0a6SToby Isaac 
373db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
374eee0c0a6SToby Isaac M*/
375eee0c0a6SToby Isaac typedef int PetscCuBLASInt;
376eee0c0a6SToby Isaac 
377bf491261SJacob Faibussowitsch enum {
378bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MIN = INT_MIN,
379bf491261SJacob Faibussowitsch   PETSC_CUBLAS_INT_MAX = INT_MAX
380bf491261SJacob Faibussowitsch };
381bf491261SJacob Faibussowitsch 
38247d993e7Ssuyashtn /*MC
38347d993e7Ssuyashtn    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
38447d993e7Ssuyashtn 
38547d993e7Ssuyashtn    Level: intermediate
38647d993e7Ssuyashtn 
387*667f096bSBarry Smith    Notes:
388*667f096bSBarry Smith    As of this writing `PetscHipBLASInt` is always the system `int`.
38947d993e7Ssuyashtn 
390*667f096bSBarry Smith    `PetscErrorCode` `PetscHipBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscHipBLASInt`, if not it
391*667f096bSBarry Smith    generates a `PETSC_ERR_ARG_OUTOFRANGE` error
392*667f096bSBarry Smith 
393*667f096bSBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscHipBLASIntCast()
39447d993e7Ssuyashtn M*/
39547d993e7Ssuyashtn typedef int PetscHipBLASInt;
39647d993e7Ssuyashtn 
397bf491261SJacob Faibussowitsch enum {
398bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MIN = INT_MIN,
399bf491261SJacob Faibussowitsch   PETSC_HIPBLAS_INT_MAX = INT_MAX
400bf491261SJacob Faibussowitsch };
401bf491261SJacob Faibussowitsch 
402df4397b0SStefano Zampini /*E
403b94d7dedSBarry Smith     PetscBool  - Logical variable. Actually an enum in C and a logical in Fortran.
404df4397b0SStefano Zampini 
405df4397b0SStefano Zampini    Level: beginner
406df4397b0SStefano Zampini 
407df4397b0SStefano Zampini    Developer Note:
40887497f52SBarry 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
409df4397b0SStefano Zampini       boolean values. It is not easy to have a simple macro that that will work properly in all circumstances with all three mechanisms.
410df4397b0SStefano Zampini 
411b94d7dedSBarry Smith .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
412df4397b0SStefano Zampini E*/
4139371c9d4SSatish Balay typedef enum {
4149371c9d4SSatish Balay   PETSC_FALSE,
4159371c9d4SSatish Balay   PETSC_TRUE
4169371c9d4SSatish Balay } PetscBool;
4173b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBools[];
418df4397b0SStefano Zampini 
419b94d7dedSBarry Smith /*E
420b94d7dedSBarry Smith     PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
421b94d7dedSBarry Smith 
422b94d7dedSBarry Smith    Level: beginner
423b94d7dedSBarry Smith 
42487497f52SBarry Smith    Note:
425b94d7dedSBarry Smith    Should not be used with the if (flg) or if (!flg) syntax.
426b94d7dedSBarry Smith 
42790dd7910SPierre Jolivet .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
428b94d7dedSBarry Smith E*/
4299371c9d4SSatish Balay typedef enum {
4309371c9d4SSatish Balay   PETSC_BOOL3_FALSE,
4319371c9d4SSatish Balay   PETSC_BOOL3_TRUE,
4329371c9d4SSatish Balay   PETSC_BOOL3_UNKNOWN = -1
4339371c9d4SSatish Balay } PetscBool3;
434b94d7dedSBarry Smith 
435b94d7dedSBarry Smith #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
436b94d7dedSBarry Smith #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
437b94d7dedSBarry Smith 
438df4397b0SStefano Zampini /*MC
43987497f52SBarry Smith    PetscReal - PETSc type that represents a real number version of `PetscScalar`
440df4397b0SStefano Zampini 
441*667f096bSBarry Smith    Level: beginner
442*667f096bSBarry Smith 
443df4397b0SStefano Zampini    Notes:
44487497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
44587497f52SBarry Smith    They will automatically work correctly regardless of the size of `PetscReal`.
446df4397b0SStefano Zampini 
44787497f52SBarry Smith    See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
448df4397b0SStefano Zampini 
449db781477SPatrick Sanan .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
450df4397b0SStefano Zampini M*/
451df4397b0SStefano Zampini 
452df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
453df4397b0SStefano Zampini typedef float PetscReal;
454df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL_DOUBLE)
455df4397b0SStefano Zampini typedef double    PetscReal;
456df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
457df4397b0SStefano Zampini   #if defined(__cplusplus)
458df4397b0SStefano Zampini extern "C" {
459df4397b0SStefano Zampini   #endif
460df4397b0SStefano Zampini   #include <quadmath.h>
461df4397b0SStefano Zampini   #if defined(__cplusplus)
462df4397b0SStefano Zampini }
463df4397b0SStefano Zampini   #endif
464df4397b0SStefano Zampini typedef __float128 PetscReal;
465df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
466df4397b0SStefano Zampini typedef __fp16 PetscReal;
467df4397b0SStefano Zampini #endif /* PETSC_USE_REAL_* */
468df4397b0SStefano Zampini 
469df4397b0SStefano Zampini /*MC
47087497f52SBarry Smith    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
471df4397b0SStefano Zampini 
472df4397b0SStefano Zampini    Synopsis:
473df4397b0SStefano Zampini    #include <petscsys.h>
474df4397b0SStefano Zampini    PetscComplex number = 1. + 2.*PETSC_i;
475df4397b0SStefano Zampini 
476*667f096bSBarry Smith    Level: beginner
477*667f096bSBarry Smith 
478df4397b0SStefano Zampini    Notes:
47987497f52SBarry Smith    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
48087497f52SBarry Smith           They will automatically work correctly regardless of the size of `PetscComplex`.
481df4397b0SStefano Zampini 
48287497f52SBarry Smith           See PetscScalar for details on how to ./configure the size of `PetscReal`
483df4397b0SStefano Zampini 
484df4397b0SStefano Zampini           Complex numbers are automatically available if PETSc was able to find a working complex implementation
485df4397b0SStefano Zampini 
48687497f52SBarry Smith     Petsc has a 'fix' for complex numbers to support expressions such as std::complex<PetscReal> + `PetscInt`, which are not supported by the standard
487a966371cSJunchao Zhang     C++ library, but are convenient for petsc users. If the C++ compiler is able to compile code in petsccxxcomplexfix.h (This is checked by
488a966371cSJunchao Zhang     configure), we include petsccxxcomplexfix.h to provide this convenience.
489a966371cSJunchao Zhang 
49087497f52SBarry 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`
491a966371cSJunchao Zhang     at the beginning of the C++ file to skip the fix.
492a966371cSJunchao Zhang 
493db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
494df4397b0SStefano Zampini M*/
495df4397b0SStefano Zampini #if !defined(PETSC_SKIP_COMPLEX)
4967a19d461SSatish Balay   #if defined(PETSC_CLANGUAGE_CXX)
4977a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
4987a19d461SSatish Balay       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
499df4397b0SStefano Zampini         #define PETSC_HAVE_COMPLEX 1
500d5b43468SJose E. Roman       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5017a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5027a19d461SSatish Balay       #endif
503450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
504450fc7c9SSatish Balay       #define PETSC_HAVE_COMPLEX 1
5057a19d461SSatish Balay     #endif
5067a19d461SSatish Balay   #else /* !PETSC_CLANGUAGE_CXX */
5077a19d461SSatish Balay     #if !defined(PETSC_USE_REAL___FP16)
5087a19d461SSatish Balay       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
5097a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
510d5b43468SJose E. Roman       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
5117a19d461SSatish Balay         #define PETSC_HAVE_COMPLEX 1
5127a19d461SSatish Balay       #endif
5137a19d461SSatish Balay     #endif
5147a19d461SSatish Balay   #endif /* PETSC_CLANGUAGE_CXX */
5157a19d461SSatish Balay #endif   /* !PETSC_SKIP_COMPLEX */
5167a19d461SSatish Balay 
5177a19d461SSatish Balay #if defined(PETSC_HAVE_COMPLEX)
5187a19d461SSatish Balay   #if defined(__cplusplus) /* C++ complex support */
51911d22bbfSJunchao Zhang     /* Locate a C++ complex template library */
52011d22bbfSJunchao Zhang     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
52111d22bbfSJunchao Zhang       #define petsccomplexlib Kokkos
52211d22bbfSJunchao Zhang       #include <Kokkos_Complex.hpp>
523022afdc5SJed Brown     #elif defined(__CUDACC__) || defined(__HIPCC__)
524df4397b0SStefano Zampini       #define petsccomplexlib thrust
525df4397b0SStefano Zampini       #include <thrust/complex.h>
526450fc7c9SSatish Balay     #elif defined(PETSC_USE_REAL___FLOAT128)
527450fc7c9SSatish Balay       #include <complex.h>
528df4397b0SStefano Zampini     #else
529df4397b0SStefano Zampini       #define petsccomplexlib std
530df4397b0SStefano Zampini       #include <complex>
531df4397b0SStefano Zampini     #endif
53211d22bbfSJunchao Zhang 
53311d22bbfSJunchao Zhang     /* Define PetscComplex based on the precision */
534df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE)
535df4397b0SStefano Zampini typedef petsccomplexlib::complex<float> PetscComplex;
536df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
537df4397b0SStefano Zampini typedef petsccomplexlib::complex<double> PetscComplex;
538df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
539450fc7c9SSatish Balay typedef __complex128 PetscComplex;
54011d22bbfSJunchao Zhang     #endif
54111d22bbfSJunchao Zhang 
542a966371cSJunchao Zhang     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
543a966371cSJunchao Zhang     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
54439829747SLisandro Dalcin       #include <petsccxxcomplexfix.h>
54511d22bbfSJunchao Zhang     #endif
5467a19d461SSatish Balay   #else /* c99 complex support */
547df4397b0SStefano Zampini     #include <complex.h>
548df4397b0SStefano Zampini     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
549df4397b0SStefano Zampini typedef float _Complex PetscComplex;
550df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL_DOUBLE)
551df4397b0SStefano Zampini typedef double _Complex PetscComplex;
552df4397b0SStefano Zampini     #elif defined(PETSC_USE_REAL___FLOAT128)
553df4397b0SStefano Zampini typedef __complex128 PetscComplex;
554df4397b0SStefano Zampini     #endif /* PETSC_USE_REAL_* */
5557a19d461SSatish Balay   #endif   /* !__cplusplus */
5567a19d461SSatish Balay #endif     /* PETSC_HAVE_COMPLEX */
557df4397b0SStefano Zampini 
558df4397b0SStefano Zampini /*MC
559df4397b0SStefano Zampini    PetscScalar - PETSc type that represents either a double precision real number, a double precision
560df4397b0SStefano Zampini        complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
561df4397b0SStefano Zampini        with --with-scalar-type=real,complex --with-precision=single,double,__float128,__fp16
562df4397b0SStefano Zampini 
563df4397b0SStefano Zampini    Notes:
56487497f52SBarry 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`.
565df4397b0SStefano Zampini 
566df4397b0SStefano Zampini    Level: beginner
567df4397b0SStefano Zampini 
568db781477SPatrick Sanan .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
569df4397b0SStefano Zampini M*/
570df4397b0SStefano Zampini 
5717a19d461SSatish Balay #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
572df4397b0SStefano Zampini typedef PetscComplex PetscScalar;
573df4397b0SStefano Zampini #else  /* PETSC_USE_COMPLEX */
574df4397b0SStefano Zampini typedef PetscReal PetscScalar;
575df4397b0SStefano Zampini #endif /* PETSC_USE_COMPLEX */
576df4397b0SStefano Zampini 
577df4397b0SStefano Zampini /*E
57887497f52SBarry Smith     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
579df4397b0SStefano Zampini 
580df4397b0SStefano Zampini    Level: beginner
581df4397b0SStefano Zampini 
582*667f096bSBarry Smith    Values for array input:
583*667f096bSBarry Smith +   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
584*667f096bSBarry 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
585*667f096bSBarry Smith                           delete the array. The array MUST have been obtained with PetscMalloc(). Hence this mode cannot be used in Fortran.
586*667f096bSBarry 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
587*667f096bSBarry Smith                           the array but the user must delete the array after the object is destroyed.
5885d80c0bfSVaclav Hapla 
589*667f096bSBarry Smith    Values for PetscObject:
590*667f096bSBarry 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.
591*667f096bSBarry Smith .   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user.
592*667f096bSBarry Smith                           increases its reference count).
593*667f096bSBarry Smith -   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
594df4397b0SStefano Zampini E*/
5959371c9d4SSatish Balay typedef enum {
5969371c9d4SSatish Balay   PETSC_COPY_VALUES,
5979371c9d4SSatish Balay   PETSC_OWN_POINTER,
5989371c9d4SSatish Balay   PETSC_USE_POINTER
5999371c9d4SSatish Balay } PetscCopyMode;
6003b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscCopyModes[];
601df4397b0SStefano Zampini 
602df4397b0SStefano Zampini /*MC
60387497f52SBarry Smith     PETSC_FALSE - False value of `PetscBool`
604df4397b0SStefano Zampini 
605df4397b0SStefano Zampini     Level: beginner
606df4397b0SStefano Zampini 
607df4397b0SStefano Zampini     Note:
608df4397b0SStefano Zampini     Zero integer
609df4397b0SStefano Zampini 
61087497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
611df4397b0SStefano Zampini M*/
612df4397b0SStefano Zampini 
613df4397b0SStefano Zampini /*MC
61487497f52SBarry Smith     PETSC_TRUE - True value of `PetscBool`
615df4397b0SStefano Zampini 
616df4397b0SStefano Zampini     Level: beginner
617df4397b0SStefano Zampini 
618df4397b0SStefano Zampini     Note:
619df4397b0SStefano Zampini     Nonzero integer
620df4397b0SStefano Zampini 
62187497f52SBarry Smith .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
622df4397b0SStefano Zampini M*/
623df4397b0SStefano Zampini 
624df4397b0SStefano Zampini /*MC
625df4397b0SStefano Zampini     PetscLogDouble - Used for logging times
626df4397b0SStefano Zampini 
6276b3bf505SPatrick Sanan   Level: developer
6286b3bf505SPatrick Sanan 
629*667f096bSBarry Smith   Note:
630*667f096bSBarry Smith   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
631*667f096bSBarry Smith 
632df4397b0SStefano Zampini M*/
633df4397b0SStefano Zampini typedef double PetscLogDouble;
634df4397b0SStefano Zampini 
635df4397b0SStefano Zampini /*E
636df4397b0SStefano Zampini     PetscDataType - Used for handling different basic data types.
637df4397b0SStefano Zampini 
638df4397b0SStefano Zampini    Level: beginner
639df4397b0SStefano Zampini 
640df4397b0SStefano Zampini    Notes:
64187497f52SBarry Smith    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
642df4397b0SStefano Zampini 
64387497f52SBarry Smith    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
64487497f52SBarry Smith    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
645277f51e8SBarry Smith 
64687497f52SBarry Smith    Developer Notes:
647df4397b0SStefano Zampini    It would be nice if we could always just use MPI Datatypes, why can we not?
648df4397b0SStefano Zampini 
64987497f52SBarry Smith    If you change any values in `PetscDatatype` make sure you update their usage in
650fa131761SBarry Smith    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
65191e29162SBarry Smith 
652*667f096bSBarry Smith    TODO:
653*667f096bSBarry Smith    Add PETSC_INT32 and remove use of improper `PETSC_ENUM`
654277f51e8SBarry Smith 
655db781477SPatrick Sanan .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
656db781477SPatrick Sanan           `PetscDataTypeGetSize()`
657df4397b0SStefano Zampini E*/
6589371c9d4SSatish Balay typedef enum {
6599371c9d4SSatish Balay   PETSC_DATATYPE_UNKNOWN = 0,
6609371c9d4SSatish Balay   PETSC_DOUBLE           = 1,
6619371c9d4SSatish Balay   PETSC_COMPLEX          = 2,
6629371c9d4SSatish Balay   PETSC_LONG             = 3,
6639371c9d4SSatish Balay   PETSC_SHORT            = 4,
6649371c9d4SSatish Balay   PETSC_FLOAT            = 5,
6659371c9d4SSatish Balay   PETSC_CHAR             = 6,
6669371c9d4SSatish Balay   PETSC_BIT_LOGICAL      = 7,
6679371c9d4SSatish Balay   PETSC_ENUM             = 8,
6689371c9d4SSatish Balay   PETSC_BOOL             = 9,
6699371c9d4SSatish Balay   PETSC___FLOAT128       = 10,
6709371c9d4SSatish Balay   PETSC_OBJECT           = 11,
6719371c9d4SSatish Balay   PETSC_FUNCTION         = 12,
6729371c9d4SSatish Balay   PETSC_STRING           = 13,
6739371c9d4SSatish Balay   PETSC___FP16           = 14,
6749371c9d4SSatish Balay   PETSC_STRUCT           = 15,
6759371c9d4SSatish Balay   PETSC_INT              = 16,
67662e5d2d2SJDBetteridge   PETSC_INT64            = 17,
67762e5d2d2SJDBetteridge   PETSC_COUNT            = 18
6789371c9d4SSatish Balay } PetscDataType;
6793b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscDataTypes[];
680df4397b0SStefano Zampini 
681df4397b0SStefano Zampini #if defined(PETSC_USE_REAL_SINGLE)
682df4397b0SStefano Zampini   #define PETSC_REAL PETSC_FLOAT
6835117d392SLisandro Dalcin #elif defined(PETSC_USE_REAL_DOUBLE)
6845117d392SLisandro Dalcin   #define PETSC_REAL PETSC_DOUBLE
685df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FLOAT128)
686df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FLOAT128
687df4397b0SStefano Zampini #elif defined(PETSC_USE_REAL___FP16)
688df4397b0SStefano Zampini   #define PETSC_REAL PETSC___FP16
689df4397b0SStefano Zampini #else
690df4397b0SStefano Zampini   #define PETSC_REAL PETSC_DOUBLE
691df4397b0SStefano Zampini #endif
6925117d392SLisandro Dalcin 
6935117d392SLisandro Dalcin #if defined(PETSC_USE_COMPLEX)
6945117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_COMPLEX
6955117d392SLisandro Dalcin #else
6965117d392SLisandro Dalcin   #define PETSC_SCALAR PETSC_REAL
6975117d392SLisandro Dalcin #endif
6985117d392SLisandro Dalcin 
699df4397b0SStefano Zampini #define PETSC_FORTRANADDR PETSC_LONG
700df4397b0SStefano Zampini 
701df4397b0SStefano Zampini /*S
702df4397b0SStefano Zampini     PetscToken - 'Token' used for managing tokenizing strings
703df4397b0SStefano Zampini 
704df4397b0SStefano Zampini   Level: intermediate
705df4397b0SStefano Zampini 
706db781477SPatrick Sanan .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
707df4397b0SStefano Zampini S*/
708df4397b0SStefano Zampini typedef struct _p_PetscToken *PetscToken;
709df4397b0SStefano Zampini 
710df4397b0SStefano Zampini /*S
71187497f52SBarry Smith      PetscObject - any PETSc object, `PetscViewer`, `Mat`, `Vec`, `KSP` etc
712df4397b0SStefano Zampini 
713df4397b0SStefano Zampini    Level: beginner
714df4397b0SStefano Zampini 
71587497f52SBarry Smith    Notes:
716df4397b0SStefano Zampini    This is the base class from which all PETSc objects are derived from.
717df4397b0SStefano Zampini 
71887497f52SBarry Smith    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
71987497f52SBarry Smith 
720db781477SPatrick Sanan .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
721df4397b0SStefano Zampini S*/
722df4397b0SStefano Zampini typedef struct _p_PetscObject *PetscObject;
723df4397b0SStefano Zampini 
724df4397b0SStefano Zampini /*MC
72587497f52SBarry Smith     PetscObjectId - unique integer Id for a `PetscObject`
726df4397b0SStefano Zampini 
727df4397b0SStefano Zampini     Level: developer
728df4397b0SStefano Zampini 
72987497f52SBarry Smith     Note:
73087497f52SBarry 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
73187497f52SBarry Smith     if the objects are the same. Never compare two object pointer values.
732df4397b0SStefano Zampini 
733db781477SPatrick Sanan .seealso: `PetscObjectState`, `PetscObjectGetId()`
734df4397b0SStefano Zampini M*/
735df4397b0SStefano Zampini typedef PetscInt64 PetscObjectId;
736df4397b0SStefano Zampini 
737df4397b0SStefano Zampini /*MC
73887497f52SBarry Smith     PetscObjectState - integer state for a `PetscObject`
739df4397b0SStefano Zampini 
740df4397b0SStefano Zampini     Level: developer
741df4397b0SStefano Zampini 
742df4397b0SStefano Zampini     Notes:
743df4397b0SStefano Zampini     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
744df4397b0SStefano 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.
745df4397b0SStefano Zampini 
746db781477SPatrick Sanan .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
747df4397b0SStefano Zampini M*/
748df4397b0SStefano Zampini typedef PetscInt64 PetscObjectState;
749df4397b0SStefano Zampini 
750df4397b0SStefano Zampini /*S
751df4397b0SStefano Zampini      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
752df4397b0SStefano Zampini       by string name
753df4397b0SStefano Zampini 
754df4397b0SStefano Zampini    Level: advanced
755df4397b0SStefano Zampini 
756db781477SPatrick Sanan .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
757df4397b0SStefano Zampini S*/
758df4397b0SStefano Zampini typedef struct _n_PetscFunctionList *PetscFunctionList;
759df4397b0SStefano Zampini 
760df4397b0SStefano Zampini /*E
761df4397b0SStefano Zampini   PetscFileMode - Access mode for a file.
762df4397b0SStefano Zampini 
763df4397b0SStefano Zampini   Level: beginner
764df4397b0SStefano Zampini 
765*667f096bSBarry Smith   Values:
766*667f096bSBarry Smith +  `FILE_MODE_UNDEFINED` - initial invalid value
767*667f096bSBarry Smith .  `FILE_MODE_READ` - open a file at its beginning for reading
768*667f096bSBarry Smith .  `FILE_MODE_WRITE` - open a file at its beginning for writing (will create if the file does not exist)
769*667f096bSBarry Smith .  `FILE_MODE_APPEND` - open a file at end for writing
770*667f096bSBarry Smith .  `FILE_MODE_UPDATE` - open a file for updating, meaning for reading and writing
771*667f096bSBarry Smith -  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
772df4397b0SStefano Zampini 
773db781477SPatrick Sanan .seealso: `PetscViewerFileSetMode()`
774df4397b0SStefano Zampini E*/
7759371c9d4SSatish Balay typedef enum {
7769371c9d4SSatish Balay   FILE_MODE_UNDEFINED = -1,
7779371c9d4SSatish Balay   FILE_MODE_READ      = 0,
7789371c9d4SSatish Balay   FILE_MODE_WRITE,
7799371c9d4SSatish Balay   FILE_MODE_APPEND,
7809371c9d4SSatish Balay   FILE_MODE_UPDATE,
7819371c9d4SSatish Balay   FILE_MODE_APPEND_UPDATE
7829371c9d4SSatish Balay } PetscFileMode;
7833b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscFileModes[];
784df4397b0SStefano Zampini 
785df4397b0SStefano Zampini typedef void *PetscDLHandle;
7869371c9d4SSatish Balay typedef enum {
7879371c9d4SSatish Balay   PETSC_DL_DECIDE = 0,
7889371c9d4SSatish Balay   PETSC_DL_NOW    = 1,
7899371c9d4SSatish Balay   PETSC_DL_LOCAL  = 2
7909371c9d4SSatish Balay } PetscDLMode;
791df4397b0SStefano Zampini 
792df4397b0SStefano Zampini /*S
7937243573dSPierre Jolivet      PetscObjectList - Linked list of PETSc objects, each accessible by string name
794df4397b0SStefano Zampini 
795df4397b0SStefano Zampini    Level: developer
796df4397b0SStefano Zampini 
79787497f52SBarry Smith    Note:
79887497f52SBarry Smith    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
799df4397b0SStefano Zampini 
800db781477SPatrick Sanan .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
801df4397b0SStefano Zampini S*/
802df4397b0SStefano Zampini typedef struct _n_PetscObjectList *PetscObjectList;
803df4397b0SStefano Zampini 
804df4397b0SStefano Zampini /*S
805*667f096bSBarry Smith      PetscDLLibrary - Linked list of dynamic libraries to search for functions
806df4397b0SStefano Zampini 
807df4397b0SStefano Zampini    Level: advanced
808df4397b0SStefano Zampini 
809db781477SPatrick Sanan .seealso: `PetscDLLibraryOpen()`
810df4397b0SStefano Zampini S*/
811df4397b0SStefano Zampini typedef struct _n_PetscDLLibrary *PetscDLLibrary;
812df4397b0SStefano Zampini 
813df4397b0SStefano Zampini /*S
814df4397b0SStefano Zampini      PetscContainer - Simple PETSc object that contains a pointer to any required data
815df4397b0SStefano Zampini 
816df4397b0SStefano Zampini    Level: advanced
817df4397b0SStefano Zampini 
81887497f52SBarry Smith    Note:
81987497f52SBarry Smith    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
82087497f52SBarry Smith 
82187497f52SBarry Smith .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
822df4397b0SStefano Zampini S*/
823df4397b0SStefano Zampini typedef struct _p_PetscContainer *PetscContainer;
824df4397b0SStefano Zampini 
825df4397b0SStefano Zampini /*S
826df4397b0SStefano Zampini      PetscRandom - Abstract PETSc object that manages generating random numbers
827df4397b0SStefano Zampini 
828df4397b0SStefano Zampini    Level: intermediate
829df4397b0SStefano Zampini 
830db781477SPatrick Sanan .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
831df4397b0SStefano Zampini S*/
832df4397b0SStefano Zampini typedef struct _p_PetscRandom *PetscRandom;
833df4397b0SStefano Zampini 
834df4397b0SStefano Zampini /*
835df4397b0SStefano Zampini    In binary files variables are stored using the following lengths,
836df4397b0SStefano Zampini   regardless of how they are stored in memory on any one particular
837df4397b0SStefano Zampini   machine. Use these rather then sizeof() in computing sizes for
838df4397b0SStefano Zampini   PetscBinarySeek().
839df4397b0SStefano Zampini */
840df4397b0SStefano Zampini #define PETSC_BINARY_INT_SIZE    (32 / 8)
841df4397b0SStefano Zampini #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
842df4397b0SStefano Zampini #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
843df4397b0SStefano Zampini #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
844df4397b0SStefano Zampini #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
845df4397b0SStefano Zampini #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
846df4397b0SStefano Zampini 
847df4397b0SStefano Zampini /*E
84887497f52SBarry Smith   PetscBinarySeekType - argument to `PetscBinarySeek()`
849df4397b0SStefano Zampini 
850df4397b0SStefano Zampini   Level: advanced
851df4397b0SStefano Zampini 
852db781477SPatrick Sanan .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
853df4397b0SStefano Zampini E*/
8549371c9d4SSatish Balay typedef enum {
8559371c9d4SSatish Balay   PETSC_BINARY_SEEK_SET = 0,
8569371c9d4SSatish Balay   PETSC_BINARY_SEEK_CUR = 1,
8579371c9d4SSatish Balay   PETSC_BINARY_SEEK_END = 2
8589371c9d4SSatish Balay } PetscBinarySeekType;
859df4397b0SStefano Zampini 
860df4397b0SStefano Zampini /*E
861df4397b0SStefano Zampini     PetscBuildTwoSidedType - algorithm for setting up two-sided communication
862df4397b0SStefano Zampini 
863*667f096bSBarry Smith    Values:
864*667f096bSBarry Smith +  `PETSC_BUILDTWOSIDED_ALLREDUCE` - classical algorithm using an `MPI_Allreduce()` with
865*667f096bSBarry Smith       a buffer of length equal to the communicator size. Not memory-scalable due to
866*667f096bSBarry Smith       the large reduction size. Requires only MPI-1.
867*667f096bSBarry Smith .  `PETSC_BUILDTWOSIDED_IBARRIER` - nonblocking algorithm based on `MPI_Issend()` and `MPI_Ibarrier()`.
868*667f096bSBarry Smith       Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires MPI-3.
869*667f096bSBarry Smith -  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
870*667f096bSBarry Smith       that only communicates the part of the reduction that is necessary.  Requires MPI-2.
871df4397b0SStefano Zampini 
872df4397b0SStefano Zampini    Level: developer
873df4397b0SStefano Zampini 
874db781477SPatrick Sanan .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
875df4397b0SStefano Zampini E*/
876df4397b0SStefano Zampini typedef enum {
877df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_NOTSET     = -1,
878df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
879df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
880df4397b0SStefano Zampini   PETSC_BUILDTWOSIDED_REDSCATTER = 2
881df4397b0SStefano Zampini   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
882df4397b0SStefano Zampini } PetscBuildTwoSidedType;
8833b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
884df4397b0SStefano Zampini 
885aa2d33c1SMatthew G. Knepley /* NOTE: If you change this, you must also change the values in src/vec/f90-mod/petscvec.h */
886df4397b0SStefano Zampini /*E
887*667f096bSBarry Smith   InsertMode - How the entries are combined with the current values in the vectors or matrices
888df4397b0SStefano Zampini 
889df4397b0SStefano Zampini   Level: beginner
890df4397b0SStefano Zampini 
891*667f096bSBarry Smith   Values:
892*667f096bSBarry Smith +  `NOT_SET_VALUES` - do not actually use the values
893*667f096bSBarry Smith .  `INSERT_VALUES` - replace the current values with the provided values, unless the index is marked as constrained by the `PetscSection`
894*667f096bSBarry Smith .  `ADD_VALUES` - add the values to the current values, unless the index is marked as constrained by the `PetscSection`
895*667f096bSBarry Smith .  `MAX_VALUES` - use the maximum of each current value and provided value
896*667f096bSBarry Smith .  `MIN_VALUES` - use the minimum of each current value and provided value
897*667f096bSBarry Smith .  `INSERT_ALL_VALUES` - insert, even if indices that are not marked as constrained by the `PetscSection`
898*667f096bSBarry Smith .  `ADD_ALL_VALUES` - add, even if indices that are not marked as constrained by the `PetscSection`
899*667f096bSBarry Smith .  `INSERT_BC_VALUES` - insert, but ignore indices that are not marked as constrained by the `PetscSection`
900*667f096bSBarry Smith -  `ADD_BC_VALUES` - add, but ignore indices that are not marked as constrained by the `PetscSection`
901*667f096bSBarry Smith 
902*667f096bSBarry Smith   Note:
903*667f096bSBarry Smith   The `PetscSection` that determines the effects of the `InsertMode` values can be obtained by the `Vec` object with `VecGetDM()`
904*667f096bSBarry Smith   and `DMGetLocalSection()`.
905*667f096bSBarry Smith 
906*667f096bSBarry Smith   Not all options are supported for all operations or PETSc object types.
907*667f096bSBarry Smith 
908db781477SPatrick Sanan .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
909db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
910db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
911df4397b0SStefano Zampini E*/
9129371c9d4SSatish Balay typedef enum {
9139371c9d4SSatish Balay   NOT_SET_VALUES,
9149371c9d4SSatish Balay   INSERT_VALUES,
9159371c9d4SSatish Balay   ADD_VALUES,
9169371c9d4SSatish Balay   MAX_VALUES,
9179371c9d4SSatish Balay   MIN_VALUES,
9189371c9d4SSatish Balay   INSERT_ALL_VALUES,
9199371c9d4SSatish Balay   ADD_ALL_VALUES,
9209371c9d4SSatish Balay   INSERT_BC_VALUES,
9219371c9d4SSatish Balay   ADD_BC_VALUES
9229371c9d4SSatish Balay } InsertMode;
923df4397b0SStefano Zampini 
924df4397b0SStefano Zampini /*MC
925df4397b0SStefano Zampini     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
926df4397b0SStefano Zampini 
927df4397b0SStefano Zampini     Level: beginner
928df4397b0SStefano Zampini 
929db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
930db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
931db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
932df4397b0SStefano Zampini M*/
933df4397b0SStefano Zampini 
934df4397b0SStefano Zampini /*MC
935df4397b0SStefano Zampini     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
936df4397b0SStefano Zampini                 value into that location
937df4397b0SStefano Zampini 
938df4397b0SStefano Zampini     Level: beginner
939df4397b0SStefano Zampini 
940db781477SPatrick Sanan .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
941db781477SPatrick Sanan           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
942db781477SPatrick Sanan           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
943df4397b0SStefano Zampini M*/
944df4397b0SStefano Zampini 
945df4397b0SStefano Zampini /*MC
946df4397b0SStefano Zampini     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
947df4397b0SStefano Zampini 
948df4397b0SStefano Zampini     Level: beginner
949df4397b0SStefano Zampini 
950db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
951df4397b0SStefano Zampini M*/
952df4397b0SStefano Zampini 
953421aa1e7SJunchao Zhang /*MC
954421aa1e7SJunchao Zhang     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
955421aa1e7SJunchao Zhang 
956421aa1e7SJunchao Zhang     Level: beginner
957421aa1e7SJunchao Zhang 
958db781477SPatrick Sanan .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
959421aa1e7SJunchao Zhang M*/
960421aa1e7SJunchao Zhang 
961df4397b0SStefano Zampini /*S
962df4397b0SStefano Zampini    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
963df4397b0SStefano Zampini 
964*667f096bSBarry Smith    Values:
965*667f096bSBarry 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
966*667f096bSBarry Smith .   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
967*667f096bSBarry Smith -   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
968*667f096bSBarry Smith 
969df4397b0SStefano Zampini    Notes:
97087497f52SBarry Smith    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
971*667f096bSBarry Smith .vb
972*667f096bSBarry Smith      `PetscSubcommChild()` returns the associated subcommunicator on this process
973*667f096bSBarry Smith      `PetscSubcommContiguousParent()` returns a parent communitor but with all child of the same subcommunicator having contiguous rank
974*667f096bSBarry Smith .ve
975df4397b0SStefano Zampini 
976df4397b0SStefano Zampini    Sample Usage:
97787497f52SBarry Smith .vb
97887497f52SBarry Smith        `PetscSubcommCreate()`
97987497f52SBarry Smith        `PetscSubcommSetNumber()`
98087497f52SBarry Smith        `PetscSubcommSetType`(`PETSC_SUBCOMM_INTERLACED`);
98187497f52SBarry Smith        ccomm = `PetscSubcommChild()`
98287497f52SBarry Smith        `PetscSubcommDestroy()`
98387497f52SBarry Smith .ve
984df4397b0SStefano Zampini 
985*667f096bSBarry Smith    Example:
986*667f096bSBarry Smith    Consider a communicator with six processes split into 3 subcommunicators.
987*667f096bSBarry Smith .vb
988*667f096bSBarry 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
989*667f096bSBarry Smith    `PETSC_SUBCOMM_INTERLACED` - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
990*667f096bSBarry Smith .ve
991*667f096bSBarry Smith 
992df4397b0SStefano Zampini    Level: advanced
993df4397b0SStefano Zampini 
99487497f52SBarry Smith    Developer Note:
99587497f52SBarry Smith    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
996df4397b0SStefano Zampini    are performed.
997df4397b0SStefano Zampini 
998db781477SPatrick Sanan .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
999df4397b0SStefano Zampini S*/
1000df4397b0SStefano Zampini typedef struct _n_PetscSubcomm *PetscSubcomm;
10019371c9d4SSatish Balay typedef enum {
10029371c9d4SSatish Balay   PETSC_SUBCOMM_GENERAL    = 0,
10039371c9d4SSatish Balay   PETSC_SUBCOMM_CONTIGUOUS = 1,
10049371c9d4SSatish Balay   PETSC_SUBCOMM_INTERLACED = 2
10059371c9d4SSatish Balay } PetscSubcommType;
10063b590011SJacob Faibussowitsch PETSC_EXTERN const char *const PetscSubcommTypes[];
1007df4397b0SStefano Zampini 
1008df4397b0SStefano Zampini /*S
1009df4397b0SStefano Zampini      PetscHeap - A simple class for managing heaps
1010df4397b0SStefano Zampini 
1011df4397b0SStefano Zampini    Level: intermediate
1012df4397b0SStefano Zampini 
1013db781477SPatrick Sanan .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
1014df4397b0SStefano Zampini S*/
1015df4397b0SStefano Zampini typedef struct _PetscHeap *PetscHeap;
1016df4397b0SStefano Zampini 
1017df4397b0SStefano Zampini typedef struct _n_PetscShmComm *PetscShmComm;
1018df4397b0SStefano Zampini typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
1019df4397b0SStefano Zampini 
1020df4397b0SStefano Zampini /*S
1021df4397b0SStefano Zampini    PetscSegBuffer - a segmented extendable buffer
1022df4397b0SStefano Zampini 
1023df4397b0SStefano Zampini    Level: developer
1024df4397b0SStefano Zampini 
1025db781477SPatrick Sanan .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
1026df4397b0SStefano Zampini S*/
1027df4397b0SStefano Zampini typedef struct _n_PetscSegBuffer *PetscSegBuffer;
1028df4397b0SStefano Zampini 
1029df4397b0SStefano Zampini typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
1030df4397b0SStefano Zampini #endif
1031