xref: /petsc/include/petscsys.h (revision 4877389942e948c907dd43b3a2d019cdca14ea44)
1 /*
2    This is the main PETSc include file (for C and C++).  It is included by all
3    other PETSc include files, so it almost never has to be specifically included.
4    Portions of this code are under:
5    Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
6 */
7 #ifndef PETSCSYS_H
8 #define PETSCSYS_H
9 
10 /* ========================================================================== */
11 /*
12    petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is
13    found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that
14    PETSc's makefiles add to the compiler rules.
15    For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same
16    directory as the other PETSc include files.
17 */
18 #include <petscconf.h>
19 #include <petscconf_poison.h>
20 #include <petscfix.h>
21 #include <petscmacros.h>
22 
23 /* SUBMANSEC = Sys */
24 
25 #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS)
26   /*
27    Feature test macros must be included before headers defined by IEEE Std 1003.1-2001
28    We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS
29 */
30   #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE)
31     #define _POSIX_C_SOURCE 200112L
32   #endif
33   #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE)
34     #define _BSD_SOURCE
35   #endif
36   #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
37     #define _DEFAULT_SOURCE
38   #endif
39   #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE)
40     #define _GNU_SOURCE
41   #endif
42 #endif
43 
44 #include <petscsystypes.h>
45 
46 /* ========================================================================== */
47 
48 /*
49     Defines the interface to MPI allowing the use of all MPI functions.
50 
51     PETSc does not use the C++ binding of MPI at ALL. The following flag
52     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
53     putting mpi.h before ANY C++ include files, we cannot control this
54     with all PETSc users. Users who want to use the MPI C++ bindings can include
55     mpicxx.h directly in their code
56 */
57 #if !defined(MPICH_SKIP_MPICXX)
58   #define MPICH_SKIP_MPICXX 1
59 #endif
60 #if !defined(OMPI_SKIP_MPICXX)
61   #define OMPI_SKIP_MPICXX 1
62 #endif
63 #if defined(PETSC_HAVE_MPIUNI)
64   #include <petsc/mpiuni/mpi.h>
65 #else
66   #include <mpi.h>
67 #endif
68 
69 /*
70    Perform various sanity checks that the correct mpi.h is being included at compile time.
71    This usually happens because
72       * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or
73       * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler
74 */
75 #if defined(PETSC_HAVE_MPIUNI)
76   #ifndef MPIUNI_H
77     #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
78   #endif
79 #elif defined(PETSC_HAVE_I_MPI_NUMVERSION)
80   #if !defined(I_MPI_NUMVERSION)
81     #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h"
82   #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION
83     #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"
84   #endif
85 #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION)
86   #if !defined(MVAPICH2_NUMVERSION)
87     #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h"
88   #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION
89     #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version"
90   #endif
91 #elif defined(PETSC_HAVE_MPICH_NUMVERSION)
92   #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION)
93     #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
94   #elif (MPICH_NUMVERSION / 100000000 != PETSC_HAVE_MPICH_NUMVERSION / 100000000) || (MPICH_NUMVERSION / 100000 < PETSC_HAVE_MPICH_NUMVERSION / 100000) || (MPICH_NUMVERSION / 100000 == PETSC_HAVE_MPICH_NUMVERSION / 100000 && MPICH_NUMVERSION % 100000 / 1000 < PETSC_HAVE_MPICH_NUMVERSION % 100000 / 1000)
95     #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version"
96   #endif
97 #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION)
98   #if !defined(OMPI_MAJOR_VERSION)
99     #error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h"
100   #elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION)
101     #error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version"
102   #endif
103   #define PETSC_MPI_COMM_FMT "p"
104   #define PETSC_MPI_WIN_FMT  "p"
105 #elif defined(PETSC_HAVE_MSMPI_VERSION)
106   #if !defined(MSMPI_VER)
107     #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h"
108   #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION)
109     #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version"
110   #endif
111 #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER)
112   #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant"
113 #endif
114 
115 /* Format specifier for printing MPI_Comm (most implementations use 'int' as type) */
116 #if !defined(PETSC_MPI_COMM_FMT)
117   #define PETSC_MPI_COMM_FMT "d"
118 #endif
119 
120 #if !defined(PETSC_MPI_WIN_FMT)
121   #define PETSC_MPI_WIN_FMT "d"
122 #endif
123 
124 /*
125     Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
126     see the top of mpicxx.h in the MPICH2 distribution.
127 */
128 #include <stdio.h>
129 
130 /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
131 #if !defined(MPIAPI)
132   #define MPIAPI
133 #endif
134 
135 PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum);
136 PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool);
137 
138 /*MC
139    MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt`
140 
141    Notes:
142    In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.
143 
144    Level: beginner
145 
146 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
147 M*/
148 
149 PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;
150 
151 #if defined(PETSC_USE_64BIT_INDICES)
152   #define MPIU_INT     MPIU_INT64
153   #define PetscInt_FMT PetscInt64_FMT
154 #else
155   #define MPIU_INT     MPI_INT
156   #define PetscInt_FMT "d"
157 #endif
158 
159 /*
160     For the rare cases when one needs to send a size_t object with MPI
161 */
162 PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t);
163 
164 /*
165       You can use PETSC_STDOUT as a replacement of stdout. You can also change
166     the value of PETSC_STDOUT to redirect all standard output elsewhere
167 */
168 PETSC_EXTERN FILE *PETSC_STDOUT;
169 
170 /*
171       You can use PETSC_STDERR as a replacement of stderr. You can also change
172     the value of PETSC_STDERR to redirect all standard error elsewhere
173 */
174 PETSC_EXTERN FILE *PETSC_STDERR;
175 
176 /* PetscPragmaSIMD - from CeedPragmaSIMD */
177 
178 #if defined(__NEC__)
179   #define PetscPragmaSIMD _Pragma("_NEC ivdep")
180 #elif defined(__INTEL_COMPILER) && !defined(_WIN32)
181   #define PetscPragmaSIMD _Pragma("vector")
182 #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI)
183   #define PetscPragmaSIMD _Pragma("GCC ivdep")
184 #elif defined(_OPENMP) && _OPENMP >= 201307
185   #if defined(_MSC_VER)
186     #define PetscPragmaSIMD __pragma(omp simd)
187   #else
188     #define PetscPragmaSIMD _Pragma("omp simd")
189   #endif
190 #elif defined(PETSC_HAVE_CRAY_VECTOR)
191   #define PetscPragmaSIMD _Pragma("_CRI ivdep")
192 #else
193   #define PetscPragmaSIMD
194 #endif
195 
196 /*
197     Declare extern C stuff after including external header files
198 */
199 
200 PETSC_EXTERN const char *const PetscBools[];
201 
202 PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
203 /*
204     Defines elementary mathematics functions and constants.
205 */
206 #include <petscmath.h>
207 
208 PETSC_EXTERN const char *const PetscCopyModes[];
209 
210 /*MC
211     PETSC_IGNORE - same as NULL, means PETSc will ignore this argument
212 
213    Level: beginner
214 
215    Note:
216    Accepted by many PETSc functions to not set a parameter and instead use some default
217 
218    Fortran Note:
219    This macro does not exist in Fortran; you must use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc
220 
221 .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE`
222 
223 M*/
224 #define PETSC_IGNORE NULL
225 
226 /* This is deprecated */
227 #define PETSC_NULL NULL
228 
229 /*MC
230     PETSC_DECIDE - standard way of passing in integer or floating point parameter
231        where you wish PETSc to use the default.
232 
233    Level: beginner
234 
235 .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`
236 
237 M*/
238 #define PETSC_DECIDE -1
239 
240 /*MC
241     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
242        where you wish PETSc to compute the required value.
243 
244    Level: beginner
245 
246    Developer Note:
247    I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for
248      some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value.
249 
250 .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`
251 
252 M*/
253 #define PETSC_DETERMINE PETSC_DECIDE
254 
255 /*MC
256     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
257        where you wish PETSc to use the default.
258 
259    Level: beginner
260 
261    Fortran Note:
262    You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`.
263 
264 .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`
265 
266 M*/
267 #define PETSC_DEFAULT -2
268 
269 /*MC
270     PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents
271            all the processes that PETSc knows about.
272 
273    Level: beginner
274 
275    Notes:
276    By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to
277           run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller)
278           communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling
279           PetscInitialize(), but after `MPI_Init()` has been called.
280 
281           The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()`
282           is called because it may not have a valid value yet.
283 
284 .seealso: `PETSC_COMM_SELF`
285 
286 M*/
287 PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
288 
289 /*MC
290     PETSC_COMM_SELF - This is always `MPI_COMM_SELF`
291 
292    Level: beginner
293 
294    Notes:
295    Do not USE/access or set this variable before PetscInitialize() has been called.
296 
297 .seealso: `PETSC_COMM_WORLD`
298 
299 M*/
300 #define PETSC_COMM_SELF MPI_COMM_SELF
301 
302 /*MC
303     PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes
304            MPI with `MPI_Init_thread()`.
305 
306    Level: beginner
307 
308    Notes:
309    By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`.
310 
311 .seealso: `PetscInitialize()`
312 
313 M*/
314 PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
315 
316 PETSC_EXTERN PetscBool PetscBeganMPI;
317 PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
318 PETSC_EXTERN PetscBool PetscInitializeCalled;
319 PETSC_EXTERN PetscBool PetscFinalizeCalled;
320 PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
321 
322 PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
323 PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
324 PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
325 PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
326 PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);
327 
328 #if defined(PETSC_HAVE_KOKKOS)
329 PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
330 #endif
331 
332 #if defined(PETSC_HAVE_NVSHMEM)
333 PETSC_EXTERN PetscBool      PetscBeganNvshmem;
334 PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
335 PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
336 #endif
337 
338 #if defined(PETSC_HAVE_ELEMENTAL)
339 PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
340 PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
341 PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
342 #endif
343 
344 /*MC
345    PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this
346 
347    Synopsis:
348     #include <petscsys.h>
349    PetscErrorCode PetscMalloc(size_t m,void **result)
350 
351    Not Collective
352 
353    Input Parameter:
354 .  m - number of bytes to allocate
355 
356    Output Parameter:
357 .  result - memory allocated
358 
359    Level: beginner
360 
361    Notes:
362    Memory is always allocated at least double aligned
363 
364    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`.
365 
366 .seealso: `PetscFree()`, `PetscNew()`
367 
368 M*/
369 #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
370 
371 /*MC
372    PetscRealloc - Reallocates memory
373 
374    Synopsis:
375     #include <petscsys.h>
376    PetscErrorCode PetscRealloc(size_t m,void **result)
377 
378    Not Collective
379 
380    Input Parameters:
381 +  m - number of bytes to allocate
382 -  result - previous memory
383 
384    Output Parameter:
385 .  result - new memory allocated
386 
387    Level: developer
388 
389    Notes:
390    Memory is always allocated at least double aligned
391 
392 .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
393 
394 M*/
395 #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))
396 
397 /*MC
398    PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment
399 
400    Synopsis:
401     #include <petscsys.h>
402    void *PetscAddrAlign(void *addr)
403 
404    Not Collective
405 
406    Input Parameters:
407 .  addr - address to align (any pointer type)
408 
409    Level: developer
410 
411 .seealso: `PetscMallocAlign()`
412 
413 M*/
414 #define PetscAddrAlign(a) (void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))
415 
416 /*MC
417    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`
418 
419    Synopsis:
420     #include <petscsys.h>
421    PetscErrorCode PetscCalloc(size_t m,void **result)
422 
423    Not Collective
424 
425    Input Parameter:
426 .  m - number of bytes to allocate
427 
428    Output Parameter:
429 .  result - memory allocated
430 
431    Level: beginner
432 
433    Notes:
434    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
435 
436    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree().
437 
438 .seealso: `PetscFree()`, `PetscNew()`
439 
440 M*/
441 #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m), (result))
442 
443 /*MC
444    PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`
445 
446    Synopsis:
447     #include <petscsys.h>
448    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
449 
450    Not Collective
451 
452    Input Parameter:
453 .  m1 - number of elements to allocate  (may be zero)
454 
455    Output Parameter:
456 .  r1 - memory allocated
457 
458    Note:
459    This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not
460          multiply the number of elements requested by the `sizeof()` the type. For example use
461 $  PetscInt *id;
462 $  PetscMalloc1(10,&id);
463         not
464 $  PetscInt *id;
465 $  PetscMalloc1(10*sizeof(PetscInt),&id);
466 
467         Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.
468 
469    Level: beginner
470 
471 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
472 
473 M*/
474 #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1))
475 
476 /*MC
477    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`
478 
479    Synopsis:
480     #include <petscsys.h>
481    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
482 
483    Not Collective
484 
485    Input Parameter:
486 .  m1 - number of elements to allocate in 1st chunk  (may be zero)
487 
488    Output Parameter:
489 .  r1 - memory allocated
490 
491    Notes:
492    See `PetsMalloc1()` for more details on usage.
493 
494    Level: beginner
495 
496 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
497 
498 M*/
499 #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1))
500 
501 /*MC
502    PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`
503 
504    Synopsis:
505     #include <petscsys.h>
506    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
507 
508    Not Collective
509 
510    Input Parameters:
511 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
512 -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
513 
514    Output Parameters:
515 +  r1 - memory allocated in first chunk
516 -  r2 - memory allocated in second chunk
517 
518    Level: developer
519 
520 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
521 
522 M*/
523 #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))
524 
525 /*MC
526    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`
527 
528    Synopsis:
529     #include <petscsys.h>
530    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
531 
532    Not Collective
533 
534    Input Parameters:
535 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
536 -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
537 
538    Output Parameters:
539 +  r1 - memory allocated in first chunk
540 -  r2 - memory allocated in second chunk
541 
542    Level: developer
543 
544 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
545 
546 M*/
547 #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))
548 
549 /*MC
550    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`
551 
552    Synopsis:
553     #include <petscsys.h>
554    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
555 
556    Not Collective
557 
558    Input Parameters:
559 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
560 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
561 -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
562 
563    Output Parameters:
564 +  r1 - memory allocated in first chunk
565 .  r2 - memory allocated in second chunk
566 -  r3 - memory allocated in third chunk
567 
568    Level: developer
569 
570 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
571 
572 M*/
573 #define PetscMalloc3(m1, r1, m2, r2, m3, r3) 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))
574 
575 /*MC
576    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
577 
578    Synopsis:
579     #include <petscsys.h>
580    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
581 
582    Not Collective
583 
584    Input Parameters:
585 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
586 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
587 -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
588 
589    Output Parameters:
590 +  r1 - memory allocated in first chunk
591 .  r2 - memory allocated in second chunk
592 -  r3 - memory allocated in third chunk
593 
594    Level: developer
595 
596 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
597 
598 M*/
599 #define PetscCalloc3(m1, r1, m2, r2, m3, r3) 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))
600 
601 /*MC
602    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`
603 
604    Synopsis:
605     #include <petscsys.h>
606    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
607 
608    Not Collective
609 
610    Input Parameters:
611 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
612 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
613 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
614 -  m4 - number of elements to allocate in 4th chunk  (may be zero)
615 
616    Output Parameters:
617 +  r1 - memory allocated in first chunk
618 .  r2 - memory allocated in second chunk
619 .  r3 - memory allocated in third chunk
620 -  r4 - memory allocated in fourth chunk
621 
622    Level: developer
623 
624 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
625 
626 M*/
627 #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
628   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))
629 
630 /*MC
631    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
632 
633    Synopsis:
634     #include <petscsys.h>
635    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
636 
637    Not Collective
638 
639    Input Parameters:
640 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
641 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
642 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
643 -  m4 - number of elements to allocate in 4th chunk  (may be zero)
644 
645    Output Parameters:
646 +  r1 - memory allocated in first chunk
647 .  r2 - memory allocated in second chunk
648 .  r3 - memory allocated in third chunk
649 -  r4 - memory allocated in fourth chunk
650 
651    Level: developer
652 
653 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
654 
655 M*/
656 #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
657   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))
658 
659 /*MC
660    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`
661 
662    Synopsis:
663     #include <petscsys.h>
664    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)
665 
666    Not Collective
667 
668    Input Parameters:
669 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
670 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
671 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
672 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
673 -  m5 - number of elements to allocate in 5th chunk  (may be zero)
674 
675    Output Parameters:
676 +  r1 - memory allocated in first chunk
677 .  r2 - memory allocated in second chunk
678 .  r3 - memory allocated in third chunk
679 .  r4 - memory allocated in fourth chunk
680 -  r5 - memory allocated in fifth chunk
681 
682    Level: developer
683 
684 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
685 
686 M*/
687 #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
688   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))
689 
690 /*MC
691    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
692 
693    Synopsis:
694     #include <petscsys.h>
695    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)
696 
697    Not Collective
698 
699    Input Parameters:
700 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
701 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
702 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
703 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
704 -  m5 - number of elements to allocate in 5th chunk  (may be zero)
705 
706    Output Parameters:
707 +  r1 - memory allocated in first chunk
708 .  r2 - memory allocated in second chunk
709 .  r3 - memory allocated in third chunk
710 .  r4 - memory allocated in fourth chunk
711 -  r5 - memory allocated in fifth chunk
712 
713    Level: developer
714 
715 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
716 
717 M*/
718 #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
719   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))
720 
721 /*MC
722    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`
723 
724    Synopsis:
725     #include <petscsys.h>
726    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)
727 
728    Not Collective
729 
730    Input Parameters:
731 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
732 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
733 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
734 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
735 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
736 -  m6 - number of elements to allocate in 6th chunk  (may be zero)
737 
738    Output Parameteasr:
739 +  r1 - memory allocated in first chunk
740 .  r2 - memory allocated in second chunk
741 .  r3 - memory allocated in third chunk
742 .  r4 - memory allocated in fourth chunk
743 .  r5 - memory allocated in fifth chunk
744 -  r6 - memory allocated in sixth chunk
745 
746    Level: developer
747 
748 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
749 
750 M*/
751 #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
752   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))
753 
754 /*MC
755    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
756 
757    Synopsis:
758     #include <petscsys.h>
759    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)
760 
761    Not Collective
762 
763    Input Parameters:
764 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
765 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
766 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
767 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
768 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
769 -  m6 - number of elements to allocate in 6th chunk  (may be zero)
770 
771    Output Parameters:
772 +  r1 - memory allocated in first chunk
773 .  r2 - memory allocated in second chunk
774 .  r3 - memory allocated in third chunk
775 .  r4 - memory allocated in fourth chunk
776 .  r5 - memory allocated in fifth chunk
777 -  r6 - memory allocated in sixth chunk
778 
779    Level: developer
780 
781 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
782 
783 M*/
784 #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
785   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))
786 
787 /*MC
788    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`
789 
790    Synopsis:
791     #include <petscsys.h>
792    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)
793 
794    Not Collective
795 
796    Input Parameters:
797 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
798 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
799 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
800 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
801 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
802 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
803 -  m7 - number of elements to allocate in 7th chunk  (may be zero)
804 
805    Output Parameters:
806 +  r1 - memory allocated in first chunk
807 .  r2 - memory allocated in second chunk
808 .  r3 - memory allocated in third chunk
809 .  r4 - memory allocated in fourth chunk
810 .  r5 - memory allocated in fifth chunk
811 .  r6 - memory allocated in sixth chunk
812 -  r7 - memory allocated in seventh chunk
813 
814    Level: developer
815 
816 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
817 
818 M*/
819 #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
820   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))
821 
822 /*MC
823    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`
824 
825    Synopsis:
826     #include <petscsys.h>
827    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)
828 
829    Not Collective
830 
831    Input Parameters:
832 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
833 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
834 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
835 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
836 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
837 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
838 -  m7 - number of elements to allocate in 7th chunk  (may be zero)
839 
840    Output Parameters:
841 +  r1 - memory allocated in first chunk
842 .  r2 - memory allocated in second chunk
843 .  r3 - memory allocated in third chunk
844 .  r4 - memory allocated in fourth chunk
845 .  r5 - memory allocated in fifth chunk
846 .  r6 - memory allocated in sixth chunk
847 -  r7 - memory allocated in seventh chunk
848 
849    Level: developer
850 
851 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
852 
853 M*/
854 #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
855   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))
856 
857 /*MC
858    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`
859 
860    Synopsis:
861     #include <petscsys.h>
862    PetscErrorCode PetscNew(type **result)
863 
864    Not Collective
865 
866    Output Parameter:
867 .  result - memory allocated, sized to match pointer type
868 
869    Level: beginner
870 
871 .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()`
872 
873 M*/
874 #define PetscNew(b) PetscCalloc1(1, (b))
875 
876 #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b))
877 
878 /*MC
879    PetscFree - Frees memory
880 
881    Synopsis:
882     #include <petscsys.h>
883    PetscErrorCode PetscFree(void *memory)
884 
885    Not Collective
886 
887    Input Parameter:
888 .   memory - memory to free (the pointer is ALWAYS set to NULL upon success)
889 
890    Level: beginner
891 
892    Notes:
893    Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.
894 
895    It is safe to call `PetscFree()` on a NULL pointer.
896 
897 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
898 
899 M*/
900 #define PetscFree(a) ((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = NULL, 0))
901 
902 /*MC
903    PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`
904 
905    Synopsis:
906     #include <petscsys.h>
907    PetscErrorCode PetscFree2(void *memory1,void *memory2)
908 
909    Not Collective
910 
911    Input Parameters:
912 +   memory1 - memory to free
913 -   memory2 - 2nd memory to free
914 
915    Level: developer
916 
917    Notes:
918     Memory must have been obtained with `PetscMalloc2()`
919 
920 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
921 
922 M*/
923 #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))
924 
925 /*MC
926    PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`
927 
928    Synopsis:
929     #include <petscsys.h>
930    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
931 
932    Not Collective
933 
934    Input Parameters:
935 +   memory1 - memory to free
936 .   memory2 - 2nd memory to free
937 -   memory3 - 3rd memory to free
938 
939    Level: developer
940 
941    Notes:
942     Memory must have been obtained with `PetscMalloc3()`
943 
944 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
945 
946 M*/
947 #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))
948 
949 /*MC
950    PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`
951 
952    Synopsis:
953     #include <petscsys.h>
954    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
955 
956    Not Collective
957 
958    Input Parameters:
959 +   m1 - memory to free
960 .   m2 - 2nd memory to free
961 .   m3 - 3rd memory to free
962 -   m4 - 4th memory to free
963 
964    Level: developer
965 
966    Notes:
967     Memory must have been obtained with `PetscMalloc4()`
968 
969 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
970 
971 M*/
972 #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))
973 
974 /*MC
975    PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`
976 
977    Synopsis:
978     #include <petscsys.h>
979    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
980 
981    Not Collective
982 
983    Input Parameters:
984 +   m1 - memory to free
985 .   m2 - 2nd memory to free
986 .   m3 - 3rd memory to free
987 .   m4 - 4th memory to free
988 -   m5 - 5th memory to free
989 
990    Level: developer
991 
992    Notes:
993     Memory must have been obtained with `PetscMalloc5()`
994 
995 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
996 
997 M*/
998 #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))
999 
1000 /*MC
1001    PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`
1002 
1003    Synopsis:
1004     #include <petscsys.h>
1005    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1006 
1007    Not Collective
1008 
1009    Input Parameters:
1010 +   m1 - memory to free
1011 .   m2 - 2nd memory to free
1012 .   m3 - 3rd memory to free
1013 .   m4 - 4th memory to free
1014 .   m5 - 5th memory to free
1015 -   m6 - 6th memory to free
1016 
1017    Level: developer
1018 
1019    Notes:
1020     Memory must have been obtained with `PetscMalloc6()`
1021 
1022 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
1023 
1024 M*/
1025 #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))
1026 
1027 /*MC
1028    PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`
1029 
1030    Synopsis:
1031     #include <petscsys.h>
1032    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1033 
1034    Not Collective
1035 
1036    Input Parameters:
1037 +   m1 - memory to free
1038 .   m2 - 2nd memory to free
1039 .   m3 - 3rd memory to free
1040 .   m4 - 4th memory to free
1041 .   m5 - 5th memory to free
1042 .   m6 - 6th memory to free
1043 -   m7 - 7th memory to free
1044 
1045    Level: developer
1046 
1047    Notes:
1048     Memory must have been obtained with `PetscMalloc7()`
1049 
1050 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
1051           `PetscMalloc7()`
1052 
1053 M*/
1054 #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))
1055 
1056 PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
1057 PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
1058 PETSC_EXTERN                PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
1059 PETSC_EXTERN                PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
1060 PETSC_EXTERN                PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
1061 PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
1062 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 **));
1063 PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1064 
1065 /*
1066   Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair.
1067 */
1068 PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1069 PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
1070 #if defined(PETSC_HAVE_CUDA)
1071 PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
1072 PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
1073 #endif
1074 #if defined(PETSC_HAVE_HIP)
1075 PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
1076 PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
1077 #endif
1078 
1079 #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
1080 #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1081 
1082 /*
1083    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1084 */
1085 PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
1086 PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1087 PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1088 PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1089 PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1090 PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
1091 PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
1092 PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
1093 PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
1094 PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
1095 PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
1096 PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1097 PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);
1098 
1099 PETSC_EXTERN const char *const PetscDataTypes[];
1100 PETSC_EXTERN PetscErrorCode    PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
1101 PETSC_EXTERN PetscErrorCode    PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
1102 PETSC_EXTERN PetscErrorCode    PetscDataTypeGetSize(PetscDataType, size_t *);
1103 PETSC_EXTERN PetscErrorCode    PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);
1104 
1105 /*
1106     Basic memory and string operations. These are usually simple wrappers
1107    around the basic Unix system calls, but a few of them have additional
1108    functionality and/or error checking.
1109 */
1110 PETSC_EXTERN PetscErrorCode PetscMemcmp(const void *, const void *, size_t, PetscBool *);
1111 PETSC_EXTERN PetscErrorCode PetscStrlen(const char[], size_t *);
1112 PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[], char, int *, char ***);
1113 PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int, char **);
1114 PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[], const char[], PetscBool *);
1115 PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[], const char[], PetscBool *);
1116 PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[], const char[], PetscBool *);
1117 PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[], const char[], size_t, PetscBool *);
1118 PETSC_EXTERN PetscErrorCode PetscStrcpy(char[], const char[]);
1119 PETSC_EXTERN PetscErrorCode PetscStrcat(char[], const char[]);
1120 PETSC_EXTERN PetscErrorCode PetscStrlcat(char[], const char[], size_t);
1121 PETSC_EXTERN PetscErrorCode PetscStrncpy(char[], const char[], size_t);
1122 PETSC_EXTERN PetscErrorCode PetscStrchr(const char[], char, char *[]);
1123 PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]);
1124 PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]);
1125 PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[], char, char *[]);
1126 PETSC_EXTERN PetscErrorCode PetscStrstr(const char[], const char[], char *[]);
1127 PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[], const char[], char *[]);
1128 PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[], const char[], PetscBool *);
1129 PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[], const char[], PetscBool *);
1130 PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[], const char *const *, PetscInt *);
1131 PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[], char *[]);
1132 PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const *, char ***);
1133 PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char ***);
1134 PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt, const char *const *, char ***);
1135 PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt, char ***);
1136 PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm, const char[], char[], size_t);
1137 
1138 PETSC_EXTERN void PetscStrcmpNoError(const char[], const char[], PetscBool *);
1139 
1140 PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[], const char, PetscToken *);
1141 PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken, char *[]);
1142 PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken *);
1143 
1144 PETSC_EXTERN PetscErrorCode PetscStrInList(const char[], const char[], char, PetscBool *);
1145 PETSC_EXTERN const char    *PetscBasename(const char[]);
1146 PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt, const char *const *, const char *, PetscInt *, PetscBool *);
1147 PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const *, const char *, PetscEnum *, PetscBool *);
1148 
1149 /*
1150    These are MPI operations for MPI_Allreduce() etc
1151 */
1152 PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1153 #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1154 PETSC_EXTERN MPI_Op MPIU_SUM;
1155 PETSC_EXTERN MPI_Op MPIU_MAX;
1156 PETSC_EXTERN MPI_Op MPIU_MIN;
1157 #else
1158   #define MPIU_SUM MPI_SUM
1159   #define MPIU_MAX MPI_MAX
1160   #define MPIU_MIN MPI_MIN
1161 #endif
1162 PETSC_EXTERN MPI_Op         Petsc_Garbage_SetIntersectOp;
1163 PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
1164 
1165 #if defined(PETSC_HAVE_REAL___FLOAT128) || defined(PETSC_HAVE_REAL___FP16)
1166 /*MC
1167     MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with
1168     custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.
1169 
1170    Level: advanced
1171 
1172    Developer Note:
1173    This should be unified with `MPIU_SUM`
1174 
1175 .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
1176 M*/
1177 PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
1178 #endif
1179 PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);
1180 
1181 PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
1182 PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
1183 
1184 PETSC_EXTERN const char *const PetscFileModes[];
1185 
1186 /*
1187     Defines PETSc error handling.
1188 */
1189 #include <petscerror.h>
1190 
1191 PETSC_EXTERN PetscBool   PetscCIEnabled;                    /* code is running in the PETSc test harness CI */
1192 PETSC_EXTERN PetscBool   PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
1193 PETSC_EXTERN const char *PetscCIFilename(const char *);
1194 PETSC_EXTERN int         PetscCILinenumber(int);
1195 
1196 #define PETSC_SMALLEST_CLASSID 1211211
1197 PETSC_EXTERN PetscClassId   PETSC_LARGEST_CLASSID;
1198 PETSC_EXTERN PetscClassId   PETSC_OBJECT_CLASSID;
1199 PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
1200 PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
1201 PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);
1202 
1203 /*
1204    Routines that get memory usage information from the OS
1205 */
1206 PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1207 PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1208 PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1209 PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1210 
1211 PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1212 
1213 /*
1214    Initialization of PETSc
1215 */
1216 PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
1217 PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]);
1218 PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1219 PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1220 PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1221 PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1222 PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1223 PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
1224 PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1225 PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1226 
1227 PETSC_EXTERN PetscErrorCode PetscEnd(void);
1228 PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
1229 
1230 PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
1231 PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1232 PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1233 PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);
1234 
1235 PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *);
1236 
1237 /*
1238      These are so that in extern C code we can caste function pointers to non-extern C
1239    function pointers. Since the regular C++ code expects its function pointers to be C++
1240 */
1241 PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void);
1242 PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void);
1243 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1244 
1245 /*
1246     Functions that can act on any PETSc object.
1247 */
1248 PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
1249 PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
1250 PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
1251 PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
1252 PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
1253 PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
1254 PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
1255 PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
1256 PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
1257 PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
1258 PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1259 PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
1260 PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1261 PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
1262 PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
1263 PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
1264 PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
1265 PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void));
1266 #define PetscObjectComposeFunction(a, b, d) PetscObjectComposeFunction_Private(a, b, (PetscVoidFunction)(d))
1267 PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1268 PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
1269 PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
1270 PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
1271 PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);
1272 
1273 #include <petscviewertypes.h>
1274 #include <petscoptions.h>
1275 
1276 PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
1277 PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);
1278 
1279 PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *);
1280 
1281 PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
1282 PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
1283 PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
1284 #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr))
1285 PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void));
1286 PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
1287 PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
1288 PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
1289 PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
1290 PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
1291 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1292 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1293 PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
1294 PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1295 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
1296 PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
1297 PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
1298 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1299 PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
1300 PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1301 PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1302 
1303 #if defined(PETSC_HAVE_SAWS)
1304 PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1305 PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1306 PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
1307 PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1308 PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1309 PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1310 PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1311 PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1312 PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1313 PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
1314 
1315 #else
1316   #define PetscSAWsBlock()                  0
1317   #define PetscObjectSAWsViewOff(obj)       0
1318   #define PetscObjectSAWsSetBlock(obj, flg) 0
1319   #define PetscObjectSAWsBlock(obj)         0
1320   #define PetscObjectSAWsGrantAccess(obj)   0
1321   #define PetscObjectSAWsTakeAccess(obj)    0
1322   #define PetscStackViewSAWs()              0
1323   #define PetscStackSAWsViewOff()           0
1324   #define PetscStackSAWsTakeAccess()
1325   #define PetscStackSAWsGrantAccess()
1326 
1327 #endif
1328 
1329 PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
1330 PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
1331 PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
1332 PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **);
1333 #ifdef PETSC_HAVE_CXX
1334 PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **);
1335 #endif
1336 
1337 #if defined(PETSC_USE_DEBUG)
1338 PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);
1339 #endif
1340 PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
1341 
1342 PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
1343 PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
1344 PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *);
1345 PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
1346 PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
1347 PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);
1348 
1349 /*
1350     Dynamic library lists. Lists of names of routines in objects or in dynamic
1351   link libraries that will be loaded as needed.
1352 */
1353 
1354 #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr))
1355 PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], void (*)(void));
1356 PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
1357 PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
1358 #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr))
1359 PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], void (**)(void));
1360 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
1361 PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
1362 PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
1363 PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
1364 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
1365 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);
1366 
1367 PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
1368 PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
1369 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
1370 PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
1371 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1372 PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
1373 PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
1374 PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1375 
1376 /*
1377      Useful utility routines
1378 */
1379 PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
1380 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
1381 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
1382 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
1383 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
1384 PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1385 PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
1386 PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
1387 PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);
1388 
1389 /*MC
1390     PetscNot - negates a logical type value and returns result as a `PetscBool`
1391 
1392     Level: beginner
1393 
1394     Note:
1395     This is useful in cases like
1396 .vb
1397      int        *a;
1398      PetscBool  flag = PetscNot(a)
1399 .ve
1400      where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.
1401 
1402 .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
1403 M*/
1404 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1405 
1406 /*MC
1407     PetscHelpPrintf - Prints help messages.
1408 
1409     Not Collective, only applies on rank 0; No Fortran Support
1410 
1411    Synopsis:
1412     #include <petscsys.h>
1413      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1414 
1415     Input Parameters:
1416 +  comm - the MPI communicator over which the help message is printed
1417 .  format - the usual printf() format string
1418 -  args - arguments to be printed
1419 
1420    Level: developer
1421 
1422    Note:
1423      You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1424 
1425       To use, write your own function, for example,
1426 $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
1427 ${
1428 $ PetscFunctionReturn(0);
1429 $}
1430 then do the assignment
1431 $    PetscHelpPrintf = mypetschelpprintf;
1432    You can do the assignment before `PetscInitialize()`.
1433 
1434   The default routine used is called `PetscHelpPrintfDefault()`.
1435 
1436 .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`
1437 M*/
1438 PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1439 
1440 /*
1441      Defines PETSc profiling.
1442 */
1443 #include <petsclog.h>
1444 
1445 /*
1446       Simple PETSc parallel IO for ASCII printing
1447 */
1448 PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
1449 PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
1450 PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
1451 PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1452 PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1453 PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1454 PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
1455 PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);
1456 
1457 PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
1458 PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
1459 PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1460 
1461 PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
1462 PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);
1463 
1464 #if defined(PETSC_HAVE_POPEN)
1465 PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
1466 PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
1467 PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1468 #endif
1469 
1470 PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
1471 PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
1472 PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
1473 PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
1474 PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
1475 PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **);
1476 PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);
1477 
1478 PETSC_EXTERN PetscClassId   PETSC_CONTAINER_CLASSID;
1479 PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **);
1480 PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
1481 PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
1482 PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
1483 PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
1484 PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *);
1485 
1486 /*
1487    For use in debuggers
1488 */
1489 PETSC_EXTERN PetscMPIInt    PetscGlobalRank;
1490 PETSC_EXTERN PetscMPIInt    PetscGlobalSize;
1491 PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
1492 PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
1493 PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);
1494 
1495 #include <stddef.h>
1496 #include <string.h> /* for memcpy, memset */
1497 #include <stdlib.h>
1498 
1499 #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__)
1500   #include <xmmintrin.h>
1501 #endif
1502 
1503 /*@C
1504    PetscMemmove - Copies n bytes, beginning at location b, to the space
1505    beginning at location a. Copying  between regions that overlap will
1506    take place correctly. Use `PetscMemcpy()` if the locations do not overlap
1507 
1508    Not Collective
1509 
1510    Input Parameters:
1511 +  b - pointer to initial memory space
1512 .  a - pointer to copy space
1513 -  n - length (in bytes) of space to copy
1514 
1515    Level: intermediate
1516 
1517    Notes:
1518    `PetscArraymove()` is preferred
1519 
1520    This routine is analogous to `memmove()`.
1521 
1522    Developers Note:
1523    This is inlined for performance
1524 
1525 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`,
1526           `PetscArraymove()`
1527 @*/
1528 static inline PetscErrorCode PetscMemmove(void *a, const void *b, size_t n)
1529 {
1530   PetscFunctionBegin;
1531   if (n > 0) {
1532     PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to null pointer");
1533     PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer");
1534   }
1535 #if !defined(PETSC_HAVE_MEMMOVE)
1536   if (a < b) {
1537     if (a <= b - n) memcpy(a, b, n);
1538     else {
1539       memcpy(a, b, (int)(b - a));
1540       PetscMemmove(b, b + (int)(b - a), n - (int)(b - a));
1541     }
1542   } else {
1543     if (b <= a - n) memcpy(a, b, n);
1544     else {
1545       memcpy(b + n, b + (n - (int)(a - b)), (int)(a - b));
1546       PetscMemmove(a, b, n - (int)(a - b));
1547     }
1548   }
1549 #else
1550   memmove((char *)(a), (char *)(b), n);
1551 #endif
1552   PetscFunctionReturn(0);
1553 }
1554 
1555 /*@C
1556    PetscMemcpy - Copies n bytes, beginning at location b, to the space
1557    beginning at location a. The two memory regions CANNOT overlap, use
1558    `PetscMemmove()` in that case.
1559 
1560    Not Collective
1561 
1562    Input Parameters:
1563 +  b - pointer to initial memory space
1564 -  n - length (in bytes) of space to copy
1565 
1566    Output Parameter:
1567 .  a - pointer to copy space
1568 
1569    Level: intermediate
1570 
1571    Compile Option:
1572     `PETSC_PREFER_DCOPY_FOR_MEMCPY` will cause the BLAS dcopy() routine to be used
1573                                   for memory copies on double precision values.
1574     `PETSC_PREFER_COPY_FOR_MEMCPY` will cause C code to be used
1575                                   for memory copies on double precision values.
1576     `PETSC_PREFER_FORTRAN_FORMEMCPY` will cause Fortran code to be used
1577                                   for memory copies on double precision values.
1578 
1579    Notes:
1580    Prefer `PetscArraycpy()`
1581 
1582    This routine is analogous to `memcpy()`.
1583 
1584    Not available from Fortran
1585 
1586    Developer Note:
1587    This is inlined for fastest performance
1588 
1589 .seealso: `PetscMemzero()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`
1590 
1591 @*/
1592 static inline PetscErrorCode PetscMemcpy(void *a, const void *b, size_t n)
1593 {
1594 #if defined(PETSC_USE_DEBUG)
1595   size_t al = (size_t)a, bl = (size_t)b;
1596   size_t nl = (size_t)n;
1597   PetscFunctionBegin;
1598   if (n > 0) {
1599     PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer");
1600     PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to a null pointer");
1601   }
1602 #else
1603   PetscFunctionBegin;
1604 #endif
1605   if (a != b && n > 0) {
1606 #if defined(PETSC_USE_DEBUG)
1607     PetscCheck(!((al > bl && (al - bl) < nl) || (bl - al) < nl), PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Memory regions overlap: either use PetscMemmov()\n\
1608               or make sure your copy regions and lengths are correct. \n\
1609               Length (bytes) %zu first address %zu second address %zu",
1610                nl, al, bl);
1611 #endif
1612 #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY))
1613     if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1614       size_t len = n / sizeof(PetscScalar);
1615   #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY)
1616       PetscBLASInt one = 1, blen;
1617       PetscCall(PetscBLASIntCast(len, &blen));
1618       PetscCallBLAS("BLAScopy", BLAScopy_(&blen, (PetscScalar *)b, &one, (PetscScalar *)a, &one));
1619   #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY)
1620       fortrancopy_(&len, (PetscScalar *)b, (PetscScalar *)a);
1621   #else
1622       PetscScalar *x = (PetscScalar *)b, *y = (PetscScalar *)a;
1623       for (size_t i = 0; i < len; i++) y[i] = x[i];
1624   #endif
1625     } else {
1626       memcpy((char *)(a), (char *)(b), n);
1627     }
1628 #else
1629     memcpy((char *)(a), (char *)(b), n);
1630 #endif
1631   }
1632   PetscFunctionReturn(0);
1633 }
1634 
1635 /*@C
1636    PetscMemzero - Zeros the specified memory.
1637 
1638    Not Collective
1639 
1640    Input Parameters:
1641 +  a - pointer to beginning memory location
1642 -  n - length (in bytes) of memory to initialize
1643 
1644    Level: intermediate
1645 
1646    Compile Option:
1647    `PETSC_PREFER_BZERO` - on certain machines (the IBM RS6000) the bzero() routine happens
1648   to be faster than the memset() routine. This flag causes the bzero() routine to be used.
1649 
1650    Notes:
1651    Not available from Fortran
1652 
1653    Prefer `PetscArrayzero()`
1654 
1655    Developer Note:
1656    This is inlined for fastest performance
1657 
1658 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`
1659 @*/
1660 static inline PetscErrorCode PetscMemzero(void *a, size_t n)
1661 {
1662   if (n > 0) {
1663 #if defined(PETSC_USE_DEBUG)
1664     PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to zero at a null pointer with %zu bytes", n);
1665 #endif
1666 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO)
1667     if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1668       size_t       i, len = n / sizeof(PetscScalar);
1669       PetscScalar *x = (PetscScalar *)a;
1670       for (i = 0; i < len; i++) x[i] = 0.0;
1671     } else {
1672 #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1673     if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1674       PetscInt len = n / sizeof(PetscScalar);
1675       fortranzero_(&len, (PetscScalar *)a);
1676     } else {
1677 #endif
1678 #if defined(PETSC_PREFER_BZERO)
1679       bzero((char *)a, n);
1680 #else
1681       memset((char *)a, 0, n);
1682 #endif
1683 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1684     }
1685 #endif
1686   }
1687   return 0;
1688 }
1689 
1690 /*MC
1691    PetscArraycmp - Compares two arrays in memory.
1692 
1693    Synopsis:
1694     #include <petscsys.h>
1695     PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e)
1696 
1697    Not Collective
1698 
1699    Input Parameters:
1700 +  str1 - First array
1701 .  str2 - Second array
1702 -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1703 
1704    Output Parameters:
1705 .   e - `PETSC_TRUE` if equal else `PETSC_FALSE`.
1706 
1707    Level: intermediate
1708 
1709    Notes:
1710    This routine is a preferred replacement to `PetscMemcmp()`
1711 
1712    The arrays must be of the same type
1713 
1714 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`,
1715           `PetscArraymove()`
1716 M*/
1717 #define PetscArraycmp(str1, str2, cnt, e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1, str2, (size_t)(cnt) * sizeof(*(str1)), e))
1718 
1719 /*MC
1720    PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use `PetscArraycpy()` when the arrays
1721                     do not overlap
1722 
1723    Synopsis:
1724     #include <petscsys.h>
1725     PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt)
1726 
1727    Not Collective
1728 
1729    Input Parameters:
1730 +  str1 - First array
1731 .  str2 - Second array
1732 -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1733 
1734    Level: intermediate
1735 
1736    Notes:
1737    This routine is a preferred replacement to `PetscMemmove()`
1738 
1739    The arrays must be of the same type
1740 
1741 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()`
1742 M*/
1743 #define PetscArraymove(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1, str2, (size_t)(cnt) * sizeof(*(str1))))
1744 
1745 /*MC
1746    PetscArraycpy - Copies from one array in memory to another
1747 
1748    Synopsis:
1749     #include <petscsys.h>
1750     PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt)
1751 
1752    Not Collective
1753 
1754    Input Parameters:
1755 +  str1 - First array (destination)
1756 .  str2 - Second array (source)
1757 -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1758 
1759    Level: intermediate
1760 
1761    Notes:
1762    This routine is a preferred replacement to `PetscMemcpy()`
1763 
1764    The arrays must be of the same type
1765 
1766 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraymove()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()`
1767 M*/
1768 #define PetscArraycpy(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcpy(str1, str2, (size_t)(cnt) * sizeof(*(str1))))
1769 
1770 /*MC
1771    PetscArrayzero - Zeros an array in memory.
1772 
1773    Synopsis:
1774     #include <petscsys.h>
1775     PetscErrorCode PetscArrayzero(anytype *str1,size_t cnt)
1776 
1777    Not Collective
1778 
1779    Input Parameters:
1780 +  str1 - array
1781 -  cnt  - Count of the array, not in bytes, but number of entries in the array
1782 
1783    Level: intermediate
1784 
1785    Note:
1786    This routine is a preferred replacement to `PetscMemzero()`
1787 
1788 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, `PetscArraymove()`
1789 M*/
1790 #define PetscArrayzero(str1, cnt) PetscMemzero(str1, (size_t)(cnt) * sizeof(*(str1)))
1791 
1792 /*MC
1793    PetscPrefetchBlock - Prefetches a block of memory
1794 
1795    Synopsis:
1796     #include <petscsys.h>
1797     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1798 
1799    Not Collective
1800 
1801    Input Parameters:
1802 +  a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
1803 .  n - number of elements to fetch
1804 .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
1805 -  t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1806 
1807    Level: developer
1808 
1809    Notes:
1810    The last two arguments (rw and t) must be compile-time constants.
1811 
1812    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
1813    equivalent locality hints, but the following macros are always defined to their closest analogue.
1814 +  `PETSC_PREFETCH_HINT_NTA` - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
1815 .  `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.
1816 .  `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1).
1817 -  `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
1818 
1819    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1820    address).
1821 
1822 M*/
1823 #define PetscPrefetchBlock(a, n, rw, t) \
1824   do { \
1825     const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
1826     for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
1827   } while (0)
1828 
1829 /*
1830       Determine if some of the kernel computation routines use
1831    Fortran (rather than C) for the numerical calculations. On some machines
1832    and compilers (like complex numbers) the Fortran version of the routines
1833    is faster than the C/C++ versions. The flag --with-fortran-kernels
1834    should be used with ./configure to turn these on.
1835 */
1836 #if defined(PETSC_USE_FORTRAN_KERNELS)
1837 
1838   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1839     #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1840   #endif
1841 
1842   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM)
1843     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM
1844   #endif
1845 
1846   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1847     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1848   #endif
1849 
1850   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1851     #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1852   #endif
1853 
1854   #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1855     #define PETSC_USE_FORTRAN_KERNEL_NORM
1856   #endif
1857 
1858   #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1859     #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1860   #endif
1861 
1862   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1863     #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1864   #endif
1865 
1866   #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1867     #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1868   #endif
1869 
1870   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1871     #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1872   #endif
1873 
1874   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1875     #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1876   #endif
1877 
1878   #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1879     #define PETSC_USE_FORTRAN_KERNEL_MDOT
1880   #endif
1881 
1882   #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1883     #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1884   #endif
1885 
1886   #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1887     #define PETSC_USE_FORTRAN_KERNEL_AYPX
1888   #endif
1889 
1890   #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1891     #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1892   #endif
1893 
1894 #endif
1895 
1896 /*
1897     Macros for indicating code that should be compiled with a C interface,
1898    rather than a C++ interface. Any routines that are dynamically loaded
1899    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1900    mangler does not change the functions symbol name. This just hides the
1901    ugly extern "C" {} wrappers.
1902 */
1903 #if defined(__cplusplus)
1904   #define EXTERN_C_BEGIN extern "C" {
1905   #define EXTERN_C_END   }
1906 #else
1907   #define EXTERN_C_BEGIN
1908   #define EXTERN_C_END
1909 #endif
1910 
1911 /* --------------------------------------------------------------------*/
1912 
1913 /*MC
1914     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1915         communication
1916 
1917    Level: beginner
1918 
1919    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1920 
1921 .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
1922 M*/
1923 
1924 #if defined(PETSC_HAVE_MPIIO)
1925 PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
1926 PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
1927 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);
1928 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);
1929 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);
1930 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);
1931 #endif
1932 
1933 /* the following petsc_static_inline require petscerror.h */
1934 
1935 /* Limit MPI to 32-bits */
1936 #define PETSC_MPI_INT_MAX 2147483647
1937 #define PETSC_MPI_INT_MIN -2147483647
1938 /* Limit BLAS to 32-bits */
1939 #define PETSC_BLAS_INT_MAX    2147483647
1940 #define PETSC_BLAS_INT_MIN    -2147483647
1941 #define PETSC_CUBLAS_INT_MAX  2147483647
1942 #define PETSC_HIPBLAS_INT_MAX 2147483647
1943 
1944 /*@C
1945     PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an
1946          error if the `PetscInt` is not large enough to hold the number.
1947 
1948    Not Collective
1949 
1950    Input Parameter:
1951 .     a - the `PetscInt64` value
1952 
1953    Output Parameter:
1954 .     b - the resulting `PetscInt` value
1955 
1956    Level: advanced
1957 
1958    Notes:
1959    If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make `PetscInt` use 64 bit ints
1960 
1961    Not available from Fortran
1962 
1963 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
1964 @*/
1965 static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b)
1966 {
1967   PetscFunctionBegin;
1968 #if !defined(PETSC_USE_64BIT_INDICES)
1969   if (a > PETSC_MAX_INT) {
1970     *b = 0;
1971     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a);
1972   }
1973 #endif
1974   *b = (PetscInt)(a);
1975   PetscFunctionReturn(0);
1976 }
1977 
1978 /*@C
1979     PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an
1980          error if the `PetscInt` is not large enough to hold the number.
1981 
1982    Not Collective
1983 
1984    Input Parameter:
1985 .     a - the `PetscCount` value
1986 
1987    Output Parameter:
1988 .     b - the resulting `PetscInt` value
1989 
1990    Level: advanced
1991 
1992    Notes:
1993      If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make PetscInt use 64 bit ints
1994 
1995    Not available from Fortran
1996 
1997 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()`
1998 @*/
1999 static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b)
2000 {
2001   PetscFunctionBegin;
2002   if (sizeof(PetscCount) > sizeof(PetscInt) && a > PETSC_MAX_INT) {
2003     *b = 0;
2004     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a);
2005   }
2006   *b = (PetscInt)(a);
2007   PetscFunctionReturn(0);
2008 }
2009 
2010 /*@C
2011     PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an
2012          error if the `PetscBLASInt` is not large enough to hold the number.
2013 
2014    Not Collective
2015 
2016    Input Parameter:
2017 .     a - the `PetscInt` value
2018 
2019    Output Parameter:
2020 .     b - the resulting `PetscBLASInt` value
2021 
2022    Level: advanced
2023 
2024    Notes:
2025    Not available from Fortran
2026 
2027    Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
2028 
2029 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()`
2030 @*/
2031 static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b)
2032 {
2033   PetscFunctionBegin;
2034   *b = 0;
2035   if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) {
2036     PetscCheck(a <= PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for BLAS/LAPACK, which is restricted to 32 bit integers. Either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-blas-indices for the case you are running", a);
2037   }
2038   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
2039   *b = (PetscBLASInt)(a);
2040   PetscFunctionReturn(0);
2041 }
2042 
2043 /*@C
2044     PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.
2045 
2046    Not Collective
2047 
2048    Input Parameter:
2049 .     a - the `PetscInt` value
2050 
2051    Output Parameter:
2052 .     b - the resulting `PetscCuBLASInt` value
2053 
2054    Level: advanced
2055 
2056    Notes:
2057       Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
2058 
2059 .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
2060 @*/
2061 static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b)
2062 {
2063   PetscFunctionBegin;
2064   *b = 0;
2065   if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32 bit integers.", a);
2066   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to cuBLAS routine");
2067   *b = (PetscCuBLASInt)(a);
2068   PetscFunctionReturn(0);
2069 }
2070 
2071 /*@C
2072     PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.
2073 
2074    Not Collective
2075 
2076    Input Parameter:
2077 .     a - the `PetscInt` value
2078 
2079    Output Parameter:
2080 .     b - the resulting `PetscHipBLASInt` value
2081 
2082    Level: advanced
2083 
2084    Notes:
2085       Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs
2086 
2087 .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()`
2088 @*/
2089 static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b)
2090 {
2091   PetscFunctionBegin;
2092   *b = 0;
2093   if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32 bit integers.", a);
2094   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to hipBLAS routine");
2095   *b = (PetscHipBLASInt)(a);
2096   PetscFunctionReturn(0);
2097 }
2098 
2099 /*@C
2100     PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an
2101          error if the PetscMPIInt is not large enough to hold the number.
2102 
2103    Not Collective
2104 
2105    Input Parameter:
2106 .     a - the `PetscInt` value
2107 
2108    Output Parameter:
2109 .     b - the resulting `PetscMPIInt` value
2110 
2111    Level: advanced
2112 
2113    Not available from Fortran
2114 
2115 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
2116 @*/
2117 static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b)
2118 {
2119   PetscFunctionBegin;
2120   *b = 0;
2121   if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_MPI_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for MPI buffer length. We currently only support 32 bit integers", a);
2122   *b = (PetscMPIInt)(a);
2123   PetscFunctionReturn(0);
2124 }
2125 
2126 #define PetscInt64Mult(a, b) ((PetscInt64)(a)) * ((PetscInt64)(b))
2127 
2128 /*@C
2129 
2130    PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive `PetscInt` and truncates the value to slightly less than the maximal possible value
2131 
2132    Not Collective
2133 
2134    Input Parameters:
2135 +     a - the `PetscReal` value
2136 -     b - the second value
2137 
2138    Returns:
2139       the result as a `PetscInt` value
2140 
2141    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2142    Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate to fit a `PetscInt`
2143    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`
2144 
2145    Developers Note:
2146    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
2147 
2148    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2149 
2150    Not available from Fortran
2151 
2152    Level: advanced
2153 
2154 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
2155 @*/
2156 static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
2157 {
2158   PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
2159   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2160   return (PetscInt)r;
2161 }
2162 
2163 /*@C
2164 
2165    PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
2166 
2167    Not Collective
2168 
2169    Input Parameters:
2170 +     a - the PetscInt value
2171 -     b - the second value
2172 
2173    Returns:
2174       the result as a `PetscInt` value
2175 
2176    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2177    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2178    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`
2179 
2180    Not available from Fortran
2181 
2182    Developers Note:
2183    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.
2184 
2185    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2186 
2187    Level: advanced
2188 
2189 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
2190 @*/
2191 static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
2192 {
2193   PetscInt64 r = PetscInt64Mult(a, b);
2194   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2195   return (PetscInt)r;
2196 }
2197 
2198 /*@C
2199 
2200    PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value
2201 
2202    Not Collective
2203 
2204    Input Parameters:
2205 +     a - the `PetscInt` value
2206 -     b - the second value
2207 
2208    Returns:
2209      the result as a `PetscInt` value
2210 
2211    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`
2212    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`
2213    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`
2214 
2215    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2216 
2217    Not available from Fortran
2218 
2219    Level: advanced
2220 
2221 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2222 @*/
2223 static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
2224 {
2225   PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b);
2226   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2227   return (PetscInt)r;
2228 }
2229 
2230 /*@C
2231 
2232    PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.
2233 
2234    Not Collective
2235 
2236    Input Parameters:
2237 +     a - the `PetscInt` value
2238 -     b - the second value
2239 
2240    Output Parameter:
2241 .     result - the result as a `PetscInt` value, or NULL if you do not want the result, you just want to check if it overflows
2242 
2243    Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`
2244    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2245 
2246    Not available from Fortran
2247 
2248    Developers Note:
2249    We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks.
2250 
2251    Level: advanced
2252 
2253 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()`
2254 @*/
2255 static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
2256 {
2257   PetscInt64 r;
2258 
2259   PetscFunctionBegin;
2260   r = PetscInt64Mult(a, b);
2261 #if !defined(PETSC_USE_64BIT_INDICES)
2262   PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %d %d 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);
2263 #endif
2264   if (result) *result = (PetscInt)r;
2265   PetscFunctionReturn(0);
2266 }
2267 
2268 /*@C
2269 
2270    PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.
2271 
2272    Not Collective
2273 
2274    Input Parameters:
2275 +     a - the `PetscInt` value
2276 -     b - the second value
2277 
2278    Output Parameter:
2279 .     c - the result as a `PetscInt` value,  or NULL if you do not want the result, you just want to check if it overflows
2280 
2281    Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64`
2282    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`
2283 
2284    Not available from Fortran
2285 
2286    Level: advanced
2287 
2288 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
2289 @*/
2290 static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
2291 {
2292   PetscInt64 r;
2293 
2294   PetscFunctionBegin;
2295   r = ((PetscInt64)a) + ((PetscInt64)b);
2296 #if !defined(PETSC_USE_64BIT_INDICES)
2297   PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %d %d 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);
2298 #endif
2299   if (result) *result = (PetscInt)r;
2300   PetscFunctionReturn(0);
2301 }
2302 
2303 /*
2304      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
2305 */
2306 #if defined(hz)
2307   #undef hz
2308 #endif
2309 
2310 #include <limits.h>
2311 
2312 /* The number of bits in a byte */
2313 
2314 #define PETSC_BITS_PER_BYTE CHAR_BIT
2315 
2316 #if defined(PETSC_HAVE_SYS_TYPES_H)
2317   #include <sys/types.h>
2318 #endif
2319 
2320 /*MC
2321 
2322     PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++
2323                     and Fortran compilers when petscsys.h is included.
2324 
2325     The current PETSc version and the API for accessing it are defined in <A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscversion.h.html">include/petscverson.html</A>
2326 
2327     The complete version number is given as the triple  PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z)
2328 
2329     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
2330     where only a change in the major version number (x) indicates a change in the API.
2331 
2332     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
2333 
2334     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),
2335     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
2336     version number (x.y.z).
2337 
2338     `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)
2339 
2340     `PETSC_VERSION_DATE` is the date the x.y.z version was released
2341 
2342     `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww
2343 
2344     `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository
2345 
2346     `PETSC_VERSION_()` is deprecated and will eventually be removed.
2347 
2348     Level: intermediate
2349 
2350 M*/
2351 
2352 PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
2353 PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
2354 PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
2355 PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
2356 PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2357 PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
2358 PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
2359 PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);
2360 
2361 PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *);
2362 PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *);
2363 PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *);
2364 PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *);
2365 PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]);
2366 PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]);
2367 PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]);
2368 PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]);
2369 PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
2370 PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
2371 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
2372 PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
2373 PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *);
2374 PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *);
2375 PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
2376 PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
2377 PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]);
2378 PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
2379 PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]);
2380 PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
2381 PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]);
2382 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
2383 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]);
2384 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]);
2385 PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]);
2386 PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *);
2387 PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]);
2388 PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2389 PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
2390 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
2391 PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *);
2392 PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
2393 PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
2394 PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **);
2395 PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **);
2396 PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **);
2397 PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **);
2398 PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
2399 
2400 PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
2401 PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
2402 PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
2403 PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
2404 PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
2405 PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
2406 PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
2407 PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);
2408 
2409 PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2410 PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);
2411 
2412 /*J
2413     PetscRandomType - String with the name of a PETSc randomizer
2414 
2415    Level: beginner
2416 
2417    Notes:
2418    To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
2419    with the option --download-sprng or --download-random123
2420 
2421 .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
2422 J*/
2423 typedef const char *PetscRandomType;
2424 #define PETSCRAND      "rand"
2425 #define PETSCRAND48    "rand48"
2426 #define PETSCSPRNG     "sprng"
2427 #define PETSCRANDER48  "rander48"
2428 #define PETSCRANDOM123 "random123"
2429 #define PETSCCURAND    "curand"
2430 
2431 /* Logging support */
2432 PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2433 
2434 PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
2435 
2436 /* Dynamic creation and loading functions */
2437 PETSC_EXTERN PetscFunctionList PetscRandomList;
2438 
2439 PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
2440 PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
2441 PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
2442 PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
2443 PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
2444 PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);
2445 
2446 PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
2447 PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
2448 PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
2449 PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
2450 PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
2451 PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
2452 PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
2453 PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long);
2454 PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *);
2455 PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2456 PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);
2457 
2458 PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
2459 PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
2460 PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
2461 PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
2462 PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
2463 PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
2464 PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
2465 PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
2466 PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
2467 PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2468 
2469 static inline PetscBool PetscBinaryBigEndian(void)
2470 {
2471   long _petsc_v = 1;
2472   return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
2473 }
2474 
2475 PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType);
2476 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
2477 PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType);
2478 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
2479 PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
2480 PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2481 PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
2482 PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
2483 PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
2484 PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
2485 PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
2486 #if defined(PETSC_USE_SOCKET_VIEWER)
2487 PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
2488 #endif
2489 
2490 PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
2491 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
2492 PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt);
2493 
2494 PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2495 PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
2496 PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2497 PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
2498 PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2499 PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
2500 PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2501 
2502 PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
2503 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **);
2504 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **);
2505 PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
2506 PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
2507 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);
2508 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
2509 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, MPI_Request **, MPI_Request **, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3);
2510 
2511 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
2512 PETSC_EXTERN PetscErrorCode    PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
2513 PETSC_EXTERN PetscErrorCode    PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);
2514 
2515 PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *);
2516 
2517 PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2518 
2519 PETSC_EXTERN const char *const PetscSubcommTypes[];
2520 
2521 struct _n_PetscSubcomm {
2522   MPI_Comm         parent;    /* parent communicator */
2523   MPI_Comm         dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2524   MPI_Comm         child;     /* the sub-communicator */
2525   PetscMPIInt      n;         /* num of subcommunicators under the parent communicator */
2526   PetscMPIInt      color;     /* color of processors belong to this communicator */
2527   PetscMPIInt     *subsize;   /* size of subcommunicator[color] */
2528   PetscSubcommType type;
2529   char            *subcommprefix;
2530 };
2531 
2532 static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
2533 {
2534   return scomm->parent;
2535 }
2536 static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
2537 {
2538   return scomm->child;
2539 }
2540 static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
2541 {
2542   return scomm->dupparent;
2543 }
2544 PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
2545 PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
2546 PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
2547 PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
2548 PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
2549 PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
2550 PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2551 PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
2552 PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
2553 PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
2554 PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);
2555 
2556 PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
2557 PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
2558 PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
2559 PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
2560 PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
2561 PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
2562 PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
2563 PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);
2564 
2565 PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
2566 PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
2567 PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
2568 PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
2569 PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);
2570 
2571 /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2572 PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
2573 PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
2574 PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
2575 PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2576 PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2577 PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2578 
2579 PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *);
2580 PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
2581 PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *);
2582 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
2583 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
2584 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
2585 PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *);
2586 PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t);
2587 
2588 /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2589  * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2590  * possible. */
2591 static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot)
2592 {
2593   return PetscSegBufferGet(seg, count, (void **)slot);
2594 }
2595 
2596 extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
2597 PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
2598 PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
2599 PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);
2600 
2601 #include <stdarg.h>
2602 PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
2603 PETSC_EXTERN                PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);
2604 
2605 PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2606 
2607 /*@C
2608       PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
2609 
2610      Not Collective - only what is registered on rank 0 of `PETSC_COMM_WORLD` will be printed
2611 
2612      Input Parameters:
2613 +      cite - the bibtex item, formatted to displayed on multiple lines nicely
2614 -      set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation
2615 
2616      Options Database: Key
2617 .     -citations [filename]   - print out the bibtex entries for the given computation
2618 
2619      Level: intermediate
2620 
2621      Fortran Note:
2622      Not available from Fortran
2623 
2624 @*/
2625 static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
2626 {
2627   size_t len;
2628   char  *vstring;
2629 
2630   PetscFunctionBegin;
2631   if (set && *set) PetscFunctionReturn(0);
2632   PetscCall(PetscStrlen(cit, &len));
2633   PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring));
2634   PetscCall(PetscArraycpy(vstring, cit, len));
2635   if (set) *set = PETSC_TRUE;
2636   PetscFunctionReturn(0);
2637 }
2638 
2639 PETSC_EXTERN                PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c);
2640 PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
2641 PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
2642 PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);
2643 
2644 PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
2645 PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
2646 
2647 PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
2648 
2649 PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *);
2650 PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *);
2651 
2652 PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
2653 PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);
2654 
2655 #if defined(PETSC_USE_DEBUG)
2656 static inline unsigned int PetscStrHash(const char *str)
2657 {
2658   unsigned int c, hash = 5381;
2659 
2660   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2661   return hash;
2662 }
2663 
2664   /*MC
2665    MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the
2666                     same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
2667                     resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.
2668 
2669    Collective
2670 
2671    Synopsis:
2672      #include <petscsys.h>
2673      PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
2674 
2675    Input Parameters:
2676 +  a - pointer to the input data to be reduced
2677 .  c - the number of MPI data items in a and b
2678 .  d - the MPI datatype, for example `MPI_INT`
2679 .  e - the MPI operation, for example `MPI_SUM`
2680 -  fcomm - the MPI communicator on which the operation occurs
2681 
2682    Output Parameter:
2683 .  b - the reduced values
2684 
2685    Notes:
2686      In optimized mode this directly calls `MPI_Allreduce()`
2687 
2688      This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void.
2689 
2690      The error code this returns should be checked with `PetscCall()` even though it looks like an MPI function because it always returns PETSc error codes
2691 
2692    Level: developer
2693 
2694 .seealso: `MPI_Allreduce()`
2695 M*/
2696   #define MPIU_Allreduce(a, b, c, d, e, fcomm) \
2697     PetscMacroReturnStandard(PetscMPIInt a_b1[6], a_b2[6]; int _mpiu_allreduce_c_int = (int)c; a_b1[0] = -(PetscMPIInt)__LINE__; a_b1[1] = -a_b1[0]; a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); a_b1[3] = -a_b1[2]; a_b1[4] = -(PetscMPIInt)(c); a_b1[5] = -a_b1[4]; PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); PetscCheck(-a_b2[4] == a_b2[5], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm)));)
2698 #else
2699   #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm))))
2700 #endif
2701 
2702 #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
2703 PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
2704 PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
2705 #endif
2706 
2707 /* this is a vile hack */
2708 #if defined(PETSC_HAVE_NECMPI)
2709   #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)
2710     #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
2711   #endif
2712 #endif
2713 
2714 /*
2715     List of external packages and queries on it
2716 */
2717 PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);
2718 
2719 /*
2720  OpenMP support
2721 */
2722 #if defined(_OPENMP)
2723   #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__))
2724 #else // no OpenMP so no threads
2725   #define PetscPragmaOMP(...)
2726 #endif
2727 
2728 /* this cannot go here because it may be in a different shared library */
2729 PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
2730 PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
2731 PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void);
2732 #endif
2733