Date: 2025-03-29T05:58:18+00:00

Actual source code: petscsys.h

      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

      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>

     23: /* SUBMANSEC = Sys */

     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

     44: #include <petscsystypes.h>

     46: /* ========================================================================== */

     48: /*
     49:     Defines the interface to MPI allowing the use of all MPI functions.

     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

     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

    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>

    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

    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);

    132: /*MC
    133:    MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt`

    135:    Level: beginner

    137:    Note:
    138:    In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value.

    140: .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
    141: M*/

    143: PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;

    145: #if defined(PETSC_USE_64BIT_INDICES)
    146:   #define MPIU_INT MPIU_INT64
    147: #else
    148:   #define MPIU_INT MPI_INT
    149: #endif

    151: /*MC
    152:    MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount`

    154:    Level: beginner

    156:    Note:
    157:    In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value.

    159:   Developer Note:
    160:   It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed

    162: .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
    163: M*/
    164: #define MPIU_COUNT MPI_AINT

    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);

    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;

    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;

    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

    191: /*
    192:     Declare extern C stuff after including external header files
    193: */

    195: PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
    196: /*
    197:     Defines elementary mathematics functions and constants.
    198: */
    199: #include <petscmath.h>

    201: /*MC
    202:     PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument

    204:    Level: beginner

    206:    Note:
    207:    Accepted by many PETSc functions to not set a parameter and instead use a default value

    209:    Fortran Note:
    210:    Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc

    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

    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

    220:    Level: beginner

    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.

    228:    Fortran Note:
    229:    Use `PETSC_UNLIMITED_INTEGER` or `PETSC_UNLIMITED_REAL`.

    231: .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DECIDE`
    232: M*/

    234: /*MC
    235:    PETSC_DECIDE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value

    237:    Level: beginner

    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()`.

    246:    Fortran Note:
    247:    Use `PETSC_DECIDE_INTEGER` or `PETSC_DECIDE_REAL`.

    249: .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_UNLIMITED'
    250: M*/

    252: /*MC
    253:    PETSC_DETERMINE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value

    255:    Level: beginner

    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.

    263:    Note:
    264:    Same as `PETSC_DECIDE`

    266:    Fortran Note:
    267:    Use `PETSC_DETERMINE_INTEGER` or `PETSC_DETERMINE_REAL`.

    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.

    273: .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`, `PETSC_UNLIMITED'
    274: M*/

    276: /*MC
    277:    PETSC_CURRENT - standard way of indicating to an object not to change the current value of the parameter in the object

    279:    Level: beginner

    281:    Note:
    282:    Use `PETSC_DECIDE` to use the value that was set by PETSc when the object's type was set

    284:    Fortran Note:
    285:    Use `PETSC_CURRENT_INTEGER` or `PETSC_CURRENT_REAL`.

    287: .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DEFAULT`, `PETSC_UNLIMITED'
    288: M*/

    290: /*MC
    291:    PETSC_DEFAULT - deprecated, see `PETSC_CURRENT` and `PETSC_DETERMINE`

    293:    Level: beginner

    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.

    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()`.

    302: .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_CURRENT`, `PETSC_UNLIMITED'
    303: M*/

    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

    313: /*MC
    314:    PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about.

    316:    Level: beginner

    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.

    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.

    327: .seealso: `PETSC_COMM_SELF`
    328: M*/
    329: PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;

    331: /*MC
    332:    PETSC_COMM_SELF - This is always `MPI_COMM_SELF`

    334:    Level: beginner

    336:    Note:
    337:    Do not USE/access or set this variable before `PetscInitialize()` has been called.

    339: .seealso: `PETSC_COMM_WORLD`
    340: M*/
    341: #define PETSC_COMM_SELF MPI_COMM_SELF

    343: /*MC
    344:    PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`.

    346:    No Fortran Support

    348:    Level: beginner

    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`

    353: .seealso: `PetscInitialize()`
    354: M*/
    355: PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;

    357: /*MC
    358:    PetscBeganMPI - indicates if PETSc initialized MPI using `MPI_Init()` during `PetscInitialize()` or if MPI was already initialized with `MPI_Init()`

    360:    Synopsis:
    361: #include <petscsys.h>
    362:    PetscBool PetscBeganMPI;

    364:    No Fortran Support

    366:    Level: developer

    368:    Note:
    369:    `MPI_Init()` can never be called after `PetscInitialize()`

    371: .seealso: `PetscInitialize()`, `PetscInitializeCalled`
    372: M*/
    373: PETSC_EXTERN PetscBool PetscBeganMPI;

    375: PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
    376: PETSC_EXTERN PetscBool PetscInitializeCalled;
    377: PETSC_EXTERN PetscBool PetscFinalizeCalled;
    378: PETSC_EXTERN PetscBool PetscViennaCLSynchronize;

    380: PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm));
    381: PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *);
    382: PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *);
    383: PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *);
    384: PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *);

    386: #if defined(PETSC_HAVE_KOKKOS)
    387: PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */
    388: #endif

    390: #if defined(PETSC_HAVE_NVSHMEM)
    391: PETSC_EXTERN PetscBool      PetscBeganNvshmem;
    392: PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
    393: PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
    394: #endif

    396: #if defined(PETSC_HAVE_ELEMENTAL)
    397: PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
    398: PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *);
    399: PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
    400: #endif

    402: /*MC
    403:    PetscMalloc - Allocates memory for use with PETSc. One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of `PetscMalloc()`

    405:    Synopsis:
    406: #include <petscsys.h>
    407:    PetscErrorCode PetscMalloc(size_t m,void **result)

    409:    Not Collective

    411:    Input Parameter:
    412: .  m - number of bytes to allocate

    414:    Output Parameter:
    415: .  result - memory allocated

    417:    Level: beginner

    419:    Notes:
    420:    Memory is always allocated at least double aligned

    422:    It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.
    423:    However, the pointer should never be dereferenced or the program will crash.

    425:    Developer Note:
    426:    All the `PetscMallocN()` routines actually call `PetscMalloc()` behind the scenes.

    428:    Except for data structures that store information about the PETSc options database all memory allocated by PETSc is
    429:    obtained with `PetscMalloc()` or `PetscCalloc()`

    431: .seealso: `PetscFree()`, `PetscNew()`, `PetscCalloc()`
    432: M*/
    433: #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))

    435: /*MC
    436:    PetscRealloc - Reallocates memory

    438:    Synopsis:
    439: #include <petscsys.h>
    440:    PetscErrorCode PetscRealloc(size_t m,void **result)

    442:    Not Collective

    444:    Input Parameters:
    445: +  m      - number of bytes to allocate
    446: -  result - previous memory

    448:    Output Parameter:
    449: .  result - new memory allocated

    451:    Level: developer

    453:    Notes:
    454:    `results` must have already been obtained with `PetscMalloc()`

    456:    Memory is always allocated at least double aligned

    458: .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()`
    459: M*/
    460: #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b)))

    462: /*MC
    463:    PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment

    465:    Synopsis:
    466: #include <petscsys.h>
    467:    void *PetscAddrAlign(void *addr)

    469:    Not Collective

    471:    Input Parameter:
    472: .  addr - address to align (any pointer type)

    474:    Level: developer

    476: .seealso: `PetscMallocAlign()`
    477: M*/
    478: #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)))

    480: /*MC
    481:    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN`, similar to `PetscMalloc()`

    483:    Synopsis:
    484: #include <petscsys.h>
    485:    PetscErrorCode PetscCalloc(size_t m,void **result)

    487:    Not Collective

    489:    Input Parameter:
    490: .  m - number of bytes to allocate

    492:    Output Parameter:
    493: .  result - memory allocated

    495:    Level: beginner

    497:    Notes:
    498:    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers

    500:    It is safe to allocate with an m of 0 and pass the resulting pointer to `PetscFree()`.

    502:    However, the pointer should never be dereferenced or the program will crash.

    504:    Developer Note:
    505:    All `PetscCallocN()` routines call `PetscCalloc()` behind the scenes.

    507: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`
    508: M*/
    509: #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result))

    511: /*MC
    512:    PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN`

    514:    Synopsis:
    515: #include <petscsys.h>
    516:    PetscErrorCode PetscMalloc1(size_t m1,type **r1)

    518:    Not Collective

    520:    Input Parameter:
    521: .  m1 - number of elements to allocate  (may be zero)

    523:    Output Parameter:
    524: .  r1 - memory allocated

    526:    Level: beginner

    528:    Note:
    529:    This uses `sizeof()` of the memory type requested to determine the total memory to be allocated; therefore, you should not
    530:    multiply the number of elements requested by the `sizeof()` the type. For example, use
    531: .vb
    532:   PetscInt *id;
    533:   PetscMalloc1(10,&id);
    534: .ve
    535:        not
    536: .vb
    537:   PetscInt *id;
    538:   PetscMalloc1(10*sizeof(PetscInt),&id);
    539: .ve

    541:   Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed.

    543:   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
    544:   32bit `int` computation - while computation in 64bit `size_t` would not overflow!
    545:   It's best if any arithmetic that is done for size computations is done with `size_t` type - avoiding arithmetic overflow!

    547:   `PetscMalloc[N]()` and `PetscCalloc[N]()` attempt to work-around this by casting the first variable to `size_t`.
    548:   This works for most expressions, but not all, such as
    549: .vb
    550:   PetscInt *id, a, b;
    551:   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
    552:   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
    553: .ve

    555:   These expressions should either be avoided, or appropriately cast variables to `size_t`:
    556: .vb
    557:   PetscInt *id, a, b;
    558:   PetscMalloc1(use_a_squared ? (size_t)a * a * b : (size_t)a * b, &id); // Cast a to size_t before multiplication
    559:   PetscMalloc1(b * b + a, &id); // b is automatically cast to size_t and order-of-operations ensures size_t precision is maintained
    560: .ve

    562: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
    563: M*/
    564: #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))

    566: /*MC
    567:    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN`

    569:    Synopsis:
    570: #include <petscsys.h>
    571:    PetscErrorCode PetscCalloc1(size_t m1,type **r1)

    573:    Not Collective

    575:    Input Parameter:
    576: .  m1 - number of elements to allocate in 1st chunk  (may be zero)

    578:    Output Parameter:
    579: .  r1 - memory allocated

    581:    Level: beginner

    583:    Note:
    584:    See `PetscMalloc1()` for more details on usage.

    586: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
    587: M*/
    588: #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1))

    590: /*MC
    591:    PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN`

    593:    Synopsis:
    594: #include <petscsys.h>
    595:    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)

    597:    Not Collective

    599:    Input Parameters:
    600: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    601: -  m2 - number of elements to allocate in 2nd chunk  (may be zero)

    603:    Output Parameters:
    604: +  r1 - memory allocated in first chunk
    605: -  r2 - memory allocated in second chunk

    607:    Level: developer

    609: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()`
    610: M*/
    611: #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))

    613: /*MC
    614:    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN`

    616:    Synopsis:
    617: #include <petscsys.h>
    618:    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)

    620:    Not Collective

    622:    Input Parameters:
    623: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    624: -  m2 - number of elements to allocate in 2nd chunk  (may be zero)

    626:    Output Parameters:
    627: +  r1 - memory allocated in first chunk
    628: -  r2 - memory allocated in second chunk

    630:    Level: developer

    632: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()`
    633: M*/
    634: #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))

    636: /*MC
    637:    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN`

    639:    Synopsis:
    640: #include <petscsys.h>
    641:    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)

    643:    Not Collective

    645:    Input Parameters:
    646: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    647: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    648: -  m3 - number of elements to allocate in 3rd chunk  (may be zero)

    650:    Output Parameters:
    651: +  r1 - memory allocated in first chunk
    652: .  r2 - memory allocated in second chunk
    653: -  r3 - memory allocated in third chunk

    655:    Level: developer

    657: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()`
    658: M*/
    659: #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \
    660:   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))

    662: /*MC
    663:    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`

    665:    Synopsis:
    666: #include <petscsys.h>
    667:    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)

    669:    Not Collective

    671:    Input Parameters:
    672: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    673: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    674: -  m3 - number of elements to allocate in 3rd chunk  (may be zero)

    676:    Output Parameters:
    677: +  r1 - memory allocated in first chunk
    678: .  r2 - memory allocated in second chunk
    679: -  r3 - memory allocated in third chunk

    681:    Level: developer

    683: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()`
    684: M*/
    685: #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \
    686:   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))

    688: /*MC
    689:    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN`

    691:    Synopsis:
    692: #include <petscsys.h>
    693:    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)

    695:    Not Collective

    697:    Input Parameters:
    698: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    699: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    700: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    701: -  m4 - number of elements to allocate in 4th chunk  (may be zero)

    703:    Output Parameters:
    704: +  r1 - memory allocated in first chunk
    705: .  r2 - memory allocated in second chunk
    706: .  r3 - memory allocated in third chunk
    707: -  r4 - memory allocated in fourth chunk

    709:    Level: developer

    711: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
    712: M*/
    713: #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
    714:   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))

    716: /*MC
    717:    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`

    719:    Synopsis:
    720: #include <petscsys.h>
    721:    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)

    723:    Not Collective

    725:    Input Parameters:
    726: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    727: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    728: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    729: -  m4 - number of elements to allocate in 4th chunk  (may be zero)

    731:    Output Parameters:
    732: +  r1 - memory allocated in first chunk
    733: .  r2 - memory allocated in second chunk
    734: .  r3 - memory allocated in third chunk
    735: -  r4 - memory allocated in fourth chunk

    737:    Level: developer

    739: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()`
    740: M*/
    741: #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \
    742:   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))

    744: /*MC
    745:    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN`

    747:    Synopsis:
    748: #include <petscsys.h>
    749:    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)

    751:    Not Collective

    753:    Input Parameters:
    754: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    755: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    756: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    757: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    758: -  m5 - number of elements to allocate in 5th chunk  (may be zero)

    760:    Output Parameters:
    761: +  r1 - memory allocated in first chunk
    762: .  r2 - memory allocated in second chunk
    763: .  r3 - memory allocated in third chunk
    764: .  r4 - memory allocated in fourth chunk
    765: -  r5 - memory allocated in fifth chunk

    767:    Level: developer

    769: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()`
    770: M*/
    771: #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
    772:   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))

    774: /*MC
    775:    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`

    777:    Synopsis:
    778: #include <petscsys.h>
    779:    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)

    781:    Not Collective

    783:    Input Parameters:
    784: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    785: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    786: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    787: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    788: -  m5 - number of elements to allocate in 5th chunk  (may be zero)

    790:    Output Parameters:
    791: +  r1 - memory allocated in first chunk
    792: .  r2 - memory allocated in second chunk
    793: .  r3 - memory allocated in third chunk
    794: .  r4 - memory allocated in fourth chunk
    795: -  r5 - memory allocated in fifth chunk

    797:    Level: developer

    799: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()`
    800: M*/
    801: #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \
    802:   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))

    804: /*MC
    805:    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN`

    807:    Synopsis:
    808: #include <petscsys.h>
    809:    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)

    811:    Not Collective

    813:    Input Parameters:
    814: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    815: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    816: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    817: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    818: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
    819: -  m6 - number of elements to allocate in 6th chunk  (may be zero)

    821:    Output Parameteasr:
    822: +  r1 - memory allocated in first chunk
    823: .  r2 - memory allocated in second chunk
    824: .  r3 - memory allocated in third chunk
    825: .  r4 - memory allocated in fourth chunk
    826: .  r5 - memory allocated in fifth chunk
    827: -  r6 - memory allocated in sixth chunk

    829:    Level: developer

    831: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()`
    832: M*/
    833: #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
    834:   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))

    836: /*MC
    837:    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`

    839:    Synopsis:
    840: #include <petscsys.h>
    841:    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)

    843:    Not Collective

    845:    Input Parameters:
    846: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    847: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    848: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    849: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    850: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
    851: -  m6 - number of elements to allocate in 6th chunk  (may be zero)

    853:    Output Parameters:
    854: +  r1 - memory allocated in first chunk
    855: .  r2 - memory allocated in second chunk
    856: .  r3 - memory allocated in third chunk
    857: .  r4 - memory allocated in fourth chunk
    858: .  r5 - memory allocated in fifth chunk
    859: -  r6 - memory allocated in sixth chunk

    861:    Level: developer

    863: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()`
    864: M*/
    865: #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \
    866:   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))

    868: /*MC
    869:    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN`

    871:    Synopsis:
    872: #include <petscsys.h>
    873:    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)

    875:    Not Collective

    877:    Input Parameters:
    878: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    879: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    880: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    881: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    882: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
    883: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
    884: -  m7 - number of elements to allocate in 7th chunk  (may be zero)

    886:    Output Parameters:
    887: +  r1 - memory allocated in first chunk
    888: .  r2 - memory allocated in second chunk
    889: .  r3 - memory allocated in third chunk
    890: .  r4 - memory allocated in fourth chunk
    891: .  r5 - memory allocated in fifth chunk
    892: .  r6 - memory allocated in sixth chunk
    893: -  r7 - memory allocated in seventh chunk

    895:    Level: developer

    897: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()`
    898: M*/
    899: #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
    900:   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))

    902: /*MC
    903:    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN`

    905:    Synopsis:
    906: #include <petscsys.h>
    907:    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)

    909:    Not Collective

    911:    Input Parameters:
    912: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
    913: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
    914: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
    915: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
    916: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
    917: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
    918: -  m7 - number of elements to allocate in 7th chunk  (may be zero)

    920:    Output Parameters:
    921: +  r1 - memory allocated in first chunk
    922: .  r2 - memory allocated in second chunk
    923: .  r3 - memory allocated in third chunk
    924: .  r4 - memory allocated in fourth chunk
    925: .  r5 - memory allocated in fifth chunk
    926: .  r6 - memory allocated in sixth chunk
    927: -  r7 - memory allocated in seventh chunk

    929:    Level: developer

    931: .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()`
    932: M*/
    933: #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \
    934:   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))

    936: /*MC
    937:    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN`

    939:    Synopsis:
    940: #include <petscsys.h>
    941:    PetscErrorCode PetscNew(type **result)

    943:    Not Collective

    945:    Output Parameter:
    946: .  result - memory allocated, sized to match pointer `type`

    948:    Level: beginner

    950:    Developer Note:
    951:    Calls `PetscCalloc()` with the appropriate memory size obtained from `type`

    953: .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCall()`, `PetscCalloc1()`, `PetscMalloc1()`
    954: M*/
    955: #define PetscNew(b) PetscCalloc1(1, (b))

    957: #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b)

    959: /*MC
    960:    PetscFree - Frees memory

    962:    Synopsis:
    963: #include <petscsys.h>
    964:    PetscErrorCode PetscFree(void *memory)

    966:    Not Collective

    968:    Input Parameter:
    969: .   memory - memory to free (the pointer is ALWAYS set to `NULL` upon success)

    971:    Level: beginner

    973:    Notes:
    974:    Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc.

    976:    It is safe to call `PetscFree()` on a `NULL` pointer.

    978: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()`
    979: M*/
    980: #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS)))

    982: /*MC
    983:    PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()`

    985:    Synopsis:
    986: #include <petscsys.h>
    987:    PetscErrorCode PetscFree2(void *memory1,void *memory2)

    989:    Not Collective

    991:    Input Parameters:
    992: +   memory1 - memory to free
    993: -   memory2 - 2nd memory to free

    995:    Level: developer

    997:    Notes:
    998:     Memory must have been obtained with `PetscMalloc2()`

    1000:     The arguments need to be in the same order as they were in the call to `PetscMalloc2()`

    1002: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`
    1003: M*/
    1004: #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2))

    1006: /*MC
    1007:    PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()`

    1009:    Synopsis:
    1010: #include <petscsys.h>
    1011:    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)

    1013:    Not Collective

    1015:    Input Parameters:
    1016: +   memory1 - memory to free
    1017: .   memory2 - 2nd memory to free
    1018: -   memory3 - 3rd memory to free

    1020:    Level: developer

    1022:    Notes:
    1023:     Memory must have been obtained with `PetscMalloc3()`

    1025:     The arguments need to be in the same order as they were in the call to `PetscMalloc3()`

    1027: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`
    1028: M*/
    1029: #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3))

    1031: /*MC
    1032:    PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()`

    1034:    Synopsis:
    1035: #include <petscsys.h>
    1036:    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)

    1038:    Not Collective

    1040:    Input Parameters:
    1041: +   m1 - memory to free
    1042: .   m2 - 2nd memory to free
    1043: .   m3 - 3rd memory to free
    1044: -   m4 - 4th memory to free

    1046:    Level: developer

    1048:    Notes:
    1049:     Memory must have been obtained with `PetscMalloc4()`

    1051:     The arguments need to be in the same order as they were in the call to `PetscMalloc4()`

    1053: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`
    1054: M*/
    1055: #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4))

    1057: /*MC
    1058:    PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()`

    1060:    Synopsis:
    1061: #include <petscsys.h>
    1062:    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)

    1064:    Not Collective

    1066:    Input Parameters:
    1067: +   m1 - memory to free
    1068: .   m2 - 2nd memory to free
    1069: .   m3 - 3rd memory to free
    1070: .   m4 - 4th memory to free
    1071: -   m5 - 5th memory to free

    1073:    Level: developer

    1075:    Notes:
    1076:     Memory must have been obtained with `PetscMalloc5()`

    1078:     The arguments need to be in the same order as they were in the call to `PetscMalloc5()`

    1080: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`
    1081: M*/
    1082: #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5))

    1084: /*MC
    1085:    PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()`

    1087:    Synopsis:
    1088: #include <petscsys.h>
    1089:    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)

    1091:    Not Collective

    1093:    Input Parameters:
    1094: +   m1 - memory to free
    1095: .   m2 - 2nd memory to free
    1096: .   m3 - 3rd memory to free
    1097: .   m4 - 4th memory to free
    1098: .   m5 - 5th memory to free
    1099: -   m6 - 6th memory to free

    1101:    Level: developer

    1103:    Notes:
    1104:     Memory must have been obtained with `PetscMalloc6()`

    1106:     The arguments need to be in the same order as they were in the call to `PetscMalloc6()`

    1108: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`
    1109: M*/
    1110: #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6))

    1112: /*MC
    1113:    PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()`

    1115:    Synopsis:
    1116: #include <petscsys.h>
    1117:    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)

    1119:    Not Collective

    1121:    Input Parameters:
    1122: +   m1 - memory to free
    1123: .   m2 - 2nd memory to free
    1124: .   m3 - 3rd memory to free
    1125: .   m4 - 4th memory to free
    1126: .   m5 - 5th memory to free
    1127: .   m6 - 6th memory to free
    1128: -   m7 - 7th memory to free

    1130:    Level: developer

    1132:    Notes:
    1133:     Memory must have been obtained with `PetscMalloc7()`

    1135:     The arguments need to be in the same order as they were in the call to `PetscMalloc7()`

    1137: .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`,
    1138:           `PetscMalloc7()`
    1139: M*/
    1140: #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7))

    1142: PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...);
    1143: PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...);
    1144: PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **);
    1145: PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]);
    1146: PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **);
    1147: PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
    1148: 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 **));
    1149: PETSC_EXTERN PetscErrorCode PetscMallocClear(void);

    1151: /*
    1152:   Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair.
    1153: */
    1154: PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
    1155: PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
    1156: #if defined(PETSC_HAVE_CUDA)
    1157: PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
    1158: PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
    1159: #endif
    1160: #if defined(PETSC_HAVE_HIP)
    1161: PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
    1162: PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
    1163: #endif

    1165: #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
    1166: #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION

    1168: /*
    1169:    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
    1170: */
    1171: PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
    1172: PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
    1173: PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
    1174: PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
    1175: PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
    1176: PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *);
    1177: PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool);
    1178: PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *);
    1179: PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]);
    1180: PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
    1181: PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *);
    1182: PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
    1183: PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *);

    1185: PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *);
    1186: PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *);
    1187: PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *);
    1188: PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *);

    1190: /*
    1191:    These are MPI operations for MPI_Allreduce() etc
    1192: */
    1193: PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
    1194: #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
    1195: PETSC_EXTERN MPI_Op MPIU_SUM;
    1196: PETSC_EXTERN MPI_Op MPIU_MAX;
    1197: PETSC_EXTERN MPI_Op MPIU_MIN;
    1198: #else
    1199:   #define MPIU_SUM MPI_SUM
    1200:   #define MPIU_MAX MPI_MAX
    1201:   #define MPIU_MIN MPI_MIN
    1202: #endif
    1203: PETSC_EXTERN MPI_Op         Petsc_Garbage_SetIntersectOp;
    1204: PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);

    1206: #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16))
    1207: /*MC
    1208:    MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with
    1209:    custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`.

    1211:    Level: advanced

    1213:    Developer Note:
    1214:    This should be unified with `MPIU_SUM`

    1216: .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX`
    1217: M*/
    1218: PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128;
    1219: #endif
    1220: PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *);

    1222: PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);
    1223: PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3);

    1225: /*
    1226:      These are so that in extern C code we can cast function pointers to non-extern C
    1227:    function pointers. Since the regular C++ code expects its function pointers to be C++
    1228: */

    1230: /*S
    1231:   PetscVoidFn - A prototype of a void (fn)(void) function

    1233:   Level: developer

    1235:   Notes:
    1236:   The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *.

    1238:   The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **.

    1240: .seealso: `PetscObject`, `PetscObjectDestroy()`
    1241: S*/
    1242: PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void);

    1244: PETSC_EXTERN_TYPEDEF typedef PetscVoidFn  *PetscVoidFunction;
    1245: PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction;

    1247: /*S
    1248:   PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function

    1250:   Level: developer

    1252:   Notes:
    1253:   The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *.

    1255: .seealso: `PetscObject`, `PetscObjectDestroy()`
    1256: S*/
    1257: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void);

    1259: PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction;

    1261: /*S
    1262:   PetscCtxDestroyFn - A prototype of a `PetscErrorCode (*)(void *)` function that is used to free user contexts

    1264:   Level: intermediate

    1266:   Note:
    1267:   Used in the prototype of functions such as `DMSetApplicationContextDestroy()`

    1269: .seealso: `PetscObject`, `PetscCtxDestroyDefault()`, `PetscObjectDestroy()`, `DMSetApplicationContextDestroy()`
    1270: S*/
    1271: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscCtxDestroyFn)(void **);

    1273: PETSC_EXTERN PetscCtxDestroyFn PetscCtxDestroyDefault;

    1275: /*
    1276:     Defines PETSc error handling.
    1277: */
    1278: #include <petscerror.h>

    1280: PETSC_EXTERN PetscBool   PetscCIEnabled;                    /* code is running in the PETSc test harness CI */
    1281: PETSC_EXTERN PetscBool   PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */
    1282: PETSC_EXTERN const char *PetscCIFilename(const char *);
    1283: PETSC_EXTERN int         PetscCILinenumber(int);

    1285: #define PETSC_SMALLEST_CLASSID 1211211
    1286: PETSC_EXTERN PetscClassId   PETSC_LARGEST_CLASSID;
    1287: PETSC_EXTERN PetscClassId   PETSC_OBJECT_CLASSID;
    1288: PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *);
    1289: PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *);
    1290: PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *);

    1292: /*
    1293:    Routines that get memory usage information from the OS
    1294: */
    1295: PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
    1296: PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
    1297: PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
    1298: PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);

    1300: PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);

    1302: /*
    1303:    Initialization of PETSc
    1304: */
    1305: PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]);
    1306: PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char *[], const char[], const char[]);
    1307: PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
    1308: PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
    1309: PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
    1310: PETSC_EXTERN PetscErrorCode PetscFinalize(void);
    1311: PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
    1312: PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***);
    1313: PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
    1314: PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);

    1316: PETSC_EXTERN PetscErrorCode PetscEnd(void);
    1317: PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
    1318: PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void);

    1320: PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]);
    1321: PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
    1322: PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
    1323: PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]);

    1325: PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscBool *);

    1327: /*
    1328:     Functions that can act on any PETSc object.
    1329: */
    1330: PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *);
    1331: PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *);
    1332: PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *);
    1333: PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]);
    1334: PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]);
    1335: PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]);
    1336: PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]);
    1337: PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt);
    1338: PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *);
    1339: PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt);
    1340: PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
    1341: PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *);
    1342: PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
    1343: PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *);
    1344: PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject);
    1345: PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]);
    1346: PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *);
    1347: PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void));
    1348: #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__))
    1349: PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
    1350: PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
    1351: PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
    1352: PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject);
    1353: PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *);

    1355: /*MC
    1356:    PetscObjectParameterSetDefault - sets a parameter default value in a `PetscObject` to a new default value.
    1357:    If the current value matches the old default value, then the current value is also set to the new value.

    1359:    No Fortran Support

    1361:    Synopsis:
    1362: #include <petscsys.h>
    1363:    PetscBool PetscObjectParameterSetDefault(PetscObject obj, char* NAME, PetscReal value);

    1365:    Input Parameters:
    1366: +  obj - the `PetscObject`
    1367: .  NAME - the name of the parameter, unquoted
    1368: -  value - the new value

    1370:    Level: developer

    1372:    Notes:
    1373:    The defaults for an object are the values set when the object's type is set.

    1375:    This should only be used in object constructors, such as, `SNESCreate_NGS()`.

    1377:    This only works for parameters that are declared in the struct with `PetscObjectParameterDeclare()`

    1379: .seealso: `PetscObjectParameterDeclare()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
    1380: M*/
    1381: #define PetscObjectParameterSetDefault(obj, NAME, value) \
    1382:   do { \
    1383:     if (obj->NAME == obj->default_##NAME) obj->NAME = value; \
    1384:     obj->default_##NAME = value; \
    1385:   } while (0)

    1387: /*MC
    1388:    PetscObjectParameterDeclare - declares a parameter in a `PetscObject` and a location to store its default

    1390:    No Fortran Support

    1392:    Synopsis:
    1393: #include <petscsys.h>
    1394:    PetscBool PetscObjectParameterDeclare(type, char* NAME)

    1396:    Input Parameters:
    1397: +  type - the type of the parameter, for example `PetscInt`
    1398: -  NAME - the name of the parameter, unquoted

    1400:    Level: developer.

    1402: .seealso: `PetscObjectParameterSetDefault()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()`
    1403: M*/
    1404: #define PetscObjectParameterDeclare(type, NAME) type NAME, default_##NAME

    1406: #include <petscviewertypes.h>
    1407: #include <petscoptions.h>

    1409: PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble);
    1410: PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *);

    1412: PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject[], PetscInt *, PetscInt *);

    1414: PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]);
    1415: PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer);
    1416: PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer);
    1417: #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr))
    1418: PETSC_EXTERN PetscErrorCode PetscObjectHasFunction(PetscObject, const char[], PetscBool *);
    1419: PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void));
    1420: PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]);
    1421: PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]);
    1422: PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]);
    1423: PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]);
    1424: PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]);
    1425: PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
    1426: PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
    1427: PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]);
    1428: PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
    1429: PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *);
    1430: PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *);
    1431: PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *);
    1432: PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
    1433: PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...);
    1434: PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
    1435: PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);

    1437: #if defined(PETSC_HAVE_SAWS)
    1438: PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
    1439: PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
    1440: PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool);
    1441: PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
    1442: PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
    1443: PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
    1444: PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
    1445: PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
    1446: PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
    1447: PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);

    1449: #else
    1450:   #define PetscSAWsBlock()                  PETSC_SUCCESS
    1451:   #define PetscObjectSAWsViewOff(obj)       PETSC_SUCCESS
    1452:   #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS
    1453:   #define PetscObjectSAWsBlock(obj)         PETSC_SUCCESS
    1454:   #define PetscObjectSAWsGrantAccess(obj)   PETSC_SUCCESS
    1455:   #define PetscObjectSAWsTakeAccess(obj)    PETSC_SUCCESS
    1456:   #define PetscStackViewSAWs()              PETSC_SUCCESS
    1457:   #define PetscStackSAWsViewOff()           PETSC_SUCCESS
    1458:   #define PetscStackSAWsTakeAccess()
    1459:   #define PetscStackSAWsGrantAccess()

    1461: #endif

    1463: PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *);
    1464: PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
    1465: PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **);
    1466: PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char *[]);
    1467: #ifdef PETSC_HAVE_CXX
    1468: PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char *[]);
    1469: #endif

    1471: PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **);

    1473: PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool);
    1474: PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer);
    1475: PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, const char *[]);
    1476: PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *);
    1477: PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *);
    1478: PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, const char *[], PetscBool *);
    1479: PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject);
    1480: PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]);
    1481: PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *);

    1483: /*
    1484:     Dynamic library lists. Lists of names of routines in objects or in dynamic
    1485:   link libraries that will be loaded as needed.
    1486: */

    1488: #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr))
    1489: PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *);
    1490: PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *);
    1491: PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList);
    1492: #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr))
    1493: PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **);
    1494: PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]);
    1495: PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *);
    1496: PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer);
    1497: PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *);
    1498: PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList);
    1499: PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void);

    1501: PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded;
    1502: PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]);
    1503: PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]);
    1504: PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **);
    1505: PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
    1506: PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *);
    1507: PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *);
    1508: PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);

    1510: /*
    1511:      Useful utility routines
    1512: */
    1513: PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *);
    1514: PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *);
    1515: PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *);
    1516: PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt);
    1517: PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt);
    1518: PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
    1519: PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *);
    1520: PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]);
    1521: PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]);

    1523: /*MC
    1524:     PetscNot - negates a logical type value and returns result as a `PetscBool`

    1526:     Level: beginner

    1528:     Note:
    1529:     This is useful in cases like
    1530: .vb
    1531:      int        *a;
    1532:      PetscBool  flag = PetscNot(a)
    1533: .ve
    1534:      where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C.

    1536: .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE`
    1537: M*/
    1538: #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)

    1540: /*MC
    1541:    PetscHelpPrintf - Prints help messages.

    1543:    Synopsis:
    1544: #include <petscsys.h>
    1545:      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);

    1547:    Not Collective, only applies on MPI rank 0; No Fortran Support

    1549:    Input Parameters:
    1550: +  comm - the MPI communicator over which the help message is printed
    1551: .  format - the usual printf() format string
    1552: -  args - arguments to be printed

    1554:    Level: developer

    1556:    Notes:
    1557:    You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.

    1559:    To use, write your own function, for example,
    1560: .vb
    1561:    PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
    1562:    {
    1563:      PetscFunctionReturn(PETSC_SUCCESS);
    1564:    }
    1565: .ve
    1566: then do the assignment
    1567: .vb
    1568:   PetscHelpPrintf = mypetschelpprintf;
    1569: .ve

    1571:   You can do the assignment before `PetscInitialize()`.

    1573:   The default routine used is called `PetscHelpPrintfDefault()`.

    1575: .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()`
    1576: M*/
    1577: PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);

    1579: /*
    1580:      Defines PETSc profiling.
    1581: */
    1582: #include <petsclog.h>

    1584: /*
    1585:       Simple PETSc parallel IO for ASCII printing
    1586: */
    1587: PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]);
    1588: PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **);
    1589: PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *);
    1590: PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
    1591: PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *);
    1592: PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
    1593: PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
    1594: PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5);
    1595: PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]);

    1597: PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
    1598: PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
    1599: PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);

    1601: PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *);
    1602: PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *);

    1604: PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **);
    1605: PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *);
    1606: PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);

    1608: PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
    1609: PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
    1610: PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *);
    1611: PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]);
    1612: PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **);
    1613: PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]);

    1615: /*MC
    1616:    PeCtx - indicates an argument that returns a pointer to a user defined C struct (or Fortran derived type)

    1618:    Level: developer

    1620:    Notes:
    1621:    This is not part of the PETSc public API and should only be used in PETSc source code.

    1623:    This should not be used for functions that return PETSc objects, or pointers to arrays of unknown type. Thus it is used for, for example,
    1624:    `KSPGetApplicationContext()` but not used for `DMNetworkGetComponent()`

    1626:    For pointers to arrays of unknown type and for functions that return PETSc internal objects that are opaque to users, such
    1627:    as `KSPMonitorDynamicToleranceCreate()` a `void **` should be used.

    1629:    Fortran Note:
    1630:    Should only be used with user defined Fortran datatypes
    1631: .vb
    1632:    type(tUserType), pointer :: ctx
    1633: .ve

    1635:    Developer Note:
    1636:    Put this in function declaration for the argument type instead of `void *`, or `void **`.

    1638:    C compilers generate a warning or error if one passes a pointer to a pointer to a specific type (instead of `void`), for example,
    1639: .vb
    1640:    extern calledfunction(void **);
    1641:    SomeCtx *ctx;
    1642:    calledfunction(&ctx);   << warning that it is passing a pointer to a pointer to a SomeCtx instead of a void **
    1643: .ve
    1644:    By using the common practice of prototyping the function as
    1645: .vb
    1646:    extern calledfunction(void *);
    1647: .ve
    1648:    the warning message is averted. `PeCtx` is used in PETSc source code so that the getAPI() code processor knows the argument is
    1649:    actually handled internally as `void **` so it can generate correct bindings for other languages.

    1651: .seealso: `PeOp`, `PeNS`, `PetscInitialize()`
    1652: M*/
    1653: typedef void *PeCtx;

    1655: PETSC_EXTERN PetscClassId   PETSC_CONTAINER_CLASSID;
    1656: PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void *);
    1657: PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *);
    1658: PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *);
    1659: PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *);
    1660: PETSC_EXTERN PetscErrorCode PetscContainerSetCtxDestroy(PetscContainer, PetscCtxDestroyFn *);
    1661: PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscContainerSetCtxDestroy()", ) PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *));
    1662: PETSC_EXTERN PetscErrorCode PetscObjectContainerCompose(PetscObject, const char *name, void *, PetscCtxDestroyFn *);
    1663: PETSC_EXTERN PetscErrorCode PetscObjectContainerQuery(PetscObject, const char *, PeCtx);

    1665: PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscCtxDestroyDefault()", ) static inline PetscErrorCode PetscContainerCtxDestroyDefault(void **a)
    1666: {
    1667:   return PetscCtxDestroyDefault(a);
    1668: }

    1670: /*
    1671:    For use in debuggers
    1672: */
    1673: PETSC_EXTERN PetscMPIInt    PetscGlobalRank;
    1674: PETSC_EXTERN PetscMPIInt    PetscGlobalSize;
    1675: PETSC_EXTERN PetscErrorCode PetscIntViewNumColumns(PetscInt, PetscInt, const PetscInt[], PetscViewer);
    1676: PETSC_EXTERN PetscErrorCode PetscRealViewNumColumns(PetscInt, PetscInt, const PetscReal[], PetscViewer);
    1677: PETSC_EXTERN PetscErrorCode PetscScalarViewNumColumns(PetscInt, PetscInt, const PetscScalar[], PetscViewer);
    1678: PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer);
    1679: PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer);
    1680: PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer);

    1682: /*
    1683:     Basic memory and string operations. These are usually simple wrappers
    1684:    around the basic Unix system calls, but a few of them have additional
    1685:    functionality and/or error checking.
    1686: */
    1687: #include <petscstring.h>

    1689: #include <stddef.h>
    1690: #include <stdlib.h>

    1692: #if defined(PETSC_CLANG_STATIC_ANALYZER)
    1693:   #define PetscPrefetchBlock(a, b, c, d)
    1694: #else
    1695:   /*MC
    1696:    PetscPrefetchBlock - Prefetches a block of memory

    1698:    Synopsis:
    1699: #include <petscsys.h>
    1700:     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)

    1702:    Not Collective

    1704:    Input Parameters:
    1705: +  a  - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`)
    1706: .  n  - number of elements to fetch
    1707: .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
    1708: -  t  - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note

    1710:    Level: developer

    1712:    Notes:
    1713:    The last two arguments (`rw` and `t`) must be compile-time constants.

    1715:    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
    1716:    equivalent locality hints, but the following macros are always defined to their closest analogue.
    1717: +  `PETSC_PREFETCH_HINT_NTA` - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
    1718: .  `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.
    1719: .  `PETSC_PREFETCH_HINT_T1`  - Fetch to level 2 and higher (not L1).
    1720: -  `PETSC_PREFETCH_HINT_T2`  - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)

    1722:    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
    1723:    address).

    1725: M*/
    1726:   #define PetscPrefetchBlock(a, n, rw, t) \
    1727:     do { \
    1728:       const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \
    1729:       for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \
    1730:     } while (0)
    1731: #endif
    1732: /*
    1733:       Determine if some of the kernel computation routines use
    1734:    Fortran (rather than C) for the numerical calculations. On some machines
    1735:    and compilers (like complex numbers) the Fortran version of the routines
    1736:    is faster than the C/C++ versions. The flag --with-fortran-kernels
    1737:    should be used with ./configure to turn these on.
    1738: */
    1739: #if defined(PETSC_USE_FORTRAN_KERNELS)

    1741:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
    1742:     #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
    1743:   #endif

    1745:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
    1746:     #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
    1747:   #endif

    1749:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
    1750:     #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
    1751:   #endif

    1753:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
    1754:     #define PETSC_USE_FORTRAN_KERNEL_MAXPY
    1755:   #endif

    1757:   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
    1758:     #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
    1759:   #endif

    1761:   #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
    1762:     #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
    1763:   #endif

    1765:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
    1766:     #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
    1767:   #endif

    1769:   #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
    1770:     #define PETSC_USE_FORTRAN_KERNEL_MDOT
    1771:   #endif

    1773:   #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
    1774:     #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
    1775:   #endif

    1777:   #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
    1778:     #define PETSC_USE_FORTRAN_KERNEL_AYPX
    1779:   #endif

    1781:   #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
    1782:     #define PETSC_USE_FORTRAN_KERNEL_WAXPY
    1783:   #endif

    1785: #endif

    1787: /*
    1788:     Macros for indicating code that should be compiled with a C interface,
    1789:    rather than a C++ interface. Any routines that are dynamically loaded
    1790:    (such as the PCCreate_XXX() routines) must be wrapped so that the name
    1791:    mangler does not change the functions symbol name. This just hides the
    1792:    ugly extern "C" {} wrappers.
    1793: */
    1794: #if defined(__cplusplus)
    1795:   #define EXTERN_C_BEGIN extern "C" {
    1796:   #define EXTERN_C_END   }
    1797: #else
    1798:   #define EXTERN_C_BEGIN
    1799:   #define EXTERN_C_END
    1800: #endif

    1802: /*MC
    1803:    MPI_Comm - the basic object used by MPI to determine which processes are involved in a
    1804:    communication

    1806:    Level: beginner

    1808:    Note:
    1809:    This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm`

    1811: .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF`
    1812: M*/

    1814: #if defined(PETSC_HAVE_MPIIO)
    1815: PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
    1816: PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4);
    1817: 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);
    1818: 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);
    1819: 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);
    1820: 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);
    1821: #endif

    1823: #if defined(PETSC_HAVE_MPI_COUNT)
    1824: typedef MPI_Count MPIU_Count;
    1825: #else
    1826: typedef PetscInt64 MPIU_Count;
    1827: #endif

    1829: /*@C
    1830:    PetscIntCast - casts a `MPI_Count`, `PetscInt64`, `PetscCount`, or `size_t` to a `PetscInt` (which may be 32-bits in size), generates an
    1831:    error if the `PetscInt` is not large enough to hold the number.

    1833:    Not Collective; No Fortran Support

    1835:    Input Parameter:
    1836: .  a - the `PetscInt64` value

    1838:    Output Parameter:
    1839: .  b - the resulting `PetscInt` value, or `NULL` if the result is not needed

    1841:    Level: advanced

    1843:    Note:
    1844:    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

    1846: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscCIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`
    1847: @*/
    1848: static inline PetscErrorCode PetscIntCast(MPIU_Count a, PetscInt *b)
    1849: {
    1850:   PetscFunctionBegin;
    1851:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1852:   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);
    1853:   if (b) *b = (PetscInt)a;
    1854:   PetscFunctionReturn(PETSC_SUCCESS);
    1855: }

    1857: /*@C
    1858:    PetscBLASIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount` or `PetscInt64` to a `PetscBLASInt` (which may be 32-bits in size), generates an
    1859:    error if the `PetscBLASInt` is not large enough to hold the number.

    1861:    Not Collective; No Fortran Support

    1863:    Input Parameter:
    1864: .  a - the `PetscInt` value

    1866:    Output Parameter:
    1867: .  b - the resulting `PetscBLASInt` value, or `NULL` if the result is not needed

    1869:    Level: advanced

    1871:    Note:
    1872:    Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs

    1874: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
    1875: @*/
    1876: static inline PetscErrorCode PetscBLASIntCast(MPIU_Count a, PetscBLASInt *b)
    1877: {
    1878:   PetscFunctionBegin;
    1879:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1880:   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);
    1881:   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine");
    1882:   if (b) *b = (PetscBLASInt)a;
    1883:   PetscFunctionReturn(PETSC_SUCCESS);
    1884: }

    1886: /*@C
    1887:    PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`.

    1889:    Not Collective; No Fortran Support

    1891:    Input Parameter:
    1892: .  a - the `PetscInt` value

    1894:    Output Parameter:
    1895: .  b - the resulting `PetscCuBLASInt` value, or `NULL` if the result is not needed

    1897:    Level: advanced

    1899:    Note:
    1900:    Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs

    1902: .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
    1903: @*/
    1904: static inline PetscErrorCode PetscCuBLASIntCast(MPIU_Count a, PetscCuBLASInt *b)
    1905: {
    1906:   PetscFunctionBegin;
    1907:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1908:   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);
    1909:   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to cuBLAS routine", (PetscInt64)a);
    1910:   if (b) *b = (PetscCuBLASInt)a;
    1911:   PetscFunctionReturn(PETSC_SUCCESS);
    1912: }

    1914: /*@C
    1915:    PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`.

    1917:    Not Collective; No Fortran Support

    1919:    Input Parameter:
    1920: .  a - the `PetscInt` value

    1922:    Output Parameter:
    1923: .  b - the resulting `PetscHipBLASInt` value, or `NULL` if the result is not needed

    1925:    Level: advanced

    1927:    Note:
    1928:    Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs

    1930: .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()`
    1931: @*/
    1932: static inline PetscErrorCode PetscHipBLASIntCast(MPIU_Count a, PetscHipBLASInt *b)
    1933: {
    1934:   PetscFunctionBegin;
    1935:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1936:   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);
    1937:   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to hipBLAS routine", (PetscInt64)a);
    1938:   if (b) *b = (PetscHipBLASInt)a;
    1939:   PetscFunctionReturn(PETSC_SUCCESS);
    1940: }

    1942: /*@C
    1943:    PetscMPIIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `PetscMPIInt` (which is always 32-bits in size), generates an
    1944:    error if the `PetscMPIInt` is not large enough to hold the number.

    1946:    Not Collective; No Fortran Support

    1948:    Input Parameter:
    1949: .  a - the `PetscInt` value

    1951:    Output Parameter:
    1952: .  b - the resulting `PetscMPIInt` value, or `NULL` if the result is not needed

    1954:    Level: advanced

    1956: .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
    1957: @*/
    1958: static inline PetscErrorCode PetscMPIIntCast(MPIU_Count a, PetscMPIInt *b)
    1959: {
    1960:   PetscFunctionBegin;
    1961:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1962:   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);
    1963:   if (b) *b = (PetscMPIInt)a;
    1964:   PetscFunctionReturn(PETSC_SUCCESS);
    1965: }

    1967: /*@C
    1968:    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.

    1970:    Not Collective; No Fortran Support

    1972:    Input Parameter:
    1973: .  a - the `PetscInt` value

    1975:    Output Parameter:
    1976: .  b - the resulting `int` value, or `NULL` if the result is not needed

    1978:    Level: advanced

    1980: .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntCast()`
    1981: @*/
    1982: static inline PetscErrorCode PetscCIntCast(MPIU_Count a, int *b)
    1983: {
    1984:   PetscFunctionBegin;
    1985:   if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
    1986:   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);
    1987:   if (b) *b = (int)a;
    1988:   PetscFunctionReturn(PETSC_SUCCESS);
    1989: }

    1991: /*MC
    1992:    PetscInt64Mult - Computes the product of two variables after casting them to `PetscInt64`.

    1994:    Not Collective; No Fortran Support

    1996:    Input Parameters:
    1997: +  a - the first variable
    1998: -  b - the second variable

    2000:    Level: advanced

    2002: .seealso: [](stylePetscCount), `PetscIntMultError()`, `PetscIntMultTruncate()`
    2003: M*/
    2004: #if defined(PETSC_USE_64BIT_INDICES)
    2005:   #define PetscInt64Mult(a, b) ((a) * (b))
    2006: #else
    2007:   #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b)))
    2008: #endif

    2010: /*@C
    2011:   PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive
    2012:   `PetscInt` and truncates the value to slightly less than the maximal possible value.

    2014:   Not Collective; No Fortran Support

    2016:   Input Parameters:
    2017: + a - The `PetscReal` value
    2018: - b - The `PetscInt` value

    2020:   Level: advanced

    2022:   Notes:
    2023:   Returns the result as a `PetscInt` value.

    2025:   Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`.

    2027:   Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate
    2028:   to fit a `PetscInt`.

    2030:   Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an
    2031:   error if the result will not fit in a `PetscInt`.

    2033:   Developer Notes:
    2034:   We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but
    2035:   requires many more checks.

    2037:   This is used where we compute approximate sizes for workspace and need to insure the
    2038:   workspace is index-able.

    2040: .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`
    2041: @*/
    2042: static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b)
    2043: {
    2044:   PetscInt64 r = (PetscInt64)(a * (PetscReal)b);
    2045:   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
    2046: #if defined(PETSC_USE_64BIT_INDICES)
    2047:   return r;
    2048: #else
    2049:   return (PetscInt)r;
    2050: #endif
    2051: }

    2053: /*@C
    2054:    PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value

    2056:    Not Collective; No Fortran Support

    2058:    Input Parameters:
    2059: +  a - the `PetscInt` value
    2060: -  b - the second value

    2062:    Returns:
    2063:    The result as a `PetscInt` value

    2065:    Level: advanced

    2067:    Notes:
    2068:    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`

    2070:    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`

    2072:    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`

    2074:    Developer Notes:
    2075:    We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks.

    2077:    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.

    2079: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`,
    2080:           `PetscIntSumTruncate()`
    2081: @*/
    2082: static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b)
    2083: {
    2084:   PetscInt64 r = PetscInt64Mult(a, b);
    2085:   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
    2086: #if defined(PETSC_USE_64BIT_INDICES)
    2087:   return r;
    2088: #else
    2089:   return (PetscInt)r;
    2090: #endif
    2091: }

    2093: /*@C
    2094:    PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value

    2096:    Not Collective; No Fortran Support

    2098:    Input Parameters:
    2099: +  a - the `PetscInt` value
    2100: -  b - the second value

    2102:    Returns:
    2103:    The result as a `PetscInt` value

    2105:    Level: advanced

    2107:    Notes:
    2108:    Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`

    2110:    Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt`

    2112:    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`

    2114:    Developer Note:
    2115:    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.

    2117: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
    2118: @*/
    2119: static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b)
    2120: {
    2121:   PetscInt64 r = a;

    2123:   r += b;
    2124:   if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100;
    2125: #if defined(PETSC_USE_64BIT_INDICES)
    2126:   return r;
    2127: #else
    2128:   return (PetscInt)r;
    2129: #endif
    2130: }

    2132: /*@C
    2133:    PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow.

    2135:    Not Collective; No Fortran Support

    2137:    Input Parameters:
    2138: +  a - the `PetscInt` value
    2139: -  b - the second value

    2141:    Output Parameter:
    2142: .  result - the result as a `PetscInt` value, or `NULL` if you do not want the result, you just want to check if it overflows

    2144:    Level: advanced

    2146:    Notes:
    2147:    Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64`

    2149:    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`

    2151:    Developer Note:
    2152:    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.
    2153:    `PetscIntSumError()` can be used to check for this situation.

    2155: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntSumError()`
    2156: @*/
    2157: static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result)
    2158: {
    2159:   PetscInt64 r = PetscInt64Mult(a, b);

    2161:   PetscFunctionBegin;
    2162: #if defined(PETSC_USE_64BIT_INDICES)
    2163:   if (result) *result = r;
    2164: #else
    2165:   if (result) *result = (PetscInt)r;
    2166: #endif
    2167:   if (!PetscDefined(USE_64BIT_INDICES)) {
    2168:     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);
    2169:   }
    2170:   PetscFunctionReturn(PETSC_SUCCESS);
    2171: }

    2173: /*@C

    2175:    PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow.

    2177:    Not Collective; No Fortran Support

    2179:    Input Parameters:
    2180: +  a - the `PetscInt` value
    2181: -  b - the second value

    2183:    Output Parameter:
    2184: .  c - the result as a `PetscInt` value,  or `NULL` if you do not want the result, you just want to check if it overflows

    2186:    Level: advanced

    2188:    Notes:
    2189:    Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64`

    2191:    Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt`

    2193: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`
    2194: @*/
    2195: static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result)
    2196: {
    2197:   PetscInt64 r = a;

    2199:   PetscFunctionBegin;
    2200:   r += b;
    2201: #if defined(PETSC_USE_64BIT_INDICES)
    2202:   if (result) *result = r;
    2203: #else
    2204:   if (result) *result = (PetscInt)r;
    2205: #endif
    2206:   if (!PetscDefined(USE_64BIT_INDICES)) {
    2207:     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);
    2208:   }
    2209:   PetscFunctionReturn(PETSC_SUCCESS);
    2210: }

    2212: /*
    2213:      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
    2214: */
    2215: #if defined(hz)
    2216:   #undef hz
    2217: #endif

    2219: #if defined(PETSC_HAVE_SYS_TYPES_H)
    2220:   #include <sys/types.h>
    2221: #endif

    2223: /*MC

    2225:     PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++
    2226:                     and Fortran compilers when `petscsys.h` is included.

    2228:     The current PETSc version and the API for accessing it are defined in <A HREF="../include/petscversion.h.html">include/petscversion.html</A>

    2230:     The complete version number is given as the triple  PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z)

    2232:     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
    2233:     where only a change in the major version number (x) indicates a change in the API.

    2235:     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

    2237:     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),
    2238:     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
    2239:     version number (x.y.z).

    2241:     `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases)

    2243:     `PETSC_VERSION_DATE` is the date the x.y.z version was released

    2245:     `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww

    2247:     `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository

    2249:     `PETSC_VERSION_()` is deprecated and will eventually be removed.

    2251:     Level: intermediate
    2252: M*/

    2254: PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t);
    2255: PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t);
    2256: PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t);
    2257: PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t);
    2258: PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
    2259: PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t);
    2260: PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
    2261: PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *);

    2263: PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscCount, const PetscInt[], PetscBool *);
    2264: PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscCount, const PetscInt64[], PetscBool *);
    2265: PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscCount, const PetscMPIInt[], PetscBool *);
    2266: PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscCount, const PetscReal[], PetscBool *);
    2267: PETSC_EXTERN PetscErrorCode PetscSortInt(PetscCount, PetscInt[]);
    2268: PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscCount, PetscInt64[]);
    2269: PETSC_EXTERN PetscErrorCode PetscSortCount(PetscCount, PetscCount[]);
    2270: PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscCount, PetscInt[]);
    2271: PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]);
    2272: PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscCount, const PetscInt[], PetscBool *);
    2273: PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsCount(PetscCount, const PetscCount[], PetscBool *);
    2274: PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]);
    2275: PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *);
    2276: PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscCount, const PetscInt[], PetscInt *);
    2277: PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscCount, const PetscMPIInt[], PetscInt *);
    2278: PETSC_EXTERN PetscErrorCode PetscFindCount(PetscCount, PetscCount, const PetscCount[], PetscCount *);
    2279: PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]);
    2280: PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]);
    2281: PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscCount, PetscInt[], PetscInt[]);
    2282: PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]);
    2283: PETSC_EXTERN PetscErrorCode PetscSortIntWithMPIIntArray(PetscCount, PetscInt[], PetscMPIInt[]);
    2284: PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscCount, PetscInt[], PetscInt[], PetscInt[]);
    2285: PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]);
    2286: PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscCount, PetscMPIInt[]);
    2287: PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]);
    2288: PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscCount, PetscMPIInt[], PetscMPIInt[]);
    2289: PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscCount, PetscMPIInt[], PetscInt[]);
    2290: PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscCount, PetscInt[], PetscScalar[]);
    2291: PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscCount, PetscInt[], void *, size_t, void *);
    2292: PETSC_EXTERN PetscErrorCode PetscSortReal(PetscCount, PetscReal[]);
    2293: PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscCount, PetscReal[], PetscInt[]);
    2294: PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]);
    2295: PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]);
    2296: PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscCount, const PetscReal[], PetscReal, PetscInt *);
    2297: PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]);
    2298: PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]);
    2299: PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[], PetscInt *[], PetscInt *[]);
    2300: PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[]);
    2301: PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt *[]);
    2302: PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt *[]);
    2303: PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);

    2305: PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *);
    2306: PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]);
    2307: PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]);
    2308: PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]);
    2309: PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *);
    2310: PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]);
    2311: PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]);
    2312: PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]);

    2314: PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
    2315: PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t);

    2317: /*J
    2318:     PetscRandomType - String with the name of a PETSc randomizer

    2320:    Level: beginner

    2322:    Note:
    2323:    To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc
    2324:    with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc.

    2326: .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()`
    2327: J*/
    2328: typedef const char *PetscRandomType;
    2329: #define PETSCRAND      "rand"
    2330: #define PETSCRAND48    "rand48"
    2331: #define PETSCSPRNG     "sprng"
    2332: #define PETSCRANDER48  "rander48"
    2333: #define PETSCRANDOM123 "random123"
    2334: #define PETSCCURAND    "curand"

    2336: /* Logging support */
    2337: PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;

    2339: PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
    2340: PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void);

    2342: /* Dynamic creation and loading functions */
    2343: PETSC_EXTERN PetscFunctionList PetscRandomList;

    2345: PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom));
    2346: PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
    2347: PETSC_EXTERN PetscErrorCode PetscRandomSetOptionsPrefix(PetscRandom, const char[]);
    2348: PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
    2349: PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *);
    2350: PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]);
    2351: PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer);

    2353: PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *);
    2354: PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *);
    2355: PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *);
    2356: PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *);
    2357: PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *);
    2358: PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *);
    2359: PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar);
    2360: PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, PetscInt64);
    2361: PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, PetscInt64 *);
    2362: PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
    2363: PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *);

    2365: PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t);
    2366: PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t);
    2367: PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t);
    2368: PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]);
    2369: PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t);
    2370: PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *);
    2371: PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *);
    2372: PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
    2373: PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
    2374: PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);

    2376: /*MC
    2377:    PetscBinaryBigEndian - indicates if values in memory are stored with big endian format

    2379:    Synopsis:
    2380: #include <petscsys.h>
    2381:    PetscBool PetscBinaryBigEndian(void);

    2383:    No Fortran Support

    2385:    Level: developer

    2387: .seealso: `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
    2388: M*/
    2389: static inline PetscBool PetscBinaryBigEndian(void)
    2390: {
    2391:   long _petsc_v = 1;
    2392:   return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;
    2393: }

    2395: PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscCount, PetscInt *, PetscDataType);
    2396: PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType);
    2397: PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscCount, PetscDataType);
    2398: PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType);
    2399: PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *);
    2400: PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
    2401: PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *);
    2402: PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *);
    2403: PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t);
    2404: PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *);
    2405: PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *);
    2406: #if defined(PETSC_USE_SOCKET_VIEWER)
    2407: PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *);
    2408: #endif

    2410: PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *);
    2411: PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *);
    2412: PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscCount);

    2414: PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
    2415: PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool);
    2416: PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
    2417: PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *);
    2418: PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
    2419: PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
    2420: PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);

    2422: PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *);
    2423: PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[]);
    2424: PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *[], PetscMPIInt *[], PetscMPIInt *[]);
    2425: PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **);
    2426: PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **);
    2427: 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);
    2428: 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);
    2429: 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);

    2431: PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType);
    2432: PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *);

    2434: PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *);

    2436: PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);

    2438: struct _n_PetscSubcomm {
    2439:   MPI_Comm         parent;    /* parent communicator */
    2440:   MPI_Comm         dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
    2441:   MPI_Comm         child;     /* the sub-communicator */
    2442:   PetscMPIInt      n;         /* num of subcommunicators under the parent communicator */
    2443:   PetscMPIInt      color;     /* color of processors belong to this communicator */
    2444:   PetscMPIInt     *subsize;   /* size of subcommunicator[color] */
    2445:   PetscSubcommType type;
    2446:   char            *subcommprefix;
    2447: };

    2449: static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm)
    2450: {
    2451:   return scomm->parent;
    2452: }
    2453: static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm)
    2454: {
    2455:   return scomm->child;
    2456: }
    2457: static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm)
    2458: {
    2459:   return scomm->dupparent;
    2460: }
    2461: PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *);
    2462: PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *);
    2463: PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt);
    2464: PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType);
    2465: PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt);
    2466: PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer);
    2467: PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
    2468: PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]);
    2469: PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *);
    2470: PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *);
    2471: PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *);

    2473: PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *);
    2474: PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt);
    2475: PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *);
    2476: PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *);
    2477: PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt);
    2478: PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
    2479: PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *);
    2480: PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer);

    2482: PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
    2483: PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *);
    2484: PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
    2485: PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *);
    2486: PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *);

    2488: /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
    2489: PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *);
    2490: PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *);
    2491: PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *);
    2492: PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
    2493: PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
    2494: PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);

    2496: PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, PetscCount, PetscSegBuffer *);
    2497: PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *);
    2498: PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, PetscCount, void *);
    2499: PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *);
    2500: PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *);
    2501: PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *);
    2502: PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, PetscCount *);
    2503: PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, PetscCount);

    2505: /*MC
    2506:   PetscSegBufferGetInts - access an array of `PetscInt` from a `PetscSegBuffer`

    2508:   Synopsis:
    2509: #include <petscsys.h>
    2510:   PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot);

    2512:   No Fortran Support

    2514:   Input Parameters:
    2515: + seg   - `PetscSegBuffer` buffer
    2516: - count - number of entries needed

    2518:   Output Parameter:
    2519: . buf - address of new buffer for contiguous data

    2521:   Level: intermediate

    2523:   Developer Note:
    2524:   Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
    2525:   prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
    2526:   possible.

    2528: .seealso: `PetscSegBuffer`, `PetscSegBufferGet()`, `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled`
    2529: M*/
    2530: static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, PetscCount count, PetscInt *PETSC_RESTRICT *slot)
    2531: {
    2532:   return PetscSegBufferGet(seg, count, (void **)slot);
    2533: }

    2535: extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
    2536: PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *);
    2537: PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *);
    2538: PETSC_EXTERN PetscErrorCode    PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *);

    2540: #include <stdarg.h>
    2541: PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list);
    2542: PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list);

    2544: PETSC_EXTERN PetscSegBuffer PetscCitationsList;

    2546: /*@
    2547:      PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.

    2549:      Not Collective; No Fortran Support

    2551:      Input Parameters:
    2552: +    cite - the bibtex item, formatted to displayed on multiple lines nicely
    2553: -    set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation

    2555:      Options Database Key:
    2556: .     -citations [filename]   - print out the bibtex entries for the given computation

    2558:      Level: intermediate
    2559: @*/
    2560: static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set)
    2561: {
    2562:   size_t len;
    2563:   char  *vstring;

    2565:   PetscFunctionBegin;
    2566:   if (set && *set) PetscFunctionReturn(PETSC_SUCCESS);
    2567:   PetscCall(PetscStrlen(cit, &len));
    2568:   PetscCall(PetscSegBufferGet(PetscCitationsList, (PetscCount)len, &vstring));
    2569:   PetscCall(PetscArraycpy(vstring, cit, len));
    2570:   if (set) *set = PETSC_TRUE;
    2571:   PetscFunctionReturn(PETSC_SUCCESS);
    2572: }

    2574: PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t);
    2575: PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t);
    2576: PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]);

    2578: PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t);
    2579: PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t);
    2580: PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]);

    2582: PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t);
    2583: PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t);
    2584: PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]);

    2586: PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *);
    2587: PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t);

    2589: #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
    2590: PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
    2591: PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
    2592: #endif

    2594: #if !defined(PETSC_HAVE_MPI_LARGE_COUNT)
    2595:   /*
    2596:    Cast PetscCount <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines.
    2597:    It is similar to PetscMPIIntCast() except that here it returns an MPI error code.
    2598: */
    2599:   #define PetscMPIIntCast_Internal(a, b) \
    2600:     do { \
    2601:       *b = 0; \
    2602:       if (PetscUnlikely(a > (MPIU_Count)PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT; \
    2603:       *b = (PetscMPIInt)a; \
    2604:     } while (0)

    2606: static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
    2607: {
    2608:   PetscMPIInt count2, err;

    2610:   *count = 0; /* to prevent incorrect warnings of uninitialized variables */
    2611:   err    = MPI_Get_count(status, dtype, &count2);
    2612:   *count = count2;
    2613:   return err;
    2614: }

    2616: static inline PetscMPIInt MPIU_Send(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm)
    2617: {
    2618:   PetscMPIInt count2, err;

    2620:   PetscMPIIntCast_Internal(count, &count2);
    2621:   err = MPI_Send((void *)buf, count2, dtype, dest, tag, comm);
    2622:   return err;
    2623: }

    2625: 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)
    2626: {
    2627:   PetscMPIInt count2, err;

    2629:   PetscMPIIntCast_Internal(count, &count2);
    2630:   err = MPI_Send_init((void *)buf, count2, dtype, dest, tag, comm, request);
    2631:   return err;
    2632: }

    2634: static inline PetscMPIInt MPIU_Isend(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
    2635: {
    2636:   PetscMPIInt count2, err;

    2638:   PetscMPIIntCast_Internal(count, &count2);
    2639:   err = MPI_Isend((void *)buf, count2, dtype, dest, tag, comm, request);
    2640:   return err;
    2641: }

    2643: static inline PetscMPIInt MPIU_Recv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Status *status)
    2644: {
    2645:   PetscMPIInt count2, err;

    2647:   PetscMPIIntCast_Internal(count, &count2);
    2648:   err = MPI_Recv((void *)buf, count2, dtype, source, tag, comm, status);
    2649:   return err;
    2650: }

    2652: 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)
    2653: {
    2654:   PetscMPIInt count2, err;

    2656:   PetscMPIIntCast_Internal(count, &count2);
    2657:   err = MPI_Recv_init((void *)buf, count2, dtype, source, tag, comm, request);
    2658:   return err;
    2659: }

    2661: static inline PetscMPIInt MPIU_Irecv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
    2662: {
    2663:   PetscMPIInt count2, err;

    2665:   PetscMPIIntCast_Internal(count, &count2);
    2666:   err = MPI_Irecv((void *)buf, count2, dtype, source, tag, comm, request);
    2667:   return err;
    2668: }

    2670: static inline PetscMPIInt MPIU_Reduce(const void *inbuf, void *outbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op, PetscMPIInt root, MPI_Comm comm)
    2671: {
    2672:   PetscMPIInt count2, err;

    2674:   PetscMPIIntCast_Internal(count, &count2);
    2675:   err = MPI_Reduce((void *)inbuf, outbuf, count2, dtype, op, root, comm);
    2676:   return err;
    2677: }

    2679:   #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
    2680: static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op)
    2681: {
    2682:   PetscMPIInt count2, err;

    2684:   PetscMPIIntCast_Internal(count, &count2);
    2685:   err = MPI_Reduce_local((void *)inbuf, inoutbuf, count2, dtype, op);
    2686:   return err;
    2687: }
    2688:   #endif

    2690:   #if !defined(PETSC_USE_64BIT_INDICES)
    2691:     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
    2692:     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
    2693:   #else
    2694:     #define MPIU_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
    2695:       ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
    2696:     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \
    2697:       ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT)
    2698:   #endif

    2700: #else

    2702:   /* on 32 bit systems MPI_Count maybe 64-bit while PetscCount is 32-bit */
    2703:   #define PetscCountCast_Internal(a, b) \
    2704:     do { \
    2705:       *b = 0; \
    2706:       if (PetscUnlikely(a > (MPI_Count)PETSC_COUNT_MAX)) return MPI_ERR_COUNT; \
    2707:       *b = (PetscMPIInt)a; \
    2708:     } while (0)

    2710: static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count)
    2711: {
    2712:   MPI_Count   count2;
    2713:   PetscMPIInt err;

    2715:   *count = 0; /* to prevent incorrect warnings of uninitialized variables */
    2716:   err    = MPI_Get_count_c(status, dtype, &count2);
    2717:   if (err) return err;
    2718:   PetscCountCast_Internal(count2, count);
    2719:   return MPI_SUCCESS;
    2720: }

    2722:   #define MPIU_Reduce(inbuf, outbuf, count, dtype, op, root, comm)      MPI_Reduce_c(inbuf, outbuf, (MPI_Count)(count), dtype, op, root, comm)
    2723:   #define MPIU_Send(buf, count, dtype, dest, tag, comm)                 MPI_Send_c(buf, (MPI_Count)(count), dtype, dest, tag, comm)
    2724:   #define MPIU_Send_init(buf, count, dtype, dest, tag, comm, request)   MPI_Send_init_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
    2725:   #define MPIU_Isend(buf, count, dtype, dest, tag, comm, request)       MPI_Isend_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request)
    2726:   #define MPIU_Recv(buf, count, dtype, source, tag, comm, status)       MPI_Recv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, status)
    2727:   #define MPIU_Recv_init(buf, count, dtype, source, tag, comm, request) MPI_Recv_init_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
    2728:   #define MPIU_Irecv(buf, count, dtype, source, tag, comm, request)     MPI_Irecv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request)
    2729:   #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
    2730:     #define MPIU_Reduce_local(inbuf, inoutbuf, count, dtype, op) MPI_Reduce_local_c(inbuf, inoutbuf, (MPI_Count)(count), dtype, op)
    2731:   #endif

    2733: /*MC
    2734:   MPIU_Scatterv - A replacement for `MPI_Scatterv()` that can be called with `PetscInt` types when PETSc is built for either 32-bit indices or 64-bit indices.

    2736:   Synopsis:
    2737: #include <petscsys.h>
    2738:   PetscMPIInt MPIU_Scatterv(const void *sendbuf, const PetscInt sendcounts[], const PetscInt displs[], MPI_Datatype sendtype, void *recvbuf, PetscInt recvcount, MPI_Datatype recvtype, PetscMPIInt root, MPI_Comm comm)

    2740:   Collective

    2742:   Input Parameters:
    2743: + sendbuf    - address of send buffer
    2744: . sendcounts - non-negative `PetscInt` array (of length `comm` group size) specifying the number of elements to send to each MPI process
    2745: . displs     - `PetscInt` array (of length `comm` group size). Entry i specifies the displacement (relative to `sendbuf`) from which to take the outgoing data to process i
    2746: . sendtype   - data type of `sendbuf` elements
    2747: . recvcount  - number of elements in `recvbuf` (non-negative integer)
    2748: . recvtype   - data type of `recvbuf` elements
    2749: . root       - Rank of the MPI root process, which will dispatch the data to scatter
    2750: - comm       - `MPI_Comm` communicator

    2752:   Output Parameter:
    2753: . recvbuf - the resulting scattered values on this MPI process

    2755:   Level: developer

    2757:   Notes:
    2758:   Should be wrapped with `PetscCallMPI()` for error checking

    2760:   This is different than most of the `MPIU_` wrappers in that all the count arguments are in `PetscInt`

    2762: .seealso: [](stylePetscCount), `MPI_Allreduce()`, `MPIU_Gatherv()`
    2763: M*/

    2765:   #if !defined(PETSC_USE_64BIT_INDICES)
    2766:     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm)
    2767:     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)
    2768:   #else
    2769:     #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv_c(sendbuf, (const MPI_Count *)(sendcounts), (const MPI_Aint *)(displs), sendtype, recvbuf, recvcount, recvtype, root, comm)
    2770:     #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm)  MPI_Gatherv_c(sendbuf, sendcount, sendtype, recvbuf, (const MPI_Count *)(recvcounts), (const MPI_Aint *)(displs), recvtype, root, comm)
    2771:   #endif

    2773: #endif

    2775: PETSC_EXTERN PetscMPIInt MPIU_Allreduce_Private(const void *, void *, MPIU_Count, MPI_Datatype, MPI_Op, MPI_Comm);

    2777: #if defined(PETSC_USE_DEBUG)
    2778: static inline unsigned int PetscStrHash(const char *str)
    2779: {
    2780:   unsigned int c, hash = 5381;

    2782:   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
    2783:   return hash;
    2784: }
    2785: #endif

    2787: /*MC
    2788:   MPIU_Allreduce - A replacement for `MPI_Allreduce()` that (1) performs single-count `MPIU_INT` operations in `PetscInt64` to detect
    2789:                    integer overflows and (2) tries to determine if the call from all the MPI ranks occur in the
    2790:                    same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths
    2791:                    resulting in inconsistent and incorrect calls to `MPI_Allreduce()`.

    2793:   Synopsis:
    2794: #include <petscsys.h>
    2795:   PetscMPIInt MPIU_Allreduce(void *indata,void *outdata,PetscCount count,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm);

    2797:   Collective

    2799:   Input Parameters:
    2800: + a     - pointer to the input data to be reduced
    2801: . count - the number of MPI data items in `a` and `b`
    2802: . dtype - the MPI datatype, for example `MPI_INT`
    2803: . op    - the MPI operation, for example `MPI_SUM`
    2804: - comm   - the MPI communicator on which the operation occurs

    2806:   Output Parameter:
    2807: . b - the reduced values

    2809:   Level: developer

    2811:   Note:
    2812:   Should be wrapped with `PetscCallMPI()` for error checking

    2814: .seealso: [](stylePetscCount), `MPI_Allreduce()`
    2815: M*/
    2816: #if defined(PETSC_USE_DEBUG)
    2817:   #define MPIU_Allreduce(a, b, c, d, e, fcomm) \
    2818:     PetscMacroReturnStandard( \
    2819:     PetscMPIInt a_b1[6], a_b2[6]; \
    2820:     int _mpiu_allreduce_c_int = (int)(c); \
    2821:     a_b1[0] = -(PetscMPIInt)__LINE__; \
    2822:     a_b1[1] = -a_b1[0]; \
    2823:     a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \
    2824:     a_b1[3] = -a_b1[2]; \
    2825:     a_b1[4] = -(PetscMPIInt)(c); \
    2826:     a_b1[5] = -a_b1[4]; \
    2827:     \
    2828:     PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \
    2829:     PetscCheck(-a_b2[0] == a_b2[1], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (code lines) on different processors"); \
    2830:     PetscCheck(-a_b2[2] == a_b2[3], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (functions) on different processors"); \
    2831:     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); \
    2832:     PetscCallMPI(MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)));)
    2833: #else
    2834:   #define MPIU_Allreduce(a, b, c, d, e, fcomm) MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm))
    2835: #endif

    2837: #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
    2838: PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *);
    2839: PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *);
    2840: #endif

    2842: /* this is a vile hack */
    2843: #if defined(PETSC_HAVE_NECMPI)
    2844:   #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)
    2845:     #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0);
    2846:   #endif
    2847: #endif

    2849: /*
    2850:     List of external packages and queries on it
    2851: */
    2852: PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *);

    2854: /* this cannot go here because it may be in a different shared library */
    2855: PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void);
    2856: PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void);
    2857: PETSC_EXTERN PetscBool      PCMPIServerActive;
    2858: PETSC_EXTERN PetscBool      PCMPIServerInSolve;
    2859: PETSC_EXTERN PetscBool      PCMPIServerUseShmget;
    2860: PETSC_EXTERN PetscErrorCode PetscShmgetAllocateArray(size_t, size_t, void **);
    2861: PETSC_EXTERN PetscErrorCode PetscShmgetDeallocateArray(void **);
    2862: PETSC_EXTERN PetscErrorCode PetscShmgetMapAddresses(MPI_Comm, PetscInt, const void **, void **);
    2863: PETSC_EXTERN PetscErrorCode PetscShmgetUnmapAddresses(PetscInt, void **);
    2864: PETSC_EXTERN PetscErrorCode PetscShmgetAddressesFinalize(void);

    2866: typedef struct {
    2867:   PetscInt n;
    2868:   void    *addr[3];
    2869: } PCMPIServerAddresses;
    2870: PETSC_EXTERN PetscCtxDestroyFn PCMPIServerAddressesDestroy;

    2872: #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS

    2874: PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt);
    2875: PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *);

    2877: /*MC
    2878:    PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset

    2880:    Level: beginner

    2882:    Note:
    2883:    This is needed to avoid errors with undefined-behavior sanitizers such as
    2884:    UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags
    2885: M*/
    2886: #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL)

    2888: /* this is required to force PetscDevice to be visible at the system level for the Fortran interface */
    2889: #include <petscdevicetypes.h>