1d382aafbSBarry Smith /* 2d382aafbSBarry Smith This is the main PETSc include file (for C and C++). It is included by all 3d382aafbSBarry Smith other PETSc include files, so it almost never has to be specifically included. 447d993e7Ssuyashtn Portions of this code are under: 547d993e7Ssuyashtn Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. 6d382aafbSBarry Smith */ 76524c165SJacob Faibussowitsch #ifndef PETSCSYS_H 826bd1501SBarry Smith #define PETSCSYS_H 93ca90d2dSJacob Faibussowitsch 10d382aafbSBarry Smith /* ========================================================================== */ 11d382aafbSBarry Smith /* 12d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 131c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 141c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules. 151c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 161cc8b206SBarry Smith directory as the other PETSc include files. 17d382aafbSBarry Smith */ 182c8e378dSBarry Smith #include <petscconf.h> 191c77a0c5SBarry Smith #include <petscconf_poison.h> 202c8e378dSBarry Smith #include <petscfix.h> 21bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2233bb201bSJacob Faibussowitsch 23ac09b921SBarry Smith /* SUBMANSEC = Sys */ 24ac09b921SBarry Smith 2573fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2673fca5a0SBarry Smith /* 2773fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2873fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2973fca5a0SBarry Smith */ 30216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 3173fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L 3273fca5a0SBarry Smith #endif 33216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3473fca5a0SBarry Smith #define _BSD_SOURCE 3573fca5a0SBarry Smith #endif 3607f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3707f00807SSatish Balay #define _DEFAULT_SOURCE 3807f00807SSatish Balay #endif 39ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 40ea0fecefSShri Abhyankar #define _GNU_SOURCE 41ea0fecefSShri Abhyankar #endif 4273fca5a0SBarry Smith #endif 4373fca5a0SBarry Smith 44df4397b0SStefano Zampini #include <petscsystypes.h> 45df4397b0SStefano Zampini 46d382aafbSBarry Smith /* ========================================================================== */ 47d382aafbSBarry Smith 48d382aafbSBarry Smith /* 49d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 50d382aafbSBarry Smith 51d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 52d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 53d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 54d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 55d382aafbSBarry Smith mpicxx.h directly in their code 56d382aafbSBarry Smith */ 57fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 58d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1 59fa9e63e2SJed Brown #endif 60fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 61d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1 62fa9e63e2SJed Brown #endif 63e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 64e771154cSJed Brown #include <petsc/mpiuni/mpi.h> 65e771154cSJed Brown #else 662c8e378dSBarry Smith #include <mpi.h> 67e771154cSJed Brown #endif 6865013866SBarry Smith 69d382aafbSBarry Smith /* 70a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 71a7886beaSBarry Smith This usually happens because 72a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 73a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 74a7886beaSBarry Smith */ 75a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 766524c165SJacob Faibussowitsch #ifndef MPIUNI_H 77a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 78a7886beaSBarry Smith #endif 7941f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 8041f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 8141f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 8241f4af4cSSatish Balay #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 8341f4af4cSSatish Balay #error "PETSc was configured with one I_MPI mpi.h version but now appears to be compiling using a different I_MPI mpi.h version" 8441f4af4cSSatish Balay #endif 8541f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 8641f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8741f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 8841f4af4cSSatish Balay #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 8941f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 9041f4af4cSSatish Balay #endif 91a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 9241f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 93a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 941c284764SMin RK #elif (MPICH_NUMVERSION / 100000000 != PETSC_HAVE_MPICH_NUMVERSION / 100000000) || (MPICH_NUMVERSION / 100000 < PETSC_HAVE_MPICH_NUMVERSION / 100000) || (MPICH_NUMVERSION / 100000 == PETSC_HAVE_MPICH_NUMVERSION / 100000 && MPICH_NUMVERSION % 100000 / 1000 < PETSC_HAVE_MPICH_NUMVERSION % 100000 / 1000) 95a7886beaSBarry Smith #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 96a7886beaSBarry Smith #endif 97a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 98a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 99a7886beaSBarry Smith #error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h" 1001c284764SMin RK #elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION) 101c3ac57cfSSatish Balay #error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version" 102a7886beaSBarry Smith #endif 103c93fae50SJacob Faibussowitsch #define PETSC_MPI_COMM_FMT "p" 104c93fae50SJacob Faibussowitsch #define PETSC_MPI_WIN_FMT "p" 105d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 106d97fd468SStefano Zampini #if !defined(MSMPI_VER) 107d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 108d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 109d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 110d97fd468SStefano Zampini #endif 111d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 112d97fd468SStefano Zampini #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant" 113a7886beaSBarry Smith #endif 114a7886beaSBarry Smith 115c93fae50SJacob Faibussowitsch /* Format specifier for printing MPI_Comm (most implementations use 'int' as type) */ 116c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_COMM_FMT) 117c93fae50SJacob Faibussowitsch #define PETSC_MPI_COMM_FMT "d" 118c93fae50SJacob Faibussowitsch #endif 119c93fae50SJacob Faibussowitsch 120c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_WIN_FMT) 121c93fae50SJacob Faibussowitsch #define PETSC_MPI_WIN_FMT "d" 122c93fae50SJacob Faibussowitsch #endif 123c93fae50SJacob Faibussowitsch 124a7886beaSBarry Smith /* 1252981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 126d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 127d382aafbSBarry Smith */ 128d382aafbSBarry Smith #include <stdio.h> 129d382aafbSBarry Smith 130d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 131d382aafbSBarry Smith #if !defined(MPIAPI) 132d382aafbSBarry Smith #define MPIAPI 133d382aafbSBarry Smith #endif 134d382aafbSBarry Smith 13593d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 13693d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 137e28ce29aSPatrick Sanan 138e28ce29aSPatrick Sanan /*MC 13987497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 140e28ce29aSPatrick Sanan 141e28ce29aSPatrick Sanan Notes: 14287497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 143e28ce29aSPatrick Sanan 144e28ce29aSPatrick Sanan Level: beginner 145e28ce29aSPatrick Sanan 146db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 147e28ce29aSPatrick Sanan M*/ 148e28ce29aSPatrick Sanan 1497cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 150b7b8f77aSBarry Smith 151d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 152bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 153a05e1a72SSatish Balay #define PetscInt_FMT PetscInt64_FMT 154d382aafbSBarry Smith #else 155d382aafbSBarry Smith #define MPIU_INT MPI_INT 156a05e1a72SSatish Balay #define PetscInt_FMT "d" 157d382aafbSBarry Smith #endif 158d382aafbSBarry Smith 159503cfb0cSBarry Smith /* 160503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 161503cfb0cSBarry Smith */ 16293d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 163d382aafbSBarry Smith 164d382aafbSBarry Smith /* 165d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 166d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 167d382aafbSBarry Smith */ 168014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 169d382aafbSBarry Smith 170d382aafbSBarry Smith /* 171d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 172d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 173d382aafbSBarry Smith */ 174014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 175d382aafbSBarry Smith 176c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */ 177c8b9133aSSatish Balay 1785c993f7fSStefano Zampini #if defined(__NEC__) 1795c993f7fSStefano Zampini #define PetscPragmaSIMD _Pragma("_NEC ivdep") 1805c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32) 181c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("vector") 1821dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI) 183c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("GCC ivdep") 184e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307 185e5518150SSatish Balay #if defined(_MSC_VER) 186160a5775SAli Reza Khaz'ali #define PetscPragmaSIMD __pragma(omp simd) 187e5518150SSatish Balay #else 188e5518150SSatish Balay #define PetscPragmaSIMD _Pragma("omp simd") 189e5518150SSatish Balay #endif 190c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR) 191c8b9133aSSatish Balay #define PetscPragmaSIMD _Pragma("_CRI ivdep") 192c8b9133aSSatish Balay #else 193c8b9133aSSatish Balay #define PetscPragmaSIMD 194c8b9133aSSatish Balay #endif 195c8b9133aSSatish Balay 196d382aafbSBarry Smith /* 197d382aafbSBarry Smith Declare extern C stuff after including external header files 198d382aafbSBarry Smith */ 199d382aafbSBarry Smith 2006a6fc655SJed Brown PETSC_EXTERN const char *const PetscBools[]; 20170b3c8c7SBarry Smith 2026edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 2038b49ba18SBarry Smith /* 204390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 2058b49ba18SBarry Smith */ 2068b49ba18SBarry Smith #include <petscmath.h> 2078b49ba18SBarry Smith 2086a6fc655SJed Brown PETSC_EXTERN const char *const PetscCopyModes[]; 209d382aafbSBarry Smith 210d382aafbSBarry Smith /*MC 2110298fd71SBarry Smith PETSC_IGNORE - same as NULL, means PETSc will ignore this argument 212d382aafbSBarry Smith 213d382aafbSBarry Smith Level: beginner 214d382aafbSBarry Smith 215e28ce29aSPatrick Sanan Note: 21687497f52SBarry Smith Accepted by many PETSc functions to not set a parameter and instead use some default 217d382aafbSBarry Smith 21887497f52SBarry Smith Fortran Note: 21987497f52SBarry Smith This macro does not exist in Fortran; you must use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 220d382aafbSBarry Smith 221db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 222d382aafbSBarry Smith 223d382aafbSBarry Smith M*/ 2240298fd71SBarry Smith #define PETSC_IGNORE NULL 225d382aafbSBarry Smith 226c528d872SBarry Smith /* This is deprecated */ 227c528d872SBarry Smith #define PETSC_NULL NULL 228c528d872SBarry Smith 229d382aafbSBarry Smith /*MC 230557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 231557d4da8SBarry Smith where you wish PETSc to use the default. 232557d4da8SBarry Smith 233557d4da8SBarry Smith Level: beginner 234557d4da8SBarry Smith 235db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 236557d4da8SBarry Smith 237557d4da8SBarry Smith M*/ 238557d4da8SBarry Smith #define PETSC_DECIDE -1 239557d4da8SBarry Smith 240557d4da8SBarry Smith /*MC 241d382aafbSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter 242d382aafbSBarry Smith where you wish PETSc to compute the required value. 243d382aafbSBarry Smith 244d382aafbSBarry Smith Level: beginner 245d382aafbSBarry Smith 246e28ce29aSPatrick Sanan Developer Note: 24787497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 24887497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 249557d4da8SBarry Smith 250db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 251d382aafbSBarry Smith 252d382aafbSBarry Smith M*/ 253d382aafbSBarry Smith #define PETSC_DETERMINE PETSC_DECIDE 254d382aafbSBarry Smith 255d382aafbSBarry Smith /*MC 256557d4da8SBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter 257557d4da8SBarry Smith where you wish PETSc to use the default. 258557d4da8SBarry Smith 259557d4da8SBarry Smith Level: beginner 260557d4da8SBarry Smith 26187497f52SBarry Smith Fortran Note: 26287497f52SBarry Smith You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 263557d4da8SBarry Smith 264db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 265557d4da8SBarry Smith 266557d4da8SBarry Smith M*/ 267557d4da8SBarry Smith #define PETSC_DEFAULT -2 268557d4da8SBarry Smith 269557d4da8SBarry Smith /*MC 27087497f52SBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents 271ea8fe74dSBarry Smith all the processes that PETSc knows about. 272d382aafbSBarry Smith 273d382aafbSBarry Smith Level: beginner 274d382aafbSBarry Smith 275e28ce29aSPatrick Sanan Notes: 27687497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 27787497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 27887497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 27987497f52SBarry Smith PetscInitialize(), but after `MPI_Init()` has been called. 280a990b902SBarry Smith 28187497f52SBarry Smith The value of `PETSC_COMM_WORLD` should never be USED/accessed before `PetscInitialize()` 282a990b902SBarry Smith is called because it may not have a valid value yet. 283d382aafbSBarry Smith 284db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 285d382aafbSBarry Smith 286d382aafbSBarry Smith M*/ 287014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 288d382aafbSBarry Smith 289d382aafbSBarry Smith /*MC 29087497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 291d382aafbSBarry Smith 292d382aafbSBarry Smith Level: beginner 293d382aafbSBarry Smith 294e28ce29aSPatrick Sanan Notes: 295e28ce29aSPatrick Sanan Do not USE/access or set this variable before PetscInitialize() has been called. 296a990b902SBarry Smith 297db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 298d382aafbSBarry Smith 299d382aafbSBarry Smith M*/ 300d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 301d382aafbSBarry Smith 3026de5d289SStefano Zampini /*MC 3036de5d289SStefano Zampini PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes 30487497f52SBarry Smith MPI with `MPI_Init_thread()`. 3056de5d289SStefano Zampini 3066de5d289SStefano Zampini Level: beginner 3076de5d289SStefano Zampini 3086de5d289SStefano Zampini Notes: 30987497f52SBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED`. 3106de5d289SStefano Zampini 311db781477SPatrick Sanan .seealso: `PetscInitialize()` 3126de5d289SStefano Zampini 3136de5d289SStefano Zampini M*/ 3146de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3156de5d289SStefano Zampini 316d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 3178ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 318014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 319014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3204cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 321d382aafbSBarry Smith 322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 323014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 32557f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 32657f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 327d382aafbSBarry Smith 32859e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 32959e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 33059e55d94SJunchao Zhang #endif 33159e55d94SJunchao Zhang 33271438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 33371438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 33471438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 33571438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 33671438e86SJunchao Zhang #endif 33771438e86SJunchao Zhang 338540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 339540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 340540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 341540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 342540e20f2SPierre Jolivet #endif 343540e20f2SPierre Jolivet 344d382aafbSBarry Smith /*MC 34587497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 346d382aafbSBarry Smith 347eca87e8dSBarry Smith Synopsis: 348aaa7dc30SBarry Smith #include <petscsys.h> 349eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 350eca87e8dSBarry Smith 351eca87e8dSBarry Smith Not Collective 352eca87e8dSBarry Smith 353d382aafbSBarry Smith Input Parameter: 354d382aafbSBarry Smith . m - number of bytes to allocate 355d382aafbSBarry Smith 356d382aafbSBarry Smith Output Parameter: 357d382aafbSBarry Smith . result - memory allocated 358d382aafbSBarry Smith 359d382aafbSBarry Smith Level: beginner 360d382aafbSBarry Smith 36149d7da52SJed Brown Notes: 36249d7da52SJed Brown Memory is always allocated at least double aligned 363d382aafbSBarry Smith 36487497f52SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to `PetscFree()`. 365d382aafbSBarry Smith 366db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 367d382aafbSBarry Smith 368d382aafbSBarry Smith M*/ 369071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 370d382aafbSBarry Smith 371d382aafbSBarry Smith /*MC 372*d5b43468SJose E. Roman PetscRealloc - Reallocates memory 3733221ece2SMatthew G. Knepley 3743221ece2SMatthew G. Knepley Synopsis: 3753221ece2SMatthew G. Knepley #include <petscsys.h> 3763221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3773221ece2SMatthew G. Knepley 3783221ece2SMatthew G. Knepley Not Collective 3793221ece2SMatthew G. Knepley 3803221ece2SMatthew G. Knepley Input Parameters: 3813221ece2SMatthew G. Knepley + m - number of bytes to allocate 38292f119d6SBarry Smith - result - previous memory 3833221ece2SMatthew G. Knepley 3843221ece2SMatthew G. Knepley Output Parameter: 3853221ece2SMatthew G. Knepley . result - new memory allocated 3863221ece2SMatthew G. Knepley 3873221ece2SMatthew G. Knepley Level: developer 3883221ece2SMatthew G. Knepley 3893221ece2SMatthew G. Knepley Notes: 3903221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 3913221ece2SMatthew G. Knepley 392db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 3933221ece2SMatthew G. Knepley 3943221ece2SMatthew G. Knepley M*/ 3953221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 3963221ece2SMatthew G. Knepley 3973221ece2SMatthew G. Knepley /*MC 39887497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 399d382aafbSBarry Smith 400d382aafbSBarry Smith Synopsis: 401aaa7dc30SBarry Smith #include <petscsys.h> 402d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 403d382aafbSBarry Smith 404eca87e8dSBarry Smith Not Collective 405eca87e8dSBarry Smith 406eca87e8dSBarry Smith Input Parameters: 407eca87e8dSBarry Smith . addr - address to align (any pointer type) 408eca87e8dSBarry Smith 409d382aafbSBarry Smith Level: developer 410d382aafbSBarry Smith 411db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 412d382aafbSBarry Smith 413d382aafbSBarry Smith M*/ 414d382aafbSBarry Smith #define PetscAddrAlign(a) (void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1)) 415d382aafbSBarry Smith 416d382aafbSBarry Smith /*MC 41787497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 4188f51dc47SJunchao Zhang 4198f51dc47SJunchao Zhang Synopsis: 4208f51dc47SJunchao Zhang #include <petscsys.h> 4218f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4228f51dc47SJunchao Zhang 4238f51dc47SJunchao Zhang Not Collective 4248f51dc47SJunchao Zhang 4258f51dc47SJunchao Zhang Input Parameter: 4268f51dc47SJunchao Zhang . m - number of bytes to allocate 4278f51dc47SJunchao Zhang 4288f51dc47SJunchao Zhang Output Parameter: 4298f51dc47SJunchao Zhang . result - memory allocated 4308f51dc47SJunchao Zhang 4318f51dc47SJunchao Zhang Level: beginner 4328f51dc47SJunchao Zhang 4338f51dc47SJunchao Zhang Notes: 4348f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4358f51dc47SJunchao Zhang 4368f51dc47SJunchao Zhang It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 4378f51dc47SJunchao Zhang 438db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4398f51dc47SJunchao Zhang 4408f51dc47SJunchao Zhang M*/ 44166122d6dSBarry Smith #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m), (result)) 4428f51dc47SJunchao Zhang 4438f51dc47SJunchao Zhang /*MC 44487497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 445d382aafbSBarry Smith 446eca87e8dSBarry Smith Synopsis: 447aaa7dc30SBarry Smith #include <petscsys.h> 448785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 449785e854fSJed Brown 450785e854fSJed Brown Not Collective 451785e854fSJed Brown 452785e854fSJed Brown Input Parameter: 453390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 454785e854fSJed Brown 455785e854fSJed Brown Output Parameter: 4561fe1b817SJunchao Zhang . r1 - memory allocated 457785e854fSJed Brown 458e28ce29aSPatrick Sanan Note: 459e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 46087497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 461390e1bf2SBarry Smith $ PetscInt *id; 462390e1bf2SBarry Smith $ PetscMalloc1(10,&id); 463390e1bf2SBarry Smith not 464390e1bf2SBarry Smith $ PetscInt *id; 465390e1bf2SBarry Smith $ PetscMalloc1(10*sizeof(PetscInt),&id); 466390e1bf2SBarry Smith 46787497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 468390e1bf2SBarry Smith 469390e1bf2SBarry Smith Level: beginner 470785e854fSJed Brown 471db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 472785e854fSJed Brown 473785e854fSJed Brown M*/ 47466122d6dSBarry Smith #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 475785e854fSJed Brown 476785e854fSJed Brown /*MC 47787497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 4781795a4d1SJed Brown 4791795a4d1SJed Brown Synopsis: 480aaa7dc30SBarry Smith #include <petscsys.h> 4811795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 4821795a4d1SJed Brown 4831795a4d1SJed Brown Not Collective 4841795a4d1SJed Brown 4851795a4d1SJed Brown Input Parameter: 4861795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 4871795a4d1SJed Brown 4881795a4d1SJed Brown Output Parameter: 4891fe1b817SJunchao Zhang . r1 - memory allocated 4901795a4d1SJed Brown 491e28ce29aSPatrick Sanan Notes: 49287497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 493390e1bf2SBarry Smith 494390e1bf2SBarry Smith Level: beginner 4951795a4d1SJed Brown 496db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 4971795a4d1SJed Brown 4981795a4d1SJed Brown M*/ 49966122d6dSBarry Smith #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size_t)((size_t)m1) * sizeof(**(r1)), (r1)) 5001795a4d1SJed Brown 5011795a4d1SJed Brown /*MC 50287497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 503d382aafbSBarry Smith 504eca87e8dSBarry Smith Synopsis: 505aaa7dc30SBarry Smith #include <petscsys.h> 506dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 507eca87e8dSBarry Smith 508eca87e8dSBarry Smith Not Collective 509eca87e8dSBarry Smith 510d8d19677SJose E. Roman Input Parameters: 511d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 512dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 513d382aafbSBarry Smith 514d8d19677SJose E. Roman Output Parameters: 515d382aafbSBarry Smith + r1 - memory allocated in first chunk 516d382aafbSBarry Smith - r2 - memory allocated in second chunk 517d382aafbSBarry Smith 518d382aafbSBarry Smith Level: developer 519d382aafbSBarry Smith 520db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 521d382aafbSBarry Smith 522d382aafbSBarry Smith M*/ 52366122d6dSBarry 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)) 524d382aafbSBarry Smith 525d382aafbSBarry Smith /*MC 52687497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 527d382aafbSBarry Smith 528eca87e8dSBarry Smith Synopsis: 529aaa7dc30SBarry Smith #include <petscsys.h> 5301795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 531eca87e8dSBarry Smith 532eca87e8dSBarry Smith Not Collective 533eca87e8dSBarry Smith 534d8d19677SJose E. Roman Input Parameters: 535d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5361795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5371795a4d1SJed Brown 538d8d19677SJose E. Roman Output Parameters: 5391795a4d1SJed Brown + r1 - memory allocated in first chunk 5401795a4d1SJed Brown - r2 - memory allocated in second chunk 5411795a4d1SJed Brown 5421795a4d1SJed Brown Level: developer 5431795a4d1SJed Brown 544db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5451795a4d1SJed Brown 5461795a4d1SJed Brown M*/ 54766122d6dSBarry 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)) 5481795a4d1SJed Brown 5491795a4d1SJed Brown /*MC 55087497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 551d382aafbSBarry Smith 552d382aafbSBarry Smith Synopsis: 553aaa7dc30SBarry Smith #include <petscsys.h> 554dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 555d382aafbSBarry Smith 556d382aafbSBarry Smith Not Collective 557d382aafbSBarry Smith 558d8d19677SJose E. Roman Input Parameters: 559d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 560d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 561dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 562d382aafbSBarry Smith 563d8d19677SJose E. Roman Output Parameters: 564d382aafbSBarry Smith + r1 - memory allocated in first chunk 565d382aafbSBarry Smith . r2 - memory allocated in second chunk 566d382aafbSBarry Smith - r3 - memory allocated in third chunk 567d382aafbSBarry Smith 568d382aafbSBarry Smith Level: developer 569d382aafbSBarry Smith 570db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 571d382aafbSBarry Smith 572d382aafbSBarry Smith M*/ 57366122d6dSBarry 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)) 574d382aafbSBarry Smith 575d382aafbSBarry Smith /*MC 57687497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 577d382aafbSBarry Smith 578eca87e8dSBarry Smith Synopsis: 579aaa7dc30SBarry Smith #include <petscsys.h> 5801795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 581eca87e8dSBarry Smith 582eca87e8dSBarry Smith Not Collective 583eca87e8dSBarry Smith 584d8d19677SJose E. Roman Input Parameters: 585d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 586d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 5871795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 5881795a4d1SJed Brown 589d8d19677SJose E. Roman Output Parameters: 5901795a4d1SJed Brown + r1 - memory allocated in first chunk 5911795a4d1SJed Brown . r2 - memory allocated in second chunk 5921795a4d1SJed Brown - r3 - memory allocated in third chunk 5931795a4d1SJed Brown 5941795a4d1SJed Brown Level: developer 5951795a4d1SJed Brown 596db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 5971795a4d1SJed Brown 5981795a4d1SJed Brown M*/ 59966122d6dSBarry 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)) 6001795a4d1SJed Brown 6011795a4d1SJed Brown /*MC 60287497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 603d382aafbSBarry Smith 604d382aafbSBarry Smith Synopsis: 605aaa7dc30SBarry Smith #include <petscsys.h> 606dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 607d382aafbSBarry Smith 608d382aafbSBarry Smith Not Collective 609d382aafbSBarry Smith 610d8d19677SJose E. Roman Input Parameters: 611d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 612d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 613d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 614dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 615d382aafbSBarry Smith 616d8d19677SJose E. Roman Output Parameters: 617d382aafbSBarry Smith + r1 - memory allocated in first chunk 618d382aafbSBarry Smith . r2 - memory allocated in second chunk 619d382aafbSBarry Smith . r3 - memory allocated in third chunk 620d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 621d382aafbSBarry Smith 622d382aafbSBarry Smith Level: developer 623d382aafbSBarry Smith 624db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 625d382aafbSBarry Smith 626d382aafbSBarry Smith M*/ 6279371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6289371c9d4SSatish 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)) 629d382aafbSBarry Smith 630d382aafbSBarry Smith /*MC 63187497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 632d382aafbSBarry Smith 633eca87e8dSBarry Smith Synopsis: 634aaa7dc30SBarry Smith #include <petscsys.h> 6351795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 636eca87e8dSBarry Smith 637eca87e8dSBarry Smith Not Collective 638eca87e8dSBarry Smith 639e28ce29aSPatrick Sanan Input Parameters: 640d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 641d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 642d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6431795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6441795a4d1SJed Brown 645e28ce29aSPatrick Sanan Output Parameters: 6461795a4d1SJed Brown + r1 - memory allocated in first chunk 6471795a4d1SJed Brown . r2 - memory allocated in second chunk 6481795a4d1SJed Brown . r3 - memory allocated in third chunk 6491795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6501795a4d1SJed Brown 6511795a4d1SJed Brown Level: developer 6521795a4d1SJed Brown 653db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6541795a4d1SJed Brown 6551795a4d1SJed Brown M*/ 6569371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 6579371c9d4SSatish 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)) 6581795a4d1SJed Brown 6591795a4d1SJed Brown /*MC 66087497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 661d382aafbSBarry Smith 662d382aafbSBarry Smith Synopsis: 663aaa7dc30SBarry Smith #include <petscsys.h> 664dcca6d9dSJed 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) 665d382aafbSBarry Smith 666d382aafbSBarry Smith Not Collective 667d382aafbSBarry Smith 668e28ce29aSPatrick Sanan Input Parameters: 669d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 670d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 671d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 672d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 673dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 674d382aafbSBarry Smith 675e28ce29aSPatrick Sanan Output Parameters: 676d382aafbSBarry Smith + r1 - memory allocated in first chunk 677d382aafbSBarry Smith . r2 - memory allocated in second chunk 678d382aafbSBarry Smith . r3 - memory allocated in third chunk 679d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 680d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 681d382aafbSBarry Smith 682d382aafbSBarry Smith Level: developer 683d382aafbSBarry Smith 684db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 685d382aafbSBarry Smith 686d382aafbSBarry Smith M*/ 6879371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 6889371c9d4SSatish 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)) 689d382aafbSBarry Smith 690d382aafbSBarry Smith /*MC 69187497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 692d382aafbSBarry Smith 693eca87e8dSBarry Smith Synopsis: 694aaa7dc30SBarry Smith #include <petscsys.h> 6951795a4d1SJed 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) 696eca87e8dSBarry Smith 697eca87e8dSBarry Smith Not Collective 698eca87e8dSBarry Smith 699e28ce29aSPatrick Sanan Input Parameters: 700d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 701d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 702d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 703d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 7041795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 7051795a4d1SJed Brown 706e28ce29aSPatrick Sanan Output Parameters: 7071795a4d1SJed Brown + r1 - memory allocated in first chunk 7081795a4d1SJed Brown . r2 - memory allocated in second chunk 7091795a4d1SJed Brown . r3 - memory allocated in third chunk 7101795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7111795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7121795a4d1SJed Brown 7131795a4d1SJed Brown Level: developer 7141795a4d1SJed Brown 715db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7161795a4d1SJed Brown 7171795a4d1SJed Brown M*/ 7189371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 7199371c9d4SSatish 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)) 720d382aafbSBarry Smith 721d382aafbSBarry Smith /*MC 72287497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 723d382aafbSBarry Smith 724d382aafbSBarry Smith Synopsis: 725aaa7dc30SBarry Smith #include <petscsys.h> 726dcca6d9dSJed 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) 727d382aafbSBarry Smith 728d382aafbSBarry Smith Not Collective 729d382aafbSBarry Smith 730e28ce29aSPatrick Sanan Input Parameters: 731d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 732d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 733d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 734d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 735d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 736dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 737d382aafbSBarry Smith 738e28ce29aSPatrick Sanan Output Parameteasr: 739d382aafbSBarry Smith + r1 - memory allocated in first chunk 740d382aafbSBarry Smith . r2 - memory allocated in second chunk 741d382aafbSBarry Smith . r3 - memory allocated in third chunk 742d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 743d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 744d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 745d382aafbSBarry Smith 746d382aafbSBarry Smith Level: developer 747d382aafbSBarry Smith 748db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 749d382aafbSBarry Smith 750d382aafbSBarry Smith M*/ 7519371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7529371c9d4SSatish 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)) 753d382aafbSBarry Smith 754d382aafbSBarry Smith /*MC 75587497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 756d382aafbSBarry Smith 757eca87e8dSBarry Smith Synopsis: 758aaa7dc30SBarry Smith #include <petscsys.h> 7591795a4d1SJed 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) 760eca87e8dSBarry Smith 761eca87e8dSBarry Smith Not Collective 762eca87e8dSBarry Smith 763e28ce29aSPatrick Sanan Input Parameters: 764d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 765d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 766d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 767d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 768d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7691795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7701795a4d1SJed Brown 771e28ce29aSPatrick Sanan Output Parameters: 7721795a4d1SJed Brown + r1 - memory allocated in first chunk 7731795a4d1SJed Brown . r2 - memory allocated in second chunk 7741795a4d1SJed Brown . r3 - memory allocated in third chunk 7751795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7761795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7771795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7781795a4d1SJed Brown 7791795a4d1SJed Brown Level: developer 7801795a4d1SJed Brown 781db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7821795a4d1SJed Brown 7831795a4d1SJed Brown M*/ 7849371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 7859371c9d4SSatish 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)) 7861795a4d1SJed Brown 7871795a4d1SJed Brown /*MC 78887497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 789d382aafbSBarry Smith 790d382aafbSBarry Smith Synopsis: 791aaa7dc30SBarry Smith #include <petscsys.h> 792dcca6d9dSJed 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) 793d382aafbSBarry Smith 794d382aafbSBarry Smith Not Collective 795d382aafbSBarry Smith 796e28ce29aSPatrick Sanan Input Parameters: 797d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 798d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 799d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 800d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 801d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 802d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 803dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 804d382aafbSBarry Smith 805e28ce29aSPatrick Sanan Output Parameters: 806d382aafbSBarry Smith + r1 - memory allocated in first chunk 807d382aafbSBarry Smith . r2 - memory allocated in second chunk 808d382aafbSBarry Smith . r3 - memory allocated in third chunk 809d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 810d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 811d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 812eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 813d382aafbSBarry Smith 814d382aafbSBarry Smith Level: developer 815d382aafbSBarry Smith 816db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 817d382aafbSBarry Smith 818d382aafbSBarry Smith M*/ 8199371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8209371c9d4SSatish 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)) 821d382aafbSBarry Smith 822d382aafbSBarry Smith /*MC 82387497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 8241795a4d1SJed Brown 8251795a4d1SJed Brown Synopsis: 826aaa7dc30SBarry Smith #include <petscsys.h> 8271795a4d1SJed 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) 8281795a4d1SJed Brown 8291795a4d1SJed Brown Not Collective 8301795a4d1SJed Brown 831e28ce29aSPatrick Sanan Input Parameters: 8321795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8331795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8341795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8351795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8361795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8371795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8381795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8391795a4d1SJed Brown 840e28ce29aSPatrick Sanan Output Parameters: 8411795a4d1SJed Brown + r1 - memory allocated in first chunk 8421795a4d1SJed Brown . r2 - memory allocated in second chunk 8431795a4d1SJed Brown . r3 - memory allocated in third chunk 8441795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8451795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8461795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8471795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8481795a4d1SJed Brown 8491795a4d1SJed Brown Level: developer 8501795a4d1SJed Brown 851db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8521795a4d1SJed Brown 8531795a4d1SJed Brown M*/ 8549371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 8559371c9d4SSatish 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)) 8561795a4d1SJed Brown 8571795a4d1SJed Brown /*MC 85887497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 859d382aafbSBarry Smith 860eca87e8dSBarry Smith Synopsis: 861aaa7dc30SBarry Smith #include <petscsys.h> 862b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 863eca87e8dSBarry Smith 864eca87e8dSBarry Smith Not Collective 865eca87e8dSBarry Smith 866d382aafbSBarry Smith Output Parameter: 867b00a9115SJed Brown . result - memory allocated, sized to match pointer type 868d382aafbSBarry Smith 869d382aafbSBarry Smith Level: beginner 870d382aafbSBarry Smith 871fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 872d382aafbSBarry Smith 873d382aafbSBarry Smith M*/ 874b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 875ad0619ddSBarry Smith 8764dfa11a4SJacob Faibussowitsch #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO("GCC warning \"PetscNewLog is deprecated, use PetscNew() instead (since version 3.18)\"") PetscNew((b)) 877d382aafbSBarry Smith 878d382aafbSBarry Smith /*MC 879d382aafbSBarry Smith PetscFree - Frees memory 880d382aafbSBarry Smith 881eca87e8dSBarry Smith Synopsis: 882aaa7dc30SBarry Smith #include <petscsys.h> 883eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 884eca87e8dSBarry Smith 885eca87e8dSBarry Smith Not Collective 886eca87e8dSBarry Smith 887d382aafbSBarry Smith Input Parameter: 8887f4976b7SJacob Faibussowitsch . memory - memory to free (the pointer is ALWAYS set to NULL upon success) 889d382aafbSBarry Smith 890d382aafbSBarry Smith Level: beginner 891d382aafbSBarry Smith 89249d7da52SJed Brown Notes: 89387497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 894390e1bf2SBarry Smith 89587497f52SBarry Smith It is safe to call `PetscFree()` on a NULL pointer. 896d382aafbSBarry Smith 897fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 898d382aafbSBarry Smith 899d382aafbSBarry Smith M*/ 900ffc31a0eSLisandro Dalcin #define PetscFree(a) ((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = NULL, 0)) 901d382aafbSBarry Smith 902d382aafbSBarry Smith /*MC 90387497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 904d382aafbSBarry Smith 905eca87e8dSBarry Smith Synopsis: 906aaa7dc30SBarry Smith #include <petscsys.h> 907eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 908eca87e8dSBarry Smith 909eca87e8dSBarry Smith Not Collective 910eca87e8dSBarry Smith 911e28ce29aSPatrick Sanan Input Parameters: 912d382aafbSBarry Smith + memory1 - memory to free 913d382aafbSBarry Smith - memory2 - 2nd memory to free 914d382aafbSBarry Smith 915d382aafbSBarry Smith Level: developer 916d382aafbSBarry Smith 91795452b02SPatrick Sanan Notes: 91887497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 919d382aafbSBarry Smith 920db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 921d382aafbSBarry Smith 922d382aafbSBarry Smith M*/ 923ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 924d382aafbSBarry Smith 925d382aafbSBarry Smith /*MC 92687497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 927d382aafbSBarry Smith 928eca87e8dSBarry Smith Synopsis: 929aaa7dc30SBarry Smith #include <petscsys.h> 930eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 931eca87e8dSBarry Smith 932eca87e8dSBarry Smith Not Collective 933eca87e8dSBarry Smith 934e28ce29aSPatrick Sanan Input Parameters: 935d382aafbSBarry Smith + memory1 - memory to free 936d382aafbSBarry Smith . memory2 - 2nd memory to free 937d382aafbSBarry Smith - memory3 - 3rd memory to free 938d382aafbSBarry Smith 939d382aafbSBarry Smith Level: developer 940d382aafbSBarry Smith 94195452b02SPatrick Sanan Notes: 94287497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 943d382aafbSBarry Smith 944db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 945d382aafbSBarry Smith 946d382aafbSBarry Smith M*/ 947ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 948d382aafbSBarry Smith 949d382aafbSBarry Smith /*MC 95087497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 951d382aafbSBarry Smith 952eca87e8dSBarry Smith Synopsis: 953aaa7dc30SBarry Smith #include <petscsys.h> 954eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 955eca87e8dSBarry Smith 956eca87e8dSBarry Smith Not Collective 957eca87e8dSBarry Smith 958e28ce29aSPatrick Sanan Input Parameters: 959d382aafbSBarry Smith + m1 - memory to free 960d382aafbSBarry Smith . m2 - 2nd memory to free 961d382aafbSBarry Smith . m3 - 3rd memory to free 962d382aafbSBarry Smith - m4 - 4th memory to free 963d382aafbSBarry Smith 964d382aafbSBarry Smith Level: developer 965d382aafbSBarry Smith 96695452b02SPatrick Sanan Notes: 96787497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 968d382aafbSBarry Smith 969db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 970d382aafbSBarry Smith 971d382aafbSBarry Smith M*/ 972ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 973d382aafbSBarry Smith 974d382aafbSBarry Smith /*MC 97587497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 976d382aafbSBarry Smith 977eca87e8dSBarry Smith Synopsis: 978aaa7dc30SBarry Smith #include <petscsys.h> 979eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 980eca87e8dSBarry Smith 981eca87e8dSBarry Smith Not Collective 982eca87e8dSBarry Smith 983e28ce29aSPatrick Sanan Input Parameters: 984d382aafbSBarry Smith + m1 - memory to free 985d382aafbSBarry Smith . m2 - 2nd memory to free 986d382aafbSBarry Smith . m3 - 3rd memory to free 987d382aafbSBarry Smith . m4 - 4th memory to free 988d382aafbSBarry Smith - m5 - 5th memory to free 989d382aafbSBarry Smith 990d382aafbSBarry Smith Level: developer 991d382aafbSBarry Smith 99295452b02SPatrick Sanan Notes: 99387497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 994d382aafbSBarry Smith 995db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 996d382aafbSBarry Smith 997d382aafbSBarry Smith M*/ 998ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 999d382aafbSBarry Smith 1000d382aafbSBarry Smith /*MC 100187497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 1002d382aafbSBarry Smith 1003eca87e8dSBarry Smith Synopsis: 1004aaa7dc30SBarry Smith #include <petscsys.h> 1005eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1006eca87e8dSBarry Smith 1007eca87e8dSBarry Smith Not Collective 1008eca87e8dSBarry Smith 1009e28ce29aSPatrick Sanan Input Parameters: 1010d382aafbSBarry Smith + m1 - memory to free 1011d382aafbSBarry Smith . m2 - 2nd memory to free 1012d382aafbSBarry Smith . m3 - 3rd memory to free 1013d382aafbSBarry Smith . m4 - 4th memory to free 1014d382aafbSBarry Smith . m5 - 5th memory to free 1015d382aafbSBarry Smith - m6 - 6th memory to free 1016d382aafbSBarry Smith 1017d382aafbSBarry Smith Level: developer 1018d382aafbSBarry Smith 101995452b02SPatrick Sanan Notes: 102087497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 1021d382aafbSBarry Smith 1022db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1023d382aafbSBarry Smith 1024d382aafbSBarry Smith M*/ 1025ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 1026d382aafbSBarry Smith 1027d382aafbSBarry Smith /*MC 102887497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 1029d382aafbSBarry Smith 1030eca87e8dSBarry Smith Synopsis: 1031aaa7dc30SBarry Smith #include <petscsys.h> 1032eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1033eca87e8dSBarry Smith 1034eca87e8dSBarry Smith Not Collective 1035eca87e8dSBarry Smith 1036e28ce29aSPatrick Sanan Input Parameters: 1037d382aafbSBarry Smith + m1 - memory to free 1038d382aafbSBarry Smith . m2 - 2nd memory to free 1039d382aafbSBarry Smith . m3 - 3rd memory to free 1040d382aafbSBarry Smith . m4 - 4th memory to free 1041d382aafbSBarry Smith . m5 - 5th memory to free 1042d382aafbSBarry Smith . m6 - 6th memory to free 1043d382aafbSBarry Smith - m7 - 7th memory to free 1044d382aafbSBarry Smith 1045d382aafbSBarry Smith Level: developer 1046d382aafbSBarry Smith 104795452b02SPatrick Sanan Notes: 104887497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1049d382aafbSBarry Smith 1050db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1051db781477SPatrick Sanan `PetscMalloc7()` 1052d382aafbSBarry Smith 1053d382aafbSBarry Smith M*/ 1054ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1055d382aafbSBarry Smith 1056ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1057ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1058071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1059efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 10603221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1061ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 106292f119d6SBarry 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 **)); 1063014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1064d382aafbSBarry Smith 1065d382aafbSBarry Smith /* 1066c1706be6SHong 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. 1067c1706be6SHong Zhang */ 1068c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1069c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 107031f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 107131f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 107231f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 107331f06eaaSHong Zhang #endif 107459af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 107559af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 107659af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 107759af0bd3SScott Kruger #endif 107859af0bd3SScott Kruger 1079a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 108036763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1081a5057860SBarry Smith 1082a5057860SBarry Smith /* 108366d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1084d382aafbSBarry Smith */ 1085014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 108692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1087014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1088014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1089e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1090e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 109192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 109292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1093efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 109492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 109592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1096608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1097608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1098d382aafbSBarry Smith 10996a6fc655SJed Brown PETSC_EXTERN const char *const PetscDataTypes[]; 1100014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1101014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1102014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 11038e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1104d382aafbSBarry Smith 1105d382aafbSBarry Smith /* 1106d382aafbSBarry Smith Basic memory and string operations. These are usually simple wrappers 1107d382aafbSBarry Smith around the basic Unix system calls, but a few of them have additional 1108d382aafbSBarry Smith functionality and/or error checking. 1109d382aafbSBarry Smith */ 1110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemcmp(const void *, const void *, size_t, PetscBool *); 1111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrlen(const char[], size_t *); 1112d67fe73bSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[], char, int *, char ***); 1113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int, char **); 1114014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[], const char[], PetscBool *); 1115014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[], const char[], PetscBool *); 1116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[], const char[], PetscBool *); 1117014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[], const char[], size_t, PetscBool *); 1118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcpy(char[], const char[]); 1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcat(char[], const char[]); 1120a126751eSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrlcat(char[], const char[], size_t); 1121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncpy(char[], const char[], size_t); 1122014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrchr(const char[], char, char *[]); 1123014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]); 11242f234a98SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]); 1125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[], char, char *[]); 1126014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrstr(const char[], const char[], char *[]); 1127014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[], const char[], char *[]); 1128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[], const char[], PetscBool *); 11292c9581d2SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[], const char[], PetscBool *); 1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[], const char *const *, PetscInt *); 1131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[], char *[]); 113247340559SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const *, char ***); 11336fed8037SJed Brown PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char ***); 11346991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt, const char *const *, char ***); 11356991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt, char ***); 1136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm, const char[], char[], size_t); 1137d382aafbSBarry Smith 1138573b0fb4SBarry Smith PETSC_EXTERN void PetscStrcmpNoError(const char[], const char[], PetscBool *); 1139573b0fb4SBarry Smith 1140014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[], const char, PetscToken *); 1141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken, char *[]); 1142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken *); 1143d382aafbSBarry Smith 1144e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscStrInList(const char[], const char[], char, PetscBool *); 114580b92c66SBarry Smith PETSC_EXTERN const char *PetscBasename(const char[]); 1146a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt, const char *const *, const char *, PetscInt *, PetscBool *); 1147a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const *, const char *, PetscEnum *, PetscBool *); 1148a53986e1SJed Brown 1149d382aafbSBarry Smith /* 1150d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1151d382aafbSBarry Smith */ 1152367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1153570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1154de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1155014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1156014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1157d9822059SBarry Smith #else 1158de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1159d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1160d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1161d9822059SBarry Smith #endif 116262e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 116362e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 116462e5d2d2SJDBetteridge 11659e517322SPierre Jolivet #if defined(PETSC_HAVE_REAL___FLOAT128) || defined(PETSC_HAVE_REAL___FP16) 1166613bf2b2SPierre Jolivet /*MC 11679e517322SPierre Jolivet MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for MPI_SUM with 11689e517322SPierre Jolivet custom MPI_Datatype `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1169613bf2b2SPierre Jolivet 1170613bf2b2SPierre Jolivet Level: advanced 1171613bf2b2SPierre Jolivet 1172613bf2b2SPierre Jolivet Developer Note: 1173613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1174613bf2b2SPierre Jolivet 1175613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1176613bf2b2SPierre Jolivet M*/ 11779e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1178613bf2b2SPierre Jolivet #endif 1179014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1180d382aafbSBarry Smith 118193d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 118293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1183eb3f98d2SBarry Smith 118495c0884eSLisandro Dalcin PETSC_EXTERN const char *const PetscFileModes[]; 1185d6a4318aSJed Brown 1186639ff905SBarry Smith /* 1187639ff905SBarry Smith Defines PETSc error handling. 1188639ff905SBarry Smith */ 1189639ff905SBarry Smith #include <petscerror.h> 1190d382aafbSBarry Smith 1191660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1192660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1193660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1194660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1195660278c0SBarry Smith 11960700a824SBarry Smith #define PETSC_SMALLEST_CLASSID 1211211 1197014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1198014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1199014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 120081256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 120181256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 120281256985SMatthew G. Knepley 1203d382aafbSBarry Smith /* 1204d382aafbSBarry Smith Routines that get memory usage information from the OS 1205d382aafbSBarry Smith */ 1206014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1209b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1210d382aafbSBarry Smith 1211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1212d382aafbSBarry Smith 1213d382aafbSBarry Smith /* 1214d382aafbSBarry Smith Initialization of PETSc 1215d382aafbSBarry Smith */ 1216014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1217014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1218014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1223014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1224014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1225014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1226d382aafbSBarry Smith 1227014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1228607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1229d382aafbSBarry Smith 1230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1233014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1234d382aafbSBarry Smith 1235a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1236a50e088cSMatthew G. Knepley 1237d382aafbSBarry Smith /* 1238d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 12392981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1240d382aafbSBarry Smith */ 1241638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void); 1242638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void); 1243638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1244d382aafbSBarry Smith 1245d382aafbSBarry Smith /* 1246d382aafbSBarry Smith Functions that can act on any PETSc object. 1247d382aafbSBarry Smith */ 1248014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1249014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1250014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1251014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1252014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1253014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1254014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1255014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1257014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1258014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1259014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1260014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1261014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1263014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1264014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1265bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 1266bdf89e91SBarry Smith #define PetscObjectComposeFunction(a, b, d) PetscObjectComposeFunction_Private(a, b, (PetscVoidFunction)(d)) 1267014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1268014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 12690eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 12700eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1271014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1272d382aafbSBarry Smith 1273665c2dedSJed Brown #include <petscviewertypes.h> 1274639ff905SBarry Smith #include <petscoptions.h> 1275639ff905SBarry Smith 1276608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1277608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1278608c71bfSMatthew G. Knepley 12790633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 12800633abcbSJed Brown 1281c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1282dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1283639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 12840005d66cSJed Brown #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFunction *)(fptr)) 12850005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1293685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1296013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 12974099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1299b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1302d382aafbSBarry Smith 1303e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 13047aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1305e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1306e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1307e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1308e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1309e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1310e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1311e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1312e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1313e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 131415681b3cSBarry Smith 1315ec7429eaSBarry Smith #else 13167aab2a10SBarry Smith #define PetscSAWsBlock() 0 1317e04113cfSBarry Smith #define PetscObjectSAWsViewOff(obj) 0 1318e04113cfSBarry Smith #define PetscObjectSAWsSetBlock(obj, flg) 0 1319e04113cfSBarry Smith #define PetscObjectSAWsBlock(obj) 0 1320e04113cfSBarry Smith #define PetscObjectSAWsGrantAccess(obj) 0 1321e04113cfSBarry Smith #define PetscObjectSAWsTakeAccess(obj) 0 1322e04113cfSBarry Smith #define PetscStackViewSAWs() 0 1323e04113cfSBarry Smith #define PetscStackSAWsViewOff() 0 1324e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1325e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 132615681b3cSBarry Smith 1327ec7429eaSBarry Smith #endif 1328b90c6cbeSBarry Smith 132982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 133082b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 133182b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1332258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1333258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1334258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1335258ec3d2SMatthew G. Knepley #endif 13367d5d4d99SBarry Smith 13375fe58b6fSBarry Smith #if defined(PETSC_USE_DEBUG) 1338a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 13395fe58b6fSBarry Smith #endif 13407eb1d149SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 1341a64a8e02SBarry Smith 1342140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1343140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1344140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1345140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1346140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1347140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1348d382aafbSBarry Smith 1349d382aafbSBarry Smith /* 1350503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1351d382aafbSBarry Smith link libraries that will be loaded as needed. 1352d382aafbSBarry Smith */ 1353a240a19fSJed Brown 1354a240a19fSJed Brown #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFunction)(fptr)) 1355a240a19fSJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], void (*)(void)); 1356140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 13570e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 13581c9cd337SJed Brown #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFunction *)(fptr)) 13591c9cd337SJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], void (**)(void)); 136044ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1361140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1362140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1363140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 13642e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 13652e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1366d382aafbSBarry Smith 1367014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1368014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1370014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1375d382aafbSBarry Smith 1376d382aafbSBarry Smith /* 1377d382aafbSBarry Smith Useful utility routines 1378d382aafbSBarry Smith */ 1379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1381d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 138658b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 138758b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1388d382aafbSBarry Smith 138964ac3b0dSPatrick Sanan /*MC 139087497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1391503cfb0cSBarry Smith 1392e28ce29aSPatrick Sanan Notes: 1393e28ce29aSPatrick Sanan This is useful in cases like 1394503cfb0cSBarry Smith $ int *a; 1395ace3abfcSBarry Smith $ PetscBool flag = PetscNot(a) 13961cc8b206SBarry Smith where !a would not return a PetscBool because we cannot provide a cast from int to PetscBool in C. 139764ac3b0dSPatrick Sanan 139864ac3b0dSPatrick Sanan Level: beginner 139964ac3b0dSPatrick Sanan 1400db781477SPatrick Sanan .seealso `:` `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 140164ac3b0dSPatrick Sanan M*/ 1402d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1403503cfb0cSBarry Smith 1404d382aafbSBarry Smith /*MC 1405d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1406d382aafbSBarry Smith 1407d382aafbSBarry Smith Synopsis: 1408aaa7dc30SBarry Smith #include <petscsys.h> 1409659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1410d382aafbSBarry Smith 1411659f7ba0SBarry Smith Collective on comm 1412eca87e8dSBarry Smith 1413d382aafbSBarry Smith Input Parameters: 1414659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1415d382aafbSBarry Smith . format - the usual printf() format string 1416659f7ba0SBarry Smith - args - arguments to be printed 1417d382aafbSBarry Smith 1418d382aafbSBarry Smith Level: developer 1419d382aafbSBarry Smith 1420d382aafbSBarry Smith Fortran Note: 1421d382aafbSBarry Smith This routine is not supported in Fortran. 1422d382aafbSBarry Smith 1423659f7ba0SBarry Smith Note: 1424659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1425659f7ba0SBarry Smith 1426659f7ba0SBarry Smith To use, write your own function, for example, 1427659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1428659f7ba0SBarry Smith ${ 1429659f7ba0SBarry Smith $ PetscFunctionReturn(0); 1430659f7ba0SBarry Smith $} 1431*d5b43468SJose E. Roman then do the assignment 1432659f7ba0SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 143387497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1434659f7ba0SBarry Smith 143587497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1436d382aafbSBarry Smith 1437db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()` 1438d382aafbSBarry Smith M*/ 14393ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1440d382aafbSBarry Smith 1441fcfd50ebSBarry Smith /* 1442fcfd50ebSBarry Smith Defines PETSc profiling. 1443fcfd50ebSBarry Smith */ 14442c8e378dSBarry Smith #include <petsclog.h> 1445fcfd50ebSBarry Smith 1446fcfd50ebSBarry Smith /* 1447fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1448fcfd50ebSBarry Smith */ 1449014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1450014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1451014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 14523ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14533ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14543ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14553ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 14561b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1457fcfd50ebSBarry Smith 14583ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14593ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14603ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1461d382aafbSBarry Smith 1462d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1463d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1464d781fa04SBarry Smith 1465d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1466014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1467016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 146874ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1469d382aafbSBarry Smith #endif 1470d382aafbSBarry Smith 14713ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14723ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14730ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1475014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1476014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm, const char[], const char[], FILE **); 1477014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1478d382aafbSBarry Smith 1479014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1480014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1481014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1483014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1485b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1486d382aafbSBarry Smith 1487d382aafbSBarry Smith /* 1488d382aafbSBarry Smith For use in debuggers 1489d382aafbSBarry Smith */ 1490014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1491014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1494014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1495d382aafbSBarry Smith 1496a663daf8SBarry Smith #include <stddef.h> 1497a3aaec0aSJed Brown #include <string.h> /* for memcpy, memset */ 1498d382aafbSBarry Smith #include <stdlib.h> 14996c7e564aSBarry Smith 15004a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1501d382aafbSBarry Smith #include <xmmintrin.h> 1502d382aafbSBarry Smith #endif 1503d382aafbSBarry Smith 1504d382aafbSBarry Smith /*@C 1505580bdb30SBarry Smith PetscMemmove - Copies n bytes, beginning at location b, to the space 1506580bdb30SBarry Smith beginning at location a. Copying between regions that overlap will 150787497f52SBarry Smith take place correctly. Use `PetscMemcpy()` if the locations do not overlap 1508580bdb30SBarry Smith 1509580bdb30SBarry Smith Not Collective 1510580bdb30SBarry Smith 1511580bdb30SBarry Smith Input Parameters: 1512580bdb30SBarry Smith + b - pointer to initial memory space 1513580bdb30SBarry Smith . a - pointer to copy space 1514580bdb30SBarry Smith - n - length (in bytes) of space to copy 1515580bdb30SBarry Smith 1516580bdb30SBarry Smith Level: intermediate 1517580bdb30SBarry Smith 151887497f52SBarry Smith Notes: 151987497f52SBarry Smith `PetscArraymove()` is preferred 1520580bdb30SBarry Smith 152187497f52SBarry Smith This routine is analogous to `memmove()`. 152287497f52SBarry Smith 152387497f52SBarry Smith Developers Note: 152487497f52SBarry Smith This is inlined for performance 1525580bdb30SBarry Smith 1526db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 1527db781477SPatrick Sanan `PetscArraymove()` 1528580bdb30SBarry Smith @*/ 1529d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemmove(void *a, const void *b, size_t n) 1530d71ae5a4SJacob Faibussowitsch { 1531580bdb30SBarry Smith PetscFunctionBegin; 15329a202e32SJacob Faibussowitsch if (n > 0) { 15332c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to null pointer"); 15342c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 15359a202e32SJacob Faibussowitsch } 1536580bdb30SBarry Smith #if !defined(PETSC_HAVE_MEMMOVE) 1537580bdb30SBarry Smith if (a < b) { 1538580bdb30SBarry Smith if (a <= b - n) memcpy(a, b, n); 1539580bdb30SBarry Smith else { 1540580bdb30SBarry Smith memcpy(a, b, (int)(b - a)); 1541580bdb30SBarry Smith PetscMemmove(b, b + (int)(b - a), n - (int)(b - a)); 1542580bdb30SBarry Smith } 1543580bdb30SBarry Smith } else { 1544580bdb30SBarry Smith if (b <= a - n) memcpy(a, b, n); 1545580bdb30SBarry Smith else { 1546580bdb30SBarry Smith memcpy(b + n, b + (n - (int)(a - b)), (int)(a - b)); 1547580bdb30SBarry Smith PetscMemmove(a, b, n - (int)(a - b)); 1548580bdb30SBarry Smith } 1549580bdb30SBarry Smith } 1550580bdb30SBarry Smith #else 1551580bdb30SBarry Smith memmove((char *)(a), (char *)(b), n); 1552580bdb30SBarry Smith #endif 1553580bdb30SBarry Smith PetscFunctionReturn(0); 1554580bdb30SBarry Smith } 1555580bdb30SBarry Smith 1556d382aafbSBarry Smith /*@C 1557d382aafbSBarry Smith PetscMemcpy - Copies n bytes, beginning at location b, to the space 1558d382aafbSBarry Smith beginning at location a. The two memory regions CANNOT overlap, use 155987497f52SBarry Smith `PetscMemmove()` in that case. 1560d382aafbSBarry Smith 1561d382aafbSBarry Smith Not Collective 1562d382aafbSBarry Smith 1563d382aafbSBarry Smith Input Parameters: 1564d382aafbSBarry Smith + b - pointer to initial memory space 1565d382aafbSBarry Smith - n - length (in bytes) of space to copy 1566d382aafbSBarry Smith 1567d382aafbSBarry Smith Output Parameter: 1568d382aafbSBarry Smith . a - pointer to copy space 1569d382aafbSBarry Smith 1570d382aafbSBarry Smith Level: intermediate 1571d382aafbSBarry Smith 1572d382aafbSBarry Smith Compile Option: 157387497f52SBarry Smith `PETSC_PREFER_DCOPY_FOR_MEMCPY` will cause the BLAS dcopy() routine to be used 1574d382aafbSBarry Smith for memory copies on double precision values. 157587497f52SBarry Smith `PETSC_PREFER_COPY_FOR_MEMCPY` will cause C code to be used 1576d382aafbSBarry Smith for memory copies on double precision values. 157787497f52SBarry Smith `PETSC_PREFER_FORTRAN_FORMEMCPY` will cause Fortran code to be used 1578d382aafbSBarry Smith for memory copies on double precision values. 1579d382aafbSBarry Smith 158087497f52SBarry Smith Notes: 158187497f52SBarry Smith Prefer `PetscArraycpy()` 158287497f52SBarry Smith 158387497f52SBarry Smith This routine is analogous to `memcpy()`. 158487497f52SBarry Smith 15851fd49c25SBarry Smith Not available from Fortran 15861fd49c25SBarry Smith 158787497f52SBarry Smith Developer Note: 158887497f52SBarry Smith This is inlined for fastest performance 1589f5f57ec0SBarry Smith 1590db781477SPatrick Sanan .seealso: `PetscMemzero()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1591d382aafbSBarry Smith 1592d382aafbSBarry Smith @*/ 1593d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemcpy(void *a, const void *b, size_t n) 1594d71ae5a4SJacob Faibussowitsch { 1595d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 1596c5e4d11fSDmitry Karpeev size_t al = (size_t)a, bl = (size_t)b; 1597c5e4d11fSDmitry Karpeev size_t nl = (size_t)n; 1598a7e36092SMatthew G Knepley PetscFunctionBegin; 15999a202e32SJacob Faibussowitsch if (n > 0) { 16002c71b3e2SJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy from a null pointer"); 16012c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to copy to a null pointer"); 16029a202e32SJacob Faibussowitsch } 1603a7e36092SMatthew G Knepley #else 1604d382aafbSBarry Smith PetscFunctionBegin; 1605a7e36092SMatthew G Knepley #endif 1606a47a537aSLisandro Dalcin if (a != b && n > 0) { 1607d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16082c71b3e2SJacob Faibussowitsch PetscCheck(!((al > bl && (al - bl) < nl) || (bl - al) < nl), PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Memory regions overlap: either use PetscMemmov()\n\ 1609d382aafbSBarry Smith or make sure your copy regions and lengths are correct. \n\ 16109371c9d4SSatish Balay Length (bytes) %zu first address %zu second address %zu", 16119371c9d4SSatish Balay nl, al, bl); 1612d382aafbSBarry Smith #endif 1613d382aafbSBarry Smith #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1614c5e4d11fSDmitry Karpeev if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1615d382aafbSBarry Smith size_t len = n / sizeof(PetscScalar); 1616d382aafbSBarry Smith #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1617c5df96a5SBarry Smith PetscBLASInt one = 1, blen; 16189566063dSJacob Faibussowitsch PetscCall(PetscBLASIntCast(len, &blen)); 1619792fecdfSBarry Smith PetscCallBLAS("BLAScopy", BLAScopy_(&blen, (PetscScalar *)b, &one, (PetscScalar *)a, &one)); 1620d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1621d382aafbSBarry Smith fortrancopy_(&len, (PetscScalar *)b, (PetscScalar *)a); 1622d382aafbSBarry Smith #else 1623d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)b, *y = (PetscScalar *)a; 16245f80ce2aSJacob Faibussowitsch for (size_t i = 0; i < len; i++) y[i] = x[i]; 1625d382aafbSBarry Smith #endif 1626d382aafbSBarry Smith } else { 1627d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1628d382aafbSBarry Smith } 1629d382aafbSBarry Smith #else 1630d382aafbSBarry Smith memcpy((char *)(a), (char *)(b), n); 1631d382aafbSBarry Smith #endif 1632d382aafbSBarry Smith } 1633d382aafbSBarry Smith PetscFunctionReturn(0); 1634d382aafbSBarry Smith } 1635d382aafbSBarry Smith 1636d382aafbSBarry Smith /*@C 1637d382aafbSBarry Smith PetscMemzero - Zeros the specified memory. 1638d382aafbSBarry Smith 1639d382aafbSBarry Smith Not Collective 1640d382aafbSBarry Smith 1641d382aafbSBarry Smith Input Parameters: 1642d382aafbSBarry Smith + a - pointer to beginning memory location 1643d382aafbSBarry Smith - n - length (in bytes) of memory to initialize 1644d382aafbSBarry Smith 1645d382aafbSBarry Smith Level: intermediate 1646d382aafbSBarry Smith 1647d382aafbSBarry Smith Compile Option: 164887497f52SBarry Smith `PETSC_PREFER_BZERO` - on certain machines (the IBM RS6000) the bzero() routine happens 1649d382aafbSBarry Smith to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1650d382aafbSBarry Smith 165187497f52SBarry Smith Notes: 16521fd49c25SBarry Smith Not available from Fortran 16531fd49c25SBarry Smith 165487497f52SBarry Smith Prefer `PetscArrayzero()` 165587497f52SBarry Smith 165687497f52SBarry Smith Developer Note: 165787497f52SBarry Smith This is inlined for fastest performance 1658503cfb0cSBarry Smith 1659db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1660d382aafbSBarry Smith @*/ 1661d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMemzero(void *a, size_t n) 1662d71ae5a4SJacob Faibussowitsch { 1663d382aafbSBarry Smith if (n > 0) { 1664d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16652c71b3e2SJacob Faibussowitsch PetscCheck(a, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Trying to zero at a null pointer with %zu bytes", n); 1666d382aafbSBarry Smith #endif 1667d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1668d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1669d382aafbSBarry Smith size_t i, len = n / sizeof(PetscScalar); 1670d382aafbSBarry Smith PetscScalar *x = (PetscScalar *)a; 1671d382aafbSBarry Smith for (i = 0; i < len; i++) x[i] = 0.0; 1672d382aafbSBarry Smith } else { 1673d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1674d382aafbSBarry Smith if (!(((long)a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1675d382aafbSBarry Smith PetscInt len = n / sizeof(PetscScalar); 1676d382aafbSBarry Smith fortranzero_(&len, (PetscScalar *)a); 1677d382aafbSBarry Smith } else { 1678d382aafbSBarry Smith #endif 1679d382aafbSBarry Smith #if defined(PETSC_PREFER_BZERO) 1680d382aafbSBarry Smith bzero((char *)a, n); 1681d382aafbSBarry Smith #else 1682d382aafbSBarry Smith memset((char *)a, 0, n); 1683d382aafbSBarry Smith #endif 1684d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1685d382aafbSBarry Smith } 1686d382aafbSBarry Smith #endif 1687d382aafbSBarry Smith } 1688d382aafbSBarry Smith return 0; 1689d382aafbSBarry Smith } 1690d382aafbSBarry Smith 1691d382aafbSBarry Smith /*MC 1692580bdb30SBarry Smith PetscArraycmp - Compares two arrays in memory. 1693580bdb30SBarry Smith 1694580bdb30SBarry Smith Synopsis: 1695580bdb30SBarry Smith #include <petscsys.h> 1696580bdb30SBarry Smith PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e) 1697580bdb30SBarry Smith 1698580bdb30SBarry Smith Not Collective 1699580bdb30SBarry Smith 1700580bdb30SBarry Smith Input Parameters: 1701580bdb30SBarry Smith + str1 - First array 1702580bdb30SBarry Smith . str2 - Second array 1703580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1704580bdb30SBarry Smith 1705580bdb30SBarry Smith Output Parameters: 170687497f52SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 1707580bdb30SBarry Smith 1708580bdb30SBarry Smith Level: intermediate 1709580bdb30SBarry Smith 171087497f52SBarry Smith Notes: 171187497f52SBarry Smith This routine is a preferred replacement to `PetscMemcmp()` 171287497f52SBarry Smith 1713580bdb30SBarry Smith The arrays must be of the same type 1714580bdb30SBarry Smith 1715db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, 1716db781477SPatrick Sanan `PetscArraymove()` 1717580bdb30SBarry Smith M*/ 17189e2232c7SLisandro Dalcin #define PetscArraycmp(str1, str2, cnt, e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1, str2, (size_t)(cnt) * sizeof(*(str1)), e)) 1719580bdb30SBarry Smith 17208f8f2f0dSBarry Smith /*MC 172187497f52SBarry Smith PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use `PetscArraycpy()` when the arrays 1722580bdb30SBarry Smith do not overlap 1723580bdb30SBarry Smith 1724580bdb30SBarry Smith Synopsis: 1725580bdb30SBarry Smith #include <petscsys.h> 1726580bdb30SBarry Smith PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt) 1727580bdb30SBarry Smith 1728580bdb30SBarry Smith Not Collective 1729580bdb30SBarry Smith 1730580bdb30SBarry Smith Input Parameters: 1731580bdb30SBarry Smith + str1 - First array 1732580bdb30SBarry Smith . str2 - Second array 1733580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1734580bdb30SBarry Smith 1735580bdb30SBarry Smith Level: intermediate 1736580bdb30SBarry Smith 173787497f52SBarry Smith Notes: 173887497f52SBarry Smith This routine is a preferred replacement to `PetscMemmove()` 173987497f52SBarry Smith 1740580bdb30SBarry Smith The arrays must be of the same type 1741580bdb30SBarry Smith 1742db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1743580bdb30SBarry Smith M*/ 17449e2232c7SLisandro Dalcin #define PetscArraymove(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1745580bdb30SBarry Smith 17468f8f2f0dSBarry Smith /*MC 1747580bdb30SBarry Smith PetscArraycpy - Copies from one array in memory to another 1748580bdb30SBarry Smith 1749580bdb30SBarry Smith Synopsis: 1750580bdb30SBarry Smith #include <petscsys.h> 1751580bdb30SBarry Smith PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt) 1752580bdb30SBarry Smith 1753580bdb30SBarry Smith Not Collective 1754580bdb30SBarry Smith 1755580bdb30SBarry Smith Input Parameters: 1756de25709eSStefano Zampini + str1 - First array (destination) 1757de25709eSStefano Zampini . str2 - Second array (source) 1758580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1759580bdb30SBarry Smith 1760580bdb30SBarry Smith Level: intermediate 1761580bdb30SBarry Smith 176287497f52SBarry Smith Notes: 176387497f52SBarry Smith This routine is a preferred replacement to `PetscMemcpy()` 176487497f52SBarry Smith 1765580bdb30SBarry Smith The arrays must be of the same type 1766580bdb30SBarry Smith 1767db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraymove()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1768580bdb30SBarry Smith M*/ 17699e2232c7SLisandro Dalcin #define PetscArraycpy(str1, str2, cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcpy(str1, str2, (size_t)(cnt) * sizeof(*(str1)))) 1770580bdb30SBarry Smith 17718f8f2f0dSBarry Smith /*MC 1772580bdb30SBarry Smith PetscArrayzero - Zeros an array in memory. 1773580bdb30SBarry Smith 1774580bdb30SBarry Smith Synopsis: 1775580bdb30SBarry Smith #include <petscsys.h> 1776580bdb30SBarry Smith PetscErrorCode PetscArrayzero(anytype *str1,size_t cnt) 1777580bdb30SBarry Smith 1778580bdb30SBarry Smith Not Collective 1779580bdb30SBarry Smith 1780580bdb30SBarry Smith Input Parameters: 1781580bdb30SBarry Smith + str1 - array 1782580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the array 1783580bdb30SBarry Smith 1784580bdb30SBarry Smith Level: intermediate 1785580bdb30SBarry Smith 1786580bdb30SBarry Smith Note: 178787497f52SBarry Smith This routine is a preferred replacement to `PetscMemzero()` 1788580bdb30SBarry Smith 1789db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, `PetscArraymove()` 1790580bdb30SBarry Smith M*/ 17919e2232c7SLisandro Dalcin #define PetscArrayzero(str1, cnt) PetscMemzero(str1, (size_t)(cnt) * sizeof(*(str1))) 1792580bdb30SBarry Smith 1793d382aafbSBarry Smith /*MC 1794d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1795d382aafbSBarry Smith 1796eca87e8dSBarry Smith Synopsis: 1797aaa7dc30SBarry Smith #include <petscsys.h> 1798eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1799eca87e8dSBarry Smith 1800d382aafbSBarry Smith Not Collective 1801d382aafbSBarry Smith 1802d382aafbSBarry Smith Input Parameters: 1803d382aafbSBarry Smith + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 1804d382aafbSBarry Smith . n - number of elements to fetch 1805d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 180650d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1807d382aafbSBarry Smith 1808d382aafbSBarry Smith Level: developer 1809d382aafbSBarry Smith 1810d382aafbSBarry Smith Notes: 1811d382aafbSBarry Smith The last two arguments (rw and t) must be compile-time constants. 1812d382aafbSBarry Smith 181350d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 181450d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 181587497f52SBarry 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). 181687497f52SBarry 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. 181787497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 181887497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1819d382aafbSBarry Smith 1820d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1821d382aafbSBarry Smith address). 1822d382aafbSBarry Smith 1823d382aafbSBarry Smith M*/ 18249371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 18259371c9d4SSatish Balay do { \ 1826d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1827d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1828d382aafbSBarry Smith } while (0) 1829d382aafbSBarry Smith 1830d382aafbSBarry Smith /* 1831d382aafbSBarry Smith Determine if some of the kernel computation routines use 1832d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1833d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1834d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1835e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1836d382aafbSBarry Smith */ 1837d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1838d382aafbSBarry Smith 1839d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1840d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1841d382aafbSBarry Smith #endif 1842d382aafbSBarry Smith 18435a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 18445a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1845d382aafbSBarry Smith #endif 1846d382aafbSBarry Smith 1847d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1848d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1849d382aafbSBarry Smith #endif 1850d382aafbSBarry Smith 1851d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1852d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1853d382aafbSBarry Smith #endif 1854d382aafbSBarry Smith 1855d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1856d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM 1857d382aafbSBarry Smith #endif 1858d382aafbSBarry Smith 1859d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1860d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1861d382aafbSBarry Smith #endif 1862d382aafbSBarry Smith 1863d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1864d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1865d382aafbSBarry Smith #endif 1866d382aafbSBarry Smith 1867d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1868d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1869d382aafbSBarry Smith #endif 1870d382aafbSBarry Smith 1871d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1872d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1873d382aafbSBarry Smith #endif 1874d382aafbSBarry Smith 1875d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1876d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1877d382aafbSBarry Smith #endif 1878d382aafbSBarry Smith 1879d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1880d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1881d382aafbSBarry Smith #endif 1882d382aafbSBarry Smith 1883d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1884d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1885d382aafbSBarry Smith #endif 1886d382aafbSBarry Smith 1887d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1888d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1889d382aafbSBarry Smith #endif 1890d382aafbSBarry Smith 1891d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1892d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1893d382aafbSBarry Smith #endif 1894d382aafbSBarry Smith 1895d382aafbSBarry Smith #endif 1896d382aafbSBarry Smith 1897d382aafbSBarry Smith /* 1898d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1899d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1900d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1901d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1902d382aafbSBarry Smith ugly extern "C" {} wrappers. 1903d382aafbSBarry Smith */ 1904d382aafbSBarry Smith #if defined(__cplusplus) 1905d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1906d382aafbSBarry Smith #define EXTERN_C_END } 1907d382aafbSBarry Smith #else 1908d382aafbSBarry Smith #define EXTERN_C_BEGIN 1909d382aafbSBarry Smith #define EXTERN_C_END 1910d382aafbSBarry Smith #endif 1911d382aafbSBarry Smith 1912d382aafbSBarry Smith /* --------------------------------------------------------------------*/ 1913d382aafbSBarry Smith 1914d382aafbSBarry Smith /*MC 1915d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1916d382aafbSBarry Smith communication 1917d382aafbSBarry Smith 1918d382aafbSBarry Smith Level: beginner 1919d382aafbSBarry Smith 1920d382aafbSBarry Smith Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1921d382aafbSBarry Smith 1922db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1923d382aafbSBarry Smith M*/ 1924d382aafbSBarry Smith 1925d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 192693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 192793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 192893d501b3SJacob 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); 192993d501b3SJacob 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); 193093d501b3SJacob 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); 193193d501b3SJacob 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); 1932d382aafbSBarry Smith #endif 1933d382aafbSBarry Smith 1934d382aafbSBarry Smith /* the following petsc_static_inline require petscerror.h */ 1935d382aafbSBarry Smith 1936d382aafbSBarry Smith /* Limit MPI to 32-bits */ 1937d382aafbSBarry Smith #define PETSC_MPI_INT_MAX 2147483647 1938d382aafbSBarry Smith #define PETSC_MPI_INT_MIN -2147483647 1939d382aafbSBarry Smith /* Limit BLAS to 32-bits */ 1940d382aafbSBarry Smith #define PETSC_BLAS_INT_MAX 2147483647 1941d382aafbSBarry Smith #define PETSC_BLAS_INT_MIN -2147483647 1942eee0c0a6SToby Isaac #define PETSC_CUBLAS_INT_MAX 2147483647 194347d993e7Ssuyashtn #define PETSC_HIPBLAS_INT_MAX 2147483647 1944d382aafbSBarry Smith 194561b0d812SBarry Smith /*@C 194687497f52SBarry Smith PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32 bits in size), generates an 194787497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1948c73702f5SBarry Smith 1949c73702f5SBarry Smith Not Collective 1950c73702f5SBarry Smith 1951c73702f5SBarry Smith Input Parameter: 195287497f52SBarry Smith . a - the `PetscInt64` value 1953c73702f5SBarry Smith 1954c73702f5SBarry Smith Output Parameter: 195587497f52SBarry Smith . b - the resulting `PetscInt` value 1956c73702f5SBarry Smith 1957c73702f5SBarry Smith Level: advanced 1958c73702f5SBarry Smith 195987497f52SBarry Smith Notes: 196087497f52SBarry 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 1961c73702f5SBarry Smith 1962c73702f5SBarry Smith Not available from Fortran 1963c73702f5SBarry Smith 1964db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1965c73702f5SBarry Smith @*/ 1966d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1967d71ae5a4SJacob Faibussowitsch { 1968c73702f5SBarry Smith PetscFunctionBegin; 1969c73702f5SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 19703ca90d2dSJacob Faibussowitsch if (a > PETSC_MAX_INT) { 19713ca90d2dSJacob Faibussowitsch *b = 0; 197298921bdaSJacob 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); 19733ca90d2dSJacob Faibussowitsch } 1974c73702f5SBarry Smith #endif 1975c73702f5SBarry Smith *b = (PetscInt)(a); 1976c73702f5SBarry Smith PetscFunctionReturn(0); 1977c73702f5SBarry Smith } 1978c73702f5SBarry Smith 1979c73702f5SBarry Smith /*@C 198087497f52SBarry Smith PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32 bits in size), generates an 198187497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1982981bb840SJunchao Zhang 1983981bb840SJunchao Zhang Not Collective 1984981bb840SJunchao Zhang 1985981bb840SJunchao Zhang Input Parameter: 198687497f52SBarry Smith . a - the `PetscCount` value 1987981bb840SJunchao Zhang 1988981bb840SJunchao Zhang Output Parameter: 198987497f52SBarry Smith . b - the resulting `PetscInt` value 1990981bb840SJunchao Zhang 1991981bb840SJunchao Zhang Level: advanced 1992981bb840SJunchao Zhang 1993981bb840SJunchao Zhang Notes: 1994981bb840SJunchao 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 1995981bb840SJunchao Zhang 1996981bb840SJunchao Zhang Not available from Fortran 1997981bb840SJunchao Zhang 1998db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1999981bb840SJunchao Zhang @*/ 2000d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 2001d71ae5a4SJacob Faibussowitsch { 2002981bb840SJunchao Zhang PetscFunctionBegin; 2003981bb840SJunchao Zhang if (sizeof(PetscCount) > sizeof(PetscInt) && a > PETSC_MAX_INT) { 2004981bb840SJunchao Zhang *b = 0; 2005981bb840SJunchao 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); 2006981bb840SJunchao Zhang } 2007981bb840SJunchao Zhang *b = (PetscInt)(a); 2008981bb840SJunchao Zhang PetscFunctionReturn(0); 2009981bb840SJunchao Zhang } 2010981bb840SJunchao Zhang 2011981bb840SJunchao Zhang /*@C 201287497f52SBarry Smith PetscBLASIntCast - casts a `PetscInt` (which may be 64 bits in size) to a `PetscBLASInt` (which may be 32 bits in size), generates an 201387497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 201461b0d812SBarry Smith 201561b0d812SBarry Smith Not Collective 201661b0d812SBarry Smith 201761b0d812SBarry Smith Input Parameter: 201887497f52SBarry Smith . a - the `PetscInt` value 201961b0d812SBarry Smith 202061b0d812SBarry Smith Output Parameter: 202187497f52SBarry Smith . b - the resulting `PetscBLASInt` value 202261b0d812SBarry Smith 202361b0d812SBarry Smith Level: advanced 202461b0d812SBarry Smith 20250bc7d38cSBarry Smith Notes: 20261fd49c25SBarry Smith Not available from Fortran 202787497f52SBarry Smith 2028f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 20291fd49c25SBarry Smith 2030db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 203161b0d812SBarry Smith @*/ 2032d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 2033d71ae5a4SJacob Faibussowitsch { 2034c5df96a5SBarry Smith PetscFunctionBegin; 203554c59aa7SJacob Faibussowitsch *b = 0; 203654c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 203754c59aa7SJacob 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); 203854c59aa7SJacob Faibussowitsch } 203954c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 2040c73702f5SBarry Smith *b = (PetscBLASInt)(a); 2041c5df96a5SBarry Smith PetscFunctionReturn(0); 2042c5df96a5SBarry Smith } 2043c5df96a5SBarry Smith 204461b0d812SBarry Smith /*@C 204587497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 2046eee0c0a6SToby Isaac 2047eee0c0a6SToby Isaac Not Collective 2048eee0c0a6SToby Isaac 2049eee0c0a6SToby Isaac Input Parameter: 205087497f52SBarry Smith . a - the `PetscInt` value 2051eee0c0a6SToby Isaac 2052eee0c0a6SToby Isaac Output Parameter: 205387497f52SBarry Smith . b - the resulting `PetscCuBLASInt` value 2054eee0c0a6SToby Isaac 2055eee0c0a6SToby Isaac Level: advanced 2056eee0c0a6SToby Isaac 2057eee0c0a6SToby Isaac Notes: 2058eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 2059eee0c0a6SToby Isaac 2060db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 2061eee0c0a6SToby Isaac @*/ 2062d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 2063d71ae5a4SJacob Faibussowitsch { 2064eee0c0a6SToby Isaac PetscFunctionBegin; 206554c59aa7SJacob Faibussowitsch *b = 0; 206654c59aa7SJacob 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); 206754c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to cuBLAS routine"); 2068eee0c0a6SToby Isaac *b = (PetscCuBLASInt)(a); 2069eee0c0a6SToby Isaac PetscFunctionReturn(0); 2070eee0c0a6SToby Isaac } 2071eee0c0a6SToby Isaac 2072eee0c0a6SToby Isaac /*@C 207347d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 207447d993e7Ssuyashtn 207547d993e7Ssuyashtn Not Collective 207647d993e7Ssuyashtn 207747d993e7Ssuyashtn Input Parameter: 207847d993e7Ssuyashtn . a - the `PetscInt` value 207947d993e7Ssuyashtn 208047d993e7Ssuyashtn Output Parameter: 208147d993e7Ssuyashtn . b - the resulting `PetscHipBLASInt` value 208247d993e7Ssuyashtn 208347d993e7Ssuyashtn Level: advanced 208447d993e7Ssuyashtn 208547d993e7Ssuyashtn Notes: 208647d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 208747d993e7Ssuyashtn 208847d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 208947d993e7Ssuyashtn @*/ 209047d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b) 209147d993e7Ssuyashtn { 209247d993e7Ssuyashtn PetscFunctionBegin; 209347d993e7Ssuyashtn *b = 0; 209447d993e7Ssuyashtn if (PetscDefined(USE_64BIT_INDICES)) PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32 bit integers.", a); 209547d993e7Ssuyashtn PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to hipBLAS routine"); 209647d993e7Ssuyashtn *b = (PetscHipBLASInt)(a); 209747d993e7Ssuyashtn PetscFunctionReturn(0); 209847d993e7Ssuyashtn } 209947d993e7Ssuyashtn 210047d993e7Ssuyashtn /*@C 210147d993e7Ssuyashtn PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an 210247d993e7Ssuyashtn error if the PetscMPIInt is not large enough to hold the number. 210361b0d812SBarry Smith 210461b0d812SBarry Smith Not Collective 210561b0d812SBarry Smith 210661b0d812SBarry Smith Input Parameter: 210787497f52SBarry Smith . a - the `PetscInt` value 210861b0d812SBarry Smith 210961b0d812SBarry Smith Output Parameter: 211087497f52SBarry Smith . b - the resulting `PetscMPIInt` value 211161b0d812SBarry Smith 211261b0d812SBarry Smith Level: advanced 211361b0d812SBarry Smith 21141fd49c25SBarry Smith Not available from Fortran 21151fd49c25SBarry Smith 2116db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 211761b0d812SBarry Smith @*/ 2118d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 2119d71ae5a4SJacob Faibussowitsch { 21204dc2109aSBarry Smith PetscFunctionBegin; 212154c59aa7SJacob Faibussowitsch *b = 0; 212254c59aa7SJacob 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); 2123c73702f5SBarry Smith *b = (PetscMPIInt)(a); 21244dc2109aSBarry Smith PetscFunctionReturn(0); 21254dc2109aSBarry Smith } 21264dc2109aSBarry Smith 2127bafee8b4SSatish Balay #define PetscInt64Mult(a, b) ((PetscInt64)(a)) * ((PetscInt64)(b)) 21282f18eb33SBarry Smith 21292f18eb33SBarry Smith /*@C 21302f18eb33SBarry Smith 213187497f52SBarry 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 21322f18eb33SBarry Smith 21332f18eb33SBarry Smith Not Collective 21342f18eb33SBarry Smith 2135d8d19677SJose E. Roman Input Parameters: 213687497f52SBarry Smith + a - the `PetscReal` value 21372f18eb33SBarry Smith - b - the second value 21382f18eb33SBarry Smith 2139390e1bf2SBarry Smith Returns: 214087497f52SBarry Smith the result as a `PetscInt` value 21412f18eb33SBarry Smith 214287497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 214387497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate to fit a `PetscInt` 214487497f52SBarry 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` 21452f18eb33SBarry Smith 2146e28ce29aSPatrick Sanan Developers Note: 214787497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21482f18eb33SBarry Smith 21492f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21502f18eb33SBarry Smith 21511fd49c25SBarry Smith Not available from Fortran 21521fd49c25SBarry Smith 21532f18eb33SBarry Smith Level: advanced 21542f18eb33SBarry Smith 2155db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21562f18eb33SBarry Smith @*/ 2157d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 2158d71ae5a4SJacob Faibussowitsch { 21595f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 21602f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21612f18eb33SBarry Smith return (PetscInt)r; 21622f18eb33SBarry Smith } 21632f18eb33SBarry Smith 21642f18eb33SBarry Smith /*@C 21652f18eb33SBarry Smith 216687497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 21672f18eb33SBarry Smith 21682f18eb33SBarry Smith Not Collective 21692f18eb33SBarry Smith 2170d8d19677SJose E. Roman Input Parameters: 21712f18eb33SBarry Smith + a - the PetscInt value 21722f18eb33SBarry Smith - b - the second value 21732f18eb33SBarry Smith 2174390e1bf2SBarry Smith Returns: 217587497f52SBarry Smith the result as a `PetscInt` value 21762f18eb33SBarry Smith 217787497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 217887497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 217987497f52SBarry 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` 21802f18eb33SBarry Smith 21811fd49c25SBarry Smith Not available from Fortran 21821fd49c25SBarry Smith 218387497f52SBarry Smith Developers Note: 218487497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 21852f18eb33SBarry Smith 21862f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21872f18eb33SBarry Smith 21882f18eb33SBarry Smith Level: advanced 21892f18eb33SBarry Smith 2190db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21912f18eb33SBarry Smith @*/ 2192d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 2193d71ae5a4SJacob Faibussowitsch { 21945f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 21952f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21962f18eb33SBarry Smith return (PetscInt)r; 21972f18eb33SBarry Smith } 21982f18eb33SBarry Smith 2199f91af8c7SBarry Smith /*@C 2200f91af8c7SBarry Smith 220187497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 2202f91af8c7SBarry Smith 2203f91af8c7SBarry Smith Not Collective 2204f91af8c7SBarry Smith 2205d8d19677SJose E. Roman Input Parameters: 220687497f52SBarry Smith + a - the `PetscInt` value 2207f91af8c7SBarry Smith - b - the second value 2208f91af8c7SBarry Smith 2209390e1bf2SBarry Smith Returns: 221087497f52SBarry Smith the result as a `PetscInt` value 2211f91af8c7SBarry Smith 221287497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 221387497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 221487497f52SBarry 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` 2215f91af8c7SBarry Smith 2216f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2217f91af8c7SBarry Smith 2218f5f57ec0SBarry Smith Not available from Fortran 2219f5f57ec0SBarry Smith 2220f91af8c7SBarry Smith Level: advanced 2221f91af8c7SBarry Smith 2222db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2223f91af8c7SBarry Smith @*/ 2224d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 2225d71ae5a4SJacob Faibussowitsch { 22265f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 2227f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 2228f91af8c7SBarry Smith return (PetscInt)r; 2229f91af8c7SBarry Smith } 2230f91af8c7SBarry Smith 22312f18eb33SBarry Smith /*@C 22322f18eb33SBarry Smith 223387497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 22342f18eb33SBarry Smith 22352f18eb33SBarry Smith Not Collective 22362f18eb33SBarry Smith 2237d8d19677SJose E. Roman Input Parameters: 223887497f52SBarry Smith + a - the `PetscInt` value 22392f18eb33SBarry Smith - b - the second value 22402f18eb33SBarry Smith 2241d8d19677SJose E. Roman Output Parameter: 224287497f52SBarry 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 22432f18eb33SBarry Smith 224487497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 224587497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 22462f18eb33SBarry Smith 2247f5f57ec0SBarry Smith Not available from Fortran 2248f5f57ec0SBarry Smith 224987497f52SBarry Smith Developers Note: 225087497f52SBarry Smith We currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks. 22512f18eb33SBarry Smith 22522f18eb33SBarry Smith Level: advanced 22532f18eb33SBarry Smith 2254db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 22552f18eb33SBarry Smith @*/ 2256d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 2257d71ae5a4SJacob Faibussowitsch { 2258bafee8b4SSatish Balay PetscInt64 r; 22592f18eb33SBarry Smith 22602f18eb33SBarry Smith PetscFunctionBegin; 2261bafee8b4SSatish Balay r = PetscInt64Mult(a, b); 22622f18eb33SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22632c71b3e2SJacob 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); 22642f18eb33SBarry Smith #endif 2265f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 2266f91af8c7SBarry Smith PetscFunctionReturn(0); 2267f91af8c7SBarry Smith } 2268f91af8c7SBarry Smith 2269f91af8c7SBarry Smith /*@C 2270f91af8c7SBarry Smith 227187497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 2272f91af8c7SBarry Smith 2273f91af8c7SBarry Smith Not Collective 2274f91af8c7SBarry Smith 2275d8d19677SJose E. Roman Input Parameters: 227687497f52SBarry Smith + a - the `PetscInt` value 2277f91af8c7SBarry Smith - b - the second value 2278f91af8c7SBarry Smith 2279d8d19677SJose E. Roman Output Parameter: 228087497f52SBarry 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 2281f91af8c7SBarry Smith 228287497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32 bit PetscInt and store in a `PetscInt64` 228387497f52SBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2284f91af8c7SBarry Smith 2285f5f57ec0SBarry Smith Not available from Fortran 2286f5f57ec0SBarry Smith 2287f91af8c7SBarry Smith Level: advanced 2288f91af8c7SBarry Smith 2289db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2290f91af8c7SBarry Smith @*/ 2291d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 2292d71ae5a4SJacob Faibussowitsch { 2293bafee8b4SSatish Balay PetscInt64 r; 2294f91af8c7SBarry Smith 2295f91af8c7SBarry Smith PetscFunctionBegin; 2296bafee8b4SSatish Balay r = ((PetscInt64)a) + ((PetscInt64)b); 2297f91af8c7SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22982c71b3e2SJacob 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); 2299f91af8c7SBarry Smith #endif 2300f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 23012f18eb33SBarry Smith PetscFunctionReturn(0); 23022f18eb33SBarry Smith } 2303c5df96a5SBarry Smith 2304d382aafbSBarry Smith /* 23052981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2306d382aafbSBarry Smith */ 2307d382aafbSBarry Smith #if defined(hz) 2308d382aafbSBarry Smith #undef hz 2309d382aafbSBarry Smith #endif 2310d382aafbSBarry Smith 231115a5570dSLisandro Dalcin #include <limits.h> 231215a5570dSLisandro Dalcin 231315a5570dSLisandro Dalcin /* The number of bits in a byte */ 231415a5570dSLisandro Dalcin 231515a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT 231615a5570dSLisandro Dalcin 2317d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2318d382aafbSBarry Smith #include <sys/types.h> 2319d382aafbSBarry Smith #endif 2320d382aafbSBarry Smith 2321d382aafbSBarry Smith /*MC 2322d382aafbSBarry Smith 232366d79e26SBarry 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++ 232466d79e26SBarry Smith and Fortran compilers when petscsys.h is included. 232566d79e26SBarry Smith 232666d79e26SBarry Smith The current PETSc version and the API for accessing it are defined in petscversion.h 232766d79e26SBarry Smith 232866d79e26SBarry 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) 232966d79e26SBarry Smith 233066d79e26SBarry 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 233166d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 233266d79e26SBarry Smith 233366d79e26SBarry 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 233466d79e26SBarry Smith 233566d79e26SBarry 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), 233666d79e26SBarry 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 233766d79e26SBarry Smith version number (x.y.z). 233866d79e26SBarry Smith 233987497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 234066d79e26SBarry Smith 234187497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 234266d79e26SBarry Smith 234387497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 234466d79e26SBarry Smith 234587497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 234666d79e26SBarry Smith 234787497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 234866d79e26SBarry Smith 2349cbc12506SBarry Smith Level: intermediate 235066d79e26SBarry Smith 235166d79e26SBarry Smith M*/ 235266d79e26SBarry Smith 2353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 2354014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 2355014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 2356014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 2357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 235927710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 23605f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 2361d382aafbSBarry Smith 23626a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 236362e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 23646a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 23656a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 2366014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 236762e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 236862e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 2369ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 237022ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 2371b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2373f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 237460e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 2375d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 2376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 2378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 2379981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 23806c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 2381981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 238217d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 238317d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 2384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 23855569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 2386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 238717df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 238939f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2391745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 239239f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 23966c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 23976c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2398e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2399ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2400ce605777SToby Isaac 24014d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2402676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2403676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2404676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 24054d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2406676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2407676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2408676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2409676f2a66SJacob Faibussowitsch 2410014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2411014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2412d382aafbSBarry Smith 241376bdecfbSBarry Smith /*J 2414d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2415d382aafbSBarry Smith 2416d382aafbSBarry Smith Level: beginner 2417d382aafbSBarry Smith 2418e28ce29aSPatrick Sanan Notes: 241987497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 242025ccb61fSToby Isaac with the option --download-sprng or --download-random123 2421d382aafbSBarry Smith 2422db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 242376bdecfbSBarry Smith J*/ 242419fd82e9SBarry Smith typedef const char *PetscRandomType; 2425d382aafbSBarry Smith #define PETSCRAND "rand" 2426d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2427d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2428c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 242925ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2430808ba619SStefano Zampini #define PETSCCURAND "curand" 2431d382aafbSBarry Smith 2432d382aafbSBarry Smith /* Logging support */ 2433014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2434d382aafbSBarry Smith 2435607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2436d382aafbSBarry Smith 2437d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2438140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2439d382aafbSBarry Smith 2440bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 244119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2442014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 244319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2444fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2445014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2446d382aafbSBarry Smith 2447014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2448014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2449014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2450808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2451808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2453014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2454014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2455014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2456014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2457014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2458d382aafbSBarry Smith 2459014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2465014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 246697540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 24678a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 246897540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2469d382aafbSBarry Smith 2470d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2471d71ae5a4SJacob Faibussowitsch { 24729371c9d4SSatish Balay long _petsc_v = 1; 24739371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 24749371c9d4SSatish Balay } 247530815ce0SLisandro Dalcin 24769860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 24779860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2478f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2479f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2480014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2481014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2483014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2487c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2488e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2489c891a504SStefano Zampini #endif 2490d382aafbSBarry Smith 2491014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2494d382aafbSBarry Smith 2495014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2496014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2497014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2498014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2499014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2500014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 25012a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2502d382aafbSBarry Smith 2503014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2504014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2505014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2506014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2507014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 250893d501b3SJacob 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); 250993d501b3SJacob 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); 251093d501b3SJacob 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); 2511d382aafbSBarry Smith 25126145cd65SJed Brown PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[]; 25136145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 25146145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 25156145cd65SJed Brown 2516014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2517d382aafbSBarry Smith 2518ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2519ce94432eSBarry Smith 252045487dadSJed Brown PETSC_EXTERN const char *const PetscSubcommTypes[]; 252145487dadSJed Brown 2522d382aafbSBarry Smith struct _n_PetscSubcomm { 2523d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2524d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2525306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 252645487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 252745487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2528708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 252945487dadSJed Brown PetscSubcommType type; 2530e5acf8a4SHong Zhang char *subcommprefix; 2531d382aafbSBarry Smith }; 2532d382aafbSBarry Smith 2533d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2534d71ae5a4SJacob Faibussowitsch { 25359371c9d4SSatish Balay return scomm->parent; 25369371c9d4SSatish Balay } 2537d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2538d71ae5a4SJacob Faibussowitsch { 25399371c9d4SSatish Balay return scomm->child; 25409371c9d4SSatish Balay } 2541d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2542d71ae5a4SJacob Faibussowitsch { 25439371c9d4SSatish Balay return scomm->dupparent; 25449371c9d4SSatish Balay } 2545014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2546014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2547014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2548014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 254965d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2550053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2551f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2552e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2553a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2554a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2555a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2556d382aafbSBarry Smith 25579962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 25589962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 25599962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 25609962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 25619962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 25629962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 25639962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 25649962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 25659962606eSBarry Smith 25665e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 25675f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 25685f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25695f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 25705f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 25715e71baefSBarry Smith 2572a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2573a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2574a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2575a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2576a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2577a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2578a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2579a32e93adSJunchao Zhang 258013e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 25810f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 258213e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2583137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2584137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2585137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 258613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 258713e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 25880f453b92SJed Brown 2589471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2590471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2591471ecdacSJed Brown * possible. */ 2592d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2593d71ae5a4SJacob Faibussowitsch { 25949371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 25959371c9d4SSatish Balay } 2596d382aafbSBarry Smith 25979de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 25989de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 25999de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 26009de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 26019de0f6ecSBarry Smith 2602ace2fbaeSBarry Smith #include <stdarg.h> 2603ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2604ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2605ace2fbaeSBarry Smith 2606268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2607fbfcfee5SBarry Smith 26081f817a21SBarry Smith /*@C 26091f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 26101f817a21SBarry Smith 261187497f52SBarry Smith Not Collective - only what is registered on rank 0 of `PETSC_COMM_WORLD` will be printed 26121f817a21SBarry Smith 26131f817a21SBarry Smith Input Parameters: 26141f817a21SBarry Smith + cite - the bibtex item, formated to displayed on multiple lines nicely 261587497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 26161f817a21SBarry Smith 2617850545d0SSatish Balay Level: intermediate 2618850545d0SSatish Balay 2619f5f57ec0SBarry Smith Not available from Fortran 2620f5f57ec0SBarry Smith 26211f817a21SBarry Smith Options Database: 2622063414e0SPatrick Sanan . -citations [filename] - print out the bibtex entries for the given computation 26231f817a21SBarry Smith @*/ 2624d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2625d71ae5a4SJacob Faibussowitsch { 2626dff31646SBarry Smith size_t len; 2627dff31646SBarry Smith char *vstring; 2628dff31646SBarry Smith 26291f817a21SBarry Smith PetscFunctionBegin; 26308d3683fcSBarry Smith if (set && *set) PetscFunctionReturn(0); 26319566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 26329566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 26339566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2634dff31646SBarry Smith if (set) *set = PETSC_TRUE; 26351f817a21SBarry Smith PetscFunctionReturn(0); 2636dff31646SBarry Smith } 2637dff31646SBarry Smith 2638d8174014SToby Isaac PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char[], char[], size_t c); 2639fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2640fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2641f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2642fe278a28SBarry Smith 2643f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2644f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 2645b967cddfSBarry Smith 26469f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 26479f4d3c52SBarry Smith 264804102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm, const char[], const char[], PetscBool *); 2649763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm, const char[], const char[], PetscBool *); 2650dff31646SBarry Smith 265168e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 26525dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2653d382aafbSBarry Smith 2654b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2655d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2656d71ae5a4SJacob Faibussowitsch { 2657df05ca09SBarry Smith unsigned int c, hash = 5381; 2658df05ca09SBarry Smith 2659503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2660df05ca09SBarry Smith return hash; 2661df05ca09SBarry Smith } 266277a5e07dSBarry Smith 266377a5e07dSBarry Smith /*MC 266487497f52SBarry Smith MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 266587497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 266687497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 266777a5e07dSBarry Smith 2668d083f849SBarry Smith Collective 266977a5e07dSBarry Smith 267077a5e07dSBarry Smith Synopsis: 267177a5e07dSBarry Smith #include <petscsys.h> 267277a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 267377a5e07dSBarry Smith 267477a5e07dSBarry Smith Input Parameters: 2675df05ca09SBarry Smith + a - pointer to the input data to be reduced 2676df05ca09SBarry Smith . c - the number of MPI data items in a and b 267787497f52SBarry Smith . d - the MPI datatype, for example `MPI_INT` 267887497f52SBarry Smith . e - the MPI operation, for example `MPI_SUM` 2679df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 268077a5e07dSBarry Smith 268177a5e07dSBarry Smith Output Parameter: 2682df05ca09SBarry Smith . b - the reduced values 268377a5e07dSBarry Smith 2684e28ce29aSPatrick Sanan Notes: 268587497f52SBarry Smith In optimized mode this directly calls `MPI_Allreduce()` 268677a5e07dSBarry Smith 2687df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2688df05ca09SBarry Smith 268987497f52SBarry 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 2690df05ca09SBarry Smith 269177a5e07dSBarry Smith Level: developer 269277a5e07dSBarry Smith 2693db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 269477a5e07dSBarry Smith M*/ 26959371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 26969371c9d4SSatish 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)));) 2697b2566f29SBarry Smith #else 26981c2dc1cbSBarry Smith #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), d, e, (fcomm)))) 2699b2566f29SBarry Smith #endif 2700b2566f29SBarry Smith 2701b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 27028198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 27038198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 27042f065d89SBarry Smith #endif 27058198064fSBarry Smith 2706cd88fca5SStefano Zampini /* this is a vile hack */ 2707cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 27089371c9d4SSatish 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) 2709cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2710cd88fca5SStefano Zampini #endif 2711961fb248SStefano Zampini #endif 2712cd88fca5SStefano Zampini 271312801b39SBarry Smith /* 271460fbe2beSVaclav Hapla List of external packages and queries on it 271560fbe2beSVaclav Hapla */ 271660fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 271760fbe2beSVaclav Hapla 2718a52b435bSMark Adams /* 2719a52b435bSMark Adams OpenMP support 2720a52b435bSMark Adams */ 2721a52b435bSMark Adams #if defined(_OPENMP) 2722a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__)) 2723a52b435bSMark Adams #else // no OpenMP so no threads 2724a52b435bSMark Adams #define PetscPragmaOMP(...) 2725a52b435bSMark Adams #endif 2726a52b435bSMark Adams 2727f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2728f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2729f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2730f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2731d382aafbSBarry Smith #endif 2732