xref: /petsc/include/petscsystypes.h (revision c200b30ea8d6d57baaba582ccaf2f8d982509d09)
1 /* Portions of this code are under:
2    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
3 */
4 
5 #ifndef PETSCSYSTYPES_H
6 #define PETSCSYSTYPES_H
7 
8 #include <petscconf.h>
9 #include <petscconf_poison.h>
10 #include <petscfix.h>
11 #include <petscmacros.h>
12 #include <stddef.h>
13 
14 /* SUBMANSEC = Sys */
15 
16 /*MC
17     PetscErrorCode - datatype used for return error code from almost all PETSc functions
18 
19     Level: beginner
20 
21 .seealso: `PetscCall()`, `SETERRQ()`
22 M*/
23 typedef int PetscErrorCode;
24 
25 /*MC
26 
27     PetscClassId - A unique id used to identify each PETSc class.
28 
29     Notes:
30     Use `PetscClassIdRegister()` to obtain a new value for a new class being created. Usually
31          XXXInitializePackage() calls it for each class it defines.
32 
33     Developer Notes:
34     Internal integer stored in the `_p_PetscObject` data structure.
35          These are all computed by an offset from the lowest one, `PETSC_SMALLEST_CLASSID`.
36 
37     Level: developer
38 
39 .seealso: `PetscClassIdRegister()`, `PetscLogEventRegister()`, `PetscHeaderCreate()`
40 M*/
41 typedef int PetscClassId;
42 
43 /*MC
44     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
45 
46     Level: intermediate
47 
48     Notes:
49     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
50            standard C/Fortran integers are 32 bit then this is NOT the same as `PetscInt`; it remains 32 bit.
51 
52     `PetscMPIIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscMPIInt`, if not it
53       generates a `PETSC_ERR_ARG_OUTOFRANGE` error.
54 
55 .seealso: `PetscBLASInt`, `PetscInt`, `PetscMPIIntCast()`
56 
57 M*/
58 typedef int PetscMPIInt;
59 
60 #include <limits.h>
61 
62 /* Limit MPI to 32-bits */
63 enum {
64   PETSC_MPI_INT_MIN = INT_MIN,
65   PETSC_MPI_INT_MAX = INT_MAX
66 };
67 
68 /*MC
69     PetscSizeT - datatype used to represent sizes in memory (like size_t)
70 
71     Level: intermediate
72 
73     Notes:
74     This is equivalent to size_t, but defined for consistency with Fortran, which lacks a native equivalent of size_t.
75 
76 .seealso: `PetscInt`, `PetscInt64`, `PetscCount`
77 
78 M*/
79 typedef size_t PetscSizeT;
80 
81 /*MC
82     PetscCount - signed datatype used to represent counts
83 
84     Level: intermediate
85 
86     Notes:
87     This is equivalent to ptrdiff_t, but defined for consistency with Fortran, which lacks a native equivalent of ptrdiff_t.
88 
89     Use `PetscCount_FMT` to format with `PetscPrintf()`, `printf()`, and related functions.
90 
91 .seealso: `PetscInt`, `PetscInt64`, `PetscSizeT`
92 
93 M*/
94 typedef ptrdiff_t PetscCount;
95 #define PetscCount_FMT "td"
96 
97 /*MC
98     PetscEnum - datatype used to pass enum types within PETSc functions.
99 
100     Level: intermediate
101 
102 .seealso: `PetscOptionsGetEnum()`, `PetscOptionsEnum()`, `PetscBagRegisterEnum()`
103 M*/
104 typedef enum {
105   ENUM_DUMMY
106 } PetscEnum;
107 
108 typedef short PetscShort;
109 typedef char  PetscChar;
110 typedef float PetscFloat;
111 
112 /*MC
113   PetscInt - PETSc type that represents an integer, used primarily to
114       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.
115 
116   Notes:
117   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.
118 
119   Level: beginner
120 
121 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
122 M*/
123 
124 #if defined(PETSC_HAVE_STDINT_H)
125   #include <stdint.h>
126 #endif
127 #if defined(PETSC_HAVE_INTTYPES_H)
128   #if !defined(__STDC_FORMAT_MACROS)
129     #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
130   #endif
131   #include <inttypes.h>
132   #if !defined(PRId64)
133     #define PRId64 "ld"
134   #endif
135 #endif
136 
137 #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 */
138 typedef int64_t PetscInt64;
139 
140   #define PETSC_INT64_MIN INT64_MIN
141   #define PETSC_INT64_MAX INT64_MAX
142 
143 #elif (PETSC_SIZEOF_LONG_LONG == 8)
144 typedef long long PetscInt64;
145 
146   #define PETSC_INT64_MIN LLONG_MIN
147   #define PETSC_INT64_MAX LLONG_MAX
148 
149 #elif defined(PETSC_HAVE___INT64)
150 typedef __int64 PetscInt64;
151 
152   #define PETSC_INT64_MIN INT64_MIN
153   #define PETSC_INT64_MAX INT64_MAX
154 
155 #else
156   #error "cannot determine PetscInt64 type"
157 #endif
158 
159 #if defined(PETSC_USE_64BIT_INDICES)
160 typedef PetscInt64 PetscInt;
161 
162   #define PETSC_INT_MIN PETSC_INT64_MIN
163   #define PETSC_INT_MAX PETSC_INT64_MAX
164   #define PetscInt_FMT  PetscInt64_FMT
165 #else
166 typedef int       PetscInt;
167 
168 enum {
169   PETSC_INT_MIN = INT_MIN,
170   PETSC_INT_MAX = INT_MAX
171 };
172 
173   #define PetscInt_FMT "d"
174 #endif
175 
176 #define PETSC_MIN_INT    PETSC_INT_MIN
177 #define PETSC_MAX_INT    PETSC_INT_MAX
178 #define PETSC_MAX_UINT16 65535
179 
180 #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 */
181   #define MPIU_INT64     MPI_INT64_T
182   #define PetscInt64_FMT PRId64
183 #elif (PETSC_SIZEOF_LONG_LONG == 8)
184   #define MPIU_INT64     MPI_LONG_LONG_INT
185   #define PetscInt64_FMT "lld"
186 #elif defined(PETSC_HAVE___INT64)
187   #define MPIU_INT64     MPI_INT64_T
188   #define PetscInt64_FMT "ld"
189 #else
190   #error "cannot determine PetscInt64 type"
191 #endif
192 
193 /*MC
194    PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
195 
196    Notes:
197     Usually this is the same as `PetscIn`t, but if PETSc was built with --with-64-bit-indices but
198            standard C/Fortran integers are 32 bit then this may not be the same as `PetscInt`,
199            except on some BLAS/LAPACK implementations that support 64 bit integers see the notes below.
200 
201     `PetscErrorCode` `PetscBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscBLASInt`, if not it
202       generates a `PETSC_ERR_ARG_OUTOFRANGE` error
203 
204    Installation Notes:
205     ./configure automatically determines the size of the integers used by BLAS/LAPACK except when --with-batch is used
206     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
207 
208     MATLAB ships with BLAS and LAPACK that use 64 bit integers, for example if you run ./configure with, the option
209      --with-blaslapack-lib=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
210 
211     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
212     against the 64 bit version, otherwise it use the 32 bit version
213 
214     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
215 
216     External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64 bit integers to BLAS/LAPACK so cannot
217     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
218     these external libraries while using 64 bit integer BLAS/LAPACK.
219 
220    Level: intermediate
221 
222 .seealso: `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`
223 
224 M*/
225 #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
226 typedef PetscInt64 PetscBLASInt;
227 
228   #define PETSC_BLAS_INT_MIN PETSC_INT64_MIN
229   #define PETSC_BLAS_INT_MAX PETSC_INT64_MAX
230   #define PetscBLASInt_FMT   PetscInt64_FMT
231 #else
232 typedef int PetscBLASInt;
233 
234 enum {
235   PETSC_BLAS_INT_MIN = INT_MIN,
236   PETSC_BLAS_INT_MAX = INT_MAX
237 };
238 
239   #define PetscBLASInt_FMT "d"
240 #endif
241 
242 /*MC
243    PetscCuBLASInt - datatype used to represent 'int' parameters to cuBLAS/cuSOLVER functions.
244 
245    Notes:
246     As of this writing PetscCuBLASInt is always the system `int`.
247 
248     `PetscErrorCode` `PetscCuBLASIntCast`(a,&b) checks if the given `PetscInt` a will fit in a `PetscCuBLASInt`, if not it
249       generates a `PETSC_ERR_ARG_OUTOFRANGE` error
250 
251    Level: intermediate
252 
253 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscCuBLASIntCast()`
254 
255 M*/
256 typedef int PetscCuBLASInt;
257 
258 enum {
259   PETSC_CUBLAS_INT_MIN = INT_MIN,
260   PETSC_CUBLAS_INT_MAX = INT_MAX
261 };
262 
263 /*MC
264    PetscHipBLASInt - datatype used to represent 'int' parameters to hipBLAS/hipSOLVER functions.
265 
266    Notes:
267     As of this writing PetscHipBLASInt is always the system `int`.
268 
269     PetscErrorCode PetscHipBLASIntCast(a,&b) checks if the given PetscInt a will fit in a PetscHipBLASInt, if not it
270       generates a PETSC_ERR_ARG_OUTOFRANGE error
271 
272    Level: intermediate
273 
274 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscHipBLASIntCast()
275 
276 M*/
277 typedef int PetscHipBLASInt;
278 
279 enum {
280   PETSC_HIPBLAS_INT_MIN = INT_MIN,
281   PETSC_HIPBLAS_INT_MAX = INT_MAX
282 };
283 
284 /*E
285     PetscBool  - Logical variable. Actually an enum in C and a logical in Fortran.
286 
287    Level: beginner
288 
289    Developer Note:
290    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
291       boolean values. It is not easy to have a simple macro that that will work properly in all circumstances with all three mechanisms.
292 
293 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PetscBool3`
294 E*/
295 typedef enum {
296   PETSC_FALSE,
297   PETSC_TRUE
298 } PetscBool;
299 PETSC_EXTERN const char *const PetscBools[];
300 
301 /*E
302     PetscBool3  - Ternary logical variable. Actually an enum in C and a 4 byte integer in Fortran.
303 
304    Level: beginner
305 
306    Note:
307    Should not be used with the if (flg) or if (!flg) syntax.
308 
309 .seealso: `PETSC_TRUE`, `PETSC_FALSE`, `PetscNot()`, `PETSC_BOOL3_TRUE`, `PETSC_BOOL3_FALSE`, `PETSC_BOOL3_UNKNOWN`
310 E*/
311 typedef enum {
312   PETSC_BOOL3_FALSE,
313   PETSC_BOOL3_TRUE,
314   PETSC_BOOL3_UNKNOWN = -1
315 } PetscBool3;
316 
317 #define PetscBool3ToBool(a) ((a) == PETSC_BOOL3_TRUE ? PETSC_TRUE : PETSC_FALSE)
318 #define PetscBoolToBool3(a) ((a) == PETSC_TRUE ? PETSC_BOOL3_TRUE : PETSC_BOOL3_FALSE)
319 
320 /*MC
321    PetscReal - PETSc type that represents a real number version of `PetscScalar`
322 
323    Notes:
324    For MPI calls that require datatypes, use `MPIU_REAL` as the datatype for `PetscReal` and `MPIU_SUM`, `MPIU_MAX`, etc. for operations.
325           They will automatically work correctly regardless of the size of `PetscReal`.
326 
327           See `PetscScalar` for details on how to ./configure the size of `PetscReal`.
328 
329    Level: beginner
330 
331 .seealso: `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`
332 M*/
333 
334 #if defined(PETSC_USE_REAL_SINGLE)
335 typedef float PetscReal;
336 #elif defined(PETSC_USE_REAL_DOUBLE)
337 typedef double    PetscReal;
338 #elif defined(PETSC_USE_REAL___FLOAT128)
339   #if defined(__cplusplus)
340 extern "C" {
341   #endif
342   #include <quadmath.h>
343   #if defined(__cplusplus)
344 }
345   #endif
346 typedef __float128 PetscReal;
347 #elif defined(PETSC_USE_REAL___FP16)
348 typedef __fp16 PetscReal;
349 #endif /* PETSC_USE_REAL_* */
350 
351 /*MC
352    PetscComplex - PETSc type that represents a complex number with precision matching that of `PetscReal`.
353 
354    Synopsis:
355    #include <petscsys.h>
356    PetscComplex number = 1. + 2.*PETSC_i;
357 
358    Notes:
359    For MPI calls that require datatypes, use `MPIU_COMPLEX` as the datatype for `PetscComplex` and `MPIU_SUM` etc for operations.
360           They will automatically work correctly regardless of the size of `PetscComplex`.
361 
362           See PetscScalar for details on how to ./configure the size of `PetscReal`
363 
364           Complex numbers are automatically available if PETSc was able to find a working complex implementation
365 
366     Petsc has a 'fix' for complex numbers to support expressions such as std::complex<PetscReal> + `PetscInt`, which are not supported by the standard
367     C++ library, but are convenient for petsc users. If the C++ compiler is able to compile code in petsccxxcomplexfix.h (This is checked by
368     configure), we include petsccxxcomplexfix.h to provide this convenience.
369 
370     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`
371     at the beginning of the C++ file to skip the fix.
372 
373    Level: beginner
374 
375 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PETSC_i`
376 M*/
377 #if !defined(PETSC_SKIP_COMPLEX)
378   #if defined(PETSC_CLANGUAGE_CXX)
379     #if !defined(PETSC_USE_REAL___FP16) && !defined(PETSC_USE_REAL___FLOAT128)
380       #if defined(__cplusplus) && defined(PETSC_HAVE_CXX_COMPLEX) /* enable complex for library code */
381         #define PETSC_HAVE_COMPLEX 1
382       #elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
383         #define PETSC_HAVE_COMPLEX 1
384       #endif
385     #elif defined(PETSC_USE_REAL___FLOAT128) && defined(PETSC_HAVE_C99_COMPLEX)
386       #define PETSC_HAVE_COMPLEX 1
387     #endif
388   #else /* !PETSC_CLANGUAGE_CXX */
389     #if !defined(PETSC_USE_REAL___FP16)
390       #if !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) /* enable complex for library code */
391         #define PETSC_HAVE_COMPLEX 1
392       #elif defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX) /* User code only - conditional on library code complex support */
393         #define PETSC_HAVE_COMPLEX 1
394       #endif
395     #endif
396   #endif /* PETSC_CLANGUAGE_CXX */
397 #endif   /* !PETSC_SKIP_COMPLEX */
398 
399 #if defined(PETSC_HAVE_COMPLEX)
400   #if defined(__cplusplus) /* C++ complex support */
401     /* Locate a C++ complex template library */
402     #if defined(PETSC_DESIRE_KOKKOS_COMPLEX) /* Defined in petscvec_kokkos.hpp for *.kokkos.cxx files */
403       #define petsccomplexlib Kokkos
404       #include <Kokkos_Complex.hpp>
405     #elif defined(__CUDACC__) || defined(__HIPCC__)
406       #define petsccomplexlib thrust
407       #include <thrust/complex.h>
408     #elif defined(PETSC_USE_REAL___FLOAT128)
409       #include <complex.h>
410     #else
411       #define petsccomplexlib std
412       #include <complex>
413     #endif
414 
415     /* Define PetscComplex based on the precision */
416     #if defined(PETSC_USE_REAL_SINGLE)
417 typedef petsccomplexlib::complex<float> PetscComplex;
418     #elif defined(PETSC_USE_REAL_DOUBLE)
419 typedef petsccomplexlib::complex<double> PetscComplex;
420     #elif defined(PETSC_USE_REAL___FLOAT128)
421 typedef __complex128 PetscComplex;
422     #endif
423 
424     /* Include a PETSc C++ complex 'fix'. Check PetscComplex manual page for details */
425     #if defined(PETSC_HAVE_CXX_COMPLEX_FIX) && !defined(PETSC_SKIP_CXX_COMPLEX_FIX)
426       #include <petsccxxcomplexfix.h>
427     #endif
428   #else /* c99 complex support */
429     #include <complex.h>
430     #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16)
431 typedef float _Complex PetscComplex;
432     #elif defined(PETSC_USE_REAL_DOUBLE)
433 typedef double _Complex PetscComplex;
434     #elif defined(PETSC_USE_REAL___FLOAT128)
435 typedef __complex128 PetscComplex;
436     #endif /* PETSC_USE_REAL_* */
437   #endif   /* !__cplusplus */
438 #endif     /* PETSC_HAVE_COMPLEX */
439 
440 /*MC
441    PetscScalar - PETSc type that represents either a double precision real number, a double precision
442        complex number, a single precision real number, a __float128 real or complex or a __fp16 real - if the code is configured
443        with --with-scalar-type=real,complex --with-precision=single,double,__float128,__fp16
444 
445    Notes:
446    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`.
447 
448    Level: beginner
449 
450 .seealso: `PetscReal`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`, `MPIU_INT`, `PetscRealPart()`, `PetscImaginaryPart()`
451 M*/
452 
453 #if defined(PETSC_USE_COMPLEX) && defined(PETSC_HAVE_COMPLEX)
454 typedef PetscComplex PetscScalar;
455 #else  /* PETSC_USE_COMPLEX */
456 typedef PetscReal PetscScalar;
457 #endif /* PETSC_USE_COMPLEX */
458 
459 /*E
460     PetscCopyMode  - Determines how an array or `PetscObject` passed to certain functions is copied or retained by the aggregate `PetscObject`
461 
462    Level: beginner
463 
464    For the array input:
465 $   `PETSC_COPY_VALUES` - the array values are copied into new space, the user is free to reuse or delete the passed in array
466 $   `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
467 $                       delete the array. The array MUST have been obtained with PetscMalloc(). Hence this mode cannot be used in Fortran.
468 $   `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
469 $                       the array but the user must delete the array after the object is destroyed.
470 
471    For the PetscObject input:
472 $   `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.
473 $   `PETSC_OWN_POINTER` - the input `PetscObject` is referenced by pointer (with reference count), thus should not be modified by the user. (Modification may cause errors or unintended side-effects in this or a future version of PETSc.)
474    For either case above, the input `PetscObject` should be destroyed by the user when no longer needed (the aggregate object increases its reference count).
475 $   `PETSC_USE_POINTER` - invalid for `PetscObject` inputs.
476 
477 E*/
478 typedef enum {
479   PETSC_COPY_VALUES,
480   PETSC_OWN_POINTER,
481   PETSC_USE_POINTER
482 } PetscCopyMode;
483 PETSC_EXTERN const char *const PetscCopyModes[];
484 
485 /*MC
486     PETSC_FALSE - False value of `PetscBool`
487 
488     Level: beginner
489 
490     Note:
491     Zero integer
492 
493 .seealso: `PetscBool`, `PetscBool3`, `PETSC_TRUE`
494 M*/
495 
496 /*MC
497     PETSC_TRUE - True value of `PetscBool`
498 
499     Level: beginner
500 
501     Note:
502     Nonzero integer
503 
504 .seealso: `PetscBool`, `PetscBool3`, `PETSC_FALSE`
505 M*/
506 
507 /*MC
508     PetscLogDouble - Used for logging times
509 
510   Notes:
511   Contains double precision numbers that are not used in the numerical computations, but rather in logging, timing etc.
512 
513   Level: developer
514 
515 M*/
516 typedef double PetscLogDouble;
517 
518 /*E
519     PetscDataType - Used for handling different basic data types.
520 
521    Level: beginner
522 
523    Notes:
524    Use of this should be avoided if one can directly use `MPI_Datatype` instead.
525 
526    `PETSC_INT` is the datatype for a `PetscInt`, regardless of whether it is 4 or 8 bytes.
527    `PETSC_REAL`, `PETSC_COMPLEX` and `PETSC_SCALAR` are the datatypes for `PetscReal`, `PetscComplex` and `PetscScalar`, regardless of their sizes.
528 
529    Developer Notes:
530    It would be nice if we could always just use MPI Datatypes, why can we not?
531 
532    If you change any values in `PetscDatatype` make sure you update their usage in
533    share/petsc/matlab/PetscBagRead.m and share/petsc/matlab/@PetscOpenSocket/read/write.m
534 
535    TODO: Add PETSC_INT32 and remove use of improper PETSC_ENUM
536 
537 .seealso: `PetscBinaryRead()`, `PetscBinaryWrite()`, `PetscDataTypeToMPIDataType()`,
538           `PetscDataTypeGetSize()`
539 
540 E*/
541 typedef enum {
542   PETSC_DATATYPE_UNKNOWN = 0,
543   PETSC_DOUBLE           = 1,
544   PETSC_COMPLEX          = 2,
545   PETSC_LONG             = 3,
546   PETSC_SHORT            = 4,
547   PETSC_FLOAT            = 5,
548   PETSC_CHAR             = 6,
549   PETSC_BIT_LOGICAL      = 7,
550   PETSC_ENUM             = 8,
551   PETSC_BOOL             = 9,
552   PETSC___FLOAT128       = 10,
553   PETSC_OBJECT           = 11,
554   PETSC_FUNCTION         = 12,
555   PETSC_STRING           = 13,
556   PETSC___FP16           = 14,
557   PETSC_STRUCT           = 15,
558   PETSC_INT              = 16,
559   PETSC_INT64            = 17,
560   PETSC_COUNT            = 18
561 } PetscDataType;
562 PETSC_EXTERN const char *const PetscDataTypes[];
563 
564 #if defined(PETSC_USE_REAL_SINGLE)
565   #define PETSC_REAL PETSC_FLOAT
566 #elif defined(PETSC_USE_REAL_DOUBLE)
567   #define PETSC_REAL PETSC_DOUBLE
568 #elif defined(PETSC_USE_REAL___FLOAT128)
569   #define PETSC_REAL PETSC___FLOAT128
570 #elif defined(PETSC_USE_REAL___FP16)
571   #define PETSC_REAL PETSC___FP16
572 #else
573   #define PETSC_REAL PETSC_DOUBLE
574 #endif
575 
576 #if defined(PETSC_USE_COMPLEX)
577   #define PETSC_SCALAR PETSC_COMPLEX
578 #else
579   #define PETSC_SCALAR PETSC_REAL
580 #endif
581 
582 #define PETSC_FORTRANADDR PETSC_LONG
583 
584 /*S
585     PetscToken - 'Token' used for managing tokenizing strings
586 
587   Level: intermediate
588 
589 .seealso: `PetscTokenCreate()`, `PetscTokenFind()`, `PetscTokenDestroy()`
590 S*/
591 typedef struct _p_PetscToken *PetscToken;
592 
593 /*S
594      PetscObject - any PETSc object, `PetscViewer`, `Mat`, `Vec`, `KSP` etc
595 
596    Level: beginner
597 
598    Notes:
599    This is the base class from which all PETSc objects are derived from.
600 
601    In certain situations one can cast an object, for example a `Vec`, to a `PetscObject` with (`PetscObject`)vec
602 
603 .seealso: `PetscObjectDestroy()`, `PetscObjectView()`, `PetscObjectGetName()`, `PetscObjectSetName()`, `PetscObjectReference()`, `PetscObjectDereference()`
604 S*/
605 typedef struct _p_PetscObject *PetscObject;
606 
607 /*MC
608     PetscObjectId - unique integer Id for a `PetscObject`
609 
610     Level: developer
611 
612     Note:
613     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
614     if the objects are the same. Never compare two object pointer values.
615 
616 .seealso: `PetscObjectState`, `PetscObjectGetId()`
617 M*/
618 typedef PetscInt64 PetscObjectId;
619 
620 /*MC
621     PetscObjectState - integer state for a `PetscObject`
622 
623     Level: developer
624 
625     Notes:
626     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
627     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.
628 
629 .seealso: `PetscObjectId`, `PetscObjectStateGet()`, `PetscObjectStateIncrease()`, `PetscObjectStateSet()`
630 M*/
631 typedef PetscInt64 PetscObjectState;
632 
633 /*S
634      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
635       by string name
636 
637    Level: advanced
638 
639 .seealso: `PetscFunctionListAdd()`, `PetscFunctionListDestroy()`
640 S*/
641 typedef struct _n_PetscFunctionList *PetscFunctionList;
642 
643 /*E
644   PetscFileMode - Access mode for a file.
645 
646   Level: beginner
647 
648 $  `FILE_MODE_UNDEFINED` - initial invalid value
649 $  `FILE_MODE_READ` - open a file at its beginning for reading
650 $  `FILE_MODE_WRITE` - open a file at its beginning for writing (will create if the file does not exist)
651 $  `FILE_MODE_APPEND` - open a file at end for writing
652 $  `FILE_MODE_UPDATE` - open a file for updating, meaning for reading and writing
653 $  `FILE_MODE_APPEND_UPDATE` - open a file for updating, meaning for reading and writing, at the end
654 
655 .seealso: `PetscViewerFileSetMode()`
656 E*/
657 typedef enum {
658   FILE_MODE_UNDEFINED = -1,
659   FILE_MODE_READ      = 0,
660   FILE_MODE_WRITE,
661   FILE_MODE_APPEND,
662   FILE_MODE_UPDATE,
663   FILE_MODE_APPEND_UPDATE
664 } PetscFileMode;
665 PETSC_EXTERN const char *const PetscFileModes[];
666 
667 typedef void *PetscDLHandle;
668 typedef enum {
669   PETSC_DL_DECIDE = 0,
670   PETSC_DL_NOW    = 1,
671   PETSC_DL_LOCAL  = 2
672 } PetscDLMode;
673 
674 /*S
675      PetscObjectList - Linked list of PETSc objects, each accessible by string name
676 
677    Level: developer
678 
679    Note:
680    Used by `PetscObjectCompose()` and `PetscObjectQuery()`
681 
682 .seealso: `PetscObjectListAdd()`, `PetscObjectListDestroy()`, `PetscObjectListFind()`, `PetscObjectCompose()`, `PetscObjectQuery()`, `PetscFunctionList`
683 S*/
684 typedef struct _n_PetscObjectList *PetscObjectList;
685 
686 /*S
687      PetscDLLibrary - Linked list of dynamics libraries to search for functions
688 
689    Level: advanced
690 
691 .seealso: `PetscDLLibraryOpen()`
692 S*/
693 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
694 
695 /*S
696      PetscContainer - Simple PETSc object that contains a pointer to any required data
697 
698    Level: advanced
699 
700    Note:
701    This is useful to attach arbitrary data to a `PetscObject` with `PetscObjectCompose()` and `PetscObjectQuery()`
702 
703 .seealso: `PetscObject`, `PetscContainerCreate()`, `PetscObjectCompose()`, `PetscObjectQuery()`
704 S*/
705 typedef struct _p_PetscContainer *PetscContainer;
706 
707 /*S
708      PetscRandom - Abstract PETSc object that manages generating random numbers
709 
710    Level: intermediate
711 
712 .seealso: `PetscRandomCreate()`, `PetscRandomGetValue()`, `PetscRandomType`
713 S*/
714 typedef struct _p_PetscRandom *PetscRandom;
715 
716 /*
717    In binary files variables are stored using the following lengths,
718   regardless of how they are stored in memory on any one particular
719   machine. Use these rather then sizeof() in computing sizes for
720   PetscBinarySeek().
721 */
722 #define PETSC_BINARY_INT_SIZE    (32 / 8)
723 #define PETSC_BINARY_FLOAT_SIZE  (32 / 8)
724 #define PETSC_BINARY_CHAR_SIZE   (8 / 8)
725 #define PETSC_BINARY_SHORT_SIZE  (16 / 8)
726 #define PETSC_BINARY_DOUBLE_SIZE (64 / 8)
727 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
728 
729 /*E
730   PetscBinarySeekType - argument to `PetscBinarySeek()`
731 
732   Level: advanced
733 
734 .seealso: `PetscBinarySeek()`, `PetscBinarySynchronizedSeek()`
735 E*/
736 typedef enum {
737   PETSC_BINARY_SEEK_SET = 0,
738   PETSC_BINARY_SEEK_CUR = 1,
739   PETSC_BINARY_SEEK_END = 2
740 } PetscBinarySeekType;
741 
742 /*E
743     PetscBuildTwoSidedType - algorithm for setting up two-sided communication
744 
745 $  `PETSC_BUILDTWOSIDED_ALLREDUCE` - classical algorithm using an MPI_Allreduce with
746 $      a buffer of length equal to the communicator size. Not memory-scalable due to
747 $      the large reduction size. Requires only MPI-1.
748 $  `PETSC_BUILDTWOSIDED_IBARRIER` - nonblocking algorithm based on MPI_Issend and MPI_Ibarrier.
749 $      Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires MPI-3.
750 $  `PETSC_BUILDTWOSIDED_REDSCATTER` - similar to above, but use more optimized function
751 $      that only communicates the part of the reduction that is necessary.  Requires MPI-2.
752 
753    Level: developer
754 
755 .seealso: `PetscCommBuildTwoSided()`, `PetscCommBuildTwoSidedSetType()`, `PetscCommBuildTwoSidedGetType()`
756 E*/
757 typedef enum {
758   PETSC_BUILDTWOSIDED_NOTSET     = -1,
759   PETSC_BUILDTWOSIDED_ALLREDUCE  = 0,
760   PETSC_BUILDTWOSIDED_IBARRIER   = 1,
761   PETSC_BUILDTWOSIDED_REDSCATTER = 2
762   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
763 } PetscBuildTwoSidedType;
764 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
765 
766 /* NOTE: If you change this, you must also change the values in src/vec/f90-mod/petscvec.h */
767 /*E
768   InsertMode - Whether entries are inserted or added into vectors or matrices
769 
770   Level: beginner
771 
772 .seealso: `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
773           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`,
774           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`
775 E*/
776 typedef enum {
777   NOT_SET_VALUES,
778   INSERT_VALUES,
779   ADD_VALUES,
780   MAX_VALUES,
781   MIN_VALUES,
782   INSERT_ALL_VALUES,
783   ADD_ALL_VALUES,
784   INSERT_BC_VALUES,
785   ADD_BC_VALUES
786 } InsertMode;
787 
788 /*MC
789     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
790 
791     Level: beginner
792 
793 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
794           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `ADD_VALUES`,
795           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
796 
797 M*/
798 
799 /*MC
800     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
801                 value into that location
802 
803     Level: beginner
804 
805 .seealso: `InsertMode`, `VecSetValues()`, `MatSetValues()`, `VecSetValue()`, `VecSetValuesBlocked()`,
806           `VecSetValuesLocal()`, `VecSetValuesBlockedLocal()`, `MatSetValuesBlocked()`, `INSERT_VALUES`,
807           `MatSetValuesBlockedLocal()`, `MatSetValuesLocal()`, `VecScatterBegin()`, `VecScatterEnd()`, `MAX_VALUES`
808 
809 M*/
810 
811 /*MC
812     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
813 
814     Level: beginner
815 
816 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
817 
818 M*/
819 
820 /*MC
821     MIN_VALUES - Puts the minimal of the scattered/gathered value and the current value into each location
822 
823     Level: beginner
824 
825 .seealso: `InsertMode`, `VecScatterBegin()`, `VecScatterEnd()`, `ADD_VALUES`, `INSERT_VALUES`
826 
827 M*/
828 
829 /*S
830    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
831 
832    Notes:
833    After a call to `PetscSubcommSetType()`, `PetscSubcommSetTypeGeneral()`, or `PetscSubcommSetFromOptions()` one may call
834 $     `PetscSubcommChild()` returns the associated subcommunicator on this process
835 $     `PetscSubcommContiguousParent()` returns a parent communitor but with all child of the same subcommunicator having contiguous rank
836 
837    Sample Usage:
838 .vb
839        `PetscSubcommCreate()`
840        `PetscSubcommSetNumber()`
841        `PetscSubcommSetType`(`PETSC_SUBCOMM_INTERLACED`);
842        ccomm = `PetscSubcommChild()`
843        `PetscSubcommDestroy()`
844 .ve
845 
846    Level: advanced
847 
848    Notes:
849 $   `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
850 $   `PETSC_SUBCOMM_CONTIGUOUS` - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
851 $   `PETSC_SUBCOMM_INTERLACED` - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
852 
853    Example: Consider a communicator with six processes split into 3 subcommunicators.
854 $     `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
855 $     `PETSC_SUBCOMM_INTERLACED` - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
856 
857    Developer Note:
858    This is used in objects such as `PCREDUNDANT` to manage the subcommunicators on which the redundant computations
859    are performed.
860 
861 .seealso: `PetscSubcommCreate()`, `PetscSubcommSetNumber()`, `PetscSubcommSetType()`, `PetscSubcommView()`, `PetscSubcommSetFromOptions()`
862 
863 S*/
864 typedef struct _n_PetscSubcomm *PetscSubcomm;
865 typedef enum {
866   PETSC_SUBCOMM_GENERAL    = 0,
867   PETSC_SUBCOMM_CONTIGUOUS = 1,
868   PETSC_SUBCOMM_INTERLACED = 2
869 } PetscSubcommType;
870 PETSC_EXTERN const char *const PetscSubcommTypes[];
871 
872 /*S
873      PetscHeap - A simple class for managing heaps
874 
875    Level: intermediate
876 
877 .seealso: `PetscHeapCreate()`, `PetscHeapAdd()`, `PetscHeapPop()`, `PetscHeapPeek()`, `PetscHeapStash()`, `PetscHeapUnstash()`, `PetscHeapView()`, `PetscHeapDestroy()`
878 S*/
879 typedef struct _PetscHeap *PetscHeap;
880 
881 typedef struct _n_PetscShmComm *PetscShmComm;
882 typedef struct _n_PetscOmpCtrl *PetscOmpCtrl;
883 
884 /*S
885    PetscSegBuffer - a segmented extendable buffer
886 
887    Level: developer
888 
889 .seealso: `PetscSegBufferCreate()`, `PetscSegBufferGet()`, `PetscSegBufferExtract()`, `PetscSegBufferDestroy()`
890 S*/
891 typedef struct _n_PetscSegBuffer *PetscSegBuffer;
892 
893 typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
894 #endif
895