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