1d382aafbSBarry Smith /* 2d382aafbSBarry Smith This is the main PETSc include file (for C and C++). It is included by all 3d382aafbSBarry Smith other PETSc include files, so it almost never has to be specifically included. 447d993e7Ssuyashtn Portions of this code are under: 547d993e7Ssuyashtn Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. 6d382aafbSBarry Smith */ 76524c165SJacob Faibussowitsch #ifndef PETSCSYS_H 826bd1501SBarry Smith #define PETSCSYS_H 93ca90d2dSJacob Faibussowitsch 10d382aafbSBarry Smith /* ========================================================================== */ 11d382aafbSBarry Smith /* 12d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 131c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 141c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules. 151c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 161cc8b206SBarry Smith directory as the other PETSc include files. 17d382aafbSBarry Smith */ 182c8e378dSBarry Smith #include <petscconf.h> 191c77a0c5SBarry Smith #include <petscconf_poison.h> 202c8e378dSBarry Smith #include <petscfix.h> 21bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2233bb201bSJacob Faibussowitsch 23ac09b921SBarry Smith /* SUBMANSEC = Sys */ 24ac09b921SBarry Smith 2573fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2673fca5a0SBarry Smith /* 2773fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2873fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2973fca5a0SBarry Smith */ 30216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 3173fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L 3273fca5a0SBarry Smith #endif 33216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3473fca5a0SBarry Smith #define _BSD_SOURCE 3573fca5a0SBarry Smith #endif 3607f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3707f00807SSatish Balay #define _DEFAULT_SOURCE 3807f00807SSatish Balay #endif 39ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 40ea0fecefSShri Abhyankar #define _GNU_SOURCE 41ea0fecefSShri Abhyankar #endif 4273fca5a0SBarry Smith #endif 4373fca5a0SBarry Smith 44df4397b0SStefano Zampini #include <petscsystypes.h> 45df4397b0SStefano Zampini 46d382aafbSBarry Smith /* ========================================================================== */ 47d382aafbSBarry Smith 48d382aafbSBarry Smith /* 49d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 50d382aafbSBarry Smith 51d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 52d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 53d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 54d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 55d382aafbSBarry Smith mpicxx.h directly in their code 56d382aafbSBarry Smith */ 57fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 58d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1 59fa9e63e2SJed Brown #endif 60fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 61d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1 62fa9e63e2SJed Brown #endif 63e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 64e771154cSJed Brown #include <petsc/mpiuni/mpi.h> 65e771154cSJed Brown #else 662c8e378dSBarry Smith #include <mpi.h> 67e771154cSJed Brown #endif 6865013866SBarry Smith 69d382aafbSBarry Smith /* 70a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 71a7886beaSBarry Smith This usually happens because 72a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 73a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 74a7886beaSBarry Smith */ 75a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 766524c165SJacob Faibussowitsch #ifndef MPIUNI_H 77a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 78a7886beaSBarry Smith #endif 7941f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 8041f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 8141f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 8241f4af4cSSatish Balay #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 8341f4af4cSSatish Balay #error "PETSc was configured with one I_MPI mpi.h version but now appears to be compiling using a different I_MPI mpi.h version" 8441f4af4cSSatish Balay #endif 8541f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 8641f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8741f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 8841f4af4cSSatish Balay #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 8941f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 9041f4af4cSSatish Balay #endif 91a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 9241f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 93a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 941c284764SMin RK #elif (MPICH_NUMVERSION / 100000000 != PETSC_HAVE_MPICH_NUMVERSION / 100000000) || (MPICH_NUMVERSION / 100000 < PETSC_HAVE_MPICH_NUMVERSION / 100000) || (MPICH_NUMVERSION / 100000 == PETSC_HAVE_MPICH_NUMVERSION / 100000 && MPICH_NUMVERSION % 100000 / 1000 < PETSC_HAVE_MPICH_NUMVERSION % 100000 / 1000) 95a7886beaSBarry Smith #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 96a7886beaSBarry Smith #endif 97a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 98a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 99a7886beaSBarry Smith #error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h" 1001c284764SMin RK #elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION) 101c3ac57cfSSatish Balay #error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version" 102a7886beaSBarry Smith #endif 103d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 104d97fd468SStefano Zampini #if !defined(MSMPI_VER) 105d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 106d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 107d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 108d97fd468SStefano Zampini #endif 109d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 110d97fd468SStefano Zampini #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant" 111a7886beaSBarry Smith #endif 112a7886beaSBarry Smith 113a7886beaSBarry Smith /* 1142981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 115d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 116d382aafbSBarry Smith */ 117d382aafbSBarry Smith #include <stdio.h> 118d382aafbSBarry Smith 119d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 120d382aafbSBarry Smith #if !defined(MPIAPI) 121d382aafbSBarry Smith #define MPIAPI 122d382aafbSBarry Smith #endif 123d382aafbSBarry Smith 12493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 12593d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 126e28ce29aSPatrick Sanan 127e28ce29aSPatrick Sanan /*MC 12887497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 129e28ce29aSPatrick Sanan 130*667f096bSBarry Smith Level: beginner 131*667f096bSBarry Smith 132e28ce29aSPatrick Sanan Notes: 13387497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 134e28ce29aSPatrick Sanan 135db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 136e28ce29aSPatrick Sanan M*/ 137e28ce29aSPatrick Sanan 1387cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 139b7b8f77aSBarry Smith 140d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 141bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 142d382aafbSBarry Smith #else 143d382aafbSBarry Smith #define MPIU_INT MPI_INT 144d382aafbSBarry Smith #endif 145d382aafbSBarry Smith 146503cfb0cSBarry Smith /* 147503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 148503cfb0cSBarry Smith */ 14993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 150d382aafbSBarry Smith 151d382aafbSBarry Smith /* 152d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 153d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 154d382aafbSBarry Smith */ 155014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 156d382aafbSBarry Smith 157d382aafbSBarry Smith /* 158d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 159d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 160d382aafbSBarry Smith */ 161014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 162d382aafbSBarry Smith 163c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */ 164c8b9133aSSatish Balay 1655c993f7fSStefano Zampini #if defined(__NEC__) 1665c993f7fSStefano Zampini #define PetscPragmaSIMD _Pragma("_NEC ivdep") 1675c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32) 168c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("vector") 1691dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI) 170c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("GCC ivdep") 171e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307 172e5518150SSatish Balay #if defined(_MSC_VER) 173160a5775SAli Reza Khaz'ali #define PetscPragmaSIMD __pragma(omp simd) 174e5518150SSatish Balay #else 175e5518150SSatish Balay #define PetscPragmaSIMD _Pragma("omp simd") 176e5518150SSatish Balay #endif 177c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR) 178c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("_CRI ivdep") 179c8b9133aSSatish Balay #else 180c8b9133aSSatish Balay #define PetscPragmaSIMD 181c8b9133aSSatish Balay #endif 182c8b9133aSSatish Balay 183d382aafbSBarry Smith /* 184dc07da0dSStefano Zampini Handle inclusion when using clang compiler with CUDA support 185dc07da0dSStefano Zampini __float128 is not available for the device 186dc07da0dSStefano Zampini */ 187dc07da0dSStefano Zampini #if defined(__clang__) && defined(__CUDA_ARCH__) 188dc07da0dSStefano Zampini #define PETSC_SKIP_REAL___FLOAT128 189dc07da0dSStefano Zampini #endif 190dc07da0dSStefano Zampini 191dc07da0dSStefano Zampini /* 192d382aafbSBarry Smith Declare extern C stuff after including external header files 193d382aafbSBarry Smith */ 194d382aafbSBarry Smith 1956edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 1968b49ba18SBarry Smith /* 197390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 1988b49ba18SBarry Smith */ 1998b49ba18SBarry Smith #include <petscmath.h> 2008b49ba18SBarry Smith 201d382aafbSBarry Smith /*MC 202*667f096bSBarry Smith PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument 203d382aafbSBarry Smith 204d382aafbSBarry Smith Level: beginner 205d382aafbSBarry Smith 206e28ce29aSPatrick Sanan Note: 207*667f096bSBarry Smith Accepted by many PETSc functions to not set a parameter and instead use a default value 208d382aafbSBarry Smith 20987497f52SBarry Smith Fortran Note: 210*667f096bSBarry Smith Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 211d382aafbSBarry Smith 212db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 213d382aafbSBarry Smith M*/ 214f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR 215f3fa974cSJacob Faibussowitsch #define PETSC_NULL PETSC_DEPRECATED_MACRO("GCC warning \"PETSC_NULL is deprecated, use PETSC_NULLPTR instead (since version 3.19)\"") PETSC_NULLPTR 216c528d872SBarry Smith 217d382aafbSBarry Smith /*MC 218557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 219557d4da8SBarry Smith where you wish PETSc to use the default. 220557d4da8SBarry Smith 221557d4da8SBarry Smith Level: beginner 222557d4da8SBarry Smith 223db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 224557d4da8SBarry Smith M*/ 225557d4da8SBarry Smith 226557d4da8SBarry Smith /*MC 227d382aafbSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter 228d382aafbSBarry Smith where you wish PETSc to compute the required value. 229d382aafbSBarry Smith 230d382aafbSBarry Smith Level: beginner 231d382aafbSBarry Smith 232e28ce29aSPatrick Sanan Developer Note: 23387497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 23487497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 235557d4da8SBarry Smith 236db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 237d382aafbSBarry Smith M*/ 238d382aafbSBarry Smith 239d382aafbSBarry Smith /*MC 240557d4da8SBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter 241557d4da8SBarry Smith where you wish PETSc to use the default. 242557d4da8SBarry Smith 243557d4da8SBarry Smith Level: beginner 244557d4da8SBarry Smith 24587497f52SBarry Smith Fortran Note: 24687497f52SBarry Smith You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 247557d4da8SBarry Smith 248db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 249557d4da8SBarry Smith M*/ 250f3fa974cSJacob Faibussowitsch enum { 251f3fa974cSJacob Faibussowitsch PETSC_DECIDE = -1, 252f3fa974cSJacob Faibussowitsch PETSC_DETERMINE = PETSC_DECIDE, 253f3fa974cSJacob Faibussowitsch PETSC_DEFAULT = -2 254f3fa974cSJacob Faibussowitsch }; 255557d4da8SBarry Smith 256557d4da8SBarry Smith /*MC 25787497f52SBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents 258ea8fe74dSBarry Smith all the processes that PETSc knows about. 259d382aafbSBarry Smith 260d382aafbSBarry Smith Level: beginner 261d382aafbSBarry Smith 262e28ce29aSPatrick Sanan Notes: 26387497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 26487497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 26587497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 26687497f52SBarry Smith PetscInitialize(), but after `MPI_Init()` has been called. 267a990b902SBarry Smith 26887497f52SBarry Smith The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()` 269a990b902SBarry Smith is called because it may not have a valid value yet. 270d382aafbSBarry Smith 271db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 272d382aafbSBarry Smith M*/ 273014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 274d382aafbSBarry Smith 275d382aafbSBarry Smith /*MC 27687497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 277d382aafbSBarry Smith 278d382aafbSBarry Smith Level: beginner 279d382aafbSBarry Smith 280e28ce29aSPatrick Sanan Notes: 281e28ce29aSPatrick Sanan Do not USE/access or set this variable before PetscInitialize() has been called. 282a990b902SBarry Smith 283db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 284d382aafbSBarry Smith M*/ 285d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 286d382aafbSBarry Smith 2876de5d289SStefano Zampini /*MC 2886de5d289SStefano Zampini PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes 28987497f52SBarry Smith MPI with `MPI_Init_thread()`. 2906de5d289SStefano Zampini 2916de5d289SStefano Zampini Level: beginner 2926de5d289SStefano Zampini 2936de5d289SStefano Zampini Notes: 29487497f52SBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`. 2956de5d289SStefano Zampini 296db781477SPatrick Sanan .seealso: `PetscInitialize()` 2976de5d289SStefano Zampini M*/ 2986de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 2996de5d289SStefano Zampini 300d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 3018ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 302014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 303014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3044cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 305d382aafbSBarry Smith 306014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 307014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 308014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 30957f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 31057f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 311d382aafbSBarry Smith 31259e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 31359e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 31459e55d94SJunchao Zhang #endif 31559e55d94SJunchao Zhang 31671438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 31771438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 31871438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 31971438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 32071438e86SJunchao Zhang #endif 32171438e86SJunchao Zhang 322540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 323540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 324540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 325540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 326540e20f2SPierre Jolivet #endif 327540e20f2SPierre Jolivet 328d382aafbSBarry Smith /*MC 32987497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 330d382aafbSBarry Smith 331eca87e8dSBarry Smith Synopsis: 332aaa7dc30SBarry Smith #include <petscsys.h> 333eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 334eca87e8dSBarry Smith 335eca87e8dSBarry Smith Not Collective 336eca87e8dSBarry Smith 337d382aafbSBarry Smith Input Parameter: 338d382aafbSBarry Smith . m - number of bytes to allocate 339d382aafbSBarry Smith 340d382aafbSBarry Smith Output Parameter: 341d382aafbSBarry Smith . result - memory allocated 342d382aafbSBarry Smith 343d382aafbSBarry Smith Level: beginner 344d382aafbSBarry Smith 34549d7da52SJed Brown Notes: 34649d7da52SJed Brown Memory is always allocated at least double aligned 347d382aafbSBarry Smith 34887497f52SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`. 349d382aafbSBarry Smith 350db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 351d382aafbSBarry Smith M*/ 352071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 353d382aafbSBarry Smith 354d382aafbSBarry Smith /*MC 355d5b43468SJose E. Roman PetscRealloc - Reallocates memory 3563221ece2SMatthew G. Knepley 3573221ece2SMatthew G. Knepley Synopsis: 3583221ece2SMatthew G. Knepley #include <petscsys.h> 3593221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3603221ece2SMatthew G. Knepley 3613221ece2SMatthew G. Knepley Not Collective 3623221ece2SMatthew G. Knepley 3633221ece2SMatthew G. Knepley Input Parameters: 3643221ece2SMatthew G. Knepley + m - number of bytes to allocate 36592f119d6SBarry Smith - result - previous memory 3663221ece2SMatthew G. Knepley 3673221ece2SMatthew G. Knepley Output Parameter: 3683221ece2SMatthew G. Knepley . result - new memory allocated 3693221ece2SMatthew G. Knepley 3703221ece2SMatthew G. Knepley Level: developer 3713221ece2SMatthew G. Knepley 3723221ece2SMatthew G. Knepley Notes: 3733221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 3743221ece2SMatthew G. Knepley 375db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 3763221ece2SMatthew G. Knepley M*/ 3773221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 3783221ece2SMatthew G. Knepley 3793221ece2SMatthew G. Knepley /*MC 38087497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 381d382aafbSBarry Smith 382d382aafbSBarry Smith Synopsis: 383aaa7dc30SBarry Smith #include <petscsys.h> 384d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 385d382aafbSBarry Smith 386eca87e8dSBarry Smith Not Collective 387eca87e8dSBarry Smith 388eca87e8dSBarry Smith Input Parameters: 389eca87e8dSBarry Smith . addr - address to align (any pointer type) 390eca87e8dSBarry Smith 391d382aafbSBarry Smith Level: developer 392d382aafbSBarry Smith 393db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 394d382aafbSBarry Smith M*/ 395f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))) 396d382aafbSBarry Smith 397d382aafbSBarry Smith /*MC 39887497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 3998f51dc47SJunchao Zhang 4008f51dc47SJunchao Zhang Synopsis: 4018f51dc47SJunchao Zhang #include <petscsys.h> 4028f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4038f51dc47SJunchao Zhang 4048f51dc47SJunchao Zhang Not Collective 4058f51dc47SJunchao Zhang 4068f51dc47SJunchao Zhang Input Parameter: 4078f51dc47SJunchao Zhang . m - number of bytes to allocate 4088f51dc47SJunchao Zhang 4098f51dc47SJunchao Zhang Output Parameter: 4108f51dc47SJunchao Zhang . result - memory allocated 4118f51dc47SJunchao Zhang 4128f51dc47SJunchao Zhang Level: beginner 4138f51dc47SJunchao Zhang 4148f51dc47SJunchao Zhang Notes: 4158f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4168f51dc47SJunchao Zhang 4178f51dc47SJunchao Zhang It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 4188f51dc47SJunchao Zhang 419db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4208f51dc47SJunchao Zhang M*/ 421f3fa974cSJacob Faibussowitsch #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result)) 4228f51dc47SJunchao Zhang 4238f51dc47SJunchao Zhang /*MC 42487497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 425d382aafbSBarry Smith 426eca87e8dSBarry Smith Synopsis: 427aaa7dc30SBarry Smith #include <petscsys.h> 428785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 429785e854fSJed Brown 430785e854fSJed Brown Not Collective 431785e854fSJed Brown 432785e854fSJed Brown Input Parameter: 433390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 434785e854fSJed Brown 435785e854fSJed Brown Output Parameter: 4361fe1b817SJunchao Zhang . r1 - memory allocated 437785e854fSJed Brown 438e28ce29aSPatrick Sanan Note: 439e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 44087497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 441390e1bf2SBarry Smith $ PetscInt *id; 442390e1bf2SBarry Smith $ PetscMalloc1(10,&id); 443390e1bf2SBarry Smith not 444390e1bf2SBarry Smith $ PetscInt *id; 445390e1bf2SBarry Smith $ PetscMalloc1(10*sizeof(PetscInt),&id); 446390e1bf2SBarry Smith 44787497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 448390e1bf2SBarry Smith 449390e1bf2SBarry Smith Level: beginner 450785e854fSJed Brown 451db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 452785e854fSJed Brown M*/ 453f3fa974cSJacob Faibussowitsch #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 454785e854fSJed Brown 455785e854fSJed Brown /*MC 45687497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 4571795a4d1SJed Brown 4581795a4d1SJed Brown Synopsis: 459aaa7dc30SBarry Smith #include <petscsys.h> 4601795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 4611795a4d1SJed Brown 4621795a4d1SJed Brown Not Collective 4631795a4d1SJed Brown 4641795a4d1SJed Brown Input Parameter: 4651795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 4661795a4d1SJed Brown 4671795a4d1SJed Brown Output Parameter: 4681fe1b817SJunchao Zhang . r1 - memory allocated 4691795a4d1SJed Brown 470e28ce29aSPatrick Sanan Notes: 47187497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 472390e1bf2SBarry Smith 473390e1bf2SBarry Smith Level: beginner 4741795a4d1SJed Brown 475db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 4761795a4d1SJed Brown M*/ 477f3fa974cSJacob Faibussowitsch #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 4781795a4d1SJed Brown 4791795a4d1SJed Brown /*MC 48087497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 481d382aafbSBarry Smith 482eca87e8dSBarry Smith Synopsis: 483aaa7dc30SBarry Smith #include <petscsys.h> 484dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 485eca87e8dSBarry Smith 486eca87e8dSBarry Smith Not Collective 487eca87e8dSBarry Smith 488d8d19677SJose E. Roman Input Parameters: 489d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 490dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 491d382aafbSBarry Smith 492d8d19677SJose E. Roman Output Parameters: 493d382aafbSBarry Smith + r1 - memory allocated in first chunk 494d382aafbSBarry Smith - r2 - memory allocated in second chunk 495d382aafbSBarry Smith 496d382aafbSBarry Smith Level: developer 497d382aafbSBarry Smith 498db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 499d382aafbSBarry Smith M*/ 500f3fa974cSJacob Faibussowitsch #define PetscMalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2)) 501d382aafbSBarry Smith 502d382aafbSBarry Smith /*MC 50387497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 504d382aafbSBarry Smith 505eca87e8dSBarry Smith Synopsis: 506aaa7dc30SBarry Smith #include <petscsys.h> 5071795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 508eca87e8dSBarry Smith 509eca87e8dSBarry Smith Not Collective 510eca87e8dSBarry Smith 511d8d19677SJose E. Roman Input Parameters: 512d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5131795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5141795a4d1SJed Brown 515d8d19677SJose E. Roman Output Parameters: 5161795a4d1SJed Brown + r1 - memory allocated in first chunk 5171795a4d1SJed Brown - r2 - memory allocated in second chunk 5181795a4d1SJed Brown 5191795a4d1SJed Brown Level: developer 5201795a4d1SJed Brown 521db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5221795a4d1SJed Brown M*/ 523f3fa974cSJacob Faibussowitsch #define PetscCalloc2(m1, r1, m2, r2) PetscMallocA(2, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2)) 5241795a4d1SJed Brown 5251795a4d1SJed Brown /*MC 52687497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 527d382aafbSBarry Smith 528d382aafbSBarry Smith Synopsis: 529aaa7dc30SBarry Smith #include <petscsys.h> 530dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 531d382aafbSBarry Smith 532d382aafbSBarry Smith Not Collective 533d382aafbSBarry Smith 534d8d19677SJose E. Roman Input Parameters: 535d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 536d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 537dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 538d382aafbSBarry Smith 539d8d19677SJose E. Roman Output Parameters: 540d382aafbSBarry Smith + r1 - memory allocated in first chunk 541d382aafbSBarry Smith . r2 - memory allocated in second chunk 542d382aafbSBarry Smith - r3 - memory allocated in third chunk 543d382aafbSBarry Smith 544d382aafbSBarry Smith Level: developer 545d382aafbSBarry Smith 546db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 547d382aafbSBarry Smith M*/ 548f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \ 549f3fa974cSJacob Faibussowitsch PetscMallocA(3, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3)) 550d382aafbSBarry Smith 551d382aafbSBarry Smith /*MC 55287497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 553d382aafbSBarry Smith 554eca87e8dSBarry Smith Synopsis: 555aaa7dc30SBarry Smith #include <petscsys.h> 5561795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 557eca87e8dSBarry Smith 558eca87e8dSBarry Smith Not Collective 559eca87e8dSBarry Smith 560d8d19677SJose E. Roman Input Parameters: 561d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 562d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 5631795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 5641795a4d1SJed Brown 565d8d19677SJose E. Roman Output Parameters: 5661795a4d1SJed Brown + r1 - memory allocated in first chunk 5671795a4d1SJed Brown . r2 - memory allocated in second chunk 5681795a4d1SJed Brown - r3 - memory allocated in third chunk 5691795a4d1SJed Brown 5701795a4d1SJed Brown Level: developer 5711795a4d1SJed Brown 572db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 5731795a4d1SJed Brown M*/ 574f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \ 575f3fa974cSJacob Faibussowitsch PetscMallocA(3, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3)) 5761795a4d1SJed Brown 5771795a4d1SJed Brown /*MC 57887497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 579d382aafbSBarry Smith 580d382aafbSBarry Smith Synopsis: 581aaa7dc30SBarry Smith #include <petscsys.h> 582dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 583d382aafbSBarry Smith 584d382aafbSBarry Smith Not Collective 585d382aafbSBarry Smith 586d8d19677SJose E. Roman Input Parameters: 587d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 588d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 589d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 590dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 591d382aafbSBarry Smith 592d8d19677SJose E. Roman Output Parameters: 593d382aafbSBarry Smith + r1 - memory allocated in first chunk 594d382aafbSBarry Smith . r2 - memory allocated in second chunk 595d382aafbSBarry Smith . r3 - memory allocated in third chunk 596d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 597d382aafbSBarry Smith 598d382aafbSBarry Smith Level: developer 599d382aafbSBarry Smith 600db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 601d382aafbSBarry Smith M*/ 6029371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 603f3fa974cSJacob Faibussowitsch PetscMallocA(4, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4)) 604d382aafbSBarry Smith 605d382aafbSBarry Smith /*MC 60687497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 607d382aafbSBarry Smith 608eca87e8dSBarry Smith Synopsis: 609aaa7dc30SBarry Smith #include <petscsys.h> 6101795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 611eca87e8dSBarry Smith 612eca87e8dSBarry Smith Not Collective 613eca87e8dSBarry Smith 614e28ce29aSPatrick Sanan Input Parameters: 615d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 616d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 617d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6181795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6191795a4d1SJed Brown 620e28ce29aSPatrick Sanan Output Parameters: 6211795a4d1SJed Brown + r1 - memory allocated in first chunk 6221795a4d1SJed Brown . r2 - memory allocated in second chunk 6231795a4d1SJed Brown . r3 - memory allocated in third chunk 6241795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6251795a4d1SJed Brown 6261795a4d1SJed Brown Level: developer 6271795a4d1SJed Brown 628db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6291795a4d1SJed Brown M*/ 6309371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 631f3fa974cSJacob Faibussowitsch PetscMallocA(4, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4)) 6321795a4d1SJed Brown 6331795a4d1SJed Brown /*MC 63487497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 635d382aafbSBarry Smith 636d382aafbSBarry Smith Synopsis: 637aaa7dc30SBarry Smith #include <petscsys.h> 638dcca6d9dSJed Brown PetscErrorCode PetscMalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5) 639d382aafbSBarry Smith 640d382aafbSBarry Smith Not Collective 641d382aafbSBarry Smith 642e28ce29aSPatrick Sanan Input Parameters: 643d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 644d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 645d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 646d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 647dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 648d382aafbSBarry Smith 649e28ce29aSPatrick Sanan Output Parameters: 650d382aafbSBarry Smith + r1 - memory allocated in first chunk 651d382aafbSBarry Smith . r2 - memory allocated in second chunk 652d382aafbSBarry Smith . r3 - memory allocated in third chunk 653d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 654d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 655d382aafbSBarry Smith 656d382aafbSBarry Smith Level: developer 657d382aafbSBarry Smith 658db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 659d382aafbSBarry Smith M*/ 6609371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 661f3fa974cSJacob Faibussowitsch PetscMallocA(5, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5)) 662d382aafbSBarry Smith 663d382aafbSBarry Smith /*MC 66487497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 665d382aafbSBarry Smith 666eca87e8dSBarry Smith Synopsis: 667aaa7dc30SBarry Smith #include <petscsys.h> 6681795a4d1SJed Brown PetscErrorCode PetscCalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5) 669eca87e8dSBarry Smith 670eca87e8dSBarry Smith Not Collective 671eca87e8dSBarry Smith 672e28ce29aSPatrick Sanan Input Parameters: 673d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 674d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 675d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 676d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 6771795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 6781795a4d1SJed Brown 679e28ce29aSPatrick Sanan Output Parameters: 6801795a4d1SJed Brown + r1 - memory allocated in first chunk 6811795a4d1SJed Brown . r2 - memory allocated in second chunk 6821795a4d1SJed Brown . r3 - memory allocated in third chunk 6831795a4d1SJed Brown . r4 - memory allocated in fourth chunk 6841795a4d1SJed Brown - r5 - memory allocated in fifth chunk 6851795a4d1SJed Brown 6861795a4d1SJed Brown Level: developer 6871795a4d1SJed Brown 688db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 6891795a4d1SJed Brown M*/ 6909371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 691f3fa974cSJacob Faibussowitsch PetscMallocA(5, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5)) 692d382aafbSBarry Smith 693d382aafbSBarry Smith /*MC 69487497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 695d382aafbSBarry Smith 696d382aafbSBarry Smith Synopsis: 697aaa7dc30SBarry Smith #include <petscsys.h> 698dcca6d9dSJed Brown PetscErrorCode PetscMalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6) 699d382aafbSBarry Smith 700d382aafbSBarry Smith Not Collective 701d382aafbSBarry Smith 702e28ce29aSPatrick Sanan Input Parameters: 703d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 704d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 705d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 706d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 707d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 708dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 709d382aafbSBarry Smith 710e28ce29aSPatrick Sanan Output Parameteasr: 711d382aafbSBarry Smith + r1 - memory allocated in first chunk 712d382aafbSBarry Smith . r2 - memory allocated in second chunk 713d382aafbSBarry Smith . r3 - memory allocated in third chunk 714d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 715d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 716d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 717d382aafbSBarry Smith 718d382aafbSBarry Smith Level: developer 719d382aafbSBarry Smith 720db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 721d382aafbSBarry Smith M*/ 7229371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 723f3fa974cSJacob Faibussowitsch PetscMallocA(6, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6)) 724d382aafbSBarry Smith 725d382aafbSBarry Smith /*MC 72687497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 727d382aafbSBarry Smith 728eca87e8dSBarry Smith Synopsis: 729aaa7dc30SBarry Smith #include <petscsys.h> 7301795a4d1SJed Brown PetscErrorCode PetscCalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6) 731eca87e8dSBarry Smith 732eca87e8dSBarry Smith Not Collective 733eca87e8dSBarry Smith 734e28ce29aSPatrick Sanan Input Parameters: 735d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 736d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 737d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 738d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 739d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7401795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7411795a4d1SJed Brown 742e28ce29aSPatrick Sanan Output Parameters: 7431795a4d1SJed Brown + r1 - memory allocated in first chunk 7441795a4d1SJed Brown . r2 - memory allocated in second chunk 7451795a4d1SJed Brown . r3 - memory allocated in third chunk 7461795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7471795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7481795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7491795a4d1SJed Brown 7501795a4d1SJed Brown Level: developer 7511795a4d1SJed Brown 752db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7531795a4d1SJed Brown M*/ 7549371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 755f3fa974cSJacob Faibussowitsch PetscMallocA(6, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6)) 7561795a4d1SJed Brown 7571795a4d1SJed Brown /*MC 75887497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 759d382aafbSBarry Smith 760d382aafbSBarry Smith Synopsis: 761aaa7dc30SBarry Smith #include <petscsys.h> 762dcca6d9dSJed Brown PetscErrorCode PetscMalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7) 763d382aafbSBarry Smith 764d382aafbSBarry Smith Not Collective 765d382aafbSBarry Smith 766e28ce29aSPatrick Sanan Input Parameters: 767d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 768d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 769d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 770d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 771d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 772d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 773dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 774d382aafbSBarry Smith 775e28ce29aSPatrick Sanan Output Parameters: 776d382aafbSBarry Smith + r1 - memory allocated in first chunk 777d382aafbSBarry Smith . r2 - memory allocated in second chunk 778d382aafbSBarry Smith . r3 - memory allocated in third chunk 779d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 780d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 781d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 782eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 783d382aafbSBarry Smith 784d382aafbSBarry Smith Level: developer 785d382aafbSBarry Smith 786db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 787d382aafbSBarry Smith M*/ 7889371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 789f3fa974cSJacob Faibussowitsch PetscMallocA(7, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7)) 790d382aafbSBarry Smith 791d382aafbSBarry Smith /*MC 79287497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 7931795a4d1SJed Brown 7941795a4d1SJed Brown Synopsis: 795aaa7dc30SBarry Smith #include <petscsys.h> 7961795a4d1SJed Brown PetscErrorCode PetscCalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7) 7971795a4d1SJed Brown 7981795a4d1SJed Brown Not Collective 7991795a4d1SJed Brown 800e28ce29aSPatrick Sanan Input Parameters: 8011795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8021795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8031795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8041795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8051795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8061795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8071795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8081795a4d1SJed Brown 809e28ce29aSPatrick Sanan Output Parameters: 8101795a4d1SJed Brown + r1 - memory allocated in first chunk 8111795a4d1SJed Brown . r2 - memory allocated in second chunk 8121795a4d1SJed Brown . r3 - memory allocated in third chunk 8131795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8141795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8151795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8161795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8171795a4d1SJed Brown 8181795a4d1SJed Brown Level: developer 8191795a4d1SJed Brown 820db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8211795a4d1SJed Brown M*/ 8229371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 823f3fa974cSJacob Faibussowitsch PetscMallocA(7, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7)) 8241795a4d1SJed Brown 8251795a4d1SJed Brown /*MC 82687497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 827d382aafbSBarry Smith 828eca87e8dSBarry Smith Synopsis: 829aaa7dc30SBarry Smith #include <petscsys.h> 830b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 831eca87e8dSBarry Smith 832eca87e8dSBarry Smith Not Collective 833eca87e8dSBarry Smith 834d382aafbSBarry Smith Output Parameter: 835b00a9115SJed Brown . result - memory allocated, sized to match pointer type 836d382aafbSBarry Smith 837d382aafbSBarry Smith Level: beginner 838d382aafbSBarry Smith 839fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 840d382aafbSBarry Smith M*/ 841b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 842ad0619ddSBarry Smith 8434dfa11a4SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b)) 844d382aafbSBarry Smith 845d382aafbSBarry Smith /*MC 846d382aafbSBarry Smith PetscFree - Frees memory 847d382aafbSBarry Smith 848eca87e8dSBarry Smith Synopsis: 849aaa7dc30SBarry Smith #include <petscsys.h> 850eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 851eca87e8dSBarry Smith 852eca87e8dSBarry Smith Not Collective 853eca87e8dSBarry Smith 854d382aafbSBarry Smith Input Parameter: 8557f4976b7SJacob Faibussowitsch . memory - memory to free (the pointer is ALWAYS set to NULL upon success) 856d382aafbSBarry Smith 857d382aafbSBarry Smith Level: beginner 858d382aafbSBarry Smith 85949d7da52SJed Brown Notes: 86087497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 861390e1bf2SBarry Smith 86287497f52SBarry Smith It is safe to call `PetscFree()` on a NULL pointer. 863d382aafbSBarry Smith 864fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 865d382aafbSBarry Smith M*/ 8663ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS))) 867d382aafbSBarry Smith 868d382aafbSBarry Smith /*MC 86987497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 870d382aafbSBarry Smith 871eca87e8dSBarry Smith Synopsis: 872aaa7dc30SBarry Smith #include <petscsys.h> 873eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 874eca87e8dSBarry Smith 875eca87e8dSBarry Smith Not Collective 876eca87e8dSBarry Smith 877e28ce29aSPatrick Sanan Input Parameters: 878d382aafbSBarry Smith + memory1 - memory to free 879d382aafbSBarry Smith - memory2 - 2nd memory to free 880d382aafbSBarry Smith 881d382aafbSBarry Smith Level: developer 882d382aafbSBarry Smith 88395452b02SPatrick Sanan Notes: 88487497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 885d382aafbSBarry Smith 886db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 887d382aafbSBarry Smith M*/ 888ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 889d382aafbSBarry Smith 890d382aafbSBarry Smith /*MC 89187497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 892d382aafbSBarry Smith 893eca87e8dSBarry Smith Synopsis: 894aaa7dc30SBarry Smith #include <petscsys.h> 895eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 896eca87e8dSBarry Smith 897eca87e8dSBarry Smith Not Collective 898eca87e8dSBarry Smith 899e28ce29aSPatrick Sanan Input Parameters: 900d382aafbSBarry Smith + memory1 - memory to free 901d382aafbSBarry Smith . memory2 - 2nd memory to free 902d382aafbSBarry Smith - memory3 - 3rd memory to free 903d382aafbSBarry Smith 904d382aafbSBarry Smith Level: developer 905d382aafbSBarry Smith 90695452b02SPatrick Sanan Notes: 90787497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 908d382aafbSBarry Smith 909db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 910d382aafbSBarry Smith M*/ 911ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 912d382aafbSBarry Smith 913d382aafbSBarry Smith /*MC 91487497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 915d382aafbSBarry Smith 916eca87e8dSBarry Smith Synopsis: 917aaa7dc30SBarry Smith #include <petscsys.h> 918eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 919eca87e8dSBarry Smith 920eca87e8dSBarry Smith Not Collective 921eca87e8dSBarry Smith 922e28ce29aSPatrick Sanan Input Parameters: 923d382aafbSBarry Smith + m1 - memory to free 924d382aafbSBarry Smith . m2 - 2nd memory to free 925d382aafbSBarry Smith . m3 - 3rd memory to free 926d382aafbSBarry Smith - m4 - 4th memory to free 927d382aafbSBarry Smith 928d382aafbSBarry Smith Level: developer 929d382aafbSBarry Smith 93095452b02SPatrick Sanan Notes: 93187497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 932d382aafbSBarry Smith 933db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 934d382aafbSBarry Smith M*/ 935ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 936d382aafbSBarry Smith 937d382aafbSBarry Smith /*MC 93887497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 939d382aafbSBarry Smith 940eca87e8dSBarry Smith Synopsis: 941aaa7dc30SBarry Smith #include <petscsys.h> 942eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 943eca87e8dSBarry Smith 944eca87e8dSBarry Smith Not Collective 945eca87e8dSBarry Smith 946e28ce29aSPatrick Sanan Input Parameters: 947d382aafbSBarry Smith + m1 - memory to free 948d382aafbSBarry Smith . m2 - 2nd memory to free 949d382aafbSBarry Smith . m3 - 3rd memory to free 950d382aafbSBarry Smith . m4 - 4th memory to free 951d382aafbSBarry Smith - m5 - 5th memory to free 952d382aafbSBarry Smith 953d382aafbSBarry Smith Level: developer 954d382aafbSBarry Smith 95595452b02SPatrick Sanan Notes: 95687497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 957d382aafbSBarry Smith 958db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 959d382aafbSBarry Smith M*/ 960ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 961d382aafbSBarry Smith 962d382aafbSBarry Smith /*MC 96387497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 964d382aafbSBarry Smith 965eca87e8dSBarry Smith Synopsis: 966aaa7dc30SBarry Smith #include <petscsys.h> 967eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 968eca87e8dSBarry Smith 969eca87e8dSBarry Smith Not Collective 970eca87e8dSBarry Smith 971e28ce29aSPatrick Sanan Input Parameters: 972d382aafbSBarry Smith + m1 - memory to free 973d382aafbSBarry Smith . m2 - 2nd memory to free 974d382aafbSBarry Smith . m3 - 3rd memory to free 975d382aafbSBarry Smith . m4 - 4th memory to free 976d382aafbSBarry Smith . m5 - 5th memory to free 977d382aafbSBarry Smith - m6 - 6th memory to free 978d382aafbSBarry Smith 979d382aafbSBarry Smith Level: developer 980d382aafbSBarry Smith 98195452b02SPatrick Sanan Notes: 98287497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 983d382aafbSBarry Smith 984db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 985d382aafbSBarry Smith M*/ 986ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 987d382aafbSBarry Smith 988d382aafbSBarry Smith /*MC 98987497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 990d382aafbSBarry Smith 991eca87e8dSBarry Smith Synopsis: 992aaa7dc30SBarry Smith #include <petscsys.h> 993eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 994eca87e8dSBarry Smith 995eca87e8dSBarry Smith Not Collective 996eca87e8dSBarry Smith 997e28ce29aSPatrick Sanan Input Parameters: 998d382aafbSBarry Smith + m1 - memory to free 999d382aafbSBarry Smith . m2 - 2nd memory to free 1000d382aafbSBarry Smith . m3 - 3rd memory to free 1001d382aafbSBarry Smith . m4 - 4th memory to free 1002d382aafbSBarry Smith . m5 - 5th memory to free 1003d382aafbSBarry Smith . m6 - 6th memory to free 1004d382aafbSBarry Smith - m7 - 7th memory to free 1005d382aafbSBarry Smith 1006d382aafbSBarry Smith Level: developer 1007d382aafbSBarry Smith 100895452b02SPatrick Sanan Notes: 100987497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1010d382aafbSBarry Smith 1011db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1012db781477SPatrick Sanan `PetscMalloc7()` 1013d382aafbSBarry Smith M*/ 1014ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1015d382aafbSBarry Smith 1016ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1017ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1018071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1019efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 10203221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1021ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 102292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSet(PetscErrorCode (*)(size_t, PetscBool, int, const char[], const char[], void **), PetscErrorCode (*)(void *, int, const char[], const char[]), PetscErrorCode (*)(size_t, int, const char[], const char[], void **)); 1023014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1024d382aafbSBarry Smith 1025d382aafbSBarry Smith /* 1026c1706be6SHong Zhang Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair. 1027c1706be6SHong Zhang */ 1028c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1029c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 103031f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 103131f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 103231f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 103331f06eaaSHong Zhang #endif 103459af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 103559af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 103659af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 103759af0bd3SScott Kruger #endif 103859af0bd3SScott Kruger 1039a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 104036763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1041a5057860SBarry Smith 1042a5057860SBarry Smith /* 104366d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1044d382aafbSBarry Smith */ 1045014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 104692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1047014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1048014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1049e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1050e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 105192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 105292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1053efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 105492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 105592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1056608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1057608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1058d382aafbSBarry Smith 1059014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1060014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1061014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 10628e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1063d382aafbSBarry Smith 1064d382aafbSBarry Smith /* 1065d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1066d382aafbSBarry Smith */ 1067367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1068570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1069de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1070014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1071014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1072d9822059SBarry Smith #else 1073de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1074d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1075d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1076d9822059SBarry Smith #endif 107762e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 107862e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 107962e5d2d2SJDBetteridge 1080a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16)) 1081613bf2b2SPierre Jolivet /*MC 10829e517322SPierre Jolivet MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with 10839e517322SPierre Jolivet custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1084613bf2b2SPierre Jolivet 1085613bf2b2SPierre Jolivet Level: advanced 1086613bf2b2SPierre Jolivet 1087613bf2b2SPierre Jolivet Developer Note: 1088613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1089613bf2b2SPierre Jolivet 1090613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1091613bf2b2SPierre Jolivet M*/ 10929e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1093613bf2b2SPierre Jolivet #endif 1094014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1095d382aafbSBarry Smith 109693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 109793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1098eb3f98d2SBarry Smith 1099639ff905SBarry Smith /* 1100639ff905SBarry Smith Defines PETSc error handling. 1101639ff905SBarry Smith */ 1102639ff905SBarry Smith #include <petscerror.h> 1103d382aafbSBarry Smith 1104660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1105660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1106660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1107660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1108660278c0SBarry Smith 1109f3fa974cSJacob Faibussowitsch #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211) 1110014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1111014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 111381256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 111481256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 111581256985SMatthew G. Knepley 1116d382aafbSBarry Smith /* 1117d382aafbSBarry Smith Routines that get memory usage information from the OS 1118d382aafbSBarry Smith */ 1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1122b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1123d382aafbSBarry Smith 1124014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1125d382aafbSBarry Smith 1126d382aafbSBarry Smith /* 1127d382aafbSBarry Smith Initialization of PETSc 1128d382aafbSBarry Smith */ 1129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1133014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1135014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1137014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1138014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1139d382aafbSBarry Smith 1140014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1141607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1142d382aafbSBarry Smith 1143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1145014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1147d382aafbSBarry Smith 1148a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1149a50e088cSMatthew G. Knepley 1150d382aafbSBarry Smith /* 1151d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 11522981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1153d382aafbSBarry Smith */ 1154638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void); 1155638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void); 1156638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1157d382aafbSBarry Smith 1158d382aafbSBarry Smith /* 1159d382aafbSBarry Smith Functions that can act on any PETSc object. 1160d382aafbSBarry Smith */ 1161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1163014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1164014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1169014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1170014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1173014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1174014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1175014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1176014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1177014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1178bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 1179f3fa974cSJacob Faibussowitsch #define PetscObjectComposeFunction(a, b, d) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFunction)(d)) 1180014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1181014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 11820eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 11830eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1184014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1185d382aafbSBarry Smith 1186665c2dedSJed Brown #include <petscviewertypes.h> 1187639ff905SBarry Smith #include <petscoptions.h> 1188639ff905SBarry Smith 1189608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1190608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1191608c71bfSMatthew G. Knepley 11920633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 11930633abcbSJed Brown 1194c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1195dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1196639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 11970005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr)) 11980005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1199014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1201014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1202014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1203014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1206685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1209013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 12104099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1212b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1213014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1214014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1215d382aafbSBarry Smith 1216e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 12177aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1218e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1219e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1220e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1221e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1222e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1223e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1224e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1225e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1226e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 122715681b3cSBarry Smith 1228ec7429eaSBarry Smith #else 12293ba16761SJacob Faibussowitsch #define PetscSAWsBlock() PETSC_SUCCESS 12303ba16761SJacob Faibussowitsch #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS 12313ba16761SJacob Faibussowitsch #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS 12323ba16761SJacob Faibussowitsch #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS 12333ba16761SJacob Faibussowitsch #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS 12343ba16761SJacob Faibussowitsch #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS 12353ba16761SJacob Faibussowitsch #define PetscStackViewSAWs() PETSC_SUCCESS 12363ba16761SJacob Faibussowitsch #define PetscStackSAWsViewOff() PETSC_SUCCESS 1237e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1238e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 123915681b3cSBarry Smith 1240ec7429eaSBarry Smith #endif 1241b90c6cbeSBarry Smith 124282b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 124382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 124482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1245258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1246258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1247258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1248258ec3d2SMatthew G. Knepley #endif 12497d5d4d99SBarry Smith 1250a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1251a64a8e02SBarry Smith 1252dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 1253140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1254140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1255140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1256140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1257140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1258140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1259d382aafbSBarry Smith 1260d382aafbSBarry Smith /* 1261503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1262d382aafbSBarry Smith link libraries that will be loaded as needed. 1263d382aafbSBarry Smith */ 1264a240a19fSJed Brown 1265a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr)) 1266ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFunction); 1267140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 12680e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 12691c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr)) 1270ed170139SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFunction *); 127144ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1272140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1273140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1274140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 12752e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 12762e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1277d382aafbSBarry Smith 1278014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1279014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1280014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1282014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1283014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1286d382aafbSBarry Smith 1287d382aafbSBarry Smith /* 1288d382aafbSBarry Smith Useful utility routines 1289d382aafbSBarry Smith */ 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1292d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 129758b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 129858b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1299d382aafbSBarry Smith 130064ac3b0dSPatrick Sanan /*MC 130187497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1302503cfb0cSBarry Smith 130364ac3b0dSPatrick Sanan Level: beginner 130464ac3b0dSPatrick Sanan 1305a1cb98faSBarry Smith Note: 1306a1cb98faSBarry Smith This is useful in cases like 1307a1cb98faSBarry Smith .vb 1308a1cb98faSBarry Smith int *a; 1309a1cb98faSBarry Smith PetscBool flag = PetscNot(a) 1310a1cb98faSBarry Smith .ve 1311a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1312a1cb98faSBarry Smith 1313a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 131464ac3b0dSPatrick Sanan M*/ 1315d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1316503cfb0cSBarry Smith 1317d382aafbSBarry Smith /*MC 1318d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1319d382aafbSBarry Smith 1320cd05f99aSJacob Faibussowitsch Not Collective, only applies on rank 0; No Fortran Support 1321cf53795eSBarry Smith 1322d382aafbSBarry Smith Synopsis: 1323aaa7dc30SBarry Smith #include <petscsys.h> 1324659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1325d382aafbSBarry Smith 1326d382aafbSBarry Smith Input Parameters: 1327659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1328d382aafbSBarry Smith . format - the usual printf() format string 1329659f7ba0SBarry Smith - args - arguments to be printed 1330d382aafbSBarry Smith 1331d382aafbSBarry Smith Level: developer 1332d382aafbSBarry Smith 1333659f7ba0SBarry Smith Note: 1334659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1335659f7ba0SBarry Smith 1336659f7ba0SBarry Smith To use, write your own function, for example, 1337659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1338659f7ba0SBarry Smith ${ 13393ba16761SJacob Faibussowitsch $ PetscFunctionReturn(PETSC_SUCCESS); 1340659f7ba0SBarry Smith $} 1341d5b43468SJose E. Roman then do the assignment 1342659f7ba0SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 134387497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1344659f7ba0SBarry Smith 134587497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1346d382aafbSBarry Smith 1347db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()` 1348d382aafbSBarry Smith M*/ 13493ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1350d382aafbSBarry Smith 1351fcfd50ebSBarry Smith /* 1352fcfd50ebSBarry Smith Defines PETSc profiling. 1353fcfd50ebSBarry Smith */ 13542c8e378dSBarry Smith #include <petsclog.h> 1355fcfd50ebSBarry Smith 1356fcfd50ebSBarry Smith /* 1357fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1358fcfd50ebSBarry Smith */ 1359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1360014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 13623ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 13633ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 13643ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 13653ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 13661b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1367fcfd50ebSBarry Smith 13683ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 13693ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 13703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1371d382aafbSBarry Smith 1372d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1373d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1374d781fa04SBarry Smith 1375d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1377016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 137874ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1379d382aafbSBarry Smith #endif 1380d382aafbSBarry Smith 13813ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 13823ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 13830ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **); 1387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1388d382aafbSBarry Smith 1389014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1395b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1396d382aafbSBarry Smith 1397d382aafbSBarry Smith /* 1398d382aafbSBarry Smith For use in debuggers 1399d382aafbSBarry Smith */ 1400014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1401014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1402014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1403014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1404014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1405d382aafbSBarry Smith 1406bbcf679cSJacob Faibussowitsch /* 1407bbcf679cSJacob Faibussowitsch Basic memory and string operations. These are usually simple wrappers 1408bbcf679cSJacob Faibussowitsch around the basic Unix system calls, but a few of them have additional 1409bbcf679cSJacob Faibussowitsch functionality and/or error checking. 1410bbcf679cSJacob Faibussowitsch */ 1411bbcf679cSJacob Faibussowitsch #include <petscstring.h> 1412bbcf679cSJacob Faibussowitsch 1413a663daf8SBarry Smith #include <stddef.h> 1414d382aafbSBarry Smith #include <stdlib.h> 14156c7e564aSBarry Smith 14164a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1417d382aafbSBarry Smith #include <xmmintrin.h> 1418d382aafbSBarry Smith #endif 1419d382aafbSBarry Smith 1420447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER) 1421447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d) 1422447bcd8fSJacob Faibussowitsch #else 1423d382aafbSBarry Smith /*MC 1424d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1425d382aafbSBarry Smith 1426eca87e8dSBarry Smith Synopsis: 1427aaa7dc30SBarry Smith #include <petscsys.h> 1428eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1429eca87e8dSBarry Smith 1430d382aafbSBarry Smith Not Collective 1431d382aafbSBarry Smith 1432d382aafbSBarry Smith Input Parameters: 1433d382aafbSBarry Smith + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 1434d382aafbSBarry Smith . n - number of elements to fetch 1435d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 143650d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1437d382aafbSBarry Smith 1438d382aafbSBarry Smith Level: developer 1439d382aafbSBarry Smith 1440d382aafbSBarry Smith Notes: 1441d382aafbSBarry Smith The last two arguments (rw and t) must be compile-time constants. 1442d382aafbSBarry Smith 144350d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 144450d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 144587497f52SBarry Smith + `PETSC_PREFETCH_HINT_NTA` - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 144687497f52SBarry Smith . `PETSC_PREFETCH_HINT_T0` - Fetch to all levels of cache and evict to the closest level. Use this when the memory will be reused regularly despite necessary eviction from L1. 144787497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 144887497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1449d382aafbSBarry Smith 1450d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1451d382aafbSBarry Smith address). 1452d382aafbSBarry Smith 1453d382aafbSBarry Smith M*/ 14549371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 14559371c9d4SSatish Balay do { \ 1456d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1457d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1458d382aafbSBarry Smith } while (0) 1459447bcd8fSJacob Faibussowitsch #endif 1460d382aafbSBarry Smith /* 1461d382aafbSBarry Smith Determine if some of the kernel computation routines use 1462d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1463d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1464d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1465e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1466d382aafbSBarry Smith */ 1467d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1468d382aafbSBarry Smith 1469d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1470d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1471d382aafbSBarry Smith #endif 1472d382aafbSBarry Smith 14735a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 14745a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1475d382aafbSBarry Smith #endif 1476d382aafbSBarry Smith 1477d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1478d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1479d382aafbSBarry Smith #endif 1480d382aafbSBarry Smith 1481d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1482d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1483d382aafbSBarry Smith #endif 1484d382aafbSBarry Smith 1485d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1486d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM 1487d382aafbSBarry Smith #endif 1488d382aafbSBarry Smith 1489d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1490d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1491d382aafbSBarry Smith #endif 1492d382aafbSBarry Smith 1493d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1494d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1495d382aafbSBarry Smith #endif 1496d382aafbSBarry Smith 1497d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1498d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1499d382aafbSBarry Smith #endif 1500d382aafbSBarry Smith 1501d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1502d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1503d382aafbSBarry Smith #endif 1504d382aafbSBarry Smith 1505d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1506d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1507d382aafbSBarry Smith #endif 1508d382aafbSBarry Smith 1509d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1510d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1511d382aafbSBarry Smith #endif 1512d382aafbSBarry Smith 1513d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1514d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1515d382aafbSBarry Smith #endif 1516d382aafbSBarry Smith 1517d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1518d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1519d382aafbSBarry Smith #endif 1520d382aafbSBarry Smith 1521d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1522d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1523d382aafbSBarry Smith #endif 1524d382aafbSBarry Smith 1525d382aafbSBarry Smith #endif 1526d382aafbSBarry Smith 1527d382aafbSBarry Smith /* 1528d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1529d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1530d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1531d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1532d382aafbSBarry Smith ugly extern "C" {} wrappers. 1533d382aafbSBarry Smith */ 1534d382aafbSBarry Smith #if defined(__cplusplus) 1535d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1536d382aafbSBarry Smith #define EXTERN_C_END } 1537d382aafbSBarry Smith #else 1538d382aafbSBarry Smith #define EXTERN_C_BEGIN 1539d382aafbSBarry Smith #define EXTERN_C_END 1540d382aafbSBarry Smith #endif 1541d382aafbSBarry Smith 1542d382aafbSBarry Smith /* --------------------------------------------------------------------*/ 1543d382aafbSBarry Smith 1544d382aafbSBarry Smith /*MC 1545d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1546d382aafbSBarry Smith communication 1547d382aafbSBarry Smith 1548d382aafbSBarry Smith Level: beginner 1549d382aafbSBarry Smith 1550d382aafbSBarry Smith Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1551d382aafbSBarry Smith 1552db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1553d382aafbSBarry Smith M*/ 1554d382aafbSBarry Smith 1555d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 155693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 155793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 155893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 155993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 156093d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 156193d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 1562d382aafbSBarry Smith #endif 1563d382aafbSBarry Smith 156461b0d812SBarry Smith /*@C 156587497f52SBarry Smith PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an 156687497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1567c73702f5SBarry Smith 1568c73702f5SBarry Smith Not Collective 1569c73702f5SBarry Smith 1570c73702f5SBarry Smith Input Parameter: 157187497f52SBarry Smith . a - the `PetscInt64` value 1572c73702f5SBarry Smith 1573c73702f5SBarry Smith Output Parameter: 157487497f52SBarry Smith . b - the resulting `PetscInt` value 1575c73702f5SBarry Smith 1576c73702f5SBarry Smith Level: advanced 1577c73702f5SBarry Smith 157887497f52SBarry Smith Notes: 157987497f52SBarry Smith If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make `PetscInt` use 64 bit ints 1580c73702f5SBarry Smith 1581c73702f5SBarry Smith Not available from Fortran 1582c73702f5SBarry Smith 1583db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1584c73702f5SBarry Smith @*/ 1585d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1586d71ae5a4SJacob Faibussowitsch { 1587c73702f5SBarry Smith PetscFunctionBegin; 15883ca90d2dSJacob Faibussowitsch *b = 0; 1589f3fa974cSJacob Faibussowitsch // if using 64-bit indices already then this comparison is tautologically true 1590f3fa974cSJacob Faibussowitsch PetscCheck(a < PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 1591f3fa974cSJacob Faibussowitsch *b = (PetscInt)a; 15923ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1593c73702f5SBarry Smith } 1594c73702f5SBarry Smith 1595c73702f5SBarry Smith /*@C 159687497f52SBarry Smith PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an 159787497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1598981bb840SJunchao Zhang 1599*667f096bSBarry Smith Not Collective; No Fortran Support 1600981bb840SJunchao Zhang 1601981bb840SJunchao Zhang Input Parameter: 160287497f52SBarry Smith . a - the `PetscCount` value 1603981bb840SJunchao Zhang 1604981bb840SJunchao Zhang Output Parameter: 160587497f52SBarry Smith . b - the resulting `PetscInt` value 1606981bb840SJunchao Zhang 1607981bb840SJunchao Zhang Level: advanced 1608981bb840SJunchao Zhang 1609*667f096bSBarry Smith Note: 1610*667f096bSBarry Smith If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make `PetscInt` use 64 bit ints 1611981bb840SJunchao Zhang 1612*667f096bSBarry Smith .seealso: `PetscCount`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1613981bb840SJunchao Zhang @*/ 1614d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 1615d71ae5a4SJacob Faibussowitsch { 1616981bb840SJunchao Zhang PetscFunctionBegin; 1617981bb840SJunchao Zhang *b = 0; 1618f3fa974cSJacob Faibussowitsch PetscCheck(sizeof(PetscCount) <= sizeof(PetscInt) || a <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 1619f3fa974cSJacob Faibussowitsch *b = (PetscInt)a; 16203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1621981bb840SJunchao Zhang } 1622981bb840SJunchao Zhang 1623981bb840SJunchao Zhang /*@C 162487497f52SBarry Smith PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an 162587497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 162661b0d812SBarry Smith 1627*667f096bSBarry Smith Not Collective; No Fortran Support 162861b0d812SBarry Smith 162961b0d812SBarry Smith Input Parameter: 163087497f52SBarry Smith . a - the `PetscInt` value 163161b0d812SBarry Smith 163261b0d812SBarry Smith Output Parameter: 163387497f52SBarry Smith . b - the resulting `PetscBLASInt` value 163461b0d812SBarry Smith 163561b0d812SBarry Smith Level: advanced 163661b0d812SBarry Smith 1637*667f096bSBarry Smith Note: 1638f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 16391fd49c25SBarry Smith 1640db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 164161b0d812SBarry Smith @*/ 1642d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 1643d71ae5a4SJacob Faibussowitsch { 1644c5df96a5SBarry Smith PetscFunctionBegin; 164554c59aa7SJacob Faibussowitsch *b = 0; 164654c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 164754c59aa7SJacob Faibussowitsch PetscCheck(a <= PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for BLAS/LAPACK, which is restricted to 32 bit integers. Either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-blas-indices for the case you are running", a); 164854c59aa7SJacob Faibussowitsch } 164954c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 1650f3fa974cSJacob Faibussowitsch *b = (PetscBLASInt)a; 16513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1652c5df96a5SBarry Smith } 1653c5df96a5SBarry Smith 165461b0d812SBarry Smith /*@C 165587497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 1656eee0c0a6SToby Isaac 1657*667f096bSBarry Smith Not Collective; No Fortran Support 1658eee0c0a6SToby Isaac 1659eee0c0a6SToby Isaac Input Parameter: 166087497f52SBarry Smith . a - the `PetscInt` value 1661eee0c0a6SToby Isaac 1662eee0c0a6SToby Isaac Output Parameter: 166387497f52SBarry Smith . b - the resulting `PetscCuBLASInt` value 1664eee0c0a6SToby Isaac 1665eee0c0a6SToby Isaac Level: advanced 1666eee0c0a6SToby Isaac 1667*667f096bSBarry Smith Note: 1668eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 1669eee0c0a6SToby Isaac 1670db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 1671eee0c0a6SToby Isaac @*/ 1672d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 1673d71ae5a4SJacob Faibussowitsch { 1674eee0c0a6SToby Isaac PetscFunctionBegin; 167554c59aa7SJacob Faibussowitsch *b = 0; 1676f3fa974cSJacob Faibussowitsch PetscCheck(a <= PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32 bit integers.", a); 1677f3fa974cSJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to cuBLAS routine", a); 1678f3fa974cSJacob Faibussowitsch *b = (PetscCuBLASInt)a; 16793ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1680eee0c0a6SToby Isaac } 1681eee0c0a6SToby Isaac 1682eee0c0a6SToby Isaac /*@C 168347d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 168447d993e7Ssuyashtn 1685*667f096bSBarry Smith Not Collective; No Fortran Support 168647d993e7Ssuyashtn 168747d993e7Ssuyashtn Input Parameter: 168847d993e7Ssuyashtn . a - the `PetscInt` value 168947d993e7Ssuyashtn 169047d993e7Ssuyashtn Output Parameter: 169147d993e7Ssuyashtn . b - the resulting `PetscHipBLASInt` value 169247d993e7Ssuyashtn 169347d993e7Ssuyashtn Level: advanced 169447d993e7Ssuyashtn 1695*667f096bSBarry Smith Note: 169647d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 169747d993e7Ssuyashtn 169847d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 169947d993e7Ssuyashtn @*/ 170047d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b) 170147d993e7Ssuyashtn { 170247d993e7Ssuyashtn PetscFunctionBegin; 170347d993e7Ssuyashtn *b = 0; 1704f3fa974cSJacob Faibussowitsch PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32 bit integers.", a); 1705f3fa974cSJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to hipBLAS routine", a); 1706f3fa974cSJacob Faibussowitsch *b = (PetscHipBLASInt)a; 17073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 170847d993e7Ssuyashtn } 170947d993e7Ssuyashtn 171047d993e7Ssuyashtn /*@C 1711*667f096bSBarry Smith PetscMPIIntCast - casts a `PetscInt` (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an 1712*667f096bSBarry Smith error if the `PetscMPIInt` is not large enough to hold the number. 171361b0d812SBarry Smith 1714*667f096bSBarry Smith Not Collective; No Fortran Support 171561b0d812SBarry Smith 171661b0d812SBarry Smith Input Parameter: 171787497f52SBarry Smith . a - the `PetscInt` value 171861b0d812SBarry Smith 171961b0d812SBarry Smith Output Parameter: 172087497f52SBarry Smith . b - the resulting `PetscMPIInt` value 172161b0d812SBarry Smith 172261b0d812SBarry Smith Level: advanced 172361b0d812SBarry Smith 1724db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 172561b0d812SBarry Smith @*/ 1726d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 1727d71ae5a4SJacob Faibussowitsch { 17284dc2109aSBarry Smith PetscFunctionBegin; 172954c59aa7SJacob Faibussowitsch *b = 0; 1730f3fa974cSJacob Faibussowitsch PetscCheck(a <= PETSC_MPI_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for MPI buffer length. Maximum supported value is %d", a, PETSC_MPI_INT_MAX); 1731f3fa974cSJacob Faibussowitsch *b = (PetscMPIInt)a; 17323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 17334dc2109aSBarry Smith } 17344dc2109aSBarry Smith 1735f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b))) 17362f18eb33SBarry Smith 17372f18eb33SBarry Smith /*@C 1738f3fa974cSJacob Faibussowitsch PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive 1739f3fa974cSJacob Faibussowitsch `PetscInt` and truncates the value to slightly less than the maximal possible value. 17402f18eb33SBarry Smith 1741f3fa974cSJacob Faibussowitsch Not Collective, Not available from Fortran 17422f18eb33SBarry Smith 1743d8d19677SJose E. Roman Input Parameters: 1744f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value 1745f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value 17462f18eb33SBarry Smith 1747*667f096bSBarry Smith Level: advanced 1748*667f096bSBarry Smith 1749f3fa974cSJacob Faibussowitsch Notes: 1750f3fa974cSJacob Faibussowitsch Returns the result as a `PetscInt` value. 17512f18eb33SBarry Smith 1752f3fa974cSJacob Faibussowitsch Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`. 1753*667f096bSBarry Smith 1754f3fa974cSJacob Faibussowitsch Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate 1755f3fa974cSJacob Faibussowitsch to fit a `PetscInt`. 1756*667f096bSBarry Smith 1757f3fa974cSJacob Faibussowitsch Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an 1758f3fa974cSJacob Faibussowitsch error if the result will not fit in a `PetscInt`. 17592f18eb33SBarry Smith 1760*667f096bSBarry Smith Developers Notes: 1761f3fa974cSJacob Faibussowitsch We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but 1762f3fa974cSJacob Faibussowitsch requires many more checks. 17632f18eb33SBarry Smith 1764f3fa974cSJacob Faibussowitsch This is used where we compute approximate sizes for workspace and need to insure the 1765f3fa974cSJacob Faibussowitsch workspace is index-able. 17661fd49c25SBarry Smith 1767f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 17682f18eb33SBarry Smith @*/ 1769d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 1770d71ae5a4SJacob Faibussowitsch { 17715f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 17722f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 17732f18eb33SBarry Smith return (PetscInt)r; 17742f18eb33SBarry Smith } 17752f18eb33SBarry Smith 17762f18eb33SBarry Smith /*@C 17772f18eb33SBarry Smith 177887497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 17792f18eb33SBarry Smith 1780*667f096bSBarry Smith Not Collective; No Fortran Support 17812f18eb33SBarry Smith 1782d8d19677SJose E. Roman Input Parameters: 17832f18eb33SBarry Smith + a - the PetscInt value 17842f18eb33SBarry Smith - b - the second value 17852f18eb33SBarry Smith 1786390e1bf2SBarry Smith Returns: 178787497f52SBarry Smith the result as a `PetscInt` value 17882f18eb33SBarry Smith 1789*667f096bSBarry Smith Level: advanced 1790*667f096bSBarry Smith 1791*667f096bSBarry Smith Notes: 179287497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1793*667f096bSBarry Smith 179487497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1795*667f096bSBarry Smith 179687497f52SBarry Smith Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an error if the result will not fit in a `PetscInt` 17972f18eb33SBarry Smith 1798*667f096bSBarry Smith Developers Notes: 179987497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 18002f18eb33SBarry Smith 18012f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 18022f18eb33SBarry Smith 1803*667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`, 1804*667f096bSBarry Smith `PetscIntSumTruncate()` 18052f18eb33SBarry Smith @*/ 1806d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 1807d71ae5a4SJacob Faibussowitsch { 18085f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 18092f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 18102f18eb33SBarry Smith return (PetscInt)r; 18112f18eb33SBarry Smith } 18122f18eb33SBarry Smith 1813f91af8c7SBarry Smith /*@C 1814f91af8c7SBarry Smith 181587497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 1816f91af8c7SBarry Smith 1817*667f096bSBarry Smith Not Collective; No Fortran Support 1818f91af8c7SBarry Smith 1819d8d19677SJose E. Roman Input Parameters: 182087497f52SBarry Smith + a - the `PetscInt` value 1821f91af8c7SBarry Smith - b - the second value 1822f91af8c7SBarry Smith 1823390e1bf2SBarry Smith Returns: 182487497f52SBarry Smith the result as a `PetscInt` value 1825f91af8c7SBarry Smith 1826*667f096bSBarry Smith Level: advanced 1827*667f096bSBarry Smith 1828*667f096bSBarry Smith Notes: 182987497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1830*667f096bSBarry Smith 183187497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1832*667f096bSBarry Smith 183387497f52SBarry Smith Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an error if the result will not fit in a `PetscInt` 1834f91af8c7SBarry Smith 1835*667f096bSBarry Smith Developers Notes: 1836f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 1837f91af8c7SBarry Smith 1838db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1839f91af8c7SBarry Smith @*/ 1840d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 1841d71ae5a4SJacob Faibussowitsch { 18425f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1843f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 1844f91af8c7SBarry Smith return (PetscInt)r; 1845f91af8c7SBarry Smith } 1846f91af8c7SBarry Smith 18472f18eb33SBarry Smith /*@C 18482f18eb33SBarry Smith 184987497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 18502f18eb33SBarry Smith 1851*667f096bSBarry Smith Not Collective; No Fortran Support 18522f18eb33SBarry Smith 1853d8d19677SJose E. Roman Input Parameters: 185487497f52SBarry Smith + a - the `PetscInt` value 18552f18eb33SBarry Smith - b - the second value 18562f18eb33SBarry Smith 1857d8d19677SJose E. Roman Output Parameter: 185887497f52SBarry Smith . result - the result as a `PetscInt` value, or NULL if you do not want the result, you just want to check if it overflows 18592f18eb33SBarry Smith 1860*667f096bSBarry Smith Level: advanced 18612f18eb33SBarry Smith 1862*667f096bSBarry Smith Notes: 1863*667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 1864*667f096bSBarry Smith 1865*667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1866f5f57ec0SBarry Smith 186787497f52SBarry Smith Developers Note: 186887497f52SBarry Smith We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks. 18692f18eb33SBarry Smith 1870db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 18712f18eb33SBarry Smith @*/ 1872d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 1873d71ae5a4SJacob Faibussowitsch { 1874f3fa974cSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 18752f18eb33SBarry Smith 18762f18eb33SBarry Smith PetscFunctionBegin; 1877f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 1878f3fa974cSJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 1879f3fa974cSJacob Faibussowitsch } 1880f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 18813ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1882f91af8c7SBarry Smith } 1883f91af8c7SBarry Smith 1884f91af8c7SBarry Smith /*@C 1885f91af8c7SBarry Smith 188687497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 1887f91af8c7SBarry Smith 1888*667f096bSBarry Smith Not Collective; No Fortran Support 1889f91af8c7SBarry Smith 1890d8d19677SJose E. Roman Input Parameters: 189187497f52SBarry Smith + a - the `PetscInt` value 1892f91af8c7SBarry Smith - b - the second value 1893f91af8c7SBarry Smith 1894d8d19677SJose E. Roman Output Parameter: 189587497f52SBarry Smith . c - the result as a `PetscInt` value, or NULL if you do not want the result, you just want to check if it overflows 1896f91af8c7SBarry Smith 1897f91af8c7SBarry Smith Level: advanced 1898f91af8c7SBarry Smith 1899*667f096bSBarry Smith Notes: 1900*667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64` 1901*667f096bSBarry Smith 1902*667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1903*667f096bSBarry Smith 1904db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1905f91af8c7SBarry Smith @*/ 1906d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 1907d71ae5a4SJacob Faibussowitsch { 1908f3fa974cSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1909f91af8c7SBarry Smith 1910f91af8c7SBarry Smith PetscFunctionBegin; 1911f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 1912f3fa974cSJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 1913f3fa974cSJacob Faibussowitsch } 1914f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 19153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19162f18eb33SBarry Smith } 1917c5df96a5SBarry Smith 1918d382aafbSBarry Smith /* 19192981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 1920d382aafbSBarry Smith */ 1921d382aafbSBarry Smith #if defined(hz) 1922d382aafbSBarry Smith #undef hz 1923d382aafbSBarry Smith #endif 1924d382aafbSBarry Smith 192515a5570dSLisandro Dalcin #include <limits.h> 192615a5570dSLisandro Dalcin 192715a5570dSLisandro Dalcin /* The number of bits in a byte */ 192815a5570dSLisandro Dalcin 192915a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT 193015a5570dSLisandro Dalcin 1931d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 1932d382aafbSBarry Smith #include <sys/types.h> 1933d382aafbSBarry Smith #endif 1934d382aafbSBarry Smith 1935d382aafbSBarry Smith /*MC 1936d382aafbSBarry Smith 193766d79e26SBarry Smith PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++ 193866d79e26SBarry Smith and Fortran compilers when petscsys.h is included. 193966d79e26SBarry Smith 19406274ba02SSatish Balay The current PETSc version and the API for accessing it are defined in <A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscversion.h.html">include/petscverson.html</A> 194166d79e26SBarry Smith 194266d79e26SBarry Smith The complete version number is given as the triple PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z) 194366d79e26SBarry Smith 194466d79e26SBarry Smith A change in the minor version number (y) indicates possible/likely changes in the PETSc API. Note this is different than with the semantic versioning convention 194566d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 194666d79e26SBarry Smith 194766d79e26SBarry Smith A subminor greater than zero indicates a patch release. Version x.y.z maintains source and binary compatibility with version x.y.w for all z and w 194866d79e26SBarry Smith 194966d79e26SBarry Smith Use the macros PETSC_VERSION_EQ(x,y,z), PETSC_VERSION_LT(x,y,z), PETSC_VERSION_LE(x,y,z), PETSC_VERSION_GT(x,y,z), 195066d79e26SBarry Smith PETSC_VERSION_GE(x,y,z) to determine if the current version is equal to, less than, less than or equal to, greater than or greater than or equal to a given 195166d79e26SBarry Smith version number (x.y.z). 195266d79e26SBarry Smith 195387497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 195466d79e26SBarry Smith 195587497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 195666d79e26SBarry Smith 195787497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 195866d79e26SBarry Smith 195987497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 196066d79e26SBarry Smith 196187497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 196266d79e26SBarry Smith 1963cbc12506SBarry Smith Level: intermediate 196466d79e26SBarry Smith M*/ 196566d79e26SBarry Smith 1966014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 1967014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 1968014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 1969014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 1970014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 1971014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 197227710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 19735f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 1974d382aafbSBarry Smith 19756a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 197662e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 19776a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 19786a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 1979014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 198062e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 198162e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 1982ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 198322ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 1984b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 1985014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 1986f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 198760e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 1988d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 1989014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 1990014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 1991014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 1992981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 19936c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 1994981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 199517d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 199617d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 1997014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 19985569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 1999014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 200017df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2001014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 200239f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2003014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2004745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 200539f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2006014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2007014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2008014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 20096c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 20106c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2011e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2012ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2013ce605777SToby Isaac 20144d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2015676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2016676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2017676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 20184d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2019676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2020676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2021676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2022676f2a66SJacob Faibussowitsch 2023014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2024014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2025d382aafbSBarry Smith 202676bdecfbSBarry Smith /*J 2027d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2028d382aafbSBarry Smith 2029d382aafbSBarry Smith Level: beginner 2030d382aafbSBarry Smith 2031*667f096bSBarry Smith Note: 203287497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 203325ccb61fSToby Isaac with the option --download-sprng or --download-random123 2034d382aafbSBarry Smith 2035db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 203676bdecfbSBarry Smith J*/ 203719fd82e9SBarry Smith typedef const char *PetscRandomType; 2038d382aafbSBarry Smith #define PETSCRAND "rand" 2039d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2040d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2041c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 204225ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2043808ba619SStefano Zampini #define PETSCCURAND "curand" 2044d382aafbSBarry Smith 2045d382aafbSBarry Smith /* Logging support */ 2046014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2047d382aafbSBarry Smith 2048607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2049d382aafbSBarry Smith 2050d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2051140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2052d382aafbSBarry Smith 2053bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 205419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2055014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 205619fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2057fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2058014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2059d382aafbSBarry Smith 2060014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2061014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2062014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2063808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2064808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2065014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2066014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2067014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2068014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2069014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2070014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2071d382aafbSBarry Smith 2072014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2073014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2074014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2075014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2076014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2077014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2078014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 207997540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 20808a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 208197540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2082d382aafbSBarry Smith 2083d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2084d71ae5a4SJacob Faibussowitsch { 20859371c9d4SSatish Balay long _petsc_v = 1; 20869371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 20879371c9d4SSatish Balay } 208830815ce0SLisandro Dalcin 20899860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 20909860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2091f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2092f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2093014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2094014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2095014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2096014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2097014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2098014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2100c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2101e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2102c891a504SStefano Zampini #endif 2103d382aafbSBarry Smith 2104014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2105014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2106014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2107d382aafbSBarry Smith 2108014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2109014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 21142a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2115d382aafbSBarry Smith 2116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2117014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 212193d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt *, const void *, PetscMPIInt *, PetscMPIInt **, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 212293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 212393d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, MPI_Request **, MPI_Request **, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 2124d382aafbSBarry Smith 21256145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 21266145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 21276145cd65SJed Brown 2128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2129d382aafbSBarry Smith 2130ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2131ce94432eSBarry Smith 2132d382aafbSBarry Smith struct _n_PetscSubcomm { 2133d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2134d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2135306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 213645487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 213745487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2138708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 213945487dadSJed Brown PetscSubcommType type; 2140e5acf8a4SHong Zhang char *subcommprefix; 2141d382aafbSBarry Smith }; 2142d382aafbSBarry Smith 2143d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2144d71ae5a4SJacob Faibussowitsch { 21459371c9d4SSatish Balay return scomm->parent; 21469371c9d4SSatish Balay } 2147d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2148d71ae5a4SJacob Faibussowitsch { 21499371c9d4SSatish Balay return scomm->child; 21509371c9d4SSatish Balay } 2151d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2152d71ae5a4SJacob Faibussowitsch { 21539371c9d4SSatish Balay return scomm->dupparent; 21549371c9d4SSatish Balay } 2155014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2156014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2158014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 215965d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2160053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2161f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2162e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2163a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2164a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2165a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2166d382aafbSBarry Smith 21679962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 21689962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 21699962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 21709962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 21719962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 21729962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 21739962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 21749962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 21759962606eSBarry Smith 21765e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 21775f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 21785f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 21795f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 21805f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 21815e71baefSBarry Smith 2182a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2183a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2184a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2185a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2186a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2187a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2188a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2189a32e93adSJunchao Zhang 219013e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 21910f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 219213e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2193137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2194137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2195137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 219613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 219713e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 21980f453b92SJed Brown 2199471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2200471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2201471ecdacSJed Brown * possible. */ 2202d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2203d71ae5a4SJacob Faibussowitsch { 22049371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 22059371c9d4SSatish Balay } 2206d382aafbSBarry Smith 22079de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 22089de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 22099de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 22109de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 22119de0f6ecSBarry Smith 2212ace2fbaeSBarry Smith #include <stdarg.h> 2213ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2214ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2215ace2fbaeSBarry Smith 2216268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2217fbfcfee5SBarry Smith 22181f817a21SBarry Smith /*@C 22191f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 22201f817a21SBarry Smith 2221*667f096bSBarry Smith Not Collective; No Fortran Support 22221f817a21SBarry Smith 22231f817a21SBarry Smith Input Parameters: 222435cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely 222587497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 22261f817a21SBarry Smith 2227*667f096bSBarry Smith Options Database Key: 22283c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation 22293c7db156SBarry Smith 2230850545d0SSatish Balay Level: intermediate 22311f817a21SBarry Smith @*/ 2232d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2233d71ae5a4SJacob Faibussowitsch { 2234dff31646SBarry Smith size_t len; 2235dff31646SBarry Smith char *vstring; 2236dff31646SBarry Smith 22371f817a21SBarry Smith PetscFunctionBegin; 22383ba16761SJacob Faibussowitsch if (set && *set) PetscFunctionReturn(PETSC_SUCCESS); 22399566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 22409566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 22419566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2242dff31646SBarry Smith if (set) *set = PETSC_TRUE; 22433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2244dff31646SBarry Smith } 2245dff31646SBarry Smith 2246d8174014SToby Isaac PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c); 2247fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2248fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2249f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2250fe278a28SBarry Smith 2251f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2252f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 2253b967cddfSBarry Smith 22549f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 22559f4d3c52SBarry Smith 225604102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *); 2257763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *); 2258dff31646SBarry Smith 225968e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 22605dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2261d382aafbSBarry Smith 2262b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2263d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2264d71ae5a4SJacob Faibussowitsch { 2265df05ca09SBarry Smith unsigned int c, hash = 5381; 2266df05ca09SBarry Smith 2267503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2268df05ca09SBarry Smith return hash; 2269df05ca09SBarry Smith } 227077a5e07dSBarry Smith 227177a5e07dSBarry Smith /*MC 227287497f52SBarry Smith MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 227387497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 227487497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 227577a5e07dSBarry Smith 2276d083f849SBarry Smith Collective 227777a5e07dSBarry Smith 227877a5e07dSBarry Smith Synopsis: 227977a5e07dSBarry Smith #include <petscsys.h> 228077a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 228177a5e07dSBarry Smith 228277a5e07dSBarry Smith Input Parameters: 2283df05ca09SBarry Smith + a - pointer to the input data to be reduced 2284df05ca09SBarry Smith . c - the number of MPI data items in a and b 228587497f52SBarry Smith . d - the MPI datatype, for example `MPI_INT` 228687497f52SBarry Smith . e - the MPI operation, for example `MPI_SUM` 2287df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 228877a5e07dSBarry Smith 228977a5e07dSBarry Smith Output Parameter: 2290df05ca09SBarry Smith . b - the reduced values 229177a5e07dSBarry Smith 2292*667f096bSBarry Smith Level: developer 2293*667f096bSBarry Smith 2294e28ce29aSPatrick Sanan Notes: 229587497f52SBarry Smith In optimized mode this directly calls `MPI_Allreduce()` 229677a5e07dSBarry Smith 2297df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2298df05ca09SBarry Smith 229987497f52SBarry Smith The error code this returns should be checked with `PetscCall()` even though it looks like an MPI function because it always returns PETSc error codes 2300df05ca09SBarry Smith 2301db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 230277a5e07dSBarry Smith M*/ 23033ba16761SJacob Faibussowitsch // clang-format off 23049371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 23053ba16761SJacob Faibussowitsch PetscMacroReturnStandard( \ 23063ba16761SJacob Faibussowitsch PetscMPIInt a_b1[6], a_b2[6]; \ 23073ba16761SJacob Faibussowitsch int _mpiu_allreduce_c_int = (int)(c); \ 23083ba16761SJacob Faibussowitsch a_b1[0] = -(PetscMPIInt)__LINE__; \ 23093ba16761SJacob Faibussowitsch a_b1[1] = -a_b1[0]; \ 23103ba16761SJacob Faibussowitsch a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \ 23113ba16761SJacob Faibussowitsch a_b1[3] = -a_b1[2]; \ 23123ba16761SJacob Faibussowitsch a_b1[4] = -(PetscMPIInt)(c); \ 23133ba16761SJacob Faibussowitsch a_b1[5] = -a_b1[4]; \ 23143ba16761SJacob Faibussowitsch \ 23153ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \ 23163ba16761SJacob Faibussowitsch PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); \ 23173ba16761SJacob Faibussowitsch PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); \ 23183ba16761SJacob Faibussowitsch PetscCheck(-a_b2[4] == a_b2[5], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); \ 23193ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)));) 23203ba16761SJacob Faibussowitsch // clang-format on 2321b2566f29SBarry Smith #else 2322f3fa974cSJacob Faibussowitsch #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)))) 2323b2566f29SBarry Smith #endif 2324b2566f29SBarry Smith 2325b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 23268198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 23278198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 23282f065d89SBarry Smith #endif 23298198064fSBarry Smith 2330cd88fca5SStefano Zampini /* this is a vile hack */ 2331cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 23329371c9d4SSatish Balay #if !defined(PETSC_NECMPI_VERSION_MAJOR) || !defined(PETSC_NECMPI_VERSION_MINOR) || PETSC_NECMPI_VERSION_MAJOR < 2 || (PETSC_NECMPI_VERSION_MAJOR == 2 && PETSC_NECMPI_VERSION_MINOR < 18) 2333cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2334cd88fca5SStefano Zampini #endif 2335961fb248SStefano Zampini #endif 2336cd88fca5SStefano Zampini 233712801b39SBarry Smith /* 233860fbe2beSVaclav Hapla List of external packages and queries on it 233960fbe2beSVaclav Hapla */ 234060fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 234160fbe2beSVaclav Hapla 2342a52b435bSMark Adams /* 2343a52b435bSMark Adams OpenMP support 2344a52b435bSMark Adams */ 2345a52b435bSMark Adams #if defined(_OPENMP) 2346a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__)) 2347a52b435bSMark Adams #else // no OpenMP so no threads 2348a52b435bSMark Adams #define PetscPragmaOMP(...) 2349a52b435bSMark Adams #endif 2350a52b435bSMark Adams 2351f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2352f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2353f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2354f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2355d382aafbSBarry Smith #endif 2356