1d382aafbSBarry Smith /* 2d382aafbSBarry Smith This is the main PETSc include file (for C and C++). It is included by all 3d382aafbSBarry Smith other PETSc include files, so it almost never has to be specifically included. 4d382aafbSBarry Smith */ 526bd1501SBarry Smith #if !defined(PETSCSYS_H) 626bd1501SBarry Smith #define PETSCSYS_H 73ca90d2dSJacob Faibussowitsch 8d382aafbSBarry Smith /* ========================================================================== */ 9d382aafbSBarry Smith /* 10d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 111c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 121c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules. 131c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 141cc8b206SBarry Smith directory as the other PETSc include files. 15d382aafbSBarry Smith */ 162c8e378dSBarry Smith #include <petscconf.h> 171c77a0c5SBarry Smith #include <petscconf_poison.h> 182c8e378dSBarry Smith #include <petscfix.h> 19bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2033bb201bSJacob Faibussowitsch 21ac09b921SBarry Smith /* SUBMANSEC = Sys */ 22ac09b921SBarry Smith 2373fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2473fca5a0SBarry Smith /* 2573fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2673fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2773fca5a0SBarry Smith */ 28216f1ae6SBarry Smith # if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 2973fca5a0SBarry Smith # define _POSIX_C_SOURCE 200112L 3073fca5a0SBarry Smith # endif 31216f1ae6SBarry Smith # if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3273fca5a0SBarry Smith # define _BSD_SOURCE 3373fca5a0SBarry Smith # endif 3407f00807SSatish Balay # if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3507f00807SSatish Balay # define _DEFAULT_SOURCE 3607f00807SSatish Balay # endif 37ea0fecefSShri Abhyankar # if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 38ea0fecefSShri Abhyankar # define _GNU_SOURCE 39ea0fecefSShri Abhyankar # endif 4073fca5a0SBarry Smith #endif 4173fca5a0SBarry Smith 42df4397b0SStefano Zampini #include <petscsystypes.h> 43df4397b0SStefano Zampini 44d382aafbSBarry Smith /* ========================================================================== */ 45d382aafbSBarry Smith 46d382aafbSBarry Smith /* 47d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 48d382aafbSBarry Smith 49d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 50d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 51d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 52d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 53d382aafbSBarry Smith mpicxx.h directly in their code 54d382aafbSBarry Smith */ 55fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 56d382aafbSBarry Smith # define MPICH_SKIP_MPICXX 1 57fa9e63e2SJed Brown #endif 58fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 59d382aafbSBarry Smith # define OMPI_SKIP_MPICXX 1 60fa9e63e2SJed Brown #endif 61e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 62e771154cSJed Brown # include <petsc/mpiuni/mpi.h> 63e771154cSJed Brown #else 642c8e378dSBarry Smith # include <mpi.h> 65e771154cSJed Brown #endif 6665013866SBarry Smith 67d382aafbSBarry Smith /* 68a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 69a7886beaSBarry Smith This usually happens because 70a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 71a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 72a7886beaSBarry Smith */ 73a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 74c9b973beSBarry Smith # if !defined(MPIUNI_H) 75a7886beaSBarry Smith # error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 76a7886beaSBarry Smith # endif 7741f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 7841f4af4cSSatish Balay # if !defined(I_MPI_NUMVERSION) 7941f4af4cSSatish Balay # error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 8041f4af4cSSatish Balay # elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 8141f4af4cSSatish Balay # error "PETSc was configured with one I_MPI mpi.h version but now appears to be compiling using a different I_MPI mpi.h version" 8241f4af4cSSatish Balay # endif 8341f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 8441f4af4cSSatish Balay # if !defined(MVAPICH2_NUMVERSION) 8541f4af4cSSatish Balay # error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 8641f4af4cSSatish Balay # elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 8741f4af4cSSatish Balay # error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 8841f4af4cSSatish Balay # endif 89a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 9041f4af4cSSatish Balay # if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 91a7886beaSBarry Smith # error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 921c284764SMin RK # elif (MPICH_NUMVERSION/100000000 != PETSC_HAVE_MPICH_NUMVERSION/100000000) || (MPICH_NUMVERSION/100000 < PETSC_HAVE_MPICH_NUMVERSION/100000) || (MPICH_NUMVERSION/100000 == PETSC_HAVE_MPICH_NUMVERSION/100000 && MPICH_NUMVERSION%100000/1000 < PETSC_HAVE_MPICH_NUMVERSION%100000/1000) 93a7886beaSBarry Smith # error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 94a7886beaSBarry Smith # endif 95a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 96a7886beaSBarry Smith # if !defined(OMPI_MAJOR_VERSION) 97a7886beaSBarry Smith # error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h" 981c284764SMin RK # elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION) 99c3ac57cfSSatish Balay # error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version" 100a7886beaSBarry Smith # endif 101c93fae50SJacob Faibussowitsch # define PETSC_MPI_COMM_FMT "p" 102c93fae50SJacob Faibussowitsch # define PETSC_MPI_WIN_FMT "p" 103d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 104d97fd468SStefano Zampini # if !defined(MSMPI_VER) 105d97fd468SStefano Zampini # error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 106d97fd468SStefano Zampini # elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 107d97fd468SStefano Zampini # error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 108d97fd468SStefano Zampini # endif 109d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 110d97fd468SStefano Zampini # error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant" 111a7886beaSBarry Smith #endif 112a7886beaSBarry Smith 113c93fae50SJacob Faibussowitsch /* Format specifier for printing MPI_Comm (most implementations use 'int' as type) */ 114c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_COMM_FMT) 115c93fae50SJacob Faibussowitsch # define PETSC_MPI_COMM_FMT "d" 116c93fae50SJacob Faibussowitsch #endif 117c93fae50SJacob Faibussowitsch 118c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_WIN_FMT) 119c93fae50SJacob Faibussowitsch # define PETSC_MPI_WIN_FMT "d" 120c93fae50SJacob Faibussowitsch #endif 121c93fae50SJacob Faibussowitsch 122a7886beaSBarry Smith /* 1232981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 124d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 125d382aafbSBarry Smith */ 126d382aafbSBarry Smith #include <stdio.h> 127d382aafbSBarry Smith 128d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 129d382aafbSBarry Smith #if !defined(MPIAPI) 130d382aafbSBarry Smith #define MPIAPI 131d382aafbSBarry Smith #endif 132d382aafbSBarry Smith 1331cc8b206SBarry Smith /* 1341cc8b206SBarry Smith Support for Clang (>=3.2) matching type tag arguments with void* buffer types. 1351cc8b206SBarry Smith This allows the compiler to detect cases where the MPI datatype argument passed to a MPI routine 1361cc8b206SBarry Smith does not match the actual type of the argument being passed in 1371cc8b206SBarry Smith */ 138c5e4d11fSDmitry Karpeev #if defined(__has_attribute) && defined(works_with_const_which_is_not_true) 139894dd566SJed Brown # if __has_attribute(argument_with_type_tag) && __has_attribute(pointer_with_type_tag) && __has_attribute(type_tag_for_datatype) 140894dd566SJed Brown # define PetscAttrMPIPointerWithType(bufno,typeno) __attribute__((pointer_with_type_tag(MPI,bufno,typeno))) 1418ad47952SJed Brown # define PetscAttrMPITypeTag(type) __attribute__((type_tag_for_datatype(MPI,type))) 1428ad47952SJed Brown # define PetscAttrMPITypeTagLayoutCompatible(type) __attribute__((type_tag_for_datatype(MPI,type,layout_compatible))) 143894dd566SJed Brown # endif 144894dd566SJed Brown #endif 145894dd566SJed Brown #if !defined(PetscAttrMPIPointerWithType) 146894dd566SJed Brown # define PetscAttrMPIPointerWithType(bufno,typeno) 1478ad47952SJed Brown # define PetscAttrMPITypeTag(type) 1488ad47952SJed Brown # define PetscAttrMPITypeTagLayoutCompatible(type) 149894dd566SJed Brown #endif 150b3506946SBarry Smith 1515a576424SJed Brown PETSC_EXTERN MPI_Datatype MPIU_ENUM PetscAttrMPITypeTag(PetscEnum); 152df4397b0SStefano Zampini PETSC_EXTERN MPI_Datatype MPIU_BOOL PetscAttrMPITypeTag(PetscBool); 153e28ce29aSPatrick Sanan 154e28ce29aSPatrick Sanan /*MC 155e28ce29aSPatrick Sanan MPIU_INT - MPI datatype corresponding to PetscInt 156e28ce29aSPatrick Sanan 157e28ce29aSPatrick Sanan Notes: 158e28ce29aSPatrick Sanan In MPI calls that require an MPI datatype that matches a PetscInt or array of PetscInt values, pass this value. 159e28ce29aSPatrick Sanan 160e28ce29aSPatrick Sanan Level: beginner 161e28ce29aSPatrick Sanan 162db781477SPatrick Sanan .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 163e28ce29aSPatrick Sanan M*/ 164e28ce29aSPatrick Sanan 1657cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 166b7b8f77aSBarry Smith 167d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 168bd84f1cfSSatish Balay # define MPIU_INT MPIU_INT64 169a05e1a72SSatish Balay # define PetscInt_FMT PetscInt64_FMT 170d382aafbSBarry Smith #else 171d382aafbSBarry Smith # define MPIU_INT MPI_INT 172a05e1a72SSatish Balay # define PetscInt_FMT "d" 173d382aafbSBarry Smith #endif 174d382aafbSBarry Smith 175503cfb0cSBarry Smith /* 176503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 177503cfb0cSBarry Smith */ 178e316c87fSJed Brown PETSC_EXTERN MPI_Datatype MPIU_SIZE_T; 179d382aafbSBarry Smith 180d382aafbSBarry Smith /* 181d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 182d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 183d382aafbSBarry Smith */ 184014dd563SJed Brown PETSC_EXTERN FILE* PETSC_STDOUT; 185d382aafbSBarry Smith 186d382aafbSBarry Smith /* 187d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 188d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 189d382aafbSBarry Smith */ 190014dd563SJed Brown PETSC_EXTERN FILE* PETSC_STDERR; 191d382aafbSBarry Smith 192c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */ 193c8b9133aSSatish Balay 1945c993f7fSStefano Zampini #if defined(__NEC__) 1955c993f7fSStefano Zampini # define PetscPragmaSIMD _Pragma("_NEC ivdep") 1965c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32) 197c8b9133aSSatish Balay # define PetscPragmaSIMD _Pragma("vector") 1981dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI) 199c8b9133aSSatish Balay # define PetscPragmaSIMD _Pragma("GCC ivdep") 200e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307 201e5518150SSatish Balay # if defined(_MSC_VER) 202160a5775SAli Reza Khaz'ali # define PetscPragmaSIMD __pragma(omp simd) 203e5518150SSatish Balay # else 204e5518150SSatish Balay # define PetscPragmaSIMD _Pragma("omp simd") 205e5518150SSatish Balay # endif 206c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR) 207c8b9133aSSatish Balay # define PetscPragmaSIMD _Pragma("_CRI ivdep") 208c8b9133aSSatish Balay #else 209c8b9133aSSatish Balay # define PetscPragmaSIMD 210c8b9133aSSatish Balay #endif 211c8b9133aSSatish Balay 212d382aafbSBarry Smith /* 213d382aafbSBarry Smith Declare extern C stuff after including external header files 214d382aafbSBarry Smith */ 215d382aafbSBarry Smith 2166a6fc655SJed Brown PETSC_EXTERN const char *const PetscBools[]; 21770b3c8c7SBarry Smith 2186edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 2198b49ba18SBarry Smith /* 220390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 2218b49ba18SBarry Smith */ 2228b49ba18SBarry Smith #include <petscmath.h> 2238b49ba18SBarry Smith 2246a6fc655SJed Brown PETSC_EXTERN const char *const PetscCopyModes[]; 225d382aafbSBarry Smith 226d382aafbSBarry Smith /*MC 2270298fd71SBarry Smith PETSC_IGNORE - same as NULL, means PETSc will ignore this argument 228d382aafbSBarry Smith 229d382aafbSBarry Smith Level: beginner 230d382aafbSBarry Smith 231e28ce29aSPatrick Sanan Note: 232e28ce29aSPatrick Sanan Accepted by many PETSc functions to not set a parameter and instead use 233d382aafbSBarry Smith some default 234d382aafbSBarry Smith 235e28ce29aSPatrick Sanan Fortran Notes: 236e28ce29aSPatrick Sanan This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 237d382aafbSBarry Smith PETSC_NULL_DOUBLE_PRECISION etc 238d382aafbSBarry Smith 239db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 240d382aafbSBarry Smith 241d382aafbSBarry Smith M*/ 2420298fd71SBarry Smith #define PETSC_IGNORE NULL 243d382aafbSBarry Smith 244c528d872SBarry Smith /* This is deprecated */ 245c528d872SBarry Smith #define PETSC_NULL NULL 246c528d872SBarry Smith 247d382aafbSBarry Smith /*MC 248557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 249557d4da8SBarry Smith where you wish PETSc to use the default. 250557d4da8SBarry Smith 251557d4da8SBarry Smith Level: beginner 252557d4da8SBarry Smith 253db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 254557d4da8SBarry Smith 255557d4da8SBarry Smith M*/ 256557d4da8SBarry Smith #define PETSC_DECIDE -1 257557d4da8SBarry Smith 258557d4da8SBarry Smith /*MC 259d382aafbSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter 260d382aafbSBarry Smith where you wish PETSc to compute the required value. 261d382aafbSBarry Smith 262d382aafbSBarry Smith Level: beginner 263d382aafbSBarry Smith 264e28ce29aSPatrick Sanan Developer Note: 265e28ce29aSPatrick Sanan I would like to use const PetscInt PETSC_DETERMINE = PETSC_DECIDE; but for 266557d4da8SBarry Smith some reason this is not allowed by the standard even though PETSC_DECIDE is a constant value. 267557d4da8SBarry Smith 268db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 269d382aafbSBarry Smith 270d382aafbSBarry Smith M*/ 271d382aafbSBarry Smith #define PETSC_DETERMINE PETSC_DECIDE 272d382aafbSBarry Smith 273d382aafbSBarry Smith /*MC 274557d4da8SBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter 275557d4da8SBarry Smith where you wish PETSc to use the default. 276557d4da8SBarry Smith 277557d4da8SBarry Smith Level: beginner 278557d4da8SBarry Smith 279e28ce29aSPatrick Sanan Fortran Notes: 280e28ce29aSPatrick Sanan You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_REAL. 281557d4da8SBarry Smith 282db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 283557d4da8SBarry Smith 284557d4da8SBarry Smith M*/ 285557d4da8SBarry Smith #define PETSC_DEFAULT -2 286557d4da8SBarry Smith 287557d4da8SBarry Smith /*MC 288d382aafbSBarry Smith PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents 289ea8fe74dSBarry Smith all the processes that PETSc knows about. 290d382aafbSBarry Smith 291d382aafbSBarry Smith Level: beginner 292d382aafbSBarry Smith 293e28ce29aSPatrick Sanan Notes: 294e28ce29aSPatrick Sanan By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 295d382aafbSBarry Smith run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller) 296d382aafbSBarry Smith communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling 297a990b902SBarry Smith PetscInitialize(), but after MPI_Init() has been called. 298a990b902SBarry Smith 299a990b902SBarry Smith The value of PETSC_COMM_WORLD should never be USED/accessed before PetscInitialize() 300a990b902SBarry Smith is called because it may not have a valid value yet. 301d382aafbSBarry Smith 302db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 303d382aafbSBarry Smith 304d382aafbSBarry Smith M*/ 305014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 306d382aafbSBarry Smith 307d382aafbSBarry Smith /*MC 308503cfb0cSBarry Smith PETSC_COMM_SELF - This is always MPI_COMM_SELF 309d382aafbSBarry Smith 310d382aafbSBarry Smith Level: beginner 311d382aafbSBarry Smith 312e28ce29aSPatrick Sanan Notes: 313e28ce29aSPatrick Sanan Do not USE/access or set this variable before PetscInitialize() has been called. 314a990b902SBarry Smith 315db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 316d382aafbSBarry Smith 317d382aafbSBarry Smith M*/ 318d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 319d382aafbSBarry Smith 3206de5d289SStefano Zampini /*MC 3216de5d289SStefano Zampini PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes 3226de5d289SStefano Zampini MPI with MPI_Init_thread. 3236de5d289SStefano Zampini 3246de5d289SStefano Zampini Level: beginner 3256de5d289SStefano Zampini 3266de5d289SStefano Zampini Notes: 3276de5d289SStefano Zampini By default PETSC_MPI_THREAD_REQUIRED equals MPI_THREAD_FUNNELED. 3286de5d289SStefano Zampini 329db781477SPatrick Sanan .seealso: `PetscInitialize()` 3306de5d289SStefano Zampini 3316de5d289SStefano Zampini M*/ 3326de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3336de5d289SStefano Zampini 334d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 3358ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 336014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 337014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3384cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 339d382aafbSBarry Smith 340014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*); 34357f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm,MPI_Comm*); 34457f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm,MPI_Comm*); 345d382aafbSBarry Smith 34659e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 34759e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 34859e55d94SJunchao Zhang #endif 34959e55d94SJunchao Zhang 35071438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 35171438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 35271438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 35371438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 35471438e86SJunchao Zhang #endif 35571438e86SJunchao Zhang 356540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 357540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 358540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool*); 359540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 360540e20f2SPierre Jolivet #endif 361540e20f2SPierre Jolivet 362d382aafbSBarry Smith /*MC 36395dccacaSBarry Smith PetscMalloc - Allocates memory, One should use PetscNew(), PetscMalloc1() or PetscCalloc1() usually instead of this 364d382aafbSBarry Smith 365eca87e8dSBarry Smith Synopsis: 366aaa7dc30SBarry Smith #include <petscsys.h> 367eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 368eca87e8dSBarry Smith 369eca87e8dSBarry Smith Not Collective 370eca87e8dSBarry Smith 371d382aafbSBarry Smith Input Parameter: 372d382aafbSBarry Smith . m - number of bytes to allocate 373d382aafbSBarry Smith 374d382aafbSBarry Smith Output Parameter: 375d382aafbSBarry Smith . result - memory allocated 376d382aafbSBarry Smith 377d382aafbSBarry Smith Level: beginner 378d382aafbSBarry Smith 37949d7da52SJed Brown Notes: 38049d7da52SJed Brown Memory is always allocated at least double aligned 381d382aafbSBarry Smith 38249d7da52SJed Brown It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 383d382aafbSBarry Smith 384db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 385d382aafbSBarry Smith 386d382aafbSBarry Smith M*/ 387071fcb05SBarry Smith #define PetscMalloc(a,b) ((*PetscTrMalloc)((a),PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b))) 388d382aafbSBarry Smith 389d382aafbSBarry Smith /*MC 3903221ece2SMatthew G. Knepley PetscRealloc - Rellocates memory 3913221ece2SMatthew G. Knepley 3923221ece2SMatthew G. Knepley Synopsis: 3933221ece2SMatthew G. Knepley #include <petscsys.h> 3943221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3953221ece2SMatthew G. Knepley 3963221ece2SMatthew G. Knepley Not Collective 3973221ece2SMatthew G. Knepley 3983221ece2SMatthew G. Knepley Input Parameters: 3993221ece2SMatthew G. Knepley + m - number of bytes to allocate 40092f119d6SBarry Smith - result - previous memory 4013221ece2SMatthew G. Knepley 4023221ece2SMatthew G. Knepley Output Parameter: 4033221ece2SMatthew G. Knepley . result - new memory allocated 4043221ece2SMatthew G. Knepley 4053221ece2SMatthew G. Knepley Level: developer 4063221ece2SMatthew G. Knepley 4073221ece2SMatthew G. Knepley Notes: 4083221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 4093221ece2SMatthew G. Knepley 410db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 4113221ece2SMatthew G. Knepley 4123221ece2SMatthew G. Knepley M*/ 4133221ece2SMatthew G. Knepley #define PetscRealloc(a,b) ((*PetscTrRealloc)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b))) 4143221ece2SMatthew G. Knepley 4153221ece2SMatthew G. Knepley /*MC 416503cfb0cSBarry Smith PetscAddrAlign - Rounds up an address to PETSC_MEMALIGN alignment 417d382aafbSBarry Smith 418d382aafbSBarry Smith Synopsis: 419aaa7dc30SBarry Smith #include <petscsys.h> 420d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 421d382aafbSBarry Smith 422eca87e8dSBarry Smith Not Collective 423eca87e8dSBarry Smith 424eca87e8dSBarry Smith Input Parameters: 425eca87e8dSBarry Smith . addr - address to align (any pointer type) 426eca87e8dSBarry Smith 427d382aafbSBarry Smith Level: developer 428d382aafbSBarry Smith 429db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 430d382aafbSBarry Smith 431d382aafbSBarry Smith M*/ 432d382aafbSBarry Smith #define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1)) 433d382aafbSBarry Smith 434d382aafbSBarry Smith /*MC 4358f51dc47SJunchao Zhang PetscCalloc - Allocates a cleared (zeroed) memory region aligned to PETSC_MEMALIGN 4368f51dc47SJunchao Zhang 4378f51dc47SJunchao Zhang Synopsis: 4388f51dc47SJunchao Zhang #include <petscsys.h> 4398f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4408f51dc47SJunchao Zhang 4418f51dc47SJunchao Zhang Not Collective 4428f51dc47SJunchao Zhang 4438f51dc47SJunchao Zhang Input Parameter: 4448f51dc47SJunchao Zhang . m - number of bytes to allocate 4458f51dc47SJunchao Zhang 4468f51dc47SJunchao Zhang Output Parameter: 4478f51dc47SJunchao Zhang . result - memory allocated 4488f51dc47SJunchao Zhang 4498f51dc47SJunchao Zhang Level: beginner 4508f51dc47SJunchao Zhang 4518f51dc47SJunchao Zhang Notes: 4528f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4538f51dc47SJunchao Zhang 4548f51dc47SJunchao Zhang It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree(). 4558f51dc47SJunchao Zhang 456db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4578f51dc47SJunchao Zhang 4588f51dc47SJunchao Zhang M*/ 45966122d6dSBarry Smith #define PetscCalloc(m,result) PetscMallocA(1,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m),(result)) 4608f51dc47SJunchao Zhang 4618f51dc47SJunchao Zhang /*MC 462785e854fSJed Brown PetscMalloc1 - Allocates an array of memory aligned to PETSC_MEMALIGN 463d382aafbSBarry Smith 464eca87e8dSBarry Smith Synopsis: 465aaa7dc30SBarry Smith #include <petscsys.h> 466785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 467785e854fSJed Brown 468785e854fSJed Brown Not Collective 469785e854fSJed Brown 470785e854fSJed Brown Input Parameter: 471390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 472785e854fSJed Brown 473785e854fSJed Brown Output Parameter: 4741fe1b817SJunchao Zhang . r1 - memory allocated 475785e854fSJed Brown 476e28ce29aSPatrick Sanan Note: 477e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 478390e1bf2SBarry Smith multiply the number of elements requested by the sizeof() the type. For example use 479390e1bf2SBarry Smith $ PetscInt *id; 480390e1bf2SBarry Smith $ PetscMalloc1(10,&id); 481390e1bf2SBarry Smith not 482390e1bf2SBarry Smith $ PetscInt *id; 483390e1bf2SBarry Smith $ PetscMalloc1(10*sizeof(PetscInt),&id); 484390e1bf2SBarry Smith 4851fe1b817SJunchao Zhang Does not zero the memory allocated, use PetscCalloc1() to obtain memory that has been zeroed. 486390e1bf2SBarry Smith 487390e1bf2SBarry Smith Level: beginner 488785e854fSJed Brown 489db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 490785e854fSJed Brown 491785e854fSJed Brown M*/ 49266122d6dSBarry Smith #define PetscMalloc1(m1,r1) PetscMallocA(1,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1)) 493785e854fSJed Brown 494785e854fSJed Brown /*MC 4951795a4d1SJed Brown PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to PETSC_MEMALIGN 4961795a4d1SJed Brown 4971795a4d1SJed Brown Synopsis: 498aaa7dc30SBarry Smith #include <petscsys.h> 4991795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 5001795a4d1SJed Brown 5011795a4d1SJed Brown Not Collective 5021795a4d1SJed Brown 5031795a4d1SJed Brown Input Parameter: 5041795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 5051795a4d1SJed Brown 5061795a4d1SJed Brown Output Parameter: 5071fe1b817SJunchao Zhang . r1 - memory allocated 5081795a4d1SJed Brown 509e28ce29aSPatrick Sanan Notes: 510e28ce29aSPatrick Sanan See PetsMalloc1() for more details on usage. 511390e1bf2SBarry Smith 512390e1bf2SBarry Smith Level: beginner 5131795a4d1SJed Brown 514db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 5151795a4d1SJed Brown 5161795a4d1SJed Brown M*/ 51766122d6dSBarry Smith #define PetscCalloc1(m1,r1) PetscMallocA(1,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1)) 5181795a4d1SJed Brown 5191795a4d1SJed Brown /*MC 520dcca6d9dSJed Brown PetscMalloc2 - Allocates 2 arrays of memory both aligned to PETSC_MEMALIGN 521d382aafbSBarry Smith 522eca87e8dSBarry Smith Synopsis: 523aaa7dc30SBarry Smith #include <petscsys.h> 524dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 525eca87e8dSBarry Smith 526eca87e8dSBarry Smith Not Collective 527eca87e8dSBarry Smith 528d8d19677SJose E. Roman Input Parameters: 529d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 530dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 531d382aafbSBarry Smith 532d8d19677SJose E. Roman Output Parameters: 533d382aafbSBarry Smith + r1 - memory allocated in first chunk 534d382aafbSBarry Smith - r2 - memory allocated in second chunk 535d382aafbSBarry Smith 536d382aafbSBarry Smith Level: developer 537d382aafbSBarry Smith 538db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 539d382aafbSBarry Smith 540d382aafbSBarry Smith M*/ 54166122d6dSBarry 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)) 542d382aafbSBarry Smith 543d382aafbSBarry Smith /*MC 5441795a4d1SJed Brown PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to PETSC_MEMALIGN 545d382aafbSBarry Smith 546eca87e8dSBarry Smith Synopsis: 547aaa7dc30SBarry Smith #include <petscsys.h> 5481795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 549eca87e8dSBarry Smith 550eca87e8dSBarry Smith Not Collective 551eca87e8dSBarry Smith 552d8d19677SJose E. Roman Input Parameters: 553d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5541795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5551795a4d1SJed Brown 556d8d19677SJose E. Roman Output Parameters: 5571795a4d1SJed Brown + r1 - memory allocated in first chunk 5581795a4d1SJed Brown - r2 - memory allocated in second chunk 5591795a4d1SJed Brown 5601795a4d1SJed Brown Level: developer 5611795a4d1SJed Brown 562db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5631795a4d1SJed Brown 5641795a4d1SJed Brown M*/ 56566122d6dSBarry 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)) 5661795a4d1SJed Brown 5671795a4d1SJed Brown /*MC 568dcca6d9dSJed Brown PetscMalloc3 - Allocates 3 arrays of memory, all aligned to PETSC_MEMALIGN 569d382aafbSBarry Smith 570d382aafbSBarry Smith Synopsis: 571aaa7dc30SBarry Smith #include <petscsys.h> 572dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 573d382aafbSBarry Smith 574d382aafbSBarry Smith Not Collective 575d382aafbSBarry Smith 576d8d19677SJose E. Roman Input Parameters: 577d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 578d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 579dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 580d382aafbSBarry Smith 581d8d19677SJose E. Roman Output Parameters: 582d382aafbSBarry Smith + r1 - memory allocated in first chunk 583d382aafbSBarry Smith . r2 - memory allocated in second chunk 584d382aafbSBarry Smith - r3 - memory allocated in third chunk 585d382aafbSBarry Smith 586d382aafbSBarry Smith Level: developer 587d382aafbSBarry Smith 588db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 589d382aafbSBarry Smith 590d382aafbSBarry Smith M*/ 59166122d6dSBarry 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)) 592d382aafbSBarry Smith 593d382aafbSBarry Smith /*MC 5941795a4d1SJed Brown PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN 595d382aafbSBarry Smith 596eca87e8dSBarry Smith Synopsis: 597aaa7dc30SBarry Smith #include <petscsys.h> 5981795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 599eca87e8dSBarry Smith 600eca87e8dSBarry Smith Not Collective 601eca87e8dSBarry Smith 602d8d19677SJose E. Roman Input Parameters: 603d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 604d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 6051795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 6061795a4d1SJed Brown 607d8d19677SJose E. Roman Output Parameters: 6081795a4d1SJed Brown + r1 - memory allocated in first chunk 6091795a4d1SJed Brown . r2 - memory allocated in second chunk 6101795a4d1SJed Brown - r3 - memory allocated in third chunk 6111795a4d1SJed Brown 6121795a4d1SJed Brown Level: developer 6131795a4d1SJed Brown 614db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 6151795a4d1SJed Brown 6161795a4d1SJed Brown M*/ 61766122d6dSBarry 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)) 6181795a4d1SJed Brown 6191795a4d1SJed Brown /*MC 620dcca6d9dSJed Brown PetscMalloc4 - Allocates 4 arrays of memory, all aligned to PETSC_MEMALIGN 621d382aafbSBarry Smith 622d382aafbSBarry Smith Synopsis: 623aaa7dc30SBarry Smith #include <petscsys.h> 624dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 625d382aafbSBarry Smith 626d382aafbSBarry Smith Not Collective 627d382aafbSBarry Smith 628d8d19677SJose E. Roman Input Parameters: 629d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 630d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 631d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 632dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 633d382aafbSBarry Smith 634d8d19677SJose E. Roman Output Parameters: 635d382aafbSBarry Smith + r1 - memory allocated in first chunk 636d382aafbSBarry Smith . r2 - memory allocated in second chunk 637d382aafbSBarry Smith . r3 - memory allocated in third chunk 638d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 639d382aafbSBarry Smith 640d382aafbSBarry Smith Level: developer 641d382aafbSBarry Smith 642db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 643d382aafbSBarry Smith 644d382aafbSBarry Smith M*/ 64566122d6dSBarry Smith #define PetscMalloc4(m1,r1,m2,r2,m3,r3,m4,r4) 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)) 646d382aafbSBarry Smith 647d382aafbSBarry Smith /*MC 6481795a4d1SJed Brown PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN 649d382aafbSBarry Smith 650eca87e8dSBarry Smith Synopsis: 651aaa7dc30SBarry Smith #include <petscsys.h> 6521795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 653eca87e8dSBarry Smith 654eca87e8dSBarry Smith Not Collective 655eca87e8dSBarry Smith 656e28ce29aSPatrick Sanan Input Parameters: 657d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 658d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 659d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6601795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6611795a4d1SJed Brown 662e28ce29aSPatrick Sanan Output Parameters: 6631795a4d1SJed Brown + r1 - memory allocated in first chunk 6641795a4d1SJed Brown . r2 - memory allocated in second chunk 6651795a4d1SJed Brown . r3 - memory allocated in third chunk 6661795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6671795a4d1SJed Brown 6681795a4d1SJed Brown Level: developer 6691795a4d1SJed Brown 670db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6711795a4d1SJed Brown 6721795a4d1SJed Brown M*/ 67366122d6dSBarry Smith #define PetscCalloc4(m1,r1,m2,r2,m3,r3,m4,r4) 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)) 6741795a4d1SJed Brown 6751795a4d1SJed Brown /*MC 676dcca6d9dSJed Brown PetscMalloc5 - Allocates 5 arrays of memory, all aligned to PETSC_MEMALIGN 677d382aafbSBarry Smith 678d382aafbSBarry Smith Synopsis: 679aaa7dc30SBarry Smith #include <petscsys.h> 680dcca6d9dSJed 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) 681d382aafbSBarry Smith 682d382aafbSBarry Smith Not Collective 683d382aafbSBarry Smith 684e28ce29aSPatrick Sanan Input Parameters: 685d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 686d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 687d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 688d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 689dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 690d382aafbSBarry Smith 691e28ce29aSPatrick Sanan Output Parameters: 692d382aafbSBarry Smith + r1 - memory allocated in first chunk 693d382aafbSBarry Smith . r2 - memory allocated in second chunk 694d382aafbSBarry Smith . r3 - memory allocated in third chunk 695d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 696d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 697d382aafbSBarry Smith 698d382aafbSBarry Smith Level: developer 699d382aafbSBarry Smith 700db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 701d382aafbSBarry Smith 702d382aafbSBarry Smith M*/ 70366122d6dSBarry Smith #define PetscMalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5) 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)) 704d382aafbSBarry Smith 705d382aafbSBarry Smith /*MC 7061795a4d1SJed Brown PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN 707d382aafbSBarry Smith 708eca87e8dSBarry Smith Synopsis: 709aaa7dc30SBarry Smith #include <petscsys.h> 7101795a4d1SJed 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) 711eca87e8dSBarry Smith 712eca87e8dSBarry Smith Not Collective 713eca87e8dSBarry Smith 714e28ce29aSPatrick Sanan Input Parameters: 715d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 716d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 717d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 718d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 7191795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 7201795a4d1SJed Brown 721e28ce29aSPatrick Sanan Output Parameters: 7221795a4d1SJed Brown + r1 - memory allocated in first chunk 7231795a4d1SJed Brown . r2 - memory allocated in second chunk 7241795a4d1SJed Brown . r3 - memory allocated in third chunk 7251795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7261795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7271795a4d1SJed Brown 7281795a4d1SJed Brown Level: developer 7291795a4d1SJed Brown 730db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7311795a4d1SJed Brown 7321795a4d1SJed Brown M*/ 73366122d6dSBarry Smith #define PetscCalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5) 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)) 734d382aafbSBarry Smith 735d382aafbSBarry Smith /*MC 736dcca6d9dSJed Brown PetscMalloc6 - Allocates 6 arrays of memory, all aligned to PETSC_MEMALIGN 737d382aafbSBarry Smith 738d382aafbSBarry Smith Synopsis: 739aaa7dc30SBarry Smith #include <petscsys.h> 740dcca6d9dSJed 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) 741d382aafbSBarry Smith 742d382aafbSBarry Smith Not Collective 743d382aafbSBarry Smith 744e28ce29aSPatrick Sanan Input Parameters: 745d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 746d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 747d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 748d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 749d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 750dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 751d382aafbSBarry Smith 752e28ce29aSPatrick Sanan Output Parameteasr: 753d382aafbSBarry Smith + r1 - memory allocated in first chunk 754d382aafbSBarry Smith . r2 - memory allocated in second chunk 755d382aafbSBarry Smith . r3 - memory allocated in third chunk 756d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 757d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 758d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 759d382aafbSBarry Smith 760d382aafbSBarry Smith Level: developer 761d382aafbSBarry Smith 762db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 763d382aafbSBarry Smith 764d382aafbSBarry Smith M*/ 76566122d6dSBarry Smith #define PetscMalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6) 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)) 766d382aafbSBarry Smith 767d382aafbSBarry Smith /*MC 7681795a4d1SJed Brown PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN 769d382aafbSBarry Smith 770eca87e8dSBarry Smith Synopsis: 771aaa7dc30SBarry Smith #include <petscsys.h> 7721795a4d1SJed 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) 773eca87e8dSBarry Smith 774eca87e8dSBarry Smith Not Collective 775eca87e8dSBarry Smith 776e28ce29aSPatrick Sanan Input Parameters: 777d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 778d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 779d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 780d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 781d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7821795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7831795a4d1SJed Brown 784e28ce29aSPatrick Sanan Output Parameters: 7851795a4d1SJed Brown + r1 - memory allocated in first chunk 7861795a4d1SJed Brown . r2 - memory allocated in second chunk 7871795a4d1SJed Brown . r3 - memory allocated in third chunk 7881795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7891795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7901795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7911795a4d1SJed Brown 7921795a4d1SJed Brown Level: developer 7931795a4d1SJed Brown 794db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7951795a4d1SJed Brown 7961795a4d1SJed Brown M*/ 79766122d6dSBarry Smith #define PetscCalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6) 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)) 7981795a4d1SJed Brown 7991795a4d1SJed Brown /*MC 800dcca6d9dSJed Brown PetscMalloc7 - Allocates 7 arrays of memory, all aligned to PETSC_MEMALIGN 801d382aafbSBarry Smith 802d382aafbSBarry Smith Synopsis: 803aaa7dc30SBarry Smith #include <petscsys.h> 804dcca6d9dSJed 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) 805d382aafbSBarry Smith 806d382aafbSBarry Smith Not Collective 807d382aafbSBarry Smith 808e28ce29aSPatrick Sanan Input Parameters: 809d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 810d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 811d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 812d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 813d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 814d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 815dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 816d382aafbSBarry Smith 817e28ce29aSPatrick Sanan Output Parameters: 818d382aafbSBarry Smith + r1 - memory allocated in first chunk 819d382aafbSBarry Smith . r2 - memory allocated in second chunk 820d382aafbSBarry Smith . r3 - memory allocated in third chunk 821d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 822d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 823d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 824eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 825d382aafbSBarry Smith 826d382aafbSBarry Smith Level: developer 827d382aafbSBarry Smith 828db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 829d382aafbSBarry Smith 830d382aafbSBarry Smith M*/ 83166122d6dSBarry Smith #define PetscMalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7) 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)) 832d382aafbSBarry Smith 833d382aafbSBarry Smith /*MC 8341795a4d1SJed Brown PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN 8351795a4d1SJed Brown 8361795a4d1SJed Brown Synopsis: 837aaa7dc30SBarry Smith #include <petscsys.h> 8381795a4d1SJed 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) 8391795a4d1SJed Brown 8401795a4d1SJed Brown Not Collective 8411795a4d1SJed Brown 842e28ce29aSPatrick Sanan Input Parameters: 8431795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8441795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8451795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8461795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8471795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8481795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8491795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8501795a4d1SJed Brown 851e28ce29aSPatrick Sanan Output Parameters: 8521795a4d1SJed Brown + r1 - memory allocated in first chunk 8531795a4d1SJed Brown . r2 - memory allocated in second chunk 8541795a4d1SJed Brown . r3 - memory allocated in third chunk 8551795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8561795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8571795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8581795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8591795a4d1SJed Brown 8601795a4d1SJed Brown Level: developer 8611795a4d1SJed Brown 862db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8631795a4d1SJed Brown 8641795a4d1SJed Brown M*/ 86566122d6dSBarry Smith #define PetscCalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7) 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)) 8661795a4d1SJed Brown 8671795a4d1SJed Brown /*MC 868503cfb0cSBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to PETSC_MEMALIGN 869d382aafbSBarry Smith 870eca87e8dSBarry Smith Synopsis: 871aaa7dc30SBarry Smith #include <petscsys.h> 872b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 873eca87e8dSBarry Smith 874eca87e8dSBarry Smith Not Collective 875eca87e8dSBarry Smith 876d382aafbSBarry Smith Output Parameter: 877b00a9115SJed Brown . result - memory allocated, sized to match pointer type 878d382aafbSBarry Smith 879d382aafbSBarry Smith Level: beginner 880d382aafbSBarry Smith 881db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscMalloc()`, `PetscNewLog()`, `PetscCalloc1()`, `PetscMalloc1()` 882d382aafbSBarry Smith 883d382aafbSBarry Smith M*/ 884b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1,(b)) 885ad0619ddSBarry Smith 886ad0619ddSBarry Smith /*MC 887b00a9115SJed Brown PetscNewLog - Allocates memory of a type matching pointer, zeros the memory! Aligned to PETSC_MEMALIGN. Associates the memory allocated 888ad0619ddSBarry Smith with the given object using PetscLogObjectMemory(). 889ad0619ddSBarry Smith 890ad0619ddSBarry Smith Synopsis: 891aaa7dc30SBarry Smith #include <petscsys.h> 892b00a9115SJed Brown PetscErrorCode PetscNewLog(PetscObject obj,type **result) 893ad0619ddSBarry Smith 894ad0619ddSBarry Smith Not Collective 895ad0619ddSBarry Smith 896ad0619ddSBarry Smith Input Parameter: 897b00a9115SJed Brown . obj - object memory is logged to 898ad0619ddSBarry Smith 899ad0619ddSBarry Smith Output Parameter: 900b00a9115SJed Brown . result - memory allocated, sized to match pointer type 901ad0619ddSBarry Smith 902ad0619ddSBarry Smith Level: developer 903ad0619ddSBarry Smith 904db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscMalloc()`, `PetscNew()`, `PetscLogObjectMemory()`, `PetscCalloc1()`, `PetscMalloc1()` 905ad0619ddSBarry Smith 906ad0619ddSBarry Smith M*/ 907d12f57a0SLisandro Dalcin #define PetscNewLog(o,b) (PetscNew((b)) || PetscLogObjectMemory((PetscObject)o,sizeof(**(b)))) 908d382aafbSBarry Smith 909d382aafbSBarry Smith /*MC 910d382aafbSBarry Smith PetscFree - Frees memory 911d382aafbSBarry Smith 912eca87e8dSBarry Smith Synopsis: 913aaa7dc30SBarry Smith #include <petscsys.h> 914eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 915eca87e8dSBarry Smith 916eca87e8dSBarry Smith Not Collective 917eca87e8dSBarry Smith 918d382aafbSBarry Smith Input Parameter: 9197f4976b7SJacob Faibussowitsch . memory - memory to free (the pointer is ALWAYS set to NULL upon success) 920d382aafbSBarry Smith 921d382aafbSBarry Smith Level: beginner 922d382aafbSBarry Smith 92349d7da52SJed Brown Notes: 924390e1bf2SBarry Smith Do not free memory obtained with PetscMalloc2(), PetscCalloc2() etc, they must be freed with PetscFree2() etc. 925390e1bf2SBarry Smith 92649d7da52SJed Brown It is safe to call PetscFree() on a NULL pointer. 927d382aafbSBarry Smith 928db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscNewLog()`, `PetscMalloc1()`, `PetscCalloc1()` 929d382aafbSBarry Smith 930d382aafbSBarry Smith M*/ 931ffc31a0eSLisandro Dalcin #define PetscFree(a) ((*PetscTrFree)((void*)(a),__LINE__,PETSC_FUNCTION_NAME,__FILE__) || ((a) = NULL,0)) 932d382aafbSBarry Smith 933d382aafbSBarry Smith /*MC 934d382aafbSBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 935d382aafbSBarry Smith 936eca87e8dSBarry Smith Synopsis: 937aaa7dc30SBarry Smith #include <petscsys.h> 938eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 939eca87e8dSBarry Smith 940eca87e8dSBarry Smith Not Collective 941eca87e8dSBarry Smith 942e28ce29aSPatrick Sanan Input Parameters: 943d382aafbSBarry Smith + memory1 - memory to free 944d382aafbSBarry Smith - memory2 - 2nd memory to free 945d382aafbSBarry Smith 946d382aafbSBarry Smith Level: developer 947d382aafbSBarry Smith 94895452b02SPatrick Sanan Notes: 94995452b02SPatrick Sanan Memory must have been obtained with PetscMalloc2() 950d382aafbSBarry Smith 951db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 952d382aafbSBarry Smith 953d382aafbSBarry Smith M*/ 954ba282f50SJed Brown #define PetscFree2(m1,m2) PetscFreeA(2,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2)) 955d382aafbSBarry Smith 956d382aafbSBarry Smith /*MC 957d382aafbSBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 958d382aafbSBarry Smith 959eca87e8dSBarry Smith Synopsis: 960aaa7dc30SBarry Smith #include <petscsys.h> 961eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 962eca87e8dSBarry Smith 963eca87e8dSBarry Smith Not Collective 964eca87e8dSBarry Smith 965e28ce29aSPatrick Sanan Input Parameters: 966d382aafbSBarry Smith + memory1 - memory to free 967d382aafbSBarry Smith . memory2 - 2nd memory to free 968d382aafbSBarry Smith - memory3 - 3rd memory to free 969d382aafbSBarry Smith 970d382aafbSBarry Smith Level: developer 971d382aafbSBarry Smith 97295452b02SPatrick Sanan Notes: 97395452b02SPatrick Sanan Memory must have been obtained with PetscMalloc3() 974d382aafbSBarry Smith 975db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 976d382aafbSBarry Smith 977d382aafbSBarry Smith M*/ 978ba282f50SJed Brown #define PetscFree3(m1,m2,m3) PetscFreeA(3,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3)) 979d382aafbSBarry Smith 980d382aafbSBarry Smith /*MC 981d382aafbSBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 982d382aafbSBarry Smith 983eca87e8dSBarry Smith Synopsis: 984aaa7dc30SBarry Smith #include <petscsys.h> 985eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 986eca87e8dSBarry Smith 987eca87e8dSBarry Smith Not Collective 988eca87e8dSBarry Smith 989e28ce29aSPatrick Sanan Input Parameters: 990d382aafbSBarry Smith + m1 - memory to free 991d382aafbSBarry Smith . m2 - 2nd memory to free 992d382aafbSBarry Smith . m3 - 3rd memory to free 993d382aafbSBarry Smith - m4 - 4th memory to free 994d382aafbSBarry Smith 995d382aafbSBarry Smith Level: developer 996d382aafbSBarry Smith 99795452b02SPatrick Sanan Notes: 99895452b02SPatrick Sanan Memory must have been obtained with PetscMalloc4() 999d382aafbSBarry Smith 1000db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 1001d382aafbSBarry Smith 1002d382aafbSBarry Smith M*/ 1003ba282f50SJed Brown #define PetscFree4(m1,m2,m3,m4) PetscFreeA(4,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4)) 1004d382aafbSBarry Smith 1005d382aafbSBarry Smith /*MC 1006d382aafbSBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 1007d382aafbSBarry Smith 1008eca87e8dSBarry Smith Synopsis: 1009aaa7dc30SBarry Smith #include <petscsys.h> 1010eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 1011eca87e8dSBarry Smith 1012eca87e8dSBarry Smith Not Collective 1013eca87e8dSBarry Smith 1014e28ce29aSPatrick Sanan Input Parameters: 1015d382aafbSBarry Smith + m1 - memory to free 1016d382aafbSBarry Smith . m2 - 2nd memory to free 1017d382aafbSBarry Smith . m3 - 3rd memory to free 1018d382aafbSBarry Smith . m4 - 4th memory to free 1019d382aafbSBarry Smith - m5 - 5th memory to free 1020d382aafbSBarry Smith 1021d382aafbSBarry Smith Level: developer 1022d382aafbSBarry Smith 102395452b02SPatrick Sanan Notes: 102495452b02SPatrick Sanan Memory must have been obtained with PetscMalloc5() 1025d382aafbSBarry Smith 1026db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 1027d382aafbSBarry Smith 1028d382aafbSBarry Smith M*/ 1029ba282f50SJed Brown #define PetscFree5(m1,m2,m3,m4,m5) PetscFreeA(5,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5)) 1030d382aafbSBarry Smith 1031d382aafbSBarry Smith /*MC 1032d382aafbSBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 1033d382aafbSBarry Smith 1034eca87e8dSBarry Smith Synopsis: 1035aaa7dc30SBarry Smith #include <petscsys.h> 1036eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1037eca87e8dSBarry Smith 1038eca87e8dSBarry Smith Not Collective 1039eca87e8dSBarry Smith 1040e28ce29aSPatrick Sanan Input Parameters: 1041d382aafbSBarry Smith + m1 - memory to free 1042d382aafbSBarry Smith . m2 - 2nd memory to free 1043d382aafbSBarry Smith . m3 - 3rd memory to free 1044d382aafbSBarry Smith . m4 - 4th memory to free 1045d382aafbSBarry Smith . m5 - 5th memory to free 1046d382aafbSBarry Smith - m6 - 6th memory to free 1047d382aafbSBarry Smith 1048d382aafbSBarry Smith Level: developer 1049d382aafbSBarry Smith 105095452b02SPatrick Sanan Notes: 105195452b02SPatrick Sanan Memory must have been obtained with PetscMalloc6() 1052d382aafbSBarry Smith 1053db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1054d382aafbSBarry Smith 1055d382aafbSBarry Smith M*/ 1056ba282f50SJed Brown #define PetscFree6(m1,m2,m3,m4,m5,m6) PetscFreeA(6,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5),&(m6)) 1057d382aafbSBarry Smith 1058d382aafbSBarry Smith /*MC 1059d382aafbSBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7() 1060d382aafbSBarry Smith 1061eca87e8dSBarry Smith Synopsis: 1062aaa7dc30SBarry Smith #include <petscsys.h> 1063eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1064eca87e8dSBarry Smith 1065eca87e8dSBarry Smith Not Collective 1066eca87e8dSBarry Smith 1067e28ce29aSPatrick Sanan Input Parameters: 1068d382aafbSBarry Smith + m1 - memory to free 1069d382aafbSBarry Smith . m2 - 2nd memory to free 1070d382aafbSBarry Smith . m3 - 3rd memory to free 1071d382aafbSBarry Smith . m4 - 4th memory to free 1072d382aafbSBarry Smith . m5 - 5th memory to free 1073d382aafbSBarry Smith . m6 - 6th memory to free 1074d382aafbSBarry Smith - m7 - 7th memory to free 1075d382aafbSBarry Smith 1076d382aafbSBarry Smith Level: developer 1077d382aafbSBarry Smith 107895452b02SPatrick Sanan Notes: 107995452b02SPatrick Sanan Memory must have been obtained with PetscMalloc7() 1080d382aafbSBarry Smith 1081db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1082db781477SPatrick Sanan `PetscMalloc7()` 1083d382aafbSBarry Smith 1084d382aafbSBarry Smith M*/ 1085ba282f50SJed Brown #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) PetscFreeA(7,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5),&(m6),&(m7)) 1086d382aafbSBarry Smith 1087ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int,PetscBool,int,const char *,const char *,size_t,void *,...); 1088ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int,int,const char *,const char *,void *,...); 1089071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,PetscBool,int,const char[],const char[],void**); 1090efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[]); 10913221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t,int,const char[],const char[],void**); 1092ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 109392f119d6SBarry 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 **)); 1094014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1095d382aafbSBarry Smith 1096d382aafbSBarry Smith /* 1097c1706be6SHong 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. 1098c1706be6SHong Zhang */ 1099c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1100c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 110131f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 110231f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 110331f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 110431f06eaaSHong Zhang #endif 110559af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 110659af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 110759af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 110859af0bd3SScott Kruger #endif 110959af0bd3SScott Kruger 1110a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 111136763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1112a5057860SBarry Smith 1113a5057860SBarry Smith /* 111466d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1115d382aafbSBarry Smith */ 1116014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 111792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1119014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1120e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1121e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int,PetscLogDouble*); 112292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool,PetscBool); 112392f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool*,PetscBool*,PetscBool*); 1124efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[]); 112592f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 112692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool*); 1127608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1128608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool*); 1129d382aafbSBarry Smith 11306a6fc655SJed Brown PETSC_EXTERN const char *const PetscDataTypes[]; 1131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 1132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*); 1133014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,size_t*); 11348e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char*,PetscDataType*,PetscBool*); 1135d382aafbSBarry Smith 1136d382aafbSBarry Smith /* 1137d382aafbSBarry Smith Basic memory and string operations. These are usually simple wrappers 1138d382aafbSBarry Smith around the basic Unix system calls, but a few of them have additional 1139d382aafbSBarry Smith functionality and/or error checking. 1140d382aafbSBarry Smith */ 1141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscBool *); 1142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrlen(const char[],size_t*); 1143d67fe73bSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[],char,int*,char ***); 1144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int,char **); 1145014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscBool *); 1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscBool *); 1147014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscBool *); 1148014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscBool *); 1149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcpy(char[],const char[]); 1150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcat(char[],const char[]); 1151a126751eSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrlcat(char[],const char[],size_t); 1152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t); 1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]); 1154014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]); 11552f234a98SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]); 1156014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]); 1157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]); 1158014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[],const char[],char *[]); 1159014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[],const char[],PetscBool*); 11602c9581d2SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[],const char[],PetscBool*); 1161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[],const char *const*,PetscInt*); 1162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]); 116347340559SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const*,char***); 11646fed8037SJed Brown PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char***); 11656991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt,const char *const*,char***); 11666991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt,char***); 1167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t); 1168d382aafbSBarry Smith 1169573b0fb4SBarry Smith PETSC_EXTERN void PetscStrcmpNoError(const char[],const char[],PetscBool *); 1170573b0fb4SBarry Smith 1171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken*); 1172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken,char *[]); 1173014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken*); 1174d382aafbSBarry Smith 1175e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscStrInList(const char[],const char[],char,PetscBool*); 117680b92c66SBarry Smith PETSC_EXTERN const char *PetscBasename(const char []); 1177a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt,const char *const*,const char*,PetscInt*,PetscBool*); 1178a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const*,const char*,PetscEnum*,PetscBool*); 1179a53986e1SJed Brown 1180d382aafbSBarry Smith /* 1181d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1182d382aafbSBarry Smith */ 1183367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1184570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1185de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1186014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1187014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1188d9822059SBarry Smith #else 1189de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1190d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1191d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1192d9822059SBarry Smith #endif 1193014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 1194d382aafbSBarry Smith 1195014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIULong_Send(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm); 1196014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIULong_Recv(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm); 1197eb3f98d2SBarry Smith 119895c0884eSLisandro Dalcin PETSC_EXTERN const char *const PetscFileModes[]; 1199d6a4318aSJed Brown 1200639ff905SBarry Smith /* 1201639ff905SBarry Smith Defines PETSc error handling. 1202639ff905SBarry Smith */ 1203639ff905SBarry Smith #include <petscerror.h> 1204d382aafbSBarry Smith 1205*660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1206*660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1207*660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1208*660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1209*660278c0SBarry Smith 12100700a824SBarry Smith #define PETSC_SMALLEST_CLASSID 1211211 1211014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1212014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1213014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[],PetscClassId *); 121481256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject,PetscObjectId*); 121581256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject,PetscObjectId,PetscBool*); 121681256985SMatthew G. Knepley 1217d382aafbSBarry Smith /* 1218d382aafbSBarry Smith Routines that get memory usage information from the OS 1219d382aafbSBarry Smith */ 1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1223b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1224d382aafbSBarry Smith 1225014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1226d382aafbSBarry Smith 1227d382aafbSBarry Smith /* 1228d382aafbSBarry Smith Initialization of PETSc 1229d382aafbSBarry Smith */ 1230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]); 1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int,char**,const char[],const char[]); 1232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1233014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1234014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1235014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1236014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int*,char ***); 1238014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1240d382aafbSBarry Smith 1241014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1242607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1243d382aafbSBarry Smith 1244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[],const char[]); 1245014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1247014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject,const char[]); 1248d382aafbSBarry Smith 1249a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscBool *); 1250a50e088cSMatthew G. Knepley 1251d382aafbSBarry Smith /* 1252d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 12532981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1254d382aafbSBarry Smith */ 1255638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void); 1256638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void); 1257638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1258d382aafbSBarry Smith 1259d382aafbSBarry Smith /* 1260d382aafbSBarry Smith Functions that can act on any PETSc object. 1261d382aafbSBarry Smith */ 1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject*); 1263014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *); 1264014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject,PetscClassId *); 1265014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject,const char *[]); 1266014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject,const char *[]); 1267014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]); 1268014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject,const char*[]); 1269014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject,PetscInt); 1270014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject,PetscInt*); 1271014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt); 1272014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1273014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*); 1274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt*); 1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject); 1277014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject,const char[]); 1278014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject*); 1279bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject,const char[],void (*)(void)); 1280bdf89e91SBarry Smith #define PetscObjectComposeFunction(a,b,d) PetscObjectComposeFunction_Private(a,b,(PetscVoidFunction)(d)) 1281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1282014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 12830eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 12840eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject,PetscObject); 1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt*); 1286d382aafbSBarry Smith 1287665c2dedSJed Brown #include <petscviewertypes.h> 1288639ff905SBarry Smith #include <petscoptions.h> 1289639ff905SBarry Smith 1290608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer,PetscBool,PetscLogDouble); 1291608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool*); 1292608c71bfSMatthew G. Knepley 12930633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm,PetscInt,PetscObject*,PetscInt*,PetscInt*); 12940633abcbSJed Brown 1295c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer,const char[]); 1296dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject,PetscViewer); 1297639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer); 12980005d66cSJed Brown #define PetscObjectQueryFunction(obj,name,fptr) PetscObjectQueryFunction_Private((obj),(name),(PetscVoidFunction*)(fptr)) 12990005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject,const char[],void (**)(void)); 1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1303014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]); 1304014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]); 1305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1306014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1307685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject,PetscObject,const char[]); 1308014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject,const char[],PetscBool *); 13104099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject,const char[],PetscBool *); 1311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject,PetscBool*,const char[],...); 1312b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject,PetscBool*,const char[],...); 1313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1315d382aafbSBarry Smith 1316e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 13177aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1318e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1319e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject,PetscBool); 1320e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1321e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1322e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1323e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1324e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1325e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1326e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 132715681b3cSBarry Smith 1328ec7429eaSBarry Smith #else 13297aab2a10SBarry Smith #define PetscSAWsBlock() 0 1330e04113cfSBarry Smith #define PetscObjectSAWsViewOff(obj) 0 1331e04113cfSBarry Smith #define PetscObjectSAWsSetBlock(obj,flg) 0 1332e04113cfSBarry Smith #define PetscObjectSAWsBlock(obj) 0 1333e04113cfSBarry Smith #define PetscObjectSAWsGrantAccess(obj) 0 1334e04113cfSBarry Smith #define PetscObjectSAWsTakeAccess(obj) 0 1335e04113cfSBarry Smith #define PetscStackViewSAWs() 0 1336e04113cfSBarry Smith #define PetscStackSAWsViewOff() 0 1337e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1338e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 133915681b3cSBarry Smith 1340ec7429eaSBarry Smith #endif 1341b90c6cbeSBarry Smith 134282b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[],PetscDLMode,PetscDLHandle *); 134382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 134482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle,const char[],void **); 1345258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1346258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1347258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1348258ec3d2SMatthew G. Knepley #endif 13497d5d4d99SBarry Smith 13505fe58b6fSBarry Smith #if defined(PETSC_USE_DEBUG) 1351a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void*,PetscStack**); 13525fe58b6fSBarry Smith #endif 13537eb1d149SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE*,PetscBool); 1354a64a8e02SBarry Smith 1355140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList*); 1356140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList,const char[],PetscObject*); 1357140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList,PetscObject,char**,PetscBool*); 1358140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *,const char[],PetscObject); 1359140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *,const char[]); 1360140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList,PetscObjectList *); 1361d382aafbSBarry Smith 1362d382aafbSBarry Smith /* 1363503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1364d382aafbSBarry Smith link libraries that will be loaded as needed. 1365d382aafbSBarry Smith */ 1366a240a19fSJed Brown 1367a240a19fSJed Brown #define PetscFunctionListAdd(list,name,fptr) PetscFunctionListAdd_Private((list),(name),(PetscVoidFunction)(fptr)) 1368a240a19fSJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList*,const char[],void (*)(void)); 1369140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList*); 13701c9cd337SJed Brown #define PetscFunctionListFind(list,name,fptr) PetscFunctionListFind_Private((list),(name),(PetscVoidFunction*)(fptr)) 13711c9cd337SJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList,const char[],void (**)(void)); 137244ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFunctionList,const char[],const char[]); 1373140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList,PetscFunctionList *); 1374140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList,PetscViewer); 1375140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList,const char ***,int*); 13762e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 13772e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1378d382aafbSBarry Smith 1379014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]); 1382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **); 1383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscBool *); 1385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *); 1386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1387d382aafbSBarry Smith 1388d382aafbSBarry Smith /* 1389d382aafbSBarry Smith Useful utility routines 1390d382aafbSBarry Smith */ 1391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1393d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm,PetscInt*,PetscInt*); 1394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1396014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1397014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE*); 139858b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm,const PetscInt[2],PetscInt[2]); 139958b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm,const PetscReal[2],PetscReal[2]); 1400d382aafbSBarry Smith 140164ac3b0dSPatrick Sanan /*MC 1402ace3abfcSBarry Smith PetscNot - negates a logical type value and returns result as a PetscBool 1403503cfb0cSBarry Smith 1404e28ce29aSPatrick Sanan Notes: 1405e28ce29aSPatrick Sanan This is useful in cases like 1406503cfb0cSBarry Smith $ int *a; 1407ace3abfcSBarry Smith $ PetscBool flag = PetscNot(a) 14081cc8b206SBarry Smith where !a would not return a PetscBool because we cannot provide a cast from int to PetscBool in C. 140964ac3b0dSPatrick Sanan 141064ac3b0dSPatrick Sanan Level: beginner 141164ac3b0dSPatrick Sanan 1412db781477SPatrick Sanan .seealso `:` `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 141364ac3b0dSPatrick Sanan M*/ 1414d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1415503cfb0cSBarry Smith 1416d382aafbSBarry Smith /*MC 1417d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1418d382aafbSBarry Smith 1419d382aafbSBarry Smith Synopsis: 1420aaa7dc30SBarry Smith #include <petscsys.h> 1421659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1422d382aafbSBarry Smith 1423659f7ba0SBarry Smith Collective on comm 1424eca87e8dSBarry Smith 1425d382aafbSBarry Smith Input Parameters: 1426659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1427d382aafbSBarry Smith . format - the usual printf() format string 1428659f7ba0SBarry Smith - args - arguments to be printed 1429d382aafbSBarry Smith 1430d382aafbSBarry Smith Level: developer 1431d382aafbSBarry Smith 1432d382aafbSBarry Smith Fortran Note: 1433d382aafbSBarry Smith This routine is not supported in Fortran. 1434d382aafbSBarry Smith 1435659f7ba0SBarry Smith Note: 1436659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1437659f7ba0SBarry Smith 1438659f7ba0SBarry Smith To use, write your own function, for example, 1439659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1440659f7ba0SBarry Smith ${ 1441659f7ba0SBarry Smith $ PetscFunctionReturn(0); 1442659f7ba0SBarry Smith $} 1443659f7ba0SBarry Smith then do the assigment 1444659f7ba0SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 1445659f7ba0SBarry Smith You can do the assignment before PetscInitialize(). 1446659f7ba0SBarry Smith 1447659f7ba0SBarry Smith The default routine used is called PetscHelpPrintfDefault(). 1448d382aafbSBarry Smith 1449db781477SPatrick Sanan .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()` 1450d382aafbSBarry Smith M*/ 14513ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3); 1452d382aafbSBarry Smith 1453fcfd50ebSBarry Smith /* 1454fcfd50ebSBarry Smith Defines PETSc profiling. 1455fcfd50ebSBarry Smith */ 14562c8e378dSBarry Smith #include <petsclog.h> 1457fcfd50ebSBarry Smith 1458fcfd50ebSBarry Smith /* 1459fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1460fcfd50ebSBarry Smith */ 1461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[],char[]); 1462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*); 14643ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_ATTRIBUTE_FORMAT(3,4); 14653ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3); 14663ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...) PETSC_ATTRIBUTE_FORMAT(3,4); 14673ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char*,size_t,const char [],size_t*,...) PETSC_ATTRIBUTE_FORMAT(3,5); 14681b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[],size_t,const char*,PetscInt,const PetscReal[]); 1469fcfd50ebSBarry Smith 14703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...) PETSC_ATTRIBUTE_FORMAT(1,2); 14713ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...) PETSC_ATTRIBUTE_FORMAT(1,2); 14723ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...) PETSC_ATTRIBUTE_FORMAT(2,3); 1473d382aafbSBarry Smith 1474d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char*,size_t*); 1475d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char*,char *); 1476d781fa04SBarry Smith 1477d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1478014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1479016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*); 148074ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1481d382aafbSBarry Smith #endif 1482d382aafbSBarry Smith 14833ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3); 14843ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_ATTRIBUTE_FORMAT(3,4); 14850ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm,FILE*); 1486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1487014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1488014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1489014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char*[]); 1490d382aafbSBarry Smith 1491014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void**); 1493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void*); 1494014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer*); 1495014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer*); 1496014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer,PetscErrorCode (*)(void*)); 1497b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void*); 1498d382aafbSBarry Smith 1499d382aafbSBarry Smith /* 1500d382aafbSBarry Smith For use in debuggers 1501d382aafbSBarry Smith */ 1502014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1503014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1504014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt,const PetscInt[],PetscViewer); 1505014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt,const PetscReal[],PetscViewer); 1506014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt,const PetscScalar[],PetscViewer); 1507d382aafbSBarry Smith 1508a663daf8SBarry Smith #include <stddef.h> 1509a3aaec0aSJed Brown #include <string.h> /* for memcpy, memset */ 1510d382aafbSBarry Smith #include <stdlib.h> 15116c7e564aSBarry Smith 15124a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1513d382aafbSBarry Smith #include <xmmintrin.h> 1514d382aafbSBarry Smith #endif 1515d382aafbSBarry Smith 1516d382aafbSBarry Smith /*@C 1517580bdb30SBarry Smith PetscMemmove - Copies n bytes, beginning at location b, to the space 1518580bdb30SBarry Smith beginning at location a. Copying between regions that overlap will 1519580bdb30SBarry Smith take place correctly. Use PetscMemcpy() if the locations do not overlap 1520580bdb30SBarry Smith 1521580bdb30SBarry Smith Not Collective 1522580bdb30SBarry Smith 1523580bdb30SBarry Smith Input Parameters: 1524580bdb30SBarry Smith + b - pointer to initial memory space 1525580bdb30SBarry Smith . a - pointer to copy space 1526580bdb30SBarry Smith - n - length (in bytes) of space to copy 1527580bdb30SBarry Smith 1528580bdb30SBarry Smith Level: intermediate 1529580bdb30SBarry Smith 1530580bdb30SBarry Smith Note: 1531857a15f1SBarry Smith PetscArraymove() is preferred 1532580bdb30SBarry Smith This routine is analogous to memmove(). 1533580bdb30SBarry Smith 1534580bdb30SBarry Smith Developers Note: This is inlined for performance 1535580bdb30SBarry Smith 1536db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 1537db781477SPatrick Sanan `PetscArraymove()` 1538580bdb30SBarry Smith @*/ 15399fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscMemmove(void *a,const void *b,size_t n) 1540580bdb30SBarry Smith { 1541580bdb30SBarry Smith PetscFunctionBegin; 15429a202e32SJacob Faibussowitsch if (n > 0) { 15432c71b3e2SJacob Faibussowitsch PetscCheck(a,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to null pointer"); 15442c71b3e2SJacob Faibussowitsch PetscCheck(b,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer"); 15459a202e32SJacob Faibussowitsch } 1546580bdb30SBarry Smith #if !defined(PETSC_HAVE_MEMMOVE) 1547580bdb30SBarry Smith if (a < b) { 1548580bdb30SBarry Smith if (a <= b - n) memcpy(a,b,n); 1549580bdb30SBarry Smith else { 1550580bdb30SBarry Smith memcpy(a,b,(int)(b - a)); 1551580bdb30SBarry Smith PetscMemmove(b,b + (int)(b - a),n - (int)(b - a)); 1552580bdb30SBarry Smith } 1553580bdb30SBarry Smith } else { 1554580bdb30SBarry Smith if (b <= a - n) memcpy(a,b,n); 1555580bdb30SBarry Smith else { 1556580bdb30SBarry Smith memcpy(b + n,b + (n - (int)(a - b)),(int)(a - b)); 1557580bdb30SBarry Smith PetscMemmove(a,b,n - (int)(a - b)); 1558580bdb30SBarry Smith } 1559580bdb30SBarry Smith } 1560580bdb30SBarry Smith #else 1561580bdb30SBarry Smith memmove((char*)(a),(char*)(b),n); 1562580bdb30SBarry Smith #endif 1563580bdb30SBarry Smith PetscFunctionReturn(0); 1564580bdb30SBarry Smith } 1565580bdb30SBarry Smith 1566d382aafbSBarry Smith /*@C 1567d382aafbSBarry Smith PetscMemcpy - Copies n bytes, beginning at location b, to the space 1568d382aafbSBarry Smith beginning at location a. The two memory regions CANNOT overlap, use 1569d382aafbSBarry Smith PetscMemmove() in that case. 1570d382aafbSBarry Smith 1571d382aafbSBarry Smith Not Collective 1572d382aafbSBarry Smith 1573d382aafbSBarry Smith Input Parameters: 1574d382aafbSBarry Smith + b - pointer to initial memory space 1575d382aafbSBarry Smith - n - length (in bytes) of space to copy 1576d382aafbSBarry Smith 1577d382aafbSBarry Smith Output Parameter: 1578d382aafbSBarry Smith . a - pointer to copy space 1579d382aafbSBarry Smith 1580d382aafbSBarry Smith Level: intermediate 1581d382aafbSBarry Smith 1582d382aafbSBarry Smith Compile Option: 1583d382aafbSBarry Smith PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used 1584d382aafbSBarry Smith for memory copies on double precision values. 1585d382aafbSBarry Smith PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used 1586d382aafbSBarry Smith for memory copies on double precision values. 1587d382aafbSBarry Smith PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used 1588d382aafbSBarry Smith for memory copies on double precision values. 1589d382aafbSBarry Smith 1590d382aafbSBarry Smith Note: 1591580bdb30SBarry Smith Prefer PetscArraycpy() 1592d382aafbSBarry Smith This routine is analogous to memcpy(). 15931fd49c25SBarry Smith Not available from Fortran 15941fd49c25SBarry Smith 1595f5f57ec0SBarry Smith Developer Note: this is inlined for fastest performance 1596f5f57ec0SBarry Smith 1597db781477SPatrick Sanan .seealso: `PetscMemzero()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1598d382aafbSBarry Smith 1599d382aafbSBarry Smith @*/ 16009fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscMemcpy(void *a,const void *b,size_t n) 1601d382aafbSBarry Smith { 1602d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 1603c5e4d11fSDmitry Karpeev size_t al = (size_t) a,bl = (size_t) b; 1604c5e4d11fSDmitry Karpeev size_t nl = (size_t) n; 1605a7e36092SMatthew G Knepley PetscFunctionBegin; 16069a202e32SJacob Faibussowitsch if (n > 0) { 16072c71b3e2SJacob Faibussowitsch PetscCheck(b,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer"); 16082c71b3e2SJacob Faibussowitsch PetscCheck(a,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer"); 16099a202e32SJacob Faibussowitsch } 1610a7e36092SMatthew G Knepley #else 1611d382aafbSBarry Smith PetscFunctionBegin; 1612a7e36092SMatthew G Knepley #endif 1613a47a537aSLisandro Dalcin if (a != b && n > 0) { 1614d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16152c71b3e2SJacob Faibussowitsch PetscCheck(!((al > bl && (al - bl) < nl) || (bl - al) < nl),PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\ 1616d382aafbSBarry Smith or make sure your copy regions and lengths are correct. \n\ 16176244d25cSSatish Balay Length (bytes) %zu first address %zu second address %zu",nl,al,bl); 1618d382aafbSBarry Smith #endif 1619d382aafbSBarry Smith #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1620c5e4d11fSDmitry Karpeev if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1621d382aafbSBarry Smith size_t len = n/sizeof(PetscScalar); 1622d382aafbSBarry Smith #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1623c5df96a5SBarry Smith PetscBLASInt one = 1,blen; 16249566063dSJacob Faibussowitsch PetscCall(PetscBLASIntCast(len,&blen)); 1625792fecdfSBarry Smith PetscCallBLAS("BLAScopy",BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one)); 1626d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1627d382aafbSBarry Smith fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a); 1628d382aafbSBarry Smith #else 1629d382aafbSBarry Smith PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a; 16305f80ce2aSJacob Faibussowitsch for (size_t i=0; i<len; i++) y[i] = x[i]; 1631d382aafbSBarry Smith #endif 1632d382aafbSBarry Smith } else { 1633d382aafbSBarry Smith memcpy((char*)(a),(char*)(b),n); 1634d382aafbSBarry Smith } 1635d382aafbSBarry Smith #else 1636d382aafbSBarry Smith memcpy((char*)(a),(char*)(b),n); 1637d382aafbSBarry Smith #endif 1638d382aafbSBarry Smith } 1639d382aafbSBarry Smith PetscFunctionReturn(0); 1640d382aafbSBarry Smith } 1641d382aafbSBarry Smith 1642d382aafbSBarry Smith /*@C 1643d382aafbSBarry Smith PetscMemzero - Zeros the specified memory. 1644d382aafbSBarry Smith 1645d382aafbSBarry Smith Not Collective 1646d382aafbSBarry Smith 1647d382aafbSBarry Smith Input Parameters: 1648d382aafbSBarry Smith + a - pointer to beginning memory location 1649d382aafbSBarry Smith - n - length (in bytes) of memory to initialize 1650d382aafbSBarry Smith 1651d382aafbSBarry Smith Level: intermediate 1652d382aafbSBarry Smith 1653d382aafbSBarry Smith Compile Option: 1654d382aafbSBarry Smith PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens 1655d382aafbSBarry Smith to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1656d382aafbSBarry Smith 16571fd49c25SBarry Smith Not available from Fortran 1658857a15f1SBarry Smith Prefer PetscArrayzero() 16591fd49c25SBarry Smith 1660503cfb0cSBarry Smith Developer Note: this is inlined for fastest performance 1661503cfb0cSBarry Smith 1662db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()` 1663d382aafbSBarry Smith @*/ 16649fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscMemzero(void *a,size_t n) 1665d382aafbSBarry Smith { 1666d382aafbSBarry Smith if (n > 0) { 1667d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG) 16682c71b3e2SJacob Faibussowitsch PetscCheck(a,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer with %zu bytes",n); 1669d382aafbSBarry Smith #endif 1670d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1671d382aafbSBarry Smith if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1672d382aafbSBarry Smith size_t i,len = n/sizeof(PetscScalar); 1673d382aafbSBarry Smith PetscScalar *x = (PetscScalar*)a; 1674d382aafbSBarry Smith for (i=0; i<len; i++) x[i] = 0.0; 1675d382aafbSBarry Smith } else { 1676d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1677d382aafbSBarry Smith if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1678d382aafbSBarry Smith PetscInt len = n/sizeof(PetscScalar); 1679d382aafbSBarry Smith fortranzero_(&len,(PetscScalar*)a); 1680d382aafbSBarry Smith } else { 1681d382aafbSBarry Smith #endif 1682d382aafbSBarry Smith #if defined(PETSC_PREFER_BZERO) 1683d382aafbSBarry Smith bzero((char *)a,n); 1684d382aafbSBarry Smith #else 1685d382aafbSBarry Smith memset((char*)a,0,n); 1686d382aafbSBarry Smith #endif 1687d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1688d382aafbSBarry Smith } 1689d382aafbSBarry Smith #endif 1690d382aafbSBarry Smith } 1691d382aafbSBarry Smith return 0; 1692d382aafbSBarry Smith } 1693d382aafbSBarry Smith 1694d382aafbSBarry Smith /*MC 1695580bdb30SBarry Smith PetscArraycmp - Compares two arrays in memory. 1696580bdb30SBarry Smith 1697580bdb30SBarry Smith Synopsis: 1698580bdb30SBarry Smith #include <petscsys.h> 1699580bdb30SBarry Smith PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e) 1700580bdb30SBarry Smith 1701580bdb30SBarry Smith Not Collective 1702580bdb30SBarry Smith 1703580bdb30SBarry Smith Input Parameters: 1704580bdb30SBarry Smith + str1 - First array 1705580bdb30SBarry Smith . str2 - Second array 1706580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1707580bdb30SBarry Smith 1708580bdb30SBarry Smith Output Parameters: 1709580bdb30SBarry Smith . e - PETSC_TRUE if equal else PETSC_FALSE. 1710580bdb30SBarry Smith 1711580bdb30SBarry Smith Level: intermediate 1712580bdb30SBarry Smith 1713580bdb30SBarry Smith Note: 1714857a15f1SBarry Smith This routine is a preferred replacement to PetscMemcmp() 1715580bdb30SBarry Smith The arrays must be of the same type 1716580bdb30SBarry Smith 1717db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscStrallocpy()`, 1718db781477SPatrick Sanan `PetscArraymove()` 1719580bdb30SBarry Smith M*/ 17209e2232c7SLisandro Dalcin #define PetscArraycmp(str1,str2,cnt,e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1,str2,(size_t)(cnt)*sizeof(*(str1)),e)) 1721580bdb30SBarry Smith 17228f8f2f0dSBarry Smith /*MC 1723580bdb30SBarry Smith PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use PetscArraycpy() when the arrays 1724580bdb30SBarry Smith do not overlap 1725580bdb30SBarry Smith 1726580bdb30SBarry Smith Synopsis: 1727580bdb30SBarry Smith #include <petscsys.h> 1728580bdb30SBarry Smith PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt) 1729580bdb30SBarry Smith 1730580bdb30SBarry Smith Not Collective 1731580bdb30SBarry Smith 1732580bdb30SBarry Smith Input Parameters: 1733580bdb30SBarry Smith + str1 - First array 1734580bdb30SBarry Smith . str2 - Second array 1735580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1736580bdb30SBarry Smith 1737580bdb30SBarry Smith Level: intermediate 1738580bdb30SBarry Smith 1739580bdb30SBarry Smith Note: 1740857a15f1SBarry Smith This routine is a preferred replacement to PetscMemmove() 1741580bdb30SBarry Smith The arrays must be of the same type 1742580bdb30SBarry Smith 1743db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycpy()`, `PetscMemmove()`, `PetscArraycmp()`, `PetscStrallocpy()` 1744580bdb30SBarry Smith M*/ 17459e2232c7SLisandro Dalcin #define PetscArraymove(str1,str2,cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1,str2,(size_t)(cnt)*sizeof(*(str1)))) 1746580bdb30SBarry Smith 17478f8f2f0dSBarry Smith /*MC 1748580bdb30SBarry Smith PetscArraycpy - Copies from one array in memory to another 1749580bdb30SBarry Smith 1750580bdb30SBarry Smith Synopsis: 1751580bdb30SBarry Smith #include <petscsys.h> 1752580bdb30SBarry Smith PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt) 1753580bdb30SBarry Smith 1754580bdb30SBarry Smith Not Collective 1755580bdb30SBarry Smith 1756580bdb30SBarry Smith Input Parameters: 1757de25709eSStefano Zampini + str1 - First array (destination) 1758de25709eSStefano Zampini . str2 - Second array (source) 1759580bdb30SBarry Smith - cnt - Count of the array, not in bytes, but number of entries in the arrays 1760580bdb30SBarry Smith 1761580bdb30SBarry Smith Level: intermediate 1762580bdb30SBarry Smith 1763580bdb30SBarry Smith Note: 1764857a15f1SBarry Smith This routine is a preferred replacement to PetscMemcpy() 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: 1787857a15f1SBarry 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. 181550d8bf02SJed Brown + PETSC_PREFETCH_HINT_NTA - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 181663cf1ef0SJed Brown . 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. 181763cf1ef0SJed Brown . PETSC_PREFETCH_HINT_T1 - Fetch to level 2 and higher (not L1). 181863cf1ef0SJed Brown - 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*/ 1824d382aafbSBarry Smith #define PetscPrefetchBlock(a,n,rw,t) do { \ 1825d382aafbSBarry Smith const char *_p = (const char*)(a),*_end = (const char*)((a)+(n)); \ 1826d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \ 1827d382aafbSBarry Smith } while (0) 1828d382aafbSBarry Smith 1829d382aafbSBarry Smith /* 1830d382aafbSBarry Smith Determine if some of the kernel computation routines use 1831d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1832d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1833d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1834e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1835d382aafbSBarry Smith */ 1836d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1837d382aafbSBarry Smith 1838d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1839d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1840d382aafbSBarry Smith #endif 1841d382aafbSBarry Smith 18425a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 18435a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1844d382aafbSBarry Smith #endif 1845d382aafbSBarry Smith 1846d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1847d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1848d382aafbSBarry Smith #endif 1849d382aafbSBarry Smith 1850d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1851d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1852d382aafbSBarry Smith #endif 1853d382aafbSBarry Smith 1854d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1855d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM 1856d382aafbSBarry Smith #endif 1857d382aafbSBarry Smith 1858d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1859d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1860d382aafbSBarry Smith #endif 1861d382aafbSBarry Smith 1862d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1863d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1864d382aafbSBarry Smith #endif 1865d382aafbSBarry Smith 1866d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1867d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1868d382aafbSBarry Smith #endif 1869d382aafbSBarry Smith 1870d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1871d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1872d382aafbSBarry Smith #endif 1873d382aafbSBarry Smith 1874d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1875d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1876d382aafbSBarry Smith #endif 1877d382aafbSBarry Smith 1878d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1879d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1880d382aafbSBarry Smith #endif 1881d382aafbSBarry Smith 1882d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1883d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1884d382aafbSBarry Smith #endif 1885d382aafbSBarry Smith 1886d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1887d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1888d382aafbSBarry Smith #endif 1889d382aafbSBarry Smith 1890d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1891d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1892d382aafbSBarry Smith #endif 1893d382aafbSBarry Smith 1894d382aafbSBarry Smith #endif 1895d382aafbSBarry Smith 1896d382aafbSBarry Smith /* 1897d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1898d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1899d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1900d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1901d382aafbSBarry Smith ugly extern "C" {} wrappers. 1902d382aafbSBarry Smith */ 1903d382aafbSBarry Smith #if defined(__cplusplus) 1904d382aafbSBarry Smith # define EXTERN_C_BEGIN extern "C" { 1905d382aafbSBarry Smith # define EXTERN_C_END } 1906d382aafbSBarry Smith #else 1907d382aafbSBarry Smith # define EXTERN_C_BEGIN 1908d382aafbSBarry Smith # define EXTERN_C_END 1909d382aafbSBarry Smith #endif 1910d382aafbSBarry Smith 1911d382aafbSBarry Smith /* --------------------------------------------------------------------*/ 1912d382aafbSBarry Smith 1913d382aafbSBarry Smith /*MC 1914d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1915d382aafbSBarry Smith communication 1916d382aafbSBarry Smith 1917d382aafbSBarry Smith Level: beginner 1918d382aafbSBarry Smith 1919d382aafbSBarry Smith Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1920d382aafbSBarry Smith 1921db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1922d382aafbSBarry Smith M*/ 1923d382aafbSBarry Smith 1924d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 1925014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1926014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1927c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_write_at(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1928c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_read_at(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1929c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_write_at_all(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1930c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_read_at_all(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1931d382aafbSBarry Smith #endif 1932d382aafbSBarry Smith 1933d382aafbSBarry Smith /* the following petsc_static_inline require petscerror.h */ 1934d382aafbSBarry Smith 1935d382aafbSBarry Smith /* Limit MPI to 32-bits */ 1936d382aafbSBarry Smith #define PETSC_MPI_INT_MAX 2147483647 1937d382aafbSBarry Smith #define PETSC_MPI_INT_MIN -2147483647 1938d382aafbSBarry Smith /* Limit BLAS to 32-bits */ 1939d382aafbSBarry Smith #define PETSC_BLAS_INT_MAX 2147483647 1940d382aafbSBarry Smith #define PETSC_BLAS_INT_MIN -2147483647 1941eee0c0a6SToby Isaac #define PETSC_CUBLAS_INT_MAX 2147483647 1942d382aafbSBarry Smith 194361b0d812SBarry Smith /*@C 1944c73702f5SBarry Smith PetscIntCast - casts a PetscInt64 (which is 64 bits in size) to a PetscInt (which may be 32 bits in size), generates an 1945c73702f5SBarry Smith error if the PetscInt is not large enough to hold the number. 1946c73702f5SBarry Smith 1947c73702f5SBarry Smith Not Collective 1948c73702f5SBarry Smith 1949c73702f5SBarry Smith Input Parameter: 1950c73702f5SBarry Smith . a - the PetscInt64 value 1951c73702f5SBarry Smith 1952c73702f5SBarry Smith Output Parameter: 1953c73702f5SBarry Smith . b - the resulting PetscInt value 1954c73702f5SBarry Smith 1955c73702f5SBarry Smith Level: advanced 1956c73702f5SBarry Smith 1957c73702f5SBarry Smith Notes: If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make PetscInt use 64 bit ints 1958c73702f5SBarry Smith 1959c73702f5SBarry Smith Not available from Fortran 1960c73702f5SBarry Smith 1961db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1962c73702f5SBarry Smith @*/ 19639fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a,PetscInt *b) 1964c73702f5SBarry Smith { 1965c73702f5SBarry Smith PetscFunctionBegin; 1966c73702f5SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 19673ca90d2dSJacob Faibussowitsch if (a > PETSC_MAX_INT) { 19683ca90d2dSJacob Faibussowitsch *b = 0; 196998921bdaSJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices",a); 19703ca90d2dSJacob Faibussowitsch } 1971c73702f5SBarry Smith #endif 1972c73702f5SBarry Smith *b = (PetscInt)(a); 1973c73702f5SBarry Smith PetscFunctionReturn(0); 1974c73702f5SBarry Smith } 1975c73702f5SBarry Smith 1976c73702f5SBarry Smith /*@C 1977981bb840SJunchao Zhang PetscCountCast - casts a PetscCount to a PetscInt (which may be 32 bits in size), generates an 1978981bb840SJunchao Zhang error if the PetscInt is not large enough to hold the number. 1979981bb840SJunchao Zhang 1980981bb840SJunchao Zhang Not Collective 1981981bb840SJunchao Zhang 1982981bb840SJunchao Zhang Input Parameter: 1983981bb840SJunchao Zhang . a - the PetscCount value 1984981bb840SJunchao Zhang 1985981bb840SJunchao Zhang Output Parameter: 1986981bb840SJunchao Zhang . b - the resulting PetscInt value 1987981bb840SJunchao Zhang 1988981bb840SJunchao Zhang Level: advanced 1989981bb840SJunchao Zhang 1990981bb840SJunchao Zhang Notes: 1991981bb840SJunchao Zhang If integers needed for the applications are too large to fit in 32 bit ints you can ./configure using --with-64-bit-indices to make PetscInt use 64 bit ints 1992981bb840SJunchao Zhang 1993981bb840SJunchao Zhang Not available from Fortran 1994981bb840SJunchao Zhang 1995db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1996981bb840SJunchao Zhang @*/ 1997981bb840SJunchao Zhang static inline PetscErrorCode PetscCountCast(PetscCount a,PetscInt *b) 1998981bb840SJunchao Zhang { 1999981bb840SJunchao Zhang PetscFunctionBegin; 2000981bb840SJunchao Zhang if (sizeof(PetscCount) > sizeof(PetscInt) && a > PETSC_MAX_INT) { 2001981bb840SJunchao Zhang *b = 0; 2002981bb840SJunchao Zhang SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices",a); 2003981bb840SJunchao Zhang } 2004981bb840SJunchao Zhang *b = (PetscInt)(a); 2005981bb840SJunchao Zhang PetscFunctionReturn(0); 2006981bb840SJunchao Zhang } 2007981bb840SJunchao Zhang 2008981bb840SJunchao Zhang /*@C 200961b0d812SBarry Smith PetscBLASIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscBLASInt (which may be 32 bits in size), generates an 201061b0d812SBarry Smith error if the PetscBLASInt is not large enough to hold the number. 201161b0d812SBarry Smith 201261b0d812SBarry Smith Not Collective 201361b0d812SBarry Smith 201461b0d812SBarry Smith Input Parameter: 201561b0d812SBarry Smith . a - the PetscInt value 201661b0d812SBarry Smith 201761b0d812SBarry Smith Output Parameter: 201861b0d812SBarry Smith . b - the resulting PetscBLASInt value 201961b0d812SBarry Smith 202061b0d812SBarry Smith Level: advanced 202161b0d812SBarry Smith 20220bc7d38cSBarry Smith Notes: 20231fd49c25SBarry Smith Not available from Fortran 2024f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 20251fd49c25SBarry Smith 2026db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 202761b0d812SBarry Smith @*/ 20289fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a,PetscBLASInt *b) 2029c5df96a5SBarry Smith { 2030c5df96a5SBarry Smith PetscFunctionBegin; 203154c59aa7SJacob Faibussowitsch *b = 0; 203254c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 203354c59aa7SJacob 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); 203454c59aa7SJacob Faibussowitsch } 203554c59aa7SJacob Faibussowitsch PetscCheck(a >= 0,PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Passing negative integer to BLAS/LAPACK routine"); 2036c73702f5SBarry Smith *b = (PetscBLASInt)(a); 2037c5df96a5SBarry Smith PetscFunctionReturn(0); 2038c5df96a5SBarry Smith } 2039c5df96a5SBarry Smith 204061b0d812SBarry Smith /*@C 2041eee0c0a6SToby Isaac PetscCuBLASIntCast - like PetscBLASIntCast(), but for PetscCuBLASInt. 2042eee0c0a6SToby Isaac 2043eee0c0a6SToby Isaac Not Collective 2044eee0c0a6SToby Isaac 2045eee0c0a6SToby Isaac Input Parameter: 2046eee0c0a6SToby Isaac . a - the PetscInt value 2047eee0c0a6SToby Isaac 2048eee0c0a6SToby Isaac Output Parameter: 2049eee0c0a6SToby Isaac . b - the resulting PetscCuBLASInt value 2050eee0c0a6SToby Isaac 2051eee0c0a6SToby Isaac Level: advanced 2052eee0c0a6SToby Isaac 2053eee0c0a6SToby Isaac Notes: 2054eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 2055eee0c0a6SToby Isaac 2056db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 2057eee0c0a6SToby Isaac @*/ 20589fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a,PetscCuBLASInt *b) 2059eee0c0a6SToby Isaac { 2060eee0c0a6SToby Isaac PetscFunctionBegin; 206154c59aa7SJacob Faibussowitsch *b = 0; 206254c59aa7SJacob 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); 206354c59aa7SJacob Faibussowitsch PetscCheck(a >= 0,PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Passing negative integer to cuBLAS routine"); 2064eee0c0a6SToby Isaac *b = (PetscCuBLASInt)(a); 2065eee0c0a6SToby Isaac PetscFunctionReturn(0); 2066eee0c0a6SToby Isaac } 2067eee0c0a6SToby Isaac 2068eee0c0a6SToby Isaac /*@C 206961b0d812SBarry Smith PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an 207061b0d812SBarry Smith error if the PetscMPIInt is not large enough to hold the number. 207161b0d812SBarry Smith 207261b0d812SBarry Smith Not Collective 207361b0d812SBarry Smith 207461b0d812SBarry Smith Input Parameter: 207561b0d812SBarry Smith . a - the PetscInt value 207661b0d812SBarry Smith 207761b0d812SBarry Smith Output Parameter: 207861b0d812SBarry Smith . b - the resulting PetscMPIInt value 207961b0d812SBarry Smith 208061b0d812SBarry Smith Level: advanced 208161b0d812SBarry Smith 20821fd49c25SBarry Smith Not available from Fortran 20831fd49c25SBarry Smith 2084db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 208561b0d812SBarry Smith @*/ 20869fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a,PetscMPIInt *b) 20874dc2109aSBarry Smith { 20884dc2109aSBarry Smith PetscFunctionBegin; 208954c59aa7SJacob Faibussowitsch *b = 0; 209054c59aa7SJacob 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); 2091c73702f5SBarry Smith *b = (PetscMPIInt)(a); 20924dc2109aSBarry Smith PetscFunctionReturn(0); 20934dc2109aSBarry Smith } 20944dc2109aSBarry Smith 2095bafee8b4SSatish Balay #define PetscInt64Mult(a,b) ((PetscInt64)(a))*((PetscInt64)(b)) 20962f18eb33SBarry Smith 20972f18eb33SBarry Smith /*@C 20982f18eb33SBarry Smith 20992f18eb33SBarry 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 21002f18eb33SBarry Smith 21012f18eb33SBarry Smith Not Collective 21022f18eb33SBarry Smith 2103d8d19677SJose E. Roman Input Parameters: 21042f18eb33SBarry Smith + a - the PetscReal value 21052f18eb33SBarry Smith - b - the second value 21062f18eb33SBarry Smith 2107390e1bf2SBarry Smith Returns: 2108390e1bf2SBarry Smith the result as a PetscInt value 21092f18eb33SBarry Smith 2110bafee8b4SSatish Balay Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64 21112f18eb33SBarry Smith Use PetscIntMultTruncate() to compute the product of two positive PetscInt and truncate to fit a PetscInt 21122f18eb33SBarry 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 21132f18eb33SBarry Smith 2114e28ce29aSPatrick Sanan Developers Note: 2115e28ce29aSPatrick Sanan We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks. 21162f18eb33SBarry Smith 21172f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21182f18eb33SBarry Smith 21191fd49c25SBarry Smith Not available from Fortran 21201fd49c25SBarry Smith 21212f18eb33SBarry Smith Level: advanced 21222f18eb33SBarry Smith 2123db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21242f18eb33SBarry Smith @*/ 21259fbee547SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a,PetscInt b) 21262f18eb33SBarry Smith { 21275f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a*(PetscReal)b); 21282f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21292f18eb33SBarry Smith return (PetscInt)r; 21302f18eb33SBarry Smith } 21312f18eb33SBarry Smith 21322f18eb33SBarry Smith /*@C 21332f18eb33SBarry Smith 21342f18eb33SBarry Smith PetscIntMultTruncate - Computes the product of two positive PetscInt and truncates the value to slightly less than the maximal possible value 21352f18eb33SBarry Smith 21362f18eb33SBarry Smith Not Collective 21372f18eb33SBarry Smith 2138d8d19677SJose E. Roman Input Parameters: 21392f18eb33SBarry Smith + a - the PetscInt value 21402f18eb33SBarry Smith - b - the second value 21412f18eb33SBarry Smith 2142390e1bf2SBarry Smith Returns: 2143390e1bf2SBarry Smith the result as a PetscInt value 21442f18eb33SBarry Smith 2145bafee8b4SSatish Balay Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64 21462f18eb33SBarry Smith Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt 21472f18eb33SBarry 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 21482f18eb33SBarry Smith 21491fd49c25SBarry Smith Not available from Fortran 21501fd49c25SBarry Smith 21512f18eb33SBarry Smith Developers Note: We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks. 21522f18eb33SBarry Smith 21532f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 21542f18eb33SBarry Smith 21552f18eb33SBarry Smith Level: advanced 21562f18eb33SBarry Smith 2157db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 21582f18eb33SBarry Smith @*/ 21599fbee547SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a,PetscInt b) 21602f18eb33SBarry Smith { 21615f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a,b); 21622f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 21632f18eb33SBarry Smith return (PetscInt)r; 21642f18eb33SBarry Smith } 21652f18eb33SBarry Smith 2166f91af8c7SBarry Smith /*@C 2167f91af8c7SBarry Smith 2168f91af8c7SBarry Smith PetscIntSumTruncate - Computes the sum of two positive PetscInt and truncates the value to slightly less than the maximal possible value 2169f91af8c7SBarry Smith 2170f91af8c7SBarry Smith Not Collective 2171f91af8c7SBarry Smith 2172d8d19677SJose E. Roman Input Parameters: 2173f91af8c7SBarry Smith + a - the PetscInt value 2174f91af8c7SBarry Smith - b - the second value 2175f91af8c7SBarry Smith 2176390e1bf2SBarry Smith Returns: 2177390e1bf2SBarry Smith the result as a PetscInt value 2178f91af8c7SBarry Smith 2179bafee8b4SSatish Balay Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64 2180f91af8c7SBarry Smith Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt 2181f91af8c7SBarry 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 2182f91af8c7SBarry Smith 2183f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2184f91af8c7SBarry Smith 2185f5f57ec0SBarry Smith Not available from Fortran 2186f5f57ec0SBarry Smith 2187f91af8c7SBarry Smith Level: advanced 2188f91af8c7SBarry Smith 2189db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2190f91af8c7SBarry Smith @*/ 21919fbee547SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a,PetscInt b) 2192f91af8c7SBarry Smith { 21935f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 2194f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 2195f91af8c7SBarry Smith return (PetscInt)r; 2196f91af8c7SBarry Smith } 2197f91af8c7SBarry Smith 21982f18eb33SBarry Smith /*@C 21992f18eb33SBarry Smith 22002f18eb33SBarry Smith PetscIntMultError - Computes the product of two positive PetscInt and generates an error with overflow. 22012f18eb33SBarry Smith 22022f18eb33SBarry Smith Not Collective 22032f18eb33SBarry Smith 2204d8d19677SJose E. Roman Input Parameters: 22052f18eb33SBarry Smith + a - the PetscInt value 22062f18eb33SBarry Smith - b - the second value 22072f18eb33SBarry Smith 2208d8d19677SJose E. Roman Output Parameter: 2209390e1bf2SBarry 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 22102f18eb33SBarry Smith 2211bafee8b4SSatish Balay Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64 22122f18eb33SBarry Smith Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt 22132f18eb33SBarry Smith 2214f5f57ec0SBarry Smith Not available from Fortran 2215f5f57ec0SBarry Smith 2216220afb94SBarry Smith Developers Note: We currently assume that PetscInt addition does not overflow, this is obviously wrong but requires many more checks. 22172f18eb33SBarry Smith 22182f18eb33SBarry Smith Level: advanced 22192f18eb33SBarry Smith 2220db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 22212f18eb33SBarry Smith @*/ 22229fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a,PetscInt b,PetscInt *result) 22232f18eb33SBarry Smith { 2224bafee8b4SSatish Balay PetscInt64 r; 22252f18eb33SBarry Smith 22262f18eb33SBarry Smith PetscFunctionBegin; 2227bafee8b4SSatish Balay r = PetscInt64Mult(a,b); 22282f18eb33SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22292c71b3e2SJacob 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); 22302f18eb33SBarry Smith #endif 2231f91af8c7SBarry Smith if (result) *result = (PetscInt)r; 2232f91af8c7SBarry Smith PetscFunctionReturn(0); 2233f91af8c7SBarry Smith } 2234f91af8c7SBarry Smith 2235f91af8c7SBarry Smith /*@C 2236f91af8c7SBarry Smith 2237fbfcfee5SBarry Smith PetscIntSumError - Computes the sum of two positive PetscInt and generates an error with overflow. 2238f91af8c7SBarry Smith 2239f91af8c7SBarry Smith Not Collective 2240f91af8c7SBarry Smith 2241d8d19677SJose E. Roman Input Parameters: 2242f91af8c7SBarry Smith + a - the PetscInt value 2243f91af8c7SBarry Smith - b - the second value 2244f91af8c7SBarry Smith 2245d8d19677SJose E. Roman Output Parameter: 2246390e1bf2SBarry 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 2247f91af8c7SBarry Smith 2248bafee8b4SSatish Balay Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64 2249f91af8c7SBarry Smith Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt 2250f91af8c7SBarry Smith 2251f5f57ec0SBarry Smith Not available from Fortran 2252f5f57ec0SBarry Smith 2253f91af8c7SBarry Smith Level: advanced 2254f91af8c7SBarry Smith 2255db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2256f91af8c7SBarry Smith @*/ 22579fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a,PetscInt b,PetscInt *result) 2258f91af8c7SBarry Smith { 2259bafee8b4SSatish Balay PetscInt64 r; 2260f91af8c7SBarry Smith 2261f91af8c7SBarry Smith PetscFunctionBegin; 2262bafee8b4SSatish Balay r = ((PetscInt64)a) + ((PetscInt64)b); 2263f91af8c7SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 22642c71b3e2SJacob 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); 2265f91af8c7SBarry Smith #endif 2266f91af8c7SBarry Smith if (result) *result = (PetscInt) r; 22672f18eb33SBarry Smith PetscFunctionReturn(0); 22682f18eb33SBarry Smith } 2269c5df96a5SBarry Smith 2270d382aafbSBarry Smith /* 22712981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2272d382aafbSBarry Smith */ 2273d382aafbSBarry Smith #if defined(hz) 2274d382aafbSBarry Smith # undef hz 2275d382aafbSBarry Smith #endif 2276d382aafbSBarry Smith 227715a5570dSLisandro Dalcin #include <limits.h> 227815a5570dSLisandro Dalcin 227915a5570dSLisandro Dalcin /* The number of bits in a byte */ 228015a5570dSLisandro Dalcin 228115a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT 228215a5570dSLisandro Dalcin 2283d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2284d382aafbSBarry Smith # include <sys/types.h> 2285d382aafbSBarry Smith #endif 2286d382aafbSBarry Smith 2287d382aafbSBarry Smith /*MC 2288d382aafbSBarry Smith 228966d79e26SBarry 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++ 229066d79e26SBarry Smith and Fortran compilers when petscsys.h is included. 229166d79e26SBarry Smith 229266d79e26SBarry Smith The current PETSc version and the API for accessing it are defined in petscversion.h 229366d79e26SBarry Smith 229466d79e26SBarry 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) 229566d79e26SBarry Smith 229666d79e26SBarry 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 229766d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 229866d79e26SBarry Smith 229966d79e26SBarry 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 230066d79e26SBarry Smith 230166d79e26SBarry 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), 230266d79e26SBarry 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 230366d79e26SBarry Smith version number (x.y.z). 230466d79e26SBarry Smith 230566d79e26SBarry Smith PETSC_RELEASE_DATE is the date the x.y version was released (i.e. the version before any patch releases) 230666d79e26SBarry Smith 230766d79e26SBarry Smith PETSC_VERSION_DATE is the date the x.y.z version was released 230866d79e26SBarry Smith 230966d79e26SBarry Smith PETSC_VERSION_GIT is the last git commit to the repository given in the form vx.y.z-wwwww 231066d79e26SBarry Smith 231166d79e26SBarry Smith PETSC_VERSION_DATE_GIT is the date of the last git commit to the repository 231266d79e26SBarry Smith 2313cbc12506SBarry Smith PETSC_VERSION_() is deprecated and will eventually be removed. 231466d79e26SBarry Smith 2315cbc12506SBarry Smith Level: intermediate 231666d79e26SBarry Smith 231766d79e26SBarry Smith M*/ 231866d79e26SBarry Smith 2319014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[],size_t); 2320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[],size_t); 2321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[],size_t); 2322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[],size_t); 2323014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[],size_t); 232527710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 23265f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt*,PetscInt*,PetscInt*,PetscInt*); 2327d382aafbSBarry Smith 23286a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt,const PetscInt[],PetscBool*); 23296a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt,const PetscMPIInt[],PetscBool*); 23306a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt,const PetscReal[],PetscBool*); 2331014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]); 2332ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt,PetscInt[]); 233322ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt*,PetscInt[]); 2334b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt,const PetscInt[],PetscBool*); 2335014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt*,PetscInt[]); 2336f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt,const PetscInt[],PetscBool*); 233760e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt*); 2338d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt*); 2339014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]); 2340014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]); 2341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]); 2342981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount,PetscInt[],PetscCount[]); 23436c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt,PetscInt[],PetscInt[],PetscInt[]); 2344981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount,PetscInt[],PetscInt[],PetscCount[]); 234517d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt,PetscMPIInt[]); 234617d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt*,PetscMPIInt[]); 2347014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]); 23485569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt,PetscMPIInt[],PetscInt[]); 2349014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]); 235017df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt,PetscInt[],void*,size_t,void*); 2351014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]); 235239f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt,PetscReal[],PetscInt[]); 2353014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]); 2354745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt*,PetscReal[]); 235539f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal,PetscInt,const PetscReal[],PetscReal,PetscInt*); 2356014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]); 2357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]); 2358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt,const PetscBool [],const PetscInt[],PetscInt*,PetscInt**,PetscInt**,PetscInt**,PetscInt**); 23596c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt,const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],PetscInt*,PetscInt**,PetscInt**); 23606c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscInt*,PetscInt**); 2361e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt,const PetscMPIInt[],PetscInt,const PetscMPIInt[],PetscInt*,PetscMPIInt**); 2362ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2363ce605777SToby Isaac 23644d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt,void*,size_t,int(*)(const void*,const void*,void*),void*); 2365676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt,PetscInt[]); 2366676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt,PetscMPIInt[]); 2367676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt,PetscReal[]); 23684d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt,void*,size_t,void*,size_t,int(*)(const void*,const void*,void*),void*); 2369676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt,PetscInt[],PetscInt[]); 2370676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt,PetscMPIInt[],PetscMPIInt[]); 2371676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt,PetscReal[],PetscInt[]); 2372676f2a66SJacob Faibussowitsch 2373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[],size_t); 2375d382aafbSBarry Smith 237676bdecfbSBarry Smith /*J 2377d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2378d382aafbSBarry Smith 2379d382aafbSBarry Smith Level: beginner 2380d382aafbSBarry Smith 2381e28ce29aSPatrick Sanan Notes: 2382e28ce29aSPatrick Sanan To use SPRNG or RANDOM123 you must have ./configure PETSc 238325ccb61fSToby Isaac with the option --download-sprng or --download-random123 2384d382aafbSBarry Smith 2385db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 238676bdecfbSBarry Smith J*/ 238719fd82e9SBarry Smith typedef const char* PetscRandomType; 2388d382aafbSBarry Smith #define PETSCRAND "rand" 2389d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2390d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2391c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 239225ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2393808ba619SStefano Zampini #define PETSCCURAND "curand" 2394d382aafbSBarry Smith 2395d382aafbSBarry Smith /* Logging support */ 2396014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2397d382aafbSBarry Smith 2398607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2399d382aafbSBarry Smith 2400d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2401140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2402d382aafbSBarry Smith 2403bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[],PetscErrorCode (*)(PetscRandom)); 240419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom,PetscRandomType); 2405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 240619fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom,PetscRandomType*); 2407fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom,PetscObject,const char[]); 2408014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer); 2409d382aafbSBarry Smith 2410014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*); 2411014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*); 2412014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom,PetscReal*); 2413808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom,PetscInt,PetscScalar*); 2414808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom,PetscInt,PetscReal*); 2415014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*); 2416014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar); 2417014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom,unsigned long); 2418014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom,unsigned long *); 2419014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2420014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom*); 2421d382aafbSBarry Smith 2422014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t); 2423014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t); 2424014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t); 2425014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[],char[]); 2426014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t); 2427014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscBool *); 2428014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscBool *); 242997540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 24308a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 243197540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2432d382aafbSBarry Smith 24339fbee547SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) {long _petsc_v = 1; return ((char*)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;} 243430815ce0SLisandro Dalcin 24359860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int,void*,PetscInt,PetscInt*,PetscDataType); 24369860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscInt*,PetscDataType); 2437f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int,const void*,PetscInt,PetscDataType); 2438f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm,int,const void*,PetscInt,PetscDataType); 2439014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[],PetscFileMode,int *); 2440014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2441014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscBool *); 2442014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscBool *); 2443014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char[],size_t); 2444014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscBool *); 2445014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char[],size_t,PetscBool *); 2446c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2447e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[],int,int*); 2448c891a504SStefano Zampini #endif 2449d382aafbSBarry Smith 2450014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*); 2451014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*); 2452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *,PetscDataType,PetscInt); 2453d382aafbSBarry Smith 2454014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2455014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscBool); 2456014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2457014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char*); 2458014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2459014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 24602a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2461d382aafbSBarry Smith 2462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*); 2463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**); 2464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**); 2465014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**); 2466014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**); 2467cf4b5b4fSJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt*,const void*,PetscMPIInt*,PetscMPIInt**,void*) 2468cf4b5b4fSJed Brown PetscAttrMPIPointerWithType(6,3); 2469d815da10SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt, 2470d815da10SJed Brown PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*), 2471d815da10SJed Brown PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx) 2472d815da10SJed Brown PetscAttrMPIPointerWithType(6,3); 24736afbe7ddSJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt, 24746afbe7ddSJed Brown MPI_Request**,MPI_Request**, 24756afbe7ddSJed Brown PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*), 24766afbe7ddSJed Brown PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx) 24776afbe7ddSJed Brown PetscAttrMPIPointerWithType(6,3); 2478d382aafbSBarry Smith 24796145cd65SJed Brown PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[]; 24806145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm,PetscBuildTwoSidedType); 24816145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm,PetscBuildTwoSidedType*); 24826145cd65SJed Brown 2483014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscBool*,PetscBool*); 2484d382aafbSBarry Smith 2485ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2486ce94432eSBarry Smith 248745487dadSJed Brown PETSC_EXTERN const char *const PetscSubcommTypes[]; 248845487dadSJed Brown 2489d382aafbSBarry Smith struct _n_PetscSubcomm { 2490d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2491d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2492306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 249345487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 249445487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2495708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 249645487dadSJed Brown PetscSubcommType type; 2497e5acf8a4SHong Zhang char *subcommprefix; 2498d382aafbSBarry Smith }; 2499d382aafbSBarry Smith 25009fbee547SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) {return scomm->parent;} 25019fbee547SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) {return scomm->child;} 25029fbee547SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) {return scomm->dupparent;} 2503014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm,PetscSubcomm*); 2504014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm*); 2505014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm,PetscInt); 2506014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm,PetscSubcommType); 250765d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm,PetscMPIInt,PetscMPIInt); 2508053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm,PetscViewer); 2509f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2510e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm,const char[]); 2511a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm,MPI_Comm*); 2512a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm,MPI_Comm*); 2513a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm,MPI_Comm*); 2514d382aafbSBarry Smith 25159962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt,PetscHeap*); 25169962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap,PetscInt,PetscInt); 25179962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap,PetscInt*,PetscInt*); 25189962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap,PetscInt*,PetscInt*); 25199962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap,PetscInt,PetscInt); 25209962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 25219962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap*); 25229962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap,PetscViewer); 25239962606eSBarry Smith 25245e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 25255f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm,PetscShmComm*); 25265f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm,PetscMPIInt,PetscMPIInt*); 25275f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm,PetscMPIInt,PetscMPIInt*); 25285f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm,MPI_Comm*); 25295e71baefSBarry Smith 2530a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2531a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm,PetscInt,PetscOmpCtrl*); 2532a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl,MPI_Comm*,MPI_Comm*,PetscBool*); 2533a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl*); 2534a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2535a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2536a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2537a32e93adSJunchao Zhang 253813e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t,size_t,PetscSegBuffer*); 25390f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer*); 254013e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer,size_t,void*); 2541137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer,void*); 2542137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer,void*); 2543137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer,void*); 254413e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer,size_t*); 254513e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer,size_t); 25460f453b92SJed Brown 2547471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2548471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2549471ecdacSJed Brown * possible. */ 25509fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg,size_t count,PetscInt *PETSC_RESTRICT *slot) {return PetscSegBufferGet(seg,count,(void**)slot);} 2551d382aafbSBarry Smith 25529de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 25539de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted*); 25549de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted*); 25559de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted,const char*,const char*,PetscBool*); 25569de0f6ecSBarry Smith 2557ace2fbaeSBarry Smith #include <stdarg.h> 2558ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],size_t*,va_list); 2559ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list); 2560ace2fbaeSBarry Smith 2561268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2562fbfcfee5SBarry Smith 25631f817a21SBarry Smith /*@C 25641f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 25651f817a21SBarry Smith 25661f817a21SBarry Smith Not Collective - only what is registered on rank 0 of PETSC_COMM_WORLD will be printed 25671f817a21SBarry Smith 25681f817a21SBarry Smith Input Parameters: 25691f817a21SBarry Smith + cite - the bibtex item, formated to displayed on multiple lines nicely 25701f817a21SBarry Smith - set - a boolean variable initially set to PETSC_FALSE; this is used to insure only a single registration of the citation 25711f817a21SBarry Smith 2572850545d0SSatish Balay Level: intermediate 2573850545d0SSatish Balay 2574f5f57ec0SBarry Smith Not available from Fortran 2575f5f57ec0SBarry Smith 25761f817a21SBarry Smith Options Database: 2577063414e0SPatrick Sanan . -citations [filename] - print out the bibtex entries for the given computation 25781f817a21SBarry Smith @*/ 25799fbee547SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[],PetscBool *set) 2580dff31646SBarry Smith { 2581dff31646SBarry Smith size_t len; 2582dff31646SBarry Smith char *vstring; 2583dff31646SBarry Smith 25841f817a21SBarry Smith PetscFunctionBegin; 25858d3683fcSBarry Smith if (set && *set) PetscFunctionReturn(0); 25869566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit,&len)); 25879566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList,len,&vstring)); 25889566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring,cit,len)); 2589dff31646SBarry Smith if (set) *set = PETSC_TRUE; 25901f817a21SBarry Smith PetscFunctionReturn(0); 2591dff31646SBarry Smith } 2592dff31646SBarry Smith 2593d8174014SToby Isaac PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Google has discontinued its URL shortener service") PetscErrorCode PetscURLShorten(const char [],char [], size_t c); 2594fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm,char[],char[],size_t); 2595fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm,const char[],char[],size_t); 2596f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm,const char[],const char []); 2597fe278a28SBarry Smith 2598f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm,char[],char[],size_t); 2599f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm,const char[],char[],char[],size_t); 2600b967cddfSBarry Smith 26019f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm,const char[],char[],size_t); 26029f4d3c52SBarry Smith 260304102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm,const char[],const char[],PetscBool*); 2604763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm,const char[],const char[],PetscBool*); 2605dff31646SBarry Smith 260668e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[],const char[],char[],size_t,PetscBool*); 26075dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[],const char[],const char[],size_t); 2608d382aafbSBarry Smith 2609b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 26109fbee547SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2611df05ca09SBarry Smith { 2612df05ca09SBarry Smith unsigned int c,hash = 5381; 2613df05ca09SBarry Smith 2614503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2615df05ca09SBarry Smith return hash; 2616df05ca09SBarry Smith } 261777a5e07dSBarry Smith 261877a5e07dSBarry Smith /*MC 261977a5e07dSBarry Smith MPIU_Allreduce - a PETSc replacement for MPI_Allreduce() that tries to determine if the call from all the MPI processes occur from the 262077a5e07dSBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI processes follow different code paths 262177a5e07dSBarry Smith resulting in inconsistent and incorrect calls to MPI_Allreduce(). 262277a5e07dSBarry Smith 2623d083f849SBarry Smith Collective 262477a5e07dSBarry Smith 262577a5e07dSBarry Smith Synopsis: 262677a5e07dSBarry Smith #include <petscsys.h> 262777a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 262877a5e07dSBarry Smith 262977a5e07dSBarry Smith Input Parameters: 2630df05ca09SBarry Smith + a - pointer to the input data to be reduced 2631df05ca09SBarry Smith . c - the number of MPI data items in a and b 2632df05ca09SBarry Smith . d - the MPI datatype, for example MPI_INT 2633df05ca09SBarry Smith . e - the MPI operation, for example MPI_SUM 2634df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 263577a5e07dSBarry Smith 263677a5e07dSBarry Smith Output Parameter: 2637df05ca09SBarry Smith . b - the reduced values 263877a5e07dSBarry Smith 2639e28ce29aSPatrick Sanan Notes: 2640e28ce29aSPatrick Sanan In optimized mode this directly calls MPI_Allreduce() 264177a5e07dSBarry Smith 2642df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2643df05ca09SBarry Smith 26441c2dc1cbSBarry 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 2645df05ca09SBarry Smith 264677a5e07dSBarry Smith Level: developer 264777a5e07dSBarry Smith 2648db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 264977a5e07dSBarry Smith M*/ 26501c2dc1cbSBarry Smith #define MPIU_Allreduce(a,b,c,d,e,fcomm) PetscMacroReturnStandard( \ 2651df05ca09SBarry Smith PetscMPIInt a_b1[6],a_b2[6]; \ 26523ca90d2dSJacob Faibussowitsch int _mpiu_allreduce_c_int = (int)c; \ 2653df05ca09SBarry Smith a_b1[0] = -(PetscMPIInt)__LINE__; a_b1[1] = -a_b1[0]; \ 2654df05ca09SBarry Smith a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); a_b1[3] = -a_b1[2]; \ 2655df05ca09SBarry Smith a_b1[4] = -(PetscMPIInt)(c); a_b1[5] = -a_b1[4]; \ 26569566063dSJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(a_b1,a_b2,6,MPI_INT,MPI_MAX,fcomm)); \ 26572c71b3e2SJacob Faibussowitsch PetscCheck(-a_b2[0] == a_b2[1],PETSC_COMM_SELF,PETSC_ERR_PLIB,"MPI_Allreduce() called in different locations (code lines) on different processors"); \ 26582c71b3e2SJacob Faibussowitsch PetscCheck(-a_b2[2] == a_b2[3],PETSC_COMM_SELF,PETSC_ERR_PLIB,"MPI_Allreduce() called in different locations (functions) on different processors"); \ 26592c71b3e2SJacob Faibussowitsch PetscCheck(-a_b2[4] == a_b2[5],PETSC_COMM_SELF,PETSC_ERR_PLIB,"MPI_Allreduce() called with different counts %d on different processors",_mpiu_allreduce_c_int); \ 26609566063dSJacob Faibussowitsch PetscCallMPI(MPI_Allreduce((a),(b),(c),d,e,(fcomm))); \ 26615f80ce2aSJacob Faibussowitsch ) 2662b2566f29SBarry Smith #else 26631c2dc1cbSBarry Smith #define MPIU_Allreduce(a,b,c,d,e,fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a),(b),(c),d,e,(fcomm)))) 2664b2566f29SBarry Smith #endif 2665b2566f29SBarry Smith 2666b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 26678198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint,PetscMPIInt,MPI_Info,MPI_Comm,void*,MPI_Win*); 26688198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win,PetscMPIInt,MPI_Aint*,PetscMPIInt*,void*); 26692f065d89SBarry Smith #endif 26708198064fSBarry Smith 2671cd88fca5SStefano Zampini /* this is a vile hack */ 2672cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 2673961fb248SStefano Zampini #if !defined(PETSC_NECMPI_VERSION_MAJOR) || \ 2674961fb248SStefano Zampini !defined(PETSC_NECMPI_VERSION_MINOR) || \ 2675961fb248SStefano Zampini PETSC_NECMPI_VERSION_MAJOR < 2 || \ 2676961fb248SStefano Zampini (PETSC_NECMPI_VERSION_MAJOR == 2 && PETSC_NECMPI_VERSION_MINOR < 18) 2677cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL,0); 2678cd88fca5SStefano Zampini #endif 2679961fb248SStefano Zampini #endif 2680cd88fca5SStefano Zampini 268112801b39SBarry Smith /* 268260fbe2beSVaclav Hapla List of external packages and queries on it 268360fbe2beSVaclav Hapla */ 268460fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[],PetscBool*); 268560fbe2beSVaclav Hapla 2686a52b435bSMark Adams /* 2687a52b435bSMark Adams OpenMP support 2688a52b435bSMark Adams */ 2689a52b435bSMark Adams #if defined(_OPENMP) 2690a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__)) 2691a52b435bSMark Adams #else // no OpenMP so no threads 2692a52b435bSMark Adams #define PetscPragmaOMP(...) 2693a52b435bSMark Adams #endif 2694a52b435bSMark Adams 2695f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2696f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2697f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2698f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2699d382aafbSBarry Smith #endif 2700