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. 4d382aafbSBarry Smith */ 56524c165SJacob Faibussowitsch #ifndef PETSCSYS_H 626bd1501SBarry Smith #define PETSCSYS_H 73ca90d2dSJacob Faibussowitsch 8d382aafbSBarry Smith /* ========================================================================== */ 9d382aafbSBarry Smith /* 10d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 111c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 121c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules. 131c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 141cc8b206SBarry Smith directory as the other PETSc include files. 15d382aafbSBarry Smith */ 162c8e378dSBarry Smith #include <petscconf.h> 171c77a0c5SBarry Smith #include <petscconf_poison.h> 182c8e378dSBarry Smith #include <petscfix.h> 19bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2033bb201bSJacob Faibussowitsch 21ac09b921SBarry Smith /* SUBMANSEC = Sys */ 22ac09b921SBarry Smith 2373fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2473fca5a0SBarry Smith /* 2573fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2673fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2773fca5a0SBarry Smith */ 28216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 2973fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L 3073fca5a0SBarry Smith #endif 31216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3273fca5a0SBarry Smith #define _BSD_SOURCE 3373fca5a0SBarry Smith #endif 3407f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3507f00807SSatish Balay #define _DEFAULT_SOURCE 3607f00807SSatish Balay #endif 37ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 38ea0fecefSShri Abhyankar #define _GNU_SOURCE 39ea0fecefSShri Abhyankar #endif 4073fca5a0SBarry Smith #endif 4173fca5a0SBarry Smith 42df4397b0SStefano Zampini #include <petscsystypes.h> 43df4397b0SStefano Zampini 44d382aafbSBarry Smith /* ========================================================================== */ 45d382aafbSBarry Smith 46d382aafbSBarry Smith /* 47d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 48d382aafbSBarry Smith 49d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 50d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 51d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 52d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 53d382aafbSBarry Smith mpicxx.h directly in their code 54d382aafbSBarry Smith */ 55fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 56d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1 57fa9e63e2SJed Brown #endif 58fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 59d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1 60fa9e63e2SJed Brown #endif 61e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 62e771154cSJed Brown #include <petsc/mpiuni/mpi.h> 63e771154cSJed Brown #else 642c8e378dSBarry Smith #include <mpi.h> 65e771154cSJed Brown #endif 6665013866SBarry Smith 67d382aafbSBarry Smith /* 68a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 69a7886beaSBarry Smith This usually happens because 70a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 71a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 72a7886beaSBarry Smith */ 73a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 746524c165SJacob Faibussowitsch #ifndef MPIUNI_H 75a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 76a7886beaSBarry Smith #endif 7741f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 7841f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 7941f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 8041f4af4cSSatish Balay #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 8141f4af4cSSatish 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" 8241f4af4cSSatish Balay #endif 8341f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 8441f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8541f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 8641f4af4cSSatish Balay #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 8741f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 8841f4af4cSSatish Balay #endif 89a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 9041f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 91a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 921c284764SMin 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) 93a7886beaSBarry Smith #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 94a7886beaSBarry Smith #endif 95a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 96a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 97a7886beaSBarry Smith #error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h" 981c284764SMin 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) 99c3ac57cfSSatish Balay #error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version" 100a7886beaSBarry Smith #endif 101c93fae50SJacob Faibussowitsch #define PETSC_MPI_COMM_FMT "p" 102c93fae50SJacob Faibussowitsch #define PETSC_MPI_WIN_FMT "p" 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 113c93fae50SJacob Faibussowitsch /* Format specifier for printing MPI_Comm (most implementations use 'int' as type) */ 114c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_COMM_FMT) 115c93fae50SJacob Faibussowitsch #define PETSC_MPI_COMM_FMT "d" 116c93fae50SJacob Faibussowitsch #endif 117c93fae50SJacob Faibussowitsch 118c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_WIN_FMT) 119c93fae50SJacob Faibussowitsch #define PETSC_MPI_WIN_FMT "d" 120c93fae50SJacob Faibussowitsch #endif 121c93fae50SJacob Faibussowitsch 122a7886beaSBarry Smith /* 1232981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 124d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 125d382aafbSBarry Smith */ 126d382aafbSBarry Smith #include <stdio.h> 127d382aafbSBarry Smith 128d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 129d382aafbSBarry Smith #if !defined(MPIAPI) 130d382aafbSBarry Smith #define MPIAPI 131d382aafbSBarry Smith #endif 132d382aafbSBarry Smith 13393d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 13493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 135e28ce29aSPatrick Sanan 136e28ce29aSPatrick Sanan /*MC 13787497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 138e28ce29aSPatrick Sanan 139e28ce29aSPatrick Sanan Notes: 14087497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 141e28ce29aSPatrick Sanan 142e28ce29aSPatrick Sanan Level: beginner 143e28ce29aSPatrick Sanan 144db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 145e28ce29aSPatrick Sanan M*/ 146e28ce29aSPatrick Sanan 1477cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 148b7b8f77aSBarry Smith 149d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 150bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 151a05e1a72SSatish Balay #define PetscInt_FMT PetscInt64_FMT 152d382aafbSBarry Smith #else 153d382aafbSBarry Smith #define MPIU_INT MPI_INT 154a05e1a72SSatish Balay #define PetscInt_FMT "d" 155d382aafbSBarry Smith #endif 156d382aafbSBarry Smith 157503cfb0cSBarry Smith /* 158503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 159503cfb0cSBarry Smith */ 16093d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 161d382aafbSBarry Smith 162d382aafbSBarry Smith /* 163d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 164d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 165d382aafbSBarry Smith */ 166014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 167d382aafbSBarry Smith 168d382aafbSBarry Smith /* 169d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 170d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 171d382aafbSBarry Smith */ 172014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 173d382aafbSBarry Smith 174c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */ 175c8b9133aSSatish Balay 1765c993f7fSStefano Zampini #if defined(__NEC__) 1775c993f7fSStefano Zampini #define PetscPragmaSIMD _Pragma("_NEC ivdep") 1785c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32) 179c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("vector") 1801dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI) 181c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("GCC ivdep") 182e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307 183e5518150SSatish Balay #if defined(_MSC_VER) 184160a5775SAli Reza Khaz'ali #define PetscPragmaSIMD __pragma(omp simd) 185e5518150SSatish Balay #else 186e5518150SSatish Balay #define PetscPragmaSIMD _Pragma("omp simd") 187e5518150SSatish Balay #endif 188c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR) 189c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("_CRI ivdep") 190c8b9133aSSatish Balay #else 191c8b9133aSSatish Balay #define PetscPragmaSIMD 192c8b9133aSSatish Balay #endif 193c8b9133aSSatish Balay 194d382aafbSBarry Smith /* 195d382aafbSBarry Smith Declare extern C stuff after including external header files 196d382aafbSBarry Smith */ 197d382aafbSBarry Smith 1986a6fc655SJed Brown PETSC_EXTERN const char *const PetscBools[]; 19970b3c8c7SBarry Smith 2006edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 2018b49ba18SBarry Smith /* 202390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 2038b49ba18SBarry Smith */ 2048b49ba18SBarry Smith #include <petscmath.h> 2058b49ba18SBarry Smith 2066a6fc655SJed Brown PETSC_EXTERN const char *const PetscCopyModes[]; 207d382aafbSBarry Smith 208d382aafbSBarry Smith /*MC 2090298fd71SBarry Smith PETSC_IGNORE - same as NULL, means PETSc will ignore this argument 210d382aafbSBarry Smith 211d382aafbSBarry Smith Level: beginner 212d382aafbSBarry Smith 213e28ce29aSPatrick Sanan Note: 21487497f52SBarry Smith Accepted by many PETSc functions to not set a parameter and instead use some default 215d382aafbSBarry Smith 21687497f52SBarry Smith Fortran Note: 21787497f52SBarry Smith This macro does not exist in Fortran; you must use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 218d382aafbSBarry Smith 219db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 220d382aafbSBarry Smith 221d382aafbSBarry Smith M*/ 2220298fd71SBarry Smith #define PETSC_IGNORE NULL 223d382aafbSBarry Smith 224c528d872SBarry Smith /* This is deprecated */ 225c528d872SBarry Smith #define PETSC_NULL NULL 226c528d872SBarry Smith 227d382aafbSBarry Smith /*MC 228557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 229557d4da8SBarry Smith where you wish PETSc to use the default. 230557d4da8SBarry Smith 231557d4da8SBarry Smith Level: beginner 232557d4da8SBarry Smith 233db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 234557d4da8SBarry Smith 235557d4da8SBarry Smith M*/ 236557d4da8SBarry Smith #define PETSC_DECIDE -1 237557d4da8SBarry Smith 238557d4da8SBarry Smith /*MC 239d382aafbSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter 240d382aafbSBarry Smith where you wish PETSc to compute the required value. 241d382aafbSBarry Smith 242d382aafbSBarry Smith Level: beginner 243d382aafbSBarry Smith 244e28ce29aSPatrick Sanan Developer Note: 24587497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 24687497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 247557d4da8SBarry Smith 248db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 249d382aafbSBarry Smith 250d382aafbSBarry Smith M*/ 251d382aafbSBarry Smith #define PETSC_DETERMINE PETSC_DECIDE 252d382aafbSBarry Smith 253d382aafbSBarry Smith /*MC 254557d4da8SBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter 255557d4da8SBarry Smith where you wish PETSc to use the default. 256557d4da8SBarry Smith 257557d4da8SBarry Smith Level: beginner 258557d4da8SBarry Smith 25987497f52SBarry Smith Fortran Note: 26087497f52SBarry Smith You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 261557d4da8SBarry Smith 262db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 263557d4da8SBarry Smith 264557d4da8SBarry Smith M*/ 265557d4da8SBarry Smith #define PETSC_DEFAULT -2 266557d4da8SBarry Smith 267557d4da8SBarry Smith /*MC 26887497f52SBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents 269ea8fe74dSBarry Smith all the processes that PETSc knows about. 270d382aafbSBarry Smith 271d382aafbSBarry Smith Level: beginner 272d382aafbSBarry Smith 273e28ce29aSPatrick Sanan Notes: 27487497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 27587497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 27687497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 27787497f52SBarry Smith PetscInitialize(), but after `MPI_Init()` has been called. 278a990b902SBarry Smith 27987497f52SBarry Smith The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()` 280a990b902SBarry Smith is called because it may not have a valid value yet. 281d382aafbSBarry Smith 282db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 283d382aafbSBarry Smith 284d382aafbSBarry Smith M*/ 285014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 286d382aafbSBarry Smith 287d382aafbSBarry Smith /*MC 28887497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 289d382aafbSBarry Smith 290d382aafbSBarry Smith Level: beginner 291d382aafbSBarry Smith 292e28ce29aSPatrick Sanan Notes: 293e28ce29aSPatrick Sanan Do not USE/access or set this variable before PetscInitialize() has been called. 294a990b902SBarry Smith 295db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 296d382aafbSBarry Smith 297d382aafbSBarry Smith M*/ 298d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 299d382aafbSBarry Smith 3006de5d289SStefano Zampini /*MC 3016de5d289SStefano Zampini PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes 30287497f52SBarry Smith MPI with `MPI_Init_thread()`. 3036de5d289SStefano Zampini 3046de5d289SStefano Zampini Level: beginner 3056de5d289SStefano Zampini 3066de5d289SStefano Zampini Notes: 30787497f52SBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`. 3086de5d289SStefano Zampini 309db781477SPatrick Sanan .seealso: `PetscInitialize()` 3106de5d289SStefano Zampini 3116de5d289SStefano Zampini M*/ 3126de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3136de5d289SStefano Zampini 314d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 3158ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 316014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 317014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3184cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 319d382aafbSBarry Smith 320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 32357f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 32457f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 325d382aafbSBarry Smith 32659e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 32759e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 32859e55d94SJunchao Zhang #endif 32959e55d94SJunchao Zhang 33071438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 33171438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 33271438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 33371438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 33471438e86SJunchao Zhang #endif 33571438e86SJunchao Zhang 336540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 337540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 338540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 339540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 340540e20f2SPierre Jolivet #endif 341540e20f2SPierre Jolivet 342d382aafbSBarry Smith /*MC 34387497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 344d382aafbSBarry Smith 345eca87e8dSBarry Smith Synopsis: 346aaa7dc30SBarry Smith #include <petscsys.h> 347eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 348eca87e8dSBarry Smith 349eca87e8dSBarry Smith Not Collective 350eca87e8dSBarry Smith 351d382aafbSBarry Smith Input Parameter: 352d382aafbSBarry Smith . m - number of bytes to allocate 353d382aafbSBarry Smith 354d382aafbSBarry Smith Output Parameter: 355d382aafbSBarry Smith . result - memory allocated 356d382aafbSBarry Smith 357d382aafbSBarry Smith Level: beginner 358d382aafbSBarry Smith 35949d7da52SJed Brown Notes: 36049d7da52SJed Brown Memory is always allocated at least double aligned 361d382aafbSBarry Smith 36287497f52SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`. 363d382aafbSBarry Smith 364db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 365d382aafbSBarry Smith 366d382aafbSBarry Smith M*/ 367071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 368d382aafbSBarry Smith 369d382aafbSBarry Smith /*MC 3703221ece2SMatthew G. Knepley PetscRealloc - Rellocates memory 3713221ece2SMatthew G. Knepley 3723221ece2SMatthew G. Knepley Synopsis: 3733221ece2SMatthew G. Knepley #include <petscsys.h> 3743221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3753221ece2SMatthew G. Knepley 3763221ece2SMatthew G. Knepley Not Collective 3773221ece2SMatthew G. Knepley 3783221ece2SMatthew G. Knepley Input Parameters: 3793221ece2SMatthew G. Knepley + m - number of bytes to allocate 38092f119d6SBarry Smith - result - previous memory 3813221ece2SMatthew G. Knepley 3823221ece2SMatthew G. Knepley Output Parameter: 3833221ece2SMatthew G. Knepley . result - new memory allocated 3843221ece2SMatthew G. Knepley 3853221ece2SMatthew G. Knepley Level: developer 3863221ece2SMatthew G. Knepley 3873221ece2SMatthew G. Knepley Notes: 3883221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 3893221ece2SMatthew G. Knepley 390db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 3913221ece2SMatthew G. Knepley 3923221ece2SMatthew G. Knepley M*/ 3933221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 3943221ece2SMatthew G. Knepley 3953221ece2SMatthew G. Knepley /*MC 39687497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 397d382aafbSBarry Smith 398d382aafbSBarry Smith Synopsis: 399aaa7dc30SBarry Smith #include <petscsys.h> 400d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 401d382aafbSBarry Smith 402eca87e8dSBarry Smith Not Collective 403eca87e8dSBarry Smith 404eca87e8dSBarry Smith Input Parameters: 405eca87e8dSBarry Smith . addr - address to align (any pointer type) 406eca87e8dSBarry Smith 407d382aafbSBarry Smith Level: developer 408d382aafbSBarry Smith 409db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 410d382aafbSBarry Smith 411d382aafbSBarry Smith M*/ 412d382aafbSBarry Smith #define PetscAddrAlign(a) (void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)) 413d382aafbSBarry Smith 414d382aafbSBarry Smith /*MC 41587497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 4168f51dc47SJunchao Zhang 4178f51dc47SJunchao Zhang Synopsis: 4188f51dc47SJunchao Zhang #include <petscsys.h> 4198f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4208f51dc47SJunchao Zhang 4218f51dc47SJunchao Zhang Not Collective 4228f51dc47SJunchao Zhang 4238f51dc47SJunchao Zhang Input Parameter: 4248f51dc47SJunchao Zhang . m - number of bytes to allocate 4258f51dc47SJunchao Zhang 4268f51dc47SJunchao Zhang Output Parameter: 4278f51dc47SJunchao Zhang . result - memory allocated 4288f51dc47SJunchao Zhang 4298f51dc47SJunchao Zhang Level: beginner 4308f51dc47SJunchao Zhang 4318f51dc47SJunchao Zhang Notes: 4328f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4338f51dc47SJunchao Zhang 4348f51dc47SJunchao Zhang It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 4358f51dc47SJunchao Zhang 436db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4378f51dc47SJunchao Zhang 4388f51dc47SJunchao Zhang M*/ 43966122d6dSBarry Smith #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m), (result)) 4408f51dc47SJunchao Zhang 4418f51dc47SJunchao Zhang /*MC 44287497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 443d382aafbSBarry Smith 444eca87e8dSBarry Smith Synopsis: 445aaa7dc30SBarry Smith #include <petscsys.h> 446785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 447785e854fSJed Brown 448785e854fSJed Brown Not Collective 449785e854fSJed Brown 450785e854fSJed Brown Input Parameter: 451390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 452785e854fSJed Brown 453785e854fSJed Brown Output Parameter: 4541fe1b817SJunchao Zhang . r1 - memory allocated 455785e854fSJed Brown 456e28ce29aSPatrick Sanan Note: 457e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 45887497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 459390e1bf2SBarry Smith $ PetscInt *id; 460390e1bf2SBarry Smith $ PetscMalloc1(10,&id); 461390e1bf2SBarry Smith not 462390e1bf2SBarry Smith $ PetscInt *id; 463390e1bf2SBarry Smith $ PetscMalloc1(10*sizeof(PetscInt),&id); 464390e1bf2SBarry Smith 46587497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 466390e1bf2SBarry Smith 467390e1bf2SBarry Smith Level: beginner 468785e854fSJed Brown 469db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 470785e854fSJed Brown 471785e854fSJed Brown M*/ 47266122d6dSBarry Smith #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 473785e854fSJed Brown 474785e854fSJed Brown /*MC 47587497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 4761795a4d1SJed Brown 4771795a4d1SJed Brown Synopsis: 478aaa7dc30SBarry Smith #include <petscsys.h> 4791795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 4801795a4d1SJed Brown 4811795a4d1SJed Brown Not Collective 4821795a4d1SJed Brown 4831795a4d1SJed Brown Input Parameter: 4841795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 4851795a4d1SJed Brown 4861795a4d1SJed Brown Output Parameter: 4871fe1b817SJunchao Zhang . r1 - memory allocated 4881795a4d1SJed Brown 489e28ce29aSPatrick Sanan Notes: 49087497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 491390e1bf2SBarry Smith 492390e1bf2SBarry Smith Level: beginner 4931795a4d1SJed Brown 494db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 4951795a4d1SJed Brown 4961795a4d1SJed Brown M*/ 49766122d6dSBarry Smith #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 4981795a4d1SJed Brown 4991795a4d1SJed Brown /*MC 50087497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 501d382aafbSBarry Smith 502eca87e8dSBarry Smith Synopsis: 503aaa7dc30SBarry Smith #include <petscsys.h> 504dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 505eca87e8dSBarry Smith 506eca87e8dSBarry Smith Not Collective 507eca87e8dSBarry Smith 508d8d19677SJose E. Roman Input Parameters: 509d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 510dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 511d382aafbSBarry Smith 512d8d19677SJose E. Roman Output Parameters: 513d382aafbSBarry Smith + r1 - memory allocated in first chunk 514d382aafbSBarry Smith - r2 - memory allocated in second chunk 515d382aafbSBarry Smith 516d382aafbSBarry Smith Level: developer 517d382aafbSBarry Smith 518db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 519d382aafbSBarry Smith 520d382aafbSBarry Smith M*/ 52166122d6dSBarry 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)) 522d382aafbSBarry Smith 523d382aafbSBarry Smith /*MC 52487497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 525d382aafbSBarry Smith 526eca87e8dSBarry Smith Synopsis: 527aaa7dc30SBarry Smith #include <petscsys.h> 5281795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 529eca87e8dSBarry Smith 530eca87e8dSBarry Smith Not Collective 531eca87e8dSBarry Smith 532d8d19677SJose E. Roman Input Parameters: 533d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5341795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5351795a4d1SJed Brown 536d8d19677SJose E. Roman Output Parameters: 5371795a4d1SJed Brown + r1 - memory allocated in first chunk 5381795a4d1SJed Brown - r2 - memory allocated in second chunk 5391795a4d1SJed Brown 5401795a4d1SJed Brown Level: developer 5411795a4d1SJed Brown 542db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5431795a4d1SJed Brown 5441795a4d1SJed Brown M*/ 54566122d6dSBarry 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)) 5461795a4d1SJed Brown 5471795a4d1SJed Brown /*MC 54887497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 549d382aafbSBarry Smith 550d382aafbSBarry Smith Synopsis: 551aaa7dc30SBarry Smith #include <petscsys.h> 552dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 553d382aafbSBarry Smith 554d382aafbSBarry Smith Not Collective 555d382aafbSBarry Smith 556d8d19677SJose E. Roman Input Parameters: 557d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 558d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 559dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 560d382aafbSBarry Smith 561d8d19677SJose E. Roman Output Parameters: 562d382aafbSBarry Smith + r1 - memory allocated in first chunk 563d382aafbSBarry Smith . r2 - memory allocated in second chunk 564d382aafbSBarry Smith - r3 - memory allocated in third chunk 565d382aafbSBarry Smith 566d382aafbSBarry Smith Level: developer 567d382aafbSBarry Smith 568db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 569d382aafbSBarry Smith 570d382aafbSBarry Smith M*/ 57166122d6dSBarry 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)) 572d382aafbSBarry Smith 573d382aafbSBarry Smith /*MC 57487497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 575d382aafbSBarry Smith 576eca87e8dSBarry Smith Synopsis: 577aaa7dc30SBarry Smith #include <petscsys.h> 5781795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 579eca87e8dSBarry Smith 580eca87e8dSBarry Smith Not Collective 581eca87e8dSBarry Smith 582d8d19677SJose E. Roman Input Parameters: 583d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 584d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 5851795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 5861795a4d1SJed Brown 587d8d19677SJose E. Roman Output Parameters: 5881795a4d1SJed Brown + r1 - memory allocated in first chunk 5891795a4d1SJed Brown . r2 - memory allocated in second chunk 5901795a4d1SJed Brown - r3 - memory allocated in third chunk 5911795a4d1SJed Brown 5921795a4d1SJed Brown Level: developer 5931795a4d1SJed Brown 594db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 5951795a4d1SJed Brown 5961795a4d1SJed Brown M*/ 59766122d6dSBarry 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)) 5981795a4d1SJed Brown 5991795a4d1SJed Brown /*MC 60087497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 601d382aafbSBarry Smith 602d382aafbSBarry Smith Synopsis: 603aaa7dc30SBarry Smith #include <petscsys.h> 604dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 605d382aafbSBarry Smith 606d382aafbSBarry Smith Not Collective 607d382aafbSBarry Smith 608d8d19677SJose E. Roman Input Parameters: 609d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 610d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 611d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 612dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 613d382aafbSBarry Smith 614d8d19677SJose E. Roman Output Parameters: 615d382aafbSBarry Smith + r1 - memory allocated in first chunk 616d382aafbSBarry Smith . r2 - memory allocated in second chunk 617d382aafbSBarry Smith . r3 - memory allocated in third chunk 618d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 619d382aafbSBarry Smith 620d382aafbSBarry Smith Level: developer 621d382aafbSBarry Smith 622db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 623d382aafbSBarry Smith 624d382aafbSBarry Smith M*/ 6259371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6269371c9d4SSatish 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)) 627d382aafbSBarry Smith 628d382aafbSBarry Smith /*MC 62987497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 630d382aafbSBarry Smith 631eca87e8dSBarry Smith Synopsis: 632aaa7dc30SBarry Smith #include <petscsys.h> 6331795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 634eca87e8dSBarry Smith 635eca87e8dSBarry Smith Not Collective 636eca87e8dSBarry Smith 637e28ce29aSPatrick Sanan Input Parameters: 638d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 639d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 640d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6411795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6421795a4d1SJed Brown 643e28ce29aSPatrick Sanan Output Parameters: 6441795a4d1SJed Brown + r1 - memory allocated in first chunk 6451795a4d1SJed Brown . r2 - memory allocated in second chunk 6461795a4d1SJed Brown . r3 - memory allocated in third chunk 6471795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6481795a4d1SJed Brown 6491795a4d1SJed Brown Level: developer 6501795a4d1SJed Brown 651db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6521795a4d1SJed Brown 6531795a4d1SJed Brown M*/ 6549371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6559371c9d4SSatish 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)) 6561795a4d1SJed Brown 6571795a4d1SJed Brown /*MC 65887497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 659d382aafbSBarry Smith 660d382aafbSBarry Smith Synopsis: 661aaa7dc30SBarry Smith #include <petscsys.h> 662dcca6d9dSJed 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) 663d382aafbSBarry Smith 664d382aafbSBarry Smith Not Collective 665d382aafbSBarry Smith 666e28ce29aSPatrick Sanan Input Parameters: 667d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 668d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 669d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 670d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 671dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 672d382aafbSBarry Smith 673e28ce29aSPatrick Sanan Output Parameters: 674d382aafbSBarry Smith + r1 - memory allocated in first chunk 675d382aafbSBarry Smith . r2 - memory allocated in second chunk 676d382aafbSBarry Smith . r3 - memory allocated in third chunk 677d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 678d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 679d382aafbSBarry Smith 680d382aafbSBarry Smith Level: developer 681d382aafbSBarry Smith 682db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 683d382aafbSBarry Smith 684d382aafbSBarry Smith M*/ 6859371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 6869371c9d4SSatish 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)) 687d382aafbSBarry Smith 688d382aafbSBarry Smith /*MC 68987497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 690d382aafbSBarry Smith 691eca87e8dSBarry Smith Synopsis: 692aaa7dc30SBarry Smith #include <petscsys.h> 6931795a4d1SJed 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) 694eca87e8dSBarry Smith 695eca87e8dSBarry Smith Not Collective 696eca87e8dSBarry Smith 697e28ce29aSPatrick Sanan Input Parameters: 698d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 699d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 700d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 701d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 7021795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 7031795a4d1SJed Brown 704e28ce29aSPatrick Sanan Output Parameters: 7051795a4d1SJed Brown + r1 - memory allocated in first chunk 7061795a4d1SJed Brown . r2 - memory allocated in second chunk 7071795a4d1SJed Brown . r3 - memory allocated in third chunk 7081795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7091795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7101795a4d1SJed Brown 7111795a4d1SJed Brown Level: developer 7121795a4d1SJed Brown 713db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7141795a4d1SJed Brown 7151795a4d1SJed Brown M*/ 7169371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 7179371c9d4SSatish 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)) 718d382aafbSBarry Smith 719d382aafbSBarry Smith /*MC 72087497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 721d382aafbSBarry Smith 722d382aafbSBarry Smith Synopsis: 723aaa7dc30SBarry Smith #include <petscsys.h> 724dcca6d9dSJed 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) 725d382aafbSBarry Smith 726d382aafbSBarry Smith Not Collective 727d382aafbSBarry Smith 728e28ce29aSPatrick Sanan Input Parameters: 729d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 730d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 731d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 732d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 733d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 734dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 735d382aafbSBarry Smith 736e28ce29aSPatrick Sanan Output Parameteasr: 737d382aafbSBarry Smith + r1 - memory allocated in first chunk 738d382aafbSBarry Smith . r2 - memory allocated in second chunk 739d382aafbSBarry Smith . r3 - memory allocated in third chunk 740d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 741d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 742d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 743d382aafbSBarry Smith 744d382aafbSBarry Smith Level: developer 745d382aafbSBarry Smith 746db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 747d382aafbSBarry Smith 748d382aafbSBarry Smith M*/ 7499371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7509371c9d4SSatish 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)) 751d382aafbSBarry Smith 752d382aafbSBarry Smith /*MC 75387497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 754d382aafbSBarry Smith 755eca87e8dSBarry Smith Synopsis: 756aaa7dc30SBarry Smith #include <petscsys.h> 7571795a4d1SJed 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) 758eca87e8dSBarry Smith 759eca87e8dSBarry Smith Not Collective 760eca87e8dSBarry Smith 761e28ce29aSPatrick Sanan Input Parameters: 762d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 763d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 764d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 765d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 766d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7671795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7681795a4d1SJed Brown 769e28ce29aSPatrick Sanan Output Parameters: 7701795a4d1SJed Brown + r1 - memory allocated in first chunk 7711795a4d1SJed Brown . r2 - memory allocated in second chunk 7721795a4d1SJed Brown . r3 - memory allocated in third chunk 7731795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7741795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7751795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7761795a4d1SJed Brown 7771795a4d1SJed Brown Level: developer 7781795a4d1SJed Brown 779db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7801795a4d1SJed Brown 7811795a4d1SJed Brown M*/ 7829371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7839371c9d4SSatish 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)) 7841795a4d1SJed Brown 7851795a4d1SJed Brown /*MC 78687497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 787d382aafbSBarry Smith 788d382aafbSBarry Smith Synopsis: 789aaa7dc30SBarry Smith #include <petscsys.h> 790dcca6d9dSJed 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) 791d382aafbSBarry Smith 792d382aafbSBarry Smith Not Collective 793d382aafbSBarry Smith 794e28ce29aSPatrick Sanan Input Parameters: 795d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 796d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 797d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 798d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 799d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 800d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 801dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 802d382aafbSBarry Smith 803e28ce29aSPatrick Sanan Output Parameters: 804d382aafbSBarry Smith + r1 - memory allocated in first chunk 805d382aafbSBarry Smith . r2 - memory allocated in second chunk 806d382aafbSBarry Smith . r3 - memory allocated in third chunk 807d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 808d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 809d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 810eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 811d382aafbSBarry Smith 812d382aafbSBarry Smith Level: developer 813d382aafbSBarry Smith 814db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 815d382aafbSBarry Smith 816d382aafbSBarry Smith M*/ 8179371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8189371c9d4SSatish 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)) 819d382aafbSBarry Smith 820d382aafbSBarry Smith /*MC 82187497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 8221795a4d1SJed Brown 8231795a4d1SJed Brown Synopsis: 824aaa7dc30SBarry Smith #include <petscsys.h> 8251795a4d1SJed 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) 8261795a4d1SJed Brown 8271795a4d1SJed Brown Not Collective 8281795a4d1SJed Brown 829e28ce29aSPatrick Sanan Input Parameters: 8301795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8311795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8321795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8331795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8341795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8351795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8361795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8371795a4d1SJed Brown 838e28ce29aSPatrick Sanan Output Parameters: 8391795a4d1SJed Brown + r1 - memory allocated in first chunk 8401795a4d1SJed Brown . r2 - memory allocated in second chunk 8411795a4d1SJed Brown . r3 - memory allocated in third chunk 8421795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8431795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8441795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8451795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8461795a4d1SJed Brown 8471795a4d1SJed Brown Level: developer 8481795a4d1SJed Brown 849db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8501795a4d1SJed Brown 8511795a4d1SJed Brown M*/ 8529371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8539371c9d4SSatish 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)) 8541795a4d1SJed Brown 8551795a4d1SJed Brown /*MC 85687497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 857d382aafbSBarry Smith 858eca87e8dSBarry Smith Synopsis: 859aaa7dc30SBarry Smith #include <petscsys.h> 860b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 861eca87e8dSBarry Smith 862eca87e8dSBarry Smith Not Collective 863eca87e8dSBarry Smith 864d382aafbSBarry Smith Output Parameter: 865b00a9115SJed Brown . result - memory allocated, sized to match pointer type 866d382aafbSBarry Smith 867d382aafbSBarry Smith Level: beginner 868d382aafbSBarry Smith 869fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 870d382aafbSBarry Smith 871d382aafbSBarry Smith M*/ 872b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 873ad0619ddSBarry Smith 8744dfa11a4SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b)) 875d382aafbSBarry Smith 876d382aafbSBarry Smith /*MC 877d382aafbSBarry Smith PetscFree - Frees memory 878d382aafbSBarry Smith 879eca87e8dSBarry Smith Synopsis: 880aaa7dc30SBarry Smith #include <petscsys.h> 881eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 882eca87e8dSBarry Smith 883eca87e8dSBarry Smith Not Collective 884eca87e8dSBarry Smith 885d382aafbSBarry Smith Input Parameter: 8867f4976b7SJacob Faibussowitsch . memory - memory to free (the pointer is ALWAYS set to NULL upon success) 887d382aafbSBarry Smith 888d382aafbSBarry Smith Level: beginner 889d382aafbSBarry Smith 89049d7da52SJed Brown Notes: 89187497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 892390e1bf2SBarry Smith 89387497f52SBarry Smith It is safe to call `PetscFree()` on a NULL pointer. 894d382aafbSBarry Smith 895fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 896d382aafbSBarry Smith 897d382aafbSBarry Smith M*/ 898ffc31a0eSLisandro Dalcin #define PetscFree(a) ((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = NULL, 0)) 899d382aafbSBarry Smith 900d382aafbSBarry Smith /*MC 90187497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 902d382aafbSBarry Smith 903eca87e8dSBarry Smith Synopsis: 904aaa7dc30SBarry Smith #include <petscsys.h> 905eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 906eca87e8dSBarry Smith 907eca87e8dSBarry Smith Not Collective 908eca87e8dSBarry Smith 909e28ce29aSPatrick Sanan Input Parameters: 910d382aafbSBarry Smith + memory1 - memory to free 911d382aafbSBarry Smith - memory2 - 2nd memory to free 912d382aafbSBarry Smith 913d382aafbSBarry Smith Level: developer 914d382aafbSBarry Smith 91595452b02SPatrick Sanan Notes: 91687497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 917d382aafbSBarry Smith 918db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 919d382aafbSBarry Smith 920d382aafbSBarry Smith M*/ 921ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 922d382aafbSBarry Smith 923d382aafbSBarry Smith /*MC 92487497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 925d382aafbSBarry Smith 926eca87e8dSBarry Smith Synopsis: 927aaa7dc30SBarry Smith #include <petscsys.h> 928eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 929eca87e8dSBarry Smith 930eca87e8dSBarry Smith Not Collective 931eca87e8dSBarry Smith 932e28ce29aSPatrick Sanan Input Parameters: 933d382aafbSBarry Smith + memory1 - memory to free 934d382aafbSBarry Smith . memory2 - 2nd memory to free 935d382aafbSBarry Smith - memory3 - 3rd memory to free 936d382aafbSBarry Smith 937d382aafbSBarry Smith Level: developer 938d382aafbSBarry Smith 93995452b02SPatrick Sanan Notes: 94087497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 941d382aafbSBarry Smith 942db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 943d382aafbSBarry Smith 944d382aafbSBarry Smith M*/ 945ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 946d382aafbSBarry Smith 947d382aafbSBarry Smith /*MC 94887497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 949d382aafbSBarry Smith 950eca87e8dSBarry Smith Synopsis: 951aaa7dc30SBarry Smith #include <petscsys.h> 952eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 953eca87e8dSBarry Smith 954eca87e8dSBarry Smith Not Collective 955eca87e8dSBarry Smith 956e28ce29aSPatrick Sanan Input Parameters: 957d382aafbSBarry Smith + m1 - memory to free 958d382aafbSBarry Smith . m2 - 2nd memory to free 959d382aafbSBarry Smith . m3 - 3rd memory to free 960d382aafbSBarry Smith - m4 - 4th memory to free 961d382aafbSBarry Smith 962d382aafbSBarry Smith Level: developer 963d382aafbSBarry Smith 96495452b02SPatrick Sanan Notes: 96587497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 966d382aafbSBarry Smith 967db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 968d382aafbSBarry Smith 969d382aafbSBarry Smith M*/ 970ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 971d382aafbSBarry Smith 972d382aafbSBarry Smith /*MC 97387497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 974d382aafbSBarry Smith 975eca87e8dSBarry Smith Synopsis: 976aaa7dc30SBarry Smith #include <petscsys.h> 977eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 978eca87e8dSBarry Smith 979eca87e8dSBarry Smith Not Collective 980eca87e8dSBarry Smith 981e28ce29aSPatrick Sanan Input Parameters: 982d382aafbSBarry Smith + m1 - memory to free 983d382aafbSBarry Smith . m2 - 2nd memory to free 984d382aafbSBarry Smith . m3 - 3rd memory to free 985d382aafbSBarry Smith . m4 - 4th memory to free 986d382aafbSBarry Smith - m5 - 5th memory to free 987d382aafbSBarry Smith 988d382aafbSBarry Smith Level: developer 989d382aafbSBarry Smith 99095452b02SPatrick Sanan Notes: 99187497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 992d382aafbSBarry Smith 993db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 994d382aafbSBarry Smith 995d382aafbSBarry Smith M*/ 996ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 997d382aafbSBarry Smith 998d382aafbSBarry Smith /*MC 99987497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 1000d382aafbSBarry Smith 1001eca87e8dSBarry Smith Synopsis: 1002aaa7dc30SBarry Smith #include <petscsys.h> 1003eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1004eca87e8dSBarry Smith 1005eca87e8dSBarry Smith Not Collective 1006eca87e8dSBarry Smith 1007e28ce29aSPatrick Sanan Input Parameters: 1008d382aafbSBarry Smith + m1 - memory to free 1009d382aafbSBarry Smith . m2 - 2nd memory to free 1010d382aafbSBarry Smith . m3 - 3rd memory to free 1011d382aafbSBarry Smith . m4 - 4th memory to free 1012d382aafbSBarry Smith . m5 - 5th memory to free 1013d382aafbSBarry Smith - m6 - 6th memory to free 1014d382aafbSBarry Smith 1015d382aafbSBarry Smith Level: developer 1016d382aafbSBarry Smith 101795452b02SPatrick Sanan Notes: 101887497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 1019d382aafbSBarry Smith 1020db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1021d382aafbSBarry Smith 1022d382aafbSBarry Smith M*/ 1023ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 1024d382aafbSBarry Smith 1025d382aafbSBarry Smith /*MC 102687497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 1027d382aafbSBarry Smith 1028eca87e8dSBarry Smith Synopsis: 1029aaa7dc30SBarry Smith #include <petscsys.h> 1030eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1031eca87e8dSBarry Smith 1032eca87e8dSBarry Smith Not Collective 1033eca87e8dSBarry Smith 1034e28ce29aSPatrick Sanan Input Parameters: 1035d382aafbSBarry Smith + m1 - memory to free 1036d382aafbSBarry Smith . m2 - 2nd memory to free 1037d382aafbSBarry Smith . m3 - 3rd memory to free 1038d382aafbSBarry Smith . m4 - 4th memory to free 1039d382aafbSBarry Smith . m5 - 5th memory to free 1040d382aafbSBarry Smith . m6 - 6th memory to free 1041d382aafbSBarry Smith - m7 - 7th memory to free 1042d382aafbSBarry Smith 1043d382aafbSBarry Smith Level: developer 1044d382aafbSBarry Smith 104595452b02SPatrick Sanan Notes: 104687497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1047d382aafbSBarry Smith 1048db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1049db781477SPatrick Sanan `PetscMalloc7()` 1050d382aafbSBarry Smith 1051d382aafbSBarry Smith M*/ 1052ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1053d382aafbSBarry Smith 1054ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1055ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1056071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1057efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 10583221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1059ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 106092f119d6SBarry 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 **)); 1061014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1062d382aafbSBarry Smith 1063d382aafbSBarry Smith /* 1064c1706be6SHong 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. 1065c1706be6SHong Zhang */ 1066c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1067c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 106831f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 106931f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 107031f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 107131f06eaaSHong Zhang #endif 107259af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 107359af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 107459af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 107559af0bd3SScott Kruger #endif 107659af0bd3SScott Kruger 1077a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 107836763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1079a5057860SBarry Smith 1080a5057860SBarry Smith /* 108166d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1082d382aafbSBarry Smith */ 1083014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 108492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1085014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1086014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1087e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1088e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 108992f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 109092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1091efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 109292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 109392f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1094608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1095608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1096d382aafbSBarry Smith 10976a6fc655SJed Brown PETSC_EXTERN const char *const PetscDataTypes[]; 1098014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1100014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 11018e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1102d382aafbSBarry Smith 1103d382aafbSBarry Smith /* 1104d382aafbSBarry Smith Basic memory and string operations. These are usually simple wrappers 1105d382aafbSBarry Smith around the basic Unix system calls, but a few of them have additional 1106d382aafbSBarry Smith functionality and/or error checking. 1107d382aafbSBarry Smith */ 1108014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemcmp(const void *, const void *, size_t, PetscBool *); 1109014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrlen(const char[], size_t *); 1110d67fe73bSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[], char, int *, char ***); 1111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int, char **); 1112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[], const char[], PetscBool *); 1113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[], const char[], PetscBool *); 1114014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[], const char[], PetscBool *); 1115014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[], const char[], size_t, PetscBool *); 1116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcpy(char[], const char[]); 1117014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcat(char[], const char[]); 1118a126751eSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrlcat(char[], const char[], size_t); 1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncpy(char[], const char[], size_t); 1120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrchr(const char[], char, char *[]); 1121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]); 11222f234a98SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]); 1123014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[], char, char *[]); 1124014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrstr(const char[], const char[], char *[]); 1125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[], const char[], char *[]); 1126014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[], const char[], PetscBool *); 11272c9581d2SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[], const char[], PetscBool *); 1128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[], const char *const *, PetscInt *); 1129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[], char *[]); 113047340559SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const *, char ***); 11316fed8037SJed Brown PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char ***); 11326991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt, const char *const *, char ***); 11336991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt, char ***); 1134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm, const char[], char[], size_t); 1135d382aafbSBarry Smith 1136573b0fb4SBarry Smith PETSC_EXTERN void PetscStrcmpNoError(const char[], const char[], PetscBool *); 1137573b0fb4SBarry Smith 1138014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[], const char, PetscToken *); 1139014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken, char *[]); 1140014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken *); 1141d382aafbSBarry Smith 1142e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscStrInList(const char[], const char[], char, PetscBool *); 114380b92c66SBarry Smith PETSC_EXTERN const char *PetscBasename(const char[]); 1144a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt, const char *const *, const char *, PetscInt *, PetscBool *); 1145a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const *, const char *, PetscEnum *, PetscBool *); 1146a53986e1SJed Brown 1147d382aafbSBarry Smith /* 1148d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1149d382aafbSBarry Smith */ 1150367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1151570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1152de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1153014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1154014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1155d9822059SBarry Smith #else 1156de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1157d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1158d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1159d9822059SBarry Smith #endif 1160*62e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 1161*62e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1162*62e5d2d2SJDBetteridge 11639e517322SPierre Jolivet #if defined(PETSC_HAVE_REAL___FLOAT128) || defined(PETSC_HAVE_REAL___FP16) 1164613bf2b2SPierre Jolivet /*MC 11659e517322SPierre Jolivet MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with 11669e517322SPierre Jolivet custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1167613bf2b2SPierre Jolivet 1168613bf2b2SPierre Jolivet Level: advanced 1169613bf2b2SPierre Jolivet 1170613bf2b2SPierre Jolivet Developer Note: 1171613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1172613bf2b2SPierre Jolivet 1173613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1174613bf2b2SPierre Jolivet M*/ 11759e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1176613bf2b2SPierre Jolivet #endif 1177014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1178d382aafbSBarry Smith 117993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 118093d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1181eb3f98d2SBarry Smith 118295c0884eSLisandro Dalcin PETSC_EXTERN const char *const PetscFileModes[]; 1183d6a4318aSJed Brown 1184639ff905SBarry Smith /* 1185639ff905SBarry Smith Defines PETSc error handling. 1186639ff905SBarry Smith */ 1187639ff905SBarry Smith #include <petscerror.h> 1188d382aafbSBarry Smith 1189660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1190660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1191660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1192660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1193660278c0SBarry Smith 11940700a824SBarry Smith #define PETSC_SMALLEST_CLASSID 1211211 1195014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1196014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1197014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 119881256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 119981256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 120081256985SMatthew G. Knepley 1201d382aafbSBarry Smith /* 1202d382aafbSBarry Smith Routines that get memory usage information from the OS 1203d382aafbSBarry Smith */ 1204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1206014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1207b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1208d382aafbSBarry Smith 1209014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1210d382aafbSBarry Smith 1211d382aafbSBarry Smith /* 1212d382aafbSBarry Smith Initialization of PETSc 1213d382aafbSBarry Smith */ 1214014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1215014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1216014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1217014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1218014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1223014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1224d382aafbSBarry Smith 1225014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1226607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1227d382aafbSBarry Smith 1228014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1229014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1232d382aafbSBarry Smith 1233a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1234a50e088cSMatthew G. Knepley 1235d382aafbSBarry Smith /* 1236d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 12372981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1238d382aafbSBarry Smith */ 1239638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void); 1240638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void); 1241638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1242d382aafbSBarry Smith 1243d382aafbSBarry Smith /* 1244d382aafbSBarry Smith Functions that can act on any PETSc object. 1245d382aafbSBarry Smith */ 1246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1247014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1248014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1249014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1250014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1251014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1252014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1253014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1254014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1255014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1257014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1258014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1259014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1260014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1261014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1263bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 1264bdf89e91SBarry Smith #define PetscObjectComposeFunction(a, b, d) PetscObjectComposeFunction_Private(a, b, (PetscVoidFunction)(d)) 1265014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1266014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 12670eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 12680eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1269014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1270d382aafbSBarry Smith 1271665c2dedSJed Brown #include <petscviewertypes.h> 1272639ff905SBarry Smith #include <petscoptions.h> 1273639ff905SBarry Smith 1274608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1275608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1276608c71bfSMatthew G. Knepley 12770633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 12780633abcbSJed Brown 1279c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1280dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1281639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 12820005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr)) 12830005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1291685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1294013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 12954099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1297b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1299014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1300d382aafbSBarry Smith 1301e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 13027aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1303e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1304e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1305e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1306e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1307e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1308e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1309e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1310e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1311e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 131215681b3cSBarry Smith 1313ec7429eaSBarry Smith #else 13147aab2a10SBarry Smith #define PetscSAWsBlock() 0 1315e04113cfSBarry Smith #define PetscObjectSAWsViewOff(obj) 0 1316e04113cfSBarry Smith #define PetscObjectSAWsSetBlock(obj, flg) 0 1317e04113cfSBarry Smith #define PetscObjectSAWsBlock(obj) 0 1318e04113cfSBarry Smith #define PetscObjectSAWsGrantAccess(obj) 0 1319e04113cfSBarry Smith #define PetscObjectSAWsTakeAccess(obj) 0 1320e04113cfSBarry Smith #define PetscStackViewSAWs() 0 1321e04113cfSBarry Smith #define PetscStackSAWsViewOff() 0 1322e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1323e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 132415681b3cSBarry Smith 1325ec7429eaSBarry Smith #endif 1326b90c6cbeSBarry Smith 132782b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 132882b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 132982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1330258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1331258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1332258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1333258ec3d2SMatthew G. Knepley #endif 13347d5d4d99SBarry Smith 13355fe58b6fSBarry Smith #if defined(PETSC_USE_DEBUG) 1336a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 13375fe58b6fSBarry Smith #endif 13387eb1d149SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 1339a64a8e02SBarry Smith 1340140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1341140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1342140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1343140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1344140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1345140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1346d382aafbSBarry Smith 1347d382aafbSBarry Smith /* 1348503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1349d382aafbSBarry Smith link libraries that will be loaded as needed. 1350d382aafbSBarry Smith */ 1351a240a19fSJed Brown 1352a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr)) 1353a240a19fSJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], void (*)(void)); 1354140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 13550e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 13561c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr)) 13571c9cd337SJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], void (**)(void)); 135844ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1359140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1360140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1361140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 13622e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 13632e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1364d382aafbSBarry Smith 1365014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1368014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1370014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1373d382aafbSBarry Smith 1374d382aafbSBarry Smith /* 1375d382aafbSBarry Smith Useful utility routines 1376d382aafbSBarry Smith */ 1377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1379d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 138458b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 138558b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1386d382aafbSBarry Smith 138764ac3b0dSPatrick Sanan /*MC 138887497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1389503cfb0cSBarry Smith 1390e28ce29aSPatrick Sanan Notes: 1391e28ce29aSPatrick Sanan This is useful in cases like 1392503cfb0cSBarry Smith $ int *a; 1393ace3abfcSBarry Smith $ PetscBool flag = PetscNot(a) 13941cc8b206SBarry Smith where !a would not return a PetscBool because we cannot provide a cast from int to PetscBool in C. 139564ac3b0dSPatrick Sanan 139664ac3b0dSPatrick Sanan Level: beginner 139764ac3b0dSPatrick Sanan 1398db781477SPatrick Sanan .seealso `:` `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 139964ac3b0dSPatrick Sanan M*/ 1400d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1401503cfb0cSBarry Smith 1402d382aafbSBarry Smith /*MC 1403d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1404d382aafbSBarry Smith 1405d382aafbSBarry Smith Synopsis: 1406aaa7dc30SBarry Smith #include <petscsys.h> 1407659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1408d382aafbSBarry Smith 1409659f7ba0SBarry Smith Collective on comm 1410eca87e8dSBarry Smith 1411d382aafbSBarry Smith Input Parameters: 1412659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1413d382aafbSBarry Smith . format - the usual printf() format string 1414659f7ba0SBarry Smith - args - arguments to be printed 1415d382aafbSBarry Smith 1416d382aafbSBarry Smith Level: developer 1417d382aafbSBarry Smith 1418d382aafbSBarry Smith Fortran Note: 1419d382aafbSBarry Smith This routine is not supported in Fortran. 1420d382aafbSBarry Smith 1421659f7ba0SBarry Smith Note: 1422659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1423659f7ba0SBarry Smith 1424659f7ba0SBarry Smith To use, write your own function, for example, 1425659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1426659f7ba0SBarry Smith ${ 1427659f7ba0SBarry Smith $ PetscFunctionReturn(0); 1428659f7ba0SBarry Smith $} 1429659f7ba0SBarry Smith then do the assigment 1430659f7ba0SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 143187497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1432659f7ba0SBarry Smith 143387497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1434d382aafbSBarry Smith 1435db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()` 1436d382aafbSBarry Smith M*/ 14373ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1438d382aafbSBarry Smith 1439fcfd50ebSBarry Smith /* 1440fcfd50ebSBarry Smith Defines PETSc profiling. 1441fcfd50ebSBarry Smith */ 14422c8e378dSBarry Smith #include <petsclog.h> 1443fcfd50ebSBarry Smith 1444fcfd50ebSBarry Smith /* 1445fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1446fcfd50ebSBarry Smith */ 1447014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1448014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1449014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 14503ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14513ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14523ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14533ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 14541b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1455fcfd50ebSBarry Smith 14563ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14573ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14583ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1459d382aafbSBarry Smith 1460d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1461d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1462d781fa04SBarry Smith 1463d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1465016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 146674ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1467d382aafbSBarry Smith #endif 1468d382aafbSBarry Smith 14693ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14710ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **); 1475014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1476d382aafbSBarry Smith 1477014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1478014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1479014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1480014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1481014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1483b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1484d382aafbSBarry Smith 1485d382aafbSBarry Smith /* 1486d382aafbSBarry Smith For use in debuggers 1487d382aafbSBarry Smith */ 1488014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1489014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1490014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1491014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1493d382aafbSBarry Smith 1494a663daf8SBarry Smith #include <stddef.h> 1495a3aaec0aSJed Brown #include <string.h> /* for memcpy, memset */ 1496d382aafbSBarry Smith #include <stdlib.h> 14976c7e564aSBarry Smith 14984a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1499d382aafbSBarry Smith #include <xmmintrin.h> 1500d382aafbSBarry Smith #endif 1501d382aafbSBarry Smith 1502d382aafbSBarry Smith /*@C 1503580bdb30SBarry Smith PetscMemmove - Copies n bytes, beginning at location b, to the space 1504580bdb30SBarry Smith beginning at location a. Copying between regions that overlap will 150587497f52SBarry Smith take place correctly. Use `PetscMemcpy()` if the locations do not overlap 1506580bdb30SBarry Smith 1507580bdb30SBarry Smith Not Collective 1508580bdb30SBarry Smith 1509580bdb30SBarry Smith Input Parameters: 1510580bdb30SBarry Smith + b - pointer to initial memory space 1511580bdb30SBarry Smith . a - pointer to copy space 1512580bdb30SBarry Smith - n - length (in bytes) of space to copy 1513580bdb30SBarry Smith 1514580bdb30SBarry Smith Level: intermediate 1515580bdb30SBarry Smith 151687497f52SBarry Smith Notes: 151787497f52SBarry Smith `PetscArraymove()` is preferred 1518580bdb30SBarry Smith 151987497f52SBarry Smith This routine is analogous to `memmove()`. 152087497f52SBarry Smith 152187497f52SBarry Smith Developers Note: 152287497f52SBarry Smith This is inlined for performance 1523580bdb30SBarry Smith 1524db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 1525db781477SPatrick Sanan `PetscArraymove()` 1526580bdb30SBarry Smith @*/ 1527d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemmove(void *a, const void *b, size_t n) 1528d71ae5a4SJacob Faibussowitsch { 1529580bdb30SBarry Smith PetscFunctionBegin; 15309a202e32SJacob Faibussowitsch if (n > 0) { 15312c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to null pointer"); 15322c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 15339a202e32SJacob Faibussowitsch } 1534580bdb30SBarry Smith #if !defined(PETSC_HAVE_MEMMOVE) 1535580bdb30SBarry Smith if (a < b) { 1536580bdb30SBarry Smith if (a <= b - n) memcpy(a, b, n); 1537580bdb30SBarry Smith else { 1538580bdb30SBarry Smith memcpy(a, b, (int)(b - a)); 1539580bdb30SBarry Smith PetscMemmove(b, b + (int)(b - a), n - (int)(b - a)); 1540580bdb30SBarry Smith } 1541580bdb30SBarry Smith } else { 1542580bdb30SBarry Smith if (b <= a - n) memcpy(a, b, n); 1543580bdb30SBarry Smith else { 1544580bdb30SBarry Smith memcpy(b + n, b + (n - (int)(a - b)), (int)(a - b)); 1545580bdb30SBarry Smith PetscMemmove(a, b, n - (int)(a - b)); 1546580bdb30SBarry Smith } 1547580bdb30SBarry Smith } 1548580bdb30SBarry Smith #else 1549580bdb30SBarry Smith memmove((char *)(a), (char *)(b), n); 1550580bdb30SBarry Smith #endif 1551580bdb30SBarry Smith PetscFunctionReturn(0); 1552580bdb30SBarry Smith } 1553580bdb30SBarry Smith 1554d382aafbSBarry Smith /*@C 1555d382aafbSBarry Smith PetscMemcpy - Copies n bytes, beginning at location b, to the space 1556d382aafbSBarry Smith beginning at location a. The two memory regions CANNOT overlap, use 155787497f52SBarry Smith `PetscMemmove()` in that case. 1558d382aafbSBarry Smith 1559d382aafbSBarry Smith Not Collective 1560d382aafbSBarry Smith 1561d382aafbSBarry Smith Input Parameters: 1562d382aafbSBarry Smith + b - pointer to initial memory space 1563d382aafbSBarry Smith - n - length (in bytes) of space to copy 1564d382aafbSBarry Smith 1565d382aafbSBarry Smith Output Parameter: 1566d382aafbSBarry Smith . a - pointer to copy space 1567d382aafbSBarry Smith 1568d382aafbSBarry Smith Level: intermediate 1569d382aafbSBarry Smith 1570d382aafbSBarry Smith Compile Option: 157187497f52SBarry Smith `PETSC_PREFER_DCOPY_FOR_MEMCPY` will cause the BLAS dcopy() routine to be used 1572d382aafbSBarry Smith for memory copies on double precision values. 157387497f52SBarry Smith `PETSC_PREFER_COPY_FOR_MEMCPY` will cause C code to be used 1574d382aafbSBarry Smith for memory copies on double precision values. 157587497f52SBarry Smith `PETSC_PREFER_FORTRAN_FORMEMCPY` will cause Fortran code to be used 1576d382aafbSBarry Smith for memory copies on double precision values. 1577d382aafbSBarry Smith 157887497f52SBarry Smith Notes: 157987497f52SBarry Smith Prefer `PetscArraycpy()` 158087497f52SBarry Smith 158187497f52SBarry Smith This routine is analogous to `memcpy()`. 158287497f52SBarry Smith 15831fd49c25SBarry Smith Not available from Fortran 15841fd49c25SBarry Smith 158587497f52SBarry Smith Developer Note: 158687497f52SBarry Smith This is inlined for fastest performance 1587f5f57ec0SBarry Smith 1588db781477SPatrick Sanan .seealso: `PetscMemzero()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1589d382aafbSBarry Smith 1590d382aafbSBarry Smith @*/ 1591d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemcpy(void *a, const void *b, size_t n) 1592d71ae5a4SJacob Faibussowitsch { 1593d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 1594c5e4d11fSDmitry Karpeev size_t al = (size_t)a, bl = (size_t)b; 1595c5e4d11fSDmitry Karpeev size_t nl = (size_t)n; 1596a7e36092SMatthew G Knepley PetscFunctionBegin; 15979a202e32SJacob Faibussowitsch if (n > 0) { 15982c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 15992c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to a null pointer"); 16009a202e32SJacob Faibussowitsch } 1601a7e36092SMatthew G Knepley #else 1602d382aafbSBarry Smith PetscFunctionBegin; 1603a7e36092SMatthew G Knepley #endif 1604a47a537aSLisandro Dalcin if (a != b && n > 0) { 1605d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16062c71b3e2SJacob Faibussowitsch PetscCheck(!((al > bl && (al - bl) < nl) || (bl - al) < nl), PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Memory regions overlap: either use PetscMemmov()\n\ 1607d382aafbSBarry Smith or make sure your copy regions and lengths are correct. \n\ 16089371c9d4SSatish Balay Length (bytes) %zu first address %zu second address %zu", 16099371c9d4SSatish Balay nl, al, bl); 1610d382aafbSBarry Smith #endif 1611d382aafbSBarry Smith #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1612c5e4d11fSDmitry Karpeev if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1613d382aafbSBarry Smith size_t len = n / sizeof(PetscScalar); 1614d382aafbSBarry Smith #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1615c5df96a5SBarry Smith PetscBLASInt one = 1, blen; 16169566063dSJacob Faibussowitsch PetscCall(PetscBLASIntCast(len, &blen)); 1617792fecdfSBarry Smith PetscCallBLAS("BLAScopy", BLAScopy_(&blen, (PetscScalar *)b, &one, (PetscScalar *)a, &one)); 1618d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1619d382aafbSBarry Smith fortrancopy_(&len, (PetscScalar *)b, (PetscScalar *)a); 1620d382aafbSBarry Smith #else 1621d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)b, *y = (PetscScalar *)a; 16225f80ce2aSJacob Faibussowitsch for (size_t i = 0; i < len; i++) y[i] = x[i]; 1623d382aafbSBarry Smith #endif 1624d382aafbSBarry Smith } else { 1625d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1626d382aafbSBarry Smith } 1627d382aafbSBarry Smith #else 1628d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1629d382aafbSBarry Smith #endif 1630d382aafbSBarry Smith } 1631d382aafbSBarry Smith PetscFunctionReturn(0); 1632d382aafbSBarry Smith } 1633d382aafbSBarry Smith 1634d382aafbSBarry Smith /*@C 1635d382aafbSBarry Smith PetscMemzero - Zeros the specified memory. 1636d382aafbSBarry Smith 1637d382aafbSBarry Smith Not Collective 1638d382aafbSBarry Smith 1639d382aafbSBarry Smith Input Parameters: 1640d382aafbSBarry Smith + a - pointer to beginning memory location 1641d382aafbSBarry Smith - n - length (in bytes) of memory to initialize 1642d382aafbSBarry Smith 1643d382aafbSBarry Smith Level: intermediate 1644d382aafbSBarry Smith 1645d382aafbSBarry Smith Compile Option: 164687497f52SBarry Smith `PETSC_PREFER_BZERO` - on certain machines (the IBM RS6000) the bzero() routine happens 1647d382aafbSBarry Smith to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1648d382aafbSBarry Smith 164987497f52SBarry Smith Notes: 16501fd49c25SBarry Smith Not available from Fortran 16511fd49c25SBarry Smith 165287497f52SBarry Smith Prefer `PetscArrayzero()` 165387497f52SBarry Smith 165487497f52SBarry Smith Developer Note: 165587497f52SBarry Smith This is inlined for fastest performance 1656503cfb0cSBarry Smith 1657db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1658d382aafbSBarry Smith @*/ 1659d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemzero(void *a, size_t n) 1660d71ae5a4SJacob Faibussowitsch { 1661d382aafbSBarry Smith if (n > 0) { 1662d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16632c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to zero at a null pointer with %zu bytes", n); 1664d382aafbSBarry Smith #endif 1665d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1666d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1667d382aafbSBarry Smith size_t i, len = n / sizeof(PetscScalar); 1668d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)a; 1669d382aafbSBarry Smith for (i = 0; i < len; i++) x[i] = 0.0; 1670d382aafbSBarry Smith } else { 1671d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1672d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1673d382aafbSBarry Smith PetscInt len = n / sizeof(PetscScalar); 1674d382aafbSBarry Smith fortranzero_(&len, (PetscScalar *)a); 1675d382aafbSBarry Smith } else { 1676d382aafbSBarry Smith #endif 1677d382aafbSBarry Smith #if defined(PETSC_PREFER_BZERO) 1678d382aafbSBarry Smith bzero((char *)a, n); 1679d382aafbSBarry Smith #else 1680d382aafbSBarry Smith memset((char *)a, 0, n); 1681d382aafbSBarry Smith #endif 1682d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1683d382aafbSBarry Smith } 1684d382aafbSBarry Smith #endif 1685d382aafbSBarry Smith } 1686d382aafbSBarry Smith return 0; 1687d382aafbSBarry Smith } 1688d382aafbSBarry Smith 1689d382aafbSBarry Smith /*MC 1690580bdb30SBarry Smith PetscArraycmp - Compares two arrays in memory. 1691580bdb30SBarry Smith 1692580bdb30SBarry Smith Synopsis: 1693580bdb30SBarry Smith #include <petscsys.h> 1694580bdb30SBarry Smith PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e) 1695580bdb30SBarry Smith 1696580bdb30SBarry Smith Not Collective 1697580bdb30SBarry Smith 1698580bdb30SBarry Smith Input Parameters: 1699580bdb30SBarry Smith + str1 - First array 1700580bdb30SBarry Smith . str2 - Second array 1701580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1702580bdb30SBarry Smith 1703580bdb30SBarry Smith Output Parameters: 170487497f52SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 1705580bdb30SBarry Smith 1706580bdb30SBarry Smith Level: intermediate 1707580bdb30SBarry Smith 170887497f52SBarry Smith Notes: 170987497f52SBarry Smith This routine is a preferred replacement to `PetscMemcmp()` 171087497f52SBarry Smith 1711580bdb30SBarry Smith The arrays must be of the same type 1712580bdb30SBarry Smith 1713db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, 1714db781477SPatrick Sanan `PetscArraymove()` 1715580bdb30SBarry Smith M*/ 17169e2232c7SLisandro Dalcin #define PetscArraycmp(str1, str2, cnt, e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1, str2, (size_t)(cnt) * sizeof(*(str1)), e)) 1717580bdb30SBarry Smith 17188f8f2f0dSBarry Smith /*MC 171987497f52SBarry Smith PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use `PetscArraycpy()` when the arrays 1720580bdb30SBarry Smith do not overlap 1721580bdb30SBarry Smith 1722580bdb30SBarry Smith Synopsis: 1723580bdb30SBarry Smith #include <petscsys.h> 1724580bdb30SBarry Smith PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt) 1725580bdb30SBarry Smith 1726580bdb30SBarry Smith Not Collective 1727580bdb30SBarry Smith 1728580bdb30SBarry Smith Input Parameters: 1729580bdb30SBarry Smith + str1 - First array 1730580bdb30SBarry Smith . str2 - Second array 1731580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1732580bdb30SBarry Smith 1733580bdb30SBarry Smith Level: intermediate 1734580bdb30SBarry Smith 173587497f52SBarry Smith Notes: 173687497f52SBarry Smith This routine is a preferred replacement to `PetscMemmove()` 173787497f52SBarry Smith 1738580bdb30SBarry Smith The arrays must be of the same type 1739580bdb30SBarry Smith 1740db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1741580bdb30SBarry Smith M*/ 17429e2232c7SLisandro Dalcin #define PetscArraymove(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1743580bdb30SBarry Smith 17448f8f2f0dSBarry Smith /*MC 1745580bdb30SBarry Smith PetscArraycpy - Copies from one array in memory to another 1746580bdb30SBarry Smith 1747580bdb30SBarry Smith Synopsis: 1748580bdb30SBarry Smith #include <petscsys.h> 1749580bdb30SBarry Smith PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt) 1750580bdb30SBarry Smith 1751580bdb30SBarry Smith Not Collective 1752580bdb30SBarry Smith 1753580bdb30SBarry Smith Input Parameters: 1754de25709eSStefano Zampini + str1 - First array (destination) 1755de25709eSStefano Zampini . str2 - Second array (source) 1756580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1757580bdb30SBarry Smith 1758580bdb30SBarry Smith Level: intermediate 1759580bdb30SBarry Smith 176087497f52SBarry Smith Notes: 176187497f52SBarry Smith This routine is a preferred replacement to `PetscMemcpy()` 176287497f52SBarry Smith 1763580bdb30SBarry Smith The arrays must be of the same type 1764580bdb30SBarry Smith 1765db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraymove()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1766580bdb30SBarry Smith M*/ 17679e2232c7SLisandro Dalcin #define PetscArraycpy(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcpy(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1768580bdb30SBarry Smith 17698f8f2f0dSBarry Smith /*MC 1770580bdb30SBarry Smith PetscArrayzero - Zeros an array in memory. 1771580bdb30SBarry Smith 1772580bdb30SBarry Smith Synopsis: 1773580bdb30SBarry Smith #include <petscsys.h> 1774580bdb30SBarry Smith PetscErrorCode PetscArrayzero(anytype *str1,size_t cnt) 1775580bdb30SBarry Smith 1776580bdb30SBarry Smith Not Collective 1777580bdb30SBarry Smith 1778580bdb30SBarry Smith Input Parameters: 1779580bdb30SBarry Smith + str1 - array 1780580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the array 1781580bdb30SBarry Smith 1782580bdb30SBarry Smith Level: intermediate 1783580bdb30SBarry Smith 1784580bdb30SBarry Smith Note: 178587497f52SBarry Smith This routine is a preferred replacement to `PetscMemzero()` 1786580bdb30SBarry Smith 1787db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, `PetscArraymove()` 1788580bdb30SBarry Smith M*/ 17899e2232c7SLisandro Dalcin #define PetscArrayzero(str1, cnt) PetscMemzero(str1, (size_t)(cnt) * sizeof(*(str1))) 1790580bdb30SBarry Smith 1791d382aafbSBarry Smith /*MC 1792d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1793d382aafbSBarry Smith 1794eca87e8dSBarry Smith Synopsis: 1795aaa7dc30SBarry Smith #include <petscsys.h> 1796eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1797eca87e8dSBarry Smith 1798d382aafbSBarry Smith Not Collective 1799d382aafbSBarry Smith 1800d382aafbSBarry Smith Input Parameters: 1801d382aafbSBarry Smith + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 1802d382aafbSBarry Smith . n - number of elements to fetch 1803d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 180450d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1805d382aafbSBarry Smith 1806d382aafbSBarry Smith Level: developer 1807d382aafbSBarry Smith 1808d382aafbSBarry Smith Notes: 1809d382aafbSBarry Smith The last two arguments (rw and t) must be compile-time constants. 1810d382aafbSBarry Smith 181150d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 181250d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 181387497f52SBarry 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). 181487497f52SBarry 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. 181587497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 181687497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1817d382aafbSBarry Smith 1818d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1819d382aafbSBarry Smith address). 1820d382aafbSBarry Smith 1821d382aafbSBarry Smith M*/ 18229371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 18239371c9d4SSatish Balay do { \ 1824d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1825d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1826d382aafbSBarry Smith } while (0) 1827d382aafbSBarry Smith 1828d382aafbSBarry Smith /* 1829d382aafbSBarry Smith Determine if some of the kernel computation routines use 1830d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1831d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1832d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1833e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1834d382aafbSBarry Smith */ 1835d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1836d382aafbSBarry Smith 1837d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1838d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1839d382aafbSBarry Smith #endif 1840d382aafbSBarry Smith 18415a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 18425a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1843d382aafbSBarry Smith #endif 1844d382aafbSBarry Smith 1845d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1846d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1847d382aafbSBarry Smith #endif 1848d382aafbSBarry Smith 1849d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1850d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1851d382aafbSBarry Smith #endif 1852d382aafbSBarry Smith 1853d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1854d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM 1855d382aafbSBarry Smith #endif 1856d382aafbSBarry Smith 1857d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1858d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1859d382aafbSBarry Smith #endif 1860d382aafbSBarry Smith 1861d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1862d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1863d382aafbSBarry Smith #endif 1864d382aafbSBarry Smith 1865d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1866d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1867d382aafbSBarry Smith #endif 1868d382aafbSBarry Smith 1869d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1870d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1871d382aafbSBarry Smith #endif 1872d382aafbSBarry Smith 1873d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1874d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1875d382aafbSBarry Smith #endif 1876d382aafbSBarry Smith 1877d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1878d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1879d382aafbSBarry Smith #endif 1880d382aafbSBarry Smith 1881d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1882d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1883d382aafbSBarry Smith #endif 1884d382aafbSBarry Smith 1885d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1886d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1887d382aafbSBarry Smith #endif 1888d382aafbSBarry Smith 1889d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1890d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1891d382aafbSBarry Smith #endif 1892d382aafbSBarry Smith 1893d382aafbSBarry Smith #endif 1894d382aafbSBarry Smith 1895d382aafbSBarry Smith /* 1896d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1897d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1898d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1899d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1900d382aafbSBarry Smith ugly extern "C" {} wrappers. 1901d382aafbSBarry Smith */ 1902d382aafbSBarry Smith #if defined(__cplusplus) 1903d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1904d382aafbSBarry Smith #define EXTERN_C_END } 1905d382aafbSBarry Smith #else 1906d382aafbSBarry Smith #define EXTERN_C_BEGIN 1907d382aafbSBarry Smith #define EXTERN_C_END 1908d382aafbSBarry Smith #endif 1909d382aafbSBarry Smith 1910d382aafbSBarry Smith /* --------------------------------------------------------------------*/ 1911d382aafbSBarry Smith 1912d382aafbSBarry Smith /*MC 1913d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1914d382aafbSBarry Smith communication 1915d382aafbSBarry Smith 1916d382aafbSBarry Smith Level: beginner 1917d382aafbSBarry Smith 1918d382aafbSBarry Smith Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1919d382aafbSBarry Smith 1920db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1921d382aafbSBarry Smith M*/ 1922d382aafbSBarry Smith 1923d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 192493d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 192593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 192693d501b3SJacob 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); 192793d501b3SJacob 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); 192893d501b3SJacob 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); 192993d501b3SJacob 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); 1930d382aafbSBarry Smith #endif 1931d382aafbSBarry Smith 1932d382aafbSBarry Smith /* the following petsc_static_inline require petscerror.h */ 1933d382aafbSBarry Smith 1934d382aafbSBarry Smith /* Limit MPI to 32-bits */ 1935d382aafbSBarry Smith #define PETSC_MPI_INT_MAX 2147483647 1936d382aafbSBarry Smith #define PETSC_MPI_INT_MIN -2147483647 1937d382aafbSBarry Smith /* Limit BLAS to 32-bits */ 1938d382aafbSBarry Smith #define PETSC_BLAS_INT_MAX 2147483647 1939d382aafbSBarry Smith #define PETSC_BLAS_INT_MIN -2147483647 1940eee0c0a6SToby Isaac #define PETSC_CUBLAS_INT_MAX 2147483647 1941d382aafbSBarry Smith 194261b0d812SBarry Smith /*@C 194387497f52SBarry Smith PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an 194487497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1945c73702f5SBarry Smith 1946c73702f5SBarry Smith Not Collective 1947c73702f5SBarry Smith 1948c73702f5SBarry Smith Input Parameter: 194987497f52SBarry Smith . a - the `PetscInt64` value 1950c73702f5SBarry Smith 1951c73702f5SBarry Smith Output Parameter: 195287497f52SBarry Smith . b - the resulting `PetscInt` value 1953c73702f5SBarry Smith 1954c73702f5SBarry Smith Level: advanced 1955c73702f5SBarry Smith 195687497f52SBarry Smith Notes: 195787497f52SBarry 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 1958c73702f5SBarry Smith 1959c73702f5SBarry Smith Not available from Fortran 1960c73702f5SBarry Smith 1961db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1962c73702f5SBarry Smith @*/ 1963d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1964d71ae5a4SJacob Faibussowitsch { 1965c73702f5SBarry Smith PetscFunctionBegin; 1966c73702f5SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 19673ca90d2dSJacob Faibussowitsch if (a > PETSC_MAX_INT) { 19683ca90d2dSJacob Faibussowitsch *b = 0; 196998921bdaSJacob 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); 19703ca90d2dSJacob Faibussowitsch } 1971c73702f5SBarry Smith #endif 1972c73702f5SBarry Smith *b = (PetscInt)(a); 1973c73702f5SBarry Smith PetscFunctionReturn(0); 1974c73702f5SBarry Smith } 1975c73702f5SBarry Smith 1976c73702f5SBarry Smith /*@C 197787497f52SBarry Smith PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an 197887497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1979981bb840SJunchao Zhang 1980981bb840SJunchao Zhang Not Collective 1981981bb840SJunchao Zhang 1982981bb840SJunchao Zhang Input Parameter: 198387497f52SBarry Smith . a - the `PetscCount` value 1984981bb840SJunchao Zhang 1985981bb840SJunchao Zhang Output Parameter: 198687497f52SBarry Smith . b - the resulting `PetscInt` value 1987981bb840SJunchao Zhang 1988981bb840SJunchao Zhang Level: advanced 1989981bb840SJunchao Zhang 1990981bb840SJunchao Zhang Notes: 1991981bb840SJunchao 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 1992981bb840SJunchao Zhang 1993981bb840SJunchao Zhang Not available from Fortran 1994981bb840SJunchao Zhang 1995db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1996981bb840SJunchao Zhang @*/ 1997d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 1998d71ae5a4SJacob Faibussowitsch { 1999981bb840SJunchao Zhang PetscFunctionBegin; 2000981bb840SJunchao Zhang if (sizeof(PetscCount) > sizeof(PetscInt) && a > PETSC_MAX_INT) { 2001981bb840SJunchao Zhang *b = 0; 2002981bb840SJunchao 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); 2003981bb840SJunchao Zhang } 2004981bb840SJunchao Zhang *b = (PetscInt)(a); 2005981bb840SJunchao Zhang PetscFunctionReturn(0); 2006981bb840SJunchao Zhang } 2007981bb840SJunchao Zhang 2008981bb840SJunchao Zhang /*@C 200987497f52SBarry Smith PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an 201087497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 201161b0d812SBarry Smith 201261b0d812SBarry Smith Not Collective 201361b0d812SBarry Smith 201461b0d812SBarry Smith Input Parameter: 201587497f52SBarry Smith . a - the `PetscInt` value 201661b0d812SBarry Smith 201761b0d812SBarry Smith Output Parameter: 201887497f52SBarry Smith . b - the resulting `PetscBLASInt` value 201961b0d812SBarry Smith 202061b0d812SBarry Smith Level: advanced 202161b0d812SBarry Smith 20220bc7d38cSBarry Smith Notes: 20231fd49c25SBarry Smith Not available from Fortran 202487497f52SBarry Smith 2025f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 20261fd49c25SBarry Smith 2027db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 202861b0d812SBarry Smith @*/ 2029d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 2030d71ae5a4SJacob Faibussowitsch { 2031c5df96a5SBarry Smith PetscFunctionBegin; 203254c59aa7SJacob Faibussowitsch *b = 0; 203354c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 203454c59aa7SJacob 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); 203554c59aa7SJacob Faibussowitsch } 203654c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 2037c73702f5SBarry Smith *b = (PetscBLASInt)(a); 2038c5df96a5SBarry Smith PetscFunctionReturn(0); 2039c5df96a5SBarry Smith } 2040c5df96a5SBarry Smith 204161b0d812SBarry Smith /*@C 204287497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 2043eee0c0a6SToby Isaac 2044eee0c0a6SToby Isaac Not Collective 2045eee0c0a6SToby Isaac 2046eee0c0a6SToby Isaac Input Parameter: 204787497f52SBarry Smith . a - the `PetscInt` value 2048eee0c0a6SToby Isaac 2049eee0c0a6SToby Isaac Output Parameter: 205087497f52SBarry Smith . b - the resulting `PetscCuBLASInt` value 2051eee0c0a6SToby Isaac 2052eee0c0a6SToby Isaac Level: advanced 2053eee0c0a6SToby Isaac 2054eee0c0a6SToby Isaac Notes: 2055eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 2056eee0c0a6SToby Isaac 2057db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 2058eee0c0a6SToby Isaac @*/ 2059d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 2060d71ae5a4SJacob Faibussowitsch { 2061eee0c0a6SToby Isaac PetscFunctionBegin; 206254c59aa7SJacob Faibussowitsch *b = 0; 206354c59aa7SJacob 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); 206454c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to cuBLAS routine"); 2065eee0c0a6SToby Isaac *b = (PetscCuBLASInt)(a); 2066eee0c0a6SToby Isaac PetscFunctionReturn(0); 2067eee0c0a6SToby Isaac } 2068eee0c0a6SToby Isaac 2069eee0c0a6SToby Isaac /*@C 207087497f52SBarry Smith PetscMPIIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscMPIInt` (which may be 32 bits in size), generates an 207187497f52SBarry Smith error if the `PetscMPIInt` is not large enough to hold the number. 207261b0d812SBarry Smith 207361b0d812SBarry Smith Not Collective 207461b0d812SBarry Smith 207561b0d812SBarry Smith Input Parameter: 207687497f52SBarry Smith . a - the `PetscInt` value 207761b0d812SBarry Smith 207861b0d812SBarry Smith Output Parameter: 207987497f52SBarry Smith . b - the resulting `PetscMPIInt` value 208061b0d812SBarry Smith 208161b0d812SBarry Smith Level: advanced 208261b0d812SBarry Smith 20831fd49c25SBarry Smith Not available from Fortran 20841fd49c25SBarry Smith 2085db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 208661b0d812SBarry Smith @*/ 2087d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 2088d71ae5a4SJacob Faibussowitsch { 20894dc2109aSBarry Smith PetscFunctionBegin; 209054c59aa7SJacob Faibussowitsch *b = 0; 209154c59aa7SJacob 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); 2092c73702f5SBarry Smith *b = (PetscMPIInt)(a); 20934dc2109aSBarry Smith PetscFunctionReturn(0); 20944dc2109aSBarry Smith } 20954dc2109aSBarry Smith 2096bafee8b4SSatish Balay #define PetscInt64Mult(a, b) ((PetscInt64)(a)) * ((PetscInt64)(b)) 20972f18eb33SBarry Smith 20982f18eb33SBarry Smith /*@C 20992f18eb33SBarry Smith 210087497f52SBarry 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 21012f18eb33SBarry Smith 21022f18eb33SBarry Smith Not Collective 21032f18eb33SBarry Smith 2104d8d19677SJose E. Roman Input Parameters: 210587497f52SBarry Smith + a - the `PetscReal` value 21062f18eb33SBarry Smith - b - the second value 21072f18eb33SBarry Smith 2108390e1bf2SBarry Smith Returns: 210987497f52SBarry Smith the result as a `PetscInt` value 21102f18eb33SBarry Smith 211187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 211287497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate to fit a `PetscInt` 211387497f52SBarry 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` 21142f18eb33SBarry Smith 2115e28ce29aSPatrick Sanan Developers Note: 211687497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21172f18eb33SBarry Smith 21182f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21192f18eb33SBarry Smith 21201fd49c25SBarry Smith Not available from Fortran 21211fd49c25SBarry Smith 21222f18eb33SBarry Smith Level: advanced 21232f18eb33SBarry Smith 2124db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21252f18eb33SBarry Smith @*/ 2126d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 2127d71ae5a4SJacob Faibussowitsch { 21285f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 21292f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21302f18eb33SBarry Smith return (PetscInt)r; 21312f18eb33SBarry Smith } 21322f18eb33SBarry Smith 21332f18eb33SBarry Smith /*@C 21342f18eb33SBarry Smith 213587497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 21362f18eb33SBarry Smith 21372f18eb33SBarry Smith Not Collective 21382f18eb33SBarry Smith 2139d8d19677SJose E. Roman Input Parameters: 21402f18eb33SBarry Smith + a - the PetscInt value 21412f18eb33SBarry Smith - b - the second value 21422f18eb33SBarry Smith 2143390e1bf2SBarry Smith Returns: 214487497f52SBarry Smith the result as a `PetscInt` value 21452f18eb33SBarry Smith 214687497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 214787497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 214887497f52SBarry 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` 21492f18eb33SBarry Smith 21501fd49c25SBarry Smith Not available from Fortran 21511fd49c25SBarry Smith 215287497f52SBarry Smith Developers Note: 215387497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21542f18eb33SBarry Smith 21552f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21562f18eb33SBarry Smith 21572f18eb33SBarry Smith Level: advanced 21582f18eb33SBarry Smith 2159db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21602f18eb33SBarry Smith @*/ 2161d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 2162d71ae5a4SJacob Faibussowitsch { 21635f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 21642f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21652f18eb33SBarry Smith return (PetscInt)r; 21662f18eb33SBarry Smith } 21672f18eb33SBarry Smith 2168f91af8c7SBarry Smith /*@C 2169f91af8c7SBarry Smith 217087497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 2171f91af8c7SBarry Smith 2172f91af8c7SBarry Smith Not Collective 2173f91af8c7SBarry Smith 2174d8d19677SJose E. Roman Input Parameters: 217587497f52SBarry Smith + a - the `PetscInt` value 2176f91af8c7SBarry Smith - b - the second value 2177f91af8c7SBarry Smith 2178390e1bf2SBarry Smith Returns: 217987497f52SBarry Smith the result as a `PetscInt` value 2180f91af8c7SBarry Smith 218187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 218287497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 218387497f52SBarry 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` 2184f91af8c7SBarry Smith 2185f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2186f91af8c7SBarry Smith 2187f5f57ec0SBarry Smith Not available from Fortran 2188f5f57ec0SBarry Smith 2189f91af8c7SBarry Smith Level: advanced 2190f91af8c7SBarry Smith 2191db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2192f91af8c7SBarry Smith @*/ 2193d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 2194d71ae5a4SJacob Faibussowitsch { 21955f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 2196f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 2197f91af8c7SBarry Smith return (PetscInt)r; 2198f91af8c7SBarry Smith } 2199f91af8c7SBarry Smith 22002f18eb33SBarry Smith /*@C 22012f18eb33SBarry Smith 220287497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 22032f18eb33SBarry Smith 22042f18eb33SBarry Smith Not Collective 22052f18eb33SBarry Smith 2206d8d19677SJose E. Roman Input Parameters: 220787497f52SBarry Smith + a - the `PetscInt` value 22082f18eb33SBarry Smith - b - the second value 22092f18eb33SBarry Smith 2210d8d19677SJose E. Roman Output Parameter: 221187497f52SBarry 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 22122f18eb33SBarry Smith 221387497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 221487497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 22152f18eb33SBarry Smith 2216f5f57ec0SBarry Smith Not available from Fortran 2217f5f57ec0SBarry Smith 221887497f52SBarry Smith Developers Note: 221987497f52SBarry Smith We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks. 22202f18eb33SBarry Smith 22212f18eb33SBarry Smith Level: advanced 22222f18eb33SBarry Smith 2223db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 22242f18eb33SBarry Smith @*/ 2225d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 2226d71ae5a4SJacob Faibussowitsch { 2227bafee8b4SSatish Balay PetscInt64 r; 22282f18eb33SBarry Smith 22292f18eb33SBarry Smith PetscFunctionBegin; 2230bafee8b4SSatish Balay r = PetscInt64Mult(a, b); 22312f18eb33SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22322c71b3e2SJacob 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); 22332f18eb33SBarry Smith #endif 2234f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 2235f91af8c7SBarry Smith PetscFunctionReturn(0); 2236f91af8c7SBarry Smith } 2237f91af8c7SBarry Smith 2238f91af8c7SBarry Smith /*@C 2239f91af8c7SBarry Smith 224087497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 2241f91af8c7SBarry Smith 2242f91af8c7SBarry Smith Not Collective 2243f91af8c7SBarry Smith 2244d8d19677SJose E. Roman Input Parameters: 224587497f52SBarry Smith + a - the `PetscInt` value 2246f91af8c7SBarry Smith - b - the second value 2247f91af8c7SBarry Smith 2248d8d19677SJose E. Roman Output Parameter: 224987497f52SBarry 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 2250f91af8c7SBarry Smith 225187497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64` 225287497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2253f91af8c7SBarry Smith 2254f5f57ec0SBarry Smith Not available from Fortran 2255f5f57ec0SBarry Smith 2256f91af8c7SBarry Smith Level: advanced 2257f91af8c7SBarry Smith 2258db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2259f91af8c7SBarry Smith @*/ 2260d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 2261d71ae5a4SJacob Faibussowitsch { 2262bafee8b4SSatish Balay PetscInt64 r; 2263f91af8c7SBarry Smith 2264f91af8c7SBarry Smith PetscFunctionBegin; 2265bafee8b4SSatish Balay r = ((PetscInt64)a) + ((PetscInt64)b); 2266f91af8c7SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22672c71b3e2SJacob 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); 2268f91af8c7SBarry Smith #endif 2269f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 22702f18eb33SBarry Smith PetscFunctionReturn(0); 22712f18eb33SBarry Smith } 2272c5df96a5SBarry Smith 2273d382aafbSBarry Smith /* 22742981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2275d382aafbSBarry Smith */ 2276d382aafbSBarry Smith #if defined(hz) 2277d382aafbSBarry Smith #undef hz 2278d382aafbSBarry Smith #endif 2279d382aafbSBarry Smith 228015a5570dSLisandro Dalcin #include <limits.h> 228115a5570dSLisandro Dalcin 228215a5570dSLisandro Dalcin /* The number of bits in a byte */ 228315a5570dSLisandro Dalcin 228415a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT 228515a5570dSLisandro Dalcin 2286d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2287d382aafbSBarry Smith #include <sys/types.h> 2288d382aafbSBarry Smith #endif 2289d382aafbSBarry Smith 2290d382aafbSBarry Smith /*MC 2291d382aafbSBarry Smith 229266d79e26SBarry 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++ 229366d79e26SBarry Smith and Fortran compilers when petscsys.h is included. 229466d79e26SBarry Smith 229566d79e26SBarry Smith The current PETSc version and the API for accessing it are defined in petscversion.h 229666d79e26SBarry Smith 229766d79e26SBarry 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) 229866d79e26SBarry Smith 229966d79e26SBarry 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 230066d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 230166d79e26SBarry Smith 230266d79e26SBarry 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 230366d79e26SBarry Smith 230466d79e26SBarry 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), 230566d79e26SBarry 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 230666d79e26SBarry Smith version number (x.y.z). 230766d79e26SBarry Smith 230887497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 230966d79e26SBarry Smith 231087497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 231166d79e26SBarry Smith 231287497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 231366d79e26SBarry Smith 231487497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 231566d79e26SBarry Smith 231687497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 231766d79e26SBarry Smith 2318cbc12506SBarry Smith Level: intermediate 231966d79e26SBarry Smith 232066d79e26SBarry Smith M*/ 232166d79e26SBarry Smith 2322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 2323014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 2324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 2325014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 2326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2327014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 232827710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 23295f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 2330d382aafbSBarry Smith 23316a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 2332*62e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 23336a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 23346a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 2335014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 2336*62e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 2337*62e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 2338ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 233922ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 2340b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2342f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 234360e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 2344d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 2345014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 2347014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 2348981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 23496c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 2350981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 235117d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 235217d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 2353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 23545569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 2355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 235617df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 235839f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2360745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 236139f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2362014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2364014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 23656c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 23666c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2367e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2368ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2369ce605777SToby Isaac 23704d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2371676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2372676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2373676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 23744d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2375676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2376676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2377676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2378676f2a66SJacob Faibussowitsch 2379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2381d382aafbSBarry Smith 238276bdecfbSBarry Smith /*J 2383d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2384d382aafbSBarry Smith 2385d382aafbSBarry Smith Level: beginner 2386d382aafbSBarry Smith 2387e28ce29aSPatrick Sanan Notes: 238887497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 238925ccb61fSToby Isaac with the option --download-sprng or --download-random123 2390d382aafbSBarry Smith 2391db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 239276bdecfbSBarry Smith J*/ 239319fd82e9SBarry Smith typedef const char *PetscRandomType; 2394d382aafbSBarry Smith #define PETSCRAND "rand" 2395d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2396d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2397c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 239825ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2399808ba619SStefano Zampini #define PETSCCURAND "curand" 2400d382aafbSBarry Smith 2401d382aafbSBarry Smith /* Logging support */ 2402014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2403d382aafbSBarry Smith 2404607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2405d382aafbSBarry Smith 2406d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2407140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2408d382aafbSBarry Smith 2409bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 241019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2411014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 241219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2413fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2414014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2415d382aafbSBarry Smith 2416014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2417014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2418014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2419808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2420808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2421014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2422014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2423014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2424014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2425014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2426014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2427d382aafbSBarry Smith 2428014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2429014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2430014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2431014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2432014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2433014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 243597540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 24368a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 243797540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2438d382aafbSBarry Smith 2439d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2440d71ae5a4SJacob Faibussowitsch { 24419371c9d4SSatish Balay long _petsc_v = 1; 24429371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 24439371c9d4SSatish Balay } 244430815ce0SLisandro Dalcin 24459860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 24469860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2447f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2448f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2449014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2450014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2451014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2453014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2454014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2455014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2456c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2457e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2458c891a504SStefano Zampini #endif 2459d382aafbSBarry Smith 2460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2463d382aafbSBarry Smith 2464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2465014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2466014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2467014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2468014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2469014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 24702a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2471d382aafbSBarry Smith 2472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2475014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2476014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 247793d501b3SJacob 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); 247893d501b3SJacob 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); 247993d501b3SJacob 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); 2480d382aafbSBarry Smith 24816145cd65SJed Brown PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[]; 24826145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 24836145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 24846145cd65SJed Brown 2485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2486d382aafbSBarry Smith 2487ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2488ce94432eSBarry Smith 248945487dadSJed Brown PETSC_EXTERN const char *const PetscSubcommTypes[]; 249045487dadSJed Brown 2491d382aafbSBarry Smith struct _n_PetscSubcomm { 2492d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2493d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2494306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 249545487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 249645487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2497708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 249845487dadSJed Brown PetscSubcommType type; 2499e5acf8a4SHong Zhang char *subcommprefix; 2500d382aafbSBarry Smith }; 2501d382aafbSBarry Smith 2502d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2503d71ae5a4SJacob Faibussowitsch { 25049371c9d4SSatish Balay return scomm->parent; 25059371c9d4SSatish Balay } 2506d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2507d71ae5a4SJacob Faibussowitsch { 25089371c9d4SSatish Balay return scomm->child; 25099371c9d4SSatish Balay } 2510d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2511d71ae5a4SJacob Faibussowitsch { 25129371c9d4SSatish Balay return scomm->dupparent; 25139371c9d4SSatish Balay } 2514014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2515014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2516014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2517014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 251865d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2519053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2520f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2521e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2522a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2523a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2524a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2525d382aafbSBarry Smith 25269962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 25279962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 25289962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 25299962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 25309962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 25319962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 25329962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 25339962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 25349962606eSBarry Smith 25355e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 25365f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 25375f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25385f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25395f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 25405e71baefSBarry Smith 2541a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2542a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2543a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2544a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2545a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2546a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2547a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2548a32e93adSJunchao Zhang 254913e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 25500f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 255113e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2552137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2553137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2554137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 255513e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 255613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 25570f453b92SJed Brown 2558471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2559471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2560471ecdacSJed Brown * possible. */ 2561d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2562d71ae5a4SJacob Faibussowitsch { 25639371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 25649371c9d4SSatish Balay } 2565d382aafbSBarry Smith 25669de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 25679de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 25689de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 25699de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 25709de0f6ecSBarry Smith 2571ace2fbaeSBarry Smith #include <stdarg.h> 2572ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2573ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2574ace2fbaeSBarry Smith 2575268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2576fbfcfee5SBarry Smith 25771f817a21SBarry Smith /*@C 25781f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 25791f817a21SBarry Smith 258087497f52SBarry Smith Not Collective - only what is registered on rank 0 of `PETSC_COMM_WORLD` will be printed 25811f817a21SBarry Smith 25821f817a21SBarry Smith Input Parameters: 25831f817a21SBarry Smith + cite - the bibtex item, formated to displayed on multiple lines nicely 258487497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 25851f817a21SBarry Smith 2586850545d0SSatish Balay Level: intermediate 2587850545d0SSatish Balay 2588f5f57ec0SBarry Smith Not available from Fortran 2589f5f57ec0SBarry Smith 25901f817a21SBarry Smith Options Database: 2591063414e0SPatrick Sanan . -citations [filename] - print out the bibtex entries for the given computation 25921f817a21SBarry Smith @*/ 2593d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2594d71ae5a4SJacob Faibussowitsch { 2595dff31646SBarry Smith size_t len; 2596dff31646SBarry Smith char *vstring; 2597dff31646SBarry Smith 25981f817a21SBarry Smith PetscFunctionBegin; 25998d3683fcSBarry Smith if (set && *set) PetscFunctionReturn(0); 26009566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 26019566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 26029566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2603dff31646SBarry Smith if (set) *set = PETSC_TRUE; 26041f817a21SBarry Smith PetscFunctionReturn(0); 2605dff31646SBarry Smith } 2606dff31646SBarry Smith 2607d8174014SToby Isaac PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c); 2608fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2609fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2610f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2611fe278a28SBarry Smith 2612f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2613f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 2614b967cddfSBarry Smith 26159f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 26169f4d3c52SBarry Smith 261704102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *); 2618763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *); 2619dff31646SBarry Smith 262068e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 26215dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2622d382aafbSBarry Smith 2623b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2624d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2625d71ae5a4SJacob Faibussowitsch { 2626df05ca09SBarry Smith unsigned int c, hash = 5381; 2627df05ca09SBarry Smith 2628503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2629df05ca09SBarry Smith return hash; 2630df05ca09SBarry Smith } 263177a5e07dSBarry Smith 263277a5e07dSBarry Smith /*MC 263387497f52SBarry Smith MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 263487497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 263587497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 263677a5e07dSBarry Smith 2637d083f849SBarry Smith Collective 263877a5e07dSBarry Smith 263977a5e07dSBarry Smith Synopsis: 264077a5e07dSBarry Smith #include <petscsys.h> 264177a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 264277a5e07dSBarry Smith 264377a5e07dSBarry Smith Input Parameters: 2644df05ca09SBarry Smith + a - pointer to the input data to be reduced 2645df05ca09SBarry Smith . c - the number of MPI data items in a and b 264687497f52SBarry Smith . d - the MPI datatype, for example `MPI_INT` 264787497f52SBarry Smith . e - the MPI operation, for example `MPI_SUM` 2648df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 264977a5e07dSBarry Smith 265077a5e07dSBarry Smith Output Parameter: 2651df05ca09SBarry Smith . b - the reduced values 265277a5e07dSBarry Smith 2653e28ce29aSPatrick Sanan Notes: 265487497f52SBarry Smith In optimized mode this directly calls `MPI_Allreduce()` 265577a5e07dSBarry Smith 2656df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2657df05ca09SBarry Smith 265887497f52SBarry 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 2659df05ca09SBarry Smith 266077a5e07dSBarry Smith Level: developer 266177a5e07dSBarry Smith 2662db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 266377a5e07dSBarry Smith M*/ 26649371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 26659371c9d4SSatish 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)));) 2666b2566f29SBarry Smith #else 26671c2dc1cbSBarry Smith #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm)))) 2668b2566f29SBarry Smith #endif 2669b2566f29SBarry Smith 2670b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 26718198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 26728198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 26732f065d89SBarry Smith #endif 26748198064fSBarry Smith 2675cd88fca5SStefano Zampini /* this is a vile hack */ 2676cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 26779371c9d4SSatish 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) 2678cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2679cd88fca5SStefano Zampini #endif 2680961fb248SStefano Zampini #endif 2681cd88fca5SStefano Zampini 268212801b39SBarry Smith /* 268360fbe2beSVaclav Hapla List of external packages and queries on it 268460fbe2beSVaclav Hapla */ 268560fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 268660fbe2beSVaclav Hapla 2687a52b435bSMark Adams /* 2688a52b435bSMark Adams OpenMP support 2689a52b435bSMark Adams */ 2690a52b435bSMark Adams #if defined(_OPENMP) 2691a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__)) 2692a52b435bSMark Adams #else // no OpenMP so no threads 2693a52b435bSMark Adams #define PetscPragmaOMP(...) 2694a52b435bSMark Adams #endif 2695a52b435bSMark Adams 2696f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2697f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2698f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2699f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2700d382aafbSBarry Smith #endif 2701