xref: /petsc/include/petscsys.h (revision feaf08ea36ffe4fb16da05e2fed575fa424e5b40)
1d382aafbSBarry Smith /*
2d382aafbSBarry Smith    This is the main PETSc include file (for C and C++).  It is included by all
3d382aafbSBarry Smith    other PETSc include files, so it almost never has to be specifically included.
447d993e7Ssuyashtn    Portions of this code are under:
547d993e7Ssuyashtn    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
6d382aafbSBarry Smith */
7a4963045SJacob Faibussowitsch #pragma once
83ca90d2dSJacob Faibussowitsch 
9d382aafbSBarry Smith /* ========================================================================== */
10d382aafbSBarry Smith /*
11d382aafbSBarry Smith    petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is
121c77a0c5SBarry Smith    found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that
131c77a0c5SBarry Smith    PETSc's makefiles add to the compiler rules.
141c77a0c5SBarry Smith    For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same
151cc8b206SBarry Smith    directory as the other PETSc include files.
16d382aafbSBarry Smith */
172c8e378dSBarry Smith #include <petscconf.h>
18100ffedbSJunchao Zhang #include <petscpkg_version.h>
191c77a0c5SBarry Smith #include <petscconf_poison.h>
202c8e378dSBarry Smith #include <petscfix.h>
21bde483f2SJacob Faibussowitsch #include <petscmacros.h>
2233bb201bSJacob Faibussowitsch 
23ac09b921SBarry Smith /* SUBMANSEC = Sys */
24ac09b921SBarry Smith 
2573fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS)
2673fca5a0SBarry Smith   /*
2773fca5a0SBarry Smith    Feature test macros must be included before headers defined by IEEE Std 1003.1-2001
2873fca5a0SBarry Smith    We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS
2973fca5a0SBarry Smith */
30216f1ae6SBarry Smith   #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE)
3173fca5a0SBarry Smith     #define _POSIX_C_SOURCE 200112L
3273fca5a0SBarry Smith   #endif
33216f1ae6SBarry Smith   #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE)
3473fca5a0SBarry Smith     #define _BSD_SOURCE
3573fca5a0SBarry Smith   #endif
3607f00807SSatish Balay   #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
3707f00807SSatish Balay     #define _DEFAULT_SOURCE
3807f00807SSatish Balay   #endif
39ea0fecefSShri Abhyankar   #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE)
40ea0fecefSShri Abhyankar     #define _GNU_SOURCE
41ea0fecefSShri Abhyankar   #endif
4273fca5a0SBarry Smith #endif
4373fca5a0SBarry Smith 
44df4397b0SStefano Zampini #include <petscsystypes.h>
45df4397b0SStefano Zampini 
46d382aafbSBarry Smith /* ========================================================================== */
47d382aafbSBarry Smith 
48d382aafbSBarry Smith /*
49d382aafbSBarry Smith     Defines the interface to MPI allowing the use of all MPI functions.
50d382aafbSBarry Smith 
51d382aafbSBarry Smith     PETSc does not use the C++ binding of MPI at ALL. The following flag
52d382aafbSBarry Smith     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
53d382aafbSBarry Smith     putting mpi.h before ANY C++ include files, we cannot control this
54d382aafbSBarry Smith     with all PETSc users. Users who want to use the MPI C++ bindings can include
55d382aafbSBarry Smith     mpicxx.h directly in their code
56d382aafbSBarry Smith */
57fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX)
58d382aafbSBarry Smith   #define MPICH_SKIP_MPICXX 1
59fa9e63e2SJed Brown #endif
60fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX)
61d382aafbSBarry Smith   #define OMPI_SKIP_MPICXX 1
62fa9e63e2SJed Brown #endif
63e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI)
64e771154cSJed Brown   #include <petsc/mpiuni/mpi.h>
65e771154cSJed Brown #else
662c8e378dSBarry Smith   #include <mpi.h>
67e771154cSJed Brown #endif
6865013866SBarry Smith 
69d382aafbSBarry Smith /*
70a7886beaSBarry Smith    Perform various sanity checks that the correct mpi.h is being included at compile time.
71a7886beaSBarry Smith    This usually happens because
72a7886beaSBarry Smith       * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or
73a7886beaSBarry Smith       * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler
74a2df2f37SMin RK    Note: with MPICH and OpenMPI, accept versions [x.y.z, x+1.0.0) as compatible
75a7886beaSBarry Smith */
76a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI)
776524c165SJacob Faibussowitsch   #ifndef MPIUNI_H
78a7886beaSBarry Smith     #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
79a7886beaSBarry Smith   #endif
800f85934cSJunchao Zhang #elif defined(PETSC_HAVE_I_MPI)
8141f4af4cSSatish Balay   #if !defined(I_MPI_NUMVERSION)
8241f4af4cSSatish Balay     #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h"
830f85934cSJunchao Zhang   #elif I_MPI_NUMVERSION != PETSC_PKG_I_MPI_NUMVERSION
8441f4af4cSSatish Balay     #error "PETSc was configured with one I_MPI mpi.h version but now appears to be compiling using a different I_MPI mpi.h version"
8541f4af4cSSatish Balay   #endif
860f85934cSJunchao Zhang #elif defined(PETSC_HAVE_MVAPICH2)
8741f4af4cSSatish Balay   #if !defined(MVAPICH2_NUMVERSION)
8841f4af4cSSatish Balay     #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h"
890f85934cSJunchao Zhang   #elif MVAPICH2_NUMVERSION != PETSC_PKG_MVAPICH2_NUMVERSION
9041f4af4cSSatish Balay     #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version"
9141f4af4cSSatish Balay   #endif
92e3c15826SJunchao Zhang #elif defined(PETSC_HAVE_MPICH)
9341f4af4cSSatish Balay   #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION)
94a7886beaSBarry Smith     #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
95a2df2f37SMin RK   #elif PETSC_PKG_MPICH_VERSION_GT(MPICH_NUMVERSION / 10000000, MPICH_NUMVERSION / 100000 % 100, MPICH_NUMVERSION / 1000 % 100)
96a2df2f37SMin RK     #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using an older MPICH mpi.h version"
97a2df2f37SMin RK   #elif PETSC_PKG_MPICH_VERSION_LT(MPICH_NUMVERSION / 10000000, 0, 0)
98a2df2f37SMin RK     #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a newer major MPICH mpi.h version"
99a7886beaSBarry Smith   #endif
100100ffedbSJunchao Zhang #elif defined(PETSC_HAVE_OPENMPI)
101a7886beaSBarry Smith   #if !defined(OMPI_MAJOR_VERSION)
102a7886beaSBarry Smith     #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h"
103a2df2f37SMin RK   #elif PETSC_PKG_OPENMPI_VERSION_GT(OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION)
104a2df2f37SMin RK     #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using an older Open MPI mpi.h version"
105a2df2f37SMin RK   #elif PETSC_PKG_OPENMPI_VERSION_LT(OMPI_MAJOR_VERSION, 0, 0)
106a2df2f37SMin RK     #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using a newer major Open MPI mpi.h version"
107a7886beaSBarry Smith   #endif
108d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION)
109d97fd468SStefano Zampini   #if !defined(MSMPI_VER)
110d97fd468SStefano Zampini     #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h"
111d97fd468SStefano Zampini   #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION)
112d97fd468SStefano Zampini     #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version"
113d97fd468SStefano Zampini   #endif
114d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER)
115d97fd468SStefano Zampini   #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of Open MPI, MS-MPI or a MPICH variant"
116a7886beaSBarry Smith #endif
117a7886beaSBarry Smith 
118a7886beaSBarry Smith /*
1192981ebdbSBarry Smith     Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
120d382aafbSBarry Smith     see the top of mpicxx.h in the MPICH2 distribution.
121d382aafbSBarry Smith */
122d382aafbSBarry Smith #include <stdio.h>
123d382aafbSBarry Smith 
1247de69702SBarry Smith /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */
125d382aafbSBarry Smith #if !defined(MPIAPI)
126d382aafbSBarry Smith   #define MPIAPI
127d382aafbSBarry Smith #endif
128d382aafbSBarry Smith 
12993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum);
13093d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool);
131e28ce29aSPatrick Sanan 
132e28ce29aSPatrick Sanan /*MC
13387497f52SBarry Smith    MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt`
134e28ce29aSPatrick Sanan 
135667f096bSBarry Smith    Level: beginner
136667f096bSBarry Smith 
13738b83642SBarry Smith    Note:
13887497f52SBarry Smith    In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.
139e28ce29aSPatrick Sanan 
14038b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
141e28ce29aSPatrick Sanan M*/
142e28ce29aSPatrick Sanan 
1437cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;
144b7b8f77aSBarry Smith 
145d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES)
146bd84f1cfSSatish Balay   #define MPIU_INT MPIU_INT64
147d382aafbSBarry Smith #else
148d382aafbSBarry Smith   #define MPIU_INT MPI_INT
149d382aafbSBarry Smith #endif
150d382aafbSBarry Smith 
15138b83642SBarry Smith /*MC
15238b83642SBarry Smith    MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount`
15338b83642SBarry Smith 
15438b83642SBarry Smith    Level: beginner
15538b83642SBarry Smith 
15638b83642SBarry Smith    Note:
15738b83642SBarry Smith    In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value.
15838b83642SBarry Smith 
15938b83642SBarry Smith   Developer Note:
16095bd0b28SBarry Smith   It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed
16138b83642SBarry Smith 
16238b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
16338b83642SBarry Smith M*/
16438b83642SBarry Smith #define MPIU_COUNT MPI_AINT
16538b83642SBarry Smith 
166503cfb0cSBarry Smith /*
167503cfb0cSBarry Smith     For the rare cases when one needs to send a size_t object with MPI
168503cfb0cSBarry Smith */
16993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t);
170d382aafbSBarry Smith 
171d382aafbSBarry Smith /*
172d382aafbSBarry Smith       You can use PETSC_STDOUT as a replacement of stdout. You can also change
173d382aafbSBarry Smith     the value of PETSC_STDOUT to redirect all standard output elsewhere
174d382aafbSBarry Smith */
175014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT;
176d382aafbSBarry Smith 
177d382aafbSBarry Smith /*
178d382aafbSBarry Smith       You can use PETSC_STDERR as a replacement of stderr. You can also change
179d382aafbSBarry Smith     the value of PETSC_STDERR to redirect all standard error elsewhere
180d382aafbSBarry Smith */
181014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR;
182d382aafbSBarry Smith 
183d382aafbSBarry Smith /*
184dc07da0dSStefano Zampini   Handle inclusion when using clang compiler with CUDA support
185dc07da0dSStefano Zampini   __float128 is not available for the device
186dc07da0dSStefano Zampini */
187731341e5SJunchao Zhang #if defined(__clang__) && (defined(__CUDA_ARCH__) || defined(__HIPCC__))
188dc07da0dSStefano Zampini   #define PETSC_SKIP_REAL___FLOAT128
189dc07da0dSStefano Zampini #endif
190dc07da0dSStefano Zampini 
191dc07da0dSStefano Zampini /*
192d382aafbSBarry Smith     Declare extern C stuff after including external header files
193d382aafbSBarry Smith */
194d382aafbSBarry Smith 
1956edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
1968b49ba18SBarry Smith /*
197390e1bf2SBarry Smith     Defines elementary mathematics functions and constants.
1988b49ba18SBarry Smith */
1998b49ba18SBarry Smith #include <petscmath.h>
2008b49ba18SBarry Smith 
201d382aafbSBarry Smith /*MC
202667f096bSBarry Smith    PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument
203d382aafbSBarry Smith 
204d382aafbSBarry Smith    Level: beginner
205d382aafbSBarry Smith 
206e28ce29aSPatrick Sanan    Note:
207667f096bSBarry Smith    Accepted by many PETSc functions to not set a parameter and instead use a default value
208d382aafbSBarry Smith 
20987497f52SBarry Smith    Fortran Note:
210*feaf08eaSBarry Smith    Use `PETSC_NULL_INTEGER`, `PETSC_NULL_SCALAR` etc
211d382aafbSBarry Smith 
212db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE`
213d382aafbSBarry Smith M*/
214f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR
215edd03b47SJacob Faibussowitsch #define PETSC_NULL   PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR
216c528d872SBarry Smith 
217d382aafbSBarry Smith /*MC
218b3480c81SBarry Smith    PETSC_UNLIMITED - standard way of passing an integer or floating point parameter to indicate PETSc there is no bound on the value allowed
219557d4da8SBarry Smith 
220557d4da8SBarry Smith    Level: beginner
221557d4da8SBarry Smith 
222b3480c81SBarry Smith    Example Usage:
223b3480c81SBarry Smith .vb
224b3480c81SBarry Smith    KSPSetTolerances(ksp, PETSC_CURRENT, PETSC_CURRENT, PETSC_UNLIMITED, PETSC_UNLIMITED);
225b3480c81SBarry Smith .ve
226b3480c81SBarry Smith   indicates that the solver is allowed to take any number of iterations and will not stop early no matter how the residual gets.
227b3480c81SBarry Smith 
228b3480c81SBarry Smith    Fortran Note:
229b3480c81SBarry Smith    Use `PETSC_UNLIMITED_INTEGER` or `PETSC_UNLIMITED_REAL`.
230b3480c81SBarry Smith 
231b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DECIDE`
232557d4da8SBarry Smith M*/
233557d4da8SBarry Smith 
234557d4da8SBarry Smith /*MC
235b3480c81SBarry Smith    PETSC_DECIDE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value
236d382aafbSBarry Smith 
237d382aafbSBarry Smith    Level: beginner
238d382aafbSBarry Smith 
239b3480c81SBarry Smith    Example Usage:
240b3480c81SBarry Smith .vb
241b3480c81SBarry Smith    VecSetSizes(ksp, PETSC_DECIDE, 10);
242b3480c81SBarry Smith .ve
243b3480c81SBarry Smith   indicates that the global size of the vector is 10 and the local size will be automatically determined so that the sum of the
244b3480c81SBarry Smith   local sizes is the global size, see `PetscSplitOwnership()`.
245b3480c81SBarry Smith 
246b3480c81SBarry Smith    Fortran Note:
247b3480c81SBarry Smith    Use `PETSC_DECIDE_INTEGER` or `PETSC_DECIDE_REAL`.
248b3480c81SBarry Smith 
249b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_UNLIMITED'
250b3480c81SBarry Smith M*/
251b3480c81SBarry Smith 
252b3480c81SBarry Smith /*MC
253b3480c81SBarry Smith    PETSC_DETERMINE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value
254b3480c81SBarry Smith 
255b3480c81SBarry Smith    Level: beginner
256b3480c81SBarry Smith 
257b3480c81SBarry Smith     Example Usage:
258b3480c81SBarry Smith .vb
259b3480c81SBarry Smith    VecSetSizes(ksp, 10, PETSC_DETERMINE);
260b3480c81SBarry Smith .ve
261b3480c81SBarry Smith   indicates that the local size of the vector is 10 and the global size will be automatically summing up all the local sizes.
262b3480c81SBarry Smith 
263b3480c81SBarry Smith    Note:
264b3480c81SBarry Smith    Same as `PETSC_DECIDE`
265b3480c81SBarry Smith 
266b3480c81SBarry Smith    Fortran Note:
267b3480c81SBarry Smith    Use `PETSC_DETERMINE_INTEGER` or `PETSC_DETERMINE_REAL`.
268b3480c81SBarry Smith 
269e28ce29aSPatrick Sanan    Developer Note:
27087497f52SBarry Smith    I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for
27187497f52SBarry Smith    some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value.
272557d4da8SBarry Smith 
273b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`, `PETSC_UNLIMITED'
274d382aafbSBarry Smith M*/
275d382aafbSBarry Smith 
276d382aafbSBarry Smith /*MC
277b3480c81SBarry Smith    PETSC_CURRENT - standard way of indicating to an object not to change the current value of the parameter in the object
278557d4da8SBarry Smith 
279557d4da8SBarry Smith    Level: beginner
280557d4da8SBarry Smith 
281b3480c81SBarry Smith    Note:
282b3480c81SBarry Smith    Use `PETSC_DECIDE` to use the value that was set by PETSc when the object's type was set
283557d4da8SBarry Smith 
284b3480c81SBarry Smith    Fortran Note:
285b3480c81SBarry Smith    Use `PETSC_CURRENT_INTEGER` or `PETSC_CURRENT_REAL`.
286b3480c81SBarry Smith 
287b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DEFAULT`, `PETSC_UNLIMITED'
288b3480c81SBarry Smith M*/
289b3480c81SBarry Smith 
290b3480c81SBarry Smith /*MC
291b3480c81SBarry Smith    PETSC_DEFAULT - deprecated, see `PETSC_CURRENT` and `PETSC_DETERMINE`
292b3480c81SBarry Smith 
293b3480c81SBarry Smith    Level: beginner
294b3480c81SBarry Smith 
295b3480c81SBarry Smith    Note:
296b3480c81SBarry Smith    The name is confusing since it tells the object to continue to use the value it is using, not the default value when the object's type was set.
297b3480c81SBarry Smith 
298b3480c81SBarry Smith    Developer Note:
299b3480c81SBarry Smith    Unfortunately this was used for two different purposes in the past, to actually trigger the use of a default value or to continue the
300b3480c81SBarry Smith    use of currently set value (in, for example, `KSPSetTolerances()`.
301b3480c81SBarry Smith 
302b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_CURRENT`, `PETSC_UNLIMITED'
303557d4da8SBarry Smith M*/
30405c2f48cSJacob Faibussowitsch 
30505c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */
30605c2f48cSJacob Faibussowitsch #define PETSC_DECIDE    (-1)
30705c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE
308b3480c81SBarry Smith #define PETSC_CURRENT   (-2)
309b3480c81SBarry Smith #define PETSC_UNLIMITED (-3)
310b3480c81SBarry Smith /*  PETSC_DEFAULT is deprecated in favor of PETSC_CURRENT for use in KSPSetTolerances() and similar functions */
311b3480c81SBarry Smith #define PETSC_DEFAULT PETSC_CURRENT
312557d4da8SBarry Smith 
313557d4da8SBarry Smith /*MC
314af27ebaaSBarry Smith    PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about.
315d382aafbSBarry Smith 
316d382aafbSBarry Smith    Level: beginner
317d382aafbSBarry Smith 
318e28ce29aSPatrick Sanan    Notes:
31987497f52SBarry Smith    By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to
32087497f52SBarry Smith    run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller)
32187497f52SBarry Smith    communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling
322af27ebaaSBarry Smith    `PetscInitialize()`, but after `MPI_Init()` has been called.
323a990b902SBarry Smith 
324af27ebaaSBarry Smith    The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()`
325a990b902SBarry Smith    is called because it may not have a valid value yet.
326d382aafbSBarry Smith 
327db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF`
328d382aafbSBarry Smith M*/
329014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
330d382aafbSBarry Smith 
331d382aafbSBarry Smith /*MC
33287497f52SBarry Smith    PETSC_COMM_SELF - This is always `MPI_COMM_SELF`
333d382aafbSBarry Smith 
334d382aafbSBarry Smith    Level: beginner
335d382aafbSBarry Smith 
33695bd0b28SBarry Smith    Note:
33716a05f60SBarry Smith    Do not USE/access or set this variable before `PetscInitialize()` has been called.
338a990b902SBarry Smith 
339db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`
340d382aafbSBarry Smith M*/
341d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF
342d382aafbSBarry Smith 
3436de5d289SStefano Zampini /*MC
344af27ebaaSBarry Smith    PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`.
3456de5d289SStefano Zampini 
346d598313aSBarry Smith    No Fortran Support
347d598313aSBarry Smith 
3486de5d289SStefano Zampini    Level: beginner
3496de5d289SStefano Zampini 
35095bd0b28SBarry Smith    Note:
351d598313aSBarry Smith    By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED` when the MPI implementation provides `MPI_Init_thread()`, otherwise it equals `MPI_THREAD_SINGLE`
3526de5d289SStefano Zampini 
353db781477SPatrick Sanan .seealso: `PetscInitialize()`
3546de5d289SStefano Zampini M*/
3556de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
3566de5d289SStefano Zampini 
357d598313aSBarry Smith /*MC
3580b4b7b1cSBarry Smith    PetscBeganMPI - indicates if PETSc initialized MPI using `MPI_Init()` during `PetscInitialize()` or if MPI was already initialized with `MPI_Init()`
359d598313aSBarry Smith 
360d598313aSBarry Smith    Synopsis:
361d598313aSBarry Smith    #include <petscsys.h>
362d598313aSBarry Smith    PetscBool PetscBeganMPI;
363d598313aSBarry Smith 
364d598313aSBarry Smith    No Fortran Support
365d598313aSBarry Smith 
366d598313aSBarry Smith    Level: developer
367d598313aSBarry Smith 
3680b4b7b1cSBarry Smith    Note:
3690b4b7b1cSBarry Smith    `MPI_Init()` can never be called after `PetscInitialize()`
3700b4b7b1cSBarry Smith 
3710241b274SPierre Jolivet .seealso: `PetscInitialize()`, `PetscInitializeCalled`
372d598313aSBarry Smith M*/
373d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI;
374d598313aSBarry Smith 
3758ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
376014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled;
377014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled;
3784cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
379d382aafbSBarry Smith 
380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
38357f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
38457f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);
385d382aafbSBarry Smith 
38659e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
38759e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
38859e55d94SJunchao Zhang #endif
38959e55d94SJunchao Zhang 
39071438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM)
39171438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscBeganNvshmem;
39271438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
39371438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
39471438e86SJunchao Zhang #endif
39571438e86SJunchao Zhang 
396540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL)
397540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
398540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
399540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
400540e20f2SPierre Jolivet #endif
401540e20f2SPierre Jolivet 
402d382aafbSBarry Smith /*MC
4030b4b7b1cSBarry Smith    PetscMalloc - Allocates memory for use with PETSc. One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of `PetscMalloc()`
404d382aafbSBarry Smith 
405eca87e8dSBarry Smith    Synopsis:
406aaa7dc30SBarry Smith     #include <petscsys.h>
407eca87e8dSBarry Smith    PetscErrorCode PetscMalloc(size_t m,void **result)
408eca87e8dSBarry Smith 
409eca87e8dSBarry Smith    Not Collective
410eca87e8dSBarry Smith 
411d382aafbSBarry Smith    Input Parameter:
412d382aafbSBarry Smith .  m - number of bytes to allocate
413d382aafbSBarry Smith 
414d382aafbSBarry Smith    Output Parameter:
415d382aafbSBarry Smith .  result - memory allocated
416d382aafbSBarry Smith 
417d382aafbSBarry Smith    Level: beginner
418d382aafbSBarry Smith 
41949d7da52SJed Brown    Notes:
42049d7da52SJed Brown    Memory is always allocated at least double aligned
421d382aafbSBarry Smith 
42276d69608SSatish Balay    It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.
4230b4b7b1cSBarry Smith    However, the pointer should never be dereferenced or the program will crash.
424d382aafbSBarry Smith 
4250b4b7b1cSBarry Smith    Developer Note:
4260b4b7b1cSBarry Smith    All the `PetscMallocN()` routines actually call `PetscMalloc()` behind the scenes.
4270b4b7b1cSBarry Smith 
4280b4b7b1cSBarry Smith    Except for data structures that store information about the PETSc options database all memory allocated by PETSc is
4290b4b7b1cSBarry Smith    obtained with `PetscMalloc()` or `PetscCalloc()`
4300b4b7b1cSBarry Smith 
4310b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscNew()`, `PetscCalloc()`
432d382aafbSBarry Smith M*/
433071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
434d382aafbSBarry Smith 
435d382aafbSBarry Smith /*MC
436d5b43468SJose E. Roman    PetscRealloc - Reallocates memory
4373221ece2SMatthew G. Knepley 
4383221ece2SMatthew G. Knepley    Synopsis:
4393221ece2SMatthew G. Knepley     #include <petscsys.h>
4403221ece2SMatthew G. Knepley    PetscErrorCode PetscRealloc(size_t m,void **result)
4413221ece2SMatthew G. Knepley 
4423221ece2SMatthew G. Knepley    Not Collective
4433221ece2SMatthew G. Knepley 
4443221ece2SMatthew G. Knepley    Input Parameters:
4453221ece2SMatthew G. Knepley +  m      - number of bytes to allocate
44692f119d6SBarry Smith -  result - previous memory
4473221ece2SMatthew G. Knepley 
4483221ece2SMatthew G. Knepley    Output Parameter:
4493221ece2SMatthew G. Knepley .  result - new memory allocated
4503221ece2SMatthew G. Knepley 
4513221ece2SMatthew G. Knepley    Level: developer
4523221ece2SMatthew G. Knepley 
4530b4b7b1cSBarry Smith    Notes:
4540b4b7b1cSBarry Smith    `results` must have already been obtained with `PetscMalloc()`
4550b4b7b1cSBarry Smith 
4563221ece2SMatthew G. Knepley    Memory is always allocated at least double aligned
4573221ece2SMatthew G. Knepley 
458db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
4593221ece2SMatthew G. Knepley M*/
4603221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
4613221ece2SMatthew G. Knepley 
4623221ece2SMatthew G. Knepley /*MC
46387497f52SBarry Smith    PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment
464d382aafbSBarry Smith 
465d382aafbSBarry Smith    Synopsis:
466aaa7dc30SBarry Smith     #include <petscsys.h>
467d382aafbSBarry Smith    void *PetscAddrAlign(void *addr)
468d382aafbSBarry Smith 
469eca87e8dSBarry Smith    Not Collective
470eca87e8dSBarry Smith 
4712fe279fdSBarry Smith    Input Parameter:
472eca87e8dSBarry Smith .  addr - address to align (any pointer type)
473eca87e8dSBarry Smith 
474d382aafbSBarry Smith    Level: developer
475d382aafbSBarry Smith 
476db781477SPatrick Sanan .seealso: `PetscMallocAlign()`
477d382aafbSBarry Smith M*/
478f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)))
479d382aafbSBarry Smith 
480d382aafbSBarry Smith /*MC
4810b4b7b1cSBarry Smith    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`, similar to `PetscMalloc()`
4828f51dc47SJunchao Zhang 
4838f51dc47SJunchao Zhang    Synopsis:
4848f51dc47SJunchao Zhang     #include <petscsys.h>
4858f51dc47SJunchao Zhang    PetscErrorCode PetscCalloc(size_t m,void **result)
4868f51dc47SJunchao Zhang 
4878f51dc47SJunchao Zhang    Not Collective
4888f51dc47SJunchao Zhang 
4898f51dc47SJunchao Zhang    Input Parameter:
4908f51dc47SJunchao Zhang .  m - number of bytes to allocate
4918f51dc47SJunchao Zhang 
4928f51dc47SJunchao Zhang    Output Parameter:
4938f51dc47SJunchao Zhang .  result - memory allocated
4948f51dc47SJunchao Zhang 
4958f51dc47SJunchao Zhang    Level: beginner
4968f51dc47SJunchao Zhang 
4978f51dc47SJunchao Zhang    Notes:
4988f51dc47SJunchao Zhang    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
4998f51dc47SJunchao Zhang 
50076d69608SSatish Balay    It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.
5018f51dc47SJunchao Zhang 
5020b4b7b1cSBarry Smith    However, the pointer should never be dereferenced or the program will crash.
5030b4b7b1cSBarry Smith 
5040b4b7b1cSBarry Smith    Developer Note:
5050b4b7b1cSBarry Smith    All `PetscCallocN()` routines call `PetscCalloc()` behind the scenes.
5060b4b7b1cSBarry Smith 
5070b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`
5088f51dc47SJunchao Zhang M*/
509b67aa78dSSatish Balay #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result))
5108f51dc47SJunchao Zhang 
5118f51dc47SJunchao Zhang /*MC
51287497f52SBarry Smith    PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`
513d382aafbSBarry Smith 
514eca87e8dSBarry Smith    Synopsis:
515aaa7dc30SBarry Smith     #include <petscsys.h>
516785e854fSJed Brown    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
517785e854fSJed Brown 
518785e854fSJed Brown    Not Collective
519785e854fSJed Brown 
520785e854fSJed Brown    Input Parameter:
521390e1bf2SBarry Smith .  m1 - number of elements to allocate  (may be zero)
522785e854fSJed Brown 
523785e854fSJed Brown    Output Parameter:
5241fe1b817SJunchao Zhang .  r1 - memory allocated
525785e854fSJed Brown 
52616a05f60SBarry Smith    Level: beginner
52716a05f60SBarry Smith 
528e28ce29aSPatrick Sanan    Note:
5294a21bc22SJames Wright    This uses `sizeof()` of the memory type requested to determine the total memory to be allocated; therefore, you should not
5304a21bc22SJames Wright    multiply the number of elements requested by the `sizeof()` the type. For example, use
53116a05f60SBarry Smith .vb
53216a05f60SBarry Smith   PetscInt *id;
53316a05f60SBarry Smith   PetscMalloc1(10,&id);
53416a05f60SBarry Smith .ve
535390e1bf2SBarry Smith        not
53616a05f60SBarry Smith .vb
53716a05f60SBarry Smith   PetscInt *id;
53816a05f60SBarry Smith   PetscMalloc1(10*sizeof(PetscInt),&id);
53916a05f60SBarry Smith .ve
540390e1bf2SBarry Smith 
54187497f52SBarry Smith   Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.
542390e1bf2SBarry Smith 
5434a21bc22SJames Wright   The `PetscMalloc[N]()` and `PetscCalloc[N]()` take an argument of type `size_t`! However, most codes use `value`, computed via `int` or `PetscInt` variables. This can overflow in
5444a21bc22SJames Wright   32bit `int` computation - while computation in 64bit `size_t` would not overflow!
5454a21bc22SJames Wright   It's best if any arithmetic that is done for size computations is done with `size_t` type - avoiding arithmetic overflow!
5464a21bc22SJames Wright 
5474a21bc22SJames Wright   `PetscMalloc[N]()` and `PetscCalloc[N]()` attempt to work-around this by casting the first variable to `size_t`.
5484a21bc22SJames Wright   This works for most expressions, but not all, such as
5494a21bc22SJames Wright .vb
5504a21bc22SJames Wright   PetscInt *id, a, b;
5514a21bc22SJames Wright   PetscMalloc1(use_a_squared ? a * a * b : a * b, &id); // use_a_squared is cast to size_t, but a and b are still PetscInt
5524a21bc22SJames Wright   PetscMalloc1(a + b * b, &id); // a is cast to size_t, but b * b is performed at PetscInt precision first due to order-of-operations
5534a21bc22SJames Wright .ve
5544a21bc22SJames Wright 
5554a21bc22SJames Wright   These expressions should either be avoided, or appropriately cast variables to `size_t`:
5564a21bc22SJames Wright .vb
5574a21bc22SJames Wright   PetscInt *id, a, b;
5584a21bc22SJames Wright   PetscMalloc1(use_a_squared ? (size_t)a * a * b : (size_t)a * b, &id); // Cast a to size_t before multiplication
5594a21bc22SJames Wright   PetscMalloc1(b * b + a, &id); // b is automatically cast to size_t and order-of-operations ensures size_t precision is maintained
5604a21bc22SJames Wright .ve
5614a21bc22SJames Wright 
562db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
563785e854fSJed Brown M*/
564b67aa78dSSatish Balay #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
565785e854fSJed Brown 
566785e854fSJed Brown /*MC
56787497f52SBarry Smith    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`
5681795a4d1SJed Brown 
5691795a4d1SJed Brown    Synopsis:
570aaa7dc30SBarry Smith     #include <petscsys.h>
5711795a4d1SJed Brown    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
5721795a4d1SJed Brown 
5731795a4d1SJed Brown    Not Collective
5741795a4d1SJed Brown 
5751795a4d1SJed Brown    Input Parameter:
5761795a4d1SJed Brown .  m1 - number of elements to allocate in 1st chunk  (may be zero)
5771795a4d1SJed Brown 
5781795a4d1SJed Brown    Output Parameter:
5791fe1b817SJunchao Zhang .  r1 - memory allocated
5801795a4d1SJed Brown 
58116a05f60SBarry Smith    Level: beginner
58216a05f60SBarry Smith 
58395bd0b28SBarry Smith    Note:
58454c05997SPierre Jolivet    See `PetscMalloc1()` for more details on usage.
585390e1bf2SBarry Smith 
586db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
5871795a4d1SJed Brown M*/
588b67aa78dSSatish Balay #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
5891795a4d1SJed Brown 
5901795a4d1SJed Brown /*MC
59187497f52SBarry Smith    PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`
592d382aafbSBarry Smith 
593eca87e8dSBarry Smith    Synopsis:
594aaa7dc30SBarry Smith     #include <petscsys.h>
595dcca6d9dSJed Brown    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
596eca87e8dSBarry Smith 
597eca87e8dSBarry Smith    Not Collective
598eca87e8dSBarry Smith 
599d8d19677SJose E. Roman    Input Parameters:
600d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
601dcca6d9dSJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
602d382aafbSBarry Smith 
603d8d19677SJose E. Roman    Output Parameters:
604d382aafbSBarry Smith +  r1 - memory allocated in first chunk
605d382aafbSBarry Smith -  r2 - memory allocated in second chunk
606d382aafbSBarry Smith 
607d382aafbSBarry Smith    Level: developer
608d382aafbSBarry Smith 
609db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
610d382aafbSBarry Smith M*/
611b67aa78dSSatish Balay #define PetscMalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2))
612d382aafbSBarry Smith 
613d382aafbSBarry Smith /*MC
61487497f52SBarry Smith    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`
615d382aafbSBarry Smith 
616eca87e8dSBarry Smith    Synopsis:
617aaa7dc30SBarry Smith     #include <petscsys.h>
6181795a4d1SJed Brown    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
619eca87e8dSBarry Smith 
620eca87e8dSBarry Smith    Not Collective
621eca87e8dSBarry Smith 
622d8d19677SJose E. Roman    Input Parameters:
623d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
6241795a4d1SJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
6251795a4d1SJed Brown 
626d8d19677SJose E. Roman    Output Parameters:
6271795a4d1SJed Brown +  r1 - memory allocated in first chunk
6281795a4d1SJed Brown -  r2 - memory allocated in second chunk
6291795a4d1SJed Brown 
6301795a4d1SJed Brown    Level: developer
6311795a4d1SJed Brown 
632db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
6331795a4d1SJed Brown M*/
634b67aa78dSSatish Balay #define PetscCalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2))
6351795a4d1SJed Brown 
6361795a4d1SJed Brown /*MC
63787497f52SBarry Smith    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`
638d382aafbSBarry Smith 
639d382aafbSBarry Smith    Synopsis:
640aaa7dc30SBarry Smith     #include <petscsys.h>
641dcca6d9dSJed Brown    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
642d382aafbSBarry Smith 
643d382aafbSBarry Smith    Not Collective
644d382aafbSBarry Smith 
645d8d19677SJose E. Roman    Input Parameters:
646d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
647d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
648dcca6d9dSJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
649d382aafbSBarry Smith 
650d8d19677SJose E. Roman    Output Parameters:
651d382aafbSBarry Smith +  r1 - memory allocated in first chunk
652d382aafbSBarry Smith .  r2 - memory allocated in second chunk
653d382aafbSBarry Smith -  r3 - memory allocated in third chunk
654d382aafbSBarry Smith 
655d382aafbSBarry Smith    Level: developer
656d382aafbSBarry Smith 
657db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
658d382aafbSBarry Smith M*/
659f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \
660b67aa78dSSatish Balay   PetscMallocA(3, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3))
661d382aafbSBarry Smith 
662d382aafbSBarry Smith /*MC
66387497f52SBarry Smith    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
664d382aafbSBarry Smith 
665eca87e8dSBarry Smith    Synopsis:
666aaa7dc30SBarry Smith     #include <petscsys.h>
6671795a4d1SJed Brown    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
668eca87e8dSBarry Smith 
669eca87e8dSBarry Smith    Not Collective
670eca87e8dSBarry Smith 
671d8d19677SJose E. Roman    Input Parameters:
672d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
673d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
6741795a4d1SJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
6751795a4d1SJed Brown 
676d8d19677SJose E. Roman    Output Parameters:
6771795a4d1SJed Brown +  r1 - memory allocated in first chunk
6781795a4d1SJed Brown .  r2 - memory allocated in second chunk
6791795a4d1SJed Brown -  r3 - memory allocated in third chunk
6801795a4d1SJed Brown 
6811795a4d1SJed Brown    Level: developer
6821795a4d1SJed Brown 
683db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
6841795a4d1SJed Brown M*/
685f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \
686b67aa78dSSatish Balay   PetscMallocA(3, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3))
6871795a4d1SJed Brown 
6881795a4d1SJed Brown /*MC
68987497f52SBarry Smith    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`
690d382aafbSBarry Smith 
691d382aafbSBarry Smith    Synopsis:
692aaa7dc30SBarry Smith     #include <petscsys.h>
693dcca6d9dSJed Brown    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
694d382aafbSBarry Smith 
695d382aafbSBarry Smith    Not Collective
696d382aafbSBarry Smith 
697d8d19677SJose E. Roman    Input Parameters:
698d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
699d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
700d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
701dcca6d9dSJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
702d382aafbSBarry Smith 
703d8d19677SJose E. Roman    Output Parameters:
704d382aafbSBarry Smith +  r1 - memory allocated in first chunk
705d382aafbSBarry Smith .  r2 - memory allocated in second chunk
706d382aafbSBarry Smith .  r3 - memory allocated in third chunk
707d382aafbSBarry Smith -  r4 - memory allocated in fourth chunk
708d382aafbSBarry Smith 
709d382aafbSBarry Smith    Level: developer
710d382aafbSBarry Smith 
711db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
712d382aafbSBarry Smith M*/
7139371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
714b67aa78dSSatish Balay   PetscMallocA(4, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4))
715d382aafbSBarry Smith 
716d382aafbSBarry Smith /*MC
71787497f52SBarry Smith    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
718d382aafbSBarry Smith 
719eca87e8dSBarry Smith    Synopsis:
720aaa7dc30SBarry Smith     #include <petscsys.h>
7211795a4d1SJed Brown    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
722eca87e8dSBarry Smith 
723eca87e8dSBarry Smith    Not Collective
724eca87e8dSBarry Smith 
725e28ce29aSPatrick Sanan    Input Parameters:
726d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
727d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
728d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
7291795a4d1SJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
7301795a4d1SJed Brown 
731e28ce29aSPatrick Sanan    Output Parameters:
7321795a4d1SJed Brown +  r1 - memory allocated in first chunk
7331795a4d1SJed Brown .  r2 - memory allocated in second chunk
7341795a4d1SJed Brown .  r3 - memory allocated in third chunk
7351795a4d1SJed Brown -  r4 - memory allocated in fourth chunk
7361795a4d1SJed Brown 
7371795a4d1SJed Brown    Level: developer
7381795a4d1SJed Brown 
739db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
7401795a4d1SJed Brown M*/
7419371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
742b67aa78dSSatish Balay   PetscMallocA(4, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4))
7431795a4d1SJed Brown 
7441795a4d1SJed Brown /*MC
74587497f52SBarry Smith    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`
746d382aafbSBarry Smith 
747d382aafbSBarry Smith    Synopsis:
748aaa7dc30SBarry Smith     #include <petscsys.h>
749dcca6d9dSJed Brown    PetscErrorCode PetscMalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5)
750d382aafbSBarry Smith 
751d382aafbSBarry Smith    Not Collective
752d382aafbSBarry Smith 
753e28ce29aSPatrick Sanan    Input Parameters:
754d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
755d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
756d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
757d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
758dcca6d9dSJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
759d382aafbSBarry Smith 
760e28ce29aSPatrick Sanan    Output Parameters:
761d382aafbSBarry Smith +  r1 - memory allocated in first chunk
762d382aafbSBarry Smith .  r2 - memory allocated in second chunk
763d382aafbSBarry Smith .  r3 - memory allocated in third chunk
764d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
765d382aafbSBarry Smith -  r5 - memory allocated in fifth chunk
766d382aafbSBarry Smith 
767d382aafbSBarry Smith    Level: developer
768d382aafbSBarry Smith 
769db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
770d382aafbSBarry Smith M*/
7719371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
772b67aa78dSSatish Balay   PetscMallocA(5, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5))
773d382aafbSBarry Smith 
774d382aafbSBarry Smith /*MC
77587497f52SBarry Smith    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
776d382aafbSBarry Smith 
777eca87e8dSBarry Smith    Synopsis:
778aaa7dc30SBarry Smith     #include <petscsys.h>
7791795a4d1SJed Brown    PetscErrorCode PetscCalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5)
780eca87e8dSBarry Smith 
781eca87e8dSBarry Smith    Not Collective
782eca87e8dSBarry Smith 
783e28ce29aSPatrick Sanan    Input Parameters:
784d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
785d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
786d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
787d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
7881795a4d1SJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
7891795a4d1SJed Brown 
790e28ce29aSPatrick Sanan    Output Parameters:
7911795a4d1SJed Brown +  r1 - memory allocated in first chunk
7921795a4d1SJed Brown .  r2 - memory allocated in second chunk
7931795a4d1SJed Brown .  r3 - memory allocated in third chunk
7941795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7951795a4d1SJed Brown -  r5 - memory allocated in fifth chunk
7961795a4d1SJed Brown 
7971795a4d1SJed Brown    Level: developer
7981795a4d1SJed Brown 
799db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
8001795a4d1SJed Brown M*/
8019371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
802b67aa78dSSatish Balay   PetscMallocA(5, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5))
803d382aafbSBarry Smith 
804d382aafbSBarry Smith /*MC
80587497f52SBarry Smith    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`
806d382aafbSBarry Smith 
807d382aafbSBarry Smith    Synopsis:
808aaa7dc30SBarry Smith     #include <petscsys.h>
809dcca6d9dSJed Brown    PetscErrorCode PetscMalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6)
810d382aafbSBarry Smith 
811d382aafbSBarry Smith    Not Collective
812d382aafbSBarry Smith 
813e28ce29aSPatrick Sanan    Input Parameters:
814d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
815d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
816d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
817d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
818d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
819dcca6d9dSJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
820d382aafbSBarry Smith 
821e28ce29aSPatrick Sanan    Output Parameteasr:
822d382aafbSBarry Smith +  r1 - memory allocated in first chunk
823d382aafbSBarry Smith .  r2 - memory allocated in second chunk
824d382aafbSBarry Smith .  r3 - memory allocated in third chunk
825d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
826d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
827d382aafbSBarry Smith -  r6 - memory allocated in sixth chunk
828d382aafbSBarry Smith 
829d382aafbSBarry Smith    Level: developer
830d382aafbSBarry Smith 
831db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
832d382aafbSBarry Smith M*/
8339371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
834b67aa78dSSatish Balay   PetscMallocA(6, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6))
835d382aafbSBarry Smith 
836d382aafbSBarry Smith /*MC
83787497f52SBarry Smith    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
838d382aafbSBarry Smith 
839eca87e8dSBarry Smith    Synopsis:
840aaa7dc30SBarry Smith     #include <petscsys.h>
8411795a4d1SJed Brown    PetscErrorCode PetscCalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6)
842eca87e8dSBarry Smith 
843eca87e8dSBarry Smith    Not Collective
844eca87e8dSBarry Smith 
845e28ce29aSPatrick Sanan    Input Parameters:
846d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
847d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
848d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
849d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
850d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
8511795a4d1SJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
8521795a4d1SJed Brown 
853e28ce29aSPatrick Sanan    Output Parameters:
8541795a4d1SJed Brown +  r1 - memory allocated in first chunk
8551795a4d1SJed Brown .  r2 - memory allocated in second chunk
8561795a4d1SJed Brown .  r3 - memory allocated in third chunk
8571795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
8581795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
8591795a4d1SJed Brown -  r6 - memory allocated in sixth chunk
8601795a4d1SJed Brown 
8611795a4d1SJed Brown    Level: developer
8621795a4d1SJed Brown 
863db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
8641795a4d1SJed Brown M*/
8659371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
866b67aa78dSSatish Balay   PetscMallocA(6, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6))
8671795a4d1SJed Brown 
8681795a4d1SJed Brown /*MC
86987497f52SBarry Smith    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`
870d382aafbSBarry Smith 
871d382aafbSBarry Smith    Synopsis:
872aaa7dc30SBarry Smith     #include <petscsys.h>
873dcca6d9dSJed Brown    PetscErrorCode PetscMalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7)
874d382aafbSBarry Smith 
875d382aafbSBarry Smith    Not Collective
876d382aafbSBarry Smith 
877e28ce29aSPatrick Sanan    Input Parameters:
878d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
879d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
880d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
881d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
882d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
883d382aafbSBarry Smith .  m6 - number of elements to allocate in 6th chunk  (may be zero)
884dcca6d9dSJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
885d382aafbSBarry Smith 
886e28ce29aSPatrick Sanan    Output Parameters:
887d382aafbSBarry Smith +  r1 - memory allocated in first chunk
888d382aafbSBarry Smith .  r2 - memory allocated in second chunk
889d382aafbSBarry Smith .  r3 - memory allocated in third chunk
890d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
891d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
892d382aafbSBarry Smith .  r6 - memory allocated in sixth chunk
893eca87e8dSBarry Smith -  r7 - memory allocated in seventh chunk
894d382aafbSBarry Smith 
895d382aafbSBarry Smith    Level: developer
896d382aafbSBarry Smith 
897db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
898d382aafbSBarry Smith M*/
8999371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
900b67aa78dSSatish Balay   PetscMallocA(7, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7))
901d382aafbSBarry Smith 
902d382aafbSBarry Smith /*MC
90387497f52SBarry Smith    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
9041795a4d1SJed Brown 
9051795a4d1SJed Brown    Synopsis:
906aaa7dc30SBarry Smith     #include <petscsys.h>
9071795a4d1SJed Brown    PetscErrorCode PetscCalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7)
9081795a4d1SJed Brown 
9091795a4d1SJed Brown    Not Collective
9101795a4d1SJed Brown 
911e28ce29aSPatrick Sanan    Input Parameters:
9121795a4d1SJed Brown +  m1 - number of elements to allocate in 1st chunk  (may be zero)
9131795a4d1SJed Brown .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
9141795a4d1SJed Brown .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
9151795a4d1SJed Brown .  m4 - number of elements to allocate in 4th chunk  (may be zero)
9161795a4d1SJed Brown .  m5 - number of elements to allocate in 5th chunk  (may be zero)
9171795a4d1SJed Brown .  m6 - number of elements to allocate in 6th chunk  (may be zero)
9181795a4d1SJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
9191795a4d1SJed Brown 
920e28ce29aSPatrick Sanan    Output Parameters:
9211795a4d1SJed Brown +  r1 - memory allocated in first chunk
9221795a4d1SJed Brown .  r2 - memory allocated in second chunk
9231795a4d1SJed Brown .  r3 - memory allocated in third chunk
9241795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
9251795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
9261795a4d1SJed Brown .  r6 - memory allocated in sixth chunk
9271795a4d1SJed Brown -  r7 - memory allocated in seventh chunk
9281795a4d1SJed Brown 
9291795a4d1SJed Brown    Level: developer
9301795a4d1SJed Brown 
931db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
9321795a4d1SJed Brown M*/
9339371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
934b67aa78dSSatish Balay   PetscMallocA(7, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7))
9351795a4d1SJed Brown 
9361795a4d1SJed Brown /*MC
93787497f52SBarry Smith    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`
938d382aafbSBarry Smith 
939eca87e8dSBarry Smith    Synopsis:
940aaa7dc30SBarry Smith     #include <petscsys.h>
941b00a9115SJed Brown    PetscErrorCode PetscNew(type **result)
942eca87e8dSBarry Smith 
943eca87e8dSBarry Smith    Not Collective
944eca87e8dSBarry Smith 
945d382aafbSBarry Smith    Output Parameter:
9460b4b7b1cSBarry Smith .  result - memory allocated, sized to match pointer `type`
947d382aafbSBarry Smith 
948d382aafbSBarry Smith    Level: beginner
949d382aafbSBarry Smith 
9500b4b7b1cSBarry Smith    Developer Note:
9510b4b7b1cSBarry Smith    Calls `PetscCalloc()` with the appropriate memory size obtained from `type`
9520b4b7b1cSBarry Smith 
9530b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCall()`, `PetscCalloc1()`, `PetscMalloc1()`
954d382aafbSBarry Smith M*/
955b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b))
956ad0619ddSBarry Smith 
957f4f49eeaSPierre Jolivet #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b)
958d382aafbSBarry Smith 
959d382aafbSBarry Smith /*MC
960d382aafbSBarry Smith    PetscFree - Frees memory
961d382aafbSBarry Smith 
962eca87e8dSBarry Smith    Synopsis:
963aaa7dc30SBarry Smith     #include <petscsys.h>
964eca87e8dSBarry Smith    PetscErrorCode PetscFree(void *memory)
965eca87e8dSBarry Smith 
966eca87e8dSBarry Smith    Not Collective
967eca87e8dSBarry Smith 
968d382aafbSBarry Smith    Input Parameter:
96916a05f60SBarry Smith .   memory - memory to free (the pointer is ALWAYS set to `NULL` upon success)
970d382aafbSBarry Smith 
971d382aafbSBarry Smith    Level: beginner
972d382aafbSBarry Smith 
97395bd0b28SBarry Smith    Notes:
97487497f52SBarry Smith    Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.
975390e1bf2SBarry Smith 
97616a05f60SBarry Smith    It is safe to call `PetscFree()` on a `NULL` pointer.
977d382aafbSBarry Smith 
978fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
979d382aafbSBarry Smith M*/
9803ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS)))
981d382aafbSBarry Smith 
982d382aafbSBarry Smith /*MC
98387497f52SBarry Smith    PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`
984d382aafbSBarry Smith 
985eca87e8dSBarry Smith    Synopsis:
986aaa7dc30SBarry Smith     #include <petscsys.h>
987eca87e8dSBarry Smith    PetscErrorCode PetscFree2(void *memory1,void *memory2)
988eca87e8dSBarry Smith 
989eca87e8dSBarry Smith    Not Collective
990eca87e8dSBarry Smith 
991e28ce29aSPatrick Sanan    Input Parameters:
992d382aafbSBarry Smith +   memory1 - memory to free
993d382aafbSBarry Smith -   memory2 - 2nd memory to free
994d382aafbSBarry Smith 
995d382aafbSBarry Smith    Level: developer
996d382aafbSBarry Smith 
9977e17494fSJames Wright    Notes:
99887497f52SBarry Smith     Memory must have been obtained with `PetscMalloc2()`
999d382aafbSBarry Smith 
10007e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc2()`
10017e17494fSJames Wright 
1002db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
1003d382aafbSBarry Smith M*/
1004ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))
1005d382aafbSBarry Smith 
1006d382aafbSBarry Smith /*MC
100787497f52SBarry Smith    PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`
1008d382aafbSBarry Smith 
1009eca87e8dSBarry Smith    Synopsis:
1010aaa7dc30SBarry Smith     #include <petscsys.h>
1011eca87e8dSBarry Smith    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
1012eca87e8dSBarry Smith 
1013eca87e8dSBarry Smith    Not Collective
1014eca87e8dSBarry Smith 
1015e28ce29aSPatrick Sanan    Input Parameters:
1016d382aafbSBarry Smith +   memory1 - memory to free
1017d382aafbSBarry Smith .   memory2 - 2nd memory to free
1018d382aafbSBarry Smith -   memory3 - 3rd memory to free
1019d382aafbSBarry Smith 
1020d382aafbSBarry Smith    Level: developer
1021d382aafbSBarry Smith 
10227e17494fSJames Wright    Notes:
102387497f52SBarry Smith     Memory must have been obtained with `PetscMalloc3()`
1024d382aafbSBarry Smith 
10257e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc3()`
10267e17494fSJames Wright 
1027db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
1028d382aafbSBarry Smith M*/
1029ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))
1030d382aafbSBarry Smith 
1031d382aafbSBarry Smith /*MC
103287497f52SBarry Smith    PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`
1033d382aafbSBarry Smith 
1034eca87e8dSBarry Smith    Synopsis:
1035aaa7dc30SBarry Smith     #include <petscsys.h>
1036eca87e8dSBarry Smith    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
1037eca87e8dSBarry Smith 
1038eca87e8dSBarry Smith    Not Collective
1039eca87e8dSBarry Smith 
1040e28ce29aSPatrick Sanan    Input Parameters:
1041d382aafbSBarry Smith +   m1 - memory to free
1042d382aafbSBarry Smith .   m2 - 2nd memory to free
1043d382aafbSBarry Smith .   m3 - 3rd memory to free
1044d382aafbSBarry Smith -   m4 - 4th memory to free
1045d382aafbSBarry Smith 
1046d382aafbSBarry Smith    Level: developer
1047d382aafbSBarry Smith 
10487e17494fSJames Wright    Notes:
104987497f52SBarry Smith     Memory must have been obtained with `PetscMalloc4()`
1050d382aafbSBarry Smith 
10517e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc4()`
10527e17494fSJames Wright 
1053db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
1054d382aafbSBarry Smith M*/
1055ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))
1056d382aafbSBarry Smith 
1057d382aafbSBarry Smith /*MC
105887497f52SBarry Smith    PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`
1059d382aafbSBarry Smith 
1060eca87e8dSBarry Smith    Synopsis:
1061aaa7dc30SBarry Smith     #include <petscsys.h>
1062eca87e8dSBarry Smith    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
1063eca87e8dSBarry Smith 
1064eca87e8dSBarry Smith    Not Collective
1065eca87e8dSBarry Smith 
1066e28ce29aSPatrick Sanan    Input Parameters:
1067d382aafbSBarry Smith +   m1 - memory to free
1068d382aafbSBarry Smith .   m2 - 2nd memory to free
1069d382aafbSBarry Smith .   m3 - 3rd memory to free
1070d382aafbSBarry Smith .   m4 - 4th memory to free
1071d382aafbSBarry Smith -   m5 - 5th memory to free
1072d382aafbSBarry Smith 
1073d382aafbSBarry Smith    Level: developer
1074d382aafbSBarry Smith 
10757e17494fSJames Wright    Notes:
107687497f52SBarry Smith     Memory must have been obtained with `PetscMalloc5()`
1077d382aafbSBarry Smith 
10787e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc5()`
10797e17494fSJames Wright 
1080db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
1081d382aafbSBarry Smith M*/
1082ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))
1083d382aafbSBarry Smith 
1084d382aafbSBarry Smith /*MC
108587497f52SBarry Smith    PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`
1086d382aafbSBarry Smith 
1087eca87e8dSBarry Smith    Synopsis:
1088aaa7dc30SBarry Smith     #include <petscsys.h>
1089eca87e8dSBarry Smith    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1090eca87e8dSBarry Smith 
1091eca87e8dSBarry Smith    Not Collective
1092eca87e8dSBarry Smith 
1093e28ce29aSPatrick Sanan    Input Parameters:
1094d382aafbSBarry Smith +   m1 - memory to free
1095d382aafbSBarry Smith .   m2 - 2nd memory to free
1096d382aafbSBarry Smith .   m3 - 3rd memory to free
1097d382aafbSBarry Smith .   m4 - 4th memory to free
1098d382aafbSBarry Smith .   m5 - 5th memory to free
1099d382aafbSBarry Smith -   m6 - 6th memory to free
1100d382aafbSBarry Smith 
1101d382aafbSBarry Smith    Level: developer
1102d382aafbSBarry Smith 
11037e17494fSJames Wright    Notes:
110487497f52SBarry Smith     Memory must have been obtained with `PetscMalloc6()`
1105d382aafbSBarry Smith 
11067e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc6()`
11077e17494fSJames Wright 
1108db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
1109d382aafbSBarry Smith M*/
1110ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))
1111d382aafbSBarry Smith 
1112d382aafbSBarry Smith /*MC
111387497f52SBarry Smith    PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`
1114d382aafbSBarry Smith 
1115eca87e8dSBarry Smith    Synopsis:
1116aaa7dc30SBarry Smith     #include <petscsys.h>
1117eca87e8dSBarry Smith    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1118eca87e8dSBarry Smith 
1119eca87e8dSBarry Smith    Not Collective
1120eca87e8dSBarry Smith 
1121e28ce29aSPatrick Sanan    Input Parameters:
1122d382aafbSBarry Smith +   m1 - memory to free
1123d382aafbSBarry Smith .   m2 - 2nd memory to free
1124d382aafbSBarry Smith .   m3 - 3rd memory to free
1125d382aafbSBarry Smith .   m4 - 4th memory to free
1126d382aafbSBarry Smith .   m5 - 5th memory to free
1127d382aafbSBarry Smith .   m6 - 6th memory to free
1128d382aafbSBarry Smith -   m7 - 7th memory to free
1129d382aafbSBarry Smith 
1130d382aafbSBarry Smith    Level: developer
1131d382aafbSBarry Smith 
11327e17494fSJames Wright    Notes:
113387497f52SBarry Smith     Memory must have been obtained with `PetscMalloc7()`
1134d382aafbSBarry Smith 
11357e17494fSJames Wright     The arguments need to be in the same order as they were in the call to `PetscMalloc7()`
11367e17494fSJames Wright 
1137db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
1138db781477SPatrick Sanan           `PetscMalloc7()`
1139d382aafbSBarry Smith M*/
1140ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))
1141d382aafbSBarry Smith 
1142ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
1143ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
1144071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
1145efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
11463221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
1147ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
114892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSet(PetscErrorCode (*)(size_t, PetscBool, int, const char[], const char[], void **), PetscErrorCode (*)(void *, int, const char[], const char[]), PetscErrorCode (*)(size_t, int, const char[], const char[], void **));
1149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1150d382aafbSBarry Smith 
1151d382aafbSBarry Smith /*
1152c1706be6SHong Zhang   Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair.
1153c1706be6SHong Zhang */
1154c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1155c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
115631f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA)
115731f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
115831f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
115931f06eaaSHong Zhang #endif
116059af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
116159af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
116259af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
116359af0bd3SScott Kruger #endif
116459af0bd3SScott Kruger 
1165a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
116636763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1167a5057860SBarry Smith 
1168a5057860SBarry Smith /*
116966d669d6SBarry Smith    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1170d382aafbSBarry Smith */
1171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
117292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1173014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1174014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1175e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1176e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
117792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
117892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
1179efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
118092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
118192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
1182608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1183608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);
1184d382aafbSBarry Smith 
1185014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
1186014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
1187014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *);
11888e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);
1189d382aafbSBarry Smith 
1190d382aafbSBarry Smith /*
1191d382aafbSBarry Smith    These are MPI operations for MPI_Allreduce() etc
1192d382aafbSBarry Smith */
1193367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1194570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1195de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM;
1196014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX;
1197014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN;
1198d9822059SBarry Smith #else
1199de272c7aSSatish Balay   #define MPIU_SUM MPI_SUM
1200d9822059SBarry Smith   #define MPIU_MAX MPI_MAX
1201d9822059SBarry Smith   #define MPIU_MIN MPI_MIN
1202d9822059SBarry Smith #endif
120362e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op         Petsc_Garbage_SetIntersectOp;
120462e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
120562e5d2d2SJDBetteridge 
1206a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16))
1207613bf2b2SPierre Jolivet /*MC
120816a05f60SBarry Smith    MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with
120916a05f60SBarry Smith    custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.
1210613bf2b2SPierre Jolivet 
1211613bf2b2SPierre Jolivet    Level: advanced
1212613bf2b2SPierre Jolivet 
1213613bf2b2SPierre Jolivet    Developer Note:
1214613bf2b2SPierre Jolivet    This should be unified with `MPIU_SUM`
1215613bf2b2SPierre Jolivet 
1216613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
1217613bf2b2SPierre Jolivet M*/
12189e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
1219613bf2b2SPierre Jolivet #endif
1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
1221d382aafbSBarry Smith 
122293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
122393d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
1224eb3f98d2SBarry Smith 
1225639ff905SBarry Smith /*
122649abdd8aSBarry Smith      These are so that in extern C code we can cast function pointers to non-extern C
122749abdd8aSBarry Smith    function pointers. Since the regular C++ code expects its function pointers to be C++
122849abdd8aSBarry Smith */
122949abdd8aSBarry Smith 
123049abdd8aSBarry Smith /*S
123149abdd8aSBarry Smith   PetscVoidFn - A prototype of a void (fn)(void) function
123249abdd8aSBarry Smith 
123349abdd8aSBarry Smith   Level: developer
123449abdd8aSBarry Smith 
123549abdd8aSBarry Smith   Notes:
123649abdd8aSBarry Smith   The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *.
123749abdd8aSBarry Smith 
123849abdd8aSBarry Smith   The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **.
123949abdd8aSBarry Smith 
124049abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()`
124149abdd8aSBarry Smith S*/
124249abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void);
124349abdd8aSBarry Smith 
124449abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn  *PetscVoidFunction;
124549abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction;
124649abdd8aSBarry Smith 
124749abdd8aSBarry Smith /*S
124849abdd8aSBarry Smith   PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function
124949abdd8aSBarry Smith 
125049abdd8aSBarry Smith   Level: developer
125149abdd8aSBarry Smith 
125249abdd8aSBarry Smith   Notes:
125349abdd8aSBarry Smith   The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *.
125449abdd8aSBarry Smith 
125549abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()`
125649abdd8aSBarry Smith S*/
125749abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void);
125849abdd8aSBarry Smith 
125949abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction;
126049abdd8aSBarry Smith 
126149abdd8aSBarry Smith /*S
126249abdd8aSBarry Smith   PetscCtxDestroyFn - A prototype of a `PetscErrorCode (*)(void *)` function that is used to free user contexts
126349abdd8aSBarry Smith 
126449abdd8aSBarry Smith   Level: intermediate
126549abdd8aSBarry Smith 
126649abdd8aSBarry Smith   Note:
126749abdd8aSBarry Smith   Used in the prototype of functions such as `DMSetApplicationContextDestroy()`
126849abdd8aSBarry Smith 
126949abdd8aSBarry Smith .seealso: `PetscObject`, `PetscCtxDestroyDefault()`, `PetscObjectDestroy()`, `DMSetApplicationContextDestroy()`
127049abdd8aSBarry Smith S*/
127149abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscCtxDestroyFn)(void **);
127249abdd8aSBarry Smith 
127349abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PetscCtxDestroyDefault;
127449abdd8aSBarry Smith 
127549abdd8aSBarry Smith /*
1276639ff905SBarry Smith     Defines PETSc error handling.
1277639ff905SBarry Smith */
1278639ff905SBarry Smith #include <petscerror.h>
1279d382aafbSBarry Smith 
1280660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabled;                    /* code is running in the PETSc test harness CI */
1281660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
1282660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *);
1283660278c0SBarry Smith PETSC_EXTERN int         PetscCILinenumber(int);
1284660278c0SBarry Smith 
1285835f2295SStefano Zampini #define PETSC_SMALLEST_CLASSID 1211211
1286014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_LARGEST_CLASSID;
1287014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_OBJECT_CLASSID;
1288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
128981256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
129081256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);
129181256985SMatthew G. Knepley 
1292d382aafbSBarry Smith /*
1293d382aafbSBarry Smith    Routines that get memory usage information from the OS
1294d382aafbSBarry Smith */
1295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1298b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1299d382aafbSBarry Smith 
1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1301d382aafbSBarry Smith 
1302d382aafbSBarry Smith /*
1303d382aafbSBarry Smith    Initialization of PETSc
1304d382aafbSBarry Smith */
1305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
1306ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char *[], const char[], const char[]);
1307014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1308014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1310014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1312014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
1313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1315d382aafbSBarry Smith 
1316014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void);
1317607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
13184bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void);
1319d382aafbSBarry Smith 
1320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
1321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1323014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);
1324d382aafbSBarry Smith 
132549abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscBool *);
1326d382aafbSBarry Smith 
1327d382aafbSBarry Smith /*
1328d382aafbSBarry Smith     Functions that can act on any PETSc object.
1329d382aafbSBarry Smith */
1330014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
1331014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
1332014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
1333014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
1334014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
1335014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
1336014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
1337014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
1338014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
1339014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
1340014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
1342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1343014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
1344014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
1345014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
1346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
1347bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void));
13488434afd1SBarry Smith #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__))
1349014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1350014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
13510eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
13520eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
1353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);
1354d382aafbSBarry Smith 
1355b3480c81SBarry Smith /*MC
1356b3480c81SBarry Smith    PetscObjectParameterSetDefault - sets a parameter default value in a `PetscObject` to a new default value.
1357b3480c81SBarry Smith    If the current value matches the old default value, then the current value is also set to the new value.
1358b3480c81SBarry Smith 
1359b3480c81SBarry Smith    No Fortran Support
1360b3480c81SBarry Smith 
1361b3480c81SBarry Smith    Synopsis:
1362b3480c81SBarry Smith    #include <petscsys.h>
1363b3480c81SBarry Smith    PetscBool PetscObjectParameterSetDefault(PetscObject obj, char* NAME, PetscReal value);
1364b3480c81SBarry Smith 
1365b3480c81SBarry Smith    Input Parameters:
1366b3480c81SBarry Smith +  obj - the `PetscObject`
1367b3480c81SBarry Smith .  NAME - the name of the parameter, unquoted
1368b3480c81SBarry Smith -  value - the new value
1369b3480c81SBarry Smith 
1370b3480c81SBarry Smith    Level: developer
1371b3480c81SBarry Smith 
1372b3480c81SBarry Smith    Notes:
1373b3480c81SBarry Smith    The defaults for an object are the values set when the object's type is set.
1374b3480c81SBarry Smith 
1375b3480c81SBarry Smith    This should only be used in object constructors, such as, `SNESCreate_NGS()`.
1376b3480c81SBarry Smith 
1377b3480c81SBarry Smith    This only works for parameters that are declared in the struct with `PetscObjectParameterDeclare()`
1378b3480c81SBarry Smith 
1379b3480c81SBarry Smith .seealso: `PetscObjectParameterDeclare()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
1380b3480c81SBarry Smith M*/
1381b3480c81SBarry Smith #define PetscObjectParameterSetDefault(obj, NAME, value) \
1382b3480c81SBarry Smith   do { \
1383b3480c81SBarry Smith     if (obj->NAME == obj->default_##NAME) obj->NAME = value; \
1384b3480c81SBarry Smith     obj->default_##NAME = value; \
1385b3480c81SBarry Smith   } while (0)
1386b3480c81SBarry Smith 
1387b3480c81SBarry Smith /*MC
1388b3480c81SBarry Smith    PetscObjectParameterDeclare - declares a parameter in a `PetscObject` and a location to store its default
1389b3480c81SBarry Smith 
1390b3480c81SBarry Smith    No Fortran Support
1391b3480c81SBarry Smith 
1392b3480c81SBarry Smith    Synopsis:
1393b3480c81SBarry Smith    #include <petscsys.h>
1394b3480c81SBarry Smith    PetscBool PetscObjectParameterDeclare(type, char* NAME)
1395b3480c81SBarry Smith 
1396b3480c81SBarry Smith    Input Parameters:
1397b3480c81SBarry Smith +  type - the type of the parameter, for example `PetscInt`
1398b3480c81SBarry Smith -  NAME - the name of the parameter, unquoted
1399b3480c81SBarry Smith 
1400b3480c81SBarry Smith    Level: developer.
1401b3480c81SBarry Smith 
1402b3480c81SBarry Smith .seealso: `PetscObjectParameterSetDefault()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
1403b3480c81SBarry Smith M*/
1404b3480c81SBarry Smith #define PetscObjectParameterDeclare(type, NAME) type NAME, default_##NAME
1405b3480c81SBarry Smith 
1406665c2dedSJed Brown #include <petscviewertypes.h>
1407639ff905SBarry Smith #include <petscoptions.h>
1408639ff905SBarry Smith 
1409608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
1410608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);
1411608c71bfSMatthew G. Knepley 
1412ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject[], PetscInt *, PetscInt *);
14130633abcbSJed Brown 
1414c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
1415dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
1416639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
14178434afd1SBarry Smith #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr))
14180cd8b6e2SStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectHasFunction(PetscObject, const char[], PetscBool *);
14190005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void));
1420014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
1421014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
1422014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
1423014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
1424014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
1425014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1426014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1427685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
1428014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1429014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
1430013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
14314099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
1432014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1433b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1435014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1436d382aafbSBarry Smith 
1437e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
14387aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1439e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1440e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
1441e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1442e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1443e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1444e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1445e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1446e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1447e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
144815681b3cSBarry Smith 
1449ec7429eaSBarry Smith #else
14503ba16761SJacob Faibussowitsch   #define PetscSAWsBlock()                  PETSC_SUCCESS
14513ba16761SJacob Faibussowitsch   #define PetscObjectSAWsViewOff(obj)       PETSC_SUCCESS
14523ba16761SJacob Faibussowitsch   #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS
14533ba16761SJacob Faibussowitsch   #define PetscObjectSAWsBlock(obj)         PETSC_SUCCESS
14543ba16761SJacob Faibussowitsch   #define PetscObjectSAWsGrantAccess(obj)   PETSC_SUCCESS
14553ba16761SJacob Faibussowitsch   #define PetscObjectSAWsTakeAccess(obj)    PETSC_SUCCESS
14563ba16761SJacob Faibussowitsch   #define PetscStackViewSAWs()              PETSC_SUCCESS
14573ba16761SJacob Faibussowitsch   #define PetscStackSAWsViewOff()           PETSC_SUCCESS
1458e04113cfSBarry Smith   #define PetscStackSAWsTakeAccess()
1459e04113cfSBarry Smith   #define PetscStackSAWsGrantAccess()
146015681b3cSBarry Smith 
1461ec7429eaSBarry Smith #endif
1462b90c6cbeSBarry Smith 
146382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
146482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
146582b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
1466ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char *[]);
1467258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX
1468ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char *[]);
1469258ec3d2SMatthew G. Knepley #endif
14707d5d4d99SBarry Smith 
1471a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);
1472a64a8e02SBarry Smith 
1473dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
14744bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer);
1475ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, const char *[]);
1476140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
1477140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
1478ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, const char *[], PetscBool *);
1479140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
1480140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
1481140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);
1482d382aafbSBarry Smith 
1483d382aafbSBarry Smith /*
1484503cfb0cSBarry Smith     Dynamic library lists. Lists of names of routines in objects or in dynamic
1485d382aafbSBarry Smith   link libraries that will be loaded as needed.
1486d382aafbSBarry Smith */
1487a240a19fSJed Brown 
14888434afd1SBarry Smith #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr))
14898434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *);
1490140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
14910e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
14928434afd1SBarry Smith #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr))
14938434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **);
149444ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
1495140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
1496140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
1497140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
14982e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
14992e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);
1500d382aafbSBarry Smith 
1501014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
1502014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
1503014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
1504014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
1505014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1506014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
1507014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
1508014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1509d382aafbSBarry Smith 
1510d382aafbSBarry Smith /*
1511d382aafbSBarry Smith      Useful utility routines
1512d382aafbSBarry Smith */
1513014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
1514014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
1515d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
1516014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
1517014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
1518014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1519014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
152058b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
152158b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);
1522d382aafbSBarry Smith 
152364ac3b0dSPatrick Sanan /*MC
152487497f52SBarry Smith     PetscNot - negates a logical type value and returns result as a `PetscBool`
1525503cfb0cSBarry Smith 
152664ac3b0dSPatrick Sanan     Level: beginner
152764ac3b0dSPatrick Sanan 
1528a1cb98faSBarry Smith     Note:
1529a1cb98faSBarry Smith     This is useful in cases like
1530a1cb98faSBarry Smith .vb
1531a1cb98faSBarry Smith      int        *a;
1532a1cb98faSBarry Smith      PetscBool  flag = PetscNot(a)
1533a1cb98faSBarry Smith .ve
1534a1cb98faSBarry Smith      where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.
1535a1cb98faSBarry Smith 
1536a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
153764ac3b0dSPatrick Sanan M*/
1538d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1539503cfb0cSBarry Smith 
1540d382aafbSBarry Smith /*MC
1541d382aafbSBarry Smith    PetscHelpPrintf - Prints help messages.
1542d382aafbSBarry Smith 
1543d382aafbSBarry Smith    Synopsis:
1544aaa7dc30SBarry Smith     #include <petscsys.h>
1545659f7ba0SBarry Smith      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1546d382aafbSBarry Smith 
15477cdbe19fSJose E. Roman    Not Collective, only applies on MPI rank 0; No Fortran Support
15487cdbe19fSJose E. Roman 
1549d382aafbSBarry Smith    Input Parameters:
1550659f7ba0SBarry Smith +  comm - the MPI communicator over which the help message is printed
1551d382aafbSBarry Smith .  format - the usual printf() format string
1552659f7ba0SBarry Smith -  args - arguments to be printed
1553d382aafbSBarry Smith 
1554d382aafbSBarry Smith    Level: developer
1555d382aafbSBarry Smith 
155695bd0b28SBarry Smith    Notes:
1557659f7ba0SBarry Smith    You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1558659f7ba0SBarry Smith 
1559659f7ba0SBarry Smith    To use, write your own function, for example,
156016a05f60SBarry Smith .vb
156116a05f60SBarry Smith    PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
156216a05f60SBarry Smith    {
156316a05f60SBarry Smith      PetscFunctionReturn(PETSC_SUCCESS);
156416a05f60SBarry Smith    }
156516a05f60SBarry Smith .ve
1566d5b43468SJose E. Roman then do the assignment
1567af27ebaaSBarry Smith .vb
1568af27ebaaSBarry Smith   PetscHelpPrintf = mypetschelpprintf;
1569af27ebaaSBarry Smith .ve
1570af27ebaaSBarry Smith 
157187497f52SBarry Smith   You can do the assignment before `PetscInitialize()`.
1572659f7ba0SBarry Smith 
157387497f52SBarry Smith   The default routine used is called `PetscHelpPrintfDefault()`.
1574d382aafbSBarry Smith 
157516a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()`
1576d382aafbSBarry Smith M*/
15773ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1578d382aafbSBarry Smith 
1579fcfd50ebSBarry Smith /*
1580fcfd50ebSBarry Smith      Defines PETSc profiling.
1581fcfd50ebSBarry Smith */
15822c8e378dSBarry Smith #include <petsclog.h>
1583fcfd50ebSBarry Smith 
1584fcfd50ebSBarry Smith /*
1585fcfd50ebSBarry Smith       Simple PETSc parallel IO for ASCII printing
1586fcfd50ebSBarry Smith */
1587014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
1588014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
1589014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
15903ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1591c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *);
15923ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
15933ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
15943ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
15951b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);
1596fcfd50ebSBarry Smith 
15973ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
15983ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
15993ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1600d382aafbSBarry Smith 
1601d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
1602d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);
1603d781fa04SBarry Smith 
1604014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
1605016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
160674ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1607d382aafbSBarry Smith 
16083ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
16093ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
16100ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
1611014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
1612014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
1613014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);
1614d382aafbSBarry Smith 
1615ce78bad3SBarry Smith /*MC
1616ce78bad3SBarry Smith    PeCtx - indicates an argument that returns a pointer to a user defined C struct (or Fortran derived type)
1617ce78bad3SBarry Smith 
1618ce78bad3SBarry Smith    Level: developer
1619ce78bad3SBarry Smith 
1620ce78bad3SBarry Smith    Notes:
1621ce78bad3SBarry Smith    This is not part of the PETSc public API and should only be used in PETSc source code.
1622ce78bad3SBarry Smith 
1623ce78bad3SBarry Smith    This should not be used for functions that return PETSc objects, or pointers to arrays of unknown type. Thus it is used for, for example,
1624ce78bad3SBarry Smith    `KSPGetApplicationContext()` but not used for `DMNetworkGetComponent()`
1625ce78bad3SBarry Smith 
1626ce78bad3SBarry Smith    For pointers to arrays of unknown type and for functions that return PETSc internal objects that are opaque to users, such
1627ce78bad3SBarry Smith    as `KSPMonitorDynamicToleranceCreate()` a `void **` should be used.
1628ce78bad3SBarry Smith 
1629ce78bad3SBarry Smith    Fortran Note:
1630ce78bad3SBarry Smith    Should only be used with user defined Fortran datatypes
1631ce78bad3SBarry Smith .vb
1632ce78bad3SBarry Smith    type(tUserType), pointer :: ctx
1633ce78bad3SBarry Smith .ve
1634ce78bad3SBarry Smith 
1635ce78bad3SBarry Smith    Developer Note:
1636ce78bad3SBarry Smith    Put this in function declaration for the argument type instead of `void *`, or `void **`.
1637ce78bad3SBarry Smith 
1638ce78bad3SBarry Smith    C compilers generate a warning or error if one passes a pointer to a pointer to a specific type (instead of `void`), for example,
1639ce78bad3SBarry Smith .vb
1640ce78bad3SBarry Smith    extern calledfunction(void **);
1641ce78bad3SBarry Smith    SomeCtx *ctx;
1642ce78bad3SBarry Smith    calledfunction(&ctx);   << warning that it is passing a pointer to a pointer to a SomeCtx instead of a void **
1643ce78bad3SBarry Smith .ve
1644ce78bad3SBarry Smith    By using the common practice of prototyping the function as
1645ce78bad3SBarry Smith .vb
1646ce78bad3SBarry Smith    extern calledfunction(void *);
1647ce78bad3SBarry Smith .ve
1648ce78bad3SBarry Smith    the warning message is averted. `PeCtx` is used in PETSc source code so that the getAPI() code processor knows the argument is
1649ce78bad3SBarry Smith    actually handled internally as `void **` so it can generate correct bindings for other languages.
1650ce78bad3SBarry Smith 
1651ce78bad3SBarry Smith .seealso: `PeOp`, `PeNS`, `PetscInitialize()`
1652ce78bad3SBarry Smith M*/
1653ce78bad3SBarry Smith typedef void *PeCtx;
1654ce78bad3SBarry Smith 
1655014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_CONTAINER_CLASSID;
1656ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void *);
1657014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
1658014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
1659014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
166049abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerSetCtxDestroy(PetscContainer, PetscCtxDestroyFn *);
166149abdd8aSBarry Smith PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscContainerSetCtxDestroy()", ) PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
166249abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerCompose(PetscObject, const char *name, void *, PetscCtxDestroyFn *);
1663ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerQuery(PetscObject, const char *, PeCtx);
1664d382aafbSBarry Smith 
166549abdd8aSBarry Smith PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscCtxDestroyDefault()", ) static inline PetscErrorCode PetscContainerCtxDestroyDefault(void **a)
166649abdd8aSBarry Smith {
166749abdd8aSBarry Smith   return PetscCtxDestroyDefault(a);
166849abdd8aSBarry Smith }
166949abdd8aSBarry Smith 
1670d382aafbSBarry Smith /*
1671d382aafbSBarry Smith    For use in debuggers
1672d382aafbSBarry Smith */
1673014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalRank;
1674014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalSize;
167557b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscIntViewNumColumns(PetscInt, PetscInt, const PetscInt[], PetscViewer);
167657b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscRealViewNumColumns(PetscInt, PetscInt, const PetscReal[], PetscViewer);
167757b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscScalarViewNumColumns(PetscInt, PetscInt, const PetscScalar[], PetscViewer);
1678014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
1679014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
1680014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);
1681d382aafbSBarry Smith 
1682bbcf679cSJacob Faibussowitsch /*
1683bbcf679cSJacob Faibussowitsch     Basic memory and string operations. These are usually simple wrappers
1684bbcf679cSJacob Faibussowitsch    around the basic Unix system calls, but a few of them have additional
1685bbcf679cSJacob Faibussowitsch    functionality and/or error checking.
1686bbcf679cSJacob Faibussowitsch */
1687bbcf679cSJacob Faibussowitsch #include <petscstring.h>
1688bbcf679cSJacob Faibussowitsch 
1689a663daf8SBarry Smith #include <stddef.h>
1690d382aafbSBarry Smith #include <stdlib.h>
16916c7e564aSBarry Smith 
1692447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
1693447bcd8fSJacob Faibussowitsch   #define PetscPrefetchBlock(a, b, c, d)
1694447bcd8fSJacob Faibussowitsch #else
1695d382aafbSBarry Smith   /*MC
1696d382aafbSBarry Smith    PetscPrefetchBlock - Prefetches a block of memory
1697d382aafbSBarry Smith 
1698eca87e8dSBarry Smith    Synopsis:
1699aaa7dc30SBarry Smith     #include <petscsys.h>
1700eca87e8dSBarry Smith     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1701eca87e8dSBarry Smith 
1702d382aafbSBarry Smith    Not Collective
1703d382aafbSBarry Smith 
1704d382aafbSBarry Smith    Input Parameters:
170516a05f60SBarry Smith +  a  - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`)
1706d382aafbSBarry Smith .  n  - number of elements to fetch
1707d382aafbSBarry Smith .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
170850d8bf02SJed Brown -  t  - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1709d382aafbSBarry Smith 
1710d382aafbSBarry Smith    Level: developer
1711d382aafbSBarry Smith 
1712d382aafbSBarry Smith    Notes:
171316a05f60SBarry Smith    The last two arguments (`rw` and `t`) must be compile-time constants.
1714d382aafbSBarry Smith 
171550d8bf02SJed Brown    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
171650d8bf02SJed Brown    equivalent locality hints, but the following macros are always defined to their closest analogue.
171787497f52SBarry Smith +  `PETSC_PREFETCH_HINT_NTA` - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
171887497f52SBarry Smith .  `PETSC_PREFETCH_HINT_T0`  - Fetch to all levels of cache and evict to the closest level.  Use this when the memory will be reused regularly despite necessary eviction from L1.
171987497f52SBarry Smith .  `PETSC_PREFETCH_HINT_T1`  - Fetch to level 2 and higher (not L1).
172087497f52SBarry Smith -  `PETSC_PREFETCH_HINT_T2`  - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
1721d382aafbSBarry Smith 
1722d382aafbSBarry Smith    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1723d382aafbSBarry Smith    address).
1724d382aafbSBarry Smith 
1725d382aafbSBarry Smith M*/
17269371c9d4SSatish Balay   #define PetscPrefetchBlock(a, n, rw, t) \
17279371c9d4SSatish Balay     do { \
1728d382aafbSBarry Smith       const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
1729d382aafbSBarry Smith       for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
1730d382aafbSBarry Smith     } while (0)
1731447bcd8fSJacob Faibussowitsch #endif
1732d382aafbSBarry Smith /*
1733d382aafbSBarry Smith       Determine if some of the kernel computation routines use
1734d382aafbSBarry Smith    Fortran (rather than C) for the numerical calculations. On some machines
1735d382aafbSBarry Smith    and compilers (like complex numbers) the Fortran version of the routines
1736d382aafbSBarry Smith    is faster than the C/C++ versions. The flag --with-fortran-kernels
1737e2e64c6bSBarry Smith    should be used with ./configure to turn these on.
1738d382aafbSBarry Smith */
1739d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS)
1740d382aafbSBarry Smith 
1741d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1742d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1743d382aafbSBarry Smith   #endif
1744d382aafbSBarry Smith 
1745d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1746d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1747d382aafbSBarry Smith   #endif
1748d382aafbSBarry Smith 
1749d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1750d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1751d382aafbSBarry Smith   #endif
1752d382aafbSBarry Smith 
1753d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1754d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1755d382aafbSBarry Smith   #endif
1756d382aafbSBarry Smith 
1757d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1758d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1759d382aafbSBarry Smith   #endif
1760d382aafbSBarry Smith 
1761d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1762d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1763d382aafbSBarry Smith   #endif
1764d382aafbSBarry Smith 
1765d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1766d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1767d382aafbSBarry Smith   #endif
1768d382aafbSBarry Smith 
1769d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1770d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MDOT
1771d382aafbSBarry Smith   #endif
1772d382aafbSBarry Smith 
1773d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1774d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1775d382aafbSBarry Smith   #endif
1776d382aafbSBarry Smith 
1777d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1778d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_AYPX
1779d382aafbSBarry Smith   #endif
1780d382aafbSBarry Smith 
1781d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1782d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1783d382aafbSBarry Smith   #endif
1784d382aafbSBarry Smith 
1785d382aafbSBarry Smith #endif
1786d382aafbSBarry Smith 
1787d382aafbSBarry Smith /*
1788d382aafbSBarry Smith     Macros for indicating code that should be compiled with a C interface,
1789d382aafbSBarry Smith    rather than a C++ interface. Any routines that are dynamically loaded
1790d382aafbSBarry Smith    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1791d382aafbSBarry Smith    mangler does not change the functions symbol name. This just hides the
1792d382aafbSBarry Smith    ugly extern "C" {} wrappers.
1793d382aafbSBarry Smith */
1794d382aafbSBarry Smith #if defined(__cplusplus)
1795d382aafbSBarry Smith   #define EXTERN_C_BEGIN extern "C" {
1796d382aafbSBarry Smith   #define EXTERN_C_END   }
1797d382aafbSBarry Smith #else
1798d382aafbSBarry Smith   #define EXTERN_C_BEGIN
1799d382aafbSBarry Smith   #define EXTERN_C_END
1800d382aafbSBarry Smith #endif
1801d382aafbSBarry Smith 
1802d382aafbSBarry Smith /*MC
1803d382aafbSBarry Smith    MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1804d382aafbSBarry Smith    communication
1805d382aafbSBarry Smith 
1806d382aafbSBarry Smith    Level: beginner
1807d382aafbSBarry Smith 
180816a05f60SBarry Smith    Note:
180916a05f60SBarry Smith    This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm`
1810d382aafbSBarry Smith 
1811db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
1812d382aafbSBarry Smith M*/
1813d382aafbSBarry Smith 
1814d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO)
181593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
181693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
181793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5);
181893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5);
181993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5);
182093d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5);
1821d382aafbSBarry Smith #endif
1822d382aafbSBarry Smith 
1823462c564dSBarry Smith #if defined(PETSC_HAVE_MPI_COUNT)
1824462c564dSBarry Smith typedef MPI_Count MPIU_Count;
1825462c564dSBarry Smith #else
1826462c564dSBarry Smith typedef PetscInt64 MPIU_Count;
1827462c564dSBarry Smith #endif
1828462c564dSBarry Smith 
182961b0d812SBarry Smith /*@C
1830462c564dSBarry Smith    PetscIntCast - casts a `MPI_Count`, `PetscInt64`, `PetscCount`, or `size_t` to a `PetscInt` (which may be 32-bits in size), generates an
183187497f52SBarry Smith    error if the `PetscInt` is not large enough to hold the number.
1832c73702f5SBarry Smith 
183320f4b53cSBarry Smith    Not Collective; No Fortran Support
1834c73702f5SBarry Smith 
1835c73702f5SBarry Smith    Input Parameter:
183687497f52SBarry Smith .  a - the `PetscInt64` value
1837c73702f5SBarry Smith 
1838c73702f5SBarry Smith    Output Parameter:
18396497c311SBarry Smith .  b - the resulting `PetscInt` value, or `NULL` if the result is not needed
1840c73702f5SBarry Smith 
1841c73702f5SBarry Smith    Level: advanced
1842c73702f5SBarry Smith 
184395bd0b28SBarry Smith    Note:
18447de69702SBarry Smith    If integers needed for the applications are too large to fit in 32-bit ints you can ./configure using `--with-64-bit-indices` to make `PetscInt` use 64-bit integers
1845c73702f5SBarry Smith 
1846784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscCIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
1847c73702f5SBarry Smith @*/
1848462c564dSBarry Smith static inline PetscErrorCode PetscIntCast(MPIU_Count a, PetscInt *b)
1849d71ae5a4SJacob Faibussowitsch {
1850c73702f5SBarry Smith   PetscFunctionBegin;
18516497c311SBarry Smith   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1852462c564dSBarry Smith   PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscInt) || (a <= (MPIU_Count)PETSC_INT_MAX && a >= (MPIU_Count)PETSC_INT_MIN), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", (PetscInt64)a);
1853377f809aSBarry Smith   if (b) *b = (PetscInt)a;
18543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1855c73702f5SBarry Smith }
1856c73702f5SBarry Smith 
1857c73702f5SBarry Smith /*@C
1858462c564dSBarry Smith    PetscBLASIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount` or `PetscInt64` to a `PetscBLASInt` (which may be 32-bits in size), generates an
185987497f52SBarry Smith    error if the `PetscBLASInt` is not large enough to hold the number.
186061b0d812SBarry Smith 
1861667f096bSBarry Smith    Not Collective; No Fortran Support
186261b0d812SBarry Smith 
186361b0d812SBarry Smith    Input Parameter:
186487497f52SBarry Smith .  a - the `PetscInt` value
186561b0d812SBarry Smith 
186661b0d812SBarry Smith    Output Parameter:
18676497c311SBarry Smith .  b - the resulting `PetscBLASInt` value, or `NULL` if the result is not needed
186861b0d812SBarry Smith 
186961b0d812SBarry Smith    Level: advanced
187061b0d812SBarry Smith 
1871667f096bSBarry Smith    Note:
1872f0b7f91aSBarry Smith    Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
18731fd49c25SBarry Smith 
1874784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
187561b0d812SBarry Smith @*/
1876462c564dSBarry Smith static inline PetscErrorCode PetscBLASIntCast(MPIU_Count a, PetscBLASInt *b)
1877d71ae5a4SJacob Faibussowitsch {
1878c5df96a5SBarry Smith   PetscFunctionBegin;
18796497c311SBarry Smith   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1880462c564dSBarry Smith   PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscBLASInt) || a <= (MPIU_Count)PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for BLAS/LAPACK, which is restricted to 32-bit integers. Either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-blas-indices for the case you are running", (PetscInt64)a);
188154c59aa7SJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
18826497c311SBarry Smith   if (b) *b = (PetscBLASInt)a;
18833ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1884c5df96a5SBarry Smith }
1885c5df96a5SBarry Smith 
188661b0d812SBarry Smith /*@C
188787497f52SBarry Smith    PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.
1888eee0c0a6SToby Isaac 
1889667f096bSBarry Smith    Not Collective; No Fortran Support
1890eee0c0a6SToby Isaac 
1891eee0c0a6SToby Isaac    Input Parameter:
189287497f52SBarry Smith .  a - the `PetscInt` value
1893eee0c0a6SToby Isaac 
1894eee0c0a6SToby Isaac    Output Parameter:
18956497c311SBarry Smith .  b - the resulting `PetscCuBLASInt` value, or `NULL` if the result is not needed
1896eee0c0a6SToby Isaac 
1897eee0c0a6SToby Isaac    Level: advanced
1898eee0c0a6SToby Isaac 
1899667f096bSBarry Smith    Note:
1900eee0c0a6SToby Isaac    Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
1901eee0c0a6SToby Isaac 
1902784a7648SPierre Jolivet .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
1903eee0c0a6SToby Isaac @*/
1904462c564dSBarry Smith static inline PetscErrorCode PetscCuBLASIntCast(MPIU_Count a, PetscCuBLASInt *b)
1905d71ae5a4SJacob Faibussowitsch {
1906eee0c0a6SToby Isaac   PetscFunctionBegin;
19076497c311SBarry Smith   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1908462c564dSBarry Smith   PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscCuBLASInt) || a <= (MPIU_Count)PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for cuBLAS, which is restricted to 32-bit integers.", (PetscInt64)a);
1909462c564dSBarry Smith   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to cuBLAS routine", (PetscInt64)a);
19106497c311SBarry Smith   if (b) *b = (PetscCuBLASInt)a;
19113ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1912eee0c0a6SToby Isaac }
1913eee0c0a6SToby Isaac 
1914eee0c0a6SToby Isaac /*@C
191547d993e7Ssuyashtn    PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.
191647d993e7Ssuyashtn 
1917667f096bSBarry Smith    Not Collective; No Fortran Support
191847d993e7Ssuyashtn 
191947d993e7Ssuyashtn    Input Parameter:
192047d993e7Ssuyashtn .  a - the `PetscInt` value
192147d993e7Ssuyashtn 
192247d993e7Ssuyashtn    Output Parameter:
19236497c311SBarry Smith .  b - the resulting `PetscHipBLASInt` value, or `NULL` if the result is not needed
192447d993e7Ssuyashtn 
192547d993e7Ssuyashtn    Level: advanced
192647d993e7Ssuyashtn 
1927667f096bSBarry Smith    Note:
192847d993e7Ssuyashtn    Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs
192947d993e7Ssuyashtn 
1930784a7648SPierre Jolivet .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
193147d993e7Ssuyashtn @*/
1932462c564dSBarry Smith static inline PetscErrorCode PetscHipBLASIntCast(MPIU_Count a, PetscHipBLASInt *b)
193347d993e7Ssuyashtn {
193447d993e7Ssuyashtn   PetscFunctionBegin;
19356497c311SBarry Smith   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1936462c564dSBarry Smith   PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscHipBLASInt) || a <= (MPIU_Count)PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for hipBLAS, which is restricted to 32-bit integers.", (PetscInt64)a);
1937462c564dSBarry Smith   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to hipBLAS routine", (PetscInt64)a);
19386497c311SBarry Smith   if (b) *b = (PetscHipBLASInt)a;
19393ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
194047d993e7Ssuyashtn }
194147d993e7Ssuyashtn 
194247d993e7Ssuyashtn /*@C
1943462c564dSBarry Smith    PetscMPIIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `PetscMPIInt` (which is always 32-bits in size), generates an
1944667f096bSBarry Smith    error if the `PetscMPIInt` is not large enough to hold the number.
194561b0d812SBarry Smith 
1946667f096bSBarry Smith    Not Collective; No Fortran Support
194761b0d812SBarry Smith 
194861b0d812SBarry Smith    Input Parameter:
194987497f52SBarry Smith .  a - the `PetscInt` value
195061b0d812SBarry Smith 
195161b0d812SBarry Smith    Output Parameter:
19526497c311SBarry Smith .  b - the resulting `PetscMPIInt` value, or `NULL` if the result is not needed
195361b0d812SBarry Smith 
195461b0d812SBarry Smith    Level: advanced
195561b0d812SBarry Smith 
19566a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
195761b0d812SBarry Smith @*/
1958462c564dSBarry Smith static inline PetscErrorCode PetscMPIIntCast(MPIU_Count a, PetscMPIInt *b)
1959d71ae5a4SJacob Faibussowitsch {
19604dc2109aSBarry Smith   PetscFunctionBegin;
19616497c311SBarry Smith   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1962462c564dSBarry Smith   PetscCheck(a <= (MPIU_Count)PETSC_MPI_INT_MAX && a >= (MPIU_Count)PETSC_MPI_INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for MPI buffer length. Maximum supported value is %d", (PetscInt64)a, PETSC_MPI_INT_MAX);
19636497c311SBarry Smith   if (b) *b = (PetscMPIInt)a;
19643ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
19654dc2109aSBarry Smith }
19664dc2109aSBarry Smith 
1967784a7648SPierre Jolivet /*@C
1968784a7648SPierre Jolivet    PetscCIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `int`, generates an error if the `int` is not large enough to hold the number.
1969784a7648SPierre Jolivet 
1970784a7648SPierre Jolivet    Not Collective; No Fortran Support
1971784a7648SPierre Jolivet 
1972784a7648SPierre Jolivet    Input Parameter:
1973784a7648SPierre Jolivet .  a - the `PetscInt` value
1974784a7648SPierre Jolivet 
1975784a7648SPierre Jolivet    Output Parameter:
1976784a7648SPierre Jolivet .  b - the resulting `int` value, or `NULL` if the result is not needed
1977784a7648SPierre Jolivet 
1978784a7648SPierre Jolivet    Level: advanced
1979784a7648SPierre Jolivet 
1980784a7648SPierre Jolivet .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntCast()`
1981784a7648SPierre Jolivet @*/
1982784a7648SPierre Jolivet static inline PetscErrorCode PetscCIntCast(MPIU_Count a, int *b)
1983784a7648SPierre Jolivet {
1984784a7648SPierre Jolivet   PetscFunctionBegin;
1985784a7648SPierre Jolivet   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1986784a7648SPierre Jolivet   PetscCheck(a <= INT_MAX && a >= INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big to be casted to an int. Maximum supported value is %d", (PetscInt64)a, INT_MAX);
1987784a7648SPierre Jolivet   if (b) *b = (int)a;
1988784a7648SPierre Jolivet   PetscFunctionReturn(PETSC_SUCCESS);
1989784a7648SPierre Jolivet }
1990784a7648SPierre Jolivet 
1991917c3dccSPierre Jolivet /*MC
1992917c3dccSPierre Jolivet    PetscInt64Mult - Computes the product of two variables after casting them to `PetscInt64`.
1993917c3dccSPierre Jolivet 
1994917c3dccSPierre Jolivet    Not Collective; No Fortran Support
1995917c3dccSPierre Jolivet 
1996917c3dccSPierre Jolivet    Input Parameters:
1997917c3dccSPierre Jolivet +  a - the first variable
1998917c3dccSPierre Jolivet -  b - the second variable
1999917c3dccSPierre Jolivet 
2000917c3dccSPierre Jolivet    Level: advanced
2001917c3dccSPierre Jolivet 
2002917c3dccSPierre Jolivet .seealso: [](stylePetscCount), `PetscIntMultError()`, `PetscIntMultTruncate()`
2003917c3dccSPierre Jolivet M*/
2004835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2005835f2295SStefano Zampini   #define PetscInt64Mult(a, b) ((a) * (b))
2006835f2295SStefano Zampini #else
2007f3fa974cSJacob Faibussowitsch   #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b)))
2008835f2295SStefano Zampini #endif
20092f18eb33SBarry Smith 
20102f18eb33SBarry Smith /*@C
2011f3fa974cSJacob Faibussowitsch   PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive
2012f3fa974cSJacob Faibussowitsch   `PetscInt` and truncates the value to slightly less than the maximal possible value.
20132f18eb33SBarry Smith 
201420f4b53cSBarry Smith   Not Collective; No Fortran Support
20152f18eb33SBarry Smith 
2016d8d19677SJose E. Roman   Input Parameters:
2017f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value
2018f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value
20192f18eb33SBarry Smith 
2020667f096bSBarry Smith   Level: advanced
2021667f096bSBarry Smith 
2022f3fa974cSJacob Faibussowitsch   Notes:
2023f3fa974cSJacob Faibussowitsch   Returns the result as a `PetscInt` value.
20242f18eb33SBarry Smith 
2025f3fa974cSJacob Faibussowitsch   Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`.
2026667f096bSBarry Smith 
2027f3fa974cSJacob Faibussowitsch   Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate
2028f3fa974cSJacob Faibussowitsch   to fit a `PetscInt`.
2029667f096bSBarry Smith 
2030f3fa974cSJacob Faibussowitsch   Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an
2031f3fa974cSJacob Faibussowitsch   error if the result will not fit in a `PetscInt`.
20322f18eb33SBarry Smith 
2033b5e6e808SPierre Jolivet   Developer Notes:
2034f3fa974cSJacob Faibussowitsch   We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but
2035f3fa974cSJacob Faibussowitsch   requires many more checks.
20362f18eb33SBarry Smith 
2037f3fa974cSJacob Faibussowitsch   This is used where we compute approximate sizes for workspace and need to insure the
2038f3fa974cSJacob Faibussowitsch   workspace is index-able.
20391fd49c25SBarry Smith 
2040f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
20412f18eb33SBarry Smith @*/
2042d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
2043d71ae5a4SJacob Faibussowitsch {
20445f80ce2aSJacob Faibussowitsch   PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
20451690c2aeSBarry Smith   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2046835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2047835f2295SStefano Zampini   return r;
2048835f2295SStefano Zampini #else
20492f18eb33SBarry Smith   return (PetscInt)r;
2050835f2295SStefano Zampini #endif
20512f18eb33SBarry Smith }
20522f18eb33SBarry Smith 
20532f18eb33SBarry Smith /*@C
205487497f52SBarry Smith    PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
20552f18eb33SBarry Smith 
2056667f096bSBarry Smith    Not Collective; No Fortran Support
20572f18eb33SBarry Smith 
2058d8d19677SJose E. Roman    Input Parameters:
2059af27ebaaSBarry Smith +  a - the `PetscInt` value
20602f18eb33SBarry Smith -  b - the second value
20612f18eb33SBarry Smith 
2062390e1bf2SBarry Smith    Returns:
2063af27ebaaSBarry Smith    The result as a `PetscInt` value
20642f18eb33SBarry Smith 
2065667f096bSBarry Smith    Level: advanced
2066667f096bSBarry Smith 
2067667f096bSBarry Smith    Notes:
206887497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2069667f096bSBarry Smith 
207087497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2071667f096bSBarry Smith 
207287497f52SBarry Smith    Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an error if the result will not fit in a `PetscInt`
20732f18eb33SBarry Smith 
2074b5e6e808SPierre Jolivet    Developer Notes:
207587497f52SBarry Smith    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
20762f18eb33SBarry Smith 
20772f18eb33SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
20782f18eb33SBarry Smith 
2079667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`,
2080667f096bSBarry Smith           `PetscIntSumTruncate()`
20812f18eb33SBarry Smith @*/
2082d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
2083d71ae5a4SJacob Faibussowitsch {
20845f80ce2aSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
20851690c2aeSBarry Smith   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2086835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2087835f2295SStefano Zampini   return r;
2088835f2295SStefano Zampini #else
20892f18eb33SBarry Smith   return (PetscInt)r;
2090835f2295SStefano Zampini #endif
20912f18eb33SBarry Smith }
20922f18eb33SBarry Smith 
2093f91af8c7SBarry Smith /*@C
209487497f52SBarry Smith    PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
2095f91af8c7SBarry Smith 
2096667f096bSBarry Smith    Not Collective; No Fortran Support
2097f91af8c7SBarry Smith 
2098d8d19677SJose E. Roman    Input Parameters:
209987497f52SBarry Smith +  a - the `PetscInt` value
2100f91af8c7SBarry Smith -  b - the second value
2101f91af8c7SBarry Smith 
2102390e1bf2SBarry Smith    Returns:
2103af27ebaaSBarry Smith    The result as a `PetscInt` value
2104f91af8c7SBarry Smith 
2105667f096bSBarry Smith    Level: advanced
2106667f096bSBarry Smith 
2107667f096bSBarry Smith    Notes:
210887497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2109667f096bSBarry Smith 
211087497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2111667f096bSBarry Smith 
211287497f52SBarry Smith    Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an error if the result will not fit in a `PetscInt`
2113f91af8c7SBarry Smith 
2114b5e6e808SPierre Jolivet    Developer Note:
2115f91af8c7SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2116f91af8c7SBarry Smith 
2117db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2118f91af8c7SBarry Smith @*/
2119d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
2120d71ae5a4SJacob Faibussowitsch {
2121835f2295SStefano Zampini   PetscInt64 r = a;
2122835f2295SStefano Zampini 
2123835f2295SStefano Zampini   r += b;
21241690c2aeSBarry Smith   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2125835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2126835f2295SStefano Zampini   return r;
2127835f2295SStefano Zampini #else
2128f91af8c7SBarry Smith   return (PetscInt)r;
2129835f2295SStefano Zampini #endif
2130f91af8c7SBarry Smith }
2131f91af8c7SBarry Smith 
21322f18eb33SBarry Smith /*@C
213387497f52SBarry Smith    PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.
21342f18eb33SBarry Smith 
2135667f096bSBarry Smith    Not Collective; No Fortran Support
21362f18eb33SBarry Smith 
2137d8d19677SJose E. Roman    Input Parameters:
213887497f52SBarry Smith +  a - the `PetscInt` value
21392f18eb33SBarry Smith -  b - the second value
21402f18eb33SBarry Smith 
2141d8d19677SJose E. Roman    Output Parameter:
214216a05f60SBarry Smith .  result - the result as a `PetscInt` value, or `NULL` if you do not want the result, you just want to check if it overflows
21432f18eb33SBarry Smith 
2144667f096bSBarry Smith    Level: advanced
21452f18eb33SBarry Smith 
2146667f096bSBarry Smith    Notes:
2147667f096bSBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`
2148667f096bSBarry Smith 
2149667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2150f5f57ec0SBarry Smith 
2151b5e6e808SPierre Jolivet    Developer Note:
215216a05f60SBarry Smith    In most places in the source code we currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks.
215316a05f60SBarry Smith    `PetscIntSumError()` can be used to check for this situation.
21542f18eb33SBarry Smith 
2155917c3dccSPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntSumError()`
21562f18eb33SBarry Smith @*/
2157d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
2158d71ae5a4SJacob Faibussowitsch {
2159f3fa974cSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
21602f18eb33SBarry Smith 
21612f18eb33SBarry Smith   PetscFunctionBegin;
2162835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2163835f2295SStefano Zampini   if (result) *result = r;
2164835f2295SStefano Zampini #else
2165c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
2166835f2295SStefano Zampini #endif
2167f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
21681690c2aeSBarry Smith     PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b);
2169f3fa974cSJacob Faibussowitsch   }
21703ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2171f91af8c7SBarry Smith }
2172f91af8c7SBarry Smith 
2173f91af8c7SBarry Smith /*@C
2174f91af8c7SBarry Smith 
217587497f52SBarry Smith    PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.
2176f91af8c7SBarry Smith 
2177667f096bSBarry Smith    Not Collective; No Fortran Support
2178f91af8c7SBarry Smith 
2179d8d19677SJose E. Roman    Input Parameters:
218087497f52SBarry Smith +  a - the `PetscInt` value
2181f91af8c7SBarry Smith -  b - the second value
2182f91af8c7SBarry Smith 
2183d8d19677SJose E. Roman    Output Parameter:
218416a05f60SBarry Smith .  c - the result as a `PetscInt` value,  or `NULL` if you do not want the result, you just want to check if it overflows
2185f91af8c7SBarry Smith 
2186f91af8c7SBarry Smith    Level: advanced
2187f91af8c7SBarry Smith 
2188667f096bSBarry Smith    Notes:
21897de69702SBarry Smith    Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64`
2190667f096bSBarry Smith 
2191667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2192667f096bSBarry Smith 
2193db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2194f91af8c7SBarry Smith @*/
2195d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
2196d71ae5a4SJacob Faibussowitsch {
2197835f2295SStefano Zampini   PetscInt64 r = a;
2198f91af8c7SBarry Smith 
2199f91af8c7SBarry Smith   PetscFunctionBegin;
2200835f2295SStefano Zampini   r += b;
2201835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2202835f2295SStefano Zampini   if (result) *result = r;
2203835f2295SStefano Zampini #else
2204c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
2205835f2295SStefano Zampini #endif
2206f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
22071690c2aeSBarry Smith     PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b);
2208f3fa974cSJacob Faibussowitsch   }
22093ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
22102f18eb33SBarry Smith }
2211c5df96a5SBarry Smith 
2212d382aafbSBarry Smith /*
22132981ebdbSBarry Smith      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
2214d382aafbSBarry Smith */
2215d382aafbSBarry Smith #if defined(hz)
2216d382aafbSBarry Smith   #undef hz
2217d382aafbSBarry Smith #endif
2218d382aafbSBarry Smith 
2219d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H)
2220d382aafbSBarry Smith   #include <sys/types.h>
2221d382aafbSBarry Smith #endif
2222d382aafbSBarry Smith 
2223d382aafbSBarry Smith /*MC
2224d382aafbSBarry Smith 
222566d79e26SBarry Smith     PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++
222616a05f60SBarry Smith                     and Fortran compilers when `petscsys.h` is included.
222766d79e26SBarry Smith 
2228baca6076SPierre Jolivet     The current PETSc version and the API for accessing it are defined in <A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscversion.h.html">include/petscversion.html</A>
222966d79e26SBarry Smith 
223066d79e26SBarry Smith     The complete version number is given as the triple  PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z)
223166d79e26SBarry Smith 
223266d79e26SBarry Smith     A change in the minor version number (y) indicates possible/likely changes in the PETSc API. Note this is different than with the semantic versioning convention
223366d79e26SBarry Smith     where only a change in the major version number (x) indicates a change in the API.
223466d79e26SBarry Smith 
223566d79e26SBarry Smith     A subminor greater than zero indicates a patch release. Version x.y.z maintains source and binary compatibility with version x.y.w for all z and w
223666d79e26SBarry Smith 
223766d79e26SBarry Smith     Use the macros PETSC_VERSION_EQ(x,y,z), PETSC_VERSION_LT(x,y,z), PETSC_VERSION_LE(x,y,z), PETSC_VERSION_GT(x,y,z),
223866d79e26SBarry Smith     PETSC_VERSION_GE(x,y,z) to determine if the current version is equal to, less than, less than or equal to, greater than or greater than or equal to a given
223966d79e26SBarry Smith     version number (x.y.z).
224066d79e26SBarry Smith 
224187497f52SBarry Smith     `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)
224266d79e26SBarry Smith 
224387497f52SBarry Smith     `PETSC_VERSION_DATE` is the date the x.y.z version was released
224466d79e26SBarry Smith 
224587497f52SBarry Smith     `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww
224666d79e26SBarry Smith 
224787497f52SBarry Smith     `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository
224866d79e26SBarry Smith 
224987497f52SBarry Smith     `PETSC_VERSION_()` is deprecated and will eventually be removed.
225066d79e26SBarry Smith 
2251cbc12506SBarry Smith     Level: intermediate
225266d79e26SBarry Smith M*/
225366d79e26SBarry Smith 
2254014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
2255014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
2256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
2257014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
2258014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2259014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
226027710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
22615f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);
2262d382aafbSBarry Smith 
22636497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscCount, const PetscInt[], PetscBool *);
22646497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscCount, const PetscInt64[], PetscBool *);
22656497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscCount, const PetscMPIInt[], PetscBool *);
22666497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscCount, const PetscReal[], PetscBool *);
22676497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt(PetscCount, PetscInt[]);
22686497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscCount, PetscInt64[]);
22696497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortCount(PetscCount, PetscCount[]);
22706497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscCount, PetscInt[]);
227122ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
22726497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscCount, const PetscInt[], PetscBool *);
227377aa4f85SJames Wright PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsCount(PetscCount, const PetscCount[], PetscBool *);
2274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
2275f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
22766497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscCount, const PetscInt[], PetscInt *);
22776497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscCount, const PetscMPIInt[], PetscInt *);
227877aa4f85SJames Wright PETSC_EXTERN PetscErrorCode PetscFindCount(PetscCount, PetscCount, const PetscCount[], PetscCount *);
2279014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
2280014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
22816497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscCount, PetscInt[], PetscInt[]);
2282981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
22836497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithMPIIntArray(PetscCount, PetscInt[], PetscMPIInt[]);
22846497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscCount, PetscInt[], PetscInt[], PetscInt[]);
2285981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
22866497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscCount, PetscMPIInt[]);
228717d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
22886497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscCount, PetscMPIInt[], PetscMPIInt[]);
22896497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscCount, PetscMPIInt[], PetscInt[]);
22906497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscCount, PetscInt[], PetscScalar[]);
22916497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscCount, PetscInt[], void *, size_t, void *);
22926497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReal(PetscCount, PetscReal[]);
22936497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscCount, PetscReal[], PetscInt[]);
2294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
2295745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
22966497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscCount, const PetscReal[], PetscReal, PetscInt *);
2297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
2298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
2299ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[], PetscInt *[], PetscInt *[]);
2300ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[]);
2301ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt *[]);
2302ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt *[]);
2303ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
2304ce605777SToby Isaac 
23054d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
2306676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
2307676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
2308676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
23094d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
2310676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
2311676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
2312676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2313676f2a66SJacob Faibussowitsch 
2314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2315014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);
2316d382aafbSBarry Smith 
231776bdecfbSBarry Smith /*J
2318d382aafbSBarry Smith     PetscRandomType - String with the name of a PETSc randomizer
2319d382aafbSBarry Smith 
2320d382aafbSBarry Smith    Level: beginner
2321d382aafbSBarry Smith 
2322667f096bSBarry Smith    Note:
232387497f52SBarry Smith    To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
232416a05f60SBarry Smith    with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc.
2325d382aafbSBarry Smith 
2326db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
232776bdecfbSBarry Smith J*/
232819fd82e9SBarry Smith typedef const char *PetscRandomType;
2329d382aafbSBarry Smith #define PETSCRAND      "rand"
2330d382aafbSBarry Smith #define PETSCRAND48    "rand48"
2331d382aafbSBarry Smith #define PETSCSPRNG     "sprng"
2332c5e4d11fSDmitry Karpeev #define PETSCRANDER48  "rander48"
233325ccb61fSToby Isaac #define PETSCRANDOM123 "random123"
2334808ba619SStefano Zampini #define PETSCCURAND    "curand"
2335d382aafbSBarry Smith 
2336d382aafbSBarry Smith /* Logging support */
2337014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2338d382aafbSBarry Smith 
2339607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
23404bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void);
2341d382aafbSBarry Smith 
2342d382aafbSBarry Smith /* Dynamic creation and loading functions */
2343140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList;
2344d382aafbSBarry Smith 
2345bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
234619fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
234744ffe595SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomSetOptionsPrefix(PetscRandom, const char[]);
2348014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
234919fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
2350fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
2351014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);
2352d382aafbSBarry Smith 
2353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
2354014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
2355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
2356808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
2357808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
2358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
2359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
2360ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, PetscInt64);
2361ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, PetscInt64 *);
2362014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);
2364d382aafbSBarry Smith 
2365014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
2366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
2367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
2368014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
2369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
2370014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
2371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
237297540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
23738a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
237497540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2375d382aafbSBarry Smith 
2376d598313aSBarry Smith /*MC
2377d598313aSBarry Smith    PetscBinaryBigEndian - indicates if values in memory are stored with big endian format
2378d598313aSBarry Smith 
2379d598313aSBarry Smith    Synopsis:
2380d598313aSBarry Smith    #include <petscsys.h>
2381d598313aSBarry Smith    PetscBool PetscBinaryBigEndian(void);
2382d598313aSBarry Smith 
2383d598313aSBarry Smith    No Fortran Support
2384d598313aSBarry Smith 
2385d598313aSBarry Smith    Level: developer
2386d598313aSBarry Smith 
2387d598313aSBarry Smith .seealso: `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
2388d598313aSBarry Smith M*/
2389d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void)
2390d71ae5a4SJacob Faibussowitsch {
23919371c9d4SSatish Balay   long _petsc_v = 1;
23929371c9d4SSatish Balay   return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
23939371c9d4SSatish Balay }
239430815ce0SLisandro Dalcin 
23956497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscCount, PetscInt *, PetscDataType);
23969860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
23976497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscCount, PetscDataType);
2398f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
2399014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
2400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
2402014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
2403014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
2404014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
2405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
2406c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER)
2407e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
2408c891a504SStefano Zampini #endif
2409d382aafbSBarry Smith 
2410014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
2411014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
24126497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscCount);
2413d382aafbSBarry Smith 
2414014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2415014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
2416014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2417014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
2418014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2419014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
24202a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2421d382aafbSBarry Smith 
2422014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
2423ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[]);
2424ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[], PetscMPIInt *[]);
2425014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
2426014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
2427ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt *[], void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
242893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
242993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, MPI_Request **, MPI_Request **, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
2430d382aafbSBarry Smith 
24316145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
24326145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);
24336145cd65SJed Brown 
2434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *);
2435d382aafbSBarry Smith 
2436ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2437ce94432eSBarry Smith 
2438d382aafbSBarry Smith struct _n_PetscSubcomm {
2439d382aafbSBarry Smith   MPI_Comm         parent;    /* parent communicator */
2440d382aafbSBarry Smith   MPI_Comm         dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2441306c2d5bSBarry Smith   MPI_Comm         child;     /* the sub-communicator */
244245487dadSJed Brown   PetscMPIInt      n;         /* num of subcommunicators under the parent communicator */
244345487dadSJed Brown   PetscMPIInt      color;     /* color of processors belong to this communicator */
2444708d824cSJed Brown   PetscMPIInt     *subsize;   /* size of subcommunicator[color] */
244545487dadSJed Brown   PetscSubcommType type;
2446e5acf8a4SHong Zhang   char            *subcommprefix;
2447d382aafbSBarry Smith };
2448d382aafbSBarry Smith 
2449d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
2450d71ae5a4SJacob Faibussowitsch {
24519371c9d4SSatish Balay   return scomm->parent;
24529371c9d4SSatish Balay }
2453d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
2454d71ae5a4SJacob Faibussowitsch {
24559371c9d4SSatish Balay   return scomm->child;
24569371c9d4SSatish Balay }
2457d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
2458d71ae5a4SJacob Faibussowitsch {
24599371c9d4SSatish Balay   return scomm->dupparent;
24609371c9d4SSatish Balay }
2461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
2462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
2463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
2464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
246565d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
2466053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
2467f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2468e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
2469a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
2470a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
2471a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);
2472d382aafbSBarry Smith 
24739962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
24749962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
24759962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
24769962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
24779962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
24789962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
24799962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
24809962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);
24819962606eSBarry Smith 
24825e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
24835f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
24845f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
24855f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
24865f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);
24875e71baefSBarry Smith 
2488a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2489a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
2490a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
2491a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
2492a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2493a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2494a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2495a32e93adSJunchao Zhang 
24966497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, PetscCount, PetscSegBuffer *);
24970f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
24986497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, PetscCount, void *);
2499137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
2500137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
2501137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
25026497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, PetscCount *);
25036497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, PetscCount);
25040f453b92SJed Brown 
2505d598313aSBarry Smith /*MC
2506d598313aSBarry Smith   PetscSegBufferGetInts - access an array of `PetscInt` from a `PetscSegBuffer`
2507d598313aSBarry Smith 
2508d598313aSBarry Smith   Synopsis:
2509d598313aSBarry Smith   #include <petscsys.h>
2510d598313aSBarry Smith   PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot);
2511d598313aSBarry Smith 
2512d598313aSBarry Smith   No Fortran Support
2513d598313aSBarry Smith 
2514d598313aSBarry Smith   Input Parameters:
2515d598313aSBarry Smith + seg   - `PetscSegBuffer` buffer
2516d598313aSBarry Smith - count - number of entries needed
2517d598313aSBarry Smith 
2518d598313aSBarry Smith   Output Parameter:
2519d598313aSBarry Smith . buf - address of new buffer for contiguous data
2520d598313aSBarry Smith 
2521d598313aSBarry Smith   Level: intermediate
2522d598313aSBarry Smith 
2523d598313aSBarry Smith   Developer Note:
2524d598313aSBarry Smith   Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2525d598313aSBarry Smith   prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2526d598313aSBarry Smith   possible.
2527d598313aSBarry Smith 
2528d598313aSBarry Smith .seealso: `PetscSegBuffer`, `PetscSegBufferGet()`, `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
2529d598313aSBarry Smith M*/
25306497c311SBarry Smith static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, PetscCount count, PetscInt *PETSC_RESTRICT *slot)
2531d71ae5a4SJacob Faibussowitsch {
25329371c9d4SSatish Balay   return PetscSegBufferGet(seg, count, (void **)slot);
25339371c9d4SSatish Balay }
2534d382aafbSBarry Smith 
25359de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
25369de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
25379de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
25389de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);
25399de0f6ecSBarry Smith 
2540ace2fbaeSBarry Smith #include <stdarg.h>
2541ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
2542ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);
2543ace2fbaeSBarry Smith 
2544268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2545fbfcfee5SBarry Smith 
25465d83a8b1SBarry Smith /*@
25471f817a21SBarry Smith      PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
25481f817a21SBarry Smith 
2549667f096bSBarry Smith      Not Collective; No Fortran Support
25501f817a21SBarry Smith 
25511f817a21SBarry Smith      Input Parameters:
255235cb6cd3SPierre Jolivet +    cite - the bibtex item, formatted to displayed on multiple lines nicely
255387497f52SBarry Smith -    set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation
25541f817a21SBarry Smith 
2555667f096bSBarry Smith      Options Database Key:
25563c7db156SBarry Smith .     -citations [filename]   - print out the bibtex entries for the given computation
25573c7db156SBarry Smith 
2558850545d0SSatish Balay      Level: intermediate
25591f817a21SBarry Smith @*/
2560d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
2561d71ae5a4SJacob Faibussowitsch {
2562dff31646SBarry Smith   size_t len;
2563dff31646SBarry Smith   char  *vstring;
2564dff31646SBarry Smith 
25651f817a21SBarry Smith   PetscFunctionBegin;
25663ba16761SJacob Faibussowitsch   if (set && *set) PetscFunctionReturn(PETSC_SUCCESS);
25679566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(cit, &len));
256835d731d1SLisandro Dalcin   PetscCall(PetscSegBufferGet(PetscCitationsList, (PetscCount)len, &vstring));
25699566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy(vstring, cit, len));
2570dff31646SBarry Smith   if (set) *set = PETSC_TRUE;
25713ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2572dff31646SBarry Smith }
2573dff31646SBarry Smith 
2574fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
2575fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
2576f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);
2577fe278a28SBarry Smith 
2578f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
2579f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
25804bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]);
2581b967cddfSBarry Smith 
25829f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
25834bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t);
25844bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]);
25859f4d3c52SBarry Smith 
258668e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
25875dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);
2588dff31646SBarry Smith 
25896497c311SBarry Smith #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
25906497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
25916497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
25926497c311SBarry Smith #endif
25936497c311SBarry Smith 
25946497c311SBarry Smith #if !defined(PETSC_HAVE_MPI_LARGE_COUNT)
2595462c564dSBarry Smith   /*
2596462c564dSBarry Smith    Cast PetscCount <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines.
25976497c311SBarry Smith    It is similar to PetscMPIIntCast() except that here it returns an MPI error code.
25986497c311SBarry Smith */
2599462c564dSBarry Smith   #define PetscMPIIntCast_Internal(a, b) \
2600462c564dSBarry Smith     do { \
2601462c564dSBarry Smith       *b = 0; \
2602462c564dSBarry Smith       if (PetscUnlikely(a > (MPIU_Count)PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT; \
2603462c564dSBarry Smith       *b = (PetscMPIInt)a; \
2604462c564dSBarry Smith     } while (0)
26056497c311SBarry Smith 
26066497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
26076497c311SBarry Smith {
2608462c564dSBarry Smith   PetscMPIInt count2, err;
26096497c311SBarry Smith 
26106497c311SBarry Smith   *count = 0; /* to prevent incorrect warnings of uninitialized variables */
2611462c564dSBarry Smith   err    = MPI_Get_count(status, dtype, &count2);
26126497c311SBarry Smith   *count = count2;
2613462c564dSBarry Smith   return err;
26146497c311SBarry Smith }
26156497c311SBarry Smith 
2616462c564dSBarry Smith static inline PetscMPIInt MPIU_Send(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm)
26176497c311SBarry Smith {
2618462c564dSBarry Smith   PetscMPIInt count2, err;
26196497c311SBarry Smith 
2620462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2621462c564dSBarry Smith   err = MPI_Send((void *)buf, count2, dtype, dest, tag, comm);
2622462c564dSBarry Smith   return err;
26236497c311SBarry Smith }
26246497c311SBarry Smith 
2625462c564dSBarry Smith static inline PetscMPIInt MPIU_Send_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
26266497c311SBarry Smith {
2627462c564dSBarry Smith   PetscMPIInt count2, err;
26286497c311SBarry Smith 
2629462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2630462c564dSBarry Smith   err = MPI_Send_init((void *)buf, count2, dtype, dest, tag, comm, request);
2631462c564dSBarry Smith   return err;
26326497c311SBarry Smith }
26336497c311SBarry Smith 
2634462c564dSBarry Smith static inline PetscMPIInt MPIU_Isend(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
26356497c311SBarry Smith {
2636462c564dSBarry Smith   PetscMPIInt count2, err;
26376497c311SBarry Smith 
2638462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2639462c564dSBarry Smith   err = MPI_Isend((void *)buf, count2, dtype, dest, tag, comm, request);
2640462c564dSBarry Smith   return err;
26416497c311SBarry Smith }
26426497c311SBarry Smith 
2643462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Status *status)
26446497c311SBarry Smith {
2645462c564dSBarry Smith   PetscMPIInt count2, err;
26466497c311SBarry Smith 
2647462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2648462c564dSBarry Smith   err = MPI_Recv((void *)buf, count2, dtype, source, tag, comm, status);
2649462c564dSBarry Smith   return err;
26506497c311SBarry Smith }
26516497c311SBarry Smith 
2652462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
26536497c311SBarry Smith {
2654462c564dSBarry Smith   PetscMPIInt count2, err;
26556497c311SBarry Smith 
2656462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2657462c564dSBarry Smith   err = MPI_Recv_init((void *)buf, count2, dtype, source, tag, comm, request);
2658462c564dSBarry Smith   return err;
26596497c311SBarry Smith }
26606497c311SBarry Smith 
2661462c564dSBarry Smith static inline PetscMPIInt MPIU_Irecv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
26626497c311SBarry Smith {
2663462c564dSBarry Smith   PetscMPIInt count2, err;
26646497c311SBarry Smith 
2665462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2666462c564dSBarry Smith   err = MPI_Irecv((void *)buf, count2, dtype, source, tag, comm, request);
2667462c564dSBarry Smith   return err;
26686497c311SBarry Smith }
26696497c311SBarry Smith 
2670462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce(const void *inbuf, void *outbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op, PetscMPIInt root, MPI_Comm comm)
26716497c311SBarry Smith {
2672462c564dSBarry Smith   PetscMPIInt count2, err;
26736497c311SBarry Smith 
2674462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2675462c564dSBarry Smith   err = MPI_Reduce((void *)inbuf, outbuf, count2, dtype, op, root, comm);
2676462c564dSBarry Smith   return err;
26776497c311SBarry Smith }
26786497c311SBarry Smith 
26796497c311SBarry Smith   #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
2680462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op)
26816497c311SBarry Smith {
2682462c564dSBarry Smith   PetscMPIInt count2, err;
26836497c311SBarry Smith 
2684462c564dSBarry Smith   PetscMPIIntCast_Internal(count, &count2);
2685462c564dSBarry Smith   err = MPI_Reduce_local((void *)inbuf, inoutbuf, count2, dtype, op);
2686462c564dSBarry Smith   return err;
26876497c311SBarry Smith }
26886497c311SBarry Smith   #endif
26896497c311SBarry Smith 
26903fa2bd1cSBarry Smith   #if !defined(PETSC_USE_64BIT_INDICES)
26913fa2bd1cSBarry Smith     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
26923fa2bd1cSBarry Smith     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
26933fa2bd1cSBarry Smith   #else
26943fa2bd1cSBarry Smith     #define MPIU_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
2695c13ed45bSPierre Jolivet       ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
26963fa2bd1cSBarry Smith     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \
2697c13ed45bSPierre Jolivet       ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
26983fa2bd1cSBarry Smith   #endif
26993fa2bd1cSBarry Smith 
27006497c311SBarry Smith #else
27016497c311SBarry Smith 
27026497c311SBarry Smith   /* on 32 bit systems MPI_Count maybe 64-bit while PetscCount is 32-bit */
2703462c564dSBarry Smith   #define PetscCountCast_Internal(a, b) \
2704462c564dSBarry Smith     do { \
2705462c564dSBarry Smith       *b = 0; \
2706462c564dSBarry Smith       if (PetscUnlikely(a > (MPI_Count)PETSC_COUNT_MAX)) return MPI_ERR_COUNT; \
2707462c564dSBarry Smith       *b = (PetscMPIInt)a; \
2708462c564dSBarry Smith     } while (0)
27096497c311SBarry Smith 
27106497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
27116497c311SBarry Smith {
27126497c311SBarry Smith   MPI_Count   count2;
2713462c564dSBarry Smith   PetscMPIInt err;
27146497c311SBarry Smith 
27156497c311SBarry Smith   *count = 0; /* to prevent incorrect warnings of uninitialized variables */
2716462c564dSBarry Smith   err    = MPI_Get_count_c(status, dtype, &count2);
2717462c564dSBarry Smith   if (err) return err;
2718462c564dSBarry Smith   PetscCountCast_Internal(count2, count);
2719462c564dSBarry Smith   return MPI_SUCCESS;
27206497c311SBarry Smith }
27216497c311SBarry Smith 
27226497c311SBarry Smith   #define MPIU_Reduce(inbuf, outbuf, count, dtype, op, root, comm)      MPI_Reduce_c(inbuf, outbuf, (MPI_Count)(count), dtype, op, root, comm)
27236497c311SBarry Smith   #define MPIU_Send(buf, count, dtype, dest, tag, comm)                 MPI_Send_c(buf, (MPI_Count)(count), dtype, dest, tag, comm)
27246497c311SBarry Smith   #define MPIU_Send_init(buf, count, dtype, dest, tag, comm, request)   MPI_Send_init_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
27256497c311SBarry Smith   #define MPIU_Isend(buf, count, dtype, dest, tag, comm, request)       MPI_Isend_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
27266497c311SBarry Smith   #define MPIU_Recv(buf, count, dtype, source, tag, comm, status)       MPI_Recv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, status)
27276497c311SBarry Smith   #define MPIU_Recv_init(buf, count, dtype, source, tag, comm, request) MPI_Recv_init_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
27286497c311SBarry Smith   #define MPIU_Irecv(buf, count, dtype, source, tag, comm, request)     MPI_Irecv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
27296497c311SBarry Smith   #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
27306a210b70SBarry Smith     #define MPIU_Reduce_local(inbuf, inoutbuf, count, dtype, op) MPI_Reduce_local_c(inbuf, inoutbuf, (MPI_Count)(count), dtype, op)
27316497c311SBarry Smith   #endif
27323fa2bd1cSBarry Smith 
27333fa2bd1cSBarry Smith /*MC
27343fa2bd1cSBarry Smith   MPIU_Scatterv - A replacement for `MPI_Scatterv()` that can be called with `PetscInt` types when PETSc is built for either 32-bit indices or 64-bit indices.
27353fa2bd1cSBarry Smith 
27363fa2bd1cSBarry Smith   Synopsis:
27373fa2bd1cSBarry Smith   #include <petscsys.h>
27383fa2bd1cSBarry Smith   PetscMPIInt MPIU_Scatterv(const void *sendbuf, const PetscInt sendcounts[], const PetscInt displs[], MPI_Datatype sendtype, void *recvbuf, PetscInt recvcount, MPI_Datatype recvtype, PetscMPIInt root, MPI_Comm comm)
27393fa2bd1cSBarry Smith 
27403fa2bd1cSBarry Smith   Collective
27413fa2bd1cSBarry Smith 
27423fa2bd1cSBarry Smith   Input Parameters:
27433fa2bd1cSBarry Smith + sendbuf    - address of send buffer
27443fa2bd1cSBarry Smith . sendcounts - non-negative `PetscInt` array (of length `comm` group size) specifying the number of elements to send to each MPI process
27453fa2bd1cSBarry Smith . displs     - `PetscInt` array (of length `comm` group size). Entry i specifies the displacement (relative to `sendbuf`) from which to take the outgoing data to process i
27463fa2bd1cSBarry Smith . sendtype   - data type of `sendbuf` elements
27473fa2bd1cSBarry Smith . recvcount  - number of elements in `recvbuf` (non-negative integer)
27483fa2bd1cSBarry Smith . recvtype   - data type of `recvbuf` elements
27493fa2bd1cSBarry Smith . root       - Rank of the MPI root process, which will dispatch the data to scatter
27503fa2bd1cSBarry Smith - comm       - `MPI_Comm` communicator
27513fa2bd1cSBarry Smith 
27523fa2bd1cSBarry Smith   Output Parameter:
27533fa2bd1cSBarry Smith . recvbuf - the resulting scattered values on this MPI process
27543fa2bd1cSBarry Smith 
27553fa2bd1cSBarry Smith   Level: developer
27563fa2bd1cSBarry Smith 
27573fa2bd1cSBarry Smith   Notes:
27583fa2bd1cSBarry Smith   Should be wrapped with `PetscCallMPI()` for error checking
27593fa2bd1cSBarry Smith 
27603fa2bd1cSBarry Smith   This is different than most of the `MPIU_` wrappers in that all the count arguments are in `PetscInt`
27613fa2bd1cSBarry Smith 
27623fa2bd1cSBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()`, `MPIU_Gatherv()`
27633fa2bd1cSBarry Smith M*/
27643fa2bd1cSBarry Smith 
27653fa2bd1cSBarry Smith   #if !defined(PETSC_USE_64BIT_INDICES)
27663fa2bd1cSBarry Smith     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
27673fa2bd1cSBarry Smith     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
27683fa2bd1cSBarry Smith   #else
27693fa2bd1cSBarry Smith     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv_c(sendbuf, (const MPI_Count *)(sendcounts), (const MPI_Aint *)(displs), sendtype, recvbuf, recvcount, recvtype, root, comm)
27703fa2bd1cSBarry Smith     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv_c(sendbuf, sendcount, sendtype, recvbuf, (const MPI_Count *)(recvcounts), (const MPI_Aint *)(displs), recvtype, root, comm)
27713fa2bd1cSBarry Smith   #endif
27723fa2bd1cSBarry Smith 
27736497c311SBarry Smith #endif
27746497c311SBarry Smith 
2775462c564dSBarry Smith PETSC_EXTERN PetscMPIInt MPIU_Allreduce_Private(const void *, void *, MPIU_Count, MPI_Datatype, MPI_Op, MPI_Comm);
27766a210b70SBarry Smith 
2777b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG)
2778d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str)
2779d71ae5a4SJacob Faibussowitsch {
2780df05ca09SBarry Smith   unsigned int c, hash = 5381;
2781df05ca09SBarry Smith 
2782503e1a2cSLisandro Dalcin   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2783df05ca09SBarry Smith   return hash;
2784df05ca09SBarry Smith }
27856497c311SBarry Smith #endif
278677a5e07dSBarry Smith 
278777a5e07dSBarry Smith /*MC
2788462c564dSBarry Smith   MPIU_Allreduce - A replacement for `MPI_Allreduce()` that (1) performs single-count `MPIU_INT` operations in `PetscInt64` to detect
2789462c564dSBarry Smith                    integer overflows and (2) tries to determine if the call from all the MPI ranks occur in the
279087497f52SBarry Smith                    same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
279187497f52SBarry Smith                    resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.
279277a5e07dSBarry Smith 
279377a5e07dSBarry Smith   Synopsis:
279477a5e07dSBarry Smith   #include <petscsys.h>
2795462c564dSBarry Smith   PetscMPIInt MPIU_Allreduce(void *indata,void *outdata,PetscCount count,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm);
279677a5e07dSBarry Smith 
27977cdbe19fSJose E. Roman   Collective
27987cdbe19fSJose E. Roman 
279977a5e07dSBarry Smith   Input Parameters:
28006a210b70SBarry Smith + a     - pointer to the input data to be reduced
28016a210b70SBarry Smith . count - the number of MPI data items in `a` and `b`
28026497c311SBarry Smith . dtype - the MPI datatype, for example `MPI_INT`
28036497c311SBarry Smith . op    - the MPI operation, for example `MPI_SUM`
28046497c311SBarry Smith - comm   - the MPI communicator on which the operation occurs
280577a5e07dSBarry Smith 
280677a5e07dSBarry Smith   Output Parameter:
28076a210b70SBarry Smith . b - the reduced values
280877a5e07dSBarry Smith 
2809667f096bSBarry Smith   Level: developer
2810667f096bSBarry Smith 
2811462c564dSBarry Smith   Note:
2812462c564dSBarry Smith   Should be wrapped with `PetscCallMPI()` for error checking
2813462c564dSBarry Smith 
28146497c311SBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()`
281577a5e07dSBarry Smith M*/
28166497c311SBarry Smith #if defined(PETSC_USE_DEBUG)
28179371c9d4SSatish Balay   #define MPIU_Allreduce(a, b, c, d, e, fcomm) \
28183ba16761SJacob Faibussowitsch     PetscMacroReturnStandard( \
28193ba16761SJacob Faibussowitsch     PetscMPIInt a_b1[6], a_b2[6]; \
28203ba16761SJacob Faibussowitsch     int _mpiu_allreduce_c_int = (int)(c); \
28213ba16761SJacob Faibussowitsch     a_b1[0] = -(PetscMPIInt)__LINE__; \
28223ba16761SJacob Faibussowitsch     a_b1[1] = -a_b1[0]; \
28233ba16761SJacob Faibussowitsch     a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \
28243ba16761SJacob Faibussowitsch     a_b1[3] = -a_b1[2]; \
28253ba16761SJacob Faibussowitsch     a_b1[4] = -(PetscMPIInt)(c); \
28263ba16761SJacob Faibussowitsch     a_b1[5] = -a_b1[4]; \
28273ba16761SJacob Faibussowitsch     \
28283ba16761SJacob Faibussowitsch     PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \
2829462c564dSBarry Smith     PetscCheck(-a_b2[0] == a_b2[1], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (code lines) on different processors"); \
2830462c564dSBarry Smith     PetscCheck(-a_b2[2] == a_b2[3], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (functions) on different processors"); \
2831462c564dSBarry Smith     PetscCheck(-a_b2[4] == a_b2[5], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); \
28326a210b70SBarry Smith     PetscCallMPI(MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)));)
2833b2566f29SBarry Smith #else
2834462c564dSBarry Smith   #define MPIU_Allreduce(a, b, c, d, e, fcomm) MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm))
2835b2566f29SBarry Smith #endif
2836b2566f29SBarry Smith 
2837b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
28388198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
28398198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
28402f065d89SBarry Smith #endif
28418198064fSBarry Smith 
2842cd88fca5SStefano Zampini /* this is a vile hack */
2843cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI)
28449371c9d4SSatish Balay   #if !defined(PETSC_NECMPI_VERSION_MAJOR) || !defined(PETSC_NECMPI_VERSION_MINOR) || PETSC_NECMPI_VERSION_MAJOR < 2 || (PETSC_NECMPI_VERSION_MAJOR == 2 && PETSC_NECMPI_VERSION_MINOR < 18)
2845cd88fca5SStefano Zampini     #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
2846cd88fca5SStefano Zampini   #endif
2847961fb248SStefano Zampini #endif
2848cd88fca5SStefano Zampini 
284912801b39SBarry Smith /*
285060fbe2beSVaclav Hapla     List of external packages and queries on it
285160fbe2beSVaclav Hapla */
285260fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);
285360fbe2beSVaclav Hapla 
2854f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */
2855f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
2856f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
28577a99bfcaSBarry Smith PETSC_EXTERN PetscBool      PCMPIServerActive;
28589f0612e4SBarry Smith PETSC_EXTERN PetscBool      PCMPIServerInSolve;
28599f0612e4SBarry Smith PETSC_EXTERN PetscBool      PCMPIServerUseShmget;
28609f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAllocateArray(size_t, size_t, void **);
28619f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetDeallocateArray(void **);
28629f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetMapAddresses(MPI_Comm, PetscInt, const void **, void **);
28639f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetUnmapAddresses(PetscInt, void **);
28649f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAddressesFinalize(void);
28659f0612e4SBarry Smith 
28669f0612e4SBarry Smith typedef struct {
28679f0612e4SBarry Smith   PetscInt n;
28689f0612e4SBarry Smith   void    *addr[3];
28699f0612e4SBarry Smith } PCMPIServerAddresses;
287049abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PCMPIServerAddressesDestroy;
2871fbf9dbe5SBarry Smith 
2872edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS
2873046ed546SBarry Smith 
2874046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt);
2875046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *);
28768e3a54c0SPierre Jolivet 
28778e3a54c0SPierre Jolivet /*MC
28788e3a54c0SPierre Jolivet    PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset
28798e3a54c0SPierre Jolivet 
28808e3a54c0SPierre Jolivet    Level: beginner
28818e3a54c0SPierre Jolivet 
28828e3a54c0SPierre Jolivet    Note:
28838e3a54c0SPierre Jolivet    This is needed to avoid errors with undefined-behavior sanitizers such as
28848e3a54c0SPierre Jolivet    UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags
28858e3a54c0SPierre Jolivet M*/
28868e3a54c0SPierre Jolivet #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL)
2887ce78bad3SBarry Smith 
2888ce78bad3SBarry Smith /* this is required to force PetscDevice to be visible at the system level for the Fortran interface */
2889ce78bad3SBarry Smith #include <petscdevicetypes.h>
2890