1d382aafbSBarry Smith /*
2d382aafbSBarry Smith This is the main PETSc include file (for C and C++). It is included by all
3d382aafbSBarry Smith other PETSc include files, so it almost never has to be specifically included.
447d993e7Ssuyashtn Portions of this code are under:
547d993e7Ssuyashtn Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
6d382aafbSBarry Smith */
7a4963045SJacob Faibussowitsch #pragma once
83ca90d2dSJacob Faibussowitsch
9958cab43SBarry Smith /*MC
10958cab43SBarry Smith PeOP - indicates an argument to a PETSc function is optional and one can pass `NULL` instead. This is used by the Fortran API generator
11958cab43SBarry Smith
12958cab43SBarry Smith Level: developer
13958cab43SBarry Smith
14958cab43SBarry Smith Example:
15958cab43SBarry Smith .vb
16958cab43SBarry Smith PetscErrorCode XXXX(Vec v, PeOp PetscObject obj, PeOp PetscInt *idx, PeOp PetscInt *array[])
17958cab43SBarry Smith .ve
18958cab43SBarry Smith
19958cab43SBarry Smith Notes:
20958cab43SBarry Smith This is not part of the PETSc public API and should only be used in PETSc source code.
21958cab43SBarry Smith
22958cab43SBarry Smith Put this in the function declaration in front of each variable that is optional
23958cab43SBarry Smith
24958cab43SBarry Smith Developer Note:
25958cab43SBarry Smith Shortened form of PETSc optional
26958cab43SBarry Smith
272a8381b2SBarry Smith .seealso: `PeNS`, `PeNSS`, `PetscCtxRt`, `PetscInitialize()`
28958cab43SBarry Smith M*/
29958cab43SBarry Smith #define PeOp
30958cab43SBarry Smith
31958cab43SBarry Smith /*MC
32958cab43SBarry Smith PeNS - indicates a function that does not use the PETSc standard arguments which make it easy to generate automatic language stubs for other languages
33958cab43SBarry Smith
34958cab43SBarry Smith Level: developer
35958cab43SBarry Smith
36958cab43SBarry Smith Notes:
37958cab43SBarry Smith This is not part of the PETSc public API and should only be used in PETSc source code.
38958cab43SBarry Smith
39958cab43SBarry Smith Put this at the end of the function declaration closing parenthesis
40958cab43SBarry Smith
41958cab43SBarry Smith Developer Note:
42958cab43SBarry Smith Shortened form of PETSc non-standard
43958cab43SBarry Smith
442a8381b2SBarry Smith .seealso: `PeOp`, `PeNSS`, `PetscCtxRt`, `PetscInitialize()`
45958cab43SBarry Smith M*/
46958cab43SBarry Smith #define PeNS
47958cab43SBarry Smith
48958cab43SBarry Smith /*MC
49958cab43SBarry Smith PeNSS - indicates a function that needs a special treatment in the C-side stub when generating the binding for other languages
50958cab43SBarry Smith
51958cab43SBarry Smith Level: developer
52958cab43SBarry Smith
53958cab43SBarry Smith Notes:
54958cab43SBarry Smith This is not part of the PETSc public API and should only be used in PETSc source code.
55958cab43SBarry Smith
56958cab43SBarry Smith Put this at the end of the function declaration closing parenthesis
57958cab43SBarry Smith
58958cab43SBarry Smith It is similar to PeNS; in Fortran it will generate the Fortran interface definition automatically but not the C stub, which should be added manually under the appropriate `ftn-custom` directory
59958cab43SBarry Smith
60958cab43SBarry Smith Developer Note:
61958cab43SBarry Smith Shortened form of PETSc non-standard stub
62958cab43SBarry Smith
632a8381b2SBarry Smith .seealso: `PeOp`, `PeNS`, `PetscCtxRt`, `PetscInitialize()`
64958cab43SBarry Smith M*/
65958cab43SBarry Smith #define PeNSS
66958cab43SBarry Smith
67d382aafbSBarry Smith /* ========================================================================== */
68d382aafbSBarry Smith /*
69d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is
701c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that
711c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules.
721c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same
731cc8b206SBarry Smith directory as the other PETSc include files.
74d382aafbSBarry Smith */
752c8e378dSBarry Smith #include <petscconf.h>
76100ffedbSJunchao Zhang #include <petscpkg_version.h>
771c77a0c5SBarry Smith #include <petscconf_poison.h>
782c8e378dSBarry Smith #include <petscfix.h>
79bde483f2SJacob Faibussowitsch #include <petscmacros.h>
8033bb201bSJacob Faibussowitsch
81ac09b921SBarry Smith /* SUBMANSEC = Sys */
82ac09b921SBarry Smith
8373fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS)
8473fca5a0SBarry Smith /*
8573fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001
8673fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS
8773fca5a0SBarry Smith */
88216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE)
8973fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L
9073fca5a0SBarry Smith #endif
91216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE)
9273fca5a0SBarry Smith #define _BSD_SOURCE
9373fca5a0SBarry Smith #endif
9407f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
9507f00807SSatish Balay #define _DEFAULT_SOURCE
9607f00807SSatish Balay #endif
97ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE)
98ea0fecefSShri Abhyankar #define _GNU_SOURCE
99ea0fecefSShri Abhyankar #endif
10073fca5a0SBarry Smith #endif
10173fca5a0SBarry Smith
102df4397b0SStefano Zampini #include <petscsystypes.h>
103df4397b0SStefano Zampini
104d382aafbSBarry Smith /* ========================================================================== */
105d382aafbSBarry Smith
106d382aafbSBarry Smith /*
107d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions.
108d382aafbSBarry Smith
109d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag
110d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE
111d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this
112d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include
113d382aafbSBarry Smith mpicxx.h directly in their code
114d382aafbSBarry Smith */
115fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX)
116d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1
117fa9e63e2SJed Brown #endif
118fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX)
119d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1
120fa9e63e2SJed Brown #endif
121e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI)
122e771154cSJed Brown #include <petsc/mpiuni/mpi.h>
123e771154cSJed Brown #else
1242c8e378dSBarry Smith #include <mpi.h>
125e771154cSJed Brown #endif
12665013866SBarry Smith
127d382aafbSBarry Smith /*
128a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time.
129a7886beaSBarry Smith This usually happens because
130a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or
131a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler
132a2df2f37SMin RK Note: with MPICH and OpenMPI, accept versions [x.y.z, x+1.0.0) as compatible
133a7886beaSBarry Smith */
134a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI)
135*beceaeb6SBarry Smith #if !defined(MPIUNI_H)
136a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
137a7886beaSBarry Smith #endif
1380f85934cSJunchao Zhang #elif defined(PETSC_HAVE_I_MPI)
13941f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION)
14041f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h"
1410f85934cSJunchao Zhang #elif I_MPI_NUMVERSION != PETSC_PKG_I_MPI_NUMVERSION
14241f4af4cSSatish 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"
14341f4af4cSSatish Balay #endif
1440f85934cSJunchao Zhang #elif defined(PETSC_HAVE_MVAPICH2)
14541f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION)
14641f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h"
1470f85934cSJunchao Zhang #elif MVAPICH2_NUMVERSION != PETSC_PKG_MVAPICH2_NUMVERSION
14841f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version"
14941f4af4cSSatish Balay #endif
150e3c15826SJunchao Zhang #elif defined(PETSC_HAVE_MPICH)
15141f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION)
152a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
153a2df2f37SMin RK #elif PETSC_PKG_MPICH_VERSION_GT(MPICH_NUMVERSION / 10000000, MPICH_NUMVERSION / 100000 % 100, MPICH_NUMVERSION / 1000 % 100)
154a2df2f37SMin RK #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using an older MPICH mpi.h version"
155a2df2f37SMin RK #elif PETSC_PKG_MPICH_VERSION_LT(MPICH_NUMVERSION / 10000000, 0, 0)
156a2df2f37SMin RK #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a newer major MPICH mpi.h version"
157a7886beaSBarry Smith #endif
158100ffedbSJunchao Zhang #elif defined(PETSC_HAVE_OPENMPI)
159a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION)
160a7886beaSBarry Smith #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h"
161a2df2f37SMin RK #elif PETSC_PKG_OPENMPI_VERSION_GT(OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION)
162a2df2f37SMin RK #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using an older Open MPI mpi.h version"
163a2df2f37SMin RK #elif PETSC_PKG_OPENMPI_VERSION_LT(OMPI_MAJOR_VERSION, 0, 0)
164a2df2f37SMin RK #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using a newer major Open MPI mpi.h version"
165a7886beaSBarry Smith #endif
166d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION)
167d97fd468SStefano Zampini #if !defined(MSMPI_VER)
168d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h"
169d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION)
170d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version"
171d97fd468SStefano Zampini #endif
172d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER)
173d97fd468SStefano Zampini #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of Open MPI, MS-MPI or a MPICH variant"
174a7886beaSBarry Smith #endif
175a7886beaSBarry Smith
176a7886beaSBarry Smith /*
1772981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
178d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution.
179d382aafbSBarry Smith */
180d382aafbSBarry Smith #include <stdio.h>
181d382aafbSBarry Smith
1827de69702SBarry Smith /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */
183d382aafbSBarry Smith #if !defined(MPIAPI)
184d382aafbSBarry Smith #define MPIAPI
185d382aafbSBarry Smith #endif
186d382aafbSBarry Smith
18793d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum);
1885440e5dcSBarry Smith #define MPIU_BOOL MPI_C_BOOL PETSC_DEPRECATED_MACRO(3, 24, 0, "MPI_C_BOOL", )
189e28ce29aSPatrick Sanan
190e28ce29aSPatrick Sanan /*MC
19187497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt`
192e28ce29aSPatrick Sanan
193667f096bSBarry Smith Level: beginner
194667f096bSBarry Smith
19538b83642SBarry Smith Note:
19687497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.
197e28ce29aSPatrick Sanan
19838b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
199e28ce29aSPatrick Sanan M*/
200e28ce29aSPatrick Sanan
2017cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;
202b7b8f77aSBarry Smith
203d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES)
204bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64
205d382aafbSBarry Smith #else
206d382aafbSBarry Smith #define MPIU_INT MPI_INT
207d382aafbSBarry Smith #endif
208d382aafbSBarry Smith
20938b83642SBarry Smith /*MC
21038b83642SBarry Smith MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount`
21138b83642SBarry Smith
21238b83642SBarry Smith Level: beginner
21338b83642SBarry Smith
21438b83642SBarry Smith Note:
21538b83642SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value.
21638b83642SBarry Smith
21738b83642SBarry Smith Developer Note:
21895bd0b28SBarry Smith It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed
21938b83642SBarry Smith
22038b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
22138b83642SBarry Smith M*/
22238b83642SBarry Smith #define MPIU_COUNT MPI_AINT
22338b83642SBarry Smith
224503cfb0cSBarry Smith /*
225503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI
226503cfb0cSBarry Smith */
22793d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t);
228d382aafbSBarry Smith
229d382aafbSBarry Smith /*
230d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change
231d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere
232d382aafbSBarry Smith */
233014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT;
234d382aafbSBarry Smith
235d382aafbSBarry Smith /*
236d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change
237d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere
238d382aafbSBarry Smith */
239014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR;
240d382aafbSBarry Smith
241d382aafbSBarry Smith /*
242dc07da0dSStefano Zampini Handle inclusion when using clang compiler with CUDA support
243dc07da0dSStefano Zampini __float128 is not available for the device
244dc07da0dSStefano Zampini */
245731341e5SJunchao Zhang #if defined(__clang__) && (defined(__CUDA_ARCH__) || defined(__HIPCC__))
246dc07da0dSStefano Zampini #define PETSC_SKIP_REAL___FLOAT128
247dc07da0dSStefano Zampini #endif
248dc07da0dSStefano Zampini
249dc07da0dSStefano Zampini /*
250d382aafbSBarry Smith Declare extern C stuff after including external header files
251d382aafbSBarry Smith */
252d382aafbSBarry Smith
2536edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
2548b49ba18SBarry Smith /*
255390e1bf2SBarry Smith Defines elementary mathematics functions and constants.
2568b49ba18SBarry Smith */
2578b49ba18SBarry Smith #include <petscmath.h>
2588b49ba18SBarry Smith
259d382aafbSBarry Smith /*MC
260667f096bSBarry Smith PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument
261d382aafbSBarry Smith
262d382aafbSBarry Smith Level: beginner
263d382aafbSBarry Smith
264e28ce29aSPatrick Sanan Note:
265667f096bSBarry Smith Accepted by many PETSc functions to not set a parameter and instead use a default value
266d382aafbSBarry Smith
26787497f52SBarry Smith Fortran Note:
268feaf08eaSBarry Smith Use `PETSC_NULL_INTEGER`, `PETSC_NULL_SCALAR` etc
269d382aafbSBarry Smith
270db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE`
271d382aafbSBarry Smith M*/
272f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR
273edd03b47SJacob Faibussowitsch #define PETSC_NULL PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR
274c528d872SBarry Smith
275d382aafbSBarry Smith /*MC
276b3480c81SBarry Smith PETSC_UNLIMITED - standard way of passing an integer or floating point parameter to indicate PETSc there is no bound on the value allowed
277557d4da8SBarry Smith
278557d4da8SBarry Smith Level: beginner
279557d4da8SBarry Smith
280b3480c81SBarry Smith Example Usage:
281b3480c81SBarry Smith .vb
282b3480c81SBarry Smith KSPSetTolerances(ksp, PETSC_CURRENT, PETSC_CURRENT, PETSC_UNLIMITED, PETSC_UNLIMITED);
283b3480c81SBarry Smith .ve
284b3480c81SBarry Smith indicates that the solver is allowed to take any number of iterations and will not stop early no matter how the residual gets.
285b3480c81SBarry Smith
286b3480c81SBarry Smith Fortran Note:
287b3480c81SBarry Smith Use `PETSC_UNLIMITED_INTEGER` or `PETSC_UNLIMITED_REAL`.
288b3480c81SBarry Smith
289b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DECIDE`
290557d4da8SBarry Smith M*/
291557d4da8SBarry Smith
292557d4da8SBarry Smith /*MC
293b3480c81SBarry Smith PETSC_DECIDE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value
294d382aafbSBarry Smith
295d382aafbSBarry Smith Level: beginner
296d382aafbSBarry Smith
297b3480c81SBarry Smith Example Usage:
298b3480c81SBarry Smith .vb
299b3480c81SBarry Smith VecSetSizes(ksp, PETSC_DECIDE, 10);
300b3480c81SBarry Smith .ve
301b3480c81SBarry Smith indicates that the global size of the vector is 10 and the local size will be automatically determined so that the sum of the
302b3480c81SBarry Smith local sizes is the global size, see `PetscSplitOwnership()`.
303b3480c81SBarry Smith
304b3480c81SBarry Smith Fortran Note:
305b3480c81SBarry Smith Use `PETSC_DECIDE_INTEGER` or `PETSC_DECIDE_REAL`.
306b3480c81SBarry Smith
30741aebf3eSJose E. Roman .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_UNLIMITED`
308b3480c81SBarry Smith M*/
309b3480c81SBarry Smith
310b3480c81SBarry Smith /*MC
311b3480c81SBarry Smith PETSC_DETERMINE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value
312b3480c81SBarry Smith
313b3480c81SBarry Smith Level: beginner
314b3480c81SBarry Smith
315b3480c81SBarry Smith Example Usage:
316b3480c81SBarry Smith .vb
317b3480c81SBarry Smith VecSetSizes(ksp, 10, PETSC_DETERMINE);
318b3480c81SBarry Smith .ve
319b3480c81SBarry Smith indicates that the local size of the vector is 10 and the global size will be automatically summing up all the local sizes.
320b3480c81SBarry Smith
321b3480c81SBarry Smith Note:
322b3480c81SBarry Smith Same as `PETSC_DECIDE`
323b3480c81SBarry Smith
324b3480c81SBarry Smith Fortran Note:
325b3480c81SBarry Smith Use `PETSC_DETERMINE_INTEGER` or `PETSC_DETERMINE_REAL`.
326b3480c81SBarry Smith
327e28ce29aSPatrick Sanan Developer Note:
32887497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for
32987497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value.
330557d4da8SBarry Smith
33141aebf3eSJose E. Roman .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`, `PETSC_UNLIMITED`
332d382aafbSBarry Smith M*/
333d382aafbSBarry Smith
334d382aafbSBarry Smith /*MC
335b3480c81SBarry Smith PETSC_CURRENT - standard way of indicating to an object not to change the current value of the parameter in the object
336557d4da8SBarry Smith
337557d4da8SBarry Smith Level: beginner
338557d4da8SBarry Smith
339b3480c81SBarry Smith Note:
340b3480c81SBarry Smith Use `PETSC_DECIDE` to use the value that was set by PETSc when the object's type was set
341557d4da8SBarry Smith
342b3480c81SBarry Smith Fortran Note:
343b3480c81SBarry Smith Use `PETSC_CURRENT_INTEGER` or `PETSC_CURRENT_REAL`.
344b3480c81SBarry Smith
34541aebf3eSJose E. Roman .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DEFAULT`, `PETSC_UNLIMITED`
346b3480c81SBarry Smith M*/
347b3480c81SBarry Smith
348b3480c81SBarry Smith /*MC
349b3480c81SBarry Smith PETSC_DEFAULT - deprecated, see `PETSC_CURRENT` and `PETSC_DETERMINE`
350b3480c81SBarry Smith
351b3480c81SBarry Smith Level: beginner
352b3480c81SBarry Smith
353b3480c81SBarry Smith Note:
354b3480c81SBarry Smith The name is confusing since it tells the object to continue to use the value it is using, not the default value when the object's type was set.
355b3480c81SBarry Smith
356b3480c81SBarry Smith Developer Note:
357b3480c81SBarry Smith Unfortunately this was used for two different purposes in the past, to actually trigger the use of a default value or to continue the
358b3480c81SBarry Smith use of currently set value (in, for example, `KSPSetTolerances()`.
359b3480c81SBarry Smith
36041aebf3eSJose E. Roman .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_CURRENT`, `PETSC_UNLIMITED`
361557d4da8SBarry Smith M*/
36205c2f48cSJacob Faibussowitsch
36305c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */
36405c2f48cSJacob Faibussowitsch #define PETSC_DECIDE (-1)
36505c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE
366b3480c81SBarry Smith #define PETSC_CURRENT (-2)
367b3480c81SBarry Smith #define PETSC_UNLIMITED (-3)
368b3480c81SBarry Smith /* PETSC_DEFAULT is deprecated in favor of PETSC_CURRENT for use in KSPSetTolerances() and similar functions */
369b3480c81SBarry Smith #define PETSC_DEFAULT PETSC_CURRENT
370557d4da8SBarry Smith
371557d4da8SBarry Smith /*MC
372af27ebaaSBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about.
373d382aafbSBarry Smith
374d382aafbSBarry Smith Level: beginner
375d382aafbSBarry Smith
376e28ce29aSPatrick Sanan Notes:
37787497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to
37887497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller)
37987497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling
380af27ebaaSBarry Smith `PetscInitialize()`, but after `MPI_Init()` has been called.
381a990b902SBarry Smith
382af27ebaaSBarry Smith The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()`
383a990b902SBarry Smith is called because it may not have a valid value yet.
384d382aafbSBarry Smith
385db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF`
386d382aafbSBarry Smith M*/
387014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
388d382aafbSBarry Smith
389d382aafbSBarry Smith /*MC
39087497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF`
391d382aafbSBarry Smith
392d382aafbSBarry Smith Level: beginner
393d382aafbSBarry Smith
39495bd0b28SBarry Smith Note:
39516a05f60SBarry Smith Do not USE/access or set this variable before `PetscInitialize()` has been called.
396a990b902SBarry Smith
397db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`
398d382aafbSBarry Smith M*/
399d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF
400d382aafbSBarry Smith
4016de5d289SStefano Zampini /*MC
402af27ebaaSBarry Smith PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`.
4036de5d289SStefano Zampini
404d598313aSBarry Smith No Fortran Support
405d598313aSBarry Smith
4066de5d289SStefano Zampini Level: beginner
4076de5d289SStefano Zampini
40895bd0b28SBarry Smith Note:
409d598313aSBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED` when the MPI implementation provides `MPI_Init_thread()`, otherwise it equals `MPI_THREAD_SINGLE`
4106de5d289SStefano Zampini
411db781477SPatrick Sanan .seealso: `PetscInitialize()`
4126de5d289SStefano Zampini M*/
4136de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
4146de5d289SStefano Zampini
415d598313aSBarry Smith /*MC
4160b4b7b1cSBarry Smith PetscBeganMPI - indicates if PETSc initialized MPI using `MPI_Init()` during `PetscInitialize()` or if MPI was already initialized with `MPI_Init()`
417d598313aSBarry Smith
418d598313aSBarry Smith Synopsis:
419d598313aSBarry Smith #include <petscsys.h>
420d598313aSBarry Smith PetscBool PetscBeganMPI;
421d598313aSBarry Smith
422d598313aSBarry Smith No Fortran Support
423d598313aSBarry Smith
424d598313aSBarry Smith Level: developer
425d598313aSBarry Smith
4260b4b7b1cSBarry Smith Note:
4270b4b7b1cSBarry Smith `MPI_Init()` can never be called after `PetscInitialize()`
4280b4b7b1cSBarry Smith
4290241b274SPierre Jolivet .seealso: `PetscInitialize()`, `PetscInitializeCalled`
430d598313aSBarry Smith M*/
431d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI;
432d598313aSBarry Smith
4338ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
434014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled;
435014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled;
4364cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
437d382aafbSBarry Smith
438014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
439014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
440014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
44157f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
44257f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);
443d382aafbSBarry Smith
44459e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
44559e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
44659e55d94SJunchao Zhang #endif
44759e55d94SJunchao Zhang
44871438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM)
44971438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem;
45071438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized;
45171438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
45271438e86SJunchao Zhang #endif
45371438e86SJunchao Zhang
454540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL)
455540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
456540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
457540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
458540e20f2SPierre Jolivet #endif
459540e20f2SPierre Jolivet
460d382aafbSBarry Smith /*MC
4610b4b7b1cSBarry Smith PetscMalloc - Allocates memory for use with PETSc. One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of `PetscMalloc()`
462d382aafbSBarry Smith
463eca87e8dSBarry Smith Synopsis:
464aaa7dc30SBarry Smith #include <petscsys.h>
465eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result)
466eca87e8dSBarry Smith
467eca87e8dSBarry Smith Not Collective
468eca87e8dSBarry Smith
469d382aafbSBarry Smith Input Parameter:
470d382aafbSBarry Smith . m - number of bytes to allocate
471d382aafbSBarry Smith
472d382aafbSBarry Smith Output Parameter:
473d382aafbSBarry Smith . result - memory allocated
474d382aafbSBarry Smith
475d382aafbSBarry Smith Level: beginner
476d382aafbSBarry Smith
47749d7da52SJed Brown Notes:
47849d7da52SJed Brown Memory is always allocated at least double aligned
479d382aafbSBarry Smith
48076d69608SSatish Balay It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.
4810b4b7b1cSBarry Smith However, the pointer should never be dereferenced or the program will crash.
482d382aafbSBarry Smith
4830b4b7b1cSBarry Smith Developer Note:
4840b4b7b1cSBarry Smith All the `PetscMallocN()` routines actually call `PetscMalloc()` behind the scenes.
4850b4b7b1cSBarry Smith
4860b4b7b1cSBarry Smith Except for data structures that store information about the PETSc options database all memory allocated by PETSc is
4870b4b7b1cSBarry Smith obtained with `PetscMalloc()` or `PetscCalloc()`
4880b4b7b1cSBarry Smith
4890b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscNew()`, `PetscCalloc()`
490d382aafbSBarry Smith M*/
491071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
492d382aafbSBarry Smith
493d382aafbSBarry Smith /*MC
494d5b43468SJose E. Roman PetscRealloc - Reallocates memory
4953221ece2SMatthew G. Knepley
4963221ece2SMatthew G. Knepley Synopsis:
4973221ece2SMatthew G. Knepley #include <petscsys.h>
4983221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result)
4993221ece2SMatthew G. Knepley
5003221ece2SMatthew G. Knepley Not Collective
5013221ece2SMatthew G. Knepley
5023221ece2SMatthew G. Knepley Input Parameters:
5033221ece2SMatthew G. Knepley + m - number of bytes to allocate
50492f119d6SBarry Smith - result - previous memory
5053221ece2SMatthew G. Knepley
5063221ece2SMatthew G. Knepley Output Parameter:
5073221ece2SMatthew G. Knepley . result - new memory allocated
5083221ece2SMatthew G. Knepley
5093221ece2SMatthew G. Knepley Level: developer
5103221ece2SMatthew G. Knepley
5110b4b7b1cSBarry Smith Notes:
5120b4b7b1cSBarry Smith `results` must have already been obtained with `PetscMalloc()`
5130b4b7b1cSBarry Smith
5143221ece2SMatthew G. Knepley Memory is always allocated at least double aligned
5153221ece2SMatthew G. Knepley
516db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
5173221ece2SMatthew G. Knepley M*/
5183221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
5193221ece2SMatthew G. Knepley
5203221ece2SMatthew G. Knepley /*MC
52187497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment
522d382aafbSBarry Smith
523d382aafbSBarry Smith Synopsis:
524aaa7dc30SBarry Smith #include <petscsys.h>
525d382aafbSBarry Smith void *PetscAddrAlign(void *addr)
526d382aafbSBarry Smith
527eca87e8dSBarry Smith Not Collective
528eca87e8dSBarry Smith
5292fe279fdSBarry Smith Input Parameter:
530eca87e8dSBarry Smith . addr - address to align (any pointer type)
531eca87e8dSBarry Smith
532d382aafbSBarry Smith Level: developer
533d382aafbSBarry Smith
534db781477SPatrick Sanan .seealso: `PetscMallocAlign()`
535d382aafbSBarry Smith M*/
536f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)))
537d382aafbSBarry Smith
538d382aafbSBarry Smith /*MC
5390b4b7b1cSBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`, similar to `PetscMalloc()`
5408f51dc47SJunchao Zhang
5418f51dc47SJunchao Zhang Synopsis:
5428f51dc47SJunchao Zhang #include <petscsys.h>
5438f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result)
5448f51dc47SJunchao Zhang
5458f51dc47SJunchao Zhang Not Collective
5468f51dc47SJunchao Zhang
5478f51dc47SJunchao Zhang Input Parameter:
5488f51dc47SJunchao Zhang . m - number of bytes to allocate
5498f51dc47SJunchao Zhang
5508f51dc47SJunchao Zhang Output Parameter:
5518f51dc47SJunchao Zhang . result - memory allocated
5528f51dc47SJunchao Zhang
5538f51dc47SJunchao Zhang Level: beginner
5548f51dc47SJunchao Zhang
5558f51dc47SJunchao Zhang Notes:
5568f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
5578f51dc47SJunchao Zhang
55876d69608SSatish Balay It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.
5598f51dc47SJunchao Zhang
5600b4b7b1cSBarry Smith However, the pointer should never be dereferenced or the program will crash.
5610b4b7b1cSBarry Smith
5620b4b7b1cSBarry Smith Developer Note:
5630b4b7b1cSBarry Smith All `PetscCallocN()` routines call `PetscCalloc()` behind the scenes.
5640b4b7b1cSBarry Smith
5650b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`
5668f51dc47SJunchao Zhang M*/
567b67aa78dSSatish Balay #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result))
5688f51dc47SJunchao Zhang
5698f51dc47SJunchao Zhang /*MC
57087497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`
571d382aafbSBarry Smith
572eca87e8dSBarry Smith Synopsis:
573aaa7dc30SBarry Smith #include <petscsys.h>
574785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1)
575785e854fSJed Brown
576785e854fSJed Brown Not Collective
577785e854fSJed Brown
578785e854fSJed Brown Input Parameter:
579390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero)
580785e854fSJed Brown
581785e854fSJed Brown Output Parameter:
5821fe1b817SJunchao Zhang . r1 - memory allocated
583785e854fSJed Brown
58416a05f60SBarry Smith Level: beginner
58516a05f60SBarry Smith
586e28ce29aSPatrick Sanan Note:
5874a21bc22SJames Wright This uses `sizeof()` of the memory type requested to determine the total memory to be allocated; therefore, you should not
5884a21bc22SJames Wright multiply the number of elements requested by the `sizeof()` the type. For example, use
58916a05f60SBarry Smith .vb
59016a05f60SBarry Smith PetscInt *id;
59116a05f60SBarry Smith PetscMalloc1(10,&id);
59216a05f60SBarry Smith .ve
593390e1bf2SBarry Smith not
59416a05f60SBarry Smith .vb
59516a05f60SBarry Smith PetscInt *id;
59616a05f60SBarry Smith PetscMalloc1(10*sizeof(PetscInt),&id);
59716a05f60SBarry Smith .ve
598390e1bf2SBarry Smith
59987497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.
600390e1bf2SBarry Smith
6014a21bc22SJames Wright The `PetscMalloc[N]()` and `PetscCalloc[N]()` take an argument of type `size_t`! However, most codes use `value`, computed via `int` or `PetscInt` variables. This can overflow in
6024a21bc22SJames Wright 32bit `int` computation - while computation in 64bit `size_t` would not overflow!
6034a21bc22SJames Wright It's best if any arithmetic that is done for size computations is done with `size_t` type - avoiding arithmetic overflow!
6044a21bc22SJames Wright
6054a21bc22SJames Wright `PetscMalloc[N]()` and `PetscCalloc[N]()` attempt to work-around this by casting the first variable to `size_t`.
6064a21bc22SJames Wright This works for most expressions, but not all, such as
6074a21bc22SJames Wright .vb
6084a21bc22SJames Wright PetscInt *id, a, b;
6094a21bc22SJames Wright PetscMalloc1(use_a_squared ? a * a * b : a * b, &id); // use_a_squared is cast to size_t, but a and b are still PetscInt
6104a21bc22SJames Wright PetscMalloc1(a + b * b, &id); // a is cast to size_t, but b * b is performed at PetscInt precision first due to order-of-operations
6114a21bc22SJames Wright .ve
6124a21bc22SJames Wright
6134a21bc22SJames Wright These expressions should either be avoided, or appropriately cast variables to `size_t`:
6144a21bc22SJames Wright .vb
6154a21bc22SJames Wright PetscInt *id, a, b;
6164a21bc22SJames Wright PetscMalloc1(use_a_squared ? (size_t)a * a * b : (size_t)a * b, &id); // Cast a to size_t before multiplication
6174a21bc22SJames Wright PetscMalloc1(b * b + a, &id); // b is automatically cast to size_t and order-of-operations ensures size_t precision is maintained
6184a21bc22SJames Wright .ve
6194a21bc22SJames Wright
620db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
621785e854fSJed Brown M*/
622b67aa78dSSatish Balay #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
623785e854fSJed Brown
624785e854fSJed Brown /*MC
62587497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`
6261795a4d1SJed Brown
6271795a4d1SJed Brown Synopsis:
628aaa7dc30SBarry Smith #include <petscsys.h>
6291795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1)
6301795a4d1SJed Brown
6311795a4d1SJed Brown Not Collective
6321795a4d1SJed Brown
6331795a4d1SJed Brown Input Parameter:
6341795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero)
6351795a4d1SJed Brown
6361795a4d1SJed Brown Output Parameter:
6371fe1b817SJunchao Zhang . r1 - memory allocated
6381795a4d1SJed Brown
63916a05f60SBarry Smith Level: beginner
64016a05f60SBarry Smith
64195bd0b28SBarry Smith Note:
64254c05997SPierre Jolivet See `PetscMalloc1()` for more details on usage.
643390e1bf2SBarry Smith
644db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
6451795a4d1SJed Brown M*/
646b67aa78dSSatish Balay #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))
6471795a4d1SJed Brown
6481795a4d1SJed Brown /*MC
64987497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`
650d382aafbSBarry Smith
651eca87e8dSBarry Smith Synopsis:
652aaa7dc30SBarry Smith #include <petscsys.h>
653dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
654eca87e8dSBarry Smith
655eca87e8dSBarry Smith Not Collective
656eca87e8dSBarry Smith
657d8d19677SJose E. Roman Input Parameters:
658d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
659dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero)
660d382aafbSBarry Smith
661d8d19677SJose E. Roman Output Parameters:
662d382aafbSBarry Smith + r1 - memory allocated in first chunk
663d382aafbSBarry Smith - r2 - memory allocated in second chunk
664d382aafbSBarry Smith
665d382aafbSBarry Smith Level: developer
666d382aafbSBarry Smith
667db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
668d382aafbSBarry Smith M*/
669b67aa78dSSatish Balay #define PetscMalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2))
670d382aafbSBarry Smith
671d382aafbSBarry Smith /*MC
67287497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`
673d382aafbSBarry Smith
674eca87e8dSBarry Smith Synopsis:
675aaa7dc30SBarry Smith #include <petscsys.h>
6761795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
677eca87e8dSBarry Smith
678eca87e8dSBarry Smith Not Collective
679eca87e8dSBarry Smith
680d8d19677SJose E. Roman Input Parameters:
681d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
6821795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero)
6831795a4d1SJed Brown
684d8d19677SJose E. Roman Output Parameters:
6851795a4d1SJed Brown + r1 - memory allocated in first chunk
6861795a4d1SJed Brown - r2 - memory allocated in second chunk
6871795a4d1SJed Brown
6881795a4d1SJed Brown Level: developer
6891795a4d1SJed Brown
690db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
6911795a4d1SJed Brown M*/
692b67aa78dSSatish Balay #define PetscCalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2))
6931795a4d1SJed Brown
6941795a4d1SJed Brown /*MC
69587497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`
696d382aafbSBarry Smith
697d382aafbSBarry Smith Synopsis:
698aaa7dc30SBarry Smith #include <petscsys.h>
699dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
700d382aafbSBarry Smith
701d382aafbSBarry Smith Not Collective
702d382aafbSBarry Smith
703d8d19677SJose E. Roman Input Parameters:
704d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
705d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
706dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero)
707d382aafbSBarry Smith
708d8d19677SJose E. Roman Output Parameters:
709d382aafbSBarry Smith + r1 - memory allocated in first chunk
710d382aafbSBarry Smith . r2 - memory allocated in second chunk
711d382aafbSBarry Smith - r3 - memory allocated in third chunk
712d382aafbSBarry Smith
713d382aafbSBarry Smith Level: developer
714d382aafbSBarry Smith
715db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
716d382aafbSBarry Smith M*/
717f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \
718b67aa78dSSatish Balay PetscMallocA(3, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3))
719d382aafbSBarry Smith
720d382aafbSBarry Smith /*MC
72187497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
722d382aafbSBarry Smith
723eca87e8dSBarry Smith Synopsis:
724aaa7dc30SBarry Smith #include <petscsys.h>
7251795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
726eca87e8dSBarry Smith
727eca87e8dSBarry Smith Not Collective
728eca87e8dSBarry Smith
729d8d19677SJose E. Roman Input Parameters:
730d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
731d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
7321795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero)
7331795a4d1SJed Brown
734d8d19677SJose E. Roman Output Parameters:
7351795a4d1SJed Brown + r1 - memory allocated in first chunk
7361795a4d1SJed Brown . r2 - memory allocated in second chunk
7371795a4d1SJed Brown - r3 - memory allocated in third chunk
7381795a4d1SJed Brown
7391795a4d1SJed Brown Level: developer
7401795a4d1SJed Brown
741db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
7421795a4d1SJed Brown M*/
743f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \
744b67aa78dSSatish Balay PetscMallocA(3, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3))
7451795a4d1SJed Brown
7461795a4d1SJed Brown /*MC
74787497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`
748d382aafbSBarry Smith
749d382aafbSBarry Smith Synopsis:
750aaa7dc30SBarry Smith #include <petscsys.h>
751dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
752d382aafbSBarry Smith
753d382aafbSBarry Smith Not Collective
754d382aafbSBarry Smith
755d8d19677SJose E. Roman Input Parameters:
756d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
757d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
758d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
759dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero)
760d382aafbSBarry Smith
761d8d19677SJose E. Roman Output Parameters:
762d382aafbSBarry Smith + r1 - memory allocated in first chunk
763d382aafbSBarry Smith . r2 - memory allocated in second chunk
764d382aafbSBarry Smith . r3 - memory allocated in third chunk
765d382aafbSBarry Smith - r4 - memory allocated in fourth chunk
766d382aafbSBarry Smith
767d382aafbSBarry Smith Level: developer
768d382aafbSBarry Smith
769db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
770d382aafbSBarry Smith M*/
7719371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
772b67aa78dSSatish Balay PetscMallocA(4, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4))
773d382aafbSBarry Smith
774d382aafbSBarry Smith /*MC
77587497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
776d382aafbSBarry Smith
777eca87e8dSBarry Smith Synopsis:
778aaa7dc30SBarry Smith #include <petscsys.h>
7791795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
780eca87e8dSBarry Smith
781eca87e8dSBarry Smith Not Collective
782eca87e8dSBarry Smith
783e28ce29aSPatrick Sanan Input Parameters:
784d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
785d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
786d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
7871795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero)
7881795a4d1SJed Brown
789e28ce29aSPatrick Sanan Output Parameters:
7901795a4d1SJed Brown + r1 - memory allocated in first chunk
7911795a4d1SJed Brown . r2 - memory allocated in second chunk
7921795a4d1SJed Brown . r3 - memory allocated in third chunk
7931795a4d1SJed Brown - r4 - memory allocated in fourth chunk
7941795a4d1SJed Brown
7951795a4d1SJed Brown Level: developer
7961795a4d1SJed Brown
797db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
7981795a4d1SJed Brown M*/
7999371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
800b67aa78dSSatish Balay PetscMallocA(4, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4))
8011795a4d1SJed Brown
8021795a4d1SJed Brown /*MC
80387497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`
804d382aafbSBarry Smith
805d382aafbSBarry Smith Synopsis:
806aaa7dc30SBarry Smith #include <petscsys.h>
807dcca6d9dSJed 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)
808d382aafbSBarry Smith
809d382aafbSBarry Smith Not Collective
810d382aafbSBarry Smith
811e28ce29aSPatrick Sanan Input Parameters:
812d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
813d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
814d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
815d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero)
816dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero)
817d382aafbSBarry Smith
818e28ce29aSPatrick Sanan Output Parameters:
819d382aafbSBarry Smith + r1 - memory allocated in first chunk
820d382aafbSBarry Smith . r2 - memory allocated in second chunk
821d382aafbSBarry Smith . r3 - memory allocated in third chunk
822d382aafbSBarry Smith . r4 - memory allocated in fourth chunk
823d382aafbSBarry Smith - r5 - memory allocated in fifth chunk
824d382aafbSBarry Smith
825d382aafbSBarry Smith Level: developer
826d382aafbSBarry Smith
827db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
828d382aafbSBarry Smith M*/
8299371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
830b67aa78dSSatish Balay PetscMallocA(5, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5))
831d382aafbSBarry Smith
832d382aafbSBarry Smith /*MC
83387497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
834d382aafbSBarry Smith
835eca87e8dSBarry Smith Synopsis:
836aaa7dc30SBarry Smith #include <petscsys.h>
8371795a4d1SJed 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)
838eca87e8dSBarry Smith
839eca87e8dSBarry Smith Not Collective
840eca87e8dSBarry Smith
841e28ce29aSPatrick Sanan Input Parameters:
842d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
843d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
844d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
845d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero)
8461795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero)
8471795a4d1SJed Brown
848e28ce29aSPatrick Sanan Output Parameters:
8491795a4d1SJed Brown + r1 - memory allocated in first chunk
8501795a4d1SJed Brown . r2 - memory allocated in second chunk
8511795a4d1SJed Brown . r3 - memory allocated in third chunk
8521795a4d1SJed Brown . r4 - memory allocated in fourth chunk
8531795a4d1SJed Brown - r5 - memory allocated in fifth chunk
8541795a4d1SJed Brown
8551795a4d1SJed Brown Level: developer
8561795a4d1SJed Brown
857db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
8581795a4d1SJed Brown M*/
8599371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
860b67aa78dSSatish Balay PetscMallocA(5, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5))
861d382aafbSBarry Smith
862d382aafbSBarry Smith /*MC
86387497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`
864d382aafbSBarry Smith
865d382aafbSBarry Smith Synopsis:
866aaa7dc30SBarry Smith #include <petscsys.h>
867dcca6d9dSJed 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)
868d382aafbSBarry Smith
869d382aafbSBarry Smith Not Collective
870d382aafbSBarry Smith
871e28ce29aSPatrick Sanan Input Parameters:
872d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
873d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
874d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
875d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero)
876d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero)
877dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero)
878d382aafbSBarry Smith
879e28ce29aSPatrick Sanan Output Parameteasr:
880d382aafbSBarry Smith + r1 - memory allocated in first chunk
881d382aafbSBarry Smith . r2 - memory allocated in second chunk
882d382aafbSBarry Smith . r3 - memory allocated in third chunk
883d382aafbSBarry Smith . r4 - memory allocated in fourth chunk
884d382aafbSBarry Smith . r5 - memory allocated in fifth chunk
885d382aafbSBarry Smith - r6 - memory allocated in sixth chunk
886d382aafbSBarry Smith
887d382aafbSBarry Smith Level: developer
888d382aafbSBarry Smith
889db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
890d382aafbSBarry Smith M*/
8919371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
892b67aa78dSSatish Balay PetscMallocA(6, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6))
893d382aafbSBarry Smith
894d382aafbSBarry Smith /*MC
89587497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
896d382aafbSBarry Smith
897eca87e8dSBarry Smith Synopsis:
898aaa7dc30SBarry Smith #include <petscsys.h>
8991795a4d1SJed 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)
900eca87e8dSBarry Smith
901eca87e8dSBarry Smith Not Collective
902eca87e8dSBarry Smith
903e28ce29aSPatrick Sanan Input Parameters:
904d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
905d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
906d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
907d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero)
908d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero)
9091795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero)
9101795a4d1SJed Brown
911e28ce29aSPatrick Sanan Output Parameters:
9121795a4d1SJed Brown + r1 - memory allocated in first chunk
9131795a4d1SJed Brown . r2 - memory allocated in second chunk
9141795a4d1SJed Brown . r3 - memory allocated in third chunk
9151795a4d1SJed Brown . r4 - memory allocated in fourth chunk
9161795a4d1SJed Brown . r5 - memory allocated in fifth chunk
9171795a4d1SJed Brown - r6 - memory allocated in sixth chunk
9181795a4d1SJed Brown
9191795a4d1SJed Brown Level: developer
9201795a4d1SJed Brown
921db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
9221795a4d1SJed Brown M*/
9239371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
924b67aa78dSSatish Balay PetscMallocA(6, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6))
9251795a4d1SJed Brown
9261795a4d1SJed Brown /*MC
92787497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`
928d382aafbSBarry Smith
929d382aafbSBarry Smith Synopsis:
930aaa7dc30SBarry Smith #include <petscsys.h>
931dcca6d9dSJed 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)
932d382aafbSBarry Smith
933d382aafbSBarry Smith Not Collective
934d382aafbSBarry Smith
935e28ce29aSPatrick Sanan Input Parameters:
936d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero)
937d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero)
938d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero)
939d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero)
940d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero)
941d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero)
942dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero)
943d382aafbSBarry Smith
944e28ce29aSPatrick Sanan Output Parameters:
945d382aafbSBarry Smith + r1 - memory allocated in first chunk
946d382aafbSBarry Smith . r2 - memory allocated in second chunk
947d382aafbSBarry Smith . r3 - memory allocated in third chunk
948d382aafbSBarry Smith . r4 - memory allocated in fourth chunk
949d382aafbSBarry Smith . r5 - memory allocated in fifth chunk
950d382aafbSBarry Smith . r6 - memory allocated in sixth chunk
951eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk
952d382aafbSBarry Smith
953d382aafbSBarry Smith Level: developer
954d382aafbSBarry Smith
955db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
956d382aafbSBarry Smith M*/
9579371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
958b67aa78dSSatish Balay PetscMallocA(7, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7))
959d382aafbSBarry Smith
960d382aafbSBarry Smith /*MC
96187497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
9621795a4d1SJed Brown
9631795a4d1SJed Brown Synopsis:
964aaa7dc30SBarry Smith #include <petscsys.h>
9651795a4d1SJed 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)
9661795a4d1SJed Brown
9671795a4d1SJed Brown Not Collective
9681795a4d1SJed Brown
969e28ce29aSPatrick Sanan Input Parameters:
9701795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero)
9711795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero)
9721795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero)
9731795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero)
9741795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero)
9751795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero)
9761795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero)
9771795a4d1SJed Brown
978e28ce29aSPatrick Sanan Output Parameters:
9791795a4d1SJed Brown + r1 - memory allocated in first chunk
9801795a4d1SJed Brown . r2 - memory allocated in second chunk
9811795a4d1SJed Brown . r3 - memory allocated in third chunk
9821795a4d1SJed Brown . r4 - memory allocated in fourth chunk
9831795a4d1SJed Brown . r5 - memory allocated in fifth chunk
9841795a4d1SJed Brown . r6 - memory allocated in sixth chunk
9851795a4d1SJed Brown - r7 - memory allocated in seventh chunk
9861795a4d1SJed Brown
9871795a4d1SJed Brown Level: developer
9881795a4d1SJed Brown
989db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
9901795a4d1SJed Brown M*/
9919371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
992b67aa78dSSatish Balay PetscMallocA(7, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7))
9931795a4d1SJed Brown
9941795a4d1SJed Brown /*MC
99587497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`
996d382aafbSBarry Smith
997eca87e8dSBarry Smith Synopsis:
998aaa7dc30SBarry Smith #include <petscsys.h>
999b00a9115SJed Brown PetscErrorCode PetscNew(type **result)
1000eca87e8dSBarry Smith
1001eca87e8dSBarry Smith Not Collective
1002eca87e8dSBarry Smith
1003d382aafbSBarry Smith Output Parameter:
10040b4b7b1cSBarry Smith . result - memory allocated, sized to match pointer `type`
1005d382aafbSBarry Smith
1006d382aafbSBarry Smith Level: beginner
1007d382aafbSBarry Smith
10080b4b7b1cSBarry Smith Developer Note:
10090b4b7b1cSBarry Smith Calls `PetscCalloc()` with the appropriate memory size obtained from `type`
10100b4b7b1cSBarry Smith
10110b4b7b1cSBarry Smith .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCall()`, `PetscCalloc1()`, `PetscMalloc1()`
1012d382aafbSBarry Smith M*/
1013b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b))
1014ad0619ddSBarry Smith
1015f4f49eeaSPierre Jolivet #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b)
1016d382aafbSBarry Smith
1017d382aafbSBarry Smith /*MC
1018d382aafbSBarry Smith PetscFree - Frees memory
1019d382aafbSBarry Smith
1020eca87e8dSBarry Smith Synopsis:
1021aaa7dc30SBarry Smith #include <petscsys.h>
1022eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory)
1023eca87e8dSBarry Smith
1024eca87e8dSBarry Smith Not Collective
1025eca87e8dSBarry Smith
1026d382aafbSBarry Smith Input Parameter:
102716a05f60SBarry Smith . memory - memory to free (the pointer is ALWAYS set to `NULL` upon success)
1028d382aafbSBarry Smith
1029d382aafbSBarry Smith Level: beginner
1030d382aafbSBarry Smith
103195bd0b28SBarry Smith Notes:
103287497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.
1033390e1bf2SBarry Smith
103416a05f60SBarry Smith It is safe to call `PetscFree()` on a `NULL` pointer.
1035d382aafbSBarry Smith
1036fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
1037d382aafbSBarry Smith M*/
10383ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS)))
1039d382aafbSBarry Smith
1040d382aafbSBarry Smith /*MC
104187497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`
1042d382aafbSBarry Smith
1043eca87e8dSBarry Smith Synopsis:
1044aaa7dc30SBarry Smith #include <petscsys.h>
1045eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2)
1046eca87e8dSBarry Smith
1047eca87e8dSBarry Smith Not Collective
1048eca87e8dSBarry Smith
1049e28ce29aSPatrick Sanan Input Parameters:
1050d382aafbSBarry Smith + memory1 - memory to free
1051d382aafbSBarry Smith - memory2 - 2nd memory to free
1052d382aafbSBarry Smith
1053d382aafbSBarry Smith Level: developer
1054d382aafbSBarry Smith
10557e17494fSJames Wright Notes:
105687497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()`
1057d382aafbSBarry Smith
10587e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc2()`
10597e17494fSJames Wright
1060db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
1061d382aafbSBarry Smith M*/
1062ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))
1063d382aafbSBarry Smith
1064d382aafbSBarry Smith /*MC
106587497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`
1066d382aafbSBarry Smith
1067eca87e8dSBarry Smith Synopsis:
1068aaa7dc30SBarry Smith #include <petscsys.h>
1069eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
1070eca87e8dSBarry Smith
1071eca87e8dSBarry Smith Not Collective
1072eca87e8dSBarry Smith
1073e28ce29aSPatrick Sanan Input Parameters:
1074d382aafbSBarry Smith + memory1 - memory to free
1075d382aafbSBarry Smith . memory2 - 2nd memory to free
1076d382aafbSBarry Smith - memory3 - 3rd memory to free
1077d382aafbSBarry Smith
1078d382aafbSBarry Smith Level: developer
1079d382aafbSBarry Smith
10807e17494fSJames Wright Notes:
108187497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()`
1082d382aafbSBarry Smith
10837e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc3()`
10847e17494fSJames Wright
1085db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
1086d382aafbSBarry Smith M*/
1087ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))
1088d382aafbSBarry Smith
1089d382aafbSBarry Smith /*MC
109087497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`
1091d382aafbSBarry Smith
1092eca87e8dSBarry Smith Synopsis:
1093aaa7dc30SBarry Smith #include <petscsys.h>
1094eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
1095eca87e8dSBarry Smith
1096eca87e8dSBarry Smith Not Collective
1097eca87e8dSBarry Smith
1098e28ce29aSPatrick Sanan Input Parameters:
1099d382aafbSBarry Smith + m1 - memory to free
1100d382aafbSBarry Smith . m2 - 2nd memory to free
1101d382aafbSBarry Smith . m3 - 3rd memory to free
1102d382aafbSBarry Smith - m4 - 4th memory to free
1103d382aafbSBarry Smith
1104d382aafbSBarry Smith Level: developer
1105d382aafbSBarry Smith
11067e17494fSJames Wright Notes:
110787497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()`
1108d382aafbSBarry Smith
11097e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc4()`
11107e17494fSJames Wright
1111db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
1112d382aafbSBarry Smith M*/
1113ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))
1114d382aafbSBarry Smith
1115d382aafbSBarry Smith /*MC
111687497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`
1117d382aafbSBarry Smith
1118eca87e8dSBarry Smith Synopsis:
1119aaa7dc30SBarry Smith #include <petscsys.h>
1120eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
1121eca87e8dSBarry Smith
1122eca87e8dSBarry Smith Not Collective
1123eca87e8dSBarry Smith
1124e28ce29aSPatrick Sanan Input Parameters:
1125d382aafbSBarry Smith + m1 - memory to free
1126d382aafbSBarry Smith . m2 - 2nd memory to free
1127d382aafbSBarry Smith . m3 - 3rd memory to free
1128d382aafbSBarry Smith . m4 - 4th memory to free
1129d382aafbSBarry Smith - m5 - 5th memory to free
1130d382aafbSBarry Smith
1131d382aafbSBarry Smith Level: developer
1132d382aafbSBarry Smith
11337e17494fSJames Wright Notes:
113487497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()`
1135d382aafbSBarry Smith
11367e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc5()`
11377e17494fSJames Wright
1138db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
1139d382aafbSBarry Smith M*/
1140ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))
1141d382aafbSBarry Smith
1142d382aafbSBarry Smith /*MC
114387497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`
1144d382aafbSBarry Smith
1145eca87e8dSBarry Smith Synopsis:
1146aaa7dc30SBarry Smith #include <petscsys.h>
1147eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1148eca87e8dSBarry Smith
1149eca87e8dSBarry Smith Not Collective
1150eca87e8dSBarry Smith
1151e28ce29aSPatrick Sanan Input Parameters:
1152d382aafbSBarry Smith + m1 - memory to free
1153d382aafbSBarry Smith . m2 - 2nd memory to free
1154d382aafbSBarry Smith . m3 - 3rd memory to free
1155d382aafbSBarry Smith . m4 - 4th memory to free
1156d382aafbSBarry Smith . m5 - 5th memory to free
1157d382aafbSBarry Smith - m6 - 6th memory to free
1158d382aafbSBarry Smith
1159d382aafbSBarry Smith Level: developer
1160d382aafbSBarry Smith
11617e17494fSJames Wright Notes:
116287497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()`
1163d382aafbSBarry Smith
11647e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc6()`
11657e17494fSJames Wright
1166db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
1167d382aafbSBarry Smith M*/
1168ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))
1169d382aafbSBarry Smith
1170d382aafbSBarry Smith /*MC
117187497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`
1172d382aafbSBarry Smith
1173eca87e8dSBarry Smith Synopsis:
1174aaa7dc30SBarry Smith #include <petscsys.h>
1175eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1176eca87e8dSBarry Smith
1177eca87e8dSBarry Smith Not Collective
1178eca87e8dSBarry Smith
1179e28ce29aSPatrick Sanan Input Parameters:
1180d382aafbSBarry Smith + m1 - memory to free
1181d382aafbSBarry Smith . m2 - 2nd memory to free
1182d382aafbSBarry Smith . m3 - 3rd memory to free
1183d382aafbSBarry Smith . m4 - 4th memory to free
1184d382aafbSBarry Smith . m5 - 5th memory to free
1185d382aafbSBarry Smith . m6 - 6th memory to free
1186d382aafbSBarry Smith - m7 - 7th memory to free
1187d382aafbSBarry Smith
1188d382aafbSBarry Smith Level: developer
1189d382aafbSBarry Smith
11907e17494fSJames Wright Notes:
119187497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()`
1192d382aafbSBarry Smith
11937e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc7()`
11947e17494fSJames Wright
1195db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
1196db781477SPatrick Sanan `PetscMalloc7()`
1197d382aafbSBarry Smith M*/
1198ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))
1199d382aafbSBarry Smith
1200ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
1201ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
1202071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
1203efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
12043221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
1205ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
120692f119d6SBarry 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 **));
1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1208d382aafbSBarry Smith
1209d382aafbSBarry Smith /*
1210c1706be6SHong 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.
1211c1706be6SHong Zhang */
1212c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1213c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
121431f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA)
121531f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
121631f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
121731f06eaaSHong Zhang #endif
121859af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
121959af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
122059af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
122159af0bd3SScott Kruger #endif
122259af0bd3SScott Kruger
1223a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
122436763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1225a5057860SBarry Smith
1226a5057860SBarry Smith /*
122766d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1228d382aafbSBarry Smith */
1229014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
123092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1233e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1234e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
123592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
123692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
1237efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
123892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
123992f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
1240608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1241608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);
1242d382aafbSBarry Smith
1243014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
1244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
1245014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *);
12468e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);
1247d382aafbSBarry Smith
1248d382aafbSBarry Smith /*
1249d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc
1250d382aafbSBarry Smith */
1251367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1252570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1253de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM;
1254014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX;
1255014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN;
1256d9822059SBarry Smith #else
1257de272c7aSSatish Balay #define MPIU_SUM MPI_SUM
1258d9822059SBarry Smith #define MPIU_MAX MPI_MAX
1259d9822059SBarry Smith #define MPIU_MIN MPI_MIN
1260d9822059SBarry Smith #endif
126162e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp;
126262e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
126362e5d2d2SJDBetteridge
1264a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16))
1265613bf2b2SPierre Jolivet /*MC
126616a05f60SBarry Smith MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with
126716a05f60SBarry Smith custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.
1268613bf2b2SPierre Jolivet
1269613bf2b2SPierre Jolivet Level: advanced
1270613bf2b2SPierre Jolivet
1271613bf2b2SPierre Jolivet Developer Note:
1272613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM`
1273613bf2b2SPierre Jolivet
1274613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
1275613bf2b2SPierre Jolivet M*/
12769e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
1277613bf2b2SPierre Jolivet #endif
1278eb3f98d2SBarry Smith
1279639ff905SBarry Smith /*
128049abdd8aSBarry Smith These are so that in extern C code we can cast function pointers to non-extern C
128149abdd8aSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++
128249abdd8aSBarry Smith */
128349abdd8aSBarry Smith
128449abdd8aSBarry Smith /*S
128557d50842SBarry Smith PetscVoidFn - A prototype of a `void fn(void)` function
128649abdd8aSBarry Smith
128757d50842SBarry Smith Level: advanced
128849abdd8aSBarry Smith
128949abdd8aSBarry Smith Notes:
129057d50842SBarry Smith `PetscVoidFn *` plays the role of `void *` for function pointers in the PETSc API that do not return an error code.
129157d50842SBarry Smith It is used where a function pointer is needed but it is not possible to use the full prototype of the function.
129257d50842SBarry Smith
129357d50842SBarry Smith `PetscErrorCodeFn` is similar to `PetscVoidFn` but should be used when the function returns a `PetscErrorCode`
129457d50842SBarry Smith
129549abdd8aSBarry Smith The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *.
129649abdd8aSBarry Smith
129749abdd8aSBarry Smith The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **.
129849abdd8aSBarry Smith
129957d50842SBarry Smith .seealso: `PetscErrorCodeFn`, `PetscObject`, `PetscObjectDestroy()`
130049abdd8aSBarry Smith S*/
1301348d23efSPierre Jolivet PETSC_EXTERN_TYPEDEF typedef void PetscVoidFn(void);
130249abdd8aSBarry Smith
130349abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn *PetscVoidFunction;
130449abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction;
130549abdd8aSBarry Smith
130649abdd8aSBarry Smith /*S
1307453a69bbSBarry Smith PetscErrorCodeFn - a function typedef that represents abstractly a function that returns a PETSc error code
1308453a69bbSBarry Smith and takes any number of arguments. Since C/C++ has no way to express this concept, it is implemented as `void (fn)(void)`.
130949abdd8aSBarry Smith
131057d50842SBarry Smith Level: advanced
131149abdd8aSBarry Smith
131249abdd8aSBarry Smith Notes:
131357d50842SBarry Smith `PetscErrorCodeFn *` plays the role of `void *` for function pointers in the PETSc API that return an error code.
131457d50842SBarry Smith It is used where a function pointer is needed but it is not possible to use the full prototype of the function,
131557d50842SBarry Smith for example `VecSetOperation()`.
131657d50842SBarry Smith
131757d50842SBarry Smith `PetscVoidFn` is similar to `PetscErrorCodeFn` but should be used when the function does not return a `PetscErrorCode`.
131857d50842SBarry Smith
131949abdd8aSBarry Smith The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *.
132049abdd8aSBarry Smith
1321453a69bbSBarry Smith Developer Notes:
1322453a69bbSBarry Smith This function type is equivalent to `PetscVoidFn`*.
1323453a69bbSBarry Smith
1324453a69bbSBarry Smith At the C/C++ syntax level this construct adds nothing of value to the PETSc source code. It provides a way, at the abstract
1325453a69bbSBarry Smith PETSc API level, to indicate specifically functions that return PETSc error codes as opposed to any C/C++ function.
1326453a69bbSBarry Smith
132757d50842SBarry Smith .seealso: `PetscVoidFn`, `PetscObject`, `PetscObjectDestroy()`, `VecSetOperation()`
132849abdd8aSBarry Smith S*/
1329453a69bbSBarry Smith PETSC_EXTERN_TYPEDEF typedef void PetscErrorCodeFn(void);
133049abdd8aSBarry Smith
133149abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction;
133249abdd8aSBarry Smith
133349abdd8aSBarry Smith /*
1334639ff905SBarry Smith Defines PETSc error handling.
1335639ff905SBarry Smith */
13367233ce55SJed Brown #include <petscerror.h> // IWYU pragma: export
1337d382aafbSBarry Smith
1338660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */
1339660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
1340660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *);
1341660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int);
1342660278c0SBarry Smith
1343835f2295SStefano Zampini #define PETSC_SMALLEST_CLASSID 1211211
1344014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID;
1345014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID;
1346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
134781256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
134881256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);
134981256985SMatthew G. Knepley
1350d382aafbSBarry Smith /*
1351d382aafbSBarry Smith Routines that get memory usage information from the OS
1352d382aafbSBarry Smith */
1353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1354014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1356b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1357d382aafbSBarry Smith
1358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1359d382aafbSBarry Smith
1360d382aafbSBarry Smith /*
1361d382aafbSBarry Smith Initialization of PETSc
1362d382aafbSBarry Smith */
1363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
1364ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char *[], const char[], const char[]);
1365014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1368014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1370014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
1371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1373d382aafbSBarry Smith
1374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void);
1375607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
13764bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void);
1377d382aafbSBarry Smith
1378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
1379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);
1382d382aafbSBarry Smith
1383d382aafbSBarry Smith /*
1384d382aafbSBarry Smith Functions that can act on any PETSc object.
1385d382aafbSBarry Smith */
1386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
1387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
1388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
1389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
1390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
1391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
1392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
1393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
1394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
1395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
1396014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1397014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
1398014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1399014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
1400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
1401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
1402014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
140357d50842SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], PetscErrorCodeFn *);
140457d50842SBarry Smith #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscErrorCodeFn *)(__VA_ARGS__))
1405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1406014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
14070eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
14080eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
1409014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);
1410d382aafbSBarry Smith
1411b3480c81SBarry Smith /*MC
1412b3480c81SBarry Smith PetscObjectParameterSetDefault - sets a parameter default value in a `PetscObject` to a new default value.
1413b3480c81SBarry Smith If the current value matches the old default value, then the current value is also set to the new value.
1414b3480c81SBarry Smith
1415b3480c81SBarry Smith No Fortran Support
1416b3480c81SBarry Smith
1417b3480c81SBarry Smith Synopsis:
1418b3480c81SBarry Smith #include <petscsys.h>
1419b3480c81SBarry Smith PetscBool PetscObjectParameterSetDefault(PetscObject obj, char* NAME, PetscReal value);
1420b3480c81SBarry Smith
1421b3480c81SBarry Smith Input Parameters:
1422b3480c81SBarry Smith + obj - the `PetscObject`
1423b3480c81SBarry Smith . NAME - the name of the parameter, unquoted
1424b3480c81SBarry Smith - value - the new value
1425b3480c81SBarry Smith
1426b3480c81SBarry Smith Level: developer
1427b3480c81SBarry Smith
1428b3480c81SBarry Smith Notes:
1429b3480c81SBarry Smith The defaults for an object are the values set when the object's type is set.
1430b3480c81SBarry Smith
1431b3480c81SBarry Smith This should only be used in object constructors, such as, `SNESCreate_NGS()`.
1432b3480c81SBarry Smith
1433b3480c81SBarry Smith This only works for parameters that are declared in the struct with `PetscObjectParameterDeclare()`
1434b3480c81SBarry Smith
1435b3480c81SBarry Smith .seealso: `PetscObjectParameterDeclare()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
1436b3480c81SBarry Smith M*/
1437b3480c81SBarry Smith #define PetscObjectParameterSetDefault(obj, NAME, value) \
1438b3480c81SBarry Smith do { \
1439b3480c81SBarry Smith if (obj->NAME == obj->default_##NAME) obj->NAME = value; \
1440b3480c81SBarry Smith obj->default_##NAME = value; \
1441b3480c81SBarry Smith } while (0)
1442b3480c81SBarry Smith
1443b3480c81SBarry Smith /*MC
1444b3480c81SBarry Smith PetscObjectParameterDeclare - declares a parameter in a `PetscObject` and a location to store its default
1445b3480c81SBarry Smith
1446b3480c81SBarry Smith No Fortran Support
1447b3480c81SBarry Smith
1448b3480c81SBarry Smith Synopsis:
1449b3480c81SBarry Smith #include <petscsys.h>
1450b3480c81SBarry Smith PetscBool PetscObjectParameterDeclare(type, char* NAME)
1451b3480c81SBarry Smith
1452b3480c81SBarry Smith Input Parameters:
1453b3480c81SBarry Smith + type - the type of the parameter, for example `PetscInt`
1454b3480c81SBarry Smith - NAME - the name of the parameter, unquoted
1455b3480c81SBarry Smith
1456b3480c81SBarry Smith Level: developer.
1457b3480c81SBarry Smith
1458b3480c81SBarry Smith .seealso: `PetscObjectParameterSetDefault()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
1459b3480c81SBarry Smith M*/
1460b3480c81SBarry Smith #define PetscObjectParameterDeclare(type, NAME) type NAME, default_##NAME
1461d476b948SAlex Lindsay #define PetscObjectParameterDeclarePtr(type, NAME) type *NAME, *default_##NAME
1462b3480c81SBarry Smith
14632a8381b2SBarry Smith /*MC
14642a8381b2SBarry Smith PetscCtx - indicates an argument that can be a pointer to any C struct (or Fortran derived type).
14652a8381b2SBarry Smith
14662a8381b2SBarry Smith Level: developer
14672a8381b2SBarry Smith
14682a8381b2SBarry Smith Notes:
14692a8381b2SBarry Smith This should not be used for arrays of unknown type.
14702a8381b2SBarry Smith
14712a8381b2SBarry Smith Fortran Notes:
14722a8381b2SBarry Smith A Fortran code that calls a function with a `PetscCtx` argument would declare the variable `ctx` with
14732a8381b2SBarry Smith .vb
14742a8381b2SBarry Smith type(AppType) :: ctx
14752a8381b2SBarry Smith .ve
14762a8381b2SBarry Smith where `AppType` is a Fortran derived type. Or the argument can be a `PetscObject`.
14772a8381b2SBarry Smith
14782a8381b2SBarry Smith Developer Note:
14792a8381b2SBarry Smith `PetscCtx` is used instead of `void *` in PETSc code to enhance the clarity of the PETSc source code since `void *` serves so many different roles.
14802a8381b2SBarry Smith The getAPI() code processor also uses the variable type to generate correct bindings for other languages.
14812a8381b2SBarry Smith
14822a8381b2SBarry Smith .seealso: [](sec_fortran_context), `PetscCtxRt`, PetscCtxDestroyFn()`, `PeOp`, `PeNS`, `PetscInitialize()`, `DMGetApplicationContext()`,
14832a8381b2SBarry Smith `DMSetApplicationContextDestroy()`
14842a8381b2SBarry Smith M*/
14852a8381b2SBarry Smith typedef void *PetscCtx;
14862a8381b2SBarry Smith
14872a8381b2SBarry Smith /*MC
14882a8381b2SBarry Smith PetscCtxRt - indicates an argument that returns a pointer to a C struct (or Fortran derived type) which is generally an application context
14892a8381b2SBarry Smith
14902a8381b2SBarry Smith Level: developer
14912a8381b2SBarry Smith
14922a8381b2SBarry Smith Notes:
14932a8381b2SBarry Smith A PETSc object (in C or Fortran) can be used as a PETSc context
14942a8381b2SBarry Smith
14952a8381b2SBarry Smith This should not be used for functions that return pointers to arrays of unknown type. Thus it is used for, for example,
14962a8381b2SBarry Smith `KSPGetApplicationContext()` but not used for `DMNetworkGetComponent()`
14972a8381b2SBarry Smith
14982a8381b2SBarry Smith A PETSc object (in C or Fortran) can be used as a PETSc context
14992a8381b2SBarry Smith
15002a8381b2SBarry Smith It is also used for functions that destroy an application context. For example, the destroy function passed to `DMSetApplicationContextDestroy()`
15012a8381b2SBarry Smith which has a prototype of `PetscCtxDestroyFn()`
15022a8381b2SBarry Smith
15032a8381b2SBarry Smith This typedef is not part of the PETSc public API and should only be used in PETSc source code.
15042a8381b2SBarry Smith
15052a8381b2SBarry Smith For pointers to arrays of unknown type and for functions that return PETSc internal objects that are opaque to users, such
15062a8381b2SBarry Smith as `KSPMonitorDynamicToleranceCreate()` a `void **` should be used.
15072a8381b2SBarry Smith
15082a8381b2SBarry Smith Fortran Notes:
15092a8381b2SBarry Smith A Fortran code that calls a function with a `PetscCtxRt` argument must declare the variable `ctx` with
15102a8381b2SBarry Smith .vb
15112a8381b2SBarry Smith type(AppType), pointer :: ctx
15122a8381b2SBarry Smith .ve
15132a8381b2SBarry Smith where `AppType` is a Fortran derived type.
15142a8381b2SBarry Smith
15152a8381b2SBarry Smith If one passes a PETSc function with a `PetscCtxRt` argument as an argument in Fortran one must use the function named suffixed with `Cptr`,
15162a8381b2SBarry Smith for example `KSPConvergedDefaultDestroyCptr`, see src/ksp/ksp/tutorials/ex1f.F90.
15172a8381b2SBarry Smith
15182a8381b2SBarry Smith Developer Notes:
15192a8381b2SBarry Smith C++ compilers generate a warning or error if one passes a pointer to a pointer to a specific type (instead of `void`), for example,
15202a8381b2SBarry Smith .vb
15212a8381b2SBarry Smith extern calledfunction(void **);
15222a8381b2SBarry Smith SomeCtx *ctx;
15232a8381b2SBarry Smith calledfunction(&ctx); << warning that it is passing a pointer to a pointer to a SomeCtx instead of a void **
15242a8381b2SBarry Smith .ve
15252a8381b2SBarry Smith By using the common practice of prototyping the function as
15262a8381b2SBarry Smith .vb
15272a8381b2SBarry Smith extern calledfunction(void *);
15282a8381b2SBarry Smith .ve
15292a8381b2SBarry Smith the warning message is averted.
15302a8381b2SBarry Smith
15312a8381b2SBarry Smith `PetscCtxRt` is used instead of `void *` in PETSc code to enhance the clarity of the PETSc source code since `void *` serves so many different roles.
15322a8381b2SBarry Smith The getAPI() code processor also uses the variable type to generate correct bindings for other languages.
15332a8381b2SBarry Smith
15342a8381b2SBarry Smith The Fortran C stub and Fortran interface definition generated for functions with a `PetscCtxRt` argument are the C function name suffixed with
15352a8381b2SBarry Smith `Cptr`, for example `KSPConvergedDefaultDestroyCptr`. The Fortran user API is a macro with the original C funtion name, for example,
15362a8381b2SBarry Smith `KSPConvergedDefaultDestroy` that calls the `KSPConvergedDefaultDestroyCptr` version and then calls `c_f_pointer()` to handle the equivalent of a `void**` cast
15372a8381b2SBarry Smith to the users Fortran derived type argument.
15382a8381b2SBarry Smith
15392a8381b2SBarry Smith .seealso: [](sec_fortran_context), `PetscCtx`, `PetscCtxDestroyFn()`, `PeOp`, `PeNS`, `PetscInitialize()`, `DMGetApplicationContext()`,
15402a8381b2SBarry Smith `DMSetApplicationContextDestroy()`
15412a8381b2SBarry Smith M*/
15422a8381b2SBarry Smith typedef void *PetscCtxRt;
15432a8381b2SBarry Smith
15442a8381b2SBarry Smith /*S
15452a8381b2SBarry Smith PetscCtxDestroyFn - A prototype of a `PetscErrorCode (*)(PetscCtxRt)` function that is used to free application contexts
15462a8381b2SBarry Smith
15472a8381b2SBarry Smith Level: intermediate
15482a8381b2SBarry Smith
15492a8381b2SBarry Smith Notes:
15502a8381b2SBarry Smith Used in the prototype of functions such as `DMSetApplicationContextDestroy()`
15512a8381b2SBarry Smith
15522a8381b2SBarry Smith The function argument is a `PetscCtxRt` which is psychologically equivalent to a `void **` meaning that this function is called with a pointer to
15532a8381b2SBarry Smith the application context (which is itself a pointer) thus the destroy implementation must first reference the context via, for example,
15542a8381b2SBarry Smith `*(AppCtx **)arg`. Note that syntactically `PetscCtxRt` is defined as a `void *`, this is because C++ does
15552a8381b2SBarry Smith not accept passing a pointer to a pointer to a `void**` but it does accept passing a pointer to a pointer to `void *`.
15562a8381b2SBarry Smith
15572a8381b2SBarry Smith PETSc destroy functions take the address of the context (rather than just the context) so that that the destroy function can "zero the pointer" when
15582a8381b2SBarry Smith appropriate, preventing accidental later use of a dangling pointer.
15592a8381b2SBarry Smith
15602a8381b2SBarry Smith .seealso: `PetscObject`, `PetscCtxDestroyDefault()`, `PetscObjectDestroy()`, `DMSetApplicationContextDestroy()`
15612a8381b2SBarry Smith S*/
15622a8381b2SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode PetscCtxDestroyFn(PetscCtxRt);
15632a8381b2SBarry Smith
15642a8381b2SBarry Smith PETSC_EXTERN PetscCtxDestroyFn PetscCtxDestroyDefault;
PetscContainerCtxDestroyDefault(PetscCtxRt a)15652a8381b2SBarry Smith PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscCtxDestroyDefault()", ) static inline PetscErrorCode PetscContainerCtxDestroyDefault(PetscCtxRt a)
15662a8381b2SBarry Smith {
15672a8381b2SBarry Smith return PetscCtxDestroyDefault(a);
15682a8381b2SBarry Smith }
15692a8381b2SBarry Smith
15702a8381b2SBarry Smith PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscBool *);
15712a8381b2SBarry Smith
1572665c2dedSJed Brown #include <petscviewertypes.h>
1573639ff905SBarry Smith #include <petscoptions.h>
1574639ff905SBarry Smith
1575608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
1576608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);
1577608c71bfSMatthew G. Knepley
1578ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject[], PetscInt *, PetscInt *);
15790633abcbSJed Brown
1580c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
1581dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
1582639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
158357d50842SBarry Smith #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscErrorCodeFn **)(fptr))
15840cd8b6e2SStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectHasFunction(PetscObject, const char[], PetscBool *);
158557d50842SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], PetscErrorCodeFn **);
1586014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
1587014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
1588014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
1589014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
1590014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
1591014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1592014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1593685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
1594014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1595014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
1596013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
15974099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
1598014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1599b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1600014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1601014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1602d382aafbSBarry Smith
1603e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
16047aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1605e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1606e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
1607e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1608e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1609e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1610e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void);
1611e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void);
1612e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1613e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
161415681b3cSBarry Smith
1615ec7429eaSBarry Smith #else
16163ba16761SJacob Faibussowitsch #define PetscSAWsBlock() PETSC_SUCCESS
16173ba16761SJacob Faibussowitsch #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS
16183ba16761SJacob Faibussowitsch #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS
16193ba16761SJacob Faibussowitsch #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS
16203ba16761SJacob Faibussowitsch #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS
16213ba16761SJacob Faibussowitsch #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS
16223ba16761SJacob Faibussowitsch #define PetscStackViewSAWs() PETSC_SUCCESS
16233ba16761SJacob Faibussowitsch #define PetscStackSAWsViewOff() PETSC_SUCCESS
1624e04113cfSBarry Smith #define PetscStackSAWsTakeAccess()
1625e04113cfSBarry Smith #define PetscStackSAWsGrantAccess()
162615681b3cSBarry Smith
1627ec7429eaSBarry Smith #endif
1628b90c6cbeSBarry Smith
162982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
163082b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
163182b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
163257d50842SBarry Smith PETSC_EXTERN PetscErrorCode PetscDLAddr(PetscVoidFn *, char *[]);
1633ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char *[]);
16347d5d4d99SBarry Smith
1635a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);
1636a64a8e02SBarry Smith
1637dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
16384bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer);
1639ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, const char *[]);
1640140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
1641140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
1642ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, const char *[], PetscBool *);
1643140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
1644140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
1645140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);
1646d382aafbSBarry Smith
1647d382aafbSBarry Smith /*
1648503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic
1649d382aafbSBarry Smith link libraries that will be loaded as needed.
1650d382aafbSBarry Smith */
1651a240a19fSJed Brown
165257d50842SBarry Smith #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscErrorCodeFn *)(fptr))
165357d50842SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscErrorCodeFn *);
1654140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
16550e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
165657d50842SBarry Smith #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscErrorCodeFn **)(fptr))
165757d50842SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscErrorCodeFn **);
165844ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
1659140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
1660140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
1661140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
16622e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
16632e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);
1664d382aafbSBarry Smith
1665014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
1666014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
1667014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
1668014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
1669014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1670014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
1671014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
1672014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1673d382aafbSBarry Smith
1674d382aafbSBarry Smith /*
1675d382aafbSBarry Smith Useful utility routines
1676d382aafbSBarry Smith */
1677014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
1678014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
1679d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
1680014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
1681014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
1682014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1683014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
168458b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
168558b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);
1686d382aafbSBarry Smith
168764ac3b0dSPatrick Sanan /*MC
168887497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool`
1689503cfb0cSBarry Smith
169064ac3b0dSPatrick Sanan Level: beginner
169164ac3b0dSPatrick Sanan
1692a1cb98faSBarry Smith Note:
1693a1cb98faSBarry Smith This is useful in cases like
1694a1cb98faSBarry Smith .vb
1695a1cb98faSBarry Smith int *a;
1696a1cb98faSBarry Smith PetscBool flag = PetscNot(a)
1697a1cb98faSBarry Smith .ve
1698a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.
1699a1cb98faSBarry Smith
1700a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
170164ac3b0dSPatrick Sanan M*/
1702d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1703503cfb0cSBarry Smith
1704d382aafbSBarry Smith /*MC
1705d382aafbSBarry Smith PetscHelpPrintf - Prints help messages.
1706d382aafbSBarry Smith
1707d382aafbSBarry Smith Synopsis:
1708aaa7dc30SBarry Smith #include <petscsys.h>
1709659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1710d382aafbSBarry Smith
17117cdbe19fSJose E. Roman Not Collective, only applies on MPI rank 0; No Fortran Support
17127cdbe19fSJose E. Roman
1713d382aafbSBarry Smith Input Parameters:
1714659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed
1715d382aafbSBarry Smith . format - the usual printf() format string
1716659f7ba0SBarry Smith - args - arguments to be printed
1717d382aafbSBarry Smith
1718d382aafbSBarry Smith Level: developer
1719d382aafbSBarry Smith
172095bd0b28SBarry Smith Notes:
1721659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1722659f7ba0SBarry Smith
1723659f7ba0SBarry Smith To use, write your own function, for example,
172416a05f60SBarry Smith .vb
172516a05f60SBarry Smith PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
172616a05f60SBarry Smith {
172716a05f60SBarry Smith PetscFunctionReturn(PETSC_SUCCESS);
172816a05f60SBarry Smith }
172916a05f60SBarry Smith .ve
1730d5b43468SJose E. Roman then do the assignment
1731af27ebaaSBarry Smith .vb
1732af27ebaaSBarry Smith PetscHelpPrintf = mypetschelpprintf;
1733af27ebaaSBarry Smith .ve
1734af27ebaaSBarry Smith
173587497f52SBarry Smith You can do the assignment before `PetscInitialize()`.
1736659f7ba0SBarry Smith
173787497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`.
1738d382aafbSBarry Smith
173916a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()`
1740d382aafbSBarry Smith M*/
17413ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1742d382aafbSBarry Smith
1743fcfd50ebSBarry Smith /*
1744fcfd50ebSBarry Smith Defines PETSc profiling.
1745fcfd50ebSBarry Smith */
17462c8e378dSBarry Smith #include <petsclog.h>
1747fcfd50ebSBarry Smith
1748fcfd50ebSBarry Smith /*
1749fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing
1750fcfd50ebSBarry Smith */
1751014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
1752014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
1753014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
17543ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1755c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *);
17563ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
17573ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
17583ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
17591b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);
1760fcfd50ebSBarry Smith
17613ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
17623ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
17633ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1764d382aafbSBarry Smith
1765d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
1766d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);
1767d781fa04SBarry Smith
1768014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
1769016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
177074ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1771d382aafbSBarry Smith
17723ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
17733ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
17740ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
1775014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
1776014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
1777014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);
1778d382aafbSBarry Smith
1779014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID;
1780ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void *);
1781014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
1782014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
1783014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
178449abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerSetCtxDestroy(PetscContainer, PetscCtxDestroyFn *);
178549abdd8aSBarry Smith PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscContainerSetCtxDestroy()", ) PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
178649abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerCompose(PetscObject, const char *name, void *, PetscCtxDestroyFn *);
17872a8381b2SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerQuery(PetscObject, const char *, PetscCtxRt);
178849abdd8aSBarry Smith
1789d382aafbSBarry Smith /*
1790d382aafbSBarry Smith For use in debuggers
1791d382aafbSBarry Smith */
1792014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank;
1793014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize;
179457b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscIntViewNumColumns(PetscInt, PetscInt, const PetscInt[], PetscViewer);
179557b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscRealViewNumColumns(PetscInt, PetscInt, const PetscReal[], PetscViewer);
179657b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscScalarViewNumColumns(PetscInt, PetscInt, const PetscScalar[], PetscViewer);
1797014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
1798014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
1799014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);
1800d382aafbSBarry Smith
1801bbcf679cSJacob Faibussowitsch /*
1802bbcf679cSJacob Faibussowitsch Basic memory and string operations. These are usually simple wrappers
1803bbcf679cSJacob Faibussowitsch around the basic Unix system calls, but a few of them have additional
1804bbcf679cSJacob Faibussowitsch functionality and/or error checking.
1805bbcf679cSJacob Faibussowitsch */
1806bbcf679cSJacob Faibussowitsch #include <petscstring.h>
1807bbcf679cSJacob Faibussowitsch
1808a663daf8SBarry Smith #include <stddef.h>
1809d382aafbSBarry Smith #include <stdlib.h>
18106c7e564aSBarry Smith
1811447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
1812447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d)
1813447bcd8fSJacob Faibussowitsch #else
1814d382aafbSBarry Smith /*MC
1815d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory
1816d382aafbSBarry Smith
1817eca87e8dSBarry Smith Synopsis:
1818aaa7dc30SBarry Smith #include <petscsys.h>
1819eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1820eca87e8dSBarry Smith
1821d382aafbSBarry Smith Not Collective
1822d382aafbSBarry Smith
1823d382aafbSBarry Smith Input Parameters:
182416a05f60SBarry Smith + a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`)
1825d382aafbSBarry Smith . n - number of elements to fetch
1826d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
182750d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1828d382aafbSBarry Smith
1829d382aafbSBarry Smith Level: developer
1830d382aafbSBarry Smith
1831d382aafbSBarry Smith Notes:
183216a05f60SBarry Smith The last two arguments (`rw` and `t`) must be compile-time constants.
1833d382aafbSBarry Smith
183450d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer
183550d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue.
183687497f52SBarry 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).
183787497f52SBarry 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.
183887497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1).
183987497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.)
1840d382aafbSBarry Smith
1841d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1842d382aafbSBarry Smith address).
1843d382aafbSBarry Smith
1844d382aafbSBarry Smith M*/
18459371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \
18469371c9d4SSatish Balay do { \
1847d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
1848d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
1849d382aafbSBarry Smith } while (0)
1850447bcd8fSJacob Faibussowitsch #endif
1851d382aafbSBarry Smith /*
1852d382aafbSBarry Smith Determine if some of the kernel computation routines use
1853d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines
1854d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines
1855d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels
1856e2e64c6bSBarry Smith should be used with ./configure to turn these on.
1857d382aafbSBarry Smith */
1858d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS)
1859d382aafbSBarry Smith
1860d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1861d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1862d382aafbSBarry Smith #endif
1863d382aafbSBarry Smith
1864d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1865d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1866d382aafbSBarry Smith #endif
1867d382aafbSBarry Smith
1868d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1869d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1870d382aafbSBarry Smith #endif
1871d382aafbSBarry Smith
1872d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1873d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1874d382aafbSBarry Smith #endif
1875d382aafbSBarry Smith
1876d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1877d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1878d382aafbSBarry Smith #endif
1879d382aafbSBarry Smith
1880d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1881d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1882d382aafbSBarry Smith #endif
1883d382aafbSBarry Smith
1884d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1885d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1886d382aafbSBarry Smith #endif
1887d382aafbSBarry Smith
1888d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1889d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT
1890d382aafbSBarry Smith #endif
1891d382aafbSBarry Smith
1892d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1893d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1894d382aafbSBarry Smith #endif
1895d382aafbSBarry Smith
1896d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1897d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX
1898d382aafbSBarry Smith #endif
1899d382aafbSBarry Smith
1900d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1901d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1902d382aafbSBarry Smith #endif
1903d382aafbSBarry Smith
1904d382aafbSBarry Smith #endif
1905d382aafbSBarry Smith
1906d382aafbSBarry Smith /*
1907d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface,
1908d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded
1909d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name
1910d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the
1911d382aafbSBarry Smith ugly extern "C" {} wrappers.
1912d382aafbSBarry Smith */
1913d382aafbSBarry Smith #if defined(__cplusplus)
1914d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" {
1915d382aafbSBarry Smith #define EXTERN_C_END }
1916d382aafbSBarry Smith #else
1917d382aafbSBarry Smith #define EXTERN_C_BEGIN
1918d382aafbSBarry Smith #define EXTERN_C_END
1919d382aafbSBarry Smith #endif
1920d382aafbSBarry Smith
1921d382aafbSBarry Smith /*MC
1922d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1923d382aafbSBarry Smith communication
1924d382aafbSBarry Smith
1925d382aafbSBarry Smith Level: beginner
1926d382aafbSBarry Smith
192716a05f60SBarry Smith Note:
192816a05f60SBarry Smith This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm`
1929d382aafbSBarry Smith
1930db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
1931d382aafbSBarry Smith M*/
1932d382aafbSBarry Smith
1933d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO)
193493d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
193593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
193693d501b3SJacob 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);
193793d501b3SJacob 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);
193893d501b3SJacob 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);
193993d501b3SJacob 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);
1940d382aafbSBarry Smith #endif
1941d382aafbSBarry Smith
1942462c564dSBarry Smith #if defined(PETSC_HAVE_MPI_COUNT)
1943462c564dSBarry Smith typedef MPI_Count MPIU_Count;
1944462c564dSBarry Smith #else
1945462c564dSBarry Smith typedef PetscInt64 MPIU_Count;
1946462c564dSBarry Smith #endif
1947462c564dSBarry Smith
194861b0d812SBarry Smith /*@C
1949462c564dSBarry Smith PetscIntCast - casts a `MPI_Count`, `PetscInt64`, `PetscCount`, or `size_t` to a `PetscInt` (which may be 32-bits in size), generates an
195087497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number.
1951c73702f5SBarry Smith
195220f4b53cSBarry Smith Not Collective; No Fortran Support
1953c73702f5SBarry Smith
1954c73702f5SBarry Smith Input Parameter:
195587497f52SBarry Smith . a - the `PetscInt64` value
1956c73702f5SBarry Smith
1957c73702f5SBarry Smith Output Parameter:
19586497c311SBarry Smith . b - the resulting `PetscInt` value, or `NULL` if the result is not needed
1959c73702f5SBarry Smith
1960c73702f5SBarry Smith Level: advanced
1961c73702f5SBarry Smith
196295bd0b28SBarry Smith Note:
19637de69702SBarry 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
1964c73702f5SBarry Smith
1965784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscCIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
1966c73702f5SBarry Smith @*/
PetscIntCast(MPIU_Count a,PetscInt * b)1967462c564dSBarry Smith static inline PetscErrorCode PetscIntCast(MPIU_Count a, PetscInt *b)
1968d71ae5a4SJacob Faibussowitsch {
1969c73702f5SBarry Smith PetscFunctionBegin;
19706497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1971462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscInt) || (a <= (MPIU_Count)PETSC_INT_MAX && a >= (MPIU_Count)PETSC_INT_MIN), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", (PetscInt64)a);
1972377f809aSBarry Smith if (b) *b = (PetscInt)a;
19733ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1974c73702f5SBarry Smith }
1975c73702f5SBarry Smith
1976c73702f5SBarry Smith /*@C
1977462c564dSBarry Smith PetscBLASIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount` or `PetscInt64` to a `PetscBLASInt` (which may be 32-bits in size), generates an
197887497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number.
197961b0d812SBarry Smith
1980667f096bSBarry Smith Not Collective; No Fortran Support
198161b0d812SBarry Smith
198261b0d812SBarry Smith Input Parameter:
198387497f52SBarry Smith . a - the `PetscInt` value
198461b0d812SBarry Smith
198561b0d812SBarry Smith Output Parameter:
19866497c311SBarry Smith . b - the resulting `PetscBLASInt` value, or `NULL` if the result is not needed
198761b0d812SBarry Smith
198861b0d812SBarry Smith Level: advanced
198961b0d812SBarry Smith
1990667f096bSBarry Smith Note:
1991f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
19921fd49c25SBarry Smith
1993784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
199461b0d812SBarry Smith @*/
PetscBLASIntCast(MPIU_Count a,PetscBLASInt * b)1995462c564dSBarry Smith static inline PetscErrorCode PetscBLASIntCast(MPIU_Count a, PetscBLASInt *b)
1996d71ae5a4SJacob Faibussowitsch {
1997c5df96a5SBarry Smith PetscFunctionBegin;
19986497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
1999462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscBLASInt) || a <= (MPIU_Count)PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for BLAS/LAPACK, which is restricted to 32-bit integers. Either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-blas-indices for the case you are running", (PetscInt64)a);
200054c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
20016497c311SBarry Smith if (b) *b = (PetscBLASInt)a;
20023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2003c5df96a5SBarry Smith }
2004c5df96a5SBarry Smith
200561b0d812SBarry Smith /*@C
200687497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.
2007eee0c0a6SToby Isaac
2008667f096bSBarry Smith Not Collective; No Fortran Support
2009eee0c0a6SToby Isaac
2010eee0c0a6SToby Isaac Input Parameter:
201187497f52SBarry Smith . a - the `PetscInt` value
2012eee0c0a6SToby Isaac
2013eee0c0a6SToby Isaac Output Parameter:
20146497c311SBarry Smith . b - the resulting `PetscCuBLASInt` value, or `NULL` if the result is not needed
2015eee0c0a6SToby Isaac
2016eee0c0a6SToby Isaac Level: advanced
2017eee0c0a6SToby Isaac
2018667f096bSBarry Smith Note:
2019eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
2020eee0c0a6SToby Isaac
2021784a7648SPierre Jolivet .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
2022eee0c0a6SToby Isaac @*/
PetscCuBLASIntCast(MPIU_Count a,PetscCuBLASInt * b)2023462c564dSBarry Smith static inline PetscErrorCode PetscCuBLASIntCast(MPIU_Count a, PetscCuBLASInt *b)
2024d71ae5a4SJacob Faibussowitsch {
2025eee0c0a6SToby Isaac PetscFunctionBegin;
20266497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
2027462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscCuBLASInt) || a <= (MPIU_Count)PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for cuBLAS, which is restricted to 32-bit integers.", (PetscInt64)a);
2028462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to cuBLAS routine", (PetscInt64)a);
20296497c311SBarry Smith if (b) *b = (PetscCuBLASInt)a;
20303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2031eee0c0a6SToby Isaac }
2032eee0c0a6SToby Isaac
2033eee0c0a6SToby Isaac /*@C
203447d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.
203547d993e7Ssuyashtn
2036667f096bSBarry Smith Not Collective; No Fortran Support
203747d993e7Ssuyashtn
203847d993e7Ssuyashtn Input Parameter:
203947d993e7Ssuyashtn . a - the `PetscInt` value
204047d993e7Ssuyashtn
204147d993e7Ssuyashtn Output Parameter:
20426497c311SBarry Smith . b - the resulting `PetscHipBLASInt` value, or `NULL` if the result is not needed
204347d993e7Ssuyashtn
204447d993e7Ssuyashtn Level: advanced
204547d993e7Ssuyashtn
2046667f096bSBarry Smith Note:
204747d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs
204847d993e7Ssuyashtn
2049784a7648SPierre Jolivet .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
205047d993e7Ssuyashtn @*/
PetscHipBLASIntCast(MPIU_Count a,PetscHipBLASInt * b)2051462c564dSBarry Smith static inline PetscErrorCode PetscHipBLASIntCast(MPIU_Count a, PetscHipBLASInt *b)
205247d993e7Ssuyashtn {
205347d993e7Ssuyashtn PetscFunctionBegin;
20546497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
2055462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscHipBLASInt) || a <= (MPIU_Count)PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for hipBLAS, which is restricted to 32-bit integers.", (PetscInt64)a);
2056462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to hipBLAS routine", (PetscInt64)a);
20576497c311SBarry Smith if (b) *b = (PetscHipBLASInt)a;
20583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
205947d993e7Ssuyashtn }
206047d993e7Ssuyashtn
206147d993e7Ssuyashtn /*@C
2062462c564dSBarry Smith PetscMPIIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `PetscMPIInt` (which is always 32-bits in size), generates an
2063667f096bSBarry Smith error if the `PetscMPIInt` is not large enough to hold the number.
206461b0d812SBarry Smith
2065667f096bSBarry Smith Not Collective; No Fortran Support
206661b0d812SBarry Smith
206761b0d812SBarry Smith Input Parameter:
206887497f52SBarry Smith . a - the `PetscInt` value
206961b0d812SBarry Smith
207061b0d812SBarry Smith Output Parameter:
20716497c311SBarry Smith . b - the resulting `PetscMPIInt` value, or `NULL` if the result is not needed
207261b0d812SBarry Smith
207361b0d812SBarry Smith Level: advanced
207461b0d812SBarry Smith
20756a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
207661b0d812SBarry Smith @*/
PetscMPIIntCast(MPIU_Count a,PetscMPIInt * b)2077462c564dSBarry Smith static inline PetscErrorCode PetscMPIIntCast(MPIU_Count a, PetscMPIInt *b)
2078d71ae5a4SJacob Faibussowitsch {
20794dc2109aSBarry Smith PetscFunctionBegin;
20806497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
2081462c564dSBarry Smith PetscCheck(a <= (MPIU_Count)PETSC_MPI_INT_MAX && a >= (MPIU_Count)PETSC_MPI_INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for MPI buffer length. Maximum supported value is %d", (PetscInt64)a, PETSC_MPI_INT_MAX);
20826497c311SBarry Smith if (b) *b = (PetscMPIInt)a;
20833ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
20844dc2109aSBarry Smith }
20854dc2109aSBarry Smith
2086784a7648SPierre Jolivet /*@C
2087784a7648SPierre Jolivet PetscCIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `int`, generates an error if the `int` is not large enough to hold the number.
2088784a7648SPierre Jolivet
2089784a7648SPierre Jolivet Not Collective; No Fortran Support
2090784a7648SPierre Jolivet
2091784a7648SPierre Jolivet Input Parameter:
2092784a7648SPierre Jolivet . a - the `PetscInt` value
2093784a7648SPierre Jolivet
2094784a7648SPierre Jolivet Output Parameter:
2095784a7648SPierre Jolivet . b - the resulting `int` value, or `NULL` if the result is not needed
2096784a7648SPierre Jolivet
2097784a7648SPierre Jolivet Level: advanced
2098784a7648SPierre Jolivet
2099784a7648SPierre Jolivet .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntCast()`
2100784a7648SPierre Jolivet @*/
PetscCIntCast(MPIU_Count a,int * b)2101784a7648SPierre Jolivet static inline PetscErrorCode PetscCIntCast(MPIU_Count a, int *b)
2102784a7648SPierre Jolivet {
2103784a7648SPierre Jolivet PetscFunctionBegin;
2104784a7648SPierre Jolivet if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
2105784a7648SPierre Jolivet PetscCheck(a <= INT_MAX && a >= INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big to be casted to an int. Maximum supported value is %d", (PetscInt64)a, INT_MAX);
2106784a7648SPierre Jolivet if (b) *b = (int)a;
2107784a7648SPierre Jolivet PetscFunctionReturn(PETSC_SUCCESS);
2108784a7648SPierre Jolivet }
2109784a7648SPierre Jolivet
2110917c3dccSPierre Jolivet /*MC
2111917c3dccSPierre Jolivet PetscInt64Mult - Computes the product of two variables after casting them to `PetscInt64`.
2112917c3dccSPierre Jolivet
2113917c3dccSPierre Jolivet Not Collective; No Fortran Support
2114917c3dccSPierre Jolivet
2115917c3dccSPierre Jolivet Input Parameters:
2116917c3dccSPierre Jolivet + a - the first variable
2117917c3dccSPierre Jolivet - b - the second variable
2118917c3dccSPierre Jolivet
2119917c3dccSPierre Jolivet Level: advanced
2120917c3dccSPierre Jolivet
2121917c3dccSPierre Jolivet .seealso: [](stylePetscCount), `PetscIntMultError()`, `PetscIntMultTruncate()`
2122917c3dccSPierre Jolivet M*/
2123835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2124835f2295SStefano Zampini #define PetscInt64Mult(a, b) ((a) * (b))
2125835f2295SStefano Zampini #else
2126f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b)))
2127835f2295SStefano Zampini #endif
21282f18eb33SBarry Smith
21292f18eb33SBarry Smith /*@C
2130f3fa974cSJacob Faibussowitsch PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive
2131f3fa974cSJacob Faibussowitsch `PetscInt` and truncates the value to slightly less than the maximal possible value.
21322f18eb33SBarry Smith
213320f4b53cSBarry Smith Not Collective; No Fortran Support
21342f18eb33SBarry Smith
2135d8d19677SJose E. Roman Input Parameters:
2136f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value
2137f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value
21382f18eb33SBarry Smith
2139667f096bSBarry Smith Level: advanced
2140667f096bSBarry Smith
2141f3fa974cSJacob Faibussowitsch Notes:
2142f3fa974cSJacob Faibussowitsch Returns the result as a `PetscInt` value.
21432f18eb33SBarry Smith
2144f3fa974cSJacob Faibussowitsch Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`.
2145667f096bSBarry Smith
2146f3fa974cSJacob Faibussowitsch Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate
2147f3fa974cSJacob Faibussowitsch to fit a `PetscInt`.
2148667f096bSBarry Smith
2149f3fa974cSJacob Faibussowitsch Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an
2150f3fa974cSJacob Faibussowitsch error if the result will not fit in a `PetscInt`.
21512f18eb33SBarry Smith
2152b5e6e808SPierre Jolivet Developer Notes:
2153f3fa974cSJacob Faibussowitsch We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but
2154f3fa974cSJacob Faibussowitsch requires many more checks.
21552f18eb33SBarry Smith
2156f3fa974cSJacob Faibussowitsch This is used where we compute approximate sizes for workspace and need to insure the
2157f3fa974cSJacob Faibussowitsch workspace is index-able.
21581fd49c25SBarry Smith
2159f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
21602f18eb33SBarry Smith @*/
PetscRealIntMultTruncate(PetscReal a,PetscInt b)2161d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
2162d71ae5a4SJacob Faibussowitsch {
21635f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
21641690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2165835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2166835f2295SStefano Zampini return r;
2167835f2295SStefano Zampini #else
21682f18eb33SBarry Smith return (PetscInt)r;
2169835f2295SStefano Zampini #endif
21702f18eb33SBarry Smith }
21712f18eb33SBarry Smith
21722f18eb33SBarry Smith /*@C
217387497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
21742f18eb33SBarry Smith
2175667f096bSBarry Smith Not Collective; No Fortran Support
21762f18eb33SBarry Smith
2177d8d19677SJose E. Roman Input Parameters:
2178af27ebaaSBarry Smith + a - the `PetscInt` value
21792f18eb33SBarry Smith - b - the second value
21802f18eb33SBarry Smith
2181390e1bf2SBarry Smith Returns:
2182af27ebaaSBarry Smith The result as a `PetscInt` value
21832f18eb33SBarry Smith
2184667f096bSBarry Smith Level: advanced
2185667f096bSBarry Smith
2186667f096bSBarry Smith Notes:
218787497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2188667f096bSBarry Smith
218987497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2190667f096bSBarry Smith
219187497f52SBarry 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`
21922f18eb33SBarry Smith
2193b5e6e808SPierre Jolivet Developer Notes:
219487497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
21952f18eb33SBarry Smith
21962f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
21972f18eb33SBarry Smith
2198667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`,
2199667f096bSBarry Smith `PetscIntSumTruncate()`
22002f18eb33SBarry Smith @*/
PetscIntMultTruncate(PetscInt a,PetscInt b)2201d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
2202d71ae5a4SJacob Faibussowitsch {
22035f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b);
22041690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2205835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2206835f2295SStefano Zampini return r;
2207835f2295SStefano Zampini #else
22082f18eb33SBarry Smith return (PetscInt)r;
2209835f2295SStefano Zampini #endif
22102f18eb33SBarry Smith }
22112f18eb33SBarry Smith
2212f91af8c7SBarry Smith /*@C
221387497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
2214f91af8c7SBarry Smith
2215667f096bSBarry Smith Not Collective; No Fortran Support
2216f91af8c7SBarry Smith
2217d8d19677SJose E. Roman Input Parameters:
221887497f52SBarry Smith + a - the `PetscInt` value
2219f91af8c7SBarry Smith - b - the second value
2220f91af8c7SBarry Smith
2221390e1bf2SBarry Smith Returns:
2222af27ebaaSBarry Smith The result as a `PetscInt` value
2223f91af8c7SBarry Smith
2224667f096bSBarry Smith Level: advanced
2225667f096bSBarry Smith
2226667f096bSBarry Smith Notes:
222787497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2228667f096bSBarry Smith
222987497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2230667f096bSBarry Smith
223187497f52SBarry 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`
2232f91af8c7SBarry Smith
2233b5e6e808SPierre Jolivet Developer Note:
2234f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2235f91af8c7SBarry Smith
2236db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2237f91af8c7SBarry Smith @*/
PetscIntSumTruncate(PetscInt a,PetscInt b)2238d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
2239d71ae5a4SJacob Faibussowitsch {
2240835f2295SStefano Zampini PetscInt64 r = a;
2241835f2295SStefano Zampini
2242835f2295SStefano Zampini r += b;
22431690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
2244835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2245835f2295SStefano Zampini return r;
2246835f2295SStefano Zampini #else
2247f91af8c7SBarry Smith return (PetscInt)r;
2248835f2295SStefano Zampini #endif
2249f91af8c7SBarry Smith }
2250f91af8c7SBarry Smith
22512f18eb33SBarry Smith /*@C
225287497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.
22532f18eb33SBarry Smith
2254667f096bSBarry Smith Not Collective; No Fortran Support
22552f18eb33SBarry Smith
2256d8d19677SJose E. Roman Input Parameters:
225787497f52SBarry Smith + a - the `PetscInt` value
22582f18eb33SBarry Smith - b - the second value
22592f18eb33SBarry Smith
2260d8d19677SJose E. Roman Output Parameter:
226116a05f60SBarry 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
22622f18eb33SBarry Smith
2263667f096bSBarry Smith Level: advanced
22642f18eb33SBarry Smith
2265667f096bSBarry Smith Notes:
2266667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`
2267667f096bSBarry Smith
2268667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2269f5f57ec0SBarry Smith
2270b5e6e808SPierre Jolivet Developer Note:
227116a05f60SBarry 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.
227216a05f60SBarry Smith `PetscIntSumError()` can be used to check for this situation.
22732f18eb33SBarry Smith
2274917c3dccSPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntSumError()`
22752f18eb33SBarry Smith @*/
PetscIntMultError(PetscInt a,PetscInt b,PetscInt * result)2276d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
2277d71ae5a4SJacob Faibussowitsch {
2278f3fa974cSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b);
22792f18eb33SBarry Smith
22802f18eb33SBarry Smith PetscFunctionBegin;
2281835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2282835f2295SStefano Zampini if (result) *result = r;
2283835f2295SStefano Zampini #else
2284c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r;
2285835f2295SStefano Zampini #endif
2286f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) {
22871690c2aeSBarry Smith PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b);
2288f3fa974cSJacob Faibussowitsch }
22893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2290f91af8c7SBarry Smith }
2291f91af8c7SBarry Smith
2292f91af8c7SBarry Smith /*@C
2293f91af8c7SBarry Smith
229487497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.
2295f91af8c7SBarry Smith
2296667f096bSBarry Smith Not Collective; No Fortran Support
2297f91af8c7SBarry Smith
2298d8d19677SJose E. Roman Input Parameters:
229987497f52SBarry Smith + a - the `PetscInt` value
2300f91af8c7SBarry Smith - b - the second value
2301f91af8c7SBarry Smith
2302d8d19677SJose E. Roman Output Parameter:
230316a05f60SBarry 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
2304f91af8c7SBarry Smith
2305f91af8c7SBarry Smith Level: advanced
2306f91af8c7SBarry Smith
2307667f096bSBarry Smith Notes:
23087de69702SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64`
2309667f096bSBarry Smith
2310667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2311667f096bSBarry Smith
2312db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2313f91af8c7SBarry Smith @*/
PetscIntSumError(PetscInt a,PetscInt b,PetscInt * result)2314d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
2315d71ae5a4SJacob Faibussowitsch {
2316835f2295SStefano Zampini PetscInt64 r = a;
2317f91af8c7SBarry Smith
2318f91af8c7SBarry Smith PetscFunctionBegin;
2319835f2295SStefano Zampini r += b;
2320835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES)
2321835f2295SStefano Zampini if (result) *result = r;
2322835f2295SStefano Zampini #else
2323c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r;
2324835f2295SStefano Zampini #endif
2325f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) {
23261690c2aeSBarry Smith PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b);
2327f3fa974cSJacob Faibussowitsch }
23283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
23292f18eb33SBarry Smith }
2330c5df96a5SBarry Smith
2331d382aafbSBarry Smith /*
23322981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
2333d382aafbSBarry Smith */
2334d382aafbSBarry Smith #if defined(hz)
2335d382aafbSBarry Smith #undef hz
2336d382aafbSBarry Smith #endif
2337d382aafbSBarry Smith
2338d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H)
2339d382aafbSBarry Smith #include <sys/types.h>
2340d382aafbSBarry Smith #endif
2341d382aafbSBarry Smith
2342d382aafbSBarry Smith /*MC
2343d382aafbSBarry Smith
234466d79e26SBarry 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++
234516a05f60SBarry Smith and Fortran compilers when `petscsys.h` is included.
234666d79e26SBarry Smith
2347baca6076SPierre Jolivet The current PETSc version and the API for accessing it are defined in <A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscversion.h.html">include/petscversion.html</A>
234866d79e26SBarry Smith
234966d79e26SBarry 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)
235066d79e26SBarry Smith
235166d79e26SBarry 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
235266d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API.
235366d79e26SBarry Smith
235466d79e26SBarry 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
235566d79e26SBarry Smith
235666d79e26SBarry 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),
235766d79e26SBarry 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
235866d79e26SBarry Smith version number (x.y.z).
235966d79e26SBarry Smith
236087497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)
236166d79e26SBarry Smith
236287497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released
236366d79e26SBarry Smith
236487497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww
236566d79e26SBarry Smith
236687497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository
236766d79e26SBarry Smith
236887497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed.
236966d79e26SBarry Smith
2370cbc12506SBarry Smith Level: intermediate
237166d79e26SBarry Smith M*/
237266d79e26SBarry Smith
2373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
2374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
2375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
2376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
2377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
237927710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
23805f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);
2381d382aafbSBarry Smith
23826497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscCount, const PetscInt[], PetscBool *);
23836497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscCount, const PetscInt64[], PetscBool *);
23846497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscCount, const PetscMPIInt[], PetscBool *);
23856497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscCount, const PetscReal[], PetscBool *);
23866497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt(PetscCount, PetscInt[]);
23876497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscCount, PetscInt64[]);
23886497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortCount(PetscCount, PetscCount[]);
23896497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscCount, PetscInt[]);
239022ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
23916497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscCount, const PetscInt[], PetscBool *);
239277aa4f85SJames Wright PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsCount(PetscCount, const PetscCount[], PetscBool *);
2393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
2394f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
23956497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscCount, const PetscInt[], PetscInt *);
23966497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscCount, const PetscMPIInt[], PetscInt *);
239777aa4f85SJames Wright PETSC_EXTERN PetscErrorCode PetscFindCount(PetscCount, PetscCount, const PetscCount[], PetscCount *);
2398014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
2399014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
24006497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscCount, PetscInt[], PetscInt[]);
2401981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
24026497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithMPIIntArray(PetscCount, PetscInt[], PetscMPIInt[]);
24036497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscCount, PetscInt[], PetscInt[], PetscInt[]);
2404981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
24056497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscCount, PetscMPIInt[]);
240617d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
24076497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscCount, PetscMPIInt[], PetscMPIInt[]);
24086497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscCount, PetscMPIInt[], PetscInt[]);
24096497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscCount, PetscInt[], PetscScalar[]);
24106497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscCount, PetscInt[], void *, size_t, void *);
24116497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReal(PetscCount, PetscReal[]);
24126497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscCount, PetscReal[], PetscInt[]);
2413014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
2414745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
24156497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscCount, const PetscReal[], PetscReal, PetscInt *);
2416014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
2417014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
2418ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[], PetscInt *[], PetscInt *[]);
2419ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[]);
2420ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt *[]);
2421ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt *[]);
2422ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
2423ce605777SToby Isaac
24244d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
2425676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
2426676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
2427676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
24284d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
2429676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
2430676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
2431676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2432676f2a66SJacob Faibussowitsch
2433014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);
2435d382aafbSBarry Smith
243676bdecfbSBarry Smith /*J
2437d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer
2438d382aafbSBarry Smith
2439d382aafbSBarry Smith Level: beginner
2440d382aafbSBarry Smith
2441667f096bSBarry Smith Note:
244287497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
244316a05f60SBarry Smith with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc.
2444d382aafbSBarry Smith
2445db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
244676bdecfbSBarry Smith J*/
244719fd82e9SBarry Smith typedef const char *PetscRandomType;
2448d382aafbSBarry Smith #define PETSCRAND "rand"
2449d382aafbSBarry Smith #define PETSCRAND48 "rand48"
2450d382aafbSBarry Smith #define PETSCSPRNG "sprng"
2451c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48"
245225ccb61fSToby Isaac #define PETSCRANDOM123 "random123"
2453808ba619SStefano Zampini #define PETSCCURAND "curand"
2454d382aafbSBarry Smith
2455d382aafbSBarry Smith /* Logging support */
2456014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2457d382aafbSBarry Smith
2458607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
24594bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void);
2460d382aafbSBarry Smith
2461d382aafbSBarry Smith /* Dynamic creation and loading functions */
2462140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList;
2463d382aafbSBarry Smith
2464bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
246519fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
246644ffe595SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomSetOptionsPrefix(PetscRandom, const char[]);
2467014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
246819fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
2469fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
2470014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);
2471d382aafbSBarry Smith
2472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
2473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
2474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
2475808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
2476808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
2477014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
2478014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
2479ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, PetscInt64);
2480ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, PetscInt64 *);
2481014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);
2483d382aafbSBarry Smith
2484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
2485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
2486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
2487014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
2488014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
2489014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
2490014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
249197540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
24928a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
249397540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2494d382aafbSBarry Smith
2495d598313aSBarry Smith /*MC
2496d598313aSBarry Smith PetscBinaryBigEndian - indicates if values in memory are stored with big endian format
2497d598313aSBarry Smith
2498d598313aSBarry Smith Synopsis:
2499d598313aSBarry Smith #include <petscsys.h>
2500d598313aSBarry Smith PetscBool PetscBinaryBigEndian(void);
2501d598313aSBarry Smith
2502d598313aSBarry Smith No Fortran Support
2503d598313aSBarry Smith
2504d598313aSBarry Smith Level: developer
2505d598313aSBarry Smith
2506d598313aSBarry Smith .seealso: `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
2507d598313aSBarry Smith M*/
PetscBinaryBigEndian(void)2508d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void)
2509d71ae5a4SJacob Faibussowitsch {
25109371c9d4SSatish Balay long _petsc_v = 1;
25119371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
25129371c9d4SSatish Balay }
251330815ce0SLisandro Dalcin
25146497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscCount, PetscInt *, PetscDataType);
25159860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
25166497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscCount, PetscDataType);
2517f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
2518014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
2519014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2520014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
2521014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
2522014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
2523014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
2524014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
2525c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER)
2526e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
2527c891a504SStefano Zampini #endif
2528d382aafbSBarry Smith
2529014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
2530014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
25316497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscCount);
2532d382aafbSBarry Smith
2533014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2534014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
2535014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2536014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
2537014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2538014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
25392a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2540d382aafbSBarry Smith
2541014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
2542ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[]);
2543ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[], PetscMPIInt *[]);
2544014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
2545014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
2546ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt *[], void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
25472a8381b2SBarry Smith 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 *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
25482a8381b2SBarry Smith 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 *), PetscCtx ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
2549d382aafbSBarry Smith
25506145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
25516145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);
25526145cd65SJed Brown
PetscSSEIsEnabled(PETSC_UNUSED MPI_Comm comm,PetscBool * lflag,PetscBool * gflag)25530a872754SPierre Jolivet PETSC_DEPRECATED_FUNCTION(3, 24, 0, "PetscSSEIsEnabled()", ) static inline PetscErrorCode PetscSSEIsEnabled(PETSC_UNUSED MPI_Comm comm, PetscBool *lflag, PetscBool *gflag)
25540a872754SPierre Jolivet {
25550a872754SPierre Jolivet if (lflag) *lflag = PETSC_FALSE;
25560a872754SPierre Jolivet if (gflag) *gflag = PETSC_FALSE;
25570a872754SPierre Jolivet return PETSC_SUCCESS;
25580a872754SPierre Jolivet }
2559d382aafbSBarry Smith
2560ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2561ce94432eSBarry Smith
2562d382aafbSBarry Smith struct _n_PetscSubcomm {
2563d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */
2564d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2565306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */
256645487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */
256745487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */
2568708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */
256945487dadSJed Brown PetscSubcommType type;
2570e5acf8a4SHong Zhang char *subcommprefix;
2571d382aafbSBarry Smith };
2572d382aafbSBarry Smith
PetscSubcommParent(PetscSubcomm scomm)2573d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
2574d71ae5a4SJacob Faibussowitsch {
25759371c9d4SSatish Balay return scomm->parent;
25769371c9d4SSatish Balay }
PetscSubcommChild(PetscSubcomm scomm)2577d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
2578d71ae5a4SJacob Faibussowitsch {
25799371c9d4SSatish Balay return scomm->child;
25809371c9d4SSatish Balay }
PetscSubcommContiguousParent(PetscSubcomm scomm)2581d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
2582d71ae5a4SJacob Faibussowitsch {
25839371c9d4SSatish Balay return scomm->dupparent;
25849371c9d4SSatish Balay }
2585014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
2586014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
2587014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
2588014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
258965d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
2590053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
2591f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2592e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
2593a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
2594a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
2595a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);
2596d382aafbSBarry Smith
25979962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
25989962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
25999962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
26009962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
26019962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
26029962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
26039962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
26049962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);
26059962606eSBarry Smith
26065e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
26075f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
26085f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
26095f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
26105f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);
26115e71baefSBarry Smith
2612a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2613a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
2614a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
2615a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
2616a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2617a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2618a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2619a32e93adSJunchao Zhang
26206497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, PetscCount, PetscSegBuffer *);
26210f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
26226497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, PetscCount, void *);
2623137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
2624137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
2625137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
26266497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, PetscCount *);
26276497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, PetscCount);
26280f453b92SJed Brown
2629d598313aSBarry Smith /*MC
2630d598313aSBarry Smith PetscSegBufferGetInts - access an array of `PetscInt` from a `PetscSegBuffer`
2631d598313aSBarry Smith
2632d598313aSBarry Smith Synopsis:
2633d598313aSBarry Smith #include <petscsys.h>
2634d598313aSBarry Smith PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot);
2635d598313aSBarry Smith
2636d598313aSBarry Smith No Fortran Support
2637d598313aSBarry Smith
2638d598313aSBarry Smith Input Parameters:
2639d598313aSBarry Smith + seg - `PetscSegBuffer` buffer
2640d598313aSBarry Smith - count - number of entries needed
2641d598313aSBarry Smith
2642d598313aSBarry Smith Output Parameter:
2643d598313aSBarry Smith . buf - address of new buffer for contiguous data
2644d598313aSBarry Smith
2645d598313aSBarry Smith Level: intermediate
2646d598313aSBarry Smith
2647d598313aSBarry Smith Developer Note:
2648d598313aSBarry Smith Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2649d598313aSBarry Smith prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2650d598313aSBarry Smith possible.
2651d598313aSBarry Smith
2652d598313aSBarry Smith .seealso: `PetscSegBuffer`, `PetscSegBufferGet()`, `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
2653d598313aSBarry Smith M*/
PetscSegBufferGetInts(PetscSegBuffer seg,PetscCount count,PetscInt * PETSC_RESTRICT * slot)26546497c311SBarry Smith static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, PetscCount count, PetscInt *PETSC_RESTRICT *slot)
2655d71ae5a4SJacob Faibussowitsch {
26569371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot);
26579371c9d4SSatish Balay }
2658d382aafbSBarry Smith
26599de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
26609de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
26619de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
26629de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);
26639de0f6ecSBarry Smith
2664ace2fbaeSBarry Smith #include <stdarg.h>
2665ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
2666ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);
2667ace2fbaeSBarry Smith
2668268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2669fbfcfee5SBarry Smith
26705d83a8b1SBarry Smith /*@
26711f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
26721f817a21SBarry Smith
2673667f096bSBarry Smith Not Collective; No Fortran Support
26741f817a21SBarry Smith
26751f817a21SBarry Smith Input Parameters:
267635cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely
267787497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation
26781f817a21SBarry Smith
2679667f096bSBarry Smith Options Database Key:
26803c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation
26813c7db156SBarry Smith
2682850545d0SSatish Balay Level: intermediate
26831f817a21SBarry Smith @*/
PetscCitationsRegister(const char cit[],PetscBool * set)2684d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
2685d71ae5a4SJacob Faibussowitsch {
2686dff31646SBarry Smith size_t len;
2687dff31646SBarry Smith char *vstring;
2688dff31646SBarry Smith
26891f817a21SBarry Smith PetscFunctionBegin;
26903ba16761SJacob Faibussowitsch if (set && *set) PetscFunctionReturn(PETSC_SUCCESS);
26919566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len));
269235d731d1SLisandro Dalcin PetscCall(PetscSegBufferGet(PetscCitationsList, (PetscCount)len, &vstring));
26939566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len));
2694dff31646SBarry Smith if (set) *set = PETSC_TRUE;
26953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2696dff31646SBarry Smith }
2697dff31646SBarry Smith
2698fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
2699fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
2700f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);
2701fe278a28SBarry Smith
2702f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
2703f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
27044bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]);
2705b967cddfSBarry Smith
27069f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
27074bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t);
27084bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]);
27099f4d3c52SBarry Smith
271068e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
27115dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);
2712dff31646SBarry Smith
27136497c311SBarry Smith #if !defined(PETSC_HAVE_MPI_LARGE_COUNT)
2714462c564dSBarry Smith /*
2715462c564dSBarry Smith Cast PetscCount <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines.
27166497c311SBarry Smith It is similar to PetscMPIIntCast() except that here it returns an MPI error code.
27176497c311SBarry Smith */
2718462c564dSBarry Smith #define PetscMPIIntCast_Internal(a, b) \
2719462c564dSBarry Smith do { \
2720462c564dSBarry Smith *b = 0; \
2721462c564dSBarry Smith if (PetscUnlikely(a > (MPIU_Count)PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT; \
2722462c564dSBarry Smith *b = (PetscMPIInt)a; \
2723462c564dSBarry Smith } while (0)
27246497c311SBarry Smith
MPIU_Get_count(MPI_Status * status,MPI_Datatype dtype,PetscCount * count)27256497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
27266497c311SBarry Smith {
2727462c564dSBarry Smith PetscMPIInt count2, err;
27286497c311SBarry Smith
27296497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */
2730462c564dSBarry Smith err = MPI_Get_count(status, dtype, &count2);
27316497c311SBarry Smith *count = count2;
2732462c564dSBarry Smith return err;
27336497c311SBarry Smith }
27346497c311SBarry Smith
MPIU_Send(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt dest,PetscMPIInt tag,MPI_Comm comm)2735462c564dSBarry Smith static inline PetscMPIInt MPIU_Send(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm)
27366497c311SBarry Smith {
2737462c564dSBarry Smith PetscMPIInt count2, err;
27386497c311SBarry Smith
2739462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2740462c564dSBarry Smith err = MPI_Send((void *)buf, count2, dtype, dest, tag, comm);
2741462c564dSBarry Smith return err;
27426497c311SBarry Smith }
27436497c311SBarry Smith
MPIU_Send_init(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt dest,PetscMPIInt tag,MPI_Comm comm,MPI_Request * request)2744462c564dSBarry Smith static inline PetscMPIInt MPIU_Send_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
27456497c311SBarry Smith {
2746462c564dSBarry Smith PetscMPIInt count2, err;
27476497c311SBarry Smith
2748462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2749462c564dSBarry Smith err = MPI_Send_init((void *)buf, count2, dtype, dest, tag, comm, request);
2750462c564dSBarry Smith return err;
27516497c311SBarry Smith }
27526497c311SBarry Smith
MPIU_Isend(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt dest,PetscMPIInt tag,MPI_Comm comm,MPI_Request * request)2753462c564dSBarry Smith static inline PetscMPIInt MPIU_Isend(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
27546497c311SBarry Smith {
2755462c564dSBarry Smith PetscMPIInt count2, err;
27566497c311SBarry Smith
2757462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2758462c564dSBarry Smith err = MPI_Isend((void *)buf, count2, dtype, dest, tag, comm, request);
2759462c564dSBarry Smith return err;
27606497c311SBarry Smith }
27616497c311SBarry Smith
MPIU_Recv(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt source,PetscMPIInt tag,MPI_Comm comm,MPI_Status * status)2762462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Status *status)
27636497c311SBarry Smith {
2764462c564dSBarry Smith PetscMPIInt count2, err;
27656497c311SBarry Smith
2766462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2767462c564dSBarry Smith err = MPI_Recv((void *)buf, count2, dtype, source, tag, comm, status);
2768462c564dSBarry Smith return err;
27696497c311SBarry Smith }
27706497c311SBarry Smith
MPIU_Recv_init(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt source,PetscMPIInt tag,MPI_Comm comm,MPI_Request * request)2771462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
27726497c311SBarry Smith {
2773462c564dSBarry Smith PetscMPIInt count2, err;
27746497c311SBarry Smith
2775462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2776462c564dSBarry Smith err = MPI_Recv_init((void *)buf, count2, dtype, source, tag, comm, request);
2777462c564dSBarry Smith return err;
27786497c311SBarry Smith }
27796497c311SBarry Smith
MPIU_Irecv(const void * buf,MPIU_Count count,MPI_Datatype dtype,PetscMPIInt source,PetscMPIInt tag,MPI_Comm comm,MPI_Request * request)2780462c564dSBarry Smith static inline PetscMPIInt MPIU_Irecv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
27816497c311SBarry Smith {
2782462c564dSBarry Smith PetscMPIInt count2, err;
27836497c311SBarry Smith
2784462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2785462c564dSBarry Smith err = MPI_Irecv((void *)buf, count2, dtype, source, tag, comm, request);
2786462c564dSBarry Smith return err;
27876497c311SBarry Smith }
27886497c311SBarry Smith
MPIU_Reduce(const void * inbuf,void * outbuf,MPIU_Count count,MPI_Datatype dtype,MPI_Op op,PetscMPIInt root,MPI_Comm comm)2789462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce(const void *inbuf, void *outbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op, PetscMPIInt root, MPI_Comm comm)
27906497c311SBarry Smith {
2791462c564dSBarry Smith PetscMPIInt count2, err;
27926497c311SBarry Smith
2793462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2794462c564dSBarry Smith err = MPI_Reduce((void *)inbuf, outbuf, count2, dtype, op, root, comm);
2795462c564dSBarry Smith return err;
27966497c311SBarry Smith }
27976497c311SBarry Smith
27986497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
MPIU_Reduce_local(const void * inbuf,void * inoutbuf,MPIU_Count count,MPI_Datatype dtype,MPI_Op op)2799462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op)
28006497c311SBarry Smith {
2801462c564dSBarry Smith PetscMPIInt count2, err;
28026497c311SBarry Smith
2803462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2);
2804462c564dSBarry Smith err = MPI_Reduce_local((void *)inbuf, inoutbuf, count2, dtype, op);
2805462c564dSBarry Smith return err;
28066497c311SBarry Smith }
28076497c311SBarry Smith #endif
28086497c311SBarry Smith
28093fa2bd1cSBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
28103fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
28113fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
28123fa2bd1cSBarry Smith #else
28133fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
2814c13ed45bSPierre Jolivet ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
28153fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \
2816c13ed45bSPierre Jolivet ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
28173fa2bd1cSBarry Smith #endif
28183fa2bd1cSBarry Smith
28196497c311SBarry Smith #else
28206497c311SBarry Smith
28216497c311SBarry Smith /* on 32 bit systems MPI_Count maybe 64-bit while PetscCount is 32-bit */
2822462c564dSBarry Smith #define PetscCountCast_Internal(a, b) \
2823462c564dSBarry Smith do { \
2824462c564dSBarry Smith *b = 0; \
2825462c564dSBarry Smith if (PetscUnlikely(a > (MPI_Count)PETSC_COUNT_MAX)) return MPI_ERR_COUNT; \
2826462c564dSBarry Smith *b = (PetscMPIInt)a; \
2827462c564dSBarry Smith } while (0)
28286497c311SBarry Smith
MPIU_Get_count(MPI_Status * status,MPI_Datatype dtype,PetscCount * count)28296497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
28306497c311SBarry Smith {
28316497c311SBarry Smith MPI_Count count2;
2832462c564dSBarry Smith PetscMPIInt err;
28336497c311SBarry Smith
28346497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */
2835462c564dSBarry Smith err = MPI_Get_count_c(status, dtype, &count2);
2836462c564dSBarry Smith if (err) return err;
2837462c564dSBarry Smith PetscCountCast_Internal(count2, count);
2838462c564dSBarry Smith return MPI_SUCCESS;
28396497c311SBarry Smith }
28406497c311SBarry Smith
28416497c311SBarry Smith #define MPIU_Reduce(inbuf, outbuf, count, dtype, op, root, comm) MPI_Reduce_c(inbuf, outbuf, (MPI_Count)(count), dtype, op, root, comm)
28426497c311SBarry Smith #define MPIU_Send(buf, count, dtype, dest, tag, comm) MPI_Send_c(buf, (MPI_Count)(count), dtype, dest, tag, comm)
28436497c311SBarry Smith #define MPIU_Send_init(buf, count, dtype, dest, tag, comm, request) MPI_Send_init_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
28446497c311SBarry Smith #define MPIU_Isend(buf, count, dtype, dest, tag, comm, request) MPI_Isend_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
28456497c311SBarry Smith #define MPIU_Recv(buf, count, dtype, source, tag, comm, status) MPI_Recv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, status)
28466497c311SBarry Smith #define MPIU_Recv_init(buf, count, dtype, source, tag, comm, request) MPI_Recv_init_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
28476497c311SBarry Smith #define MPIU_Irecv(buf, count, dtype, source, tag, comm, request) MPI_Irecv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
28486497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
28496a210b70SBarry Smith #define MPIU_Reduce_local(inbuf, inoutbuf, count, dtype, op) MPI_Reduce_local_c(inbuf, inoutbuf, (MPI_Count)(count), dtype, op)
28506497c311SBarry Smith #endif
28513fa2bd1cSBarry Smith
28523fa2bd1cSBarry Smith /*MC
28533fa2bd1cSBarry Smith MPIU_Scatterv - A replacement for `MPI_Scatterv()` that can be called with `PetscInt` types when PETSc is built for either 32-bit indices or 64-bit indices.
28543fa2bd1cSBarry Smith
28553fa2bd1cSBarry Smith Synopsis:
28563fa2bd1cSBarry Smith #include <petscsys.h>
28573fa2bd1cSBarry Smith PetscMPIInt MPIU_Scatterv(const void *sendbuf, const PetscInt sendcounts[], const PetscInt displs[], MPI_Datatype sendtype, void *recvbuf, PetscInt recvcount, MPI_Datatype recvtype, PetscMPIInt root, MPI_Comm comm)
28583fa2bd1cSBarry Smith
28593fa2bd1cSBarry Smith Collective
28603fa2bd1cSBarry Smith
28613fa2bd1cSBarry Smith Input Parameters:
28623fa2bd1cSBarry Smith + sendbuf - address of send buffer
28633fa2bd1cSBarry Smith . sendcounts - non-negative `PetscInt` array (of length `comm` group size) specifying the number of elements to send to each MPI process
28643fa2bd1cSBarry Smith . displs - `PetscInt` array (of length `comm` group size). Entry i specifies the displacement (relative to `sendbuf`) from which to take the outgoing data to process i
28653fa2bd1cSBarry Smith . sendtype - data type of `sendbuf` elements
28663fa2bd1cSBarry Smith . recvcount - number of elements in `recvbuf` (non-negative integer)
28673fa2bd1cSBarry Smith . recvtype - data type of `recvbuf` elements
28683fa2bd1cSBarry Smith . root - Rank of the MPI root process, which will dispatch the data to scatter
28693fa2bd1cSBarry Smith - comm - `MPI_Comm` communicator
28703fa2bd1cSBarry Smith
28713fa2bd1cSBarry Smith Output Parameter:
28723fa2bd1cSBarry Smith . recvbuf - the resulting scattered values on this MPI process
28733fa2bd1cSBarry Smith
28743fa2bd1cSBarry Smith Level: developer
28753fa2bd1cSBarry Smith
28763fa2bd1cSBarry Smith Notes:
28773fa2bd1cSBarry Smith Should be wrapped with `PetscCallMPI()` for error checking
28783fa2bd1cSBarry Smith
28793fa2bd1cSBarry Smith This is different than most of the `MPIU_` wrappers in that all the count arguments are in `PetscInt`
28803fa2bd1cSBarry Smith
28813fa2bd1cSBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()`, `MPIU_Gatherv()`
28823fa2bd1cSBarry Smith M*/
28833fa2bd1cSBarry Smith
28843fa2bd1cSBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
28853fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
28863fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
28873fa2bd1cSBarry Smith #else
28883fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv_c(sendbuf, (const MPI_Count *)(sendcounts), (const MPI_Aint *)(displs), sendtype, recvbuf, recvcount, recvtype, root, comm)
28893fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv_c(sendbuf, sendcount, sendtype, recvbuf, (const MPI_Count *)(recvcounts), (const MPI_Aint *)(displs), recvtype, root, comm)
28903fa2bd1cSBarry Smith #endif
28913fa2bd1cSBarry Smith
28926497c311SBarry Smith #endif
28936497c311SBarry Smith
2894462c564dSBarry Smith PETSC_EXTERN PetscMPIInt MPIU_Allreduce_Private(const void *, void *, MPIU_Count, MPI_Datatype, MPI_Op, MPI_Comm);
289526139085SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckAllreduceSameLineAndCount_Private(MPI_Comm, const char *, PetscMPIInt, PetscMPIInt);
28966a210b70SBarry Smith
2897b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG)
PetscStrHash(const char * str)2898d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str)
2899d71ae5a4SJacob Faibussowitsch {
2900df05ca09SBarry Smith unsigned int c, hash = 5381;
2901df05ca09SBarry Smith
2902503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2903df05ca09SBarry Smith return hash;
2904df05ca09SBarry Smith }
29056497c311SBarry Smith #endif
290677a5e07dSBarry Smith
290777a5e07dSBarry Smith /*MC
2908462c564dSBarry Smith MPIU_Allreduce - A replacement for `MPI_Allreduce()` that (1) performs single-count `MPIU_INT` operations in `PetscInt64` to detect
2909462c564dSBarry Smith integer overflows and (2) tries to determine if the call from all the MPI ranks occur in the
291087497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
291187497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.
291277a5e07dSBarry Smith
291377a5e07dSBarry Smith Synopsis:
291477a5e07dSBarry Smith #include <petscsys.h>
2915462c564dSBarry Smith PetscMPIInt MPIU_Allreduce(void *indata,void *outdata,PetscCount count,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm);
291677a5e07dSBarry Smith
29177cdbe19fSJose E. Roman Collective
29187cdbe19fSJose E. Roman
291977a5e07dSBarry Smith Input Parameters:
29206a210b70SBarry Smith + a - pointer to the input data to be reduced
29216a210b70SBarry Smith . count - the number of MPI data items in `a` and `b`
29226497c311SBarry Smith . dtype - the MPI datatype, for example `MPI_INT`
29236497c311SBarry Smith . op - the MPI operation, for example `MPI_SUM`
29246497c311SBarry Smith - comm - the MPI communicator on which the operation occurs
292577a5e07dSBarry Smith
292677a5e07dSBarry Smith Output Parameter:
29276a210b70SBarry Smith . b - the reduced values
292877a5e07dSBarry Smith
2929667f096bSBarry Smith Level: developer
2930667f096bSBarry Smith
2931462c564dSBarry Smith Note:
2932462c564dSBarry Smith Should be wrapped with `PetscCallMPI()` for error checking
2933462c564dSBarry Smith
29346497c311SBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()`
293577a5e07dSBarry Smith M*/
29366497c311SBarry Smith #if defined(PETSC_USE_DEBUG)
293726139085SJunchao Zhang #define MPIU_Allreduce(a, b, count, dtype, op, comm) \
29383ba16761SJacob Faibussowitsch PetscMacroReturnStandard( \
293926139085SJunchao Zhang PetscCall(PetscCheckAllreduceSameLineAndCount_Private((comm), __FILE__, (PetscMPIInt)__LINE__, (PetscMPIInt)(count))); \
294026139085SJunchao Zhang PetscCallMPI(MPIU_Allreduce_Private((a), (b), (count), (dtype), (op), (comm)));)
2941b2566f29SBarry Smith #else
294226139085SJunchao Zhang #define MPIU_Allreduce(a, b, count, dtype, op, comm) MPIU_Allreduce_Private((a), (b), (count), (dtype), (op), (comm))
2943b2566f29SBarry Smith #endif
2944b2566f29SBarry Smith
2945cd88fca5SStefano Zampini /* this is a vile hack */
2946cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI)
29479371c9d4SSatish 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)
2948cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
2949cd88fca5SStefano Zampini #endif
2950961fb248SStefano Zampini #endif
2951cd88fca5SStefano Zampini
295212801b39SBarry Smith /*
295360fbe2beSVaclav Hapla List of external packages and queries on it
295460fbe2beSVaclav Hapla */
295560fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);
295660fbe2beSVaclav Hapla
2957f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */
2958f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
2959f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
29607a99bfcaSBarry Smith PETSC_EXTERN PetscBool PCMPIServerActive;
29619f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerInSolve;
29629f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerUseShmget;
29639f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAllocateArray(size_t, size_t, void **);
29649f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetDeallocateArray(void **);
29659f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetMapAddresses(MPI_Comm, PetscInt, const void **, void **);
29669f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetUnmapAddresses(PetscInt, void **);
29679f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAddressesFinalize(void);
29689f0612e4SBarry Smith
29699f0612e4SBarry Smith typedef struct {
29709f0612e4SBarry Smith PetscInt n;
29719f0612e4SBarry Smith void *addr[3];
29729f0612e4SBarry Smith } PCMPIServerAddresses;
29732a8381b2SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerAddressesDestroy(PetscCtxRt);
2974fbf9dbe5SBarry Smith
2975edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS
2976046ed546SBarry Smith
2977046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt);
2978046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *);
29798e3a54c0SPierre Jolivet
29808e3a54c0SPierre Jolivet /*MC
29818e3a54c0SPierre Jolivet PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset
29828e3a54c0SPierre Jolivet
29838e3a54c0SPierre Jolivet Level: beginner
29848e3a54c0SPierre Jolivet
29858e3a54c0SPierre Jolivet Note:
29868e3a54c0SPierre Jolivet This is needed to avoid errors with undefined-behavior sanitizers such as
29878e3a54c0SPierre Jolivet UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags
29888e3a54c0SPierre Jolivet M*/
29898e3a54c0SPierre Jolivet #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL)
2990ce78bad3SBarry Smith
2991ce78bad3SBarry Smith /* this is required to force PetscDevice to be visible at the system level for the Fortran interface */
2992ce78bad3SBarry Smith #include <petscdevicetypes.h>
299367a21fd9SBarry Smith
299467a21fd9SBarry Smith #if PetscDefined(USE_DEBUG) && !PetscDefined(HAVE_THREADSAFETY)
299567a21fd9SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE *);
299667a21fd9SBarry Smith #else
299767a21fd9SBarry Smith #define PetscStackView(file) PETSC_SUCCESS
299867a21fd9SBarry Smith #endif
2999