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 130e28ce29aSPatrick Sanan Notes: 13187497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 132e28ce29aSPatrick Sanan 133e28ce29aSPatrick Sanan Level: beginner 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 142a05e1a72SSatish Balay #define PetscInt_FMT PetscInt64_FMT 143d382aafbSBarry Smith #else 144d382aafbSBarry Smith #define MPIU_INT MPI_INT 145a05e1a72SSatish Balay #define PetscInt_FMT "d" 146d382aafbSBarry Smith #endif 147d382aafbSBarry Smith 148503cfb0cSBarry Smith /* 149503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 150503cfb0cSBarry Smith */ 15193d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 152d382aafbSBarry Smith 153d382aafbSBarry Smith /* 154d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 155d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 156d382aafbSBarry Smith */ 157014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 158d382aafbSBarry Smith 159d382aafbSBarry Smith /* 160d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 161d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 162d382aafbSBarry Smith */ 163014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 164d382aafbSBarry Smith 165c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */ 166c8b9133aSSatish Balay 1675c993f7fSStefano Zampini #if defined(__NEC__) 1685c993f7fSStefano Zampini #define PetscPragmaSIMD _Pragma("_NEC ivdep") 1695c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32) 170c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("vector") 1711dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI) 172c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("GCC ivdep") 173e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307 174e5518150SSatish Balay #if defined(_MSC_VER) 175160a5775SAli Reza Khaz'ali #define PetscPragmaSIMD __pragma(omp simd) 176e5518150SSatish Balay #else 177e5518150SSatish Balay #define PetscPragmaSIMD _Pragma("omp simd") 178e5518150SSatish Balay #endif 179c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR) 180c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("_CRI ivdep") 181c8b9133aSSatish Balay #else 182c8b9133aSSatish Balay #define PetscPragmaSIMD 183c8b9133aSSatish Balay #endif 184c8b9133aSSatish Balay 185d382aafbSBarry Smith /* 186d382aafbSBarry Smith Declare extern C stuff after including external header files 187d382aafbSBarry Smith */ 188d382aafbSBarry Smith 1896a6fc655SJed Brown PETSC_EXTERN const char *const PetscBools[]; 19070b3c8c7SBarry Smith 1916edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 1928b49ba18SBarry Smith /* 193390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 1948b49ba18SBarry Smith */ 1958b49ba18SBarry Smith #include <petscmath.h> 1968b49ba18SBarry Smith 1976a6fc655SJed Brown PETSC_EXTERN const char *const PetscCopyModes[]; 198d382aafbSBarry Smith 199d382aafbSBarry Smith /*MC 2000298fd71SBarry Smith PETSC_IGNORE - same as NULL, means PETSc will ignore this argument 201d382aafbSBarry Smith 202d382aafbSBarry Smith Level: beginner 203d382aafbSBarry Smith 204e28ce29aSPatrick Sanan Note: 20587497f52SBarry Smith Accepted by many PETSc functions to not set a parameter and instead use some default 206d382aafbSBarry Smith 20787497f52SBarry Smith Fortran Note: 20887497f52SBarry Smith This macro does not exist in Fortran; you must use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 209d382aafbSBarry Smith 210db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 211d382aafbSBarry Smith 212d382aafbSBarry Smith M*/ 2130298fd71SBarry Smith #define PETSC_IGNORE NULL 214d382aafbSBarry Smith 215c528d872SBarry Smith /* This is deprecated */ 216c528d872SBarry Smith #define PETSC_NULL NULL 217c528d872SBarry Smith 218d382aafbSBarry Smith /*MC 219557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 220557d4da8SBarry Smith where you wish PETSc to use the default. 221557d4da8SBarry Smith 222557d4da8SBarry Smith Level: beginner 223557d4da8SBarry Smith 224db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 225557d4da8SBarry Smith 226557d4da8SBarry Smith M*/ 227557d4da8SBarry Smith #define PETSC_DECIDE -1 228557d4da8SBarry Smith 229557d4da8SBarry Smith /*MC 230d382aafbSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter 231d382aafbSBarry Smith where you wish PETSc to compute the required value. 232d382aafbSBarry Smith 233d382aafbSBarry Smith Level: beginner 234d382aafbSBarry Smith 235e28ce29aSPatrick Sanan Developer Note: 23687497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 23787497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 238557d4da8SBarry Smith 239db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 240d382aafbSBarry Smith 241d382aafbSBarry Smith M*/ 242d382aafbSBarry Smith #define PETSC_DETERMINE PETSC_DECIDE 243d382aafbSBarry Smith 244d382aafbSBarry Smith /*MC 245557d4da8SBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter 246557d4da8SBarry Smith where you wish PETSc to use the default. 247557d4da8SBarry Smith 248557d4da8SBarry Smith Level: beginner 249557d4da8SBarry Smith 25087497f52SBarry Smith Fortran Note: 25187497f52SBarry Smith You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 252557d4da8SBarry Smith 253db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 254557d4da8SBarry Smith 255557d4da8SBarry Smith M*/ 256557d4da8SBarry Smith #define PETSC_DEFAULT -2 257557d4da8SBarry Smith 258557d4da8SBarry Smith /*MC 25987497f52SBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents 260ea8fe74dSBarry Smith all the processes that PETSc knows about. 261d382aafbSBarry Smith 262d382aafbSBarry Smith Level: beginner 263d382aafbSBarry Smith 264e28ce29aSPatrick Sanan Notes: 26587497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 26687497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 26787497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 26887497f52SBarry Smith PetscInitialize(), but after `MPI_Init()` has been called. 269a990b902SBarry Smith 27087497f52SBarry Smith The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()` 271a990b902SBarry Smith is called because it may not have a valid value yet. 272d382aafbSBarry Smith 273db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 274d382aafbSBarry Smith 275d382aafbSBarry Smith M*/ 276014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 277d382aafbSBarry Smith 278d382aafbSBarry Smith /*MC 27987497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 280d382aafbSBarry Smith 281d382aafbSBarry Smith Level: beginner 282d382aafbSBarry Smith 283e28ce29aSPatrick Sanan Notes: 284e28ce29aSPatrick Sanan Do not USE/access or set this variable before PetscInitialize() has been called. 285a990b902SBarry Smith 286db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 287d382aafbSBarry Smith 288d382aafbSBarry Smith M*/ 289d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 290d382aafbSBarry Smith 2916de5d289SStefano Zampini /*MC 2926de5d289SStefano Zampini PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes 29387497f52SBarry Smith MPI with `MPI_Init_thread()`. 2946de5d289SStefano Zampini 2956de5d289SStefano Zampini Level: beginner 2966de5d289SStefano Zampini 2976de5d289SStefano Zampini Notes: 29887497f52SBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`. 2996de5d289SStefano Zampini 300db781477SPatrick Sanan .seealso: `PetscInitialize()` 3016de5d289SStefano Zampini 3026de5d289SStefano Zampini M*/ 3036de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3046de5d289SStefano Zampini 305d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 3068ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 307014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 308014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3094cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 310d382aafbSBarry Smith 311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 312014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 31457f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 31557f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 316d382aafbSBarry Smith 31759e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 31859e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 31959e55d94SJunchao Zhang #endif 32059e55d94SJunchao Zhang 32171438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 32271438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 32371438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 32471438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 32571438e86SJunchao Zhang #endif 32671438e86SJunchao Zhang 327540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 328540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 329540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 330540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 331540e20f2SPierre Jolivet #endif 332540e20f2SPierre Jolivet 333d382aafbSBarry Smith /*MC 33487497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 335d382aafbSBarry Smith 336eca87e8dSBarry Smith Synopsis: 337aaa7dc30SBarry Smith #include <petscsys.h> 338eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 339eca87e8dSBarry Smith 340eca87e8dSBarry Smith Not Collective 341eca87e8dSBarry Smith 342d382aafbSBarry Smith Input Parameter: 343d382aafbSBarry Smith . m - number of bytes to allocate 344d382aafbSBarry Smith 345d382aafbSBarry Smith Output Parameter: 346d382aafbSBarry Smith . result - memory allocated 347d382aafbSBarry Smith 348d382aafbSBarry Smith Level: beginner 349d382aafbSBarry Smith 35049d7da52SJed Brown Notes: 35149d7da52SJed Brown Memory is always allocated at least double aligned 352d382aafbSBarry Smith 35387497f52SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`. 354d382aafbSBarry Smith 355db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 356d382aafbSBarry Smith 357d382aafbSBarry Smith M*/ 358071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 359d382aafbSBarry Smith 360d382aafbSBarry Smith /*MC 361d5b43468SJose E. Roman PetscRealloc - Reallocates memory 3623221ece2SMatthew G. Knepley 3633221ece2SMatthew G. Knepley Synopsis: 3643221ece2SMatthew G. Knepley #include <petscsys.h> 3653221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3663221ece2SMatthew G. Knepley 3673221ece2SMatthew G. Knepley Not Collective 3683221ece2SMatthew G. Knepley 3693221ece2SMatthew G. Knepley Input Parameters: 3703221ece2SMatthew G. Knepley + m - number of bytes to allocate 37192f119d6SBarry Smith - result - previous memory 3723221ece2SMatthew G. Knepley 3733221ece2SMatthew G. Knepley Output Parameter: 3743221ece2SMatthew G. Knepley . result - new memory allocated 3753221ece2SMatthew G. Knepley 3763221ece2SMatthew G. Knepley Level: developer 3773221ece2SMatthew G. Knepley 3783221ece2SMatthew G. Knepley Notes: 3793221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 3803221ece2SMatthew G. Knepley 381db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 3823221ece2SMatthew G. Knepley 3833221ece2SMatthew G. Knepley M*/ 3843221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 3853221ece2SMatthew G. Knepley 3863221ece2SMatthew G. Knepley /*MC 38787497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 388d382aafbSBarry Smith 389d382aafbSBarry Smith Synopsis: 390aaa7dc30SBarry Smith #include <petscsys.h> 391d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 392d382aafbSBarry Smith 393eca87e8dSBarry Smith Not Collective 394eca87e8dSBarry Smith 395eca87e8dSBarry Smith Input Parameters: 396eca87e8dSBarry Smith . addr - address to align (any pointer type) 397eca87e8dSBarry Smith 398d382aafbSBarry Smith Level: developer 399d382aafbSBarry Smith 400db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 401d382aafbSBarry Smith 402d382aafbSBarry Smith M*/ 403d382aafbSBarry Smith #define PetscAddrAlign(a) (void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)) 404d382aafbSBarry Smith 405d382aafbSBarry Smith /*MC 40687497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 4078f51dc47SJunchao Zhang 4088f51dc47SJunchao Zhang Synopsis: 4098f51dc47SJunchao Zhang #include <petscsys.h> 4108f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4118f51dc47SJunchao Zhang 4128f51dc47SJunchao Zhang Not Collective 4138f51dc47SJunchao Zhang 4148f51dc47SJunchao Zhang Input Parameter: 4158f51dc47SJunchao Zhang . m - number of bytes to allocate 4168f51dc47SJunchao Zhang 4178f51dc47SJunchao Zhang Output Parameter: 4188f51dc47SJunchao Zhang . result - memory allocated 4198f51dc47SJunchao Zhang 4208f51dc47SJunchao Zhang Level: beginner 4218f51dc47SJunchao Zhang 4228f51dc47SJunchao Zhang Notes: 4238f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4248f51dc47SJunchao Zhang 4258f51dc47SJunchao Zhang It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 4268f51dc47SJunchao Zhang 427db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4288f51dc47SJunchao Zhang 4298f51dc47SJunchao Zhang M*/ 43066122d6dSBarry Smith #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m), (result)) 4318f51dc47SJunchao Zhang 4328f51dc47SJunchao Zhang /*MC 43387497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 434d382aafbSBarry Smith 435eca87e8dSBarry Smith Synopsis: 436aaa7dc30SBarry Smith #include <petscsys.h> 437785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 438785e854fSJed Brown 439785e854fSJed Brown Not Collective 440785e854fSJed Brown 441785e854fSJed Brown Input Parameter: 442390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 443785e854fSJed Brown 444785e854fSJed Brown Output Parameter: 4451fe1b817SJunchao Zhang . r1 - memory allocated 446785e854fSJed Brown 447e28ce29aSPatrick Sanan Note: 448e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 44987497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 450390e1bf2SBarry Smith $ PetscInt *id; 451390e1bf2SBarry Smith $ PetscMalloc1(10,&id); 452390e1bf2SBarry Smith not 453390e1bf2SBarry Smith $ PetscInt *id; 454390e1bf2SBarry Smith $ PetscMalloc1(10*sizeof(PetscInt),&id); 455390e1bf2SBarry Smith 45687497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 457390e1bf2SBarry Smith 458390e1bf2SBarry Smith Level: beginner 459785e854fSJed Brown 460db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 461785e854fSJed Brown 462785e854fSJed Brown M*/ 46366122d6dSBarry Smith #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 464785e854fSJed Brown 465785e854fSJed Brown /*MC 46687497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 4671795a4d1SJed Brown 4681795a4d1SJed Brown Synopsis: 469aaa7dc30SBarry Smith #include <petscsys.h> 4701795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 4711795a4d1SJed Brown 4721795a4d1SJed Brown Not Collective 4731795a4d1SJed Brown 4741795a4d1SJed Brown Input Parameter: 4751795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 4761795a4d1SJed Brown 4771795a4d1SJed Brown Output Parameter: 4781fe1b817SJunchao Zhang . r1 - memory allocated 4791795a4d1SJed Brown 480e28ce29aSPatrick Sanan Notes: 48187497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 482390e1bf2SBarry Smith 483390e1bf2SBarry Smith Level: beginner 4841795a4d1SJed Brown 485db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 4861795a4d1SJed Brown 4871795a4d1SJed Brown M*/ 48866122d6dSBarry Smith #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 4891795a4d1SJed Brown 4901795a4d1SJed Brown /*MC 49187497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 492d382aafbSBarry Smith 493eca87e8dSBarry Smith Synopsis: 494aaa7dc30SBarry Smith #include <petscsys.h> 495dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 496eca87e8dSBarry Smith 497eca87e8dSBarry Smith Not Collective 498eca87e8dSBarry Smith 499d8d19677SJose E. Roman Input Parameters: 500d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 501dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 502d382aafbSBarry Smith 503d8d19677SJose E. Roman Output Parameters: 504d382aafbSBarry Smith + r1 - memory allocated in first chunk 505d382aafbSBarry Smith - r2 - memory allocated in second chunk 506d382aafbSBarry Smith 507d382aafbSBarry Smith Level: developer 508d382aafbSBarry Smith 509db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 510d382aafbSBarry Smith 511d382aafbSBarry Smith M*/ 51266122d6dSBarry Smith #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)) 513d382aafbSBarry Smith 514d382aafbSBarry Smith /*MC 51587497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 516d382aafbSBarry Smith 517eca87e8dSBarry Smith Synopsis: 518aaa7dc30SBarry Smith #include <petscsys.h> 5191795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 520eca87e8dSBarry Smith 521eca87e8dSBarry Smith Not Collective 522eca87e8dSBarry Smith 523d8d19677SJose E. Roman Input Parameters: 524d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5251795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5261795a4d1SJed Brown 527d8d19677SJose E. Roman Output Parameters: 5281795a4d1SJed Brown + r1 - memory allocated in first chunk 5291795a4d1SJed Brown - r2 - memory allocated in second chunk 5301795a4d1SJed Brown 5311795a4d1SJed Brown Level: developer 5321795a4d1SJed Brown 533db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5341795a4d1SJed Brown 5351795a4d1SJed Brown M*/ 53666122d6dSBarry Smith #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)) 5371795a4d1SJed Brown 5381795a4d1SJed Brown /*MC 53987497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 540d382aafbSBarry Smith 541d382aafbSBarry Smith Synopsis: 542aaa7dc30SBarry Smith #include <petscsys.h> 543dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 544d382aafbSBarry Smith 545d382aafbSBarry Smith Not Collective 546d382aafbSBarry Smith 547d8d19677SJose E. Roman Input Parameters: 548d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 549d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 550dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 551d382aafbSBarry Smith 552d8d19677SJose E. Roman Output Parameters: 553d382aafbSBarry Smith + r1 - memory allocated in first chunk 554d382aafbSBarry Smith . r2 - memory allocated in second chunk 555d382aafbSBarry Smith - r3 - memory allocated in third chunk 556d382aafbSBarry Smith 557d382aafbSBarry Smith Level: developer 558d382aafbSBarry Smith 559db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 560d382aafbSBarry Smith 561d382aafbSBarry Smith M*/ 56266122d6dSBarry Smith #define PetscMalloc3(m1, r1, m2, r2, m3, r3) PetscMallocA(3, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3)) 563d382aafbSBarry Smith 564d382aafbSBarry Smith /*MC 56587497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 566d382aafbSBarry Smith 567eca87e8dSBarry Smith Synopsis: 568aaa7dc30SBarry Smith #include <petscsys.h> 5691795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 570eca87e8dSBarry Smith 571eca87e8dSBarry Smith Not Collective 572eca87e8dSBarry Smith 573d8d19677SJose E. Roman Input Parameters: 574d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 575d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 5761795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 5771795a4d1SJed Brown 578d8d19677SJose E. Roman Output Parameters: 5791795a4d1SJed Brown + r1 - memory allocated in first chunk 5801795a4d1SJed Brown . r2 - memory allocated in second chunk 5811795a4d1SJed Brown - r3 - memory allocated in third chunk 5821795a4d1SJed Brown 5831795a4d1SJed Brown Level: developer 5841795a4d1SJed Brown 585db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 5861795a4d1SJed Brown 5871795a4d1SJed Brown M*/ 58866122d6dSBarry Smith #define PetscCalloc3(m1, r1, m2, r2, m3, r3) PetscMallocA(3, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3)) 5891795a4d1SJed Brown 5901795a4d1SJed Brown /*MC 59187497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 592d382aafbSBarry Smith 593d382aafbSBarry Smith Synopsis: 594aaa7dc30SBarry Smith #include <petscsys.h> 595dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 596d382aafbSBarry Smith 597d382aafbSBarry Smith Not Collective 598d382aafbSBarry Smith 599d8d19677SJose E. Roman Input Parameters: 600d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 601d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 602d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 603dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 604d382aafbSBarry Smith 605d8d19677SJose E. Roman Output Parameters: 606d382aafbSBarry Smith + r1 - memory allocated in first chunk 607d382aafbSBarry Smith . r2 - memory allocated in second chunk 608d382aafbSBarry Smith . r3 - memory allocated in third chunk 609d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 610d382aafbSBarry Smith 611d382aafbSBarry Smith Level: developer 612d382aafbSBarry Smith 613db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 614d382aafbSBarry Smith 615d382aafbSBarry Smith M*/ 6169371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6179371c9d4SSatish Balay PetscMallocA(4, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4)) 618d382aafbSBarry Smith 619d382aafbSBarry Smith /*MC 62087497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 621d382aafbSBarry Smith 622eca87e8dSBarry Smith Synopsis: 623aaa7dc30SBarry Smith #include <petscsys.h> 6241795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 625eca87e8dSBarry Smith 626eca87e8dSBarry Smith Not Collective 627eca87e8dSBarry Smith 628e28ce29aSPatrick Sanan Input Parameters: 629d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 630d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 631d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6321795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6331795a4d1SJed Brown 634e28ce29aSPatrick Sanan Output Parameters: 6351795a4d1SJed Brown + r1 - memory allocated in first chunk 6361795a4d1SJed Brown . r2 - memory allocated in second chunk 6371795a4d1SJed Brown . r3 - memory allocated in third chunk 6381795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6391795a4d1SJed Brown 6401795a4d1SJed Brown Level: developer 6411795a4d1SJed Brown 642db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6431795a4d1SJed Brown 6441795a4d1SJed Brown M*/ 6459371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6469371c9d4SSatish Balay PetscMallocA(4, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4)) 6471795a4d1SJed Brown 6481795a4d1SJed Brown /*MC 64987497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 650d382aafbSBarry Smith 651d382aafbSBarry Smith Synopsis: 652aaa7dc30SBarry Smith #include <petscsys.h> 653dcca6d9dSJed 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) 654d382aafbSBarry Smith 655d382aafbSBarry Smith Not Collective 656d382aafbSBarry Smith 657e28ce29aSPatrick Sanan Input Parameters: 658d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 659d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 660d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 661d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 662dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 663d382aafbSBarry Smith 664e28ce29aSPatrick Sanan Output Parameters: 665d382aafbSBarry Smith + r1 - memory allocated in first chunk 666d382aafbSBarry Smith . r2 - memory allocated in second chunk 667d382aafbSBarry Smith . r3 - memory allocated in third chunk 668d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 669d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 670d382aafbSBarry Smith 671d382aafbSBarry Smith Level: developer 672d382aafbSBarry Smith 673db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 674d382aafbSBarry Smith 675d382aafbSBarry Smith M*/ 6769371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 6779371c9d4SSatish Balay PetscMallocA(5, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5)) 678d382aafbSBarry Smith 679d382aafbSBarry Smith /*MC 68087497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 681d382aafbSBarry Smith 682eca87e8dSBarry Smith Synopsis: 683aaa7dc30SBarry Smith #include <petscsys.h> 6841795a4d1SJed 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) 685eca87e8dSBarry Smith 686eca87e8dSBarry Smith Not Collective 687eca87e8dSBarry Smith 688e28ce29aSPatrick Sanan Input Parameters: 689d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 690d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 691d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 692d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 6931795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 6941795a4d1SJed Brown 695e28ce29aSPatrick Sanan Output Parameters: 6961795a4d1SJed Brown + r1 - memory allocated in first chunk 6971795a4d1SJed Brown . r2 - memory allocated in second chunk 6981795a4d1SJed Brown . r3 - memory allocated in third chunk 6991795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7001795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7011795a4d1SJed Brown 7021795a4d1SJed Brown Level: developer 7031795a4d1SJed Brown 704db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7051795a4d1SJed Brown 7061795a4d1SJed Brown M*/ 7079371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 7089371c9d4SSatish Balay PetscMallocA(5, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5)) 709d382aafbSBarry Smith 710d382aafbSBarry Smith /*MC 71187497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 712d382aafbSBarry Smith 713d382aafbSBarry Smith Synopsis: 714aaa7dc30SBarry Smith #include <petscsys.h> 715dcca6d9dSJed 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) 716d382aafbSBarry Smith 717d382aafbSBarry Smith Not Collective 718d382aafbSBarry Smith 719e28ce29aSPatrick Sanan Input Parameters: 720d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 721d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 722d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 723d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 724d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 725dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 726d382aafbSBarry Smith 727e28ce29aSPatrick Sanan Output Parameteasr: 728d382aafbSBarry Smith + r1 - memory allocated in first chunk 729d382aafbSBarry Smith . r2 - memory allocated in second chunk 730d382aafbSBarry Smith . r3 - memory allocated in third chunk 731d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 732d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 733d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 734d382aafbSBarry Smith 735d382aafbSBarry Smith Level: developer 736d382aafbSBarry Smith 737db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 738d382aafbSBarry Smith 739d382aafbSBarry Smith M*/ 7409371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7419371c9d4SSatish Balay PetscMallocA(6, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5), (size_t)((size_t)m6) * sizeof(**(r6)), (r6)) 742d382aafbSBarry Smith 743d382aafbSBarry Smith /*MC 74487497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 745d382aafbSBarry Smith 746eca87e8dSBarry Smith Synopsis: 747aaa7dc30SBarry Smith #include <petscsys.h> 7481795a4d1SJed 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) 749eca87e8dSBarry Smith 750eca87e8dSBarry Smith Not Collective 751eca87e8dSBarry Smith 752e28ce29aSPatrick Sanan Input Parameters: 753d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 754d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 755d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 756d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 757d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7581795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7591795a4d1SJed Brown 760e28ce29aSPatrick Sanan Output Parameters: 7611795a4d1SJed Brown + r1 - memory allocated in first chunk 7621795a4d1SJed Brown . r2 - memory allocated in second chunk 7631795a4d1SJed Brown . r3 - memory allocated in third chunk 7641795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7651795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7661795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7671795a4d1SJed Brown 7681795a4d1SJed Brown Level: developer 7691795a4d1SJed Brown 770db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7711795a4d1SJed Brown 7721795a4d1SJed Brown M*/ 7739371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7749371c9d4SSatish Balay PetscMallocA(6, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5), (size_t)((size_t)m6) * sizeof(**(r6)), (r6)) 7751795a4d1SJed Brown 7761795a4d1SJed Brown /*MC 77787497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 778d382aafbSBarry Smith 779d382aafbSBarry Smith Synopsis: 780aaa7dc30SBarry Smith #include <petscsys.h> 781dcca6d9dSJed 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) 782d382aafbSBarry Smith 783d382aafbSBarry Smith Not Collective 784d382aafbSBarry Smith 785e28ce29aSPatrick Sanan Input Parameters: 786d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 787d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 788d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 789d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 790d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 791d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 792dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 793d382aafbSBarry Smith 794e28ce29aSPatrick Sanan Output Parameters: 795d382aafbSBarry Smith + r1 - memory allocated in first chunk 796d382aafbSBarry Smith . r2 - memory allocated in second chunk 797d382aafbSBarry Smith . r3 - memory allocated in third chunk 798d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 799d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 800d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 801eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 802d382aafbSBarry Smith 803d382aafbSBarry Smith Level: developer 804d382aafbSBarry Smith 805db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 806d382aafbSBarry Smith 807d382aafbSBarry Smith M*/ 8089371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8099371c9d4SSatish Balay PetscMallocA(7, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5), (size_t)((size_t)m6) * sizeof(**(r6)), (r6), (size_t)((size_t)m7) * sizeof(**(r7)), (r7)) 810d382aafbSBarry Smith 811d382aafbSBarry Smith /*MC 81287497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 8131795a4d1SJed Brown 8141795a4d1SJed Brown Synopsis: 815aaa7dc30SBarry Smith #include <petscsys.h> 8161795a4d1SJed 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) 8171795a4d1SJed Brown 8181795a4d1SJed Brown Not Collective 8191795a4d1SJed Brown 820e28ce29aSPatrick Sanan Input Parameters: 8211795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8221795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8231795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8241795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8251795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8261795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8271795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8281795a4d1SJed Brown 829e28ce29aSPatrick Sanan Output Parameters: 8301795a4d1SJed Brown + r1 - memory allocated in first chunk 8311795a4d1SJed Brown . r2 - memory allocated in second chunk 8321795a4d1SJed Brown . r3 - memory allocated in third chunk 8331795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8341795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8351795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8361795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8371795a4d1SJed Brown 8381795a4d1SJed Brown Level: developer 8391795a4d1SJed Brown 840db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8411795a4d1SJed Brown 8421795a4d1SJed Brown M*/ 8439371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8449371c9d4SSatish Balay PetscMallocA(7, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1), (size_t)((size_t)m2) * sizeof(**(r2)), (r2), (size_t)((size_t)m3) * sizeof(**(r3)), (r3), (size_t)((size_t)m4) * sizeof(**(r4)), (r4), (size_t)((size_t)m5) * sizeof(**(r5)), (r5), (size_t)((size_t)m6) * sizeof(**(r6)), (r6), (size_t)((size_t)m7) * sizeof(**(r7)), (r7)) 8451795a4d1SJed Brown 8461795a4d1SJed Brown /*MC 84787497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 848d382aafbSBarry Smith 849eca87e8dSBarry Smith Synopsis: 850aaa7dc30SBarry Smith #include <petscsys.h> 851b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 852eca87e8dSBarry Smith 853eca87e8dSBarry Smith Not Collective 854eca87e8dSBarry Smith 855d382aafbSBarry Smith Output Parameter: 856b00a9115SJed Brown . result - memory allocated, sized to match pointer type 857d382aafbSBarry Smith 858d382aafbSBarry Smith Level: beginner 859d382aafbSBarry Smith 860fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 861d382aafbSBarry Smith 862d382aafbSBarry Smith M*/ 863b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 864ad0619ddSBarry Smith 8654dfa11a4SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b)) 866d382aafbSBarry Smith 867d382aafbSBarry Smith /*MC 868d382aafbSBarry Smith PetscFree - Frees memory 869d382aafbSBarry Smith 870eca87e8dSBarry Smith Synopsis: 871aaa7dc30SBarry Smith #include <petscsys.h> 872eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 873eca87e8dSBarry Smith 874eca87e8dSBarry Smith Not Collective 875eca87e8dSBarry Smith 876d382aafbSBarry Smith Input Parameter: 8777f4976b7SJacob Faibussowitsch . memory - memory to free (the pointer is ALWAYS set to NULL upon success) 878d382aafbSBarry Smith 879d382aafbSBarry Smith Level: beginner 880d382aafbSBarry Smith 88149d7da52SJed Brown Notes: 88287497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 883390e1bf2SBarry Smith 88487497f52SBarry Smith It is safe to call `PetscFree()` on a NULL pointer. 885d382aafbSBarry Smith 886fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 887d382aafbSBarry Smith 888d382aafbSBarry Smith M*/ 889ffc31a0eSLisandro Dalcin #define PetscFree(a) ((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = NULL, 0)) 890d382aafbSBarry Smith 891d382aafbSBarry Smith /*MC 89287497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 893d382aafbSBarry Smith 894eca87e8dSBarry Smith Synopsis: 895aaa7dc30SBarry Smith #include <petscsys.h> 896eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 897eca87e8dSBarry Smith 898eca87e8dSBarry Smith Not Collective 899eca87e8dSBarry Smith 900e28ce29aSPatrick Sanan Input Parameters: 901d382aafbSBarry Smith + memory1 - memory to free 902d382aafbSBarry Smith - memory2 - 2nd memory to free 903d382aafbSBarry Smith 904d382aafbSBarry Smith Level: developer 905d382aafbSBarry Smith 90695452b02SPatrick Sanan Notes: 90787497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 908d382aafbSBarry Smith 909db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 910d382aafbSBarry Smith 911d382aafbSBarry Smith M*/ 912ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 913d382aafbSBarry Smith 914d382aafbSBarry Smith /*MC 91587497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 916d382aafbSBarry Smith 917eca87e8dSBarry Smith Synopsis: 918aaa7dc30SBarry Smith #include <petscsys.h> 919eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 920eca87e8dSBarry Smith 921eca87e8dSBarry Smith Not Collective 922eca87e8dSBarry Smith 923e28ce29aSPatrick Sanan Input Parameters: 924d382aafbSBarry Smith + memory1 - memory to free 925d382aafbSBarry Smith . memory2 - 2nd memory to free 926d382aafbSBarry Smith - memory3 - 3rd memory to free 927d382aafbSBarry Smith 928d382aafbSBarry Smith Level: developer 929d382aafbSBarry Smith 93095452b02SPatrick Sanan Notes: 93187497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 932d382aafbSBarry Smith 933db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 934d382aafbSBarry Smith 935d382aafbSBarry Smith M*/ 936ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 937d382aafbSBarry Smith 938d382aafbSBarry Smith /*MC 93987497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 940d382aafbSBarry Smith 941eca87e8dSBarry Smith Synopsis: 942aaa7dc30SBarry Smith #include <petscsys.h> 943eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 944eca87e8dSBarry Smith 945eca87e8dSBarry Smith Not Collective 946eca87e8dSBarry Smith 947e28ce29aSPatrick Sanan Input Parameters: 948d382aafbSBarry Smith + m1 - memory to free 949d382aafbSBarry Smith . m2 - 2nd memory to free 950d382aafbSBarry Smith . m3 - 3rd memory to free 951d382aafbSBarry Smith - m4 - 4th memory to free 952d382aafbSBarry Smith 953d382aafbSBarry Smith Level: developer 954d382aafbSBarry Smith 95595452b02SPatrick Sanan Notes: 95687497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 957d382aafbSBarry Smith 958db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 959d382aafbSBarry Smith 960d382aafbSBarry Smith M*/ 961ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 962d382aafbSBarry Smith 963d382aafbSBarry Smith /*MC 96487497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 965d382aafbSBarry Smith 966eca87e8dSBarry Smith Synopsis: 967aaa7dc30SBarry Smith #include <petscsys.h> 968eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 969eca87e8dSBarry Smith 970eca87e8dSBarry Smith Not Collective 971eca87e8dSBarry Smith 972e28ce29aSPatrick Sanan Input Parameters: 973d382aafbSBarry Smith + m1 - memory to free 974d382aafbSBarry Smith . m2 - 2nd memory to free 975d382aafbSBarry Smith . m3 - 3rd memory to free 976d382aafbSBarry Smith . m4 - 4th memory to free 977d382aafbSBarry Smith - m5 - 5th memory to free 978d382aafbSBarry Smith 979d382aafbSBarry Smith Level: developer 980d382aafbSBarry Smith 98195452b02SPatrick Sanan Notes: 98287497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 983d382aafbSBarry Smith 984db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 985d382aafbSBarry Smith 986d382aafbSBarry Smith M*/ 987ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 988d382aafbSBarry Smith 989d382aafbSBarry Smith /*MC 99087497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 991d382aafbSBarry Smith 992eca87e8dSBarry Smith Synopsis: 993aaa7dc30SBarry Smith #include <petscsys.h> 994eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 995eca87e8dSBarry Smith 996eca87e8dSBarry Smith Not Collective 997eca87e8dSBarry Smith 998e28ce29aSPatrick Sanan Input Parameters: 999d382aafbSBarry Smith + m1 - memory to free 1000d382aafbSBarry Smith . m2 - 2nd memory to free 1001d382aafbSBarry Smith . m3 - 3rd memory to free 1002d382aafbSBarry Smith . m4 - 4th memory to free 1003d382aafbSBarry Smith . m5 - 5th memory to free 1004d382aafbSBarry Smith - m6 - 6th memory to free 1005d382aafbSBarry Smith 1006d382aafbSBarry Smith Level: developer 1007d382aafbSBarry Smith 100895452b02SPatrick Sanan Notes: 100987497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 1010d382aafbSBarry Smith 1011db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1012d382aafbSBarry Smith 1013d382aafbSBarry Smith M*/ 1014ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 1015d382aafbSBarry Smith 1016d382aafbSBarry Smith /*MC 101787497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 1018d382aafbSBarry Smith 1019eca87e8dSBarry Smith Synopsis: 1020aaa7dc30SBarry Smith #include <petscsys.h> 1021eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1022eca87e8dSBarry Smith 1023eca87e8dSBarry Smith Not Collective 1024eca87e8dSBarry Smith 1025e28ce29aSPatrick Sanan Input Parameters: 1026d382aafbSBarry Smith + m1 - memory to free 1027d382aafbSBarry Smith . m2 - 2nd memory to free 1028d382aafbSBarry Smith . m3 - 3rd memory to free 1029d382aafbSBarry Smith . m4 - 4th memory to free 1030d382aafbSBarry Smith . m5 - 5th memory to free 1031d382aafbSBarry Smith . m6 - 6th memory to free 1032d382aafbSBarry Smith - m7 - 7th memory to free 1033d382aafbSBarry Smith 1034d382aafbSBarry Smith Level: developer 1035d382aafbSBarry Smith 103695452b02SPatrick Sanan Notes: 103787497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1038d382aafbSBarry Smith 1039db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1040db781477SPatrick Sanan `PetscMalloc7()` 1041d382aafbSBarry Smith 1042d382aafbSBarry Smith M*/ 1043ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1044d382aafbSBarry Smith 1045ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1046ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1047071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1048efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 10493221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1050ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 105192f119d6SBarry 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 **)); 1052014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1053d382aafbSBarry Smith 1054d382aafbSBarry Smith /* 1055c1706be6SHong 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. 1056c1706be6SHong Zhang */ 1057c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1058c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 105931f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 106031f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 106131f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 106231f06eaaSHong Zhang #endif 106359af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 106459af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 106559af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 106659af0bd3SScott Kruger #endif 106759af0bd3SScott Kruger 1068a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 106936763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1070a5057860SBarry Smith 1071a5057860SBarry Smith /* 107266d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1073d382aafbSBarry Smith */ 1074014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 107592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1076014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1077014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1078e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1079e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 108092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 108192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1082efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 108392f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 108492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1085608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1086608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1087d382aafbSBarry Smith 10886a6fc655SJed Brown PETSC_EXTERN const char *const PetscDataTypes[]; 1089014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1090014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1091014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 10928e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1093d382aafbSBarry Smith 1094d382aafbSBarry Smith /* 1095d382aafbSBarry Smith Basic memory and string operations. These are usually simple wrappers 1096d382aafbSBarry Smith around the basic Unix system calls, but a few of them have additional 1097d382aafbSBarry Smith functionality and/or error checking. 1098d382aafbSBarry Smith */ 1099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemcmp(const void *, const void *, size_t, PetscBool *); 1100014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrlen(const char[], size_t *); 1101d67fe73bSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[], char, int *, char ***); 1102014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int, char **); 1103014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[], const char[], PetscBool *); 1104014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[], const char[], PetscBool *); 1105014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[], const char[], PetscBool *); 1106014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[], const char[], size_t, PetscBool *); 1107014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcpy(char[], const char[]); 1108014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcat(char[], const char[]); 1109a126751eSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrlcat(char[], const char[], size_t); 1110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncpy(char[], const char[], size_t); 1111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrchr(const char[], char, char *[]); 1112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]); 11132f234a98SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]); 1114014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[], char, char *[]); 1115014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrstr(const char[], const char[], char *[]); 1116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[], const char[], char *[]); 1117014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[], const char[], PetscBool *); 11182c9581d2SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[], const char[], PetscBool *); 1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[], const char *const *, PetscInt *); 1120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[], char *[]); 112147340559SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const *, char ***); 11226fed8037SJed Brown PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char ***); 11236991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt, const char *const *, char ***); 11246991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt, char ***); 1125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm, const char[], char[], size_t); 1126d382aafbSBarry Smith 1127573b0fb4SBarry Smith PETSC_EXTERN void PetscStrcmpNoError(const char[], const char[], PetscBool *); 1128573b0fb4SBarry Smith 1129*98e514b7SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[], char, PetscToken *); 1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken, char *[]); 1131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken *); 1132d382aafbSBarry Smith 1133e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscStrInList(const char[], const char[], char, PetscBool *); 113480b92c66SBarry Smith PETSC_EXTERN const char *PetscBasename(const char[]); 1135a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt, const char *const *, const char *, PetscInt *, PetscBool *); 1136a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const *, const char *, PetscEnum *, PetscBool *); 1137a53986e1SJed Brown 1138d382aafbSBarry Smith /* 1139d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1140d382aafbSBarry Smith */ 1141367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1142570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1143de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1144014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1145014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1146d9822059SBarry Smith #else 1147de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1148d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1149d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1150d9822059SBarry Smith #endif 115162e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 115262e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 115362e5d2d2SJDBetteridge 11549e517322SPierre Jolivet #if defined(PETSC_HAVE_REAL___FLOAT128) || defined(PETSC_HAVE_REAL___FP16) 1155613bf2b2SPierre Jolivet /*MC 11569e517322SPierre Jolivet MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with 11579e517322SPierre Jolivet custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1158613bf2b2SPierre Jolivet 1159613bf2b2SPierre Jolivet Level: advanced 1160613bf2b2SPierre Jolivet 1161613bf2b2SPierre Jolivet Developer Note: 1162613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1163613bf2b2SPierre Jolivet 1164613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1165613bf2b2SPierre Jolivet M*/ 11669e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1167613bf2b2SPierre Jolivet #endif 1168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1169d382aafbSBarry Smith 117093d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 117193d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1172eb3f98d2SBarry Smith 117395c0884eSLisandro Dalcin PETSC_EXTERN const char *const PetscFileModes[]; 1174d6a4318aSJed Brown 1175639ff905SBarry Smith /* 1176639ff905SBarry Smith Defines PETSc error handling. 1177639ff905SBarry Smith */ 1178639ff905SBarry Smith #include <petscerror.h> 1179d382aafbSBarry Smith 1180660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1181660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1182660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1183660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1184660278c0SBarry Smith 11850700a824SBarry Smith #define PETSC_SMALLEST_CLASSID 1211211 1186014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1187014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1188014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 118981256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 119081256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 119181256985SMatthew G. Knepley 1192d382aafbSBarry Smith /* 1193d382aafbSBarry Smith Routines that get memory usage information from the OS 1194d382aafbSBarry Smith */ 1195014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1196014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1197014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1198b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1199d382aafbSBarry Smith 1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1201d382aafbSBarry Smith 1202d382aafbSBarry Smith /* 1203d382aafbSBarry Smith Initialization of PETSc 1204d382aafbSBarry Smith */ 1205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1206014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1209014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1210014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1212014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1213014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1214014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1215d382aafbSBarry Smith 1216014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1217607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1218d382aafbSBarry Smith 1219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1223d382aafbSBarry Smith 1224a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1225a50e088cSMatthew G. Knepley 1226d382aafbSBarry Smith /* 1227d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 12282981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1229d382aafbSBarry Smith */ 1230638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void); 1231638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void); 1232638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1233d382aafbSBarry Smith 1234d382aafbSBarry Smith /* 1235d382aafbSBarry Smith Functions that can act on any PETSc object. 1236d382aafbSBarry Smith */ 1237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1238014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1241014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1242014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1243014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1245014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1247014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1248014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1249014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1250014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1251014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1252014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1253014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1254bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 1255bdf89e91SBarry Smith #define PetscObjectComposeFunction(a, b, d) PetscObjectComposeFunction_Private(a, b, (PetscVoidFunction)(d)) 1256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1257014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 12580eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 12590eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1260014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1261d382aafbSBarry Smith 1262665c2dedSJed Brown #include <petscviewertypes.h> 1263639ff905SBarry Smith #include <petscoptions.h> 1264639ff905SBarry Smith 1265608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1266608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1267608c71bfSMatthew G. Knepley 12680633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 12690633abcbSJed Brown 1270c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1271dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1272639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 12730005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr)) 12740005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1277014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1278014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1279014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1280014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1282685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1283014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1285013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 12864099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1288b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1291d382aafbSBarry Smith 1292e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 12937aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1294e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1295e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1296e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1297e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1298e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1299e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1300e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1301e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1302e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 130315681b3cSBarry Smith 1304ec7429eaSBarry Smith #else 13057aab2a10SBarry Smith #define PetscSAWsBlock() 0 1306e04113cfSBarry Smith #define PetscObjectSAWsViewOff(obj) 0 1307e04113cfSBarry Smith #define PetscObjectSAWsSetBlock(obj, flg) 0 1308e04113cfSBarry Smith #define PetscObjectSAWsBlock(obj) 0 1309e04113cfSBarry Smith #define PetscObjectSAWsGrantAccess(obj) 0 1310e04113cfSBarry Smith #define PetscObjectSAWsTakeAccess(obj) 0 1311e04113cfSBarry Smith #define PetscStackViewSAWs() 0 1312e04113cfSBarry Smith #define PetscStackSAWsViewOff() 0 1313e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1314e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 131515681b3cSBarry Smith 1316ec7429eaSBarry Smith #endif 1317b90c6cbeSBarry Smith 131882b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 131982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 132082b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1321258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1322258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1323258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1324258ec3d2SMatthew G. Knepley #endif 13257d5d4d99SBarry Smith 1326a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1327a64a8e02SBarry Smith 1328dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 1329140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1330140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1331140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1332140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1333140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1334140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1335d382aafbSBarry Smith 1336d382aafbSBarry Smith /* 1337503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1338d382aafbSBarry Smith link libraries that will be loaded as needed. 1339d382aafbSBarry Smith */ 1340a240a19fSJed Brown 1341a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr)) 1342a240a19fSJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], void (*)(void)); 1343140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 13440e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 13451c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr)) 13461c9cd337SJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], void (**)(void)); 134744ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1348140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1349140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1350140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 13512e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 13522e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1353d382aafbSBarry Smith 1354014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1356014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1360014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1362d382aafbSBarry Smith 1363d382aafbSBarry Smith /* 1364d382aafbSBarry Smith Useful utility routines 1365d382aafbSBarry Smith */ 1366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1368d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1370014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 137358b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 137458b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1375d382aafbSBarry Smith 137664ac3b0dSPatrick Sanan /*MC 137787497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1378503cfb0cSBarry Smith 137964ac3b0dSPatrick Sanan Level: beginner 138064ac3b0dSPatrick Sanan 1381a1cb98faSBarry Smith Note: 1382a1cb98faSBarry Smith This is useful in cases like 1383a1cb98faSBarry Smith .vb 1384a1cb98faSBarry Smith int *a; 1385a1cb98faSBarry Smith PetscBool flag = PetscNot(a) 1386a1cb98faSBarry Smith .ve 1387a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1388a1cb98faSBarry Smith 1389a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 139064ac3b0dSPatrick Sanan M*/ 1391d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1392503cfb0cSBarry Smith 1393d382aafbSBarry Smith /*MC 1394d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1395d382aafbSBarry Smith 1396cd05f99aSJacob Faibussowitsch Not Collective, only applies on rank 0; No Fortran Support 1397cf53795eSBarry Smith 1398d382aafbSBarry Smith Synopsis: 1399aaa7dc30SBarry Smith #include <petscsys.h> 1400659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1401d382aafbSBarry Smith 1402d382aafbSBarry Smith Input Parameters: 1403659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1404d382aafbSBarry Smith . format - the usual printf() format string 1405659f7ba0SBarry Smith - args - arguments to be printed 1406d382aafbSBarry Smith 1407d382aafbSBarry Smith Level: developer 1408d382aafbSBarry Smith 1409659f7ba0SBarry Smith Note: 1410659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1411659f7ba0SBarry Smith 1412659f7ba0SBarry Smith To use, write your own function, for example, 1413659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1414659f7ba0SBarry Smith ${ 1415659f7ba0SBarry Smith $ PetscFunctionReturn(0); 1416659f7ba0SBarry Smith $} 1417d5b43468SJose E. Roman then do the assignment 1418659f7ba0SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 141987497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1420659f7ba0SBarry Smith 142187497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1422d382aafbSBarry Smith 1423db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()` 1424d382aafbSBarry Smith M*/ 14253ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1426d382aafbSBarry Smith 1427fcfd50ebSBarry Smith /* 1428fcfd50ebSBarry Smith Defines PETSc profiling. 1429fcfd50ebSBarry Smith */ 14302c8e378dSBarry Smith #include <petsclog.h> 1431fcfd50ebSBarry Smith 1432fcfd50ebSBarry Smith /* 1433fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1434fcfd50ebSBarry Smith */ 1435014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1436014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1437014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 14383ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14393ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14403ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14413ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 14421b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1443fcfd50ebSBarry Smith 14443ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14453ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14463ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1447d382aafbSBarry Smith 1448d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1449d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1450d781fa04SBarry Smith 1451d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1453016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 145474ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1455d382aafbSBarry Smith #endif 1456d382aafbSBarry Smith 14573ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14583ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14590ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **); 1463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1464d382aafbSBarry Smith 1465014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1466014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1467014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1468014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1469014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1470014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1471b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1472d382aafbSBarry Smith 1473d382aafbSBarry Smith /* 1474d382aafbSBarry Smith For use in debuggers 1475d382aafbSBarry Smith */ 1476014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1477014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1478014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1479014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1480014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1481d382aafbSBarry Smith 1482a663daf8SBarry Smith #include <stddef.h> 1483a3aaec0aSJed Brown #include <string.h> /* for memcpy, memset */ 1484d382aafbSBarry Smith #include <stdlib.h> 14856c7e564aSBarry Smith 14864a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1487d382aafbSBarry Smith #include <xmmintrin.h> 1488d382aafbSBarry Smith #endif 1489d382aafbSBarry Smith 1490d382aafbSBarry Smith /*@C 1491580bdb30SBarry Smith PetscMemmove - Copies n bytes, beginning at location b, to the space 1492580bdb30SBarry Smith beginning at location a. Copying between regions that overlap will 149387497f52SBarry Smith take place correctly. Use `PetscMemcpy()` if the locations do not overlap 1494580bdb30SBarry Smith 1495580bdb30SBarry Smith Not Collective 1496580bdb30SBarry Smith 1497580bdb30SBarry Smith Input Parameters: 1498580bdb30SBarry Smith + b - pointer to initial memory space 1499580bdb30SBarry Smith . a - pointer to copy space 1500580bdb30SBarry Smith - n - length (in bytes) of space to copy 1501580bdb30SBarry Smith 1502580bdb30SBarry Smith Level: intermediate 1503580bdb30SBarry Smith 150487497f52SBarry Smith Notes: 150587497f52SBarry Smith `PetscArraymove()` is preferred 1506580bdb30SBarry Smith 150787497f52SBarry Smith This routine is analogous to `memmove()`. 150887497f52SBarry Smith 150987497f52SBarry Smith Developers Note: 151087497f52SBarry Smith This is inlined for performance 1511580bdb30SBarry Smith 1512db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 1513db781477SPatrick Sanan `PetscArraymove()` 1514580bdb30SBarry Smith @*/ 1515d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemmove(void *a, const void *b, size_t n) 1516d71ae5a4SJacob Faibussowitsch { 1517580bdb30SBarry Smith PetscFunctionBegin; 15189a202e32SJacob Faibussowitsch if (n > 0) { 15192c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to null pointer"); 15202c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 15219a202e32SJacob Faibussowitsch } 1522580bdb30SBarry Smith #if !defined(PETSC_HAVE_MEMMOVE) 1523580bdb30SBarry Smith if (a < b) { 1524580bdb30SBarry Smith if (a <= b - n) memcpy(a, b, n); 1525580bdb30SBarry Smith else { 1526580bdb30SBarry Smith memcpy(a, b, (int)(b - a)); 1527580bdb30SBarry Smith PetscMemmove(b, b + (int)(b - a), n - (int)(b - a)); 1528580bdb30SBarry Smith } 1529580bdb30SBarry Smith } else { 1530580bdb30SBarry Smith if (b <= a - n) memcpy(a, b, n); 1531580bdb30SBarry Smith else { 1532580bdb30SBarry Smith memcpy(b + n, b + (n - (int)(a - b)), (int)(a - b)); 1533580bdb30SBarry Smith PetscMemmove(a, b, n - (int)(a - b)); 1534580bdb30SBarry Smith } 1535580bdb30SBarry Smith } 1536580bdb30SBarry Smith #else 1537580bdb30SBarry Smith memmove((char *)(a), (char *)(b), n); 1538580bdb30SBarry Smith #endif 1539580bdb30SBarry Smith PetscFunctionReturn(0); 1540580bdb30SBarry Smith } 1541580bdb30SBarry Smith 1542d382aafbSBarry Smith /*@C 1543d382aafbSBarry Smith PetscMemcpy - Copies n bytes, beginning at location b, to the space 1544d382aafbSBarry Smith beginning at location a. The two memory regions CANNOT overlap, use 154587497f52SBarry Smith `PetscMemmove()` in that case. 1546d382aafbSBarry Smith 1547d382aafbSBarry Smith Not Collective 1548d382aafbSBarry Smith 1549d382aafbSBarry Smith Input Parameters: 1550d382aafbSBarry Smith + b - pointer to initial memory space 1551d382aafbSBarry Smith - n - length (in bytes) of space to copy 1552d382aafbSBarry Smith 1553d382aafbSBarry Smith Output Parameter: 1554d382aafbSBarry Smith . a - pointer to copy space 1555d382aafbSBarry Smith 1556d382aafbSBarry Smith Level: intermediate 1557d382aafbSBarry Smith 1558d382aafbSBarry Smith Compile Option: 155987497f52SBarry Smith `PETSC_PREFER_DCOPY_FOR_MEMCPY` will cause the BLAS dcopy() routine to be used 1560d382aafbSBarry Smith for memory copies on double precision values. 156187497f52SBarry Smith `PETSC_PREFER_COPY_FOR_MEMCPY` will cause C code to be used 1562d382aafbSBarry Smith for memory copies on double precision values. 156387497f52SBarry Smith `PETSC_PREFER_FORTRAN_FORMEMCPY` will cause Fortran code to be used 1564d382aafbSBarry Smith for memory copies on double precision values. 1565d382aafbSBarry Smith 156687497f52SBarry Smith Notes: 156787497f52SBarry Smith Prefer `PetscArraycpy()` 156887497f52SBarry Smith 156987497f52SBarry Smith This routine is analogous to `memcpy()`. 157087497f52SBarry Smith 15711fd49c25SBarry Smith Not available from Fortran 15721fd49c25SBarry Smith 157387497f52SBarry Smith Developer Note: 157487497f52SBarry Smith This is inlined for fastest performance 1575f5f57ec0SBarry Smith 1576db781477SPatrick Sanan .seealso: `PetscMemzero()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1577d382aafbSBarry Smith 1578d382aafbSBarry Smith @*/ 1579d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemcpy(void *a, const void *b, size_t n) 1580d71ae5a4SJacob Faibussowitsch { 1581d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 1582c5e4d11fSDmitry Karpeev size_t al = (size_t)a, bl = (size_t)b; 1583c5e4d11fSDmitry Karpeev size_t nl = (size_t)n; 1584a7e36092SMatthew G Knepley PetscFunctionBegin; 15859a202e32SJacob Faibussowitsch if (n > 0) { 15862c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 15872c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to a null pointer"); 15889a202e32SJacob Faibussowitsch } 1589a7e36092SMatthew G Knepley #else 1590d382aafbSBarry Smith PetscFunctionBegin; 1591a7e36092SMatthew G Knepley #endif 1592a47a537aSLisandro Dalcin if (a != b && n > 0) { 1593d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 15942c71b3e2SJacob Faibussowitsch PetscCheck(!((al > bl && (al - bl) < nl) || (bl - al) < nl), PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Memory regions overlap: either use PetscMemmov()\n\ 1595d382aafbSBarry Smith or make sure your copy regions and lengths are correct. \n\ 15969371c9d4SSatish Balay Length (bytes) %zu first address %zu second address %zu", 15979371c9d4SSatish Balay nl, al, bl); 1598d382aafbSBarry Smith #endif 1599d382aafbSBarry Smith #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1600c5e4d11fSDmitry Karpeev if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1601d382aafbSBarry Smith size_t len = n / sizeof(PetscScalar); 1602d382aafbSBarry Smith #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1603c5df96a5SBarry Smith PetscBLASInt one = 1, blen; 16049566063dSJacob Faibussowitsch PetscCall(PetscBLASIntCast(len, &blen)); 1605792fecdfSBarry Smith PetscCallBLAS("BLAScopy", BLAScopy_(&blen, (PetscScalar *)b, &one, (PetscScalar *)a, &one)); 1606d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1607d382aafbSBarry Smith fortrancopy_(&len, (PetscScalar *)b, (PetscScalar *)a); 1608d382aafbSBarry Smith #else 1609d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)b, *y = (PetscScalar *)a; 16105f80ce2aSJacob Faibussowitsch for (size_t i = 0; i < len; i++) y[i] = x[i]; 1611d382aafbSBarry Smith #endif 1612d382aafbSBarry Smith } else { 1613d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1614d382aafbSBarry Smith } 1615d382aafbSBarry Smith #else 1616d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1617d382aafbSBarry Smith #endif 1618d382aafbSBarry Smith } 1619d382aafbSBarry Smith PetscFunctionReturn(0); 1620d382aafbSBarry Smith } 1621d382aafbSBarry Smith 1622d382aafbSBarry Smith /*@C 1623d382aafbSBarry Smith PetscMemzero - Zeros the specified memory. 1624d382aafbSBarry Smith 1625d382aafbSBarry Smith Not Collective 1626d382aafbSBarry Smith 1627d382aafbSBarry Smith Input Parameters: 1628d382aafbSBarry Smith + a - pointer to beginning memory location 1629d382aafbSBarry Smith - n - length (in bytes) of memory to initialize 1630d382aafbSBarry Smith 1631d382aafbSBarry Smith Level: intermediate 1632d382aafbSBarry Smith 1633d382aafbSBarry Smith Compile Option: 163487497f52SBarry Smith `PETSC_PREFER_BZERO` - on certain machines (the IBM RS6000) the bzero() routine happens 1635d382aafbSBarry Smith to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1636d382aafbSBarry Smith 163787497f52SBarry Smith Notes: 16381fd49c25SBarry Smith Not available from Fortran 16391fd49c25SBarry Smith 164087497f52SBarry Smith Prefer `PetscArrayzero()` 164187497f52SBarry Smith 164287497f52SBarry Smith Developer Note: 164387497f52SBarry Smith This is inlined for fastest performance 1644503cfb0cSBarry Smith 1645db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1646d382aafbSBarry Smith @*/ 1647d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemzero(void *a, size_t n) 1648d71ae5a4SJacob Faibussowitsch { 1649d382aafbSBarry Smith if (n > 0) { 1650d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16512c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to zero at a null pointer with %zu bytes", n); 1652d382aafbSBarry Smith #endif 1653d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1654d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1655d382aafbSBarry Smith size_t i, len = n / sizeof(PetscScalar); 1656d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)a; 1657d382aafbSBarry Smith for (i = 0; i < len; i++) x[i] = 0.0; 1658d382aafbSBarry Smith } else { 1659d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1660d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1661d382aafbSBarry Smith PetscInt len = n / sizeof(PetscScalar); 1662d382aafbSBarry Smith fortranzero_(&len, (PetscScalar *)a); 1663d382aafbSBarry Smith } else { 1664d382aafbSBarry Smith #endif 1665d382aafbSBarry Smith #if defined(PETSC_PREFER_BZERO) 1666d382aafbSBarry Smith bzero((char *)a, n); 1667d382aafbSBarry Smith #else 1668d382aafbSBarry Smith memset((char *)a, 0, n); 1669d382aafbSBarry Smith #endif 1670d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1671d382aafbSBarry Smith } 1672d382aafbSBarry Smith #endif 1673d382aafbSBarry Smith } 1674d382aafbSBarry Smith return 0; 1675d382aafbSBarry Smith } 1676d382aafbSBarry Smith 1677d382aafbSBarry Smith /*MC 1678580bdb30SBarry Smith PetscArraycmp - Compares two arrays in memory. 1679580bdb30SBarry Smith 1680580bdb30SBarry Smith Synopsis: 1681580bdb30SBarry Smith #include <petscsys.h> 1682580bdb30SBarry Smith PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e) 1683580bdb30SBarry Smith 1684580bdb30SBarry Smith Not Collective 1685580bdb30SBarry Smith 1686580bdb30SBarry Smith Input Parameters: 1687580bdb30SBarry Smith + str1 - First array 1688580bdb30SBarry Smith . str2 - Second array 1689580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1690580bdb30SBarry Smith 1691580bdb30SBarry Smith Output Parameters: 169287497f52SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 1693580bdb30SBarry Smith 1694580bdb30SBarry Smith Level: intermediate 1695580bdb30SBarry Smith 169687497f52SBarry Smith Notes: 169787497f52SBarry Smith This routine is a preferred replacement to `PetscMemcmp()` 169887497f52SBarry Smith 1699580bdb30SBarry Smith The arrays must be of the same type 1700580bdb30SBarry Smith 1701db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, 1702db781477SPatrick Sanan `PetscArraymove()` 1703580bdb30SBarry Smith M*/ 17049e2232c7SLisandro Dalcin #define PetscArraycmp(str1, str2, cnt, e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1, str2, (size_t)(cnt) * sizeof(*(str1)), e)) 1705580bdb30SBarry Smith 17068f8f2f0dSBarry Smith /*MC 170787497f52SBarry Smith PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use `PetscArraycpy()` when the arrays 1708580bdb30SBarry Smith do not overlap 1709580bdb30SBarry Smith 1710580bdb30SBarry Smith Synopsis: 1711580bdb30SBarry Smith #include <petscsys.h> 1712580bdb30SBarry Smith PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt) 1713580bdb30SBarry Smith 1714580bdb30SBarry Smith Not Collective 1715580bdb30SBarry Smith 1716580bdb30SBarry Smith Input Parameters: 1717580bdb30SBarry Smith + str1 - First array 1718580bdb30SBarry Smith . str2 - Second array 1719580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1720580bdb30SBarry Smith 1721580bdb30SBarry Smith Level: intermediate 1722580bdb30SBarry Smith 172387497f52SBarry Smith Notes: 172487497f52SBarry Smith This routine is a preferred replacement to `PetscMemmove()` 172587497f52SBarry Smith 1726580bdb30SBarry Smith The arrays must be of the same type 1727580bdb30SBarry Smith 1728db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1729580bdb30SBarry Smith M*/ 17309e2232c7SLisandro Dalcin #define PetscArraymove(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1731580bdb30SBarry Smith 17328f8f2f0dSBarry Smith /*MC 1733580bdb30SBarry Smith PetscArraycpy - Copies from one array in memory to another 1734580bdb30SBarry Smith 1735580bdb30SBarry Smith Synopsis: 1736580bdb30SBarry Smith #include <petscsys.h> 1737580bdb30SBarry Smith PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt) 1738580bdb30SBarry Smith 1739580bdb30SBarry Smith Not Collective 1740580bdb30SBarry Smith 1741580bdb30SBarry Smith Input Parameters: 1742de25709eSStefano Zampini + str1 - First array (destination) 1743de25709eSStefano Zampini . str2 - Second array (source) 1744580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1745580bdb30SBarry Smith 1746580bdb30SBarry Smith Level: intermediate 1747580bdb30SBarry Smith 174887497f52SBarry Smith Notes: 174987497f52SBarry Smith This routine is a preferred replacement to `PetscMemcpy()` 175087497f52SBarry Smith 1751580bdb30SBarry Smith The arrays must be of the same type 1752580bdb30SBarry Smith 1753db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraymove()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1754580bdb30SBarry Smith M*/ 17559e2232c7SLisandro Dalcin #define PetscArraycpy(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcpy(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1756580bdb30SBarry Smith 17578f8f2f0dSBarry Smith /*MC 1758580bdb30SBarry Smith PetscArrayzero - Zeros an array in memory. 1759580bdb30SBarry Smith 1760580bdb30SBarry Smith Synopsis: 1761580bdb30SBarry Smith #include <petscsys.h> 1762580bdb30SBarry Smith PetscErrorCode PetscArrayzero(anytype *str1,size_t cnt) 1763580bdb30SBarry Smith 1764580bdb30SBarry Smith Not Collective 1765580bdb30SBarry Smith 1766580bdb30SBarry Smith Input Parameters: 1767580bdb30SBarry Smith + str1 - array 1768580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the array 1769580bdb30SBarry Smith 1770580bdb30SBarry Smith Level: intermediate 1771580bdb30SBarry Smith 1772580bdb30SBarry Smith Note: 177387497f52SBarry Smith This routine is a preferred replacement to `PetscMemzero()` 1774580bdb30SBarry Smith 1775db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, `PetscArraymove()` 1776580bdb30SBarry Smith M*/ 17779e2232c7SLisandro Dalcin #define PetscArrayzero(str1, cnt) PetscMemzero(str1, (size_t)(cnt) * sizeof(*(str1))) 1778580bdb30SBarry Smith 1779447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER) 1780447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d) 1781447bcd8fSJacob Faibussowitsch #else 1782d382aafbSBarry Smith /*MC 1783d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1784d382aafbSBarry Smith 1785eca87e8dSBarry Smith Synopsis: 1786aaa7dc30SBarry Smith #include <petscsys.h> 1787eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1788eca87e8dSBarry Smith 1789d382aafbSBarry Smith Not Collective 1790d382aafbSBarry Smith 1791d382aafbSBarry Smith Input Parameters: 1792d382aafbSBarry Smith + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 1793d382aafbSBarry Smith . n - number of elements to fetch 1794d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 179550d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1796d382aafbSBarry Smith 1797d382aafbSBarry Smith Level: developer 1798d382aafbSBarry Smith 1799d382aafbSBarry Smith Notes: 1800d382aafbSBarry Smith The last two arguments (rw and t) must be compile-time constants. 1801d382aafbSBarry Smith 180250d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 180350d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 180487497f52SBarry 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). 180587497f52SBarry 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. 180687497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 180787497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1808d382aafbSBarry Smith 1809d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1810d382aafbSBarry Smith address). 1811d382aafbSBarry Smith 1812d382aafbSBarry Smith M*/ 18139371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 18149371c9d4SSatish Balay do { \ 1815d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1816d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1817d382aafbSBarry Smith } while (0) 1818447bcd8fSJacob Faibussowitsch #endif 1819d382aafbSBarry Smith /* 1820d382aafbSBarry Smith Determine if some of the kernel computation routines use 1821d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1822d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1823d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1824e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1825d382aafbSBarry Smith */ 1826d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1827d382aafbSBarry Smith 1828d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1829d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1830d382aafbSBarry Smith #endif 1831d382aafbSBarry Smith 18325a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 18335a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1834d382aafbSBarry Smith #endif 1835d382aafbSBarry Smith 1836d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1837d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1838d382aafbSBarry Smith #endif 1839d382aafbSBarry Smith 1840d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1841d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1842d382aafbSBarry Smith #endif 1843d382aafbSBarry Smith 1844d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1845d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM 1846d382aafbSBarry Smith #endif 1847d382aafbSBarry Smith 1848d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1849d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1850d382aafbSBarry Smith #endif 1851d382aafbSBarry Smith 1852d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1853d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1854d382aafbSBarry Smith #endif 1855d382aafbSBarry Smith 1856d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1857d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1858d382aafbSBarry Smith #endif 1859d382aafbSBarry Smith 1860d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1861d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1862d382aafbSBarry Smith #endif 1863d382aafbSBarry Smith 1864d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1865d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1866d382aafbSBarry Smith #endif 1867d382aafbSBarry Smith 1868d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1869d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1870d382aafbSBarry Smith #endif 1871d382aafbSBarry Smith 1872d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1873d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1874d382aafbSBarry Smith #endif 1875d382aafbSBarry Smith 1876d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1877d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1878d382aafbSBarry Smith #endif 1879d382aafbSBarry Smith 1880d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1881d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1882d382aafbSBarry Smith #endif 1883d382aafbSBarry Smith 1884d382aafbSBarry Smith #endif 1885d382aafbSBarry Smith 1886d382aafbSBarry Smith /* 1887d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1888d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1889d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1890d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1891d382aafbSBarry Smith ugly extern "C" {} wrappers. 1892d382aafbSBarry Smith */ 1893d382aafbSBarry Smith #if defined(__cplusplus) 1894d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1895d382aafbSBarry Smith #define EXTERN_C_END } 1896d382aafbSBarry Smith #else 1897d382aafbSBarry Smith #define EXTERN_C_BEGIN 1898d382aafbSBarry Smith #define EXTERN_C_END 1899d382aafbSBarry Smith #endif 1900d382aafbSBarry Smith 1901d382aafbSBarry Smith /* --------------------------------------------------------------------*/ 1902d382aafbSBarry Smith 1903d382aafbSBarry Smith /*MC 1904d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1905d382aafbSBarry Smith communication 1906d382aafbSBarry Smith 1907d382aafbSBarry Smith Level: beginner 1908d382aafbSBarry Smith 1909d382aafbSBarry Smith Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1910d382aafbSBarry Smith 1911db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1912d382aafbSBarry Smith M*/ 1913d382aafbSBarry Smith 1914d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 191593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 191693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 191793d501b3SJacob 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); 191893d501b3SJacob 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); 191993d501b3SJacob 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); 192093d501b3SJacob 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); 1921d382aafbSBarry Smith #endif 1922d382aafbSBarry Smith 1923d382aafbSBarry Smith /* the following petsc_static_inline require petscerror.h */ 1924d382aafbSBarry Smith 1925d382aafbSBarry Smith /* Limit MPI to 32-bits */ 1926d382aafbSBarry Smith #define PETSC_MPI_INT_MAX 2147483647 1927d382aafbSBarry Smith #define PETSC_MPI_INT_MIN -2147483647 1928d382aafbSBarry Smith /* Limit BLAS to 32-bits */ 1929d382aafbSBarry Smith #define PETSC_BLAS_INT_MAX 2147483647 1930d382aafbSBarry Smith #define PETSC_BLAS_INT_MIN -2147483647 1931eee0c0a6SToby Isaac #define PETSC_CUBLAS_INT_MAX 2147483647 193247d993e7Ssuyashtn #define PETSC_HIPBLAS_INT_MAX 2147483647 1933d382aafbSBarry Smith 193461b0d812SBarry Smith /*@C 193587497f52SBarry Smith PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an 193687497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1937c73702f5SBarry Smith 1938c73702f5SBarry Smith Not Collective 1939c73702f5SBarry Smith 1940c73702f5SBarry Smith Input Parameter: 194187497f52SBarry Smith . a - the `PetscInt64` value 1942c73702f5SBarry Smith 1943c73702f5SBarry Smith Output Parameter: 194487497f52SBarry Smith . b - the resulting `PetscInt` value 1945c73702f5SBarry Smith 1946c73702f5SBarry Smith Level: advanced 1947c73702f5SBarry Smith 194887497f52SBarry Smith Notes: 194987497f52SBarry 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 1950c73702f5SBarry Smith 1951c73702f5SBarry Smith Not available from Fortran 1952c73702f5SBarry Smith 1953db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1954c73702f5SBarry Smith @*/ 1955d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1956d71ae5a4SJacob Faibussowitsch { 1957c73702f5SBarry Smith PetscFunctionBegin; 1958c73702f5SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 19593ca90d2dSJacob Faibussowitsch if (a > PETSC_MAX_INT) { 19603ca90d2dSJacob Faibussowitsch *b = 0; 196198921bdaSJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 19623ca90d2dSJacob Faibussowitsch } 1963c73702f5SBarry Smith #endif 1964c73702f5SBarry Smith *b = (PetscInt)(a); 1965c73702f5SBarry Smith PetscFunctionReturn(0); 1966c73702f5SBarry Smith } 1967c73702f5SBarry Smith 1968c73702f5SBarry Smith /*@C 196987497f52SBarry Smith PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an 197087497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1971981bb840SJunchao Zhang 1972981bb840SJunchao Zhang Not Collective 1973981bb840SJunchao Zhang 1974981bb840SJunchao Zhang Input Parameter: 197587497f52SBarry Smith . a - the `PetscCount` value 1976981bb840SJunchao Zhang 1977981bb840SJunchao Zhang Output Parameter: 197887497f52SBarry Smith . b - the resulting `PetscInt` value 1979981bb840SJunchao Zhang 1980981bb840SJunchao Zhang Level: advanced 1981981bb840SJunchao Zhang 1982981bb840SJunchao Zhang Notes: 1983981bb840SJunchao Zhang 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 1984981bb840SJunchao Zhang 1985981bb840SJunchao Zhang Not available from Fortran 1986981bb840SJunchao Zhang 1987db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1988981bb840SJunchao Zhang @*/ 1989d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 1990d71ae5a4SJacob Faibussowitsch { 1991981bb840SJunchao Zhang PetscFunctionBegin; 1992981bb840SJunchao Zhang if (sizeof(PetscCount) > sizeof(PetscInt) && a > PETSC_MAX_INT) { 1993981bb840SJunchao Zhang *b = 0; 1994981bb840SJunchao Zhang SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 1995981bb840SJunchao Zhang } 1996981bb840SJunchao Zhang *b = (PetscInt)(a); 1997981bb840SJunchao Zhang PetscFunctionReturn(0); 1998981bb840SJunchao Zhang } 1999981bb840SJunchao Zhang 2000981bb840SJunchao Zhang /*@C 200187497f52SBarry Smith PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an 200287497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 200361b0d812SBarry Smith 200461b0d812SBarry Smith Not Collective 200561b0d812SBarry Smith 200661b0d812SBarry Smith Input Parameter: 200787497f52SBarry Smith . a - the `PetscInt` value 200861b0d812SBarry Smith 200961b0d812SBarry Smith Output Parameter: 201087497f52SBarry Smith . b - the resulting `PetscBLASInt` value 201161b0d812SBarry Smith 201261b0d812SBarry Smith Level: advanced 201361b0d812SBarry Smith 20140bc7d38cSBarry Smith Notes: 20151fd49c25SBarry Smith Not available from Fortran 201687497f52SBarry Smith 2017f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 20181fd49c25SBarry Smith 2019db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 202061b0d812SBarry Smith @*/ 2021d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 2022d71ae5a4SJacob Faibussowitsch { 2023c5df96a5SBarry Smith PetscFunctionBegin; 202454c59aa7SJacob Faibussowitsch *b = 0; 202554c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 202654c59aa7SJacob 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); 202754c59aa7SJacob Faibussowitsch } 202854c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 2029c73702f5SBarry Smith *b = (PetscBLASInt)(a); 2030c5df96a5SBarry Smith PetscFunctionReturn(0); 2031c5df96a5SBarry Smith } 2032c5df96a5SBarry Smith 203361b0d812SBarry Smith /*@C 203487497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 2035eee0c0a6SToby Isaac 2036eee0c0a6SToby Isaac Not Collective 2037eee0c0a6SToby Isaac 2038eee0c0a6SToby Isaac Input Parameter: 203987497f52SBarry Smith . a - the `PetscInt` value 2040eee0c0a6SToby Isaac 2041eee0c0a6SToby Isaac Output Parameter: 204287497f52SBarry Smith . b - the resulting `PetscCuBLASInt` value 2043eee0c0a6SToby Isaac 2044eee0c0a6SToby Isaac Level: advanced 2045eee0c0a6SToby Isaac 2046eee0c0a6SToby Isaac Notes: 2047eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 2048eee0c0a6SToby Isaac 2049db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 2050eee0c0a6SToby Isaac @*/ 2051d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 2052d71ae5a4SJacob Faibussowitsch { 2053eee0c0a6SToby Isaac PetscFunctionBegin; 205454c59aa7SJacob Faibussowitsch *b = 0; 205554c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32 bit integers.", a); 205654c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to cuBLAS routine"); 2057eee0c0a6SToby Isaac *b = (PetscCuBLASInt)(a); 2058eee0c0a6SToby Isaac PetscFunctionReturn(0); 2059eee0c0a6SToby Isaac } 2060eee0c0a6SToby Isaac 2061eee0c0a6SToby Isaac /*@C 206247d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 206347d993e7Ssuyashtn 206447d993e7Ssuyashtn Not Collective 206547d993e7Ssuyashtn 206647d993e7Ssuyashtn Input Parameter: 206747d993e7Ssuyashtn . a - the `PetscInt` value 206847d993e7Ssuyashtn 206947d993e7Ssuyashtn Output Parameter: 207047d993e7Ssuyashtn . b - the resulting `PetscHipBLASInt` value 207147d993e7Ssuyashtn 207247d993e7Ssuyashtn Level: advanced 207347d993e7Ssuyashtn 207447d993e7Ssuyashtn Notes: 207547d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 207647d993e7Ssuyashtn 207747d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 207847d993e7Ssuyashtn @*/ 207947d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b) 208047d993e7Ssuyashtn { 208147d993e7Ssuyashtn PetscFunctionBegin; 208247d993e7Ssuyashtn *b = 0; 208347d993e7Ssuyashtn if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32 bit integers.", a); 208447d993e7Ssuyashtn PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to hipBLAS routine"); 208547d993e7Ssuyashtn *b = (PetscHipBLASInt)(a); 208647d993e7Ssuyashtn PetscFunctionReturn(0); 208747d993e7Ssuyashtn } 208847d993e7Ssuyashtn 208947d993e7Ssuyashtn /*@C 209047d993e7Ssuyashtn PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an 209147d993e7Ssuyashtn error if the PetscMPIInt is not large enough to hold the number. 209261b0d812SBarry Smith 209361b0d812SBarry Smith Not Collective 209461b0d812SBarry Smith 209561b0d812SBarry Smith Input Parameter: 209687497f52SBarry Smith . a - the `PetscInt` value 209761b0d812SBarry Smith 209861b0d812SBarry Smith Output Parameter: 209987497f52SBarry Smith . b - the resulting `PetscMPIInt` value 210061b0d812SBarry Smith 210161b0d812SBarry Smith Level: advanced 210261b0d812SBarry Smith 21031fd49c25SBarry Smith Not available from Fortran 21041fd49c25SBarry Smith 2105db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 210661b0d812SBarry Smith @*/ 2107d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 2108d71ae5a4SJacob Faibussowitsch { 21094dc2109aSBarry Smith PetscFunctionBegin; 211054c59aa7SJacob Faibussowitsch *b = 0; 211154c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_MPI_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for MPI buffer length. We currently only support 32 bit integers", a); 2112c73702f5SBarry Smith *b = (PetscMPIInt)(a); 21134dc2109aSBarry Smith PetscFunctionReturn(0); 21144dc2109aSBarry Smith } 21154dc2109aSBarry Smith 2116bafee8b4SSatish Balay #define PetscInt64Mult(a, b) ((PetscInt64)(a)) * ((PetscInt64)(b)) 21172f18eb33SBarry Smith 21182f18eb33SBarry Smith /*@C 21192f18eb33SBarry Smith 212087497f52SBarry Smith PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive `PetscInt` and truncates the value to slightly less than the maximal possible value 21212f18eb33SBarry Smith 21222f18eb33SBarry Smith Not Collective 21232f18eb33SBarry Smith 2124d8d19677SJose E. Roman Input Parameters: 212587497f52SBarry Smith + a - the `PetscReal` value 21262f18eb33SBarry Smith - b - the second value 21272f18eb33SBarry Smith 2128390e1bf2SBarry Smith Returns: 212987497f52SBarry Smith the result as a `PetscInt` value 21302f18eb33SBarry Smith 213187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 213287497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate to fit a `PetscInt` 213387497f52SBarry 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` 21342f18eb33SBarry Smith 2135e28ce29aSPatrick Sanan Developers Note: 213687497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21372f18eb33SBarry Smith 21382f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21392f18eb33SBarry Smith 21401fd49c25SBarry Smith Not available from Fortran 21411fd49c25SBarry Smith 21422f18eb33SBarry Smith Level: advanced 21432f18eb33SBarry Smith 2144db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21452f18eb33SBarry Smith @*/ 2146d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 2147d71ae5a4SJacob Faibussowitsch { 21485f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 21492f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21502f18eb33SBarry Smith return (PetscInt)r; 21512f18eb33SBarry Smith } 21522f18eb33SBarry Smith 21532f18eb33SBarry Smith /*@C 21542f18eb33SBarry Smith 215587497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 21562f18eb33SBarry Smith 21572f18eb33SBarry Smith Not Collective 21582f18eb33SBarry Smith 2159d8d19677SJose E. Roman Input Parameters: 21602f18eb33SBarry Smith + a - the PetscInt value 21612f18eb33SBarry Smith - b - the second value 21622f18eb33SBarry Smith 2163390e1bf2SBarry Smith Returns: 216487497f52SBarry Smith the result as a `PetscInt` value 21652f18eb33SBarry Smith 216687497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 216787497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 216887497f52SBarry 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` 21692f18eb33SBarry Smith 21701fd49c25SBarry Smith Not available from Fortran 21711fd49c25SBarry Smith 217287497f52SBarry Smith Developers Note: 217387497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21742f18eb33SBarry Smith 21752f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21762f18eb33SBarry Smith 21772f18eb33SBarry Smith Level: advanced 21782f18eb33SBarry Smith 2179db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21802f18eb33SBarry Smith @*/ 2181d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 2182d71ae5a4SJacob Faibussowitsch { 21835f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 21842f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21852f18eb33SBarry Smith return (PetscInt)r; 21862f18eb33SBarry Smith } 21872f18eb33SBarry Smith 2188f91af8c7SBarry Smith /*@C 2189f91af8c7SBarry Smith 219087497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 2191f91af8c7SBarry Smith 2192f91af8c7SBarry Smith Not Collective 2193f91af8c7SBarry Smith 2194d8d19677SJose E. Roman Input Parameters: 219587497f52SBarry Smith + a - the `PetscInt` value 2196f91af8c7SBarry Smith - b - the second value 2197f91af8c7SBarry Smith 2198390e1bf2SBarry Smith Returns: 219987497f52SBarry Smith the result as a `PetscInt` value 2200f91af8c7SBarry Smith 220187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 220287497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 220387497f52SBarry 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` 2204f91af8c7SBarry Smith 2205f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2206f91af8c7SBarry Smith 2207f5f57ec0SBarry Smith Not available from Fortran 2208f5f57ec0SBarry Smith 2209f91af8c7SBarry Smith Level: advanced 2210f91af8c7SBarry Smith 2211db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2212f91af8c7SBarry Smith @*/ 2213d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 2214d71ae5a4SJacob Faibussowitsch { 22155f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 2216f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 2217f91af8c7SBarry Smith return (PetscInt)r; 2218f91af8c7SBarry Smith } 2219f91af8c7SBarry Smith 22202f18eb33SBarry Smith /*@C 22212f18eb33SBarry Smith 222287497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 22232f18eb33SBarry Smith 22242f18eb33SBarry Smith Not Collective 22252f18eb33SBarry Smith 2226d8d19677SJose E. Roman Input Parameters: 222787497f52SBarry Smith + a - the `PetscInt` value 22282f18eb33SBarry Smith - b - the second value 22292f18eb33SBarry Smith 2230d8d19677SJose E. Roman Output Parameter: 223187497f52SBarry 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 22322f18eb33SBarry Smith 223387497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 223487497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 22352f18eb33SBarry Smith 2236f5f57ec0SBarry Smith Not available from Fortran 2237f5f57ec0SBarry Smith 223887497f52SBarry Smith Developers Note: 223987497f52SBarry Smith We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks. 22402f18eb33SBarry Smith 22412f18eb33SBarry Smith Level: advanced 22422f18eb33SBarry Smith 2243db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 22442f18eb33SBarry Smith @*/ 2245d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 2246d71ae5a4SJacob Faibussowitsch { 2247bafee8b4SSatish Balay PetscInt64 r; 22482f18eb33SBarry Smith 22492f18eb33SBarry Smith PetscFunctionBegin; 2250bafee8b4SSatish Balay r = PetscInt64Mult(a, b); 22512f18eb33SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22522c71b3e2SJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %d %d overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 22532f18eb33SBarry Smith #endif 2254f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 2255f91af8c7SBarry Smith PetscFunctionReturn(0); 2256f91af8c7SBarry Smith } 2257f91af8c7SBarry Smith 2258f91af8c7SBarry Smith /*@C 2259f91af8c7SBarry Smith 226087497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 2261f91af8c7SBarry Smith 2262f91af8c7SBarry Smith Not Collective 2263f91af8c7SBarry Smith 2264d8d19677SJose E. Roman Input Parameters: 226587497f52SBarry Smith + a - the `PetscInt` value 2266f91af8c7SBarry Smith - b - the second value 2267f91af8c7SBarry Smith 2268d8d19677SJose E. Roman Output Parameter: 226987497f52SBarry 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 2270f91af8c7SBarry Smith 227187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64` 227287497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2273f91af8c7SBarry Smith 2274f5f57ec0SBarry Smith Not available from Fortran 2275f5f57ec0SBarry Smith 2276f91af8c7SBarry Smith Level: advanced 2277f91af8c7SBarry Smith 2278db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2279f91af8c7SBarry Smith @*/ 2280d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 2281d71ae5a4SJacob Faibussowitsch { 2282bafee8b4SSatish Balay PetscInt64 r; 2283f91af8c7SBarry Smith 2284f91af8c7SBarry Smith PetscFunctionBegin; 2285bafee8b4SSatish Balay r = ((PetscInt64)a) + ((PetscInt64)b); 2286f91af8c7SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22872c71b3e2SJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %d %d overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 2288f91af8c7SBarry Smith #endif 2289f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 22902f18eb33SBarry Smith PetscFunctionReturn(0); 22912f18eb33SBarry Smith } 2292c5df96a5SBarry Smith 2293d382aafbSBarry Smith /* 22942981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2295d382aafbSBarry Smith */ 2296d382aafbSBarry Smith #if defined(hz) 2297d382aafbSBarry Smith #undef hz 2298d382aafbSBarry Smith #endif 2299d382aafbSBarry Smith 230015a5570dSLisandro Dalcin #include <limits.h> 230115a5570dSLisandro Dalcin 230215a5570dSLisandro Dalcin /* The number of bits in a byte */ 230315a5570dSLisandro Dalcin 230415a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT 230515a5570dSLisandro Dalcin 2306d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2307d382aafbSBarry Smith #include <sys/types.h> 2308d382aafbSBarry Smith #endif 2309d382aafbSBarry Smith 2310d382aafbSBarry Smith /*MC 2311d382aafbSBarry Smith 231266d79e26SBarry 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++ 231366d79e26SBarry Smith and Fortran compilers when petscsys.h is included. 231466d79e26SBarry Smith 23156274ba02SSatish 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> 231666d79e26SBarry Smith 231766d79e26SBarry 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) 231866d79e26SBarry Smith 231966d79e26SBarry 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 232066d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 232166d79e26SBarry Smith 232266d79e26SBarry 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 232366d79e26SBarry Smith 232466d79e26SBarry 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), 232566d79e26SBarry 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 232666d79e26SBarry Smith version number (x.y.z). 232766d79e26SBarry Smith 232887497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 232966d79e26SBarry Smith 233087497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 233166d79e26SBarry Smith 233287497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 233366d79e26SBarry Smith 233487497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 233566d79e26SBarry Smith 233687497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 233766d79e26SBarry Smith 2338cbc12506SBarry Smith Level: intermediate 233966d79e26SBarry Smith 234066d79e26SBarry Smith M*/ 234166d79e26SBarry Smith 2342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 2343014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 2344014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 2345014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 2346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2347014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 234827710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 23495f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 2350d382aafbSBarry Smith 23516a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 235262e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 23536a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 23546a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 2355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 235662e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 235762e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 2358ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 235922ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 2360b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2362f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 236360e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 2364d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 2365014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 2367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 2368981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 23696c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 2370981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 237117d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 237217d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 2373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 23745569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 2375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 237617df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 237839f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2380745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 238139f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 23856c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 23866c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2387e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2388ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2389ce605777SToby Isaac 23904d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2391676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2392676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2393676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 23944d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2395676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2396676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2397676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2398676f2a66SJacob Faibussowitsch 2399014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2401d382aafbSBarry Smith 240276bdecfbSBarry Smith /*J 2403d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2404d382aafbSBarry Smith 2405d382aafbSBarry Smith Level: beginner 2406d382aafbSBarry Smith 2407e28ce29aSPatrick Sanan Notes: 240887497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 240925ccb61fSToby Isaac with the option --download-sprng or --download-random123 2410d382aafbSBarry Smith 2411db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 241276bdecfbSBarry Smith J*/ 241319fd82e9SBarry Smith typedef const char *PetscRandomType; 2414d382aafbSBarry Smith #define PETSCRAND "rand" 2415d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2416d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2417c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 241825ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2419808ba619SStefano Zampini #define PETSCCURAND "curand" 2420d382aafbSBarry Smith 2421d382aafbSBarry Smith /* Logging support */ 2422014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2423d382aafbSBarry Smith 2424607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2425d382aafbSBarry Smith 2426d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2427140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2428d382aafbSBarry Smith 2429bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 243019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2431014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 243219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2433fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2435d382aafbSBarry Smith 2436014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2437014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2438014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2439808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2440808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2441014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2442014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2443014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2444014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2445014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2446014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2447d382aafbSBarry Smith 2448014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2449014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2450014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2451014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2453014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2454014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 245597540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 24568a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 245797540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2458d382aafbSBarry Smith 2459d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2460d71ae5a4SJacob Faibussowitsch { 24619371c9d4SSatish Balay long _petsc_v = 1; 24629371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 24639371c9d4SSatish Balay } 246430815ce0SLisandro Dalcin 24659860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 24669860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2467f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2468f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2469014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2470014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2471014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2475014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2476c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2477e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2478c891a504SStefano Zampini #endif 2479d382aafbSBarry Smith 2480014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2481014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2483d382aafbSBarry Smith 2484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2487014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2488014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2489014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 24902a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2491d382aafbSBarry Smith 2492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2494014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2495014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2496014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 249793d501b3SJacob 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); 249893d501b3SJacob 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); 249993d501b3SJacob 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); 2500d382aafbSBarry Smith 25016145cd65SJed Brown PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[]; 25026145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 25036145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 25046145cd65SJed Brown 2505014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2506d382aafbSBarry Smith 2507ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2508ce94432eSBarry Smith 250945487dadSJed Brown PETSC_EXTERN const char *const PetscSubcommTypes[]; 251045487dadSJed Brown 2511d382aafbSBarry Smith struct _n_PetscSubcomm { 2512d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2513d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2514306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 251545487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 251645487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2517708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 251845487dadSJed Brown PetscSubcommType type; 2519e5acf8a4SHong Zhang char *subcommprefix; 2520d382aafbSBarry Smith }; 2521d382aafbSBarry Smith 2522d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2523d71ae5a4SJacob Faibussowitsch { 25249371c9d4SSatish Balay return scomm->parent; 25259371c9d4SSatish Balay } 2526d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2527d71ae5a4SJacob Faibussowitsch { 25289371c9d4SSatish Balay return scomm->child; 25299371c9d4SSatish Balay } 2530d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2531d71ae5a4SJacob Faibussowitsch { 25329371c9d4SSatish Balay return scomm->dupparent; 25339371c9d4SSatish Balay } 2534014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2535014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2536014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2537014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 253865d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2539053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2540f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2541e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2542a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2543a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2544a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2545d382aafbSBarry Smith 25469962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 25479962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 25489962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 25499962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 25509962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 25519962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 25529962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 25539962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 25549962606eSBarry Smith 25555e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 25565f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 25575f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25585f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25595f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 25605e71baefSBarry Smith 2561a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2562a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2563a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2564a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2565a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2566a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2567a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2568a32e93adSJunchao Zhang 256913e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 25700f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 257113e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2572137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2573137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2574137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 257513e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 257613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 25770f453b92SJed Brown 2578471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2579471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2580471ecdacSJed Brown * possible. */ 2581d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2582d71ae5a4SJacob Faibussowitsch { 25839371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 25849371c9d4SSatish Balay } 2585d382aafbSBarry Smith 25869de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 25879de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 25889de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 25899de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 25909de0f6ecSBarry Smith 2591ace2fbaeSBarry Smith #include <stdarg.h> 2592ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2593ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2594ace2fbaeSBarry Smith 2595268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2596fbfcfee5SBarry Smith 25971f817a21SBarry Smith /*@C 25981f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 25991f817a21SBarry Smith 260087497f52SBarry Smith Not Collective - only what is registered on rank 0 of `PETSC_COMM_WORLD` will be printed 26011f817a21SBarry Smith 26021f817a21SBarry Smith Input Parameters: 260335cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely 260487497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 26051f817a21SBarry Smith 26063c7db156SBarry Smith Options Database: Key 26073c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation 26083c7db156SBarry Smith 2609850545d0SSatish Balay Level: intermediate 2610850545d0SSatish Balay 26113c7db156SBarry Smith Fortran Note: 2612f5f57ec0SBarry Smith Not available from Fortran 2613f5f57ec0SBarry Smith 26141f817a21SBarry Smith @*/ 2615d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2616d71ae5a4SJacob Faibussowitsch { 2617dff31646SBarry Smith size_t len; 2618dff31646SBarry Smith char *vstring; 2619dff31646SBarry Smith 26201f817a21SBarry Smith PetscFunctionBegin; 26218d3683fcSBarry Smith if (set && *set) PetscFunctionReturn(0); 26229566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 26239566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 26249566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2625dff31646SBarry Smith if (set) *set = PETSC_TRUE; 26261f817a21SBarry Smith PetscFunctionReturn(0); 2627dff31646SBarry Smith } 2628dff31646SBarry Smith 2629d8174014SToby Isaac PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c); 2630fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2631fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2632f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2633fe278a28SBarry Smith 2634f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2635f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 2636b967cddfSBarry Smith 26379f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 26389f4d3c52SBarry Smith 263904102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *); 2640763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *); 2641dff31646SBarry Smith 264268e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 26435dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2644d382aafbSBarry Smith 2645b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2646d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2647d71ae5a4SJacob Faibussowitsch { 2648df05ca09SBarry Smith unsigned int c, hash = 5381; 2649df05ca09SBarry Smith 2650503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2651df05ca09SBarry Smith return hash; 2652df05ca09SBarry Smith } 265377a5e07dSBarry Smith 265477a5e07dSBarry Smith /*MC 265587497f52SBarry Smith MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 265687497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 265787497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 265877a5e07dSBarry Smith 2659d083f849SBarry Smith Collective 266077a5e07dSBarry Smith 266177a5e07dSBarry Smith Synopsis: 266277a5e07dSBarry Smith #include <petscsys.h> 266377a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 266477a5e07dSBarry Smith 266577a5e07dSBarry Smith Input Parameters: 2666df05ca09SBarry Smith + a - pointer to the input data to be reduced 2667df05ca09SBarry Smith . c - the number of MPI data items in a and b 266887497f52SBarry Smith . d - the MPI datatype, for example `MPI_INT` 266987497f52SBarry Smith . e - the MPI operation, for example `MPI_SUM` 2670df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 267177a5e07dSBarry Smith 267277a5e07dSBarry Smith Output Parameter: 2673df05ca09SBarry Smith . b - the reduced values 267477a5e07dSBarry Smith 2675e28ce29aSPatrick Sanan Notes: 267687497f52SBarry Smith In optimized mode this directly calls `MPI_Allreduce()` 267777a5e07dSBarry Smith 2678df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2679df05ca09SBarry Smith 268087497f52SBarry 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 2681df05ca09SBarry Smith 268277a5e07dSBarry Smith Level: developer 268377a5e07dSBarry Smith 2684db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 268577a5e07dSBarry Smith M*/ 26869371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 26879371c9d4SSatish Balay PetscMacroReturnStandard(PetscMPIInt a_b1[6], a_b2[6]; int _mpiu_allreduce_c_int = (int)c; a_b1[0] = -(PetscMPIInt)__LINE__; a_b1[1] = -a_b1[0]; a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); a_b1[3] = -a_b1[2]; a_b1[4] = -(PetscMPIInt)(c); a_b1[5] = -a_b1[4]; PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); PetscCheck(-a_b2[4] == a_b2[5], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm)));) 2688b2566f29SBarry Smith #else 26891c2dc1cbSBarry Smith #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm)))) 2690b2566f29SBarry Smith #endif 2691b2566f29SBarry Smith 2692b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 26938198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 26948198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 26952f065d89SBarry Smith #endif 26968198064fSBarry Smith 2697cd88fca5SStefano Zampini /* this is a vile hack */ 2698cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 26999371c9d4SSatish 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) 2700cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2701cd88fca5SStefano Zampini #endif 2702961fb248SStefano Zampini #endif 2703cd88fca5SStefano Zampini 270412801b39SBarry Smith /* 270560fbe2beSVaclav Hapla List of external packages and queries on it 270660fbe2beSVaclav Hapla */ 270760fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 270860fbe2beSVaclav Hapla 2709a52b435bSMark Adams /* 2710a52b435bSMark Adams OpenMP support 2711a52b435bSMark Adams */ 2712a52b435bSMark Adams #if defined(_OPENMP) 2713a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__)) 2714a52b435bSMark Adams #else // no OpenMP so no threads 2715a52b435bSMark Adams #define PetscPragmaOMP(...) 2716a52b435bSMark Adams #endif 2717a52b435bSMark Adams 2718f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2719f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2720f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2721f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2722d382aafbSBarry Smith #endif 2723