xref: /petsc/include/petscsys.h (revision 2fe279fdf3e687a416e4eadb7d3c7a82d60442c6)
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 */
76524c165SJacob Faibussowitsch #ifndef PETSCSYS_H
826bd1501SBarry Smith #define PETSCSYS_H
93ca90d2dSJacob Faibussowitsch 
10d382aafbSBarry Smith /* ========================================================================== */
11d382aafbSBarry Smith /*
12d382aafbSBarry Smith    petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is
131c77a0c5SBarry Smith    found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that
141c77a0c5SBarry Smith    PETSc's makefiles add to the compiler rules.
151c77a0c5SBarry Smith    For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same
161cc8b206SBarry Smith    directory as the other PETSc include files.
17d382aafbSBarry Smith */
182c8e378dSBarry Smith #include <petscconf.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
74a7886beaSBarry Smith */
75a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI)
766524c165SJacob Faibussowitsch   #ifndef MPIUNI_H
77a7886beaSBarry Smith     #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
78a7886beaSBarry Smith   #endif
7941f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION)
8041f4af4cSSatish Balay   #if !defined(I_MPI_NUMVERSION)
8141f4af4cSSatish Balay     #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h"
8241f4af4cSSatish Balay   #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION
8341f4af4cSSatish 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"
8441f4af4cSSatish Balay   #endif
8541f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION)
8641f4af4cSSatish Balay   #if !defined(MVAPICH2_NUMVERSION)
8741f4af4cSSatish Balay     #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h"
8841f4af4cSSatish Balay   #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION
8941f4af4cSSatish Balay     #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version"
9041f4af4cSSatish Balay   #endif
91a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION)
9241f4af4cSSatish Balay   #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION)
93a7886beaSBarry Smith     #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
941c284764SMin RK   #elif (MPICH_NUMVERSION / 100000000 != PETSC_HAVE_MPICH_NUMVERSION / 100000000) || (MPICH_NUMVERSION / 100000 < PETSC_HAVE_MPICH_NUMVERSION / 100000) || (MPICH_NUMVERSION / 100000 == PETSC_HAVE_MPICH_NUMVERSION / 100000 && MPICH_NUMVERSION % 100000 / 1000 < PETSC_HAVE_MPICH_NUMVERSION % 100000 / 1000)
95a7886beaSBarry Smith     #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version"
96a7886beaSBarry Smith   #endif
97a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION)
98a7886beaSBarry Smith   #if !defined(OMPI_MAJOR_VERSION)
99a7886beaSBarry Smith     #error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h"
1001c284764SMin RK   #elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION)
101c3ac57cfSSatish Balay     #error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version"
102a7886beaSBarry Smith   #endif
103d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION)
104d97fd468SStefano Zampini   #if !defined(MSMPI_VER)
105d97fd468SStefano Zampini     #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h"
106d97fd468SStefano Zampini   #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION)
107d97fd468SStefano Zampini     #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version"
108d97fd468SStefano Zampini   #endif
109d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER)
110d97fd468SStefano Zampini   #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant"
111a7886beaSBarry Smith #endif
112a7886beaSBarry Smith 
113a7886beaSBarry Smith /*
1142981ebdbSBarry Smith     Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
115d382aafbSBarry Smith     see the top of mpicxx.h in the MPICH2 distribution.
116d382aafbSBarry Smith */
117d382aafbSBarry Smith #include <stdio.h>
118d382aafbSBarry Smith 
119d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
120d382aafbSBarry Smith #if !defined(MPIAPI)
121d382aafbSBarry Smith   #define MPIAPI
122d382aafbSBarry Smith #endif
123d382aafbSBarry Smith 
12493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum);
12593d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool);
126e28ce29aSPatrick Sanan 
127e28ce29aSPatrick Sanan /*MC
12887497f52SBarry Smith    MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt`
129e28ce29aSPatrick Sanan 
130667f096bSBarry Smith    Level: beginner
131667f096bSBarry Smith 
132e28ce29aSPatrick Sanan    Notes:
13387497f52SBarry Smith    In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.
134e28ce29aSPatrick Sanan 
135db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
136e28ce29aSPatrick Sanan M*/
137e28ce29aSPatrick Sanan 
1387cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;
139b7b8f77aSBarry Smith 
140d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES)
141bd84f1cfSSatish Balay   #define MPIU_INT MPIU_INT64
142d382aafbSBarry Smith #else
143d382aafbSBarry Smith   #define MPIU_INT MPI_INT
144d382aafbSBarry Smith #endif
145d382aafbSBarry Smith 
146503cfb0cSBarry Smith /*
147503cfb0cSBarry Smith     For the rare cases when one needs to send a size_t object with MPI
148503cfb0cSBarry Smith */
14993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t);
150d382aafbSBarry Smith 
151d382aafbSBarry Smith /*
152d382aafbSBarry Smith       You can use PETSC_STDOUT as a replacement of stdout. You can also change
153d382aafbSBarry Smith     the value of PETSC_STDOUT to redirect all standard output elsewhere
154d382aafbSBarry Smith */
155014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT;
156d382aafbSBarry Smith 
157d382aafbSBarry Smith /*
158d382aafbSBarry Smith       You can use PETSC_STDERR as a replacement of stderr. You can also change
159d382aafbSBarry Smith     the value of PETSC_STDERR to redirect all standard error elsewhere
160d382aafbSBarry Smith */
161014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR;
162d382aafbSBarry Smith 
163d382aafbSBarry Smith /*
164dc07da0dSStefano Zampini   Handle inclusion when using clang compiler with CUDA support
165dc07da0dSStefano Zampini   __float128 is not available for the device
166dc07da0dSStefano Zampini */
167dc07da0dSStefano Zampini #if defined(__clang__) && defined(__CUDA_ARCH__)
168dc07da0dSStefano Zampini   #define PETSC_SKIP_REAL___FLOAT128
169dc07da0dSStefano Zampini #endif
170dc07da0dSStefano Zampini 
171dc07da0dSStefano Zampini /*
172d382aafbSBarry Smith     Declare extern C stuff after including external header files
173d382aafbSBarry Smith */
174d382aafbSBarry Smith 
1756edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
1768b49ba18SBarry Smith /*
177390e1bf2SBarry Smith     Defines elementary mathematics functions and constants.
1788b49ba18SBarry Smith */
1798b49ba18SBarry Smith #include <petscmath.h>
1808b49ba18SBarry Smith 
181d382aafbSBarry Smith /*MC
182667f096bSBarry Smith     PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument
183d382aafbSBarry Smith 
184d382aafbSBarry Smith    Level: beginner
185d382aafbSBarry Smith 
186e28ce29aSPatrick Sanan    Note:
187667f096bSBarry Smith    Accepted by many PETSc functions to not set a parameter and instead use a default value
188d382aafbSBarry Smith 
18987497f52SBarry Smith    Fortran Note:
190667f096bSBarry Smith    Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc
191d382aafbSBarry Smith 
192db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE`
193d382aafbSBarry Smith M*/
194f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR
195f3fa974cSJacob Faibussowitsch #define PETSC_NULL   PETSC_DEPRECATED_MACRO("GCC warning \"PETSC_NULL is deprecated, use PETSC_NULLPTR instead (since version 3.19)\"") PETSC_NULLPTR
196c528d872SBarry Smith 
197d382aafbSBarry Smith /*MC
198557d4da8SBarry Smith     PETSC_DECIDE - standard way of passing in integer or floating point parameter
199557d4da8SBarry Smith        where you wish PETSc to use the default.
200557d4da8SBarry Smith 
201557d4da8SBarry Smith    Level: beginner
202557d4da8SBarry Smith 
203db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`
204557d4da8SBarry Smith M*/
205557d4da8SBarry Smith 
206557d4da8SBarry Smith /*MC
207d382aafbSBarry Smith     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
208d382aafbSBarry Smith        where you wish PETSc to compute the required value.
209d382aafbSBarry Smith 
210d382aafbSBarry Smith    Level: beginner
211d382aafbSBarry Smith 
212e28ce29aSPatrick Sanan    Developer Note:
21387497f52SBarry Smith    I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for
21487497f52SBarry Smith      some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value.
215557d4da8SBarry Smith 
216db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`
217d382aafbSBarry Smith M*/
218d382aafbSBarry Smith 
219d382aafbSBarry Smith /*MC
220557d4da8SBarry Smith     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
221557d4da8SBarry Smith        where you wish PETSc to use the default.
222557d4da8SBarry Smith 
223557d4da8SBarry Smith    Level: beginner
224557d4da8SBarry Smith 
22587497f52SBarry Smith    Fortran Note:
22687497f52SBarry Smith    You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`.
227557d4da8SBarry Smith 
228db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`
229557d4da8SBarry Smith M*/
230f3fa974cSJacob Faibussowitsch enum {
231f3fa974cSJacob Faibussowitsch   PETSC_DECIDE    = -1,
232f3fa974cSJacob Faibussowitsch   PETSC_DETERMINE = PETSC_DECIDE,
233f3fa974cSJacob Faibussowitsch   PETSC_DEFAULT   = -2
234f3fa974cSJacob Faibussowitsch };
235557d4da8SBarry Smith 
236557d4da8SBarry Smith /*MC
23787497f52SBarry Smith     PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents
238ea8fe74dSBarry Smith            all the processes that PETSc knows about.
239d382aafbSBarry Smith 
240d382aafbSBarry Smith    Level: beginner
241d382aafbSBarry Smith 
242e28ce29aSPatrick Sanan    Notes:
24387497f52SBarry Smith    By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to
24487497f52SBarry Smith           run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller)
24587497f52SBarry Smith           communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling
24687497f52SBarry Smith           PetscInitialize(), but after `MPI_Init()` has been called.
247a990b902SBarry Smith 
24887497f52SBarry Smith           The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()`
249a990b902SBarry Smith           is called because it may not have a valid value yet.
250d382aafbSBarry Smith 
251db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF`
252d382aafbSBarry Smith M*/
253014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
254d382aafbSBarry Smith 
255d382aafbSBarry Smith /*MC
25687497f52SBarry Smith     PETSC_COMM_SELF - This is always `MPI_COMM_SELF`
257d382aafbSBarry Smith 
258d382aafbSBarry Smith    Level: beginner
259d382aafbSBarry Smith 
260e28ce29aSPatrick Sanan    Notes:
261e28ce29aSPatrick Sanan    Do not USE/access or set this variable before PetscInitialize() has been called.
262a990b902SBarry Smith 
263db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`
264d382aafbSBarry Smith M*/
265d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF
266d382aafbSBarry Smith 
2676de5d289SStefano Zampini /*MC
2686de5d289SStefano Zampini     PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes
26987497f52SBarry Smith            MPI with `MPI_Init_thread()`.
2706de5d289SStefano Zampini 
2716de5d289SStefano Zampini    Level: beginner
2726de5d289SStefano Zampini 
2736de5d289SStefano Zampini    Notes:
27487497f52SBarry Smith    By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`.
2756de5d289SStefano Zampini 
276db781477SPatrick Sanan .seealso: `PetscInitialize()`
2776de5d289SStefano Zampini M*/
2786de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
2796de5d289SStefano Zampini 
280d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI;
2818ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
282014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled;
283014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled;
2844cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
285d382aafbSBarry Smith 
286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
28957f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
29057f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);
291d382aafbSBarry Smith 
29259e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
29359e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
29459e55d94SJunchao Zhang #endif
29559e55d94SJunchao Zhang 
29671438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM)
29771438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscBeganNvshmem;
29871438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
29971438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
30071438e86SJunchao Zhang #endif
30171438e86SJunchao Zhang 
302540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL)
303540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
304540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
305540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
306540e20f2SPierre Jolivet #endif
307540e20f2SPierre Jolivet 
308d382aafbSBarry Smith /*MC
30987497f52SBarry Smith    PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this
310d382aafbSBarry Smith 
311eca87e8dSBarry Smith    Synopsis:
312aaa7dc30SBarry Smith     #include <petscsys.h>
313eca87e8dSBarry Smith    PetscErrorCode PetscMalloc(size_t m,void **result)
314eca87e8dSBarry Smith 
315eca87e8dSBarry Smith    Not Collective
316eca87e8dSBarry Smith 
317d382aafbSBarry Smith    Input Parameter:
318d382aafbSBarry Smith .  m - number of bytes to allocate
319d382aafbSBarry Smith 
320d382aafbSBarry Smith    Output Parameter:
321d382aafbSBarry Smith .  result - memory allocated
322d382aafbSBarry Smith 
323d382aafbSBarry Smith    Level: beginner
324d382aafbSBarry Smith 
32549d7da52SJed Brown    Notes:
32649d7da52SJed Brown    Memory is always allocated at least double aligned
327d382aafbSBarry Smith 
32887497f52SBarry Smith    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`.
329d382aafbSBarry Smith 
330db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`
331d382aafbSBarry Smith M*/
332071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
333d382aafbSBarry Smith 
334d382aafbSBarry Smith /*MC
335d5b43468SJose E. Roman    PetscRealloc - Reallocates memory
3363221ece2SMatthew G. Knepley 
3373221ece2SMatthew G. Knepley    Synopsis:
3383221ece2SMatthew G. Knepley     #include <petscsys.h>
3393221ece2SMatthew G. Knepley    PetscErrorCode PetscRealloc(size_t m,void **result)
3403221ece2SMatthew G. Knepley 
3413221ece2SMatthew G. Knepley    Not Collective
3423221ece2SMatthew G. Knepley 
3433221ece2SMatthew G. Knepley    Input Parameters:
3443221ece2SMatthew G. Knepley +  m - number of bytes to allocate
34592f119d6SBarry Smith -  result - previous memory
3463221ece2SMatthew G. Knepley 
3473221ece2SMatthew G. Knepley    Output Parameter:
3483221ece2SMatthew G. Knepley .  result - new memory allocated
3493221ece2SMatthew G. Knepley 
3503221ece2SMatthew G. Knepley    Level: developer
3513221ece2SMatthew G. Knepley 
3523221ece2SMatthew G. Knepley    Notes:
3533221ece2SMatthew G. Knepley    Memory is always allocated at least double aligned
3543221ece2SMatthew G. Knepley 
355db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
3563221ece2SMatthew G. Knepley M*/
3573221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
3583221ece2SMatthew G. Knepley 
3593221ece2SMatthew G. Knepley /*MC
36087497f52SBarry Smith    PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment
361d382aafbSBarry Smith 
362d382aafbSBarry Smith    Synopsis:
363aaa7dc30SBarry Smith     #include <petscsys.h>
364d382aafbSBarry Smith    void *PetscAddrAlign(void *addr)
365d382aafbSBarry Smith 
366eca87e8dSBarry Smith    Not Collective
367eca87e8dSBarry Smith 
368*2fe279fdSBarry Smith    Input Parameter:
369eca87e8dSBarry Smith .  addr - address to align (any pointer type)
370eca87e8dSBarry Smith 
371d382aafbSBarry Smith    Level: developer
372d382aafbSBarry Smith 
373db781477SPatrick Sanan .seealso: `PetscMallocAlign()`
374d382aafbSBarry Smith M*/
375f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)))
376d382aafbSBarry Smith 
377d382aafbSBarry Smith /*MC
37887497f52SBarry Smith    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`
3798f51dc47SJunchao Zhang 
3808f51dc47SJunchao Zhang    Synopsis:
3818f51dc47SJunchao Zhang     #include <petscsys.h>
3828f51dc47SJunchao Zhang    PetscErrorCode PetscCalloc(size_t m,void **result)
3838f51dc47SJunchao Zhang 
3848f51dc47SJunchao Zhang    Not Collective
3858f51dc47SJunchao Zhang 
3868f51dc47SJunchao Zhang    Input Parameter:
3878f51dc47SJunchao Zhang .  m - number of bytes to allocate
3888f51dc47SJunchao Zhang 
3898f51dc47SJunchao Zhang    Output Parameter:
3908f51dc47SJunchao Zhang .  result - memory allocated
3918f51dc47SJunchao Zhang 
3928f51dc47SJunchao Zhang    Level: beginner
3938f51dc47SJunchao Zhang 
3948f51dc47SJunchao Zhang    Notes:
3958f51dc47SJunchao Zhang    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
3968f51dc47SJunchao Zhang 
3978f51dc47SJunchao Zhang    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree().
3988f51dc47SJunchao Zhang 
399db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`
4008f51dc47SJunchao Zhang M*/
401f3fa974cSJacob Faibussowitsch #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result))
4028f51dc47SJunchao Zhang 
4038f51dc47SJunchao Zhang /*MC
40487497f52SBarry Smith    PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`
405d382aafbSBarry Smith 
406eca87e8dSBarry Smith    Synopsis:
407aaa7dc30SBarry Smith     #include <petscsys.h>
408785e854fSJed Brown    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
409785e854fSJed Brown 
410785e854fSJed Brown    Not Collective
411785e854fSJed Brown 
412785e854fSJed Brown    Input Parameter:
413390e1bf2SBarry Smith .  m1 - number of elements to allocate  (may be zero)
414785e854fSJed Brown 
415785e854fSJed Brown    Output Parameter:
4161fe1b817SJunchao Zhang .  r1 - memory allocated
417785e854fSJed Brown 
418e28ce29aSPatrick Sanan    Note:
419e28ce29aSPatrick Sanan    This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not
42087497f52SBarry Smith          multiply the number of elements requested by the `sizeof()` the type. For example use
421390e1bf2SBarry Smith $  PetscInt *id;
422390e1bf2SBarry Smith $  PetscMalloc1(10,&id);
423390e1bf2SBarry Smith         not
424390e1bf2SBarry Smith $  PetscInt *id;
425390e1bf2SBarry Smith $  PetscMalloc1(10*sizeof(PetscInt),&id);
426390e1bf2SBarry Smith 
42787497f52SBarry Smith         Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.
428390e1bf2SBarry Smith 
429390e1bf2SBarry Smith    Level: beginner
430785e854fSJed Brown 
431db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
432785e854fSJed Brown M*/
433f3fa974cSJacob Faibussowitsch #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
434785e854fSJed Brown 
435785e854fSJed Brown /*MC
43687497f52SBarry Smith    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`
4371795a4d1SJed Brown 
4381795a4d1SJed Brown    Synopsis:
439aaa7dc30SBarry Smith     #include <petscsys.h>
4401795a4d1SJed Brown    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
4411795a4d1SJed Brown 
4421795a4d1SJed Brown    Not Collective
4431795a4d1SJed Brown 
4441795a4d1SJed Brown    Input Parameter:
4451795a4d1SJed Brown .  m1 - number of elements to allocate in 1st chunk  (may be zero)
4461795a4d1SJed Brown 
4471795a4d1SJed Brown    Output Parameter:
4481fe1b817SJunchao Zhang .  r1 - memory allocated
4491795a4d1SJed Brown 
450e28ce29aSPatrick Sanan    Notes:
45187497f52SBarry Smith    See `PetsMalloc1()` for more details on usage.
452390e1bf2SBarry Smith 
453390e1bf2SBarry Smith    Level: beginner
4541795a4d1SJed Brown 
455db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
4561795a4d1SJed Brown M*/
457f3fa974cSJacob Faibussowitsch #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
4581795a4d1SJed Brown 
4591795a4d1SJed Brown /*MC
46087497f52SBarry Smith    PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`
461d382aafbSBarry Smith 
462eca87e8dSBarry Smith    Synopsis:
463aaa7dc30SBarry Smith     #include <petscsys.h>
464dcca6d9dSJed Brown    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
465eca87e8dSBarry Smith 
466eca87e8dSBarry Smith    Not Collective
467eca87e8dSBarry Smith 
468d8d19677SJose E. Roman    Input Parameters:
469d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
470dcca6d9dSJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
471d382aafbSBarry Smith 
472d8d19677SJose E. Roman    Output Parameters:
473d382aafbSBarry Smith +  r1 - memory allocated in first chunk
474d382aafbSBarry Smith -  r2 - memory allocated in second chunk
475d382aafbSBarry Smith 
476d382aafbSBarry Smith    Level: developer
477d382aafbSBarry Smith 
478db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
479d382aafbSBarry Smith M*/
480f3fa974cSJacob Faibussowitsch #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))
481d382aafbSBarry Smith 
482d382aafbSBarry Smith /*MC
48387497f52SBarry Smith    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`
484d382aafbSBarry Smith 
485eca87e8dSBarry Smith    Synopsis:
486aaa7dc30SBarry Smith     #include <petscsys.h>
4871795a4d1SJed Brown    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
488eca87e8dSBarry Smith 
489eca87e8dSBarry Smith    Not Collective
490eca87e8dSBarry Smith 
491d8d19677SJose E. Roman    Input Parameters:
492d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
4931795a4d1SJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
4941795a4d1SJed Brown 
495d8d19677SJose E. Roman    Output Parameters:
4961795a4d1SJed Brown +  r1 - memory allocated in first chunk
4971795a4d1SJed Brown -  r2 - memory allocated in second chunk
4981795a4d1SJed Brown 
4991795a4d1SJed Brown    Level: developer
5001795a4d1SJed Brown 
501db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
5021795a4d1SJed Brown M*/
503f3fa974cSJacob Faibussowitsch #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))
5041795a4d1SJed Brown 
5051795a4d1SJed Brown /*MC
50687497f52SBarry Smith    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`
507d382aafbSBarry Smith 
508d382aafbSBarry Smith    Synopsis:
509aaa7dc30SBarry Smith     #include <petscsys.h>
510dcca6d9dSJed Brown    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
511d382aafbSBarry Smith 
512d382aafbSBarry Smith    Not Collective
513d382aafbSBarry Smith 
514d8d19677SJose E. Roman    Input Parameters:
515d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
516d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
517dcca6d9dSJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
518d382aafbSBarry Smith 
519d8d19677SJose E. Roman    Output Parameters:
520d382aafbSBarry Smith +  r1 - memory allocated in first chunk
521d382aafbSBarry Smith .  r2 - memory allocated in second chunk
522d382aafbSBarry Smith -  r3 - memory allocated in third chunk
523d382aafbSBarry Smith 
524d382aafbSBarry Smith    Level: developer
525d382aafbSBarry Smith 
526db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
527d382aafbSBarry Smith M*/
528f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \
529f3fa974cSJacob Faibussowitsch   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))
530d382aafbSBarry Smith 
531d382aafbSBarry Smith /*MC
53287497f52SBarry Smith    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
533d382aafbSBarry Smith 
534eca87e8dSBarry Smith    Synopsis:
535aaa7dc30SBarry Smith     #include <petscsys.h>
5361795a4d1SJed Brown    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
537eca87e8dSBarry Smith 
538eca87e8dSBarry Smith    Not Collective
539eca87e8dSBarry Smith 
540d8d19677SJose E. Roman    Input Parameters:
541d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
542d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
5431795a4d1SJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
5441795a4d1SJed Brown 
545d8d19677SJose E. Roman    Output Parameters:
5461795a4d1SJed Brown +  r1 - memory allocated in first chunk
5471795a4d1SJed Brown .  r2 - memory allocated in second chunk
5481795a4d1SJed Brown -  r3 - memory allocated in third chunk
5491795a4d1SJed Brown 
5501795a4d1SJed Brown    Level: developer
5511795a4d1SJed Brown 
552db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
5531795a4d1SJed Brown M*/
554f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \
555f3fa974cSJacob Faibussowitsch   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))
5561795a4d1SJed Brown 
5571795a4d1SJed Brown /*MC
55887497f52SBarry Smith    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`
559d382aafbSBarry Smith 
560d382aafbSBarry Smith    Synopsis:
561aaa7dc30SBarry Smith     #include <petscsys.h>
562dcca6d9dSJed Brown    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
563d382aafbSBarry Smith 
564d382aafbSBarry Smith    Not Collective
565d382aafbSBarry Smith 
566d8d19677SJose E. Roman    Input Parameters:
567d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
568d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
569d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
570dcca6d9dSJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
571d382aafbSBarry Smith 
572d8d19677SJose E. Roman    Output Parameters:
573d382aafbSBarry Smith +  r1 - memory allocated in first chunk
574d382aafbSBarry Smith .  r2 - memory allocated in second chunk
575d382aafbSBarry Smith .  r3 - memory allocated in third chunk
576d382aafbSBarry Smith -  r4 - memory allocated in fourth chunk
577d382aafbSBarry Smith 
578d382aafbSBarry Smith    Level: developer
579d382aafbSBarry Smith 
580db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
581d382aafbSBarry Smith M*/
5829371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
583f3fa974cSJacob Faibussowitsch   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))
584d382aafbSBarry Smith 
585d382aafbSBarry Smith /*MC
58687497f52SBarry Smith    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
587d382aafbSBarry Smith 
588eca87e8dSBarry Smith    Synopsis:
589aaa7dc30SBarry Smith     #include <petscsys.h>
5901795a4d1SJed Brown    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
591eca87e8dSBarry Smith 
592eca87e8dSBarry Smith    Not Collective
593eca87e8dSBarry Smith 
594e28ce29aSPatrick Sanan    Input Parameters:
595d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
596d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
597d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
5981795a4d1SJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
5991795a4d1SJed Brown 
600e28ce29aSPatrick Sanan    Output Parameters:
6011795a4d1SJed Brown +  r1 - memory allocated in first chunk
6021795a4d1SJed Brown .  r2 - memory allocated in second chunk
6031795a4d1SJed Brown .  r3 - memory allocated in third chunk
6041795a4d1SJed Brown -  r4 - memory allocated in fourth chunk
6051795a4d1SJed Brown 
6061795a4d1SJed Brown    Level: developer
6071795a4d1SJed Brown 
608db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
6091795a4d1SJed Brown M*/
6109371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
611f3fa974cSJacob Faibussowitsch   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))
6121795a4d1SJed Brown 
6131795a4d1SJed Brown /*MC
61487497f52SBarry Smith    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`
615d382aafbSBarry Smith 
616d382aafbSBarry Smith    Synopsis:
617aaa7dc30SBarry Smith     #include <petscsys.h>
618dcca6d9dSJed 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)
619d382aafbSBarry Smith 
620d382aafbSBarry Smith    Not Collective
621d382aafbSBarry Smith 
622e28ce29aSPatrick Sanan    Input Parameters:
623d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
624d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
625d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
626d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
627dcca6d9dSJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
628d382aafbSBarry Smith 
629e28ce29aSPatrick Sanan    Output Parameters:
630d382aafbSBarry Smith +  r1 - memory allocated in first chunk
631d382aafbSBarry Smith .  r2 - memory allocated in second chunk
632d382aafbSBarry Smith .  r3 - memory allocated in third chunk
633d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
634d382aafbSBarry Smith -  r5 - memory allocated in fifth chunk
635d382aafbSBarry Smith 
636d382aafbSBarry Smith    Level: developer
637d382aafbSBarry Smith 
638db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
639d382aafbSBarry Smith M*/
6409371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
641f3fa974cSJacob Faibussowitsch   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))
642d382aafbSBarry Smith 
643d382aafbSBarry Smith /*MC
64487497f52SBarry Smith    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
645d382aafbSBarry Smith 
646eca87e8dSBarry Smith    Synopsis:
647aaa7dc30SBarry Smith     #include <petscsys.h>
6481795a4d1SJed 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)
649eca87e8dSBarry Smith 
650eca87e8dSBarry Smith    Not Collective
651eca87e8dSBarry Smith 
652e28ce29aSPatrick Sanan    Input Parameters:
653d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
654d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
655d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
656d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
6571795a4d1SJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
6581795a4d1SJed Brown 
659e28ce29aSPatrick Sanan    Output Parameters:
6601795a4d1SJed Brown +  r1 - memory allocated in first chunk
6611795a4d1SJed Brown .  r2 - memory allocated in second chunk
6621795a4d1SJed Brown .  r3 - memory allocated in third chunk
6631795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
6641795a4d1SJed Brown -  r5 - memory allocated in fifth chunk
6651795a4d1SJed Brown 
6661795a4d1SJed Brown    Level: developer
6671795a4d1SJed Brown 
668db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
6691795a4d1SJed Brown M*/
6709371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
671f3fa974cSJacob Faibussowitsch   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))
672d382aafbSBarry Smith 
673d382aafbSBarry Smith /*MC
67487497f52SBarry Smith    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`
675d382aafbSBarry Smith 
676d382aafbSBarry Smith    Synopsis:
677aaa7dc30SBarry Smith     #include <petscsys.h>
678dcca6d9dSJed 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)
679d382aafbSBarry Smith 
680d382aafbSBarry Smith    Not Collective
681d382aafbSBarry Smith 
682e28ce29aSPatrick Sanan    Input Parameters:
683d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
684d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
685d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
686d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
687d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
688dcca6d9dSJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
689d382aafbSBarry Smith 
690e28ce29aSPatrick Sanan    Output Parameteasr:
691d382aafbSBarry Smith +  r1 - memory allocated in first chunk
692d382aafbSBarry Smith .  r2 - memory allocated in second chunk
693d382aafbSBarry Smith .  r3 - memory allocated in third chunk
694d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
695d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
696d382aafbSBarry Smith -  r6 - memory allocated in sixth chunk
697d382aafbSBarry Smith 
698d382aafbSBarry Smith    Level: developer
699d382aafbSBarry Smith 
700db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
701d382aafbSBarry Smith M*/
7029371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
703f3fa974cSJacob Faibussowitsch   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))
704d382aafbSBarry Smith 
705d382aafbSBarry Smith /*MC
70687497f52SBarry Smith    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
707d382aafbSBarry Smith 
708eca87e8dSBarry Smith    Synopsis:
709aaa7dc30SBarry Smith     #include <petscsys.h>
7101795a4d1SJed 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)
711eca87e8dSBarry Smith 
712eca87e8dSBarry Smith    Not Collective
713eca87e8dSBarry Smith 
714e28ce29aSPatrick Sanan    Input Parameters:
715d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
716d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
717d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
718d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
719d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
7201795a4d1SJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
7211795a4d1SJed Brown 
722e28ce29aSPatrick Sanan    Output Parameters:
7231795a4d1SJed Brown +  r1 - memory allocated in first chunk
7241795a4d1SJed Brown .  r2 - memory allocated in second chunk
7251795a4d1SJed Brown .  r3 - memory allocated in third chunk
7261795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7271795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
7281795a4d1SJed Brown -  r6 - memory allocated in sixth chunk
7291795a4d1SJed Brown 
7301795a4d1SJed Brown    Level: developer
7311795a4d1SJed Brown 
732db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
7331795a4d1SJed Brown M*/
7349371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
735f3fa974cSJacob Faibussowitsch   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))
7361795a4d1SJed Brown 
7371795a4d1SJed Brown /*MC
73887497f52SBarry Smith    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`
739d382aafbSBarry Smith 
740d382aafbSBarry Smith    Synopsis:
741aaa7dc30SBarry Smith     #include <petscsys.h>
742dcca6d9dSJed 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)
743d382aafbSBarry Smith 
744d382aafbSBarry Smith    Not Collective
745d382aafbSBarry Smith 
746e28ce29aSPatrick Sanan    Input Parameters:
747d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
748d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
749d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
750d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
751d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
752d382aafbSBarry Smith .  m6 - number of elements to allocate in 6th chunk  (may be zero)
753dcca6d9dSJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
754d382aafbSBarry Smith 
755e28ce29aSPatrick Sanan    Output Parameters:
756d382aafbSBarry Smith +  r1 - memory allocated in first chunk
757d382aafbSBarry Smith .  r2 - memory allocated in second chunk
758d382aafbSBarry Smith .  r3 - memory allocated in third chunk
759d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
760d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
761d382aafbSBarry Smith .  r6 - memory allocated in sixth chunk
762eca87e8dSBarry Smith -  r7 - memory allocated in seventh chunk
763d382aafbSBarry Smith 
764d382aafbSBarry Smith    Level: developer
765d382aafbSBarry Smith 
766db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
767d382aafbSBarry Smith M*/
7689371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
769f3fa974cSJacob Faibussowitsch   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))
770d382aafbSBarry Smith 
771d382aafbSBarry Smith /*MC
77287497f52SBarry Smith    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
7731795a4d1SJed Brown 
7741795a4d1SJed Brown    Synopsis:
775aaa7dc30SBarry Smith     #include <petscsys.h>
7761795a4d1SJed 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)
7771795a4d1SJed Brown 
7781795a4d1SJed Brown    Not Collective
7791795a4d1SJed Brown 
780e28ce29aSPatrick Sanan    Input Parameters:
7811795a4d1SJed Brown +  m1 - number of elements to allocate in 1st chunk  (may be zero)
7821795a4d1SJed Brown .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
7831795a4d1SJed Brown .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
7841795a4d1SJed Brown .  m4 - number of elements to allocate in 4th chunk  (may be zero)
7851795a4d1SJed Brown .  m5 - number of elements to allocate in 5th chunk  (may be zero)
7861795a4d1SJed Brown .  m6 - number of elements to allocate in 6th chunk  (may be zero)
7871795a4d1SJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
7881795a4d1SJed Brown 
789e28ce29aSPatrick Sanan    Output Parameters:
7901795a4d1SJed Brown +  r1 - memory allocated in first chunk
7911795a4d1SJed Brown .  r2 - memory allocated in second chunk
7921795a4d1SJed Brown .  r3 - memory allocated in third chunk
7931795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7941795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
7951795a4d1SJed Brown .  r6 - memory allocated in sixth chunk
7961795a4d1SJed Brown -  r7 - memory allocated in seventh chunk
7971795a4d1SJed Brown 
7981795a4d1SJed Brown    Level: developer
7991795a4d1SJed Brown 
800db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
8011795a4d1SJed Brown M*/
8029371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
803f3fa974cSJacob Faibussowitsch   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))
8041795a4d1SJed Brown 
8051795a4d1SJed Brown /*MC
80687497f52SBarry Smith    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`
807d382aafbSBarry Smith 
808eca87e8dSBarry Smith    Synopsis:
809aaa7dc30SBarry Smith     #include <petscsys.h>
810b00a9115SJed Brown    PetscErrorCode PetscNew(type **result)
811eca87e8dSBarry Smith 
812eca87e8dSBarry Smith    Not Collective
813eca87e8dSBarry Smith 
814d382aafbSBarry Smith    Output Parameter:
815b00a9115SJed Brown .  result - memory allocated, sized to match pointer type
816d382aafbSBarry Smith 
817d382aafbSBarry Smith    Level: beginner
818d382aafbSBarry Smith 
819fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()`
820d382aafbSBarry Smith M*/
821b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b))
822ad0619ddSBarry Smith 
8234dfa11a4SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b))
824d382aafbSBarry Smith 
825d382aafbSBarry Smith /*MC
826d382aafbSBarry Smith    PetscFree - Frees memory
827d382aafbSBarry Smith 
828eca87e8dSBarry Smith    Synopsis:
829aaa7dc30SBarry Smith     #include <petscsys.h>
830eca87e8dSBarry Smith    PetscErrorCode PetscFree(void *memory)
831eca87e8dSBarry Smith 
832eca87e8dSBarry Smith    Not Collective
833eca87e8dSBarry Smith 
834d382aafbSBarry Smith    Input Parameter:
8357f4976b7SJacob Faibussowitsch .   memory - memory to free (the pointer is ALWAYS set to NULL upon success)
836d382aafbSBarry Smith 
837d382aafbSBarry Smith    Level: beginner
838d382aafbSBarry Smith 
83949d7da52SJed Brown    Notes:
84087497f52SBarry Smith    Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.
841390e1bf2SBarry Smith 
84287497f52SBarry Smith    It is safe to call `PetscFree()` on a NULL pointer.
843d382aafbSBarry Smith 
844fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
845d382aafbSBarry Smith M*/
8463ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS)))
847d382aafbSBarry Smith 
848d382aafbSBarry Smith /*MC
84987497f52SBarry Smith    PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`
850d382aafbSBarry Smith 
851eca87e8dSBarry Smith    Synopsis:
852aaa7dc30SBarry Smith     #include <petscsys.h>
853eca87e8dSBarry Smith    PetscErrorCode PetscFree2(void *memory1,void *memory2)
854eca87e8dSBarry Smith 
855eca87e8dSBarry Smith    Not Collective
856eca87e8dSBarry Smith 
857e28ce29aSPatrick Sanan    Input Parameters:
858d382aafbSBarry Smith +   memory1 - memory to free
859d382aafbSBarry Smith -   memory2 - 2nd memory to free
860d382aafbSBarry Smith 
861d382aafbSBarry Smith    Level: developer
862d382aafbSBarry Smith 
86395452b02SPatrick Sanan    Notes:
86487497f52SBarry Smith     Memory must have been obtained with `PetscMalloc2()`
865d382aafbSBarry Smith 
866db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
867d382aafbSBarry Smith M*/
868ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))
869d382aafbSBarry Smith 
870d382aafbSBarry Smith /*MC
87187497f52SBarry Smith    PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`
872d382aafbSBarry Smith 
873eca87e8dSBarry Smith    Synopsis:
874aaa7dc30SBarry Smith     #include <petscsys.h>
875eca87e8dSBarry Smith    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
876eca87e8dSBarry Smith 
877eca87e8dSBarry Smith    Not Collective
878eca87e8dSBarry Smith 
879e28ce29aSPatrick Sanan    Input Parameters:
880d382aafbSBarry Smith +   memory1 - memory to free
881d382aafbSBarry Smith .   memory2 - 2nd memory to free
882d382aafbSBarry Smith -   memory3 - 3rd memory to free
883d382aafbSBarry Smith 
884d382aafbSBarry Smith    Level: developer
885d382aafbSBarry Smith 
88695452b02SPatrick Sanan    Notes:
88787497f52SBarry Smith     Memory must have been obtained with `PetscMalloc3()`
888d382aafbSBarry Smith 
889db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
890d382aafbSBarry Smith M*/
891ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))
892d382aafbSBarry Smith 
893d382aafbSBarry Smith /*MC
89487497f52SBarry Smith    PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`
895d382aafbSBarry Smith 
896eca87e8dSBarry Smith    Synopsis:
897aaa7dc30SBarry Smith     #include <petscsys.h>
898eca87e8dSBarry Smith    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
899eca87e8dSBarry Smith 
900eca87e8dSBarry Smith    Not Collective
901eca87e8dSBarry Smith 
902e28ce29aSPatrick Sanan    Input Parameters:
903d382aafbSBarry Smith +   m1 - memory to free
904d382aafbSBarry Smith .   m2 - 2nd memory to free
905d382aafbSBarry Smith .   m3 - 3rd memory to free
906d382aafbSBarry Smith -   m4 - 4th memory to free
907d382aafbSBarry Smith 
908d382aafbSBarry Smith    Level: developer
909d382aafbSBarry Smith 
91095452b02SPatrick Sanan    Notes:
91187497f52SBarry Smith     Memory must have been obtained with `PetscMalloc4()`
912d382aafbSBarry Smith 
913db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
914d382aafbSBarry Smith M*/
915ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))
916d382aafbSBarry Smith 
917d382aafbSBarry Smith /*MC
91887497f52SBarry Smith    PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`
919d382aafbSBarry Smith 
920eca87e8dSBarry Smith    Synopsis:
921aaa7dc30SBarry Smith     #include <petscsys.h>
922eca87e8dSBarry Smith    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
923eca87e8dSBarry Smith 
924eca87e8dSBarry Smith    Not Collective
925eca87e8dSBarry Smith 
926e28ce29aSPatrick Sanan    Input Parameters:
927d382aafbSBarry Smith +   m1 - memory to free
928d382aafbSBarry Smith .   m2 - 2nd memory to free
929d382aafbSBarry Smith .   m3 - 3rd memory to free
930d382aafbSBarry Smith .   m4 - 4th memory to free
931d382aafbSBarry Smith -   m5 - 5th memory to free
932d382aafbSBarry Smith 
933d382aafbSBarry Smith    Level: developer
934d382aafbSBarry Smith 
93595452b02SPatrick Sanan    Notes:
93687497f52SBarry Smith     Memory must have been obtained with `PetscMalloc5()`
937d382aafbSBarry Smith 
938db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
939d382aafbSBarry Smith M*/
940ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))
941d382aafbSBarry Smith 
942d382aafbSBarry Smith /*MC
94387497f52SBarry Smith    PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`
944d382aafbSBarry Smith 
945eca87e8dSBarry Smith    Synopsis:
946aaa7dc30SBarry Smith     #include <petscsys.h>
947eca87e8dSBarry Smith    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
948eca87e8dSBarry Smith 
949eca87e8dSBarry Smith    Not Collective
950eca87e8dSBarry Smith 
951e28ce29aSPatrick Sanan    Input Parameters:
952d382aafbSBarry Smith +   m1 - memory to free
953d382aafbSBarry Smith .   m2 - 2nd memory to free
954d382aafbSBarry Smith .   m3 - 3rd memory to free
955d382aafbSBarry Smith .   m4 - 4th memory to free
956d382aafbSBarry Smith .   m5 - 5th memory to free
957d382aafbSBarry Smith -   m6 - 6th memory to free
958d382aafbSBarry Smith 
959d382aafbSBarry Smith    Level: developer
960d382aafbSBarry Smith 
96195452b02SPatrick Sanan    Notes:
96287497f52SBarry Smith     Memory must have been obtained with `PetscMalloc6()`
963d382aafbSBarry Smith 
964db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
965d382aafbSBarry Smith M*/
966ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))
967d382aafbSBarry Smith 
968d382aafbSBarry Smith /*MC
96987497f52SBarry Smith    PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`
970d382aafbSBarry Smith 
971eca87e8dSBarry Smith    Synopsis:
972aaa7dc30SBarry Smith     #include <petscsys.h>
973eca87e8dSBarry Smith    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
974eca87e8dSBarry Smith 
975eca87e8dSBarry Smith    Not Collective
976eca87e8dSBarry Smith 
977e28ce29aSPatrick Sanan    Input Parameters:
978d382aafbSBarry Smith +   m1 - memory to free
979d382aafbSBarry Smith .   m2 - 2nd memory to free
980d382aafbSBarry Smith .   m3 - 3rd memory to free
981d382aafbSBarry Smith .   m4 - 4th memory to free
982d382aafbSBarry Smith .   m5 - 5th memory to free
983d382aafbSBarry Smith .   m6 - 6th memory to free
984d382aafbSBarry Smith -   m7 - 7th memory to free
985d382aafbSBarry Smith 
986d382aafbSBarry Smith    Level: developer
987d382aafbSBarry Smith 
98895452b02SPatrick Sanan    Notes:
98987497f52SBarry Smith     Memory must have been obtained with `PetscMalloc7()`
990d382aafbSBarry Smith 
991db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
992db781477SPatrick Sanan           `PetscMalloc7()`
993d382aafbSBarry Smith M*/
994ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))
995d382aafbSBarry Smith 
996ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
997ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
998071fcb05SBarry Smith PETSC_EXTERN                PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
999efca3c55SSatish Balay PETSC_EXTERN                PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
10003221ece2SMatthew G. Knepley PETSC_EXTERN                PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
1001ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
100292f119d6SBarry 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 **));
1003014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1004d382aafbSBarry Smith 
1005d382aafbSBarry Smith /*
1006c1706be6SHong 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.
1007c1706be6SHong Zhang */
1008c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1009c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
101031f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA)
101131f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
101231f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
101331f06eaaSHong Zhang #endif
101459af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
101559af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
101659af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
101759af0bd3SScott Kruger #endif
101859af0bd3SScott Kruger 
1019a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
102036763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1021a5057860SBarry Smith 
1022a5057860SBarry Smith /*
102366d669d6SBarry Smith    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1024d382aafbSBarry Smith */
1025014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
102692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1027014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1028014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1029e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1030e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
103192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
103292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
1033efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
103492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
103592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
1036608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1037608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);
1038d382aafbSBarry Smith 
1039014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
1040014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
1041014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *);
10428e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);
1043d382aafbSBarry Smith 
1044d382aafbSBarry Smith /*
1045d382aafbSBarry Smith    These are MPI operations for MPI_Allreduce() etc
1046d382aafbSBarry Smith */
1047367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1048570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1049de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM;
1050014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX;
1051014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN;
1052d9822059SBarry Smith #else
1053de272c7aSSatish Balay   #define MPIU_SUM MPI_SUM
1054d9822059SBarry Smith   #define MPIU_MAX MPI_MAX
1055d9822059SBarry Smith   #define MPIU_MIN MPI_MIN
1056d9822059SBarry Smith #endif
105762e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op         Petsc_Garbage_SetIntersectOp;
105862e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
105962e5d2d2SJDBetteridge 
1060a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16))
1061613bf2b2SPierre Jolivet /*MC
10629e517322SPierre Jolivet     MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with
10639e517322SPierre Jolivet     custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.
1064613bf2b2SPierre Jolivet 
1065613bf2b2SPierre Jolivet    Level: advanced
1066613bf2b2SPierre Jolivet 
1067613bf2b2SPierre Jolivet    Developer Note:
1068613bf2b2SPierre Jolivet    This should be unified with `MPIU_SUM`
1069613bf2b2SPierre Jolivet 
1070613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
1071613bf2b2SPierre Jolivet M*/
10729e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
1073613bf2b2SPierre Jolivet #endif
1074014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
1075d382aafbSBarry Smith 
107693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
107793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
1078eb3f98d2SBarry Smith 
1079639ff905SBarry Smith /*
1080639ff905SBarry Smith     Defines PETSc error handling.
1081639ff905SBarry Smith */
1082639ff905SBarry Smith #include <petscerror.h>
1083d382aafbSBarry Smith 
1084660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabled;                    /* code is running in the PETSc test harness CI */
1085660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
1086660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *);
1087660278c0SBarry Smith PETSC_EXTERN int         PetscCILinenumber(int);
1088660278c0SBarry Smith 
1089f3fa974cSJacob Faibussowitsch #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211)
1090014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_LARGEST_CLASSID;
1091014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_OBJECT_CLASSID;
1092014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
109381256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
109481256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);
109581256985SMatthew G. Knepley 
1096d382aafbSBarry Smith /*
1097d382aafbSBarry Smith    Routines that get memory usage information from the OS
1098d382aafbSBarry Smith */
1099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1100014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1101014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1102b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1103d382aafbSBarry Smith 
1104014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1105d382aafbSBarry Smith 
1106d382aafbSBarry Smith /*
1107d382aafbSBarry Smith    Initialization of PETSc
1108d382aafbSBarry Smith */
1109014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
1110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]);
1111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1114014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1115014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
1117014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1119d382aafbSBarry Smith 
1120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void);
1121607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
1122d382aafbSBarry Smith 
1123014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
1124014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1126014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);
1127d382aafbSBarry Smith 
1128a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *);
1129a50e088cSMatthew G. Knepley 
1130d382aafbSBarry Smith /*
1131d382aafbSBarry Smith      These are so that in extern C code we can caste function pointers to non-extern C
11322981ebdbSBarry Smith    function pointers. Since the regular C++ code expects its function pointers to be C++
1133d382aafbSBarry Smith */
1134638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void);
1135638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void);
1136638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1137d382aafbSBarry Smith 
1138d382aafbSBarry Smith /*
1139d382aafbSBarry Smith     Functions that can act on any PETSc object.
1140d382aafbSBarry Smith */
1141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
1142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
1143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
1144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
1145014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
1147014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
1148014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
1149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
1150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
1151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1154014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
1155014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
1156014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
1157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
1158bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void));
1159a20e6990SJacob Faibussowitsch #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFunction)(__VA_ARGS__))
1160014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
11620eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
11630eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
1164014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);
1165d382aafbSBarry Smith 
1166665c2dedSJed Brown #include <petscviewertypes.h>
1167639ff905SBarry Smith #include <petscoptions.h>
1168639ff905SBarry Smith 
1169608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
1170608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);
1171608c71bfSMatthew G. Knepley 
11720633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *);
11730633abcbSJed Brown 
1174c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
1175dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
1176639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
11770005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr))
11780005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void));
1179014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
1180014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
1181014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
1182014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
1183014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
1184014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1185014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1186685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
1187014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1188014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
1189013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
11904099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
1191014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1192b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1193014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1194014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1195d382aafbSBarry Smith 
1196e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
11977aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1198e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1199e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
1200e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1201e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1202e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1203e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1204e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1205e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1206e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
120715681b3cSBarry Smith 
1208ec7429eaSBarry Smith #else
12093ba16761SJacob Faibussowitsch   #define PetscSAWsBlock()                  PETSC_SUCCESS
12103ba16761SJacob Faibussowitsch   #define PetscObjectSAWsViewOff(obj)       PETSC_SUCCESS
12113ba16761SJacob Faibussowitsch   #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS
12123ba16761SJacob Faibussowitsch   #define PetscObjectSAWsBlock(obj)         PETSC_SUCCESS
12133ba16761SJacob Faibussowitsch   #define PetscObjectSAWsGrantAccess(obj)   PETSC_SUCCESS
12143ba16761SJacob Faibussowitsch   #define PetscObjectSAWsTakeAccess(obj)    PETSC_SUCCESS
12153ba16761SJacob Faibussowitsch   #define PetscStackViewSAWs()              PETSC_SUCCESS
12163ba16761SJacob Faibussowitsch   #define PetscStackSAWsViewOff()           PETSC_SUCCESS
1217e04113cfSBarry Smith   #define PetscStackSAWsTakeAccess()
1218e04113cfSBarry Smith   #define PetscStackSAWsGrantAccess()
121915681b3cSBarry Smith 
1220ec7429eaSBarry Smith #endif
1221b90c6cbeSBarry Smith 
122282b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
122382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
122482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
1225258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **);
1226258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX
1227258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **);
1228258ec3d2SMatthew G. Knepley #endif
12297d5d4d99SBarry Smith 
1230a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);
1231a64a8e02SBarry Smith 
1232dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
1233140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
1234140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
1235140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *);
1236140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
1237140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
1238140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);
1239d382aafbSBarry Smith 
1240d382aafbSBarry Smith /*
1241503cfb0cSBarry Smith     Dynamic library lists. Lists of names of routines in objects or in dynamic
1242d382aafbSBarry Smith   link libraries that will be loaded as needed.
1243d382aafbSBarry Smith */
1244a240a19fSJed Brown 
1245a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr))
1246ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFunction);
1247140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
12480e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
12491c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr))
1250ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFunction *);
125144ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
1252140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
1253140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
1254140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
12552e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
12562e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);
1257d382aafbSBarry Smith 
1258014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
1259014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
1260014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
1261014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1263014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
1264014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
1265014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1266d382aafbSBarry Smith 
1267d382aafbSBarry Smith /*
1268d382aafbSBarry Smith      Useful utility routines
1269d382aafbSBarry Smith */
1270014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
1271014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
1272d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
1273014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
1274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
1275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
127758b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
127858b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);
1279d382aafbSBarry Smith 
128064ac3b0dSPatrick Sanan /*MC
128187497f52SBarry Smith     PetscNot - negates a logical type value and returns result as a `PetscBool`
1282503cfb0cSBarry Smith 
128364ac3b0dSPatrick Sanan     Level: beginner
128464ac3b0dSPatrick Sanan 
1285a1cb98faSBarry Smith     Note:
1286a1cb98faSBarry Smith     This is useful in cases like
1287a1cb98faSBarry Smith .vb
1288a1cb98faSBarry Smith      int        *a;
1289a1cb98faSBarry Smith      PetscBool  flag = PetscNot(a)
1290a1cb98faSBarry Smith .ve
1291a1cb98faSBarry Smith      where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.
1292a1cb98faSBarry Smith 
1293a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
129464ac3b0dSPatrick Sanan M*/
1295d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1296503cfb0cSBarry Smith 
1297d382aafbSBarry Smith /*MC
1298d382aafbSBarry Smith     PetscHelpPrintf - Prints help messages.
1299d382aafbSBarry Smith 
1300cd05f99aSJacob Faibussowitsch     Not Collective, only applies on rank 0; No Fortran Support
1301cf53795eSBarry Smith 
1302d382aafbSBarry Smith    Synopsis:
1303aaa7dc30SBarry Smith     #include <petscsys.h>
1304659f7ba0SBarry Smith      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1305d382aafbSBarry Smith 
1306d382aafbSBarry Smith     Input Parameters:
1307659f7ba0SBarry Smith +  comm - the MPI communicator over which the help message is printed
1308d382aafbSBarry Smith .  format - the usual printf() format string
1309659f7ba0SBarry Smith -  args - arguments to be printed
1310d382aafbSBarry Smith 
1311d382aafbSBarry Smith    Level: developer
1312d382aafbSBarry Smith 
1313659f7ba0SBarry Smith    Note:
1314659f7ba0SBarry Smith      You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1315659f7ba0SBarry Smith 
1316659f7ba0SBarry Smith       To use, write your own function, for example,
1317659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
1318659f7ba0SBarry Smith ${
13193ba16761SJacob Faibussowitsch $ PetscFunctionReturn(PETSC_SUCCESS);
1320659f7ba0SBarry Smith $}
1321d5b43468SJose E. Roman then do the assignment
1322659f7ba0SBarry Smith $    PetscHelpPrintf = mypetschelpprintf;
132387497f52SBarry Smith    You can do the assignment before `PetscInitialize()`.
1324659f7ba0SBarry Smith 
132587497f52SBarry Smith   The default routine used is called `PetscHelpPrintfDefault()`.
1326d382aafbSBarry Smith 
1327db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`
1328d382aafbSBarry Smith M*/
13293ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1330d382aafbSBarry Smith 
1331fcfd50ebSBarry Smith /*
1332fcfd50ebSBarry Smith      Defines PETSc profiling.
1333fcfd50ebSBarry Smith */
13342c8e378dSBarry Smith #include <petsclog.h>
1335fcfd50ebSBarry Smith 
1336fcfd50ebSBarry Smith /*
1337fcfd50ebSBarry Smith       Simple PETSc parallel IO for ASCII printing
1338fcfd50ebSBarry Smith */
1339014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
1340014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
1341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
13423ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1343c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *);
13443ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
13453ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
13463ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
13471b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);
1348fcfd50ebSBarry Smith 
13493ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
13503ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
13513ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1352d382aafbSBarry Smith 
1353d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
1354d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);
1355d781fa04SBarry Smith 
1356d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN)
1357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
1358016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
135974ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1360d382aafbSBarry Smith #endif
1361d382aafbSBarry Smith 
13623ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
13633ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
13640ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
1365014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
1366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
1367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **);
1368014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);
1369d382aafbSBarry Smith 
1370014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_CONTAINER_CLASSID;
1371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **);
1372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
1373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
1374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
1375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
1376b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *);
1377d382aafbSBarry Smith 
1378d382aafbSBarry Smith /*
1379d382aafbSBarry Smith    For use in debuggers
1380d382aafbSBarry Smith */
1381014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalRank;
1382014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalSize;
1383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
1385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);
1386d382aafbSBarry Smith 
1387bbcf679cSJacob Faibussowitsch /*
1388bbcf679cSJacob Faibussowitsch     Basic memory and string operations. These are usually simple wrappers
1389bbcf679cSJacob Faibussowitsch    around the basic Unix system calls, but a few of them have additional
1390bbcf679cSJacob Faibussowitsch    functionality and/or error checking.
1391bbcf679cSJacob Faibussowitsch */
1392bbcf679cSJacob Faibussowitsch #include <petscstring.h>
1393bbcf679cSJacob Faibussowitsch 
1394a663daf8SBarry Smith #include <stddef.h>
1395d382aafbSBarry Smith #include <stdlib.h>
13966c7e564aSBarry Smith 
13974a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__)
1398d382aafbSBarry Smith   #include <xmmintrin.h>
1399d382aafbSBarry Smith #endif
1400d382aafbSBarry Smith 
1401447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
1402447bcd8fSJacob Faibussowitsch   #define PetscPrefetchBlock(a, b, c, d)
1403447bcd8fSJacob Faibussowitsch #else
1404d382aafbSBarry Smith   /*MC
1405d382aafbSBarry Smith    PetscPrefetchBlock - Prefetches a block of memory
1406d382aafbSBarry Smith 
1407eca87e8dSBarry Smith    Synopsis:
1408aaa7dc30SBarry Smith     #include <petscsys.h>
1409eca87e8dSBarry Smith     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1410eca87e8dSBarry Smith 
1411d382aafbSBarry Smith    Not Collective
1412d382aafbSBarry Smith 
1413d382aafbSBarry Smith    Input Parameters:
1414d382aafbSBarry Smith +  a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
1415d382aafbSBarry Smith .  n - number of elements to fetch
1416d382aafbSBarry Smith .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
141750d8bf02SJed Brown -  t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1418d382aafbSBarry Smith 
1419d382aafbSBarry Smith    Level: developer
1420d382aafbSBarry Smith 
1421d382aafbSBarry Smith    Notes:
1422d382aafbSBarry Smith    The last two arguments (rw and t) must be compile-time constants.
1423d382aafbSBarry Smith 
142450d8bf02SJed Brown    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
142550d8bf02SJed Brown    equivalent locality hints, but the following macros are always defined to their closest analogue.
142687497f52SBarry 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).
142787497f52SBarry 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.
142887497f52SBarry Smith .  `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1).
142987497f52SBarry Smith -  `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
1430d382aafbSBarry Smith 
1431d382aafbSBarry Smith    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1432d382aafbSBarry Smith    address).
1433d382aafbSBarry Smith 
1434d382aafbSBarry Smith M*/
14359371c9d4SSatish Balay   #define PetscPrefetchBlock(a, n, rw, t) \
14369371c9d4SSatish Balay     do { \
1437d382aafbSBarry Smith       const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
1438d382aafbSBarry Smith       for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
1439d382aafbSBarry Smith     } while (0)
1440447bcd8fSJacob Faibussowitsch #endif
1441d382aafbSBarry Smith /*
1442d382aafbSBarry Smith       Determine if some of the kernel computation routines use
1443d382aafbSBarry Smith    Fortran (rather than C) for the numerical calculations. On some machines
1444d382aafbSBarry Smith    and compilers (like complex numbers) the Fortran version of the routines
1445d382aafbSBarry Smith    is faster than the C/C++ versions. The flag --with-fortran-kernels
1446e2e64c6bSBarry Smith    should be used with ./configure to turn these on.
1447d382aafbSBarry Smith */
1448d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS)
1449d382aafbSBarry Smith 
1450d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1451d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1452d382aafbSBarry Smith   #endif
1453d382aafbSBarry Smith 
14545a11e1b2SBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM)
14555a11e1b2SBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM
1456d382aafbSBarry Smith   #endif
1457d382aafbSBarry Smith 
1458d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1459d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1460d382aafbSBarry Smith   #endif
1461d382aafbSBarry Smith 
1462d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1463d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1464d382aafbSBarry Smith   #endif
1465d382aafbSBarry Smith 
1466d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1467d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_NORM
1468d382aafbSBarry Smith   #endif
1469d382aafbSBarry Smith 
1470d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1471d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1472d382aafbSBarry Smith   #endif
1473d382aafbSBarry Smith 
1474d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1475d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1476d382aafbSBarry Smith   #endif
1477d382aafbSBarry Smith 
1478d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1479d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1480d382aafbSBarry Smith   #endif
1481d382aafbSBarry Smith 
1482d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1483d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1484d382aafbSBarry Smith   #endif
1485d382aafbSBarry Smith 
1486d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1487d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1488d382aafbSBarry Smith   #endif
1489d382aafbSBarry Smith 
1490d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1491d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MDOT
1492d382aafbSBarry Smith   #endif
1493d382aafbSBarry Smith 
1494d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1495d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1496d382aafbSBarry Smith   #endif
1497d382aafbSBarry Smith 
1498d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1499d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_AYPX
1500d382aafbSBarry Smith   #endif
1501d382aafbSBarry Smith 
1502d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1503d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1504d382aafbSBarry Smith   #endif
1505d382aafbSBarry Smith 
1506d382aafbSBarry Smith #endif
1507d382aafbSBarry Smith 
1508d382aafbSBarry Smith /*
1509d382aafbSBarry Smith     Macros for indicating code that should be compiled with a C interface,
1510d382aafbSBarry Smith    rather than a C++ interface. Any routines that are dynamically loaded
1511d382aafbSBarry Smith    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1512d382aafbSBarry Smith    mangler does not change the functions symbol name. This just hides the
1513d382aafbSBarry Smith    ugly extern "C" {} wrappers.
1514d382aafbSBarry Smith */
1515d382aafbSBarry Smith #if defined(__cplusplus)
1516d382aafbSBarry Smith   #define EXTERN_C_BEGIN extern "C" {
1517d382aafbSBarry Smith   #define EXTERN_C_END   }
1518d382aafbSBarry Smith #else
1519d382aafbSBarry Smith   #define EXTERN_C_BEGIN
1520d382aafbSBarry Smith   #define EXTERN_C_END
1521d382aafbSBarry Smith #endif
1522d382aafbSBarry Smith 
1523d382aafbSBarry Smith /* --------------------------------------------------------------------*/
1524d382aafbSBarry Smith 
1525d382aafbSBarry Smith /*MC
1526d382aafbSBarry Smith     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1527d382aafbSBarry Smith         communication
1528d382aafbSBarry Smith 
1529d382aafbSBarry Smith    Level: beginner
1530d382aafbSBarry Smith 
1531d382aafbSBarry Smith    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1532d382aafbSBarry Smith 
1533db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
1534d382aafbSBarry Smith M*/
1535d382aafbSBarry Smith 
1536d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO)
153793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
153893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
153993d501b3SJacob 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);
154093d501b3SJacob 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);
154193d501b3SJacob 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);
154293d501b3SJacob 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);
1543d382aafbSBarry Smith #endif
1544d382aafbSBarry Smith 
154561b0d812SBarry Smith /*@C
154687497f52SBarry Smith     PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an
154787497f52SBarry Smith          error if the `PetscInt` is not large enough to hold the number.
1548c73702f5SBarry Smith 
154920f4b53cSBarry Smith    Not Collective; No Fortran Support
1550c73702f5SBarry Smith 
1551c73702f5SBarry Smith    Input Parameter:
155287497f52SBarry Smith .     a - the `PetscInt64` value
1553c73702f5SBarry Smith 
1554c73702f5SBarry Smith    Output Parameter:
155587497f52SBarry Smith .     b - the resulting `PetscInt` value
1556c73702f5SBarry Smith 
1557c73702f5SBarry Smith    Level: advanced
1558c73702f5SBarry Smith 
155987497f52SBarry Smith    Notes:
156087497f52SBarry 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 ints
1561c73702f5SBarry Smith 
1562db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
1563c73702f5SBarry Smith @*/
1564d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b)
1565d71ae5a4SJacob Faibussowitsch {
1566c73702f5SBarry Smith   PetscFunctionBegin;
15673ca90d2dSJacob Faibussowitsch   *b = 0;
1568f3fa974cSJacob Faibussowitsch   // if using 64-bit indices already then this comparison is tautologically true
1569f3fa974cSJacob Faibussowitsch   PetscCheck(a < PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a);
1570f3fa974cSJacob Faibussowitsch   *b = (PetscInt)a;
15713ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1572c73702f5SBarry Smith }
1573c73702f5SBarry Smith 
1574c73702f5SBarry Smith /*@C
157587497f52SBarry Smith     PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an
157687497f52SBarry Smith          error if the `PetscInt` is not large enough to hold the number.
1577981bb840SJunchao Zhang 
1578667f096bSBarry Smith    Not Collective; No Fortran Support
1579981bb840SJunchao Zhang 
1580981bb840SJunchao Zhang    Input Parameter:
158187497f52SBarry Smith .     a - the `PetscCount` value
1582981bb840SJunchao Zhang 
1583981bb840SJunchao Zhang    Output Parameter:
158487497f52SBarry Smith .     b - the resulting `PetscInt` value
1585981bb840SJunchao Zhang 
1586981bb840SJunchao Zhang    Level: advanced
1587981bb840SJunchao Zhang 
1588667f096bSBarry Smith    Note:
1589667f096bSBarry 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 ints
1590981bb840SJunchao Zhang 
1591667f096bSBarry Smith .seealso: `PetscCount`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()`
1592981bb840SJunchao Zhang @*/
1593d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b)
1594d71ae5a4SJacob Faibussowitsch {
1595981bb840SJunchao Zhang   PetscFunctionBegin;
1596981bb840SJunchao Zhang   *b = 0;
1597f3fa974cSJacob Faibussowitsch   PetscCheck(sizeof(PetscCount) <= sizeof(PetscInt) || a <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a);
1598f3fa974cSJacob Faibussowitsch   *b = (PetscInt)a;
15993ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1600981bb840SJunchao Zhang }
1601981bb840SJunchao Zhang 
1602981bb840SJunchao Zhang /*@C
160387497f52SBarry Smith     PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an
160487497f52SBarry Smith          error if the `PetscBLASInt` is not large enough to hold the number.
160561b0d812SBarry Smith 
1606667f096bSBarry Smith    Not Collective; No Fortran Support
160761b0d812SBarry Smith 
160861b0d812SBarry Smith    Input Parameter:
160987497f52SBarry Smith .     a - the `PetscInt` value
161061b0d812SBarry Smith 
161161b0d812SBarry Smith    Output Parameter:
161287497f52SBarry Smith .     b - the resulting `PetscBLASInt` value
161361b0d812SBarry Smith 
161461b0d812SBarry Smith    Level: advanced
161561b0d812SBarry Smith 
1616667f096bSBarry Smith    Note:
1617f0b7f91aSBarry Smith    Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
16181fd49c25SBarry Smith 
1619db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()`
162061b0d812SBarry Smith @*/
1621d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b)
1622d71ae5a4SJacob Faibussowitsch {
1623c5df96a5SBarry Smith   PetscFunctionBegin;
162454c59aa7SJacob Faibussowitsch   *b = 0;
162554c59aa7SJacob Faibussowitsch   if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) {
162654c59aa7SJacob Faibussowitsch     PetscCheck(a <= PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_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", a);
162754c59aa7SJacob Faibussowitsch   }
162854c59aa7SJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
1629f3fa974cSJacob Faibussowitsch   *b = (PetscBLASInt)a;
16303ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1631c5df96a5SBarry Smith }
1632c5df96a5SBarry Smith 
163361b0d812SBarry Smith /*@C
163487497f52SBarry Smith     PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.
1635eee0c0a6SToby Isaac 
1636667f096bSBarry Smith    Not Collective; No Fortran Support
1637eee0c0a6SToby Isaac 
1638eee0c0a6SToby Isaac    Input Parameter:
163987497f52SBarry Smith .     a - the `PetscInt` value
1640eee0c0a6SToby Isaac 
1641eee0c0a6SToby Isaac    Output Parameter:
164287497f52SBarry Smith .     b - the resulting `PetscCuBLASInt` value
1643eee0c0a6SToby Isaac 
1644eee0c0a6SToby Isaac    Level: advanced
1645eee0c0a6SToby Isaac 
1646667f096bSBarry Smith    Note:
1647eee0c0a6SToby Isaac       Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
1648eee0c0a6SToby Isaac 
1649db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
1650eee0c0a6SToby Isaac @*/
1651d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b)
1652d71ae5a4SJacob Faibussowitsch {
1653eee0c0a6SToby Isaac   PetscFunctionBegin;
165454c59aa7SJacob Faibussowitsch   *b = 0;
1655f3fa974cSJacob Faibussowitsch   PetscCheck(a <= PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32 bit integers.", a);
1656f3fa974cSJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to cuBLAS routine", a);
1657f3fa974cSJacob Faibussowitsch   *b = (PetscCuBLASInt)a;
16583ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1659eee0c0a6SToby Isaac }
1660eee0c0a6SToby Isaac 
1661eee0c0a6SToby Isaac /*@C
166247d993e7Ssuyashtn     PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.
166347d993e7Ssuyashtn 
1664667f096bSBarry Smith    Not Collective; No Fortran Support
166547d993e7Ssuyashtn 
166647d993e7Ssuyashtn    Input Parameter:
166747d993e7Ssuyashtn .     a - the `PetscInt` value
166847d993e7Ssuyashtn 
166947d993e7Ssuyashtn    Output Parameter:
167047d993e7Ssuyashtn .     b - the resulting `PetscHipBLASInt` value
167147d993e7Ssuyashtn 
167247d993e7Ssuyashtn    Level: advanced
167347d993e7Ssuyashtn 
1674667f096bSBarry Smith    Note:
167547d993e7Ssuyashtn       Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs
167647d993e7Ssuyashtn 
167747d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
167847d993e7Ssuyashtn @*/
167947d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b)
168047d993e7Ssuyashtn {
168147d993e7Ssuyashtn   PetscFunctionBegin;
168247d993e7Ssuyashtn   *b = 0;
1683f3fa974cSJacob Faibussowitsch   PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32 bit integers.", a);
1684f3fa974cSJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to hipBLAS routine", a);
1685f3fa974cSJacob Faibussowitsch   *b = (PetscHipBLASInt)a;
16863ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
168747d993e7Ssuyashtn }
168847d993e7Ssuyashtn 
168947d993e7Ssuyashtn /*@C
1690667f096bSBarry Smith     PetscMPIIntCast - casts a `PetscInt` (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an
1691667f096bSBarry Smith          error if the `PetscMPIInt` is not large enough to hold the number.
169261b0d812SBarry Smith 
1693667f096bSBarry Smith    Not Collective; No Fortran Support
169461b0d812SBarry Smith 
169561b0d812SBarry Smith    Input Parameter:
169687497f52SBarry Smith .     a - the `PetscInt` value
169761b0d812SBarry Smith 
169861b0d812SBarry Smith    Output Parameter:
169987497f52SBarry Smith .     b - the resulting `PetscMPIInt` value
170061b0d812SBarry Smith 
170161b0d812SBarry Smith    Level: advanced
170261b0d812SBarry Smith 
1703db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
170461b0d812SBarry Smith @*/
1705d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b)
1706d71ae5a4SJacob Faibussowitsch {
17074dc2109aSBarry Smith   PetscFunctionBegin;
170854c59aa7SJacob Faibussowitsch   *b = 0;
1709f3fa974cSJacob Faibussowitsch   PetscCheck(a <= PETSC_MPI_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for MPI buffer length. Maximum supported value is %d", a, PETSC_MPI_INT_MAX);
1710f3fa974cSJacob Faibussowitsch   *b = (PetscMPIInt)a;
17113ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
17124dc2109aSBarry Smith }
17134dc2109aSBarry Smith 
1714f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b)))
17152f18eb33SBarry Smith 
17162f18eb33SBarry Smith /*@C
1717f3fa974cSJacob Faibussowitsch   PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive
1718f3fa974cSJacob Faibussowitsch   `PetscInt` and truncates the value to slightly less than the maximal possible value.
17192f18eb33SBarry Smith 
172020f4b53cSBarry Smith   Not Collective; No Fortran Support
17212f18eb33SBarry Smith 
1722d8d19677SJose E. Roman   Input Parameters:
1723f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value
1724f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value
17252f18eb33SBarry Smith 
1726667f096bSBarry Smith   Level: advanced
1727667f096bSBarry Smith 
1728f3fa974cSJacob Faibussowitsch   Notes:
1729f3fa974cSJacob Faibussowitsch   Returns the result as a `PetscInt` value.
17302f18eb33SBarry Smith 
1731f3fa974cSJacob Faibussowitsch   Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`.
1732667f096bSBarry Smith 
1733f3fa974cSJacob Faibussowitsch   Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate
1734f3fa974cSJacob Faibussowitsch   to fit a `PetscInt`.
1735667f096bSBarry Smith 
1736f3fa974cSJacob Faibussowitsch   Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an
1737f3fa974cSJacob Faibussowitsch   error if the result will not fit in a `PetscInt`.
17382f18eb33SBarry Smith 
1739667f096bSBarry Smith   Developers Notes:
1740f3fa974cSJacob Faibussowitsch   We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but
1741f3fa974cSJacob Faibussowitsch   requires many more checks.
17422f18eb33SBarry Smith 
1743f3fa974cSJacob Faibussowitsch   This is used where we compute approximate sizes for workspace and need to insure the
1744f3fa974cSJacob Faibussowitsch   workspace is index-able.
17451fd49c25SBarry Smith 
1746f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
17472f18eb33SBarry Smith @*/
1748d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
1749d71ae5a4SJacob Faibussowitsch {
17505f80ce2aSJacob Faibussowitsch   PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
17512f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
17522f18eb33SBarry Smith   return (PetscInt)r;
17532f18eb33SBarry Smith }
17542f18eb33SBarry Smith 
17552f18eb33SBarry Smith /*@C
17562f18eb33SBarry Smith 
175787497f52SBarry Smith    PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
17582f18eb33SBarry Smith 
1759667f096bSBarry Smith    Not Collective; No Fortran Support
17602f18eb33SBarry Smith 
1761d8d19677SJose E. Roman    Input Parameters:
17622f18eb33SBarry Smith +     a - the PetscInt value
17632f18eb33SBarry Smith -     b - the second value
17642f18eb33SBarry Smith 
1765390e1bf2SBarry Smith    Returns:
176687497f52SBarry Smith       the result as a `PetscInt` value
17672f18eb33SBarry Smith 
1768667f096bSBarry Smith    Level: advanced
1769667f096bSBarry Smith 
1770667f096bSBarry Smith    Notes:
177187497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
1772667f096bSBarry Smith 
177387497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
1774667f096bSBarry Smith 
177587497f52SBarry 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`
17762f18eb33SBarry Smith 
1777667f096bSBarry Smith    Developers Notes:
177887497f52SBarry Smith    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
17792f18eb33SBarry Smith 
17802f18eb33SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
17812f18eb33SBarry Smith 
1782667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`,
1783667f096bSBarry Smith           `PetscIntSumTruncate()`
17842f18eb33SBarry Smith @*/
1785d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
1786d71ae5a4SJacob Faibussowitsch {
17875f80ce2aSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
17882f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
17892f18eb33SBarry Smith   return (PetscInt)r;
17902f18eb33SBarry Smith }
17912f18eb33SBarry Smith 
1792f91af8c7SBarry Smith /*@C
1793f91af8c7SBarry Smith 
179487497f52SBarry Smith    PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
1795f91af8c7SBarry Smith 
1796667f096bSBarry Smith    Not Collective; No Fortran Support
1797f91af8c7SBarry Smith 
1798d8d19677SJose E. Roman    Input Parameters:
179987497f52SBarry Smith +     a - the `PetscInt` value
1800f91af8c7SBarry Smith -     b - the second value
1801f91af8c7SBarry Smith 
1802390e1bf2SBarry Smith    Returns:
180387497f52SBarry Smith      the result as a `PetscInt` value
1804f91af8c7SBarry Smith 
1805667f096bSBarry Smith    Level: advanced
1806667f096bSBarry Smith 
1807667f096bSBarry Smith    Notes:
180887497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
1809667f096bSBarry Smith 
181087497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
1811667f096bSBarry Smith 
181287497f52SBarry 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`
1813f91af8c7SBarry Smith 
1814667f096bSBarry Smith    Developers Notes:
1815f91af8c7SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
1816f91af8c7SBarry Smith 
1817db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
1818f91af8c7SBarry Smith @*/
1819d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
1820d71ae5a4SJacob Faibussowitsch {
18215f80ce2aSJacob Faibussowitsch   PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b);
1822f91af8c7SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
1823f91af8c7SBarry Smith   return (PetscInt)r;
1824f91af8c7SBarry Smith }
1825f91af8c7SBarry Smith 
18262f18eb33SBarry Smith /*@C
18272f18eb33SBarry Smith 
182887497f52SBarry Smith    PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.
18292f18eb33SBarry Smith 
1830667f096bSBarry Smith    Not Collective; No Fortran Support
18312f18eb33SBarry Smith 
1832d8d19677SJose E. Roman    Input Parameters:
183387497f52SBarry Smith +     a - the `PetscInt` value
18342f18eb33SBarry Smith -     b - the second value
18352f18eb33SBarry Smith 
1836d8d19677SJose E. Roman    Output Parameter:
183787497f52SBarry 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
18382f18eb33SBarry Smith 
1839667f096bSBarry Smith    Level: advanced
18402f18eb33SBarry Smith 
1841667f096bSBarry Smith    Notes:
1842667f096bSBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`
1843667f096bSBarry Smith 
1844667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
1845f5f57ec0SBarry Smith 
184687497f52SBarry Smith    Developers Note:
184787497f52SBarry Smith    We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks.
18482f18eb33SBarry Smith 
1849db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()`
18502f18eb33SBarry Smith @*/
1851d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
1852d71ae5a4SJacob Faibussowitsch {
1853f3fa974cSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
18542f18eb33SBarry Smith 
18552f18eb33SBarry Smith   PetscFunctionBegin;
1856c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
1857f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
1858f3fa974cSJacob Faibussowitsch     PetscCheck(r <= PETSC_MAX_INT, 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);
1859f3fa974cSJacob Faibussowitsch   }
18603ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1861f91af8c7SBarry Smith }
1862f91af8c7SBarry Smith 
1863f91af8c7SBarry Smith /*@C
1864f91af8c7SBarry Smith 
186587497f52SBarry Smith    PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.
1866f91af8c7SBarry Smith 
1867667f096bSBarry Smith    Not Collective; No Fortran Support
1868f91af8c7SBarry Smith 
1869d8d19677SJose E. Roman    Input Parameters:
187087497f52SBarry Smith +     a - the `PetscInt` value
1871f91af8c7SBarry Smith -     b - the second value
1872f91af8c7SBarry Smith 
1873d8d19677SJose E. Roman    Output Parameter:
187487497f52SBarry 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
1875f91af8c7SBarry Smith 
1876f91af8c7SBarry Smith    Level: advanced
1877f91af8c7SBarry Smith 
1878667f096bSBarry Smith    Notes:
1879667f096bSBarry Smith    Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64`
1880667f096bSBarry Smith 
1881667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
1882667f096bSBarry Smith 
1883db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
1884f91af8c7SBarry Smith @*/
1885d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
1886d71ae5a4SJacob Faibussowitsch {
1887f3fa974cSJacob Faibussowitsch   PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b);
1888f91af8c7SBarry Smith 
1889f91af8c7SBarry Smith   PetscFunctionBegin;
1890c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
1891f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
1892f3fa974cSJacob Faibussowitsch     PetscCheck(r <= PETSC_MAX_INT, 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);
1893f3fa974cSJacob Faibussowitsch   }
18943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
18952f18eb33SBarry Smith }
1896c5df96a5SBarry Smith 
1897d382aafbSBarry Smith /*
18982981ebdbSBarry Smith      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
1899d382aafbSBarry Smith */
1900d382aafbSBarry Smith #if defined(hz)
1901d382aafbSBarry Smith   #undef hz
1902d382aafbSBarry Smith #endif
1903d382aafbSBarry Smith 
190415a5570dSLisandro Dalcin #include <limits.h>
190515a5570dSLisandro Dalcin 
190615a5570dSLisandro Dalcin /* The number of bits in a byte */
190715a5570dSLisandro Dalcin 
190815a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT
190915a5570dSLisandro Dalcin 
1910d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H)
1911d382aafbSBarry Smith   #include <sys/types.h>
1912d382aafbSBarry Smith #endif
1913d382aafbSBarry Smith 
1914d382aafbSBarry Smith /*MC
1915d382aafbSBarry Smith 
191666d79e26SBarry 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++
191766d79e26SBarry Smith                     and Fortran compilers when petscsys.h is included.
191866d79e26SBarry Smith 
19196274ba02SSatish Balay     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/petscverson.html</A>
192066d79e26SBarry Smith 
192166d79e26SBarry 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)
192266d79e26SBarry Smith 
192366d79e26SBarry 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
192466d79e26SBarry Smith     where only a change in the major version number (x) indicates a change in the API.
192566d79e26SBarry Smith 
192666d79e26SBarry 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
192766d79e26SBarry Smith 
192866d79e26SBarry 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),
192966d79e26SBarry 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
193066d79e26SBarry Smith     version number (x.y.z).
193166d79e26SBarry Smith 
193287497f52SBarry Smith     `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)
193366d79e26SBarry Smith 
193487497f52SBarry Smith     `PETSC_VERSION_DATE` is the date the x.y.z version was released
193566d79e26SBarry Smith 
193687497f52SBarry Smith     `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww
193766d79e26SBarry Smith 
193887497f52SBarry Smith     `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository
193966d79e26SBarry Smith 
194087497f52SBarry Smith     `PETSC_VERSION_()` is deprecated and will eventually be removed.
194166d79e26SBarry Smith 
1942cbc12506SBarry Smith     Level: intermediate
194366d79e26SBarry Smith M*/
194466d79e26SBarry Smith 
1945014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
1946014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
1947014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
1948014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
1949014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
1950014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
195127710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
19525f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);
1953d382aafbSBarry Smith 
19546a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *);
195562e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *);
19566a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *);
19576a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *);
1958014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]);
195962e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]);
196062e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]);
1961ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]);
196222ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
1963b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
1964014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
1965f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
196660e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *);
1967d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *);
1968014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
1969014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
1970014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]);
1971981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
19726c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]);
1973981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
197417d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]);
197517d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
1976014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]);
19775569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]);
1978014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]);
197917df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *);
1980014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]);
198139f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
1982014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
1983745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
198439f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *);
1985014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
1986014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
1987014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **);
19886c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **);
19896c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **);
1990e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **);
1991ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
1992ce605777SToby Isaac 
19934d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
1994676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
1995676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
1996676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
19974d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
1998676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
1999676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
2000676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2001676f2a66SJacob Faibussowitsch 
2002014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2003014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);
2004d382aafbSBarry Smith 
200576bdecfbSBarry Smith /*J
2006d382aafbSBarry Smith     PetscRandomType - String with the name of a PETSc randomizer
2007d382aafbSBarry Smith 
2008d382aafbSBarry Smith    Level: beginner
2009d382aafbSBarry Smith 
2010667f096bSBarry Smith    Note:
201187497f52SBarry Smith    To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
201225ccb61fSToby Isaac    with the option --download-sprng or --download-random123
2013d382aafbSBarry Smith 
2014db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
201576bdecfbSBarry Smith J*/
201619fd82e9SBarry Smith typedef const char *PetscRandomType;
2017d382aafbSBarry Smith #define PETSCRAND      "rand"
2018d382aafbSBarry Smith #define PETSCRAND48    "rand48"
2019d382aafbSBarry Smith #define PETSCSPRNG     "sprng"
2020c5e4d11fSDmitry Karpeev #define PETSCRANDER48  "rander48"
202125ccb61fSToby Isaac #define PETSCRANDOM123 "random123"
2022808ba619SStefano Zampini #define PETSCCURAND    "curand"
2023d382aafbSBarry Smith 
2024d382aafbSBarry Smith /* Logging support */
2025014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2026d382aafbSBarry Smith 
2027607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
2028d382aafbSBarry Smith 
2029d382aafbSBarry Smith /* Dynamic creation and loading functions */
2030140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList;
2031d382aafbSBarry Smith 
2032bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
203319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
2034014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
203519fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
2036fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
2037014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);
2038d382aafbSBarry Smith 
2039014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
2040014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
2041014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
2042808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
2043808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
2044014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
2045014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
2046014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long);
2047014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *);
2048014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2049014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);
2050d382aafbSBarry Smith 
2051014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
2052014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
2053014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
2054014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
2055014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
2056014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
2057014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
205897540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
20598a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
206097540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2061d382aafbSBarry Smith 
2062d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void)
2063d71ae5a4SJacob Faibussowitsch {
20649371c9d4SSatish Balay   long _petsc_v = 1;
20659371c9d4SSatish Balay   return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
20669371c9d4SSatish Balay }
206730815ce0SLisandro Dalcin 
20689860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType);
20699860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
2070f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType);
2071f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
2072014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
2073014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2074014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
2075014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
2076014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
2077014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
2078014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
2079c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER)
2080e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
2081c891a504SStefano Zampini #endif
2082d382aafbSBarry Smith 
2083014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
2084014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
2085014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt);
2086d382aafbSBarry Smith 
2087014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2088014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
2089014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2090014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
2091014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2092014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
20932a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2094d382aafbSBarry Smith 
2095014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
2096014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **);
2097014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **);
2098014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
2099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
210093d501b3SJacob Faibussowitsch 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);
210193d501b3SJacob 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);
210293d501b3SJacob 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);
2103d382aafbSBarry Smith 
21046145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
21056145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);
21066145cd65SJed Brown 
2107014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *);
2108d382aafbSBarry Smith 
2109ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2110ce94432eSBarry Smith 
2111d382aafbSBarry Smith struct _n_PetscSubcomm {
2112d382aafbSBarry Smith   MPI_Comm         parent;    /* parent communicator */
2113d382aafbSBarry Smith   MPI_Comm         dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2114306c2d5bSBarry Smith   MPI_Comm         child;     /* the sub-communicator */
211545487dadSJed Brown   PetscMPIInt      n;         /* num of subcommunicators under the parent communicator */
211645487dadSJed Brown   PetscMPIInt      color;     /* color of processors belong to this communicator */
2117708d824cSJed Brown   PetscMPIInt     *subsize;   /* size of subcommunicator[color] */
211845487dadSJed Brown   PetscSubcommType type;
2119e5acf8a4SHong Zhang   char            *subcommprefix;
2120d382aafbSBarry Smith };
2121d382aafbSBarry Smith 
2122d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
2123d71ae5a4SJacob Faibussowitsch {
21249371c9d4SSatish Balay   return scomm->parent;
21259371c9d4SSatish Balay }
2126d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
2127d71ae5a4SJacob Faibussowitsch {
21289371c9d4SSatish Balay   return scomm->child;
21299371c9d4SSatish Balay }
2130d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
2131d71ae5a4SJacob Faibussowitsch {
21329371c9d4SSatish Balay   return scomm->dupparent;
21339371c9d4SSatish Balay }
2134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
2135014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
2136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
2137014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
213865d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
2139053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
2140f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2141e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
2142a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
2143a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
2144a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);
2145d382aafbSBarry Smith 
21469962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
21479962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
21489962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
21499962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
21509962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
21519962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
21529962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
21539962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);
21549962606eSBarry Smith 
21555e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
21565f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
21575f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
21585f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
21595f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);
21605e71baefSBarry Smith 
2161a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2162a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
2163a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
2164a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
2165a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2166a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2167a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2168a32e93adSJunchao Zhang 
216913e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *);
21700f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
217113e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *);
2172137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
2173137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
2174137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
217513e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *);
217613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t);
21770f453b92SJed Brown 
2178471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2179471ecdacSJed Brown  * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2180471ecdacSJed Brown  * possible. */
2181d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot)
2182d71ae5a4SJacob Faibussowitsch {
21839371c9d4SSatish Balay   return PetscSegBufferGet(seg, count, (void **)slot);
21849371c9d4SSatish Balay }
2185d382aafbSBarry Smith 
21869de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
21879de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
21889de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
21899de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);
21909de0f6ecSBarry Smith 
2191ace2fbaeSBarry Smith #include <stdarg.h>
2192ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
2193ace2fbaeSBarry Smith PETSC_EXTERN                PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);
2194ace2fbaeSBarry Smith 
2195268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2196fbfcfee5SBarry Smith 
21971f817a21SBarry Smith /*@C
21981f817a21SBarry Smith       PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
21991f817a21SBarry Smith 
2200667f096bSBarry Smith      Not Collective; No Fortran Support
22011f817a21SBarry Smith 
22021f817a21SBarry Smith      Input Parameters:
220335cb6cd3SPierre Jolivet +      cite - the bibtex item, formatted to displayed on multiple lines nicely
220487497f52SBarry Smith -      set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation
22051f817a21SBarry Smith 
2206667f096bSBarry Smith      Options Database Key:
22073c7db156SBarry Smith .     -citations [filename]   - print out the bibtex entries for the given computation
22083c7db156SBarry Smith 
2209850545d0SSatish Balay      Level: intermediate
22101f817a21SBarry Smith @*/
2211d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
2212d71ae5a4SJacob Faibussowitsch {
2213dff31646SBarry Smith   size_t len;
2214dff31646SBarry Smith   char  *vstring;
2215dff31646SBarry Smith 
22161f817a21SBarry Smith   PetscFunctionBegin;
22173ba16761SJacob Faibussowitsch   if (set && *set) PetscFunctionReturn(PETSC_SUCCESS);
22189566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(cit, &len));
22199566063dSJacob Faibussowitsch   PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring));
22209566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy(vstring, cit, len));
2221dff31646SBarry Smith   if (set) *set = PETSC_TRUE;
22223ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2223dff31646SBarry Smith }
2224dff31646SBarry Smith 
2225d8174014SToby Isaac PETSC_EXTERN                PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c);
2226fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
2227fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
2228f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);
2229fe278a28SBarry Smith 
2230f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
2231f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
2232b967cddfSBarry Smith 
22339f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
22349f4d3c52SBarry Smith 
223504102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *);
2236763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *);
2237dff31646SBarry Smith 
223868e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
22395dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);
2240d382aafbSBarry Smith 
2241b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG)
2242d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str)
2243d71ae5a4SJacob Faibussowitsch {
2244df05ca09SBarry Smith   unsigned int c, hash = 5381;
2245df05ca09SBarry Smith 
2246503e1a2cSLisandro Dalcin   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2247df05ca09SBarry Smith   return hash;
2248df05ca09SBarry Smith }
224977a5e07dSBarry Smith 
225077a5e07dSBarry Smith   /*MC
225187497f52SBarry Smith    MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the
225287497f52SBarry Smith                     same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
225387497f52SBarry Smith                     resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.
225477a5e07dSBarry Smith 
2255d083f849SBarry Smith    Collective
225677a5e07dSBarry Smith 
225777a5e07dSBarry Smith    Synopsis:
225877a5e07dSBarry Smith      #include <petscsys.h>
225977a5e07dSBarry Smith      PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
226077a5e07dSBarry Smith 
226177a5e07dSBarry Smith    Input Parameters:
2262df05ca09SBarry Smith +  a - pointer to the input data to be reduced
2263df05ca09SBarry Smith .  c - the number of MPI data items in a and b
226487497f52SBarry Smith .  d - the MPI datatype, for example `MPI_INT`
226587497f52SBarry Smith .  e - the MPI operation, for example `MPI_SUM`
2266df05ca09SBarry Smith -  fcomm - the MPI communicator on which the operation occurs
226777a5e07dSBarry Smith 
226877a5e07dSBarry Smith    Output Parameter:
2269df05ca09SBarry Smith .  b - the reduced values
227077a5e07dSBarry Smith 
2271667f096bSBarry Smith    Level: developer
2272667f096bSBarry Smith 
2273e28ce29aSPatrick Sanan    Notes:
227487497f52SBarry Smith      In optimized mode this directly calls `MPI_Allreduce()`
227577a5e07dSBarry Smith 
2276df05ca09SBarry Smith      This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void.
2277df05ca09SBarry Smith 
227887497f52SBarry Smith      The error code this returns should be checked with `PetscCall()` even though it looks like an MPI function because it always returns PETSc error codes
2279df05ca09SBarry Smith 
2280db781477SPatrick Sanan .seealso: `MPI_Allreduce()`
228177a5e07dSBarry Smith M*/
22823ba16761SJacob Faibussowitsch   // clang-format off
22839371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \
22843ba16761SJacob Faibussowitsch   PetscMacroReturnStandard( \
22853ba16761SJacob Faibussowitsch     PetscMPIInt a_b1[6], a_b2[6]; \
22863ba16761SJacob Faibussowitsch     int _mpiu_allreduce_c_int = (int)(c); \
22873ba16761SJacob Faibussowitsch     a_b1[0] = -(PetscMPIInt)__LINE__; \
22883ba16761SJacob Faibussowitsch     a_b1[1] = -a_b1[0]; \
22893ba16761SJacob Faibussowitsch     a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \
22903ba16761SJacob Faibussowitsch     a_b1[3] = -a_b1[2]; \
22913ba16761SJacob Faibussowitsch     a_b1[4] = -(PetscMPIInt)(c); \
22923ba16761SJacob Faibussowitsch     a_b1[5] = -a_b1[4]; \
22933ba16761SJacob Faibussowitsch     \
22943ba16761SJacob Faibussowitsch     PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \
22953ba16761SJacob Faibussowitsch     PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); \
22963ba16761SJacob Faibussowitsch     PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); \
22973ba16761SJacob Faibussowitsch     PetscCheck(-a_b2[4] == a_b2[5], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); \
22983ba16761SJacob Faibussowitsch     PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)));)
22993ba16761SJacob Faibussowitsch // clang-format on
2300b2566f29SBarry Smith #else
2301f3fa974cSJacob Faibussowitsch   #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm))))
2302b2566f29SBarry Smith #endif
2303b2566f29SBarry Smith 
2304b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
23058198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
23068198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
23072f065d89SBarry Smith #endif
23088198064fSBarry Smith 
2309cd88fca5SStefano Zampini /* this is a vile hack */
2310cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI)
23119371c9d4SSatish 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)
2312cd88fca5SStefano Zampini     #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
2313cd88fca5SStefano Zampini   #endif
2314961fb248SStefano Zampini #endif
2315cd88fca5SStefano Zampini 
231612801b39SBarry Smith /*
231760fbe2beSVaclav Hapla     List of external packages and queries on it
231860fbe2beSVaclav Hapla */
231960fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);
232060fbe2beSVaclav Hapla 
2321f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */
2322f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
2323f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
2324f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void);
2325d382aafbSBarry Smith #endif
2326