xref: /petsc/include/petscsys.h (revision 4bf303fab8706fca5c4c2515917737579b84f96a)
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 
1197de69702SBarry Smith /* MSMPI on 32-bit Microsoft 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 
13238b83642SBarry Smith    Note:
13387497f52SBarry Smith    In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.
134e28ce29aSPatrick Sanan 
13538b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `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 
14638b83642SBarry Smith /*MC
14738b83642SBarry Smith    MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount`
14838b83642SBarry Smith 
14938b83642SBarry Smith    Level: beginner
15038b83642SBarry Smith 
15138b83642SBarry Smith    Note:
15238b83642SBarry Smith    In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value.
15338b83642SBarry Smith 
15438b83642SBarry Smith   Developer Note:
15538b83642SBarry Smith   It seems MPI_AINT is unsigned so this may be the wrong choice here since `PetscCount` is signed
15638b83642SBarry Smith 
15738b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
15838b83642SBarry Smith M*/
15938b83642SBarry Smith #define MPIU_COUNT MPI_AINT
16038b83642SBarry Smith 
161503cfb0cSBarry Smith /*
162503cfb0cSBarry Smith     For the rare cases when one needs to send a size_t object with MPI
163503cfb0cSBarry Smith */
16493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t);
165d382aafbSBarry Smith 
166d382aafbSBarry Smith /*
167d382aafbSBarry Smith       You can use PETSC_STDOUT as a replacement of stdout. You can also change
168d382aafbSBarry Smith     the value of PETSC_STDOUT to redirect all standard output elsewhere
169d382aafbSBarry Smith */
170014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT;
171d382aafbSBarry Smith 
172d382aafbSBarry Smith /*
173d382aafbSBarry Smith       You can use PETSC_STDERR as a replacement of stderr. You can also change
174d382aafbSBarry Smith     the value of PETSC_STDERR to redirect all standard error elsewhere
175d382aafbSBarry Smith */
176014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR;
177d382aafbSBarry Smith 
178d382aafbSBarry Smith /*
179dc07da0dSStefano Zampini   Handle inclusion when using clang compiler with CUDA support
180dc07da0dSStefano Zampini   __float128 is not available for the device
181dc07da0dSStefano Zampini */
182dc07da0dSStefano Zampini #if defined(__clang__) && defined(__CUDA_ARCH__)
183dc07da0dSStefano Zampini   #define PETSC_SKIP_REAL___FLOAT128
184dc07da0dSStefano Zampini #endif
185dc07da0dSStefano Zampini 
186dc07da0dSStefano Zampini /*
187d382aafbSBarry Smith     Declare extern C stuff after including external header files
188d382aafbSBarry Smith */
189d382aafbSBarry Smith 
1906edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
1918b49ba18SBarry Smith /*
192390e1bf2SBarry Smith     Defines elementary mathematics functions and constants.
1938b49ba18SBarry Smith */
1948b49ba18SBarry Smith #include <petscmath.h>
1958b49ba18SBarry Smith 
196d382aafbSBarry Smith /*MC
197667f096bSBarry Smith     PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument
198d382aafbSBarry Smith 
199d382aafbSBarry Smith    Level: beginner
200d382aafbSBarry Smith 
201e28ce29aSPatrick Sanan    Note:
202667f096bSBarry Smith    Accepted by many PETSc functions to not set a parameter and instead use a default value
203d382aafbSBarry Smith 
20487497f52SBarry Smith    Fortran Note:
205667f096bSBarry Smith    Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc
206d382aafbSBarry Smith 
207db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE`
208d382aafbSBarry Smith M*/
209f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR
210edd03b47SJacob Faibussowitsch #define PETSC_NULL   PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR
211c528d872SBarry Smith 
212d382aafbSBarry Smith /*MC
213557d4da8SBarry Smith     PETSC_DECIDE - standard way of passing in integer or floating point parameter
214557d4da8SBarry Smith        where you wish PETSc to use the default.
215557d4da8SBarry Smith 
216557d4da8SBarry Smith    Level: beginner
217557d4da8SBarry Smith 
218db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`
219557d4da8SBarry Smith M*/
220557d4da8SBarry Smith 
221557d4da8SBarry Smith /*MC
222d382aafbSBarry Smith     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
223d382aafbSBarry Smith        where you wish PETSc to compute the required value.
224d382aafbSBarry Smith 
225d382aafbSBarry Smith    Level: beginner
226d382aafbSBarry Smith 
227e28ce29aSPatrick Sanan    Developer Note:
22887497f52SBarry Smith    I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for
22987497f52SBarry Smith      some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value.
230557d4da8SBarry Smith 
231db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`
232d382aafbSBarry Smith M*/
233d382aafbSBarry Smith 
234d382aafbSBarry Smith /*MC
235557d4da8SBarry Smith     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
236557d4da8SBarry Smith        where you wish PETSc to use the default.
237557d4da8SBarry Smith 
238557d4da8SBarry Smith    Level: beginner
239557d4da8SBarry Smith 
24087497f52SBarry Smith    Fortran Note:
24187497f52SBarry Smith    You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`.
242557d4da8SBarry Smith 
243db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`
244557d4da8SBarry Smith M*/
24505c2f48cSJacob Faibussowitsch 
24605c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */
24705c2f48cSJacob Faibussowitsch #define PETSC_DECIDE    (-1)
24805c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE
24905c2f48cSJacob Faibussowitsch #define PETSC_DEFAULT   (-2)
250557d4da8SBarry Smith 
251557d4da8SBarry Smith /*MC
25287497f52SBarry Smith     PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents
253ea8fe74dSBarry Smith            all the processes that PETSc knows about.
254d382aafbSBarry Smith 
255d382aafbSBarry Smith    Level: beginner
256d382aafbSBarry Smith 
257e28ce29aSPatrick Sanan    Notes:
25887497f52SBarry Smith    By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to
25987497f52SBarry Smith           run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller)
26087497f52SBarry Smith           communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling
26187497f52SBarry Smith           PetscInitialize(), but after `MPI_Init()` has been called.
262a990b902SBarry Smith 
26387497f52SBarry Smith           The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()`
264a990b902SBarry Smith           is called because it may not have a valid value yet.
265d382aafbSBarry Smith 
266db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF`
267d382aafbSBarry Smith M*/
268014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
269d382aafbSBarry Smith 
270d382aafbSBarry Smith /*MC
27187497f52SBarry Smith     PETSC_COMM_SELF - This is always `MPI_COMM_SELF`
272d382aafbSBarry Smith 
273d382aafbSBarry Smith    Level: beginner
274d382aafbSBarry Smith 
275e28ce29aSPatrick Sanan    Notes:
27616a05f60SBarry Smith    Do not USE/access or set this variable before `PetscInitialize()` has been called.
277a990b902SBarry Smith 
278db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`
279d382aafbSBarry Smith M*/
280d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF
281d382aafbSBarry Smith 
2826de5d289SStefano Zampini /*MC
2836de5d289SStefano Zampini     PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes
28487497f52SBarry Smith            MPI with `MPI_Init_thread()`.
2856de5d289SStefano Zampini 
2866de5d289SStefano Zampini    Level: beginner
2876de5d289SStefano Zampini 
2886de5d289SStefano Zampini    Notes:
28987497f52SBarry Smith    By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`.
2906de5d289SStefano Zampini 
291db781477SPatrick Sanan .seealso: `PetscInitialize()`
2926de5d289SStefano Zampini M*/
2936de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
2946de5d289SStefano Zampini 
295d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI;
2968ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
297014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled;
298014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled;
2994cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
300d382aafbSBarry Smith 
301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
303014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
30457f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
30557f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);
306d382aafbSBarry Smith 
30759e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
30859e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
30959e55d94SJunchao Zhang #endif
31059e55d94SJunchao Zhang 
31171438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM)
31271438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscBeganNvshmem;
31371438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
31471438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
31571438e86SJunchao Zhang #endif
31671438e86SJunchao Zhang 
317540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL)
318540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
319540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
320540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
321540e20f2SPierre Jolivet #endif
322540e20f2SPierre Jolivet 
323d382aafbSBarry Smith /*MC
32487497f52SBarry Smith    PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this
325d382aafbSBarry Smith 
326eca87e8dSBarry Smith    Synopsis:
327aaa7dc30SBarry Smith     #include <petscsys.h>
328eca87e8dSBarry Smith    PetscErrorCode PetscMalloc(size_t m,void **result)
329eca87e8dSBarry Smith 
330eca87e8dSBarry Smith    Not Collective
331eca87e8dSBarry Smith 
332d382aafbSBarry Smith    Input Parameter:
333d382aafbSBarry Smith .  m - number of bytes to allocate
334d382aafbSBarry Smith 
335d382aafbSBarry Smith    Output Parameter:
336d382aafbSBarry Smith .  result - memory allocated
337d382aafbSBarry Smith 
338d382aafbSBarry Smith    Level: beginner
339d382aafbSBarry Smith 
34049d7da52SJed Brown    Notes:
34149d7da52SJed Brown    Memory is always allocated at least double aligned
342d382aafbSBarry Smith 
34316a05f60SBarry Smith    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`.
344d382aafbSBarry Smith 
345db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`
346d382aafbSBarry Smith M*/
347071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
348d382aafbSBarry Smith 
349d382aafbSBarry Smith /*MC
350d5b43468SJose E. Roman    PetscRealloc - Reallocates memory
3513221ece2SMatthew G. Knepley 
3523221ece2SMatthew G. Knepley    Synopsis:
3533221ece2SMatthew G. Knepley     #include <petscsys.h>
3543221ece2SMatthew G. Knepley    PetscErrorCode PetscRealloc(size_t m,void **result)
3553221ece2SMatthew G. Knepley 
3563221ece2SMatthew G. Knepley    Not Collective
3573221ece2SMatthew G. Knepley 
3583221ece2SMatthew G. Knepley    Input Parameters:
3593221ece2SMatthew G. Knepley +  m - number of bytes to allocate
36092f119d6SBarry Smith -  result - previous memory
3613221ece2SMatthew G. Knepley 
3623221ece2SMatthew G. Knepley    Output Parameter:
3633221ece2SMatthew G. Knepley .  result - new memory allocated
3643221ece2SMatthew G. Knepley 
3653221ece2SMatthew G. Knepley    Level: developer
3663221ece2SMatthew G. Knepley 
3673221ece2SMatthew G. Knepley    Notes:
3683221ece2SMatthew G. Knepley    Memory is always allocated at least double aligned
3693221ece2SMatthew G. Knepley 
370db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
3713221ece2SMatthew G. Knepley M*/
3723221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
3733221ece2SMatthew G. Knepley 
3743221ece2SMatthew G. Knepley /*MC
37587497f52SBarry Smith    PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment
376d382aafbSBarry Smith 
377d382aafbSBarry Smith    Synopsis:
378aaa7dc30SBarry Smith     #include <petscsys.h>
379d382aafbSBarry Smith    void *PetscAddrAlign(void *addr)
380d382aafbSBarry Smith 
381eca87e8dSBarry Smith    Not Collective
382eca87e8dSBarry Smith 
3832fe279fdSBarry Smith    Input Parameter:
384eca87e8dSBarry Smith .  addr - address to align (any pointer type)
385eca87e8dSBarry Smith 
386d382aafbSBarry Smith    Level: developer
387d382aafbSBarry Smith 
388db781477SPatrick Sanan .seealso: `PetscMallocAlign()`
389d382aafbSBarry Smith M*/
390f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)))
391d382aafbSBarry Smith 
392d382aafbSBarry Smith /*MC
39387497f52SBarry Smith    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`
3948f51dc47SJunchao Zhang 
3958f51dc47SJunchao Zhang    Synopsis:
3968f51dc47SJunchao Zhang     #include <petscsys.h>
3978f51dc47SJunchao Zhang    PetscErrorCode PetscCalloc(size_t m,void **result)
3988f51dc47SJunchao Zhang 
3998f51dc47SJunchao Zhang    Not Collective
4008f51dc47SJunchao Zhang 
4018f51dc47SJunchao Zhang    Input Parameter:
4028f51dc47SJunchao Zhang .  m - number of bytes to allocate
4038f51dc47SJunchao Zhang 
4048f51dc47SJunchao Zhang    Output Parameter:
4058f51dc47SJunchao Zhang .  result - memory allocated
4068f51dc47SJunchao Zhang 
4078f51dc47SJunchao Zhang    Level: beginner
4088f51dc47SJunchao Zhang 
4098f51dc47SJunchao Zhang    Notes:
4108f51dc47SJunchao Zhang    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
4118f51dc47SJunchao Zhang 
41216a05f60SBarry Smith    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`.
4138f51dc47SJunchao Zhang 
414db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`
4158f51dc47SJunchao Zhang M*/
416f3fa974cSJacob Faibussowitsch #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result))
4178f51dc47SJunchao Zhang 
4188f51dc47SJunchao Zhang /*MC
41987497f52SBarry Smith    PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`
420d382aafbSBarry Smith 
421eca87e8dSBarry Smith    Synopsis:
422aaa7dc30SBarry Smith     #include <petscsys.h>
423785e854fSJed Brown    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
424785e854fSJed Brown 
425785e854fSJed Brown    Not Collective
426785e854fSJed Brown 
427785e854fSJed Brown    Input Parameter:
428390e1bf2SBarry Smith .  m1 - number of elements to allocate  (may be zero)
429785e854fSJed Brown 
430785e854fSJed Brown    Output Parameter:
4311fe1b817SJunchao Zhang .  r1 - memory allocated
432785e854fSJed Brown 
43316a05f60SBarry Smith    Level: beginner
43416a05f60SBarry Smith 
435e28ce29aSPatrick Sanan    Note:
436e28ce29aSPatrick Sanan    This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not
43787497f52SBarry Smith          multiply the number of elements requested by the `sizeof()` the type. For example use
43816a05f60SBarry Smith .vb
43916a05f60SBarry Smith   PetscInt *id;
44016a05f60SBarry Smith   PetscMalloc1(10,&id);
44116a05f60SBarry Smith .ve
442390e1bf2SBarry Smith        not
44316a05f60SBarry Smith .vb
44416a05f60SBarry Smith   PetscInt *id;
44516a05f60SBarry Smith   PetscMalloc1(10*sizeof(PetscInt),&id);
44616a05f60SBarry Smith .ve
447390e1bf2SBarry Smith 
44887497f52SBarry Smith         Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.
449390e1bf2SBarry Smith 
450db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
451785e854fSJed Brown M*/
452f3fa974cSJacob Faibussowitsch #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
453785e854fSJed Brown 
454785e854fSJed Brown /*MC
45587497f52SBarry Smith    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`
4561795a4d1SJed Brown 
4571795a4d1SJed Brown    Synopsis:
458aaa7dc30SBarry Smith     #include <petscsys.h>
4591795a4d1SJed Brown    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
4601795a4d1SJed Brown 
4611795a4d1SJed Brown    Not Collective
4621795a4d1SJed Brown 
4631795a4d1SJed Brown    Input Parameter:
4641795a4d1SJed Brown .  m1 - number of elements to allocate in 1st chunk  (may be zero)
4651795a4d1SJed Brown 
4661795a4d1SJed Brown    Output Parameter:
4671fe1b817SJunchao Zhang .  r1 - memory allocated
4681795a4d1SJed Brown 
46916a05f60SBarry Smith    Level: beginner
47016a05f60SBarry Smith 
471e28ce29aSPatrick Sanan    Notes:
47287497f52SBarry Smith    See `PetsMalloc1()` for more details on usage.
473390e1bf2SBarry Smith 
474db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
4751795a4d1SJed Brown M*/
476f3fa974cSJacob Faibussowitsch #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
4771795a4d1SJed Brown 
4781795a4d1SJed Brown /*MC
47987497f52SBarry Smith    PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`
480d382aafbSBarry Smith 
481eca87e8dSBarry Smith    Synopsis:
482aaa7dc30SBarry Smith     #include <petscsys.h>
483dcca6d9dSJed Brown    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
484eca87e8dSBarry Smith 
485eca87e8dSBarry Smith    Not Collective
486eca87e8dSBarry Smith 
487d8d19677SJose E. Roman    Input Parameters:
488d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
489dcca6d9dSJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
490d382aafbSBarry Smith 
491d8d19677SJose E. Roman    Output Parameters:
492d382aafbSBarry Smith +  r1 - memory allocated in first chunk
493d382aafbSBarry Smith -  r2 - memory allocated in second chunk
494d382aafbSBarry Smith 
495d382aafbSBarry Smith    Level: developer
496d382aafbSBarry Smith 
497db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
498d382aafbSBarry Smith M*/
499f3fa974cSJacob 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))
500d382aafbSBarry Smith 
501d382aafbSBarry Smith /*MC
50287497f52SBarry Smith    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`
503d382aafbSBarry Smith 
504eca87e8dSBarry Smith    Synopsis:
505aaa7dc30SBarry Smith     #include <petscsys.h>
5061795a4d1SJed Brown    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
507eca87e8dSBarry Smith 
508eca87e8dSBarry Smith    Not Collective
509eca87e8dSBarry Smith 
510d8d19677SJose E. Roman    Input Parameters:
511d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
5121795a4d1SJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
5131795a4d1SJed Brown 
514d8d19677SJose E. Roman    Output Parameters:
5151795a4d1SJed Brown +  r1 - memory allocated in first chunk
5161795a4d1SJed Brown -  r2 - memory allocated in second chunk
5171795a4d1SJed Brown 
5181795a4d1SJed Brown    Level: developer
5191795a4d1SJed Brown 
520db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
5211795a4d1SJed Brown M*/
522f3fa974cSJacob 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))
5231795a4d1SJed Brown 
5241795a4d1SJed Brown /*MC
52587497f52SBarry Smith    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`
526d382aafbSBarry Smith 
527d382aafbSBarry Smith    Synopsis:
528aaa7dc30SBarry Smith     #include <petscsys.h>
529dcca6d9dSJed Brown    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
530d382aafbSBarry Smith 
531d382aafbSBarry Smith    Not Collective
532d382aafbSBarry Smith 
533d8d19677SJose E. Roman    Input Parameters:
534d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
535d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
536dcca6d9dSJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
537d382aafbSBarry Smith 
538d8d19677SJose E. Roman    Output Parameters:
539d382aafbSBarry Smith +  r1 - memory allocated in first chunk
540d382aafbSBarry Smith .  r2 - memory allocated in second chunk
541d382aafbSBarry Smith -  r3 - memory allocated in third chunk
542d382aafbSBarry Smith 
543d382aafbSBarry Smith    Level: developer
544d382aafbSBarry Smith 
545db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
546d382aafbSBarry Smith M*/
547f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \
548f3fa974cSJacob 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))
549d382aafbSBarry Smith 
550d382aafbSBarry Smith /*MC
55187497f52SBarry Smith    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
552d382aafbSBarry Smith 
553eca87e8dSBarry Smith    Synopsis:
554aaa7dc30SBarry Smith     #include <petscsys.h>
5551795a4d1SJed Brown    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
556eca87e8dSBarry Smith 
557eca87e8dSBarry Smith    Not Collective
558eca87e8dSBarry Smith 
559d8d19677SJose E. Roman    Input Parameters:
560d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
561d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
5621795a4d1SJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
5631795a4d1SJed Brown 
564d8d19677SJose E. Roman    Output Parameters:
5651795a4d1SJed Brown +  r1 - memory allocated in first chunk
5661795a4d1SJed Brown .  r2 - memory allocated in second chunk
5671795a4d1SJed Brown -  r3 - memory allocated in third chunk
5681795a4d1SJed Brown 
5691795a4d1SJed Brown    Level: developer
5701795a4d1SJed Brown 
571db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
5721795a4d1SJed Brown M*/
573f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \
574f3fa974cSJacob 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))
5751795a4d1SJed Brown 
5761795a4d1SJed Brown /*MC
57787497f52SBarry Smith    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`
578d382aafbSBarry Smith 
579d382aafbSBarry Smith    Synopsis:
580aaa7dc30SBarry Smith     #include <petscsys.h>
581dcca6d9dSJed Brown    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
582d382aafbSBarry Smith 
583d382aafbSBarry Smith    Not Collective
584d382aafbSBarry Smith 
585d8d19677SJose E. Roman    Input Parameters:
586d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
587d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
588d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
589dcca6d9dSJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
590d382aafbSBarry Smith 
591d8d19677SJose E. Roman    Output Parameters:
592d382aafbSBarry Smith +  r1 - memory allocated in first chunk
593d382aafbSBarry Smith .  r2 - memory allocated in second chunk
594d382aafbSBarry Smith .  r3 - memory allocated in third chunk
595d382aafbSBarry Smith -  r4 - memory allocated in fourth chunk
596d382aafbSBarry Smith 
597d382aafbSBarry Smith    Level: developer
598d382aafbSBarry Smith 
599db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
600d382aafbSBarry Smith M*/
6019371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
602f3fa974cSJacob 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))
603d382aafbSBarry Smith 
604d382aafbSBarry Smith /*MC
60587497f52SBarry Smith    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
606d382aafbSBarry Smith 
607eca87e8dSBarry Smith    Synopsis:
608aaa7dc30SBarry Smith     #include <petscsys.h>
6091795a4d1SJed Brown    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
610eca87e8dSBarry Smith 
611eca87e8dSBarry Smith    Not Collective
612eca87e8dSBarry Smith 
613e28ce29aSPatrick Sanan    Input Parameters:
614d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
615d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
616d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
6171795a4d1SJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
6181795a4d1SJed Brown 
619e28ce29aSPatrick Sanan    Output Parameters:
6201795a4d1SJed Brown +  r1 - memory allocated in first chunk
6211795a4d1SJed Brown .  r2 - memory allocated in second chunk
6221795a4d1SJed Brown .  r3 - memory allocated in third chunk
6231795a4d1SJed Brown -  r4 - memory allocated in fourth chunk
6241795a4d1SJed Brown 
6251795a4d1SJed Brown    Level: developer
6261795a4d1SJed Brown 
627db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
6281795a4d1SJed Brown M*/
6299371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
630f3fa974cSJacob 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))
6311795a4d1SJed Brown 
6321795a4d1SJed Brown /*MC
63387497f52SBarry Smith    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`
634d382aafbSBarry Smith 
635d382aafbSBarry Smith    Synopsis:
636aaa7dc30SBarry Smith     #include <petscsys.h>
637dcca6d9dSJed 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)
638d382aafbSBarry Smith 
639d382aafbSBarry Smith    Not Collective
640d382aafbSBarry Smith 
641e28ce29aSPatrick Sanan    Input Parameters:
642d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
643d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
644d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
645d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
646dcca6d9dSJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
647d382aafbSBarry Smith 
648e28ce29aSPatrick Sanan    Output Parameters:
649d382aafbSBarry Smith +  r1 - memory allocated in first chunk
650d382aafbSBarry Smith .  r2 - memory allocated in second chunk
651d382aafbSBarry Smith .  r3 - memory allocated in third chunk
652d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
653d382aafbSBarry Smith -  r5 - memory allocated in fifth chunk
654d382aafbSBarry Smith 
655d382aafbSBarry Smith    Level: developer
656d382aafbSBarry Smith 
657db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
658d382aafbSBarry Smith M*/
6599371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
660f3fa974cSJacob 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))
661d382aafbSBarry Smith 
662d382aafbSBarry Smith /*MC
66387497f52SBarry Smith    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
664d382aafbSBarry Smith 
665eca87e8dSBarry Smith    Synopsis:
666aaa7dc30SBarry Smith     #include <petscsys.h>
6671795a4d1SJed 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)
668eca87e8dSBarry Smith 
669eca87e8dSBarry Smith    Not Collective
670eca87e8dSBarry Smith 
671e28ce29aSPatrick Sanan    Input Parameters:
672d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
673d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
674d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
675d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
6761795a4d1SJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
6771795a4d1SJed Brown 
678e28ce29aSPatrick Sanan    Output Parameters:
6791795a4d1SJed Brown +  r1 - memory allocated in first chunk
6801795a4d1SJed Brown .  r2 - memory allocated in second chunk
6811795a4d1SJed Brown .  r3 - memory allocated in third chunk
6821795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
6831795a4d1SJed Brown -  r5 - memory allocated in fifth chunk
6841795a4d1SJed Brown 
6851795a4d1SJed Brown    Level: developer
6861795a4d1SJed Brown 
687db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
6881795a4d1SJed Brown M*/
6899371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
690f3fa974cSJacob 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))
691d382aafbSBarry Smith 
692d382aafbSBarry Smith /*MC
69387497f52SBarry Smith    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`
694d382aafbSBarry Smith 
695d382aafbSBarry Smith    Synopsis:
696aaa7dc30SBarry Smith     #include <petscsys.h>
697dcca6d9dSJed 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)
698d382aafbSBarry Smith 
699d382aafbSBarry Smith    Not Collective
700d382aafbSBarry Smith 
701e28ce29aSPatrick Sanan    Input Parameters:
702d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
703d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
704d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
705d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
706d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
707dcca6d9dSJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
708d382aafbSBarry Smith 
709e28ce29aSPatrick Sanan    Output Parameteasr:
710d382aafbSBarry Smith +  r1 - memory allocated in first chunk
711d382aafbSBarry Smith .  r2 - memory allocated in second chunk
712d382aafbSBarry Smith .  r3 - memory allocated in third chunk
713d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
714d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
715d382aafbSBarry Smith -  r6 - memory allocated in sixth chunk
716d382aafbSBarry Smith 
717d382aafbSBarry Smith    Level: developer
718d382aafbSBarry Smith 
719db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
720d382aafbSBarry Smith M*/
7219371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
722f3fa974cSJacob 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))
723d382aafbSBarry Smith 
724d382aafbSBarry Smith /*MC
72587497f52SBarry Smith    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
726d382aafbSBarry Smith 
727eca87e8dSBarry Smith    Synopsis:
728aaa7dc30SBarry Smith     #include <petscsys.h>
7291795a4d1SJed 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)
730eca87e8dSBarry Smith 
731eca87e8dSBarry Smith    Not Collective
732eca87e8dSBarry Smith 
733e28ce29aSPatrick Sanan    Input Parameters:
734d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
735d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
736d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
737d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
738d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
7391795a4d1SJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
7401795a4d1SJed Brown 
741e28ce29aSPatrick Sanan    Output Parameters:
7421795a4d1SJed Brown +  r1 - memory allocated in first chunk
7431795a4d1SJed Brown .  r2 - memory allocated in second chunk
7441795a4d1SJed Brown .  r3 - memory allocated in third chunk
7451795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7461795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
7471795a4d1SJed Brown -  r6 - memory allocated in sixth chunk
7481795a4d1SJed Brown 
7491795a4d1SJed Brown    Level: developer
7501795a4d1SJed Brown 
751db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
7521795a4d1SJed Brown M*/
7539371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
754f3fa974cSJacob 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))
7551795a4d1SJed Brown 
7561795a4d1SJed Brown /*MC
75787497f52SBarry Smith    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`
758d382aafbSBarry Smith 
759d382aafbSBarry Smith    Synopsis:
760aaa7dc30SBarry Smith     #include <petscsys.h>
761dcca6d9dSJed 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)
762d382aafbSBarry Smith 
763d382aafbSBarry Smith    Not Collective
764d382aafbSBarry Smith 
765e28ce29aSPatrick Sanan    Input Parameters:
766d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
767d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
768d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
769d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
770d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
771d382aafbSBarry Smith .  m6 - number of elements to allocate in 6th chunk  (may be zero)
772dcca6d9dSJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
773d382aafbSBarry Smith 
774e28ce29aSPatrick Sanan    Output Parameters:
775d382aafbSBarry Smith +  r1 - memory allocated in first chunk
776d382aafbSBarry Smith .  r2 - memory allocated in second chunk
777d382aafbSBarry Smith .  r3 - memory allocated in third chunk
778d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
779d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
780d382aafbSBarry Smith .  r6 - memory allocated in sixth chunk
781eca87e8dSBarry Smith -  r7 - memory allocated in seventh chunk
782d382aafbSBarry Smith 
783d382aafbSBarry Smith    Level: developer
784d382aafbSBarry Smith 
785db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
786d382aafbSBarry Smith M*/
7879371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
788f3fa974cSJacob 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))
789d382aafbSBarry Smith 
790d382aafbSBarry Smith /*MC
79187497f52SBarry Smith    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
7921795a4d1SJed Brown 
7931795a4d1SJed Brown    Synopsis:
794aaa7dc30SBarry Smith     #include <petscsys.h>
7951795a4d1SJed 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)
7961795a4d1SJed Brown 
7971795a4d1SJed Brown    Not Collective
7981795a4d1SJed Brown 
799e28ce29aSPatrick Sanan    Input Parameters:
8001795a4d1SJed Brown +  m1 - number of elements to allocate in 1st chunk  (may be zero)
8011795a4d1SJed Brown .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
8021795a4d1SJed Brown .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
8031795a4d1SJed Brown .  m4 - number of elements to allocate in 4th chunk  (may be zero)
8041795a4d1SJed Brown .  m5 - number of elements to allocate in 5th chunk  (may be zero)
8051795a4d1SJed Brown .  m6 - number of elements to allocate in 6th chunk  (may be zero)
8061795a4d1SJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
8071795a4d1SJed Brown 
808e28ce29aSPatrick Sanan    Output Parameters:
8091795a4d1SJed Brown +  r1 - memory allocated in first chunk
8101795a4d1SJed Brown .  r2 - memory allocated in second chunk
8111795a4d1SJed Brown .  r3 - memory allocated in third chunk
8121795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
8131795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
8141795a4d1SJed Brown .  r6 - memory allocated in sixth chunk
8151795a4d1SJed Brown -  r7 - memory allocated in seventh chunk
8161795a4d1SJed Brown 
8171795a4d1SJed Brown    Level: developer
8181795a4d1SJed Brown 
819db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
8201795a4d1SJed Brown M*/
8219371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
822f3fa974cSJacob 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))
8231795a4d1SJed Brown 
8241795a4d1SJed Brown /*MC
82587497f52SBarry Smith    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`
826d382aafbSBarry Smith 
827eca87e8dSBarry Smith    Synopsis:
828aaa7dc30SBarry Smith     #include <petscsys.h>
829b00a9115SJed Brown    PetscErrorCode PetscNew(type **result)
830eca87e8dSBarry Smith 
831eca87e8dSBarry Smith    Not Collective
832eca87e8dSBarry Smith 
833d382aafbSBarry Smith    Output Parameter:
834b00a9115SJed Brown .  result - memory allocated, sized to match pointer type
835d382aafbSBarry Smith 
836d382aafbSBarry Smith    Level: beginner
837d382aafbSBarry Smith 
838fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()`
839d382aafbSBarry Smith M*/
840b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b))
841ad0619ddSBarry Smith 
842edd03b47SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew((b))
843d382aafbSBarry Smith 
844d382aafbSBarry Smith /*MC
845d382aafbSBarry Smith    PetscFree - Frees memory
846d382aafbSBarry Smith 
847eca87e8dSBarry Smith    Synopsis:
848aaa7dc30SBarry Smith     #include <petscsys.h>
849eca87e8dSBarry Smith    PetscErrorCode PetscFree(void *memory)
850eca87e8dSBarry Smith 
851eca87e8dSBarry Smith    Not Collective
852eca87e8dSBarry Smith 
853d382aafbSBarry Smith    Input Parameter:
85416a05f60SBarry Smith .   memory - memory to free (the pointer is ALWAYS set to `NULL` upon success)
855d382aafbSBarry Smith 
856d382aafbSBarry Smith    Level: beginner
857d382aafbSBarry Smith 
85816a05f60SBarry Smith    Note:
85987497f52SBarry Smith    Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.
860390e1bf2SBarry Smith 
86116a05f60SBarry Smith    It is safe to call `PetscFree()` on a `NULL` pointer.
862d382aafbSBarry Smith 
863fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
864d382aafbSBarry Smith M*/
8653ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS)))
866d382aafbSBarry Smith 
867d382aafbSBarry Smith /*MC
86887497f52SBarry Smith    PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`
869d382aafbSBarry Smith 
870eca87e8dSBarry Smith    Synopsis:
871aaa7dc30SBarry Smith     #include <petscsys.h>
872eca87e8dSBarry Smith    PetscErrorCode PetscFree2(void *memory1,void *memory2)
873eca87e8dSBarry Smith 
874eca87e8dSBarry Smith    Not Collective
875eca87e8dSBarry Smith 
876e28ce29aSPatrick Sanan    Input Parameters:
877d382aafbSBarry Smith +   memory1 - memory to free
878d382aafbSBarry Smith -   memory2 - 2nd memory to free
879d382aafbSBarry Smith 
880d382aafbSBarry Smith    Level: developer
881d382aafbSBarry Smith 
88216a05f60SBarry Smith    Note:
88387497f52SBarry Smith     Memory must have been obtained with `PetscMalloc2()`
884d382aafbSBarry Smith 
885db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
886d382aafbSBarry Smith M*/
887ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))
888d382aafbSBarry Smith 
889d382aafbSBarry Smith /*MC
89087497f52SBarry Smith    PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`
891d382aafbSBarry Smith 
892eca87e8dSBarry Smith    Synopsis:
893aaa7dc30SBarry Smith     #include <petscsys.h>
894eca87e8dSBarry Smith    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
895eca87e8dSBarry Smith 
896eca87e8dSBarry Smith    Not Collective
897eca87e8dSBarry Smith 
898e28ce29aSPatrick Sanan    Input Parameters:
899d382aafbSBarry Smith +   memory1 - memory to free
900d382aafbSBarry Smith .   memory2 - 2nd memory to free
901d382aafbSBarry Smith -   memory3 - 3rd memory to free
902d382aafbSBarry Smith 
903d382aafbSBarry Smith    Level: developer
904d382aafbSBarry Smith 
90516a05f60SBarry Smith    Note:
90687497f52SBarry Smith     Memory must have been obtained with `PetscMalloc3()`
907d382aafbSBarry Smith 
908db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
909d382aafbSBarry Smith M*/
910ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))
911d382aafbSBarry Smith 
912d382aafbSBarry Smith /*MC
91387497f52SBarry Smith    PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`
914d382aafbSBarry Smith 
915eca87e8dSBarry Smith    Synopsis:
916aaa7dc30SBarry Smith     #include <petscsys.h>
917eca87e8dSBarry Smith    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
918eca87e8dSBarry Smith 
919eca87e8dSBarry Smith    Not Collective
920eca87e8dSBarry Smith 
921e28ce29aSPatrick Sanan    Input Parameters:
922d382aafbSBarry Smith +   m1 - memory to free
923d382aafbSBarry Smith .   m2 - 2nd memory to free
924d382aafbSBarry Smith .   m3 - 3rd memory to free
925d382aafbSBarry Smith -   m4 - 4th memory to free
926d382aafbSBarry Smith 
927d382aafbSBarry Smith    Level: developer
928d382aafbSBarry Smith 
92916a05f60SBarry Smith    Note:
93087497f52SBarry Smith     Memory must have been obtained with `PetscMalloc4()`
931d382aafbSBarry Smith 
932db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
933d382aafbSBarry Smith M*/
934ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))
935d382aafbSBarry Smith 
936d382aafbSBarry Smith /*MC
93787497f52SBarry Smith    PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`
938d382aafbSBarry Smith 
939eca87e8dSBarry Smith    Synopsis:
940aaa7dc30SBarry Smith     #include <petscsys.h>
941eca87e8dSBarry Smith    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
942eca87e8dSBarry Smith 
943eca87e8dSBarry Smith    Not Collective
944eca87e8dSBarry Smith 
945e28ce29aSPatrick Sanan    Input Parameters:
946d382aafbSBarry Smith +   m1 - memory to free
947d382aafbSBarry Smith .   m2 - 2nd memory to free
948d382aafbSBarry Smith .   m3 - 3rd memory to free
949d382aafbSBarry Smith .   m4 - 4th memory to free
950d382aafbSBarry Smith -   m5 - 5th memory to free
951d382aafbSBarry Smith 
952d382aafbSBarry Smith    Level: developer
953d382aafbSBarry Smith 
95416a05f60SBarry Smith    Note:
95587497f52SBarry Smith     Memory must have been obtained with `PetscMalloc5()`
956d382aafbSBarry Smith 
957db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
958d382aafbSBarry Smith M*/
959ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))
960d382aafbSBarry Smith 
961d382aafbSBarry Smith /*MC
96287497f52SBarry Smith    PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`
963d382aafbSBarry Smith 
964eca87e8dSBarry Smith    Synopsis:
965aaa7dc30SBarry Smith     #include <petscsys.h>
966eca87e8dSBarry Smith    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
967eca87e8dSBarry Smith 
968eca87e8dSBarry Smith    Not Collective
969eca87e8dSBarry Smith 
970e28ce29aSPatrick Sanan    Input Parameters:
971d382aafbSBarry Smith +   m1 - memory to free
972d382aafbSBarry Smith .   m2 - 2nd memory to free
973d382aafbSBarry Smith .   m3 - 3rd memory to free
974d382aafbSBarry Smith .   m4 - 4th memory to free
975d382aafbSBarry Smith .   m5 - 5th memory to free
976d382aafbSBarry Smith -   m6 - 6th memory to free
977d382aafbSBarry Smith 
978d382aafbSBarry Smith    Level: developer
979d382aafbSBarry Smith 
98016a05f60SBarry Smith    Note:
98187497f52SBarry Smith     Memory must have been obtained with `PetscMalloc6()`
982d382aafbSBarry Smith 
983db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
984d382aafbSBarry Smith M*/
985ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))
986d382aafbSBarry Smith 
987d382aafbSBarry Smith /*MC
98887497f52SBarry Smith    PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`
989d382aafbSBarry Smith 
990eca87e8dSBarry Smith    Synopsis:
991aaa7dc30SBarry Smith     #include <petscsys.h>
992eca87e8dSBarry Smith    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
993eca87e8dSBarry Smith 
994eca87e8dSBarry Smith    Not Collective
995eca87e8dSBarry Smith 
996e28ce29aSPatrick Sanan    Input Parameters:
997d382aafbSBarry Smith +   m1 - memory to free
998d382aafbSBarry Smith .   m2 - 2nd memory to free
999d382aafbSBarry Smith .   m3 - 3rd memory to free
1000d382aafbSBarry Smith .   m4 - 4th memory to free
1001d382aafbSBarry Smith .   m5 - 5th memory to free
1002d382aafbSBarry Smith .   m6 - 6th memory to free
1003d382aafbSBarry Smith -   m7 - 7th memory to free
1004d382aafbSBarry Smith 
1005d382aafbSBarry Smith    Level: developer
1006d382aafbSBarry Smith 
100716a05f60SBarry Smith    Note:
100887497f52SBarry Smith     Memory must have been obtained with `PetscMalloc7()`
1009d382aafbSBarry Smith 
1010db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
1011db781477SPatrick Sanan           `PetscMalloc7()`
1012d382aafbSBarry Smith M*/
1013ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))
1014d382aafbSBarry Smith 
1015ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
1016ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
1017071fcb05SBarry Smith PETSC_EXTERN                PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
1018efca3c55SSatish Balay PETSC_EXTERN                PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
10193221ece2SMatthew G. Knepley PETSC_EXTERN                PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
1020ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
102192f119d6SBarry 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 **));
1022014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1023d382aafbSBarry Smith 
1024d382aafbSBarry Smith /*
1025c1706be6SHong 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.
1026c1706be6SHong Zhang */
1027c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1028c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
102931f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA)
103031f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
103131f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
103231f06eaaSHong Zhang #endif
103359af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
103459af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
103559af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
103659af0bd3SScott Kruger #endif
103759af0bd3SScott Kruger 
1038a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
103936763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1040a5057860SBarry Smith 
1041a5057860SBarry Smith /*
104266d669d6SBarry Smith    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1043d382aafbSBarry Smith */
1044014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
104592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1046014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1047014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1048e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1049e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
105092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
105192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
1052efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
105392f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
105492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
1055608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1056608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);
1057d382aafbSBarry Smith 
1058014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
1059014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
1060014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *);
10618e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);
1062d382aafbSBarry Smith 
1063d382aafbSBarry Smith /*
1064d382aafbSBarry Smith    These are MPI operations for MPI_Allreduce() etc
1065d382aafbSBarry Smith */
1066367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1067570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1068de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM;
1069014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX;
1070014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN;
1071d9822059SBarry Smith #else
1072de272c7aSSatish Balay   #define MPIU_SUM MPI_SUM
1073d9822059SBarry Smith   #define MPIU_MAX MPI_MAX
1074d9822059SBarry Smith   #define MPIU_MIN MPI_MIN
1075d9822059SBarry Smith #endif
107662e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op         Petsc_Garbage_SetIntersectOp;
107762e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
107862e5d2d2SJDBetteridge 
1079a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16))
1080613bf2b2SPierre Jolivet /*MC
108116a05f60SBarry Smith     MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with
108216a05f60SBarry Smith     custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.
1083613bf2b2SPierre Jolivet 
1084613bf2b2SPierre Jolivet    Level: advanced
1085613bf2b2SPierre Jolivet 
1086613bf2b2SPierre Jolivet    Developer Note:
1087613bf2b2SPierre Jolivet    This should be unified with `MPIU_SUM`
1088613bf2b2SPierre Jolivet 
1089613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
1090613bf2b2SPierre Jolivet M*/
10919e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
1092613bf2b2SPierre Jolivet #endif
1093014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
1094d382aafbSBarry Smith 
109593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
109693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
1097eb3f98d2SBarry Smith 
1098639ff905SBarry Smith /*
1099639ff905SBarry Smith     Defines PETSc error handling.
1100639ff905SBarry Smith */
1101639ff905SBarry Smith #include <petscerror.h>
1102d382aafbSBarry Smith 
1103660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabled;                    /* code is running in the PETSc test harness CI */
1104660278c0SBarry Smith PETSC_EXTERN PetscBool   PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
1105660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *);
1106660278c0SBarry Smith PETSC_EXTERN int         PetscCILinenumber(int);
1107660278c0SBarry Smith 
1108f3fa974cSJacob Faibussowitsch #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211)
1109014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_LARGEST_CLASSID;
1110014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_OBJECT_CLASSID;
1111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
111281256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
111381256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);
111481256985SMatthew G. Knepley 
1115d382aafbSBarry Smith /*
1116d382aafbSBarry Smith    Routines that get memory usage information from the OS
1117d382aafbSBarry Smith */
1118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1121b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1122d382aafbSBarry Smith 
1123014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1124d382aafbSBarry Smith 
1125d382aafbSBarry Smith /*
1126d382aafbSBarry Smith    Initialization of PETSc
1127d382aafbSBarry Smith */
1128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
1129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]);
1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1133014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1135014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
1136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1137014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1138d382aafbSBarry Smith 
1139014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void);
1140607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
1141*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void);
1142d382aafbSBarry Smith 
1143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
1144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1145014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);
1147d382aafbSBarry Smith 
1148a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *);
1149a50e088cSMatthew G. Knepley 
1150d382aafbSBarry Smith /*
1151d382aafbSBarry Smith      These are so that in extern C code we can caste function pointers to non-extern C
11522981ebdbSBarry Smith    function pointers. Since the regular C++ code expects its function pointers to be C++
1153d382aafbSBarry Smith */
1154638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void);
1155638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void);
1156638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1157d382aafbSBarry Smith 
1158d382aafbSBarry Smith /*
1159d382aafbSBarry Smith     Functions that can act on any PETSc object.
1160d382aafbSBarry Smith */
1161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
1162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
1163014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
1164014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
1165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
1166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
1167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
1168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
1169014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
1170014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
1171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
1173014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1174014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
1175014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
1176014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
1177014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
1178bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void));
1179a20e6990SJacob Faibussowitsch #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFunction)(__VA_ARGS__))
1180014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1181014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
11820eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
11830eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
1184014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);
1185d382aafbSBarry Smith 
1186665c2dedSJed Brown #include <petscviewertypes.h>
1187639ff905SBarry Smith #include <petscoptions.h>
1188639ff905SBarry Smith 
1189608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
1190608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);
1191608c71bfSMatthew G. Knepley 
11920633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *);
11930633abcbSJed Brown 
1194c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
1195dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
1196639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
11970005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr))
11980005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void));
1199014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
1201014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
1202014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
1203014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
1204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1206685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
1209013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
12104099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
1211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1212b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1213014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1214014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1215d382aafbSBarry Smith 
1216e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
12177aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1218e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1219e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
1220e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1221e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1222e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1223e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1224e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1225e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1226e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
122715681b3cSBarry Smith 
1228ec7429eaSBarry Smith #else
12293ba16761SJacob Faibussowitsch   #define PetscSAWsBlock()                  PETSC_SUCCESS
12303ba16761SJacob Faibussowitsch   #define PetscObjectSAWsViewOff(obj)       PETSC_SUCCESS
12313ba16761SJacob Faibussowitsch   #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS
12323ba16761SJacob Faibussowitsch   #define PetscObjectSAWsBlock(obj)         PETSC_SUCCESS
12333ba16761SJacob Faibussowitsch   #define PetscObjectSAWsGrantAccess(obj)   PETSC_SUCCESS
12343ba16761SJacob Faibussowitsch   #define PetscObjectSAWsTakeAccess(obj)    PETSC_SUCCESS
12353ba16761SJacob Faibussowitsch   #define PetscStackViewSAWs()              PETSC_SUCCESS
12363ba16761SJacob Faibussowitsch   #define PetscStackSAWsViewOff()           PETSC_SUCCESS
1237e04113cfSBarry Smith   #define PetscStackSAWsTakeAccess()
1238e04113cfSBarry Smith   #define PetscStackSAWsGrantAccess()
123915681b3cSBarry Smith 
1240ec7429eaSBarry Smith #endif
1241b90c6cbeSBarry Smith 
124282b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
124382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
124482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
1245258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **);
1246258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX
1247258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **);
1248258ec3d2SMatthew G. Knepley #endif
12497d5d4d99SBarry Smith 
1250a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);
1251a64a8e02SBarry Smith 
1252dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
1253*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer);
1254*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, char **);
1255140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
1256140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
1257140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *);
1258140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
1259140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
1260140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);
1261d382aafbSBarry Smith 
1262d382aafbSBarry Smith /*
1263503cfb0cSBarry Smith     Dynamic library lists. Lists of names of routines in objects or in dynamic
1264d382aafbSBarry Smith   link libraries that will be loaded as needed.
1265d382aafbSBarry Smith */
1266a240a19fSJed Brown 
1267a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr))
1268ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFunction);
1269140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
12700e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
12711c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr))
1272ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFunction *);
127344ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
1274140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
1275140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
1276140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
12772e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
12782e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);
1279d382aafbSBarry Smith 
1280014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
1281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
1282014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
1283014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
1284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1288d382aafbSBarry Smith 
1289d382aafbSBarry Smith /*
1290d382aafbSBarry Smith      Useful utility routines
1291d382aafbSBarry Smith */
1292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
1294d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
1295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
1297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
129958b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
130058b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);
1301d382aafbSBarry Smith 
130264ac3b0dSPatrick Sanan /*MC
130387497f52SBarry Smith     PetscNot - negates a logical type value and returns result as a `PetscBool`
1304503cfb0cSBarry Smith 
130564ac3b0dSPatrick Sanan     Level: beginner
130664ac3b0dSPatrick Sanan 
1307a1cb98faSBarry Smith     Note:
1308a1cb98faSBarry Smith     This is useful in cases like
1309a1cb98faSBarry Smith .vb
1310a1cb98faSBarry Smith      int        *a;
1311a1cb98faSBarry Smith      PetscBool  flag = PetscNot(a)
1312a1cb98faSBarry Smith .ve
1313a1cb98faSBarry Smith      where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.
1314a1cb98faSBarry Smith 
1315a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
131664ac3b0dSPatrick Sanan M*/
1317d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1318503cfb0cSBarry Smith 
1319d382aafbSBarry Smith /*MC
1320d382aafbSBarry Smith     PetscHelpPrintf - Prints help messages.
1321d382aafbSBarry Smith 
1322d382aafbSBarry Smith    Synopsis:
1323aaa7dc30SBarry Smith     #include <petscsys.h>
1324659f7ba0SBarry Smith      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1325d382aafbSBarry Smith 
13267cdbe19fSJose E. Roman     Not Collective, only applies on MPI rank 0; No Fortran Support
13277cdbe19fSJose E. Roman 
1328d382aafbSBarry Smith     Input Parameters:
1329659f7ba0SBarry Smith +  comm - the MPI communicator over which the help message is printed
1330d382aafbSBarry Smith .  format - the usual printf() format string
1331659f7ba0SBarry Smith -  args - arguments to be printed
1332d382aafbSBarry Smith 
1333d382aafbSBarry Smith    Level: developer
1334d382aafbSBarry Smith 
1335659f7ba0SBarry Smith    Note:
1336659f7ba0SBarry Smith      You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1337659f7ba0SBarry Smith 
1338659f7ba0SBarry Smith       To use, write your own function, for example,
133916a05f60SBarry Smith .vb
134016a05f60SBarry Smith    PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
134116a05f60SBarry Smith    {
134216a05f60SBarry Smith      PetscFunctionReturn(PETSC_SUCCESS);
134316a05f60SBarry Smith    }
134416a05f60SBarry Smith .ve
1345d5b43468SJose E. Roman then do the assignment
1346659f7ba0SBarry Smith $    PetscHelpPrintf = mypetschelpprintf;
134787497f52SBarry Smith    You can do the assignment before `PetscInitialize()`.
1348659f7ba0SBarry Smith 
134987497f52SBarry Smith   The default routine used is called `PetscHelpPrintfDefault()`.
1350d382aafbSBarry Smith 
135116a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()`
1352d382aafbSBarry Smith M*/
13533ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1354d382aafbSBarry Smith 
1355fcfd50ebSBarry Smith /*
1356fcfd50ebSBarry Smith      Defines PETSc profiling.
1357fcfd50ebSBarry Smith */
13582c8e378dSBarry Smith #include <petsclog.h>
1359fcfd50ebSBarry Smith 
1360fcfd50ebSBarry Smith /*
1361fcfd50ebSBarry Smith       Simple PETSc parallel IO for ASCII printing
1362fcfd50ebSBarry Smith */
1363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
1364014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
1365014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
13663ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1367c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *);
13683ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
13693ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
13703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
13711b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);
1372fcfd50ebSBarry Smith 
13733ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
13743ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
13753ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1376d382aafbSBarry Smith 
1377d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
1378d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);
1379d781fa04SBarry Smith 
1380d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN)
1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
1382016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
138374ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1384d382aafbSBarry Smith #endif
1385d382aafbSBarry Smith 
13863ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
13873ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
13880ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
1389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
1390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
1391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);
1392d382aafbSBarry Smith 
1393014dd563SJed Brown PETSC_EXTERN PetscClassId   PETSC_CONTAINER_CLASSID;
1394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **);
1395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
1396014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
1397014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
1398014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
1399b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *);
1400d382aafbSBarry Smith 
1401d382aafbSBarry Smith /*
1402d382aafbSBarry Smith    For use in debuggers
1403d382aafbSBarry Smith */
1404014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalRank;
1405014dd563SJed Brown PETSC_EXTERN PetscMPIInt    PetscGlobalSize;
1406014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
1407014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
1408014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);
1409d382aafbSBarry Smith 
1410bbcf679cSJacob Faibussowitsch /*
1411bbcf679cSJacob Faibussowitsch     Basic memory and string operations. These are usually simple wrappers
1412bbcf679cSJacob Faibussowitsch    around the basic Unix system calls, but a few of them have additional
1413bbcf679cSJacob Faibussowitsch    functionality and/or error checking.
1414bbcf679cSJacob Faibussowitsch */
1415bbcf679cSJacob Faibussowitsch #include <petscstring.h>
1416bbcf679cSJacob Faibussowitsch 
1417a663daf8SBarry Smith #include <stddef.h>
1418d382aafbSBarry Smith #include <stdlib.h>
14196c7e564aSBarry Smith 
1420447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
1421447bcd8fSJacob Faibussowitsch   #define PetscPrefetchBlock(a, b, c, d)
1422447bcd8fSJacob Faibussowitsch #else
1423d382aafbSBarry Smith   /*MC
1424d382aafbSBarry Smith    PetscPrefetchBlock - Prefetches a block of memory
1425d382aafbSBarry Smith 
1426eca87e8dSBarry Smith    Synopsis:
1427aaa7dc30SBarry Smith     #include <petscsys.h>
1428eca87e8dSBarry Smith     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1429eca87e8dSBarry Smith 
1430d382aafbSBarry Smith    Not Collective
1431d382aafbSBarry Smith 
1432d382aafbSBarry Smith    Input Parameters:
143316a05f60SBarry Smith +  a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`)
1434d382aafbSBarry Smith .  n - number of elements to fetch
1435d382aafbSBarry Smith .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
143650d8bf02SJed Brown -  t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1437d382aafbSBarry Smith 
1438d382aafbSBarry Smith    Level: developer
1439d382aafbSBarry Smith 
1440d382aafbSBarry Smith    Notes:
144116a05f60SBarry Smith    The last two arguments (`rw` and `t`) must be compile-time constants.
1442d382aafbSBarry Smith 
144350d8bf02SJed Brown    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
144450d8bf02SJed Brown    equivalent locality hints, but the following macros are always defined to their closest analogue.
144587497f52SBarry 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).
144687497f52SBarry 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.
144787497f52SBarry Smith .  `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1).
144887497f52SBarry Smith -  `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
1449d382aafbSBarry Smith 
1450d382aafbSBarry Smith    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1451d382aafbSBarry Smith    address).
1452d382aafbSBarry Smith 
1453d382aafbSBarry Smith M*/
14549371c9d4SSatish Balay   #define PetscPrefetchBlock(a, n, rw, t) \
14559371c9d4SSatish Balay     do { \
1456d382aafbSBarry Smith       const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
1457d382aafbSBarry Smith       for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
1458d382aafbSBarry Smith     } while (0)
1459447bcd8fSJacob Faibussowitsch #endif
1460d382aafbSBarry Smith /*
1461d382aafbSBarry Smith       Determine if some of the kernel computation routines use
1462d382aafbSBarry Smith    Fortran (rather than C) for the numerical calculations. On some machines
1463d382aafbSBarry Smith    and compilers (like complex numbers) the Fortran version of the routines
1464d382aafbSBarry Smith    is faster than the C/C++ versions. The flag --with-fortran-kernels
1465e2e64c6bSBarry Smith    should be used with ./configure to turn these on.
1466d382aafbSBarry Smith */
1467d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS)
1468d382aafbSBarry Smith 
1469d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1470d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1471d382aafbSBarry Smith   #endif
1472d382aafbSBarry Smith 
14735a11e1b2SBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM)
14745a11e1b2SBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM
1475d382aafbSBarry Smith   #endif
1476d382aafbSBarry Smith 
1477d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1478d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1479d382aafbSBarry Smith   #endif
1480d382aafbSBarry Smith 
1481d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1482d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1483d382aafbSBarry Smith   #endif
1484d382aafbSBarry Smith 
1485d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1486d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_NORM
1487d382aafbSBarry Smith   #endif
1488d382aafbSBarry Smith 
1489d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1490d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1491d382aafbSBarry Smith   #endif
1492d382aafbSBarry Smith 
1493d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1494d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1495d382aafbSBarry Smith   #endif
1496d382aafbSBarry Smith 
1497d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1498d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1499d382aafbSBarry Smith   #endif
1500d382aafbSBarry Smith 
1501d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1502d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1503d382aafbSBarry Smith   #endif
1504d382aafbSBarry Smith 
1505d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1506d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1507d382aafbSBarry Smith   #endif
1508d382aafbSBarry Smith 
1509d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1510d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_MDOT
1511d382aafbSBarry Smith   #endif
1512d382aafbSBarry Smith 
1513d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1514d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1515d382aafbSBarry Smith   #endif
1516d382aafbSBarry Smith 
1517d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1518d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_AYPX
1519d382aafbSBarry Smith   #endif
1520d382aafbSBarry Smith 
1521d382aafbSBarry Smith   #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1522d382aafbSBarry Smith     #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1523d382aafbSBarry Smith   #endif
1524d382aafbSBarry Smith 
1525d382aafbSBarry Smith #endif
1526d382aafbSBarry Smith 
1527d382aafbSBarry Smith /*
1528d382aafbSBarry Smith     Macros for indicating code that should be compiled with a C interface,
1529d382aafbSBarry Smith    rather than a C++ interface. Any routines that are dynamically loaded
1530d382aafbSBarry Smith    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1531d382aafbSBarry Smith    mangler does not change the functions symbol name. This just hides the
1532d382aafbSBarry Smith    ugly extern "C" {} wrappers.
1533d382aafbSBarry Smith */
1534d382aafbSBarry Smith #if defined(__cplusplus)
1535d382aafbSBarry Smith   #define EXTERN_C_BEGIN extern "C" {
1536d382aafbSBarry Smith   #define EXTERN_C_END   }
1537d382aafbSBarry Smith #else
1538d382aafbSBarry Smith   #define EXTERN_C_BEGIN
1539d382aafbSBarry Smith   #define EXTERN_C_END
1540d382aafbSBarry Smith #endif
1541d382aafbSBarry Smith 
1542d382aafbSBarry Smith /*MC
1543d382aafbSBarry Smith     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1544d382aafbSBarry Smith         communication
1545d382aafbSBarry Smith 
1546d382aafbSBarry Smith    Level: beginner
1547d382aafbSBarry Smith 
154816a05f60SBarry Smith    Note:
154916a05f60SBarry Smith    This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm`
1550d382aafbSBarry Smith 
1551db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
1552d382aafbSBarry Smith M*/
1553d382aafbSBarry Smith 
1554d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO)
155593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
155693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
155793d501b3SJacob 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);
155893d501b3SJacob 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);
155993d501b3SJacob 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);
156093d501b3SJacob 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);
1561d382aafbSBarry Smith #endif
1562d382aafbSBarry Smith 
156361b0d812SBarry Smith /*@C
15647de69702SBarry Smith     PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32-bits in size), generates an
156587497f52SBarry Smith          error if the `PetscInt` is not large enough to hold the number.
1566c73702f5SBarry Smith 
156720f4b53cSBarry Smith    Not Collective; No Fortran Support
1568c73702f5SBarry Smith 
1569c73702f5SBarry Smith    Input Parameter:
157087497f52SBarry Smith .     a - the `PetscInt64` value
1571c73702f5SBarry Smith 
1572c73702f5SBarry Smith    Output Parameter:
157387497f52SBarry Smith .     b - the resulting `PetscInt` value
1574c73702f5SBarry Smith 
1575c73702f5SBarry Smith    Level: advanced
1576c73702f5SBarry Smith 
157787497f52SBarry Smith    Notes:
15787de69702SBarry Smith    If integers needed for the applications are too large to fit in 32-bit ints you can ./configure using `--with-64-bit-indices` to make `PetscInt` use 64-bit integers
1579c73702f5SBarry Smith 
1580db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
1581c73702f5SBarry Smith @*/
1582d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b)
1583d71ae5a4SJacob Faibussowitsch {
1584c73702f5SBarry Smith   PetscFunctionBegin;
15853ca90d2dSJacob Faibussowitsch   *b = 0;
1586f3fa974cSJacob Faibussowitsch   // if using 64-bit indices already then this comparison is tautologically true
1587f3fa974cSJacob 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);
1588f3fa974cSJacob Faibussowitsch   *b = (PetscInt)a;
15893ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1590c73702f5SBarry Smith }
1591c73702f5SBarry Smith 
1592c73702f5SBarry Smith /*@C
15937de69702SBarry Smith     PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32-bits in size), generates an
159487497f52SBarry Smith          error if the `PetscInt` is not large enough to hold the number.
1595981bb840SJunchao Zhang 
1596667f096bSBarry Smith    Not Collective; No Fortran Support
1597981bb840SJunchao Zhang 
1598981bb840SJunchao Zhang    Input Parameter:
159987497f52SBarry Smith .     a - the `PetscCount` value
1600981bb840SJunchao Zhang 
1601981bb840SJunchao Zhang    Output Parameter:
160287497f52SBarry Smith .     b - the resulting `PetscInt` value
1603981bb840SJunchao Zhang 
1604981bb840SJunchao Zhang    Level: advanced
1605981bb840SJunchao Zhang 
1606667f096bSBarry Smith    Note:
16077de69702SBarry Smith      If integers needed for the applications are too large to fit in 32-bit integers you can ./configure using `--with-64-bit-indices` to make `PetscInt` use 64-bit integers
1608981bb840SJunchao Zhang 
1609667f096bSBarry Smith .seealso: `PetscCount`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()`
1610981bb840SJunchao Zhang @*/
1611d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b)
1612d71ae5a4SJacob Faibussowitsch {
1613981bb840SJunchao Zhang   PetscFunctionBegin;
1614981bb840SJunchao Zhang   *b = 0;
1615f3fa974cSJacob 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);
1616f3fa974cSJacob Faibussowitsch   *b = (PetscInt)a;
16173ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1618981bb840SJunchao Zhang }
1619981bb840SJunchao Zhang 
1620981bb840SJunchao Zhang /*@C
16217de69702SBarry Smith     PetscBLASIntCast - casts a `PetscInt` (which may be 64-bits in size) to a `PetscBLASInt` (which may be 32-bits in size), generates an
162287497f52SBarry Smith          error if the `PetscBLASInt` is not large enough to hold the number.
162361b0d812SBarry Smith 
1624667f096bSBarry Smith    Not Collective; No Fortran Support
162561b0d812SBarry Smith 
162661b0d812SBarry Smith    Input Parameter:
162787497f52SBarry Smith .     a - the `PetscInt` value
162861b0d812SBarry Smith 
162961b0d812SBarry Smith    Output Parameter:
163087497f52SBarry Smith .     b - the resulting `PetscBLASInt` value
163161b0d812SBarry Smith 
163261b0d812SBarry Smith    Level: advanced
163361b0d812SBarry Smith 
1634667f096bSBarry Smith    Note:
1635f0b7f91aSBarry Smith    Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
16361fd49c25SBarry Smith 
1637db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()`
163861b0d812SBarry Smith @*/
1639d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b)
1640d71ae5a4SJacob Faibussowitsch {
1641c5df96a5SBarry Smith   PetscFunctionBegin;
164254c59aa7SJacob Faibussowitsch   *b = 0;
164354c59aa7SJacob Faibussowitsch   if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) {
16447de69702SBarry Smith     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);
164554c59aa7SJacob Faibussowitsch   }
164654c59aa7SJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
1647f3fa974cSJacob Faibussowitsch   *b = (PetscBLASInt)a;
16483ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1649c5df96a5SBarry Smith }
1650c5df96a5SBarry Smith 
165161b0d812SBarry Smith /*@C
165287497f52SBarry Smith     PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.
1653eee0c0a6SToby Isaac 
1654667f096bSBarry Smith    Not Collective; No Fortran Support
1655eee0c0a6SToby Isaac 
1656eee0c0a6SToby Isaac    Input Parameter:
165787497f52SBarry Smith .     a - the `PetscInt` value
1658eee0c0a6SToby Isaac 
1659eee0c0a6SToby Isaac    Output Parameter:
166087497f52SBarry Smith .     b - the resulting `PetscCuBLASInt` value
1661eee0c0a6SToby Isaac 
1662eee0c0a6SToby Isaac    Level: advanced
1663eee0c0a6SToby Isaac 
1664667f096bSBarry Smith    Note:
1665eee0c0a6SToby Isaac       Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
1666eee0c0a6SToby Isaac 
1667db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
1668eee0c0a6SToby Isaac @*/
1669d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b)
1670d71ae5a4SJacob Faibussowitsch {
1671eee0c0a6SToby Isaac   PetscFunctionBegin;
167254c59aa7SJacob Faibussowitsch   *b = 0;
16737de69702SBarry Smith   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);
1674f3fa974cSJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to cuBLAS routine", a);
1675f3fa974cSJacob Faibussowitsch   *b = (PetscCuBLASInt)a;
16763ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1677eee0c0a6SToby Isaac }
1678eee0c0a6SToby Isaac 
1679eee0c0a6SToby Isaac /*@C
168047d993e7Ssuyashtn     PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.
168147d993e7Ssuyashtn 
1682667f096bSBarry Smith    Not Collective; No Fortran Support
168347d993e7Ssuyashtn 
168447d993e7Ssuyashtn    Input Parameter:
168547d993e7Ssuyashtn .     a - the `PetscInt` value
168647d993e7Ssuyashtn 
168747d993e7Ssuyashtn    Output Parameter:
168847d993e7Ssuyashtn .     b - the resulting `PetscHipBLASInt` value
168947d993e7Ssuyashtn 
169047d993e7Ssuyashtn    Level: advanced
169147d993e7Ssuyashtn 
1692667f096bSBarry Smith    Note:
169347d993e7Ssuyashtn       Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs
169447d993e7Ssuyashtn 
169547d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
169647d993e7Ssuyashtn @*/
169747d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b)
169847d993e7Ssuyashtn {
169947d993e7Ssuyashtn   PetscFunctionBegin;
170047d993e7Ssuyashtn   *b = 0;
17017de69702SBarry Smith   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);
1702f3fa974cSJacob Faibussowitsch   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to hipBLAS routine", a);
1703f3fa974cSJacob Faibussowitsch   *b = (PetscHipBLASInt)a;
17043ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
170547d993e7Ssuyashtn }
170647d993e7Ssuyashtn 
170747d993e7Ssuyashtn /*@C
17087de69702SBarry Smith     PetscMPIIntCast - casts a `PetscInt` (which may be 64-bits in size) to a PetscMPIInt (which may be 32-bits in size), generates an
1709667f096bSBarry Smith          error if the `PetscMPIInt` is not large enough to hold the number.
171061b0d812SBarry Smith 
1711667f096bSBarry Smith    Not Collective; No Fortran Support
171261b0d812SBarry Smith 
171361b0d812SBarry Smith    Input Parameter:
171487497f52SBarry Smith .     a - the `PetscInt` value
171561b0d812SBarry Smith 
171661b0d812SBarry Smith    Output Parameter:
171787497f52SBarry Smith .     b - the resulting `PetscMPIInt` value
171861b0d812SBarry Smith 
171961b0d812SBarry Smith    Level: advanced
172061b0d812SBarry Smith 
1721db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
172261b0d812SBarry Smith @*/
1723d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b)
1724d71ae5a4SJacob Faibussowitsch {
17254dc2109aSBarry Smith   PetscFunctionBegin;
172654c59aa7SJacob Faibussowitsch   *b = 0;
1727f3fa974cSJacob 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);
1728f3fa974cSJacob Faibussowitsch   *b = (PetscMPIInt)a;
17293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
17304dc2109aSBarry Smith }
17314dc2109aSBarry Smith 
1732f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b)))
17332f18eb33SBarry Smith 
17342f18eb33SBarry Smith /*@C
1735f3fa974cSJacob Faibussowitsch   PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive
1736f3fa974cSJacob Faibussowitsch   `PetscInt` and truncates the value to slightly less than the maximal possible value.
17372f18eb33SBarry Smith 
173820f4b53cSBarry Smith   Not Collective; No Fortran Support
17392f18eb33SBarry Smith 
1740d8d19677SJose E. Roman   Input Parameters:
1741f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value
1742f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value
17432f18eb33SBarry Smith 
1744667f096bSBarry Smith   Level: advanced
1745667f096bSBarry Smith 
1746f3fa974cSJacob Faibussowitsch   Notes:
1747f3fa974cSJacob Faibussowitsch   Returns the result as a `PetscInt` value.
17482f18eb33SBarry Smith 
1749f3fa974cSJacob Faibussowitsch   Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`.
1750667f096bSBarry Smith 
1751f3fa974cSJacob Faibussowitsch   Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate
1752f3fa974cSJacob Faibussowitsch   to fit a `PetscInt`.
1753667f096bSBarry Smith 
1754f3fa974cSJacob Faibussowitsch   Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an
1755f3fa974cSJacob Faibussowitsch   error if the result will not fit in a `PetscInt`.
17562f18eb33SBarry Smith 
1757667f096bSBarry Smith   Developers Notes:
1758f3fa974cSJacob Faibussowitsch   We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but
1759f3fa974cSJacob Faibussowitsch   requires many more checks.
17602f18eb33SBarry Smith 
1761f3fa974cSJacob Faibussowitsch   This is used where we compute approximate sizes for workspace and need to insure the
1762f3fa974cSJacob Faibussowitsch   workspace is index-able.
17631fd49c25SBarry Smith 
1764f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
17652f18eb33SBarry Smith @*/
1766d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
1767d71ae5a4SJacob Faibussowitsch {
17685f80ce2aSJacob Faibussowitsch   PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
17692f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
17702f18eb33SBarry Smith   return (PetscInt)r;
17712f18eb33SBarry Smith }
17722f18eb33SBarry Smith 
17732f18eb33SBarry Smith /*@C
17742f18eb33SBarry Smith 
177587497f52SBarry Smith    PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
17762f18eb33SBarry Smith 
1777667f096bSBarry Smith    Not Collective; No Fortran Support
17782f18eb33SBarry Smith 
1779d8d19677SJose E. Roman    Input Parameters:
17802f18eb33SBarry Smith +     a - the PetscInt value
17812f18eb33SBarry Smith -     b - the second value
17822f18eb33SBarry Smith 
1783390e1bf2SBarry Smith    Returns:
178487497f52SBarry Smith       the result as a `PetscInt` value
17852f18eb33SBarry Smith 
1786667f096bSBarry Smith    Level: advanced
1787667f096bSBarry Smith 
1788667f096bSBarry Smith    Notes:
178987497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
1790667f096bSBarry Smith 
179187497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
1792667f096bSBarry Smith 
179387497f52SBarry 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`
17942f18eb33SBarry Smith 
1795667f096bSBarry Smith    Developers Notes:
179687497f52SBarry Smith    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
17972f18eb33SBarry Smith 
17982f18eb33SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
17992f18eb33SBarry Smith 
1800667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`,
1801667f096bSBarry Smith           `PetscIntSumTruncate()`
18022f18eb33SBarry Smith @*/
1803d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
1804d71ae5a4SJacob Faibussowitsch {
18055f80ce2aSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
18062f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
18072f18eb33SBarry Smith   return (PetscInt)r;
18082f18eb33SBarry Smith }
18092f18eb33SBarry Smith 
1810f91af8c7SBarry Smith /*@C
1811f91af8c7SBarry Smith 
181287497f52SBarry Smith    PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
1813f91af8c7SBarry Smith 
1814667f096bSBarry Smith    Not Collective; No Fortran Support
1815f91af8c7SBarry Smith 
1816d8d19677SJose E. Roman    Input Parameters:
181787497f52SBarry Smith +     a - the `PetscInt` value
1818f91af8c7SBarry Smith -     b - the second value
1819f91af8c7SBarry Smith 
1820390e1bf2SBarry Smith    Returns:
182187497f52SBarry Smith      the result as a `PetscInt` value
1822f91af8c7SBarry Smith 
1823667f096bSBarry Smith    Level: advanced
1824667f096bSBarry Smith 
1825667f096bSBarry Smith    Notes:
182687497f52SBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
1827667f096bSBarry Smith 
182887497f52SBarry Smith    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
1829667f096bSBarry Smith 
183087497f52SBarry 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`
1831f91af8c7SBarry Smith 
1832667f096bSBarry Smith    Developers Notes:
1833f91af8c7SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
1834f91af8c7SBarry Smith 
1835db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
1836f91af8c7SBarry Smith @*/
1837d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
1838d71ae5a4SJacob Faibussowitsch {
18395f80ce2aSJacob Faibussowitsch   PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b);
1840f91af8c7SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
1841f91af8c7SBarry Smith   return (PetscInt)r;
1842f91af8c7SBarry Smith }
1843f91af8c7SBarry Smith 
18442f18eb33SBarry Smith /*@C
18452f18eb33SBarry Smith 
184687497f52SBarry Smith    PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.
18472f18eb33SBarry Smith 
1848667f096bSBarry Smith    Not Collective; No Fortran Support
18492f18eb33SBarry Smith 
1850d8d19677SJose E. Roman    Input Parameters:
185187497f52SBarry Smith +     a - the `PetscInt` value
18522f18eb33SBarry Smith -     b - the second value
18532f18eb33SBarry Smith 
1854d8d19677SJose E. Roman    Output Parameter:
185516a05f60SBarry 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
18562f18eb33SBarry Smith 
1857667f096bSBarry Smith    Level: advanced
18582f18eb33SBarry Smith 
1859667f096bSBarry Smith    Notes:
1860667f096bSBarry Smith    Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`
1861667f096bSBarry Smith 
1862667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
1863f5f57ec0SBarry Smith 
186487497f52SBarry Smith    Developers Note:
186516a05f60SBarry Smith    In most places in the source code we currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks.
186616a05f60SBarry Smith    `PetscIntSumError()` can be used to check for this situation.
18672f18eb33SBarry Smith 
1868db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()`
18692f18eb33SBarry Smith @*/
1870d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
1871d71ae5a4SJacob Faibussowitsch {
1872f3fa974cSJacob Faibussowitsch   PetscInt64 r = PetscInt64Mult(a, b);
18732f18eb33SBarry Smith 
18742f18eb33SBarry Smith   PetscFunctionBegin;
1875c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
1876f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
1877f3fa974cSJacob 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);
1878f3fa974cSJacob Faibussowitsch   }
18793ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1880f91af8c7SBarry Smith }
1881f91af8c7SBarry Smith 
1882f91af8c7SBarry Smith /*@C
1883f91af8c7SBarry Smith 
188487497f52SBarry Smith    PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.
1885f91af8c7SBarry Smith 
1886667f096bSBarry Smith    Not Collective; No Fortran Support
1887f91af8c7SBarry Smith 
1888d8d19677SJose E. Roman    Input Parameters:
188987497f52SBarry Smith +     a - the `PetscInt` value
1890f91af8c7SBarry Smith -     b - the second value
1891f91af8c7SBarry Smith 
1892d8d19677SJose E. Roman    Output Parameter:
189316a05f60SBarry 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
1894f91af8c7SBarry Smith 
1895f91af8c7SBarry Smith    Level: advanced
1896f91af8c7SBarry Smith 
1897667f096bSBarry Smith    Notes:
18987de69702SBarry Smith    Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64`
1899667f096bSBarry Smith 
1900667f096bSBarry Smith    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
1901667f096bSBarry Smith 
1902db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
1903f91af8c7SBarry Smith @*/
1904d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
1905d71ae5a4SJacob Faibussowitsch {
1906f3fa974cSJacob Faibussowitsch   PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b);
1907f91af8c7SBarry Smith 
1908f91af8c7SBarry Smith   PetscFunctionBegin;
1909c72d0b4cSJacob Faibussowitsch   if (result) *result = (PetscInt)r;
1910f3fa974cSJacob Faibussowitsch   if (!PetscDefined(USE_64BIT_INDICES)) {
1911f3fa974cSJacob 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);
1912f3fa974cSJacob Faibussowitsch   }
19133ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
19142f18eb33SBarry Smith }
1915c5df96a5SBarry Smith 
1916d382aafbSBarry Smith /*
19172981ebdbSBarry Smith      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
1918d382aafbSBarry Smith */
1919d382aafbSBarry Smith #if defined(hz)
1920d382aafbSBarry Smith   #undef hz
1921d382aafbSBarry Smith #endif
1922d382aafbSBarry Smith 
1923d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H)
1924d382aafbSBarry Smith   #include <sys/types.h>
1925d382aafbSBarry Smith #endif
1926d382aafbSBarry Smith 
1927d382aafbSBarry Smith /*MC
1928d382aafbSBarry Smith 
192966d79e26SBarry 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++
193016a05f60SBarry Smith                     and Fortran compilers when `petscsys.h` is included.
193166d79e26SBarry Smith 
19326274ba02SSatish 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>
193366d79e26SBarry Smith 
193466d79e26SBarry 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)
193566d79e26SBarry Smith 
193666d79e26SBarry 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
193766d79e26SBarry Smith     where only a change in the major version number (x) indicates a change in the API.
193866d79e26SBarry Smith 
193966d79e26SBarry 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
194066d79e26SBarry Smith 
194166d79e26SBarry 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),
194266d79e26SBarry 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
194366d79e26SBarry Smith     version number (x.y.z).
194466d79e26SBarry Smith 
194587497f52SBarry Smith     `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)
194666d79e26SBarry Smith 
194787497f52SBarry Smith     `PETSC_VERSION_DATE` is the date the x.y.z version was released
194866d79e26SBarry Smith 
194987497f52SBarry Smith     `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww
195066d79e26SBarry Smith 
195187497f52SBarry Smith     `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository
195266d79e26SBarry Smith 
195387497f52SBarry Smith     `PETSC_VERSION_()` is deprecated and will eventually be removed.
195466d79e26SBarry Smith 
1955cbc12506SBarry Smith     Level: intermediate
195666d79e26SBarry Smith M*/
195766d79e26SBarry Smith 
1958014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
1959014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
1960014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
1961014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
1962014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
1963014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
196427710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
19655f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);
1966d382aafbSBarry Smith 
19676a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *);
196862e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *);
19696a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *);
19706a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *);
1971014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]);
197262e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]);
197362e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]);
1974ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]);
197522ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
1976b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
1977014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
1978f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
197960e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *);
1980d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *);
1981014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
1982014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
1983014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]);
1984981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
19856c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]);
1986981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
198717d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]);
198817d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
1989014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]);
19905569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]);
1991014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]);
199217df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *);
1993014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]);
199439f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
1995014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
1996745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
199739f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *);
1998014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
1999014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
2000014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **);
20016c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **);
20026c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **);
2003e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **);
2004ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
2005ce605777SToby Isaac 
20064d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
2007676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
2008676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
2009676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
20104d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
2011676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
2012676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
2013676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2014676f2a66SJacob Faibussowitsch 
2015014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2016014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);
2017d382aafbSBarry Smith 
201876bdecfbSBarry Smith /*J
2019d382aafbSBarry Smith     PetscRandomType - String with the name of a PETSc randomizer
2020d382aafbSBarry Smith 
2021d382aafbSBarry Smith    Level: beginner
2022d382aafbSBarry Smith 
2023667f096bSBarry Smith    Note:
202487497f52SBarry Smith    To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
202516a05f60SBarry Smith    with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc.
2026d382aafbSBarry Smith 
2027db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
202876bdecfbSBarry Smith J*/
202919fd82e9SBarry Smith typedef const char *PetscRandomType;
2030d382aafbSBarry Smith #define PETSCRAND      "rand"
2031d382aafbSBarry Smith #define PETSCRAND48    "rand48"
2032d382aafbSBarry Smith #define PETSCSPRNG     "sprng"
2033c5e4d11fSDmitry Karpeev #define PETSCRANDER48  "rander48"
203425ccb61fSToby Isaac #define PETSCRANDOM123 "random123"
2035808ba619SStefano Zampini #define PETSCCURAND    "curand"
2036d382aafbSBarry Smith 
2037d382aafbSBarry Smith /* Logging support */
2038014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2039d382aafbSBarry Smith 
2040607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
2041*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void);
2042d382aafbSBarry Smith 
2043d382aafbSBarry Smith /* Dynamic creation and loading functions */
2044140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList;
2045d382aafbSBarry Smith 
2046bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
204719fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
2048014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
204919fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
2050fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
2051014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);
2052d382aafbSBarry Smith 
2053014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
2054014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
2055014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
2056808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
2057808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
2058014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
2059014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
2060014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long);
2061014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *);
2062014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2063014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);
2064d382aafbSBarry Smith 
2065014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
2066014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
2067014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
2068014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
2069014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
2070014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
2071014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
207297540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
20738a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
207497540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2075d382aafbSBarry Smith 
2076d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void)
2077d71ae5a4SJacob Faibussowitsch {
20789371c9d4SSatish Balay   long _petsc_v = 1;
20799371c9d4SSatish Balay   return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
20809371c9d4SSatish Balay }
208130815ce0SLisandro Dalcin 
20829860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType);
20839860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
2084f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType);
2085f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
2086014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
2087014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2088014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
2089014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
2090014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
2091014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
2092014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
2093c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER)
2094e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
2095c891a504SStefano Zampini #endif
2096d382aafbSBarry Smith 
2097014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
2098014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
2099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt);
2100d382aafbSBarry Smith 
2101014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2102014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
2103014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2104014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
2105014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2106014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
21072a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2108d382aafbSBarry Smith 
2109014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
2110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **);
2111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **);
2112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
2113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
211493d501b3SJacob 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);
211593d501b3SJacob 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);
211693d501b3SJacob 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);
2117d382aafbSBarry Smith 
21186145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
21196145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);
21206145cd65SJed Brown 
2121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *);
2122d382aafbSBarry Smith 
2123ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2124ce94432eSBarry Smith 
2125d382aafbSBarry Smith struct _n_PetscSubcomm {
2126d382aafbSBarry Smith   MPI_Comm         parent;    /* parent communicator */
2127d382aafbSBarry Smith   MPI_Comm         dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2128306c2d5bSBarry Smith   MPI_Comm         child;     /* the sub-communicator */
212945487dadSJed Brown   PetscMPIInt      n;         /* num of subcommunicators under the parent communicator */
213045487dadSJed Brown   PetscMPIInt      color;     /* color of processors belong to this communicator */
2131708d824cSJed Brown   PetscMPIInt     *subsize;   /* size of subcommunicator[color] */
213245487dadSJed Brown   PetscSubcommType type;
2133e5acf8a4SHong Zhang   char            *subcommprefix;
2134d382aafbSBarry Smith };
2135d382aafbSBarry Smith 
2136d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
2137d71ae5a4SJacob Faibussowitsch {
21389371c9d4SSatish Balay   return scomm->parent;
21399371c9d4SSatish Balay }
2140d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
2141d71ae5a4SJacob Faibussowitsch {
21429371c9d4SSatish Balay   return scomm->child;
21439371c9d4SSatish Balay }
2144d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
2145d71ae5a4SJacob Faibussowitsch {
21469371c9d4SSatish Balay   return scomm->dupparent;
21479371c9d4SSatish Balay }
2148014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
2149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
2150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
2151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
215265d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
2153053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
2154f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2155e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
2156a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
2157a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
2158a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);
2159d382aafbSBarry Smith 
21609962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
21619962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
21629962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
21639962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
21649962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
21659962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
21669962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
21679962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);
21689962606eSBarry Smith 
21695e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
21705f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
21715f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
21725f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
21735f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);
21745e71baefSBarry Smith 
2175a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2176a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
2177a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
2178a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
2179a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2180a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2181a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2182a32e93adSJunchao Zhang 
218313e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *);
21840f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
218513e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *);
2186137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
2187137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
2188137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
218913e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *);
219013e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t);
21910f453b92SJed Brown 
2192471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2193471ecdacSJed Brown  * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2194471ecdacSJed Brown  * possible. */
2195d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot)
2196d71ae5a4SJacob Faibussowitsch {
21979371c9d4SSatish Balay   return PetscSegBufferGet(seg, count, (void **)slot);
21989371c9d4SSatish Balay }
2199d382aafbSBarry Smith 
22009de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
22019de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
22029de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
22039de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);
22049de0f6ecSBarry Smith 
2205ace2fbaeSBarry Smith #include <stdarg.h>
2206ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
2207ace2fbaeSBarry Smith PETSC_EXTERN                PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);
2208ace2fbaeSBarry Smith 
2209268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2210fbfcfee5SBarry Smith 
22111f817a21SBarry Smith /*@C
22121f817a21SBarry Smith       PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
22131f817a21SBarry Smith 
2214667f096bSBarry Smith      Not Collective; No Fortran Support
22151f817a21SBarry Smith 
22161f817a21SBarry Smith      Input Parameters:
221735cb6cd3SPierre Jolivet +      cite - the bibtex item, formatted to displayed on multiple lines nicely
221887497f52SBarry Smith -      set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation
22191f817a21SBarry Smith 
2220667f096bSBarry Smith      Options Database Key:
22213c7db156SBarry Smith .     -citations [filename]   - print out the bibtex entries for the given computation
22223c7db156SBarry Smith 
2223850545d0SSatish Balay      Level: intermediate
22241f817a21SBarry Smith @*/
2225d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
2226d71ae5a4SJacob Faibussowitsch {
2227dff31646SBarry Smith   size_t len;
2228dff31646SBarry Smith   char  *vstring;
2229dff31646SBarry Smith 
22301f817a21SBarry Smith   PetscFunctionBegin;
22313ba16761SJacob Faibussowitsch   if (set && *set) PetscFunctionReturn(PETSC_SUCCESS);
22329566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(cit, &len));
22339566063dSJacob Faibussowitsch   PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring));
22349566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy(vstring, cit, len));
2235dff31646SBarry Smith   if (set) *set = PETSC_TRUE;
22363ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2237dff31646SBarry Smith }
2238dff31646SBarry Smith 
2239fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
2240fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
2241f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);
2242fe278a28SBarry Smith 
2243f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
2244f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
2245*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]);
2246b967cddfSBarry Smith 
22479f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
2248*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t);
2249*4bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]);
22509f4d3c52SBarry Smith 
225168e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
22525dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);
2253dff31646SBarry Smith 
2254b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG)
2255d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str)
2256d71ae5a4SJacob Faibussowitsch {
2257df05ca09SBarry Smith   unsigned int c, hash = 5381;
2258df05ca09SBarry Smith 
2259503e1a2cSLisandro Dalcin   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2260df05ca09SBarry Smith   return hash;
2261df05ca09SBarry Smith }
226277a5e07dSBarry Smith 
226377a5e07dSBarry Smith   /*MC
226487497f52SBarry Smith    MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the
226587497f52SBarry Smith                     same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
226687497f52SBarry Smith                     resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.
226777a5e07dSBarry Smith 
226877a5e07dSBarry Smith    Synopsis:
226977a5e07dSBarry Smith      #include <petscsys.h>
227077a5e07dSBarry Smith      PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
227177a5e07dSBarry Smith 
22727cdbe19fSJose E. Roman    Collective
22737cdbe19fSJose E. Roman 
227477a5e07dSBarry Smith    Input Parameters:
2275df05ca09SBarry Smith +  a - pointer to the input data to be reduced
2276df05ca09SBarry Smith .  c - the number of MPI data items in a and b
227787497f52SBarry Smith .  d - the MPI datatype, for example `MPI_INT`
227887497f52SBarry Smith .  e - the MPI operation, for example `MPI_SUM`
2279df05ca09SBarry Smith -  fcomm - the MPI communicator on which the operation occurs
228077a5e07dSBarry Smith 
228177a5e07dSBarry Smith    Output Parameter:
2282df05ca09SBarry Smith .  b - the reduced values
228377a5e07dSBarry Smith 
2284667f096bSBarry Smith    Level: developer
2285667f096bSBarry Smith 
2286e28ce29aSPatrick Sanan    Notes:
228787497f52SBarry Smith      In optimized mode this directly calls `MPI_Allreduce()`
228877a5e07dSBarry Smith 
2289df05ca09SBarry Smith      This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void.
2290df05ca09SBarry Smith 
229187497f52SBarry 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
2292df05ca09SBarry Smith 
2293db781477SPatrick Sanan .seealso: `MPI_Allreduce()`
229477a5e07dSBarry Smith M*/
22953ba16761SJacob Faibussowitsch   // clang-format off
22969371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \
22973ba16761SJacob Faibussowitsch   PetscMacroReturnStandard( \
22983ba16761SJacob Faibussowitsch     PetscMPIInt a_b1[6], a_b2[6]; \
22993ba16761SJacob Faibussowitsch     int _mpiu_allreduce_c_int = (int)(c); \
23003ba16761SJacob Faibussowitsch     a_b1[0] = -(PetscMPIInt)__LINE__; \
23013ba16761SJacob Faibussowitsch     a_b1[1] = -a_b1[0]; \
23023ba16761SJacob Faibussowitsch     a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \
23033ba16761SJacob Faibussowitsch     a_b1[3] = -a_b1[2]; \
23043ba16761SJacob Faibussowitsch     a_b1[4] = -(PetscMPIInt)(c); \
23053ba16761SJacob Faibussowitsch     a_b1[5] = -a_b1[4]; \
23063ba16761SJacob Faibussowitsch     \
23073ba16761SJacob Faibussowitsch     PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \
23083ba16761SJacob 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"); \
23093ba16761SJacob Faibussowitsch     PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); \
23103ba16761SJacob 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); \
23113ba16761SJacob Faibussowitsch     PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)));)
23123ba16761SJacob Faibussowitsch // clang-format on
2313b2566f29SBarry Smith #else
2314f3fa974cSJacob Faibussowitsch   #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm))))
2315b2566f29SBarry Smith #endif
2316b2566f29SBarry Smith 
2317b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
23188198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
23198198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
23202f065d89SBarry Smith #endif
23218198064fSBarry Smith 
2322cd88fca5SStefano Zampini /* this is a vile hack */
2323cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI)
23249371c9d4SSatish 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)
2325cd88fca5SStefano Zampini     #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
2326cd88fca5SStefano Zampini   #endif
2327961fb248SStefano Zampini #endif
2328cd88fca5SStefano Zampini 
232912801b39SBarry Smith /*
233060fbe2beSVaclav Hapla     List of external packages and queries on it
233160fbe2beSVaclav Hapla */
233260fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);
233360fbe2beSVaclav Hapla 
2334f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */
2335f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
2336f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
2337f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void);
23387a99bfcaSBarry Smith PETSC_EXTERN PetscBool      PCMPIServerActive;
2339fbf9dbe5SBarry Smith 
2340edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS
2341fbf9dbe5SBarry Smith 
2342d382aafbSBarry Smith #endif
2343