1d382aafbSBarry Smith /* 2d382aafbSBarry Smith This is the main PETSc include file (for C and C++). It is included by all 3d382aafbSBarry Smith other PETSc include files, so it almost never has to be specifically included. 447d993e7Ssuyashtn Portions of this code are under: 547d993e7Ssuyashtn Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. 6d382aafbSBarry Smith */ 7a4963045SJacob Faibussowitsch #pragma once 83ca90d2dSJacob Faibussowitsch 9d382aafbSBarry Smith /* ========================================================================== */ 10d382aafbSBarry Smith /* 11d382aafbSBarry Smith petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 121c77a0c5SBarry Smith found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 131c77a0c5SBarry Smith PETSc's makefiles add to the compiler rules. 141c77a0c5SBarry Smith For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 151cc8b206SBarry Smith directory as the other PETSc include files. 16d382aafbSBarry Smith */ 172c8e378dSBarry Smith #include <petscconf.h> 18100ffedbSJunchao Zhang #include <petscpkg_version.h> 191c77a0c5SBarry Smith #include <petscconf_poison.h> 202c8e378dSBarry Smith #include <petscfix.h> 21bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2233bb201bSJacob Faibussowitsch 23ac09b921SBarry Smith /* SUBMANSEC = Sys */ 24ac09b921SBarry Smith 2573fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2673fca5a0SBarry Smith /* 2773fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2873fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2973fca5a0SBarry Smith */ 30216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 3173fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L 3273fca5a0SBarry Smith #endif 33216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3473fca5a0SBarry Smith #define _BSD_SOURCE 3573fca5a0SBarry Smith #endif 3607f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3707f00807SSatish Balay #define _DEFAULT_SOURCE 3807f00807SSatish Balay #endif 39ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 40ea0fecefSShri Abhyankar #define _GNU_SOURCE 41ea0fecefSShri Abhyankar #endif 4273fca5a0SBarry Smith #endif 4373fca5a0SBarry Smith 44df4397b0SStefano Zampini #include <petscsystypes.h> 45df4397b0SStefano Zampini 46d382aafbSBarry Smith /* ========================================================================== */ 47d382aafbSBarry Smith 48d382aafbSBarry Smith /* 49d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 50d382aafbSBarry Smith 51d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 52d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 53d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 54d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 55d382aafbSBarry Smith mpicxx.h directly in their code 56d382aafbSBarry Smith */ 57fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 58d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1 59fa9e63e2SJed Brown #endif 60fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 61d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1 62fa9e63e2SJed Brown #endif 63e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 64e771154cSJed Brown #include <petsc/mpiuni/mpi.h> 65e771154cSJed Brown #else 662c8e378dSBarry Smith #include <mpi.h> 67e771154cSJed Brown #endif 6865013866SBarry Smith 69d382aafbSBarry Smith /* 70a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 71a7886beaSBarry Smith This usually happens because 72a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 73a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 74a2df2f37SMin RK Note: with MPICH and OpenMPI, accept versions [x.y.z, x+1.0.0) as compatible 75a7886beaSBarry Smith */ 76a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 776524c165SJacob Faibussowitsch #ifndef MPIUNI_H 78a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 79a7886beaSBarry Smith #endif 800f85934cSJunchao Zhang #elif defined(PETSC_HAVE_I_MPI) 8141f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 8241f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 830f85934cSJunchao Zhang #elif I_MPI_NUMVERSION != PETSC_PKG_I_MPI_NUMVERSION 8441f4af4cSSatish 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" 8541f4af4cSSatish Balay #endif 860f85934cSJunchao Zhang #elif defined(PETSC_HAVE_MVAPICH2) 8741f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8841f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 890f85934cSJunchao Zhang #elif MVAPICH2_NUMVERSION != PETSC_PKG_MVAPICH2_NUMVERSION 9041f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 9141f4af4cSSatish Balay #endif 92e3c15826SJunchao Zhang #elif defined(PETSC_HAVE_MPICH) 9341f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 94a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 95a2df2f37SMin RK #elif PETSC_PKG_MPICH_VERSION_GT(MPICH_NUMVERSION / 10000000, MPICH_NUMVERSION / 100000 % 100, MPICH_NUMVERSION / 1000 % 100) 96a2df2f37SMin RK #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using an older MPICH mpi.h version" 97a2df2f37SMin RK #elif PETSC_PKG_MPICH_VERSION_LT(MPICH_NUMVERSION / 10000000, 0, 0) 98a2df2f37SMin RK #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a newer major MPICH mpi.h version" 99a7886beaSBarry Smith #endif 100100ffedbSJunchao Zhang #elif defined(PETSC_HAVE_OPENMPI) 101a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 102a7886beaSBarry Smith #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h" 103a2df2f37SMin RK #elif PETSC_PKG_OPENMPI_VERSION_GT(OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION) 104a2df2f37SMin RK #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using an older Open MPI mpi.h version" 105a2df2f37SMin RK #elif PETSC_PKG_OPENMPI_VERSION_LT(OMPI_MAJOR_VERSION, 0, 0) 106a2df2f37SMin RK #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using a newer major Open MPI mpi.h version" 107a7886beaSBarry Smith #endif 108d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 109d97fd468SStefano Zampini #if !defined(MSMPI_VER) 110d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 111d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 112d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 113d97fd468SStefano Zampini #endif 114d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 115d97fd468SStefano Zampini #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of Open MPI, MS-MPI or a MPICH variant" 116a7886beaSBarry Smith #endif 117a7886beaSBarry Smith 118a7886beaSBarry Smith /* 1192981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 120d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 121d382aafbSBarry Smith */ 122d382aafbSBarry Smith #include <stdio.h> 123d382aafbSBarry Smith 1247de69702SBarry Smith /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */ 125d382aafbSBarry Smith #if !defined(MPIAPI) 126d382aafbSBarry Smith #define MPIAPI 127d382aafbSBarry Smith #endif 128d382aafbSBarry Smith 12993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 13093d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 131e28ce29aSPatrick Sanan 132e28ce29aSPatrick Sanan /*MC 13387497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 134e28ce29aSPatrick Sanan 135667f096bSBarry Smith Level: beginner 136667f096bSBarry Smith 13738b83642SBarry Smith Note: 13887497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 139e28ce29aSPatrick Sanan 14038b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 141e28ce29aSPatrick Sanan M*/ 142e28ce29aSPatrick Sanan 1437cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 144b7b8f77aSBarry Smith 145d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 146bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 147d382aafbSBarry Smith #else 148d382aafbSBarry Smith #define MPIU_INT MPI_INT 149d382aafbSBarry Smith #endif 150d382aafbSBarry Smith 15138b83642SBarry Smith /*MC 15238b83642SBarry Smith MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount` 15338b83642SBarry Smith 15438b83642SBarry Smith Level: beginner 15538b83642SBarry Smith 15638b83642SBarry Smith Note: 15738b83642SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value. 15838b83642SBarry Smith 15938b83642SBarry Smith Developer Note: 16095bd0b28SBarry Smith It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed 16138b83642SBarry Smith 16238b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 16338b83642SBarry Smith M*/ 16438b83642SBarry Smith #define MPIU_COUNT MPI_AINT 16538b83642SBarry Smith 166503cfb0cSBarry Smith /* 167503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 168503cfb0cSBarry Smith */ 16993d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 170d382aafbSBarry Smith 171d382aafbSBarry Smith /* 172d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 173d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 174d382aafbSBarry Smith */ 175014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 176d382aafbSBarry Smith 177d382aafbSBarry Smith /* 178d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 179d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 180d382aafbSBarry Smith */ 181014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 182d382aafbSBarry Smith 183d382aafbSBarry Smith /* 184dc07da0dSStefano Zampini Handle inclusion when using clang compiler with CUDA support 185dc07da0dSStefano Zampini __float128 is not available for the device 186dc07da0dSStefano Zampini */ 187731341e5SJunchao Zhang #if defined(__clang__) && (defined(__CUDA_ARCH__) || defined(__HIPCC__)) 188dc07da0dSStefano Zampini #define PETSC_SKIP_REAL___FLOAT128 189dc07da0dSStefano Zampini #endif 190dc07da0dSStefano Zampini 191dc07da0dSStefano Zampini /* 192d382aafbSBarry Smith Declare extern C stuff after including external header files 193d382aafbSBarry Smith */ 194d382aafbSBarry Smith 1956edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 1968b49ba18SBarry Smith /* 197390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 1988b49ba18SBarry Smith */ 1998b49ba18SBarry Smith #include <petscmath.h> 2008b49ba18SBarry Smith 201d382aafbSBarry Smith /*MC 202667f096bSBarry Smith PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument 203d382aafbSBarry Smith 204d382aafbSBarry Smith Level: beginner 205d382aafbSBarry Smith 206e28ce29aSPatrick Sanan Note: 207667f096bSBarry Smith Accepted by many PETSc functions to not set a parameter and instead use a default value 208d382aafbSBarry Smith 20987497f52SBarry Smith Fortran Note: 210667f096bSBarry Smith Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 211d382aafbSBarry Smith 212db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 213d382aafbSBarry Smith M*/ 214f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR 215edd03b47SJacob Faibussowitsch #define PETSC_NULL PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR 216c528d872SBarry Smith 217d382aafbSBarry Smith /*MC 218b3480c81SBarry Smith PETSC_UNLIMITED - standard way of passing an integer or floating point parameter to indicate PETSc there is no bound on the value allowed 219557d4da8SBarry Smith 220557d4da8SBarry Smith Level: beginner 221557d4da8SBarry Smith 222b3480c81SBarry Smith Example Usage: 223b3480c81SBarry Smith .vb 224b3480c81SBarry Smith KSPSetTolerances(ksp, PETSC_CURRENT, PETSC_CURRENT, PETSC_UNLIMITED, PETSC_UNLIMITED); 225b3480c81SBarry Smith .ve 226b3480c81SBarry Smith indicates that the solver is allowed to take any number of iterations and will not stop early no matter how the residual gets. 227b3480c81SBarry Smith 228b3480c81SBarry Smith Fortran Note: 229b3480c81SBarry Smith Use `PETSC_UNLIMITED_INTEGER` or `PETSC_UNLIMITED_REAL`. 230b3480c81SBarry Smith 231b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DECIDE` 232557d4da8SBarry Smith M*/ 233557d4da8SBarry Smith 234557d4da8SBarry Smith /*MC 235b3480c81SBarry Smith PETSC_DECIDE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value 236d382aafbSBarry Smith 237d382aafbSBarry Smith Level: beginner 238d382aafbSBarry Smith 239b3480c81SBarry Smith Example Usage: 240b3480c81SBarry Smith .vb 241b3480c81SBarry Smith VecSetSizes(ksp, PETSC_DECIDE, 10); 242b3480c81SBarry Smith .ve 243b3480c81SBarry Smith indicates that the global size of the vector is 10 and the local size will be automatically determined so that the sum of the 244b3480c81SBarry Smith local sizes is the global size, see `PetscSplitOwnership()`. 245b3480c81SBarry Smith 246b3480c81SBarry Smith Fortran Note: 247b3480c81SBarry Smith Use `PETSC_DECIDE_INTEGER` or `PETSC_DECIDE_REAL`. 248b3480c81SBarry Smith 249b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_UNLIMITED' 250b3480c81SBarry Smith M*/ 251b3480c81SBarry Smith 252b3480c81SBarry Smith /*MC 253b3480c81SBarry Smith PETSC_DETERMINE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value 254b3480c81SBarry Smith 255b3480c81SBarry Smith Level: beginner 256b3480c81SBarry Smith 257b3480c81SBarry Smith Example Usage: 258b3480c81SBarry Smith .vb 259b3480c81SBarry Smith VecSetSizes(ksp, 10, PETSC_DETERMINE); 260b3480c81SBarry Smith .ve 261b3480c81SBarry Smith indicates that the local size of the vector is 10 and the global size will be automatically summing up all the local sizes. 262b3480c81SBarry Smith 263b3480c81SBarry Smith Note: 264b3480c81SBarry Smith Same as `PETSC_DECIDE` 265b3480c81SBarry Smith 266b3480c81SBarry Smith Fortran Note: 267b3480c81SBarry Smith Use `PETSC_DETERMINE_INTEGER` or `PETSC_DETERMINE_REAL`. 268b3480c81SBarry Smith 269e28ce29aSPatrick Sanan Developer Note: 27087497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 27187497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 272557d4da8SBarry Smith 273b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`, `PETSC_UNLIMITED' 274d382aafbSBarry Smith M*/ 275d382aafbSBarry Smith 276d382aafbSBarry Smith /*MC 277b3480c81SBarry Smith PETSC_CURRENT - standard way of indicating to an object not to change the current value of the parameter in the object 278557d4da8SBarry Smith 279557d4da8SBarry Smith Level: beginner 280557d4da8SBarry Smith 281b3480c81SBarry Smith Note: 282b3480c81SBarry Smith Use `PETSC_DECIDE` to use the value that was set by PETSc when the object's type was set 283557d4da8SBarry Smith 284b3480c81SBarry Smith Fortran Note: 285b3480c81SBarry Smith Use `PETSC_CURRENT_INTEGER` or `PETSC_CURRENT_REAL`. 286b3480c81SBarry Smith 287b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DEFAULT`, `PETSC_UNLIMITED' 288b3480c81SBarry Smith M*/ 289b3480c81SBarry Smith 290b3480c81SBarry Smith /*MC 291b3480c81SBarry Smith PETSC_DEFAULT - deprecated, see `PETSC_CURRENT` and `PETSC_DETERMINE` 292b3480c81SBarry Smith 293b3480c81SBarry Smith Level: beginner 294b3480c81SBarry Smith 295b3480c81SBarry Smith Note: 296b3480c81SBarry Smith The name is confusing since it tells the object to continue to use the value it is using, not the default value when the object's type was set. 297b3480c81SBarry Smith 298b3480c81SBarry Smith Developer Note: 299b3480c81SBarry Smith Unfortunately this was used for two different purposes in the past, to actually trigger the use of a default value or to continue the 300b3480c81SBarry Smith use of currently set value (in, for example, `KSPSetTolerances()`. 301b3480c81SBarry Smith 302b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_CURRENT`, `PETSC_UNLIMITED' 303557d4da8SBarry Smith M*/ 30405c2f48cSJacob Faibussowitsch 30505c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */ 30605c2f48cSJacob Faibussowitsch #define PETSC_DECIDE (-1) 30705c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE 308b3480c81SBarry Smith #define PETSC_CURRENT (-2) 309b3480c81SBarry Smith #define PETSC_UNLIMITED (-3) 310b3480c81SBarry Smith /* PETSC_DEFAULT is deprecated in favor of PETSC_CURRENT for use in KSPSetTolerances() and similar functions */ 311b3480c81SBarry Smith #define PETSC_DEFAULT PETSC_CURRENT 312557d4da8SBarry Smith 313557d4da8SBarry Smith /*MC 314af27ebaaSBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about. 315d382aafbSBarry Smith 316d382aafbSBarry Smith Level: beginner 317d382aafbSBarry Smith 318e28ce29aSPatrick Sanan Notes: 31987497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 32087497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 32187497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 322af27ebaaSBarry Smith `PetscInitialize()`, but after `MPI_Init()` has been called. 323a990b902SBarry Smith 324af27ebaaSBarry Smith The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()` 325a990b902SBarry Smith is called because it may not have a valid value yet. 326d382aafbSBarry Smith 327db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 328d382aafbSBarry Smith M*/ 329014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 330d382aafbSBarry Smith 331d382aafbSBarry Smith /*MC 33287497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 333d382aafbSBarry Smith 334d382aafbSBarry Smith Level: beginner 335d382aafbSBarry Smith 33695bd0b28SBarry Smith Note: 33716a05f60SBarry Smith Do not USE/access or set this variable before `PetscInitialize()` has been called. 338a990b902SBarry Smith 339db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 340d382aafbSBarry Smith M*/ 341d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 342d382aafbSBarry Smith 3436de5d289SStefano Zampini /*MC 344af27ebaaSBarry Smith PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`. 3456de5d289SStefano Zampini 346d598313aSBarry Smith No Fortran Support 347d598313aSBarry Smith 3486de5d289SStefano Zampini Level: beginner 3496de5d289SStefano Zampini 35095bd0b28SBarry Smith Note: 351d598313aSBarry Smith By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED` when the MPI implementation provides `MPI_Init_thread()`, otherwise it equals `MPI_THREAD_SINGLE` 3526de5d289SStefano Zampini 353db781477SPatrick Sanan .seealso: `PetscInitialize()` 3546de5d289SStefano Zampini M*/ 3556de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3566de5d289SStefano Zampini 357d598313aSBarry Smith /*MC 358d598313aSBarry Smith PetscBeganMPI - indicates if PETSc initialized MPI during `PetscInitialize()` or if MPI was already initialized. 359d598313aSBarry Smith 360d598313aSBarry Smith Synopsis: 361d598313aSBarry Smith #include <petscsys.h> 362d598313aSBarry Smith PetscBool PetscBeganMPI; 363d598313aSBarry Smith 364d598313aSBarry Smith No Fortran Support 365d598313aSBarry Smith 366d598313aSBarry Smith Level: developer 367d598313aSBarry Smith 3680241b274SPierre Jolivet .seealso: `PetscInitialize()`, `PetscInitializeCalled` 369d598313aSBarry Smith M*/ 370d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 371d598313aSBarry Smith 3728ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 373014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 374014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3754cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 376d382aafbSBarry Smith 377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 38057f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 38157f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 382d382aafbSBarry Smith 38359e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 38459e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 38559e55d94SJunchao Zhang #endif 38659e55d94SJunchao Zhang 38771438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 38871438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 38971438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 39071438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 39171438e86SJunchao Zhang #endif 39271438e86SJunchao Zhang 393540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 394540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 395540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 396540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 397540e20f2SPierre Jolivet #endif 398540e20f2SPierre Jolivet 399d382aafbSBarry Smith /*MC 40087497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 401d382aafbSBarry Smith 402eca87e8dSBarry Smith Synopsis: 403aaa7dc30SBarry Smith #include <petscsys.h> 404eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 405eca87e8dSBarry Smith 406eca87e8dSBarry Smith Not Collective 407eca87e8dSBarry Smith 408d382aafbSBarry Smith Input Parameter: 409d382aafbSBarry Smith . m - number of bytes to allocate 410d382aafbSBarry Smith 411d382aafbSBarry Smith Output Parameter: 412d382aafbSBarry Smith . result - memory allocated 413d382aafbSBarry Smith 414d382aafbSBarry Smith Level: beginner 415d382aafbSBarry Smith 41649d7da52SJed Brown Notes: 41749d7da52SJed Brown Memory is always allocated at least double aligned 418d382aafbSBarry Smith 419835f2295SStefano Zampini It is safe to allocate size 0 and pass the resulting pointer to `PetscFree()`. 420d382aafbSBarry Smith 421db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 422d382aafbSBarry Smith M*/ 423071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 424d382aafbSBarry Smith 425d382aafbSBarry Smith /*MC 426d5b43468SJose E. Roman PetscRealloc - Reallocates memory 4273221ece2SMatthew G. Knepley 4283221ece2SMatthew G. Knepley Synopsis: 4293221ece2SMatthew G. Knepley #include <petscsys.h> 4303221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 4313221ece2SMatthew G. Knepley 4323221ece2SMatthew G. Knepley Not Collective 4333221ece2SMatthew G. Knepley 4343221ece2SMatthew G. Knepley Input Parameters: 4353221ece2SMatthew G. Knepley + m - number of bytes to allocate 43692f119d6SBarry Smith - result - previous memory 4373221ece2SMatthew G. Knepley 4383221ece2SMatthew G. Knepley Output Parameter: 4393221ece2SMatthew G. Knepley . result - new memory allocated 4403221ece2SMatthew G. Knepley 4413221ece2SMatthew G. Knepley Level: developer 4423221ece2SMatthew G. Knepley 44395bd0b28SBarry Smith Note: 4443221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 4453221ece2SMatthew G. Knepley 446db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 4473221ece2SMatthew G. Knepley M*/ 4483221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 4493221ece2SMatthew G. Knepley 4503221ece2SMatthew G. Knepley /*MC 45187497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 452d382aafbSBarry Smith 453d382aafbSBarry Smith Synopsis: 454aaa7dc30SBarry Smith #include <petscsys.h> 455d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 456d382aafbSBarry Smith 457eca87e8dSBarry Smith Not Collective 458eca87e8dSBarry Smith 4592fe279fdSBarry Smith Input Parameter: 460eca87e8dSBarry Smith . addr - address to align (any pointer type) 461eca87e8dSBarry Smith 462d382aafbSBarry Smith Level: developer 463d382aafbSBarry Smith 464db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 465d382aafbSBarry Smith M*/ 466f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))) 467d382aafbSBarry Smith 468d382aafbSBarry Smith /*MC 46987497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 4708f51dc47SJunchao Zhang 4718f51dc47SJunchao Zhang Synopsis: 4728f51dc47SJunchao Zhang #include <petscsys.h> 4738f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4748f51dc47SJunchao Zhang 4758f51dc47SJunchao Zhang Not Collective 4768f51dc47SJunchao Zhang 4778f51dc47SJunchao Zhang Input Parameter: 4788f51dc47SJunchao Zhang . m - number of bytes to allocate 4798f51dc47SJunchao Zhang 4808f51dc47SJunchao Zhang Output Parameter: 4818f51dc47SJunchao Zhang . result - memory allocated 4828f51dc47SJunchao Zhang 4838f51dc47SJunchao Zhang Level: beginner 4848f51dc47SJunchao Zhang 4858f51dc47SJunchao Zhang Notes: 4868f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4878f51dc47SJunchao Zhang 488835f2295SStefano Zampini It is safe to allocate size 0 and pass the resulting pointer to `PetscFree()`. 4898f51dc47SJunchao Zhang 490db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4918f51dc47SJunchao Zhang M*/ 492b67aa78dSSatish Balay #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result)) 4938f51dc47SJunchao Zhang 4948f51dc47SJunchao Zhang /*MC 49587497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 496d382aafbSBarry Smith 497eca87e8dSBarry Smith Synopsis: 498aaa7dc30SBarry Smith #include <petscsys.h> 499785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 500785e854fSJed Brown 501785e854fSJed Brown Not Collective 502785e854fSJed Brown 503785e854fSJed Brown Input Parameter: 504390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 505785e854fSJed Brown 506785e854fSJed Brown Output Parameter: 5071fe1b817SJunchao Zhang . r1 - memory allocated 508785e854fSJed Brown 50916a05f60SBarry Smith Level: beginner 51016a05f60SBarry Smith 511e28ce29aSPatrick Sanan Note: 5124a21bc22SJames Wright This uses `sizeof()` of the memory type requested to determine the total memory to be allocated; therefore, you should not 5134a21bc22SJames Wright multiply the number of elements requested by the `sizeof()` the type. For example, use 51416a05f60SBarry Smith .vb 51516a05f60SBarry Smith PetscInt *id; 51616a05f60SBarry Smith PetscMalloc1(10,&id); 51716a05f60SBarry Smith .ve 518390e1bf2SBarry Smith not 51916a05f60SBarry Smith .vb 52016a05f60SBarry Smith PetscInt *id; 52116a05f60SBarry Smith PetscMalloc1(10*sizeof(PetscInt),&id); 52216a05f60SBarry Smith .ve 523390e1bf2SBarry Smith 52487497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 525390e1bf2SBarry Smith 5264a21bc22SJames Wright The `PetscMalloc[N]()` and `PetscCalloc[N]()` take an argument of type `size_t`! However, most codes use `value`, computed via `int` or `PetscInt` variables. This can overflow in 5274a21bc22SJames Wright 32bit `int` computation - while computation in 64bit `size_t` would not overflow! 5284a21bc22SJames Wright It's best if any arithmetic that is done for size computations is done with `size_t` type - avoiding arithmetic overflow! 5294a21bc22SJames Wright 5304a21bc22SJames Wright `PetscMalloc[N]()` and `PetscCalloc[N]()` attempt to work-around this by casting the first variable to `size_t`. 5314a21bc22SJames Wright This works for most expressions, but not all, such as 5324a21bc22SJames Wright .vb 5334a21bc22SJames Wright PetscInt *id, a, b; 5344a21bc22SJames Wright PetscMalloc1(use_a_squared ? a * a * b : a * b, &id); // use_a_squared is cast to size_t, but a and b are still PetscInt 5354a21bc22SJames Wright PetscMalloc1(a + b * b, &id); // a is cast to size_t, but b * b is performed at PetscInt precision first due to order-of-operations 5364a21bc22SJames Wright .ve 5374a21bc22SJames Wright 5384a21bc22SJames Wright These expressions should either be avoided, or appropriately cast variables to `size_t`: 5394a21bc22SJames Wright .vb 5404a21bc22SJames Wright PetscInt *id, a, b; 5414a21bc22SJames Wright PetscMalloc1(use_a_squared ? (size_t)a * a * b : (size_t)a * b, &id); // Cast a to size_t before multiplication 5424a21bc22SJames Wright PetscMalloc1(b * b + a, &id); // b is automatically cast to size_t and order-of-operations ensures size_t precision is maintained 5434a21bc22SJames Wright .ve 5444a21bc22SJames Wright 545db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 546785e854fSJed Brown M*/ 547b67aa78dSSatish Balay #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 548785e854fSJed Brown 549785e854fSJed Brown /*MC 55087497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 5511795a4d1SJed Brown 5521795a4d1SJed Brown Synopsis: 553aaa7dc30SBarry Smith #include <petscsys.h> 5541795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 5551795a4d1SJed Brown 5561795a4d1SJed Brown Not Collective 5571795a4d1SJed Brown 5581795a4d1SJed Brown Input Parameter: 5591795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 5601795a4d1SJed Brown 5611795a4d1SJed Brown Output Parameter: 5621fe1b817SJunchao Zhang . r1 - memory allocated 5631795a4d1SJed Brown 56416a05f60SBarry Smith Level: beginner 56516a05f60SBarry Smith 56695bd0b28SBarry Smith Note: 56787497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 568390e1bf2SBarry Smith 569db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 5701795a4d1SJed Brown M*/ 571b67aa78dSSatish Balay #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 5721795a4d1SJed Brown 5731795a4d1SJed Brown /*MC 57487497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 575d382aafbSBarry Smith 576eca87e8dSBarry Smith Synopsis: 577aaa7dc30SBarry Smith #include <petscsys.h> 578dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 579eca87e8dSBarry Smith 580eca87e8dSBarry Smith Not Collective 581eca87e8dSBarry Smith 582d8d19677SJose E. Roman Input Parameters: 583d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 584dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 585d382aafbSBarry Smith 586d8d19677SJose E. Roman Output Parameters: 587d382aafbSBarry Smith + r1 - memory allocated in first chunk 588d382aafbSBarry Smith - r2 - memory allocated in second chunk 589d382aafbSBarry Smith 590d382aafbSBarry Smith Level: developer 591d382aafbSBarry Smith 592db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 593d382aafbSBarry Smith M*/ 594b67aa78dSSatish Balay #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)) 595d382aafbSBarry Smith 596d382aafbSBarry Smith /*MC 59787497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 598d382aafbSBarry Smith 599eca87e8dSBarry Smith Synopsis: 600aaa7dc30SBarry Smith #include <petscsys.h> 6011795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 602eca87e8dSBarry Smith 603eca87e8dSBarry Smith Not Collective 604eca87e8dSBarry Smith 605d8d19677SJose E. Roman Input Parameters: 606d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 6071795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 6081795a4d1SJed Brown 609d8d19677SJose E. Roman Output Parameters: 6101795a4d1SJed Brown + r1 - memory allocated in first chunk 6111795a4d1SJed Brown - r2 - memory allocated in second chunk 6121795a4d1SJed Brown 6131795a4d1SJed Brown Level: developer 6141795a4d1SJed Brown 615db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 6161795a4d1SJed Brown M*/ 617b67aa78dSSatish Balay #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)) 6181795a4d1SJed Brown 6191795a4d1SJed Brown /*MC 62087497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 621d382aafbSBarry Smith 622d382aafbSBarry Smith Synopsis: 623aaa7dc30SBarry Smith #include <petscsys.h> 624dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 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) 631dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 632d382aafbSBarry Smith 633d8d19677SJose E. Roman Output Parameters: 634d382aafbSBarry Smith + r1 - memory allocated in first chunk 635d382aafbSBarry Smith . r2 - memory allocated in second chunk 636d382aafbSBarry Smith - r3 - memory allocated in third chunk 637d382aafbSBarry Smith 638d382aafbSBarry Smith Level: developer 639d382aafbSBarry Smith 640db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 641d382aafbSBarry Smith M*/ 642f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \ 643b67aa78dSSatish Balay 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)) 644d382aafbSBarry Smith 645d382aafbSBarry Smith /*MC 64687497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 647d382aafbSBarry Smith 648eca87e8dSBarry Smith Synopsis: 649aaa7dc30SBarry Smith #include <petscsys.h> 6501795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 651eca87e8dSBarry Smith 652eca87e8dSBarry Smith Not Collective 653eca87e8dSBarry Smith 654d8d19677SJose E. Roman Input Parameters: 655d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 656d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 6571795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 6581795a4d1SJed Brown 659d8d19677SJose E. Roman Output Parameters: 6601795a4d1SJed Brown + r1 - memory allocated in first chunk 6611795a4d1SJed Brown . r2 - memory allocated in second chunk 6621795a4d1SJed Brown - r3 - memory allocated in third chunk 6631795a4d1SJed Brown 6641795a4d1SJed Brown Level: developer 6651795a4d1SJed Brown 666db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 6671795a4d1SJed Brown M*/ 668f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \ 669b67aa78dSSatish Balay 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)) 6701795a4d1SJed Brown 6711795a4d1SJed Brown /*MC 67287497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 673d382aafbSBarry Smith 674d382aafbSBarry Smith Synopsis: 675aaa7dc30SBarry Smith #include <petscsys.h> 676dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 677d382aafbSBarry Smith 678d382aafbSBarry Smith Not Collective 679d382aafbSBarry Smith 680d8d19677SJose E. Roman Input Parameters: 681d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 682d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 683d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 684dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 685d382aafbSBarry Smith 686d8d19677SJose E. Roman Output Parameters: 687d382aafbSBarry Smith + r1 - memory allocated in first chunk 688d382aafbSBarry Smith . r2 - memory allocated in second chunk 689d382aafbSBarry Smith . r3 - memory allocated in third chunk 690d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 691d382aafbSBarry Smith 692d382aafbSBarry Smith Level: developer 693d382aafbSBarry Smith 694db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 695d382aafbSBarry Smith M*/ 6969371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 697b67aa78dSSatish Balay PetscMallocA(4, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4)) 698d382aafbSBarry Smith 699d382aafbSBarry Smith /*MC 70087497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 701d382aafbSBarry Smith 702eca87e8dSBarry Smith Synopsis: 703aaa7dc30SBarry Smith #include <petscsys.h> 7041795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 705eca87e8dSBarry Smith 706eca87e8dSBarry Smith Not Collective 707eca87e8dSBarry Smith 708e28ce29aSPatrick Sanan Input Parameters: 709d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 710d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 711d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 7121795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 7131795a4d1SJed Brown 714e28ce29aSPatrick Sanan Output Parameters: 7151795a4d1SJed Brown + r1 - memory allocated in first chunk 7161795a4d1SJed Brown . r2 - memory allocated in second chunk 7171795a4d1SJed Brown . r3 - memory allocated in third chunk 7181795a4d1SJed Brown - r4 - memory allocated in fourth chunk 7191795a4d1SJed Brown 7201795a4d1SJed Brown Level: developer 7211795a4d1SJed Brown 722db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 7231795a4d1SJed Brown M*/ 7249371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 725b67aa78dSSatish Balay PetscMallocA(4, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4)) 7261795a4d1SJed Brown 7271795a4d1SJed Brown /*MC 72887497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 729d382aafbSBarry Smith 730d382aafbSBarry Smith Synopsis: 731aaa7dc30SBarry Smith #include <petscsys.h> 732dcca6d9dSJed 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) 733d382aafbSBarry Smith 734d382aafbSBarry Smith Not Collective 735d382aafbSBarry Smith 736e28ce29aSPatrick Sanan Input Parameters: 737d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 738d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 739d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 740d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 741dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 742d382aafbSBarry Smith 743e28ce29aSPatrick Sanan Output Parameters: 744d382aafbSBarry Smith + r1 - memory allocated in first chunk 745d382aafbSBarry Smith . r2 - memory allocated in second chunk 746d382aafbSBarry Smith . r3 - memory allocated in third chunk 747d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 748d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 749d382aafbSBarry Smith 750d382aafbSBarry Smith Level: developer 751d382aafbSBarry Smith 752db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 753d382aafbSBarry Smith M*/ 7549371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 755b67aa78dSSatish Balay PetscMallocA(5, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5)) 756d382aafbSBarry Smith 757d382aafbSBarry Smith /*MC 75887497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 759d382aafbSBarry Smith 760eca87e8dSBarry Smith Synopsis: 761aaa7dc30SBarry Smith #include <petscsys.h> 7621795a4d1SJed 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) 763eca87e8dSBarry Smith 764eca87e8dSBarry Smith Not Collective 765eca87e8dSBarry Smith 766e28ce29aSPatrick Sanan Input Parameters: 767d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 768d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 769d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 770d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 7711795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 7721795a4d1SJed Brown 773e28ce29aSPatrick Sanan Output Parameters: 7741795a4d1SJed Brown + r1 - memory allocated in first chunk 7751795a4d1SJed Brown . r2 - memory allocated in second chunk 7761795a4d1SJed Brown . r3 - memory allocated in third chunk 7771795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7781795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7791795a4d1SJed Brown 7801795a4d1SJed Brown Level: developer 7811795a4d1SJed Brown 782db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7831795a4d1SJed Brown M*/ 7849371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 785b67aa78dSSatish Balay PetscMallocA(5, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5)) 786d382aafbSBarry Smith 787d382aafbSBarry Smith /*MC 78887497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 789d382aafbSBarry Smith 790d382aafbSBarry Smith Synopsis: 791aaa7dc30SBarry Smith #include <petscsys.h> 792dcca6d9dSJed 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) 793d382aafbSBarry Smith 794d382aafbSBarry Smith Not Collective 795d382aafbSBarry Smith 796e28ce29aSPatrick Sanan Input Parameters: 797d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 798d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 799d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 800d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 801d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 802dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 803d382aafbSBarry Smith 804e28ce29aSPatrick Sanan Output Parameteasr: 805d382aafbSBarry Smith + r1 - memory allocated in first chunk 806d382aafbSBarry Smith . r2 - memory allocated in second chunk 807d382aafbSBarry Smith . r3 - memory allocated in third chunk 808d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 809d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 810d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 811d382aafbSBarry Smith 812d382aafbSBarry Smith Level: developer 813d382aafbSBarry Smith 814db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 815d382aafbSBarry Smith M*/ 8169371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 817b67aa78dSSatish Balay PetscMallocA(6, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6)) 818d382aafbSBarry Smith 819d382aafbSBarry Smith /*MC 82087497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 821d382aafbSBarry Smith 822eca87e8dSBarry Smith Synopsis: 823aaa7dc30SBarry Smith #include <petscsys.h> 8241795a4d1SJed 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) 825eca87e8dSBarry Smith 826eca87e8dSBarry Smith Not Collective 827eca87e8dSBarry Smith 828e28ce29aSPatrick Sanan Input Parameters: 829d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 830d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 831d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 832d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 833d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 8341795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 8351795a4d1SJed Brown 836e28ce29aSPatrick Sanan Output Parameters: 8371795a4d1SJed Brown + r1 - memory allocated in first chunk 8381795a4d1SJed Brown . r2 - memory allocated in second chunk 8391795a4d1SJed Brown . r3 - memory allocated in third chunk 8401795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8411795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8421795a4d1SJed Brown - r6 - memory allocated in sixth chunk 8431795a4d1SJed Brown 8441795a4d1SJed Brown Level: developer 8451795a4d1SJed Brown 846db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 8471795a4d1SJed Brown M*/ 8489371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 849b67aa78dSSatish Balay PetscMallocA(6, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6)) 8501795a4d1SJed Brown 8511795a4d1SJed Brown /*MC 85287497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 853d382aafbSBarry Smith 854d382aafbSBarry Smith Synopsis: 855aaa7dc30SBarry Smith #include <petscsys.h> 856dcca6d9dSJed 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) 857d382aafbSBarry Smith 858d382aafbSBarry Smith Not Collective 859d382aafbSBarry Smith 860e28ce29aSPatrick Sanan Input Parameters: 861d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 862d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 863d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 864d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 865d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 866d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 867dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 868d382aafbSBarry Smith 869e28ce29aSPatrick Sanan Output Parameters: 870d382aafbSBarry Smith + r1 - memory allocated in first chunk 871d382aafbSBarry Smith . r2 - memory allocated in second chunk 872d382aafbSBarry Smith . r3 - memory allocated in third chunk 873d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 874d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 875d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 876eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 877d382aafbSBarry Smith 878d382aafbSBarry Smith Level: developer 879d382aafbSBarry Smith 880db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 881d382aafbSBarry Smith M*/ 8829371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 883b67aa78dSSatish Balay PetscMallocA(7, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7)) 884d382aafbSBarry Smith 885d382aafbSBarry Smith /*MC 88687497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 8871795a4d1SJed Brown 8881795a4d1SJed Brown Synopsis: 889aaa7dc30SBarry Smith #include <petscsys.h> 8901795a4d1SJed 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) 8911795a4d1SJed Brown 8921795a4d1SJed Brown Not Collective 8931795a4d1SJed Brown 894e28ce29aSPatrick Sanan Input Parameters: 8951795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8961795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8971795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8981795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8991795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 9001795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 9011795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 9021795a4d1SJed Brown 903e28ce29aSPatrick Sanan Output Parameters: 9041795a4d1SJed Brown + r1 - memory allocated in first chunk 9051795a4d1SJed Brown . r2 - memory allocated in second chunk 9061795a4d1SJed Brown . r3 - memory allocated in third chunk 9071795a4d1SJed Brown . r4 - memory allocated in fourth chunk 9081795a4d1SJed Brown . r5 - memory allocated in fifth chunk 9091795a4d1SJed Brown . r6 - memory allocated in sixth chunk 9101795a4d1SJed Brown - r7 - memory allocated in seventh chunk 9111795a4d1SJed Brown 9121795a4d1SJed Brown Level: developer 9131795a4d1SJed Brown 914db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 9151795a4d1SJed Brown M*/ 9169371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 917b67aa78dSSatish Balay PetscMallocA(7, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1), ((size_t)((size_t)m2) * sizeof(**(r2))), (r2), ((size_t)((size_t)m3) * sizeof(**(r3))), (r3), ((size_t)((size_t)m4) * sizeof(**(r4))), (r4), ((size_t)((size_t)m5) * sizeof(**(r5))), (r5), ((size_t)((size_t)m6) * sizeof(**(r6))), (r6), ((size_t)((size_t)m7) * sizeof(**(r7))), (r7)) 9181795a4d1SJed Brown 9191795a4d1SJed Brown /*MC 92087497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 921d382aafbSBarry Smith 922eca87e8dSBarry Smith Synopsis: 923aaa7dc30SBarry Smith #include <petscsys.h> 924b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 925eca87e8dSBarry Smith 926eca87e8dSBarry Smith Not Collective 927eca87e8dSBarry Smith 928d382aafbSBarry Smith Output Parameter: 929b00a9115SJed Brown . result - memory allocated, sized to match pointer type 930d382aafbSBarry Smith 931d382aafbSBarry Smith Level: beginner 932d382aafbSBarry Smith 933fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 934d382aafbSBarry Smith M*/ 935b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 936ad0619ddSBarry Smith 937f4f49eeaSPierre Jolivet #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b) 938d382aafbSBarry Smith 939d382aafbSBarry Smith /*MC 940d382aafbSBarry Smith PetscFree - Frees memory 941d382aafbSBarry Smith 942eca87e8dSBarry Smith Synopsis: 943aaa7dc30SBarry Smith #include <petscsys.h> 944eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 945eca87e8dSBarry Smith 946eca87e8dSBarry Smith Not Collective 947eca87e8dSBarry Smith 948d382aafbSBarry Smith Input Parameter: 94916a05f60SBarry Smith . memory - memory to free (the pointer is ALWAYS set to `NULL` upon success) 950d382aafbSBarry Smith 951d382aafbSBarry Smith Level: beginner 952d382aafbSBarry Smith 95395bd0b28SBarry Smith Notes: 95487497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 955390e1bf2SBarry Smith 95616a05f60SBarry Smith It is safe to call `PetscFree()` on a `NULL` pointer. 957d382aafbSBarry Smith 958fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 959d382aafbSBarry Smith M*/ 9603ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS))) 961d382aafbSBarry Smith 962d382aafbSBarry Smith /*MC 96387497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 964d382aafbSBarry Smith 965eca87e8dSBarry Smith Synopsis: 966aaa7dc30SBarry Smith #include <petscsys.h> 967eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 968eca87e8dSBarry Smith 969eca87e8dSBarry Smith Not Collective 970eca87e8dSBarry Smith 971e28ce29aSPatrick Sanan Input Parameters: 972d382aafbSBarry Smith + memory1 - memory to free 973d382aafbSBarry Smith - memory2 - 2nd memory to free 974d382aafbSBarry Smith 975d382aafbSBarry Smith Level: developer 976d382aafbSBarry Smith 9777e17494fSJames Wright Notes: 97887497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 979d382aafbSBarry Smith 9807e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc2()` 9817e17494fSJames Wright 982db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 983d382aafbSBarry Smith M*/ 984ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 985d382aafbSBarry Smith 986d382aafbSBarry Smith /*MC 98787497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 988d382aafbSBarry Smith 989eca87e8dSBarry Smith Synopsis: 990aaa7dc30SBarry Smith #include <petscsys.h> 991eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 992eca87e8dSBarry Smith 993eca87e8dSBarry Smith Not Collective 994eca87e8dSBarry Smith 995e28ce29aSPatrick Sanan Input Parameters: 996d382aafbSBarry Smith + memory1 - memory to free 997d382aafbSBarry Smith . memory2 - 2nd memory to free 998d382aafbSBarry Smith - memory3 - 3rd memory to free 999d382aafbSBarry Smith 1000d382aafbSBarry Smith Level: developer 1001d382aafbSBarry Smith 10027e17494fSJames Wright Notes: 100387497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 1004d382aafbSBarry Smith 10057e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc3()` 10067e17494fSJames Wright 1007db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 1008d382aafbSBarry Smith M*/ 1009ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 1010d382aafbSBarry Smith 1011d382aafbSBarry Smith /*MC 101287497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 1013d382aafbSBarry Smith 1014eca87e8dSBarry Smith Synopsis: 1015aaa7dc30SBarry Smith #include <petscsys.h> 1016eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 1017eca87e8dSBarry Smith 1018eca87e8dSBarry Smith Not Collective 1019eca87e8dSBarry Smith 1020e28ce29aSPatrick Sanan Input Parameters: 1021d382aafbSBarry Smith + m1 - memory to free 1022d382aafbSBarry Smith . m2 - 2nd memory to free 1023d382aafbSBarry Smith . m3 - 3rd memory to free 1024d382aafbSBarry Smith - m4 - 4th memory to free 1025d382aafbSBarry Smith 1026d382aafbSBarry Smith Level: developer 1027d382aafbSBarry Smith 10287e17494fSJames Wright Notes: 102987497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 1030d382aafbSBarry Smith 10317e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc4()` 10327e17494fSJames Wright 1033db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 1034d382aafbSBarry Smith M*/ 1035ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 1036d382aafbSBarry Smith 1037d382aafbSBarry Smith /*MC 103887497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 1039d382aafbSBarry Smith 1040eca87e8dSBarry Smith Synopsis: 1041aaa7dc30SBarry Smith #include <petscsys.h> 1042eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 1043eca87e8dSBarry Smith 1044eca87e8dSBarry Smith Not Collective 1045eca87e8dSBarry Smith 1046e28ce29aSPatrick Sanan Input Parameters: 1047d382aafbSBarry Smith + m1 - memory to free 1048d382aafbSBarry Smith . m2 - 2nd memory to free 1049d382aafbSBarry Smith . m3 - 3rd memory to free 1050d382aafbSBarry Smith . m4 - 4th memory to free 1051d382aafbSBarry Smith - m5 - 5th memory to free 1052d382aafbSBarry Smith 1053d382aafbSBarry Smith Level: developer 1054d382aafbSBarry Smith 10557e17494fSJames Wright Notes: 105687497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 1057d382aafbSBarry Smith 10587e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc5()` 10597e17494fSJames Wright 1060db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 1061d382aafbSBarry Smith M*/ 1062ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 1063d382aafbSBarry Smith 1064d382aafbSBarry Smith /*MC 106587497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 1066d382aafbSBarry Smith 1067eca87e8dSBarry Smith Synopsis: 1068aaa7dc30SBarry Smith #include <petscsys.h> 1069eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1070eca87e8dSBarry Smith 1071eca87e8dSBarry Smith Not Collective 1072eca87e8dSBarry Smith 1073e28ce29aSPatrick Sanan Input Parameters: 1074d382aafbSBarry Smith + m1 - memory to free 1075d382aafbSBarry Smith . m2 - 2nd memory to free 1076d382aafbSBarry Smith . m3 - 3rd memory to free 1077d382aafbSBarry Smith . m4 - 4th memory to free 1078d382aafbSBarry Smith . m5 - 5th memory to free 1079d382aafbSBarry Smith - m6 - 6th memory to free 1080d382aafbSBarry Smith 1081d382aafbSBarry Smith Level: developer 1082d382aafbSBarry Smith 10837e17494fSJames Wright Notes: 108487497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 1085d382aafbSBarry Smith 10867e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc6()` 10877e17494fSJames Wright 1088db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1089d382aafbSBarry Smith M*/ 1090ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 1091d382aafbSBarry Smith 1092d382aafbSBarry Smith /*MC 109387497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 1094d382aafbSBarry Smith 1095eca87e8dSBarry Smith Synopsis: 1096aaa7dc30SBarry Smith #include <petscsys.h> 1097eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1098eca87e8dSBarry Smith 1099eca87e8dSBarry Smith Not Collective 1100eca87e8dSBarry Smith 1101e28ce29aSPatrick Sanan Input Parameters: 1102d382aafbSBarry Smith + m1 - memory to free 1103d382aafbSBarry Smith . m2 - 2nd memory to free 1104d382aafbSBarry Smith . m3 - 3rd memory to free 1105d382aafbSBarry Smith . m4 - 4th memory to free 1106d382aafbSBarry Smith . m5 - 5th memory to free 1107d382aafbSBarry Smith . m6 - 6th memory to free 1108d382aafbSBarry Smith - m7 - 7th memory to free 1109d382aafbSBarry Smith 1110d382aafbSBarry Smith Level: developer 1111d382aafbSBarry Smith 11127e17494fSJames Wright Notes: 111387497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1114d382aafbSBarry Smith 11157e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc7()` 11167e17494fSJames Wright 1117db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1118db781477SPatrick Sanan `PetscMalloc7()` 1119d382aafbSBarry Smith M*/ 1120ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1121d382aafbSBarry Smith 1122ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1123ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1124071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1125efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 11263221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1127ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 112892f119d6SBarry 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 **)); 1129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1130d382aafbSBarry Smith 1131d382aafbSBarry Smith /* 1132c1706be6SHong 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. 1133c1706be6SHong Zhang */ 1134c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1135c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 113631f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 113731f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 113831f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 113931f06eaaSHong Zhang #endif 114059af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 114159af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 114259af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 114359af0bd3SScott Kruger #endif 114459af0bd3SScott Kruger 1145a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 114636763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1147a5057860SBarry Smith 1148a5057860SBarry Smith /* 114966d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1150d382aafbSBarry Smith */ 1151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 115292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1154014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1155e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1156e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 115792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 115892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1159efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 116092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 116192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1162608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1163608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1164d382aafbSBarry Smith 1165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 11688e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1169d382aafbSBarry Smith 1170d382aafbSBarry Smith /* 1171d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1172d382aafbSBarry Smith */ 1173367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1174570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1175de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1176014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1177014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1178d9822059SBarry Smith #else 1179de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1180d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1181d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1182d9822059SBarry Smith #endif 118362e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 118462e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 118562e5d2d2SJDBetteridge 1186a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16)) 1187613bf2b2SPierre Jolivet /*MC 118816a05f60SBarry Smith MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with 118916a05f60SBarry Smith custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1190613bf2b2SPierre Jolivet 1191613bf2b2SPierre Jolivet Level: advanced 1192613bf2b2SPierre Jolivet 1193613bf2b2SPierre Jolivet Developer Note: 1194613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1195613bf2b2SPierre Jolivet 1196613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1197613bf2b2SPierre Jolivet M*/ 11989e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1199613bf2b2SPierre Jolivet #endif 1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1201d382aafbSBarry Smith 120293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 120393d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1204eb3f98d2SBarry Smith 1205639ff905SBarry Smith /* 120649abdd8aSBarry Smith These are so that in extern C code we can cast function pointers to non-extern C 120749abdd8aSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 120849abdd8aSBarry Smith */ 120949abdd8aSBarry Smith 121049abdd8aSBarry Smith /*S 121149abdd8aSBarry Smith PetscVoidFn - A prototype of a void (fn)(void) function 121249abdd8aSBarry Smith 121349abdd8aSBarry Smith Level: developer 121449abdd8aSBarry Smith 121549abdd8aSBarry Smith Notes: 121649abdd8aSBarry Smith The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *. 121749abdd8aSBarry Smith 121849abdd8aSBarry Smith The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **. 121949abdd8aSBarry Smith 122049abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 122149abdd8aSBarry Smith S*/ 122249abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void); 122349abdd8aSBarry Smith 122449abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn *PetscVoidFunction; 122549abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction; 122649abdd8aSBarry Smith 122749abdd8aSBarry Smith /*S 122849abdd8aSBarry Smith PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function 122949abdd8aSBarry Smith 123049abdd8aSBarry Smith Level: developer 123149abdd8aSBarry Smith 123249abdd8aSBarry Smith Notes: 123349abdd8aSBarry Smith The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *. 123449abdd8aSBarry Smith 123549abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 123649abdd8aSBarry Smith S*/ 123749abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void); 123849abdd8aSBarry Smith 123949abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction; 124049abdd8aSBarry Smith 124149abdd8aSBarry Smith /*S 124249abdd8aSBarry Smith PetscCtxDestroyFn - A prototype of a `PetscErrorCode (*)(void *)` function that is used to free user contexts 124349abdd8aSBarry Smith 124449abdd8aSBarry Smith Level: intermediate 124549abdd8aSBarry Smith 124649abdd8aSBarry Smith Note: 124749abdd8aSBarry Smith Used in the prototype of functions such as `DMSetApplicationContextDestroy()` 124849abdd8aSBarry Smith 124949abdd8aSBarry Smith .seealso: `PetscObject`, `PetscCtxDestroyDefault()`, `PetscObjectDestroy()`, `DMSetApplicationContextDestroy()` 125049abdd8aSBarry Smith S*/ 125149abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscCtxDestroyFn)(void **); 125249abdd8aSBarry Smith 125349abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PetscCtxDestroyDefault; 125449abdd8aSBarry Smith 125549abdd8aSBarry Smith /* 1256639ff905SBarry Smith Defines PETSc error handling. 1257639ff905SBarry Smith */ 1258639ff905SBarry Smith #include <petscerror.h> 1259d382aafbSBarry Smith 1260660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1261660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1262660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1263660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1264660278c0SBarry Smith 1265835f2295SStefano Zampini #define PETSC_SMALLEST_CLASSID 1211211 1266014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1267014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1268014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 126981256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 127081256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 127181256985SMatthew G. Knepley 1272d382aafbSBarry Smith /* 1273d382aafbSBarry Smith Routines that get memory usage information from the OS 1274d382aafbSBarry Smith */ 1275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1277014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1278b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1279d382aafbSBarry Smith 1280014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1281d382aafbSBarry Smith 1282d382aafbSBarry Smith /* 1283d382aafbSBarry Smith Initialization of PETSc 1284d382aafbSBarry Smith */ 1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1295d382aafbSBarry Smith 1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1297607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 12984bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void); 1299d382aafbSBarry Smith 1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1303014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1304d382aafbSBarry Smith 130549abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscBool *); 1306d382aafbSBarry Smith 1307d382aafbSBarry Smith /* 1308d382aafbSBarry Smith Functions that can act on any PETSc object. 1309d382aafbSBarry Smith */ 1310014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1312014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1315014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1316014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1317014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1318014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1319014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1323014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1325014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1327bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 13288434afd1SBarry Smith #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__)) 1329014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1330014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 13310eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 13320eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1333014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1334d382aafbSBarry Smith 1335b3480c81SBarry Smith /*MC 1336b3480c81SBarry Smith PetscObjectParameterSetDefault - sets a parameter default value in a `PetscObject` to a new default value. 1337b3480c81SBarry Smith If the current value matches the old default value, then the current value is also set to the new value. 1338b3480c81SBarry Smith 1339b3480c81SBarry Smith No Fortran Support 1340b3480c81SBarry Smith 1341b3480c81SBarry Smith Synopsis: 1342b3480c81SBarry Smith #include <petscsys.h> 1343b3480c81SBarry Smith PetscBool PetscObjectParameterSetDefault(PetscObject obj, char* NAME, PetscReal value); 1344b3480c81SBarry Smith 1345b3480c81SBarry Smith Input Parameters: 1346b3480c81SBarry Smith + obj - the `PetscObject` 1347b3480c81SBarry Smith . NAME - the name of the parameter, unquoted 1348b3480c81SBarry Smith - value - the new value 1349b3480c81SBarry Smith 1350b3480c81SBarry Smith Level: developer 1351b3480c81SBarry Smith 1352b3480c81SBarry Smith Notes: 1353b3480c81SBarry Smith The defaults for an object are the values set when the object's type is set. 1354b3480c81SBarry Smith 1355b3480c81SBarry Smith This should only be used in object constructors, such as, `SNESCreate_NGS()`. 1356b3480c81SBarry Smith 1357b3480c81SBarry Smith This only works for parameters that are declared in the struct with `PetscObjectParameterDeclare()` 1358b3480c81SBarry Smith 1359b3480c81SBarry Smith .seealso: `PetscObjectParameterDeclare()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()` 1360b3480c81SBarry Smith M*/ 1361b3480c81SBarry Smith #define PetscObjectParameterSetDefault(obj, NAME, value) \ 1362b3480c81SBarry Smith do { \ 1363b3480c81SBarry Smith if (obj->NAME == obj->default_##NAME) obj->NAME = value; \ 1364b3480c81SBarry Smith obj->default_##NAME = value; \ 1365b3480c81SBarry Smith } while (0) 1366b3480c81SBarry Smith 1367b3480c81SBarry Smith /*MC 1368b3480c81SBarry Smith PetscObjectParameterDeclare - declares a parameter in a `PetscObject` and a location to store its default 1369b3480c81SBarry Smith 1370b3480c81SBarry Smith No Fortran Support 1371b3480c81SBarry Smith 1372b3480c81SBarry Smith Synopsis: 1373b3480c81SBarry Smith #include <petscsys.h> 1374b3480c81SBarry Smith PetscBool PetscObjectParameterDeclare(type, char* NAME) 1375b3480c81SBarry Smith 1376b3480c81SBarry Smith Input Parameters: 1377b3480c81SBarry Smith + type - the type of the parameter, for example `PetscInt` 1378b3480c81SBarry Smith - NAME - the name of the parameter, unquoted 1379b3480c81SBarry Smith 1380b3480c81SBarry Smith Level: developer. 1381b3480c81SBarry Smith 1382b3480c81SBarry Smith .seealso: `PetscObjectParameterSetDefault()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()` 1383b3480c81SBarry Smith M*/ 1384b3480c81SBarry Smith #define PetscObjectParameterDeclare(type, NAME) type NAME, default_##NAME 1385b3480c81SBarry Smith 1386665c2dedSJed Brown #include <petscviewertypes.h> 1387639ff905SBarry Smith #include <petscoptions.h> 1388639ff905SBarry Smith 1389608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1390608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1391608c71bfSMatthew G. Knepley 13920633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 13930633abcbSJed Brown 1394c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1395dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1396639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 13978434afd1SBarry Smith #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr)) 13980cd8b6e2SStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectHasFunction(PetscObject, const char[], PetscBool *); 13990005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1400014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1402014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1403014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1404014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1406014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1407685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1408014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1409014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1410013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 14114099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1412014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1413b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1414014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1415014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1416d382aafbSBarry Smith 1417e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 14187aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1419e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1420e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1421e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1422e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1423e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1424e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1425e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1426e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1427e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 142815681b3cSBarry Smith 1429ec7429eaSBarry Smith #else 14303ba16761SJacob Faibussowitsch #define PetscSAWsBlock() PETSC_SUCCESS 14313ba16761SJacob Faibussowitsch #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS 14323ba16761SJacob Faibussowitsch #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS 14333ba16761SJacob Faibussowitsch #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS 14343ba16761SJacob Faibussowitsch #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS 14353ba16761SJacob Faibussowitsch #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS 14363ba16761SJacob Faibussowitsch #define PetscStackViewSAWs() PETSC_SUCCESS 14373ba16761SJacob Faibussowitsch #define PetscStackSAWsViewOff() PETSC_SUCCESS 1438e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1439e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 144015681b3cSBarry Smith 1441ec7429eaSBarry Smith #endif 1442b90c6cbeSBarry Smith 144382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 144482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 144582b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1446258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1447258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1448258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1449258ec3d2SMatthew G. Knepley #endif 14507d5d4d99SBarry Smith 1451a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1452a64a8e02SBarry Smith 1453dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 14544bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer); 14555d83a8b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, const char **); 1456140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1457140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1458140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1459140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1460140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1461140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1462d382aafbSBarry Smith 1463d382aafbSBarry Smith /* 1464503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1465d382aafbSBarry Smith link libraries that will be loaded as needed. 1466d382aafbSBarry Smith */ 1467a240a19fSJed Brown 14688434afd1SBarry Smith #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr)) 14698434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *); 1470140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 14710e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 14728434afd1SBarry Smith #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr)) 14738434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **); 147444ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1475140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1476140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1477140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 14782e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 14792e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1480d382aafbSBarry Smith 1481014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1482014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1483014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1487014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1488014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1489d382aafbSBarry Smith 1490d382aafbSBarry Smith /* 1491d382aafbSBarry Smith Useful utility routines 1492d382aafbSBarry Smith */ 1493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1494014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1495d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1496014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1497014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1498014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1499014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 150058b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 150158b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1502d382aafbSBarry Smith 150364ac3b0dSPatrick Sanan /*MC 150487497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1505503cfb0cSBarry Smith 150664ac3b0dSPatrick Sanan Level: beginner 150764ac3b0dSPatrick Sanan 1508a1cb98faSBarry Smith Note: 1509a1cb98faSBarry Smith This is useful in cases like 1510a1cb98faSBarry Smith .vb 1511a1cb98faSBarry Smith int *a; 1512a1cb98faSBarry Smith PetscBool flag = PetscNot(a) 1513a1cb98faSBarry Smith .ve 1514a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1515a1cb98faSBarry Smith 1516a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 151764ac3b0dSPatrick Sanan M*/ 1518d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1519503cfb0cSBarry Smith 1520d382aafbSBarry Smith /*MC 1521d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1522d382aafbSBarry Smith 1523d382aafbSBarry Smith Synopsis: 1524aaa7dc30SBarry Smith #include <petscsys.h> 1525659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1526d382aafbSBarry Smith 15277cdbe19fSJose E. Roman Not Collective, only applies on MPI rank 0; No Fortran Support 15287cdbe19fSJose E. Roman 1529d382aafbSBarry Smith Input Parameters: 1530659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1531d382aafbSBarry Smith . format - the usual printf() format string 1532659f7ba0SBarry Smith - args - arguments to be printed 1533d382aafbSBarry Smith 1534d382aafbSBarry Smith Level: developer 1535d382aafbSBarry Smith 153695bd0b28SBarry Smith Notes: 1537659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1538659f7ba0SBarry Smith 1539659f7ba0SBarry Smith To use, write your own function, for example, 154016a05f60SBarry Smith .vb 154116a05f60SBarry Smith PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 154216a05f60SBarry Smith { 154316a05f60SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 154416a05f60SBarry Smith } 154516a05f60SBarry Smith .ve 1546d5b43468SJose E. Roman then do the assignment 1547af27ebaaSBarry Smith .vb 1548af27ebaaSBarry Smith PetscHelpPrintf = mypetschelpprintf; 1549af27ebaaSBarry Smith .ve 1550af27ebaaSBarry Smith 155187497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1552659f7ba0SBarry Smith 155387497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1554d382aafbSBarry Smith 155516a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()` 1556d382aafbSBarry Smith M*/ 15573ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1558d382aafbSBarry Smith 1559fcfd50ebSBarry Smith /* 1560fcfd50ebSBarry Smith Defines PETSc profiling. 1561fcfd50ebSBarry Smith */ 15622c8e378dSBarry Smith #include <petsclog.h> 1563fcfd50ebSBarry Smith 1564fcfd50ebSBarry Smith /* 1565fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1566fcfd50ebSBarry Smith */ 1567014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1568014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1569014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 15703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1571c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *); 15723ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 15733ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 15743ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 15751b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1576fcfd50ebSBarry Smith 15773ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 15783ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 15793ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1580d382aafbSBarry Smith 1581d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1582d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1583d781fa04SBarry Smith 1584014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1585016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 158674ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1587d382aafbSBarry Smith 15883ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 15893ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 15900ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1591014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1592014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1593014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1594d382aafbSBarry Smith 1595014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1596014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1597014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1598014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1599014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 160049abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerSetCtxDestroy(PetscContainer, PetscCtxDestroyFn *); 160149abdd8aSBarry Smith PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscContainerSetCtxDestroy()", ) PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 160249abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerCompose(PetscObject, const char *name, void *, PetscCtxDestroyFn *); 16038a085367SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerQuery(PetscObject, const char *, void **); 1604d382aafbSBarry Smith 160549abdd8aSBarry Smith PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscCtxDestroyDefault()", ) static inline PetscErrorCode PetscContainerCtxDestroyDefault(void **a) 160649abdd8aSBarry Smith { 160749abdd8aSBarry Smith return PetscCtxDestroyDefault(a); 160849abdd8aSBarry Smith } 160949abdd8aSBarry Smith 1610d382aafbSBarry Smith /* 1611d382aafbSBarry Smith For use in debuggers 1612d382aafbSBarry Smith */ 1613014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1614014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 161557b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscIntViewNumColumns(PetscInt, PetscInt, const PetscInt[], PetscViewer); 161657b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscRealViewNumColumns(PetscInt, PetscInt, const PetscReal[], PetscViewer); 161757b47c28SJames Wright PETSC_EXTERN PetscErrorCode PetscScalarViewNumColumns(PetscInt, PetscInt, const PetscScalar[], PetscViewer); 1618014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1619014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1620014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1621d382aafbSBarry Smith 1622bbcf679cSJacob Faibussowitsch /* 1623bbcf679cSJacob Faibussowitsch Basic memory and string operations. These are usually simple wrappers 1624bbcf679cSJacob Faibussowitsch around the basic Unix system calls, but a few of them have additional 1625bbcf679cSJacob Faibussowitsch functionality and/or error checking. 1626bbcf679cSJacob Faibussowitsch */ 1627bbcf679cSJacob Faibussowitsch #include <petscstring.h> 1628bbcf679cSJacob Faibussowitsch 1629a663daf8SBarry Smith #include <stddef.h> 1630d382aafbSBarry Smith #include <stdlib.h> 16316c7e564aSBarry Smith 1632447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER) 1633447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d) 1634447bcd8fSJacob Faibussowitsch #else 1635d382aafbSBarry Smith /*MC 1636d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1637d382aafbSBarry Smith 1638eca87e8dSBarry Smith Synopsis: 1639aaa7dc30SBarry Smith #include <petscsys.h> 1640eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1641eca87e8dSBarry Smith 1642d382aafbSBarry Smith Not Collective 1643d382aafbSBarry Smith 1644d382aafbSBarry Smith Input Parameters: 164516a05f60SBarry Smith + a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`) 1646d382aafbSBarry Smith . n - number of elements to fetch 1647d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 164850d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1649d382aafbSBarry Smith 1650d382aafbSBarry Smith Level: developer 1651d382aafbSBarry Smith 1652d382aafbSBarry Smith Notes: 165316a05f60SBarry Smith The last two arguments (`rw` and `t`) must be compile-time constants. 1654d382aafbSBarry Smith 165550d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 165650d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 165787497f52SBarry Smith + `PETSC_PREFETCH_HINT_NTA` - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 165887497f52SBarry Smith . `PETSC_PREFETCH_HINT_T0` - Fetch to all levels of cache and evict to the closest level. Use this when the memory will be reused regularly despite necessary eviction from L1. 165987497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 166087497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1661d382aafbSBarry Smith 1662d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1663d382aafbSBarry Smith address). 1664d382aafbSBarry Smith 1665d382aafbSBarry Smith M*/ 16669371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 16679371c9d4SSatish Balay do { \ 1668d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1669d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1670d382aafbSBarry Smith } while (0) 1671447bcd8fSJacob Faibussowitsch #endif 1672d382aafbSBarry Smith /* 1673d382aafbSBarry Smith Determine if some of the kernel computation routines use 1674d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1675d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1676d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1677e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1678d382aafbSBarry Smith */ 1679d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1680d382aafbSBarry Smith 1681d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1682d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1683d382aafbSBarry Smith #endif 1684d382aafbSBarry Smith 1685d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1686d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1687d382aafbSBarry Smith #endif 1688d382aafbSBarry Smith 1689d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1690d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1691d382aafbSBarry Smith #endif 1692d382aafbSBarry Smith 1693d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1694d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1695d382aafbSBarry Smith #endif 1696d382aafbSBarry Smith 1697d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1698d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1699d382aafbSBarry Smith #endif 1700d382aafbSBarry Smith 1701d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1702d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1703d382aafbSBarry Smith #endif 1704d382aafbSBarry Smith 1705d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1706d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1707d382aafbSBarry Smith #endif 1708d382aafbSBarry Smith 1709d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1710d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1711d382aafbSBarry Smith #endif 1712d382aafbSBarry Smith 1713d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1714d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1715d382aafbSBarry Smith #endif 1716d382aafbSBarry Smith 1717d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1718d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1719d382aafbSBarry Smith #endif 1720d382aafbSBarry Smith 1721d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1722d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1723d382aafbSBarry Smith #endif 1724d382aafbSBarry Smith 1725d382aafbSBarry Smith #endif 1726d382aafbSBarry Smith 1727d382aafbSBarry Smith /* 1728d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1729d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1730d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1731d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1732d382aafbSBarry Smith ugly extern "C" {} wrappers. 1733d382aafbSBarry Smith */ 1734d382aafbSBarry Smith #if defined(__cplusplus) 1735d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1736d382aafbSBarry Smith #define EXTERN_C_END } 1737d382aafbSBarry Smith #else 1738d382aafbSBarry Smith #define EXTERN_C_BEGIN 1739d382aafbSBarry Smith #define EXTERN_C_END 1740d382aafbSBarry Smith #endif 1741d382aafbSBarry Smith 1742d382aafbSBarry Smith /*MC 1743d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1744d382aafbSBarry Smith communication 1745d382aafbSBarry Smith 1746d382aafbSBarry Smith Level: beginner 1747d382aafbSBarry Smith 174816a05f60SBarry Smith Note: 174916a05f60SBarry Smith This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm` 1750d382aafbSBarry Smith 1751db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1752d382aafbSBarry Smith M*/ 1753d382aafbSBarry Smith 1754d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 175593d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 175693d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 175793d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 175893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 175993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 176093d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_at_all(MPI_File, MPI_Offset, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 5); 1761d382aafbSBarry Smith #endif 1762d382aafbSBarry Smith 1763462c564dSBarry Smith #if defined(PETSC_HAVE_MPI_COUNT) 1764462c564dSBarry Smith typedef MPI_Count MPIU_Count; 1765462c564dSBarry Smith #else 1766462c564dSBarry Smith typedef PetscInt64 MPIU_Count; 1767462c564dSBarry Smith #endif 1768462c564dSBarry Smith 176961b0d812SBarry Smith /*@C 1770462c564dSBarry Smith PetscIntCast - casts a `MPI_Count`, `PetscInt64`, `PetscCount`, or `size_t` to a `PetscInt` (which may be 32-bits in size), generates an 177187497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1772c73702f5SBarry Smith 177320f4b53cSBarry Smith Not Collective; No Fortran Support 1774c73702f5SBarry Smith 1775c73702f5SBarry Smith Input Parameter: 177687497f52SBarry Smith . a - the `PetscInt64` value 1777c73702f5SBarry Smith 1778c73702f5SBarry Smith Output Parameter: 17796497c311SBarry Smith . b - the resulting `PetscInt` value, or `NULL` if the result is not needed 1780c73702f5SBarry Smith 1781c73702f5SBarry Smith Level: advanced 1782c73702f5SBarry Smith 178395bd0b28SBarry Smith Note: 17847de69702SBarry Smith If integers needed for the applications are too large to fit in 32-bit ints you can ./configure using `--with-64-bit-indices` to make `PetscInt` use 64-bit integers 1785c73702f5SBarry Smith 1786784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscCIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1787c73702f5SBarry Smith @*/ 1788462c564dSBarry Smith static inline PetscErrorCode PetscIntCast(MPIU_Count a, PetscInt *b) 1789d71ae5a4SJacob Faibussowitsch { 1790c73702f5SBarry Smith PetscFunctionBegin; 17916497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1792462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscInt) || (a <= (MPIU_Count)PETSC_INT_MAX && a >= (MPIU_Count)PETSC_INT_MIN), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", (PetscInt64)a); 1793377f809aSBarry Smith if (b) *b = (PetscInt)a; 17943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1795c73702f5SBarry Smith } 1796c73702f5SBarry Smith 1797c73702f5SBarry Smith /*@C 1798462c564dSBarry Smith PetscBLASIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount` or `PetscInt64` to a `PetscBLASInt` (which may be 32-bits in size), generates an 179987497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 180061b0d812SBarry Smith 1801667f096bSBarry Smith Not Collective; No Fortran Support 180261b0d812SBarry Smith 180361b0d812SBarry Smith Input Parameter: 180487497f52SBarry Smith . a - the `PetscInt` value 180561b0d812SBarry Smith 180661b0d812SBarry Smith Output Parameter: 18076497c311SBarry Smith . b - the resulting `PetscBLASInt` value, or `NULL` if the result is not needed 180861b0d812SBarry Smith 180961b0d812SBarry Smith Level: advanced 181061b0d812SBarry Smith 1811667f096bSBarry Smith Note: 1812f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 18131fd49c25SBarry Smith 1814784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 181561b0d812SBarry Smith @*/ 1816462c564dSBarry Smith static inline PetscErrorCode PetscBLASIntCast(MPIU_Count a, PetscBLASInt *b) 1817d71ae5a4SJacob Faibussowitsch { 1818c5df96a5SBarry Smith PetscFunctionBegin; 18196497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1820462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscBLASInt) || a <= (MPIU_Count)PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_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", (PetscInt64)a); 182154c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 18226497c311SBarry Smith if (b) *b = (PetscBLASInt)a; 18233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1824c5df96a5SBarry Smith } 1825c5df96a5SBarry Smith 182661b0d812SBarry Smith /*@C 182787497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 1828eee0c0a6SToby Isaac 1829667f096bSBarry Smith Not Collective; No Fortran Support 1830eee0c0a6SToby Isaac 1831eee0c0a6SToby Isaac Input Parameter: 183287497f52SBarry Smith . a - the `PetscInt` value 1833eee0c0a6SToby Isaac 1834eee0c0a6SToby Isaac Output Parameter: 18356497c311SBarry Smith . b - the resulting `PetscCuBLASInt` value, or `NULL` if the result is not needed 1836eee0c0a6SToby Isaac 1837eee0c0a6SToby Isaac Level: advanced 1838eee0c0a6SToby Isaac 1839667f096bSBarry Smith Note: 1840eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 1841eee0c0a6SToby Isaac 1842784a7648SPierre Jolivet .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 1843eee0c0a6SToby Isaac @*/ 1844462c564dSBarry Smith static inline PetscErrorCode PetscCuBLASIntCast(MPIU_Count a, PetscCuBLASInt *b) 1845d71ae5a4SJacob Faibussowitsch { 1846eee0c0a6SToby Isaac PetscFunctionBegin; 18476497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1848462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscCuBLASInt) || a <= (MPIU_Count)PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for cuBLAS, which is restricted to 32-bit integers.", (PetscInt64)a); 1849462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to cuBLAS routine", (PetscInt64)a); 18506497c311SBarry Smith if (b) *b = (PetscCuBLASInt)a; 18513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1852eee0c0a6SToby Isaac } 1853eee0c0a6SToby Isaac 1854eee0c0a6SToby Isaac /*@C 185547d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 185647d993e7Ssuyashtn 1857667f096bSBarry Smith Not Collective; No Fortran Support 185847d993e7Ssuyashtn 185947d993e7Ssuyashtn Input Parameter: 186047d993e7Ssuyashtn . a - the `PetscInt` value 186147d993e7Ssuyashtn 186247d993e7Ssuyashtn Output Parameter: 18636497c311SBarry Smith . b - the resulting `PetscHipBLASInt` value, or `NULL` if the result is not needed 186447d993e7Ssuyashtn 186547d993e7Ssuyashtn Level: advanced 186647d993e7Ssuyashtn 1867667f096bSBarry Smith Note: 186847d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 186947d993e7Ssuyashtn 1870784a7648SPierre Jolivet .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 187147d993e7Ssuyashtn @*/ 1872462c564dSBarry Smith static inline PetscErrorCode PetscHipBLASIntCast(MPIU_Count a, PetscHipBLASInt *b) 187347d993e7Ssuyashtn { 187447d993e7Ssuyashtn PetscFunctionBegin; 18756497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1876462c564dSBarry Smith PetscCheck(sizeof(MPIU_Count) <= sizeof(PetscHipBLASInt) || a <= (MPIU_Count)PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for hipBLAS, which is restricted to 32-bit integers.", (PetscInt64)a); 1877462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to hipBLAS routine", (PetscInt64)a); 18786497c311SBarry Smith if (b) *b = (PetscHipBLASInt)a; 18793ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 188047d993e7Ssuyashtn } 188147d993e7Ssuyashtn 188247d993e7Ssuyashtn /*@C 1883462c564dSBarry Smith PetscMPIIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `PetscMPIInt` (which is always 32-bits in size), generates an 1884667f096bSBarry Smith error if the `PetscMPIInt` is not large enough to hold the number. 188561b0d812SBarry Smith 1886667f096bSBarry Smith Not Collective; No Fortran Support 188761b0d812SBarry Smith 188861b0d812SBarry Smith Input Parameter: 188987497f52SBarry Smith . a - the `PetscInt` value 189061b0d812SBarry Smith 189161b0d812SBarry Smith Output Parameter: 18926497c311SBarry Smith . b - the resulting `PetscMPIInt` value, or `NULL` if the result is not needed 189361b0d812SBarry Smith 189461b0d812SBarry Smith Level: advanced 189561b0d812SBarry Smith 18966a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 189761b0d812SBarry Smith @*/ 1898462c564dSBarry Smith static inline PetscErrorCode PetscMPIIntCast(MPIU_Count a, PetscMPIInt *b) 1899d71ae5a4SJacob Faibussowitsch { 19004dc2109aSBarry Smith PetscFunctionBegin; 19016497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1902462c564dSBarry Smith PetscCheck(a <= (MPIU_Count)PETSC_MPI_INT_MAX && a >= (MPIU_Count)PETSC_MPI_INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for MPI buffer length. Maximum supported value is %d", (PetscInt64)a, PETSC_MPI_INT_MAX); 19036497c311SBarry Smith if (b) *b = (PetscMPIInt)a; 19043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19054dc2109aSBarry Smith } 19064dc2109aSBarry Smith 1907784a7648SPierre Jolivet /*@C 1908784a7648SPierre Jolivet PetscCIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `int`, generates an error if the `int` is not large enough to hold the number. 1909784a7648SPierre Jolivet 1910784a7648SPierre Jolivet Not Collective; No Fortran Support 1911784a7648SPierre Jolivet 1912784a7648SPierre Jolivet Input Parameter: 1913784a7648SPierre Jolivet . a - the `PetscInt` value 1914784a7648SPierre Jolivet 1915784a7648SPierre Jolivet Output Parameter: 1916784a7648SPierre Jolivet . b - the resulting `int` value, or `NULL` if the result is not needed 1917784a7648SPierre Jolivet 1918784a7648SPierre Jolivet Level: advanced 1919784a7648SPierre Jolivet 1920784a7648SPierre Jolivet .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntCast()` 1921784a7648SPierre Jolivet @*/ 1922784a7648SPierre Jolivet static inline PetscErrorCode PetscCIntCast(MPIU_Count a, int *b) 1923784a7648SPierre Jolivet { 1924784a7648SPierre Jolivet PetscFunctionBegin; 1925784a7648SPierre Jolivet if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1926784a7648SPierre Jolivet PetscCheck(a <= INT_MAX && a >= INT_MIN, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big to be casted to an int. Maximum supported value is %d", (PetscInt64)a, INT_MAX); 1927784a7648SPierre Jolivet if (b) *b = (int)a; 1928784a7648SPierre Jolivet PetscFunctionReturn(PETSC_SUCCESS); 1929784a7648SPierre Jolivet } 1930784a7648SPierre Jolivet 1931835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 1932835f2295SStefano Zampini #define PetscInt64Mult(a, b) ((a) * (b)) 1933835f2295SStefano Zampini #else 1934f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b))) 1935835f2295SStefano Zampini #endif 19362f18eb33SBarry Smith 19372f18eb33SBarry Smith /*@C 1938f3fa974cSJacob Faibussowitsch PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive 1939f3fa974cSJacob Faibussowitsch `PetscInt` and truncates the value to slightly less than the maximal possible value. 19402f18eb33SBarry Smith 194120f4b53cSBarry Smith Not Collective; No Fortran Support 19422f18eb33SBarry Smith 1943d8d19677SJose E. Roman Input Parameters: 1944f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value 1945f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value 19462f18eb33SBarry Smith 1947667f096bSBarry Smith Level: advanced 1948667f096bSBarry Smith 1949f3fa974cSJacob Faibussowitsch Notes: 1950f3fa974cSJacob Faibussowitsch Returns the result as a `PetscInt` value. 19512f18eb33SBarry Smith 1952f3fa974cSJacob Faibussowitsch Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`. 1953667f096bSBarry Smith 1954f3fa974cSJacob Faibussowitsch Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate 1955f3fa974cSJacob Faibussowitsch to fit a `PetscInt`. 1956667f096bSBarry Smith 1957f3fa974cSJacob Faibussowitsch Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an 1958f3fa974cSJacob Faibussowitsch error if the result will not fit in a `PetscInt`. 19592f18eb33SBarry Smith 1960b5e6e808SPierre Jolivet Developer Notes: 1961f3fa974cSJacob Faibussowitsch We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but 1962f3fa974cSJacob Faibussowitsch requires many more checks. 19632f18eb33SBarry Smith 1964f3fa974cSJacob Faibussowitsch This is used where we compute approximate sizes for workspace and need to insure the 1965f3fa974cSJacob Faibussowitsch workspace is index-able. 19661fd49c25SBarry Smith 1967f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 19682f18eb33SBarry Smith @*/ 1969d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 1970d71ae5a4SJacob Faibussowitsch { 19715f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 19721690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 1973835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 1974835f2295SStefano Zampini return r; 1975835f2295SStefano Zampini #else 19762f18eb33SBarry Smith return (PetscInt)r; 1977835f2295SStefano Zampini #endif 19782f18eb33SBarry Smith } 19792f18eb33SBarry Smith 19802f18eb33SBarry Smith /*@C 198187497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 19822f18eb33SBarry Smith 1983667f096bSBarry Smith Not Collective; No Fortran Support 19842f18eb33SBarry Smith 1985d8d19677SJose E. Roman Input Parameters: 1986af27ebaaSBarry Smith + a - the `PetscInt` value 19872f18eb33SBarry Smith - b - the second value 19882f18eb33SBarry Smith 1989390e1bf2SBarry Smith Returns: 1990af27ebaaSBarry Smith The result as a `PetscInt` value 19912f18eb33SBarry Smith 1992667f096bSBarry Smith Level: advanced 1993667f096bSBarry Smith 1994667f096bSBarry Smith Notes: 199587497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1996667f096bSBarry Smith 199787497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1998667f096bSBarry Smith 199987497f52SBarry 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` 20002f18eb33SBarry Smith 2001b5e6e808SPierre Jolivet Developer Notes: 200287497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 20032f18eb33SBarry Smith 20042f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 20052f18eb33SBarry Smith 2006667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`, 2007667f096bSBarry Smith `PetscIntSumTruncate()` 20082f18eb33SBarry Smith @*/ 2009d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 2010d71ae5a4SJacob Faibussowitsch { 20115f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 20121690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 2013835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 2014835f2295SStefano Zampini return r; 2015835f2295SStefano Zampini #else 20162f18eb33SBarry Smith return (PetscInt)r; 2017835f2295SStefano Zampini #endif 20182f18eb33SBarry Smith } 20192f18eb33SBarry Smith 2020f91af8c7SBarry Smith /*@C 202187497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 2022f91af8c7SBarry Smith 2023667f096bSBarry Smith Not Collective; No Fortran Support 2024f91af8c7SBarry Smith 2025d8d19677SJose E. Roman Input Parameters: 202687497f52SBarry Smith + a - the `PetscInt` value 2027f91af8c7SBarry Smith - b - the second value 2028f91af8c7SBarry Smith 2029390e1bf2SBarry Smith Returns: 2030af27ebaaSBarry Smith The result as a `PetscInt` value 2031f91af8c7SBarry Smith 2032667f096bSBarry Smith Level: advanced 2033667f096bSBarry Smith 2034667f096bSBarry Smith Notes: 203587497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 2036667f096bSBarry Smith 203787497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 2038667f096bSBarry Smith 203987497f52SBarry 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` 2040f91af8c7SBarry Smith 2041b5e6e808SPierre Jolivet Developer Note: 2042f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2043f91af8c7SBarry Smith 2044db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2045f91af8c7SBarry Smith @*/ 2046d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 2047d71ae5a4SJacob Faibussowitsch { 2048835f2295SStefano Zampini PetscInt64 r = a; 2049835f2295SStefano Zampini 2050835f2295SStefano Zampini r += b; 20511690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 2052835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 2053835f2295SStefano Zampini return r; 2054835f2295SStefano Zampini #else 2055f91af8c7SBarry Smith return (PetscInt)r; 2056835f2295SStefano Zampini #endif 2057f91af8c7SBarry Smith } 2058f91af8c7SBarry Smith 20592f18eb33SBarry Smith /*@C 206087497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 20612f18eb33SBarry Smith 2062667f096bSBarry Smith Not Collective; No Fortran Support 20632f18eb33SBarry Smith 2064d8d19677SJose E. Roman Input Parameters: 206587497f52SBarry Smith + a - the `PetscInt` value 20662f18eb33SBarry Smith - b - the second value 20672f18eb33SBarry Smith 2068d8d19677SJose E. Roman Output Parameter: 206916a05f60SBarry 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 20702f18eb33SBarry Smith 2071667f096bSBarry Smith Level: advanced 20722f18eb33SBarry Smith 2073667f096bSBarry Smith Notes: 2074667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 2075667f096bSBarry Smith 2076667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2077f5f57ec0SBarry Smith 2078b5e6e808SPierre Jolivet Developer Note: 207916a05f60SBarry Smith In most places in the source code we currently assume that `PetscInt` addition does not overflow, this is obviously wrong but requires many more checks. 208016a05f60SBarry Smith `PetscIntSumError()` can be used to check for this situation. 20812f18eb33SBarry Smith 2082db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 20832f18eb33SBarry Smith @*/ 2084d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 2085d71ae5a4SJacob Faibussowitsch { 2086f3fa974cSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 20872f18eb33SBarry Smith 20882f18eb33SBarry Smith PetscFunctionBegin; 2089835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 2090835f2295SStefano Zampini if (result) *result = r; 2091835f2295SStefano Zampini #else 2092c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 2093835f2295SStefano Zampini #endif 2094f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 20951690c2aeSBarry Smith PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Product of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 2096f3fa974cSJacob Faibussowitsch } 20973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2098f91af8c7SBarry Smith } 2099f91af8c7SBarry Smith 2100f91af8c7SBarry Smith /*@C 2101f91af8c7SBarry Smith 210287497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 2103f91af8c7SBarry Smith 2104667f096bSBarry Smith Not Collective; No Fortran Support 2105f91af8c7SBarry Smith 2106d8d19677SJose E. Roman Input Parameters: 210787497f52SBarry Smith + a - the `PetscInt` value 2108f91af8c7SBarry Smith - b - the second value 2109f91af8c7SBarry Smith 2110d8d19677SJose E. Roman Output Parameter: 211116a05f60SBarry 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 2112f91af8c7SBarry Smith 2113f91af8c7SBarry Smith Level: advanced 2114f91af8c7SBarry Smith 2115667f096bSBarry Smith Notes: 21167de69702SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64` 2117667f096bSBarry Smith 2118667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2119667f096bSBarry Smith 2120db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2121f91af8c7SBarry Smith @*/ 2122d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 2123d71ae5a4SJacob Faibussowitsch { 2124835f2295SStefano Zampini PetscInt64 r = a; 2125f91af8c7SBarry Smith 2126f91af8c7SBarry Smith PetscFunctionBegin; 2127835f2295SStefano Zampini r += b; 2128835f2295SStefano Zampini #if defined(PETSC_USE_64BIT_INDICES) 2129835f2295SStefano Zampini if (result) *result = r; 2130835f2295SStefano Zampini #else 2131c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 2132835f2295SStefano Zampini #endif 2133f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 21341690c2aeSBarry Smith PetscCheck(r <= PETSC_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_SUP, "Sum of two integers %" PetscInt_FMT " %" PetscInt_FMT " overflow, either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-indices for the case you are running", a, b); 2135f3fa974cSJacob Faibussowitsch } 21363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 21372f18eb33SBarry Smith } 2138c5df96a5SBarry Smith 2139d382aafbSBarry Smith /* 21402981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2141d382aafbSBarry Smith */ 2142d382aafbSBarry Smith #if defined(hz) 2143d382aafbSBarry Smith #undef hz 2144d382aafbSBarry Smith #endif 2145d382aafbSBarry Smith 2146d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2147d382aafbSBarry Smith #include <sys/types.h> 2148d382aafbSBarry Smith #endif 2149d382aafbSBarry Smith 2150d382aafbSBarry Smith /*MC 2151d382aafbSBarry Smith 215266d79e26SBarry 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++ 215316a05f60SBarry Smith and Fortran compilers when `petscsys.h` is included. 215466d79e26SBarry Smith 2155baca6076SPierre Jolivet The current PETSc version and the API for accessing it are defined in <A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscversion.h.html">include/petscversion.html</A> 215666d79e26SBarry Smith 215766d79e26SBarry 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) 215866d79e26SBarry Smith 215966d79e26SBarry 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 216066d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 216166d79e26SBarry Smith 216266d79e26SBarry 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 216366d79e26SBarry Smith 216466d79e26SBarry 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), 216566d79e26SBarry 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 216666d79e26SBarry Smith version number (x.y.z). 216766d79e26SBarry Smith 216887497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 216966d79e26SBarry Smith 217087497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 217166d79e26SBarry Smith 217287497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 217366d79e26SBarry Smith 217487497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 217566d79e26SBarry Smith 217687497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 217766d79e26SBarry Smith 2178cbc12506SBarry Smith Level: intermediate 217966d79e26SBarry Smith M*/ 218066d79e26SBarry Smith 2181014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 2182014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 2183014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 2184014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 2185014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2186014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 218727710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 21885f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 2189d382aafbSBarry Smith 21906497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscCount, const PetscInt[], PetscBool *); 21916497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscCount, const PetscInt64[], PetscBool *); 21926497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscCount, const PetscMPIInt[], PetscBool *); 21936497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscCount, const PetscReal[], PetscBool *); 21946497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt(PetscCount, PetscInt[]); 21956497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscCount, PetscInt64[]); 21966497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortCount(PetscCount, PetscCount[]); 21976497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscCount, PetscInt[]); 219822ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 21996497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscCount, const PetscInt[], PetscBool *); 2200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2201f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 22026497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscCount, const PetscInt[], PetscInt *); 22036497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscCount, const PetscMPIInt[], PetscInt *); 2204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 22066497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscCount, PetscInt[], PetscInt[]); 2207981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 22086497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithMPIIntArray(PetscCount, PetscInt[], PetscMPIInt[]); 22096497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscCount, PetscInt[], PetscInt[], PetscInt[]); 2210981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 22116497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscCount, PetscMPIInt[]); 221217d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 22136497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscCount, PetscMPIInt[], PetscMPIInt[]); 22146497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscCount, PetscMPIInt[], PetscInt[]); 22156497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscCount, PetscInt[], PetscScalar[]); 22166497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscCount, PetscInt[], void *, size_t, void *); 22176497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReal(PetscCount, PetscReal[]); 22186497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscCount, PetscReal[], PetscInt[]); 2219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2220745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 22216497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscCount, const PetscReal[], PetscReal, PetscInt *); 2222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2223014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2224014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 22256c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 22266c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2227e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2228ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2229ce605777SToby Isaac 22304d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2231676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2232676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2233676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 22344d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2235676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2236676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2237676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2238676f2a66SJacob Faibussowitsch 2239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2241d382aafbSBarry Smith 224276bdecfbSBarry Smith /*J 2243d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2244d382aafbSBarry Smith 2245d382aafbSBarry Smith Level: beginner 2246d382aafbSBarry Smith 2247667f096bSBarry Smith Note: 224887497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 224916a05f60SBarry Smith with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc. 2250d382aafbSBarry Smith 2251db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 225276bdecfbSBarry Smith J*/ 225319fd82e9SBarry Smith typedef const char *PetscRandomType; 2254d382aafbSBarry Smith #define PETSCRAND "rand" 2255d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2256d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2257c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 225825ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2259808ba619SStefano Zampini #define PETSCCURAND "curand" 2260d382aafbSBarry Smith 2261d382aafbSBarry Smith /* Logging support */ 2262014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2263d382aafbSBarry Smith 2264607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 22654bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void); 2266d382aafbSBarry Smith 2267d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2268140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2269d382aafbSBarry Smith 2270bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 227119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 227244ffe595SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomSetOptionsPrefix(PetscRandom, const char[]); 2273014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 227419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2275fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2277d382aafbSBarry Smith 2278014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2279014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2280014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2281808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2282808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2283014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2289d382aafbSBarry Smith 2290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 229797540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 22988a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 229997540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2300d382aafbSBarry Smith 2301d598313aSBarry Smith /*MC 2302d598313aSBarry Smith PetscBinaryBigEndian - indicates if values in memory are stored with big endian format 2303d598313aSBarry Smith 2304d598313aSBarry Smith Synopsis: 2305d598313aSBarry Smith #include <petscsys.h> 2306d598313aSBarry Smith PetscBool PetscBinaryBigEndian(void); 2307d598313aSBarry Smith 2308d598313aSBarry Smith No Fortran Support 2309d598313aSBarry Smith 2310d598313aSBarry Smith Level: developer 2311d598313aSBarry Smith 2312d598313aSBarry Smith .seealso: `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled` 2313d598313aSBarry Smith M*/ 2314d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2315d71ae5a4SJacob Faibussowitsch { 23169371c9d4SSatish Balay long _petsc_v = 1; 23179371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 23189371c9d4SSatish Balay } 231930815ce0SLisandro Dalcin 23206497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscCount, PetscInt *, PetscDataType); 23219860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 23226497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscCount, PetscDataType); 2323f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2325014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2327014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2328014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2329014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2330014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2331c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2332e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2333c891a504SStefano Zampini #endif 2334d382aafbSBarry Smith 2335014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2336014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 23376497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscCount); 2338d382aafbSBarry Smith 2339014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2340014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2343014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2344014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 23452a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2346d382aafbSBarry Smith 2347014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2348014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2349014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2350014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2351014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 235293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt *, const void *, PetscMPIInt *, PetscMPIInt **, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 235393d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 235493d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm, PetscMPIInt, MPI_Datatype, PetscMPIInt, const PetscMPIInt[], const void *, PetscMPIInt *, PetscMPIInt **, void *, PetscMPIInt, MPI_Request **, MPI_Request **, PetscErrorCode (*send)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, PetscMPIInt, void *, MPI_Request[], void *), PetscErrorCode (*recv)(MPI_Comm, const PetscMPIInt[], PetscMPIInt, void *, MPI_Request[], void *), void *ctx) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 3); 2355d382aafbSBarry Smith 23566145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 23576145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 23586145cd65SJed Brown 2359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2360d382aafbSBarry Smith 2361ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2362ce94432eSBarry Smith 2363d382aafbSBarry Smith struct _n_PetscSubcomm { 2364d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2365d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2366306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 236745487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 236845487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2369708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 237045487dadSJed Brown PetscSubcommType type; 2371e5acf8a4SHong Zhang char *subcommprefix; 2372d382aafbSBarry Smith }; 2373d382aafbSBarry Smith 2374d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2375d71ae5a4SJacob Faibussowitsch { 23769371c9d4SSatish Balay return scomm->parent; 23779371c9d4SSatish Balay } 2378d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2379d71ae5a4SJacob Faibussowitsch { 23809371c9d4SSatish Balay return scomm->child; 23819371c9d4SSatish Balay } 2382d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2383d71ae5a4SJacob Faibussowitsch { 23849371c9d4SSatish Balay return scomm->dupparent; 23859371c9d4SSatish Balay } 2386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 239065d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2391053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2392f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2393e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2394a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2395a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2396a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2397d382aafbSBarry Smith 23989962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 23999962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 24009962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 24019962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 24029962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 24039962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 24049962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 24059962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 24069962606eSBarry Smith 24075e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 24085f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 24095f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 24105f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 24115f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 24125e71baefSBarry Smith 2413a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2414a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2415a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2416a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2417a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2418a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2419a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2420a32e93adSJunchao Zhang 24216497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, PetscCount, PetscSegBuffer *); 24220f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 24236497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, PetscCount, void *); 2424137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2425137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2426137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 24276497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, PetscCount *); 24286497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, PetscCount); 24290f453b92SJed Brown 2430d598313aSBarry Smith /*MC 2431d598313aSBarry Smith PetscSegBufferGetInts - access an array of `PetscInt` from a `PetscSegBuffer` 2432d598313aSBarry Smith 2433d598313aSBarry Smith Synopsis: 2434d598313aSBarry Smith #include <petscsys.h> 2435d598313aSBarry Smith PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot); 2436d598313aSBarry Smith 2437d598313aSBarry Smith No Fortran Support 2438d598313aSBarry Smith 2439d598313aSBarry Smith Input Parameters: 2440d598313aSBarry Smith + seg - `PetscSegBuffer` buffer 2441d598313aSBarry Smith - count - number of entries needed 2442d598313aSBarry Smith 2443d598313aSBarry Smith Output Parameter: 2444d598313aSBarry Smith . buf - address of new buffer for contiguous data 2445d598313aSBarry Smith 2446d598313aSBarry Smith Level: intermediate 2447d598313aSBarry Smith 2448d598313aSBarry Smith Developer Note: 2449d598313aSBarry Smith Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2450d598313aSBarry Smith prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2451d598313aSBarry Smith possible. 2452d598313aSBarry Smith 2453d598313aSBarry Smith .seealso: `PetscSegBuffer`, `PetscSegBufferGet()`, `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled` 2454d598313aSBarry Smith M*/ 2455d598313aSBarry Smith /* */ 24566497c311SBarry Smith static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, PetscCount count, PetscInt *PETSC_RESTRICT *slot) 2457d71ae5a4SJacob Faibussowitsch { 24589371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 24599371c9d4SSatish Balay } 2460d382aafbSBarry Smith 24619de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 24629de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 24639de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 24649de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 24659de0f6ecSBarry Smith 2466ace2fbaeSBarry Smith #include <stdarg.h> 2467ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2468ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2469ace2fbaeSBarry Smith 2470268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2471fbfcfee5SBarry Smith 24725d83a8b1SBarry Smith /*@ 24731f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 24741f817a21SBarry Smith 2475667f096bSBarry Smith Not Collective; No Fortran Support 24761f817a21SBarry Smith 24771f817a21SBarry Smith Input Parameters: 247835cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely 247987497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 24801f817a21SBarry Smith 2481667f096bSBarry Smith Options Database Key: 24823c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation 24833c7db156SBarry Smith 2484850545d0SSatish Balay Level: intermediate 24851f817a21SBarry Smith @*/ 2486d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2487d71ae5a4SJacob Faibussowitsch { 2488dff31646SBarry Smith size_t len; 2489dff31646SBarry Smith char *vstring; 2490dff31646SBarry Smith 24911f817a21SBarry Smith PetscFunctionBegin; 24923ba16761SJacob Faibussowitsch if (set && *set) PetscFunctionReturn(PETSC_SUCCESS); 24939566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 249435d731d1SLisandro Dalcin PetscCall(PetscSegBufferGet(PetscCitationsList, (PetscCount)len, &vstring)); 24959566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2496dff31646SBarry Smith if (set) *set = PETSC_TRUE; 24973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2498dff31646SBarry Smith } 2499dff31646SBarry Smith 2500fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2501fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2502f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2503fe278a28SBarry Smith 2504f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2505f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 25064bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]); 2507b967cddfSBarry Smith 25089f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 25094bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t); 25104bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]); 25119f4d3c52SBarry Smith 251268e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 25135dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2514dff31646SBarry Smith 25156497c311SBarry Smith #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 25166497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 25176497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 25186497c311SBarry Smith #endif 25196497c311SBarry Smith 25206497c311SBarry Smith #if !defined(PETSC_HAVE_MPI_LARGE_COUNT) 2521462c564dSBarry Smith /* 2522462c564dSBarry Smith Cast PetscCount <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines. 25236497c311SBarry Smith It is similar to PetscMPIIntCast() except that here it returns an MPI error code. 25246497c311SBarry Smith */ 2525462c564dSBarry Smith #define PetscMPIIntCast_Internal(a, b) \ 2526462c564dSBarry Smith do { \ 2527462c564dSBarry Smith *b = 0; \ 2528462c564dSBarry Smith if (PetscUnlikely(a > (MPIU_Count)PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT; \ 2529462c564dSBarry Smith *b = (PetscMPIInt)a; \ 2530462c564dSBarry Smith } while (0) 25316497c311SBarry Smith 25326497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count) 25336497c311SBarry Smith { 2534462c564dSBarry Smith PetscMPIInt count2, err; 25356497c311SBarry Smith 25366497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */ 2537462c564dSBarry Smith err = MPI_Get_count(status, dtype, &count2); 25386497c311SBarry Smith *count = count2; 2539462c564dSBarry Smith return err; 25406497c311SBarry Smith } 25416497c311SBarry Smith 2542462c564dSBarry Smith static inline PetscMPIInt MPIU_Send(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm) 25436497c311SBarry Smith { 2544462c564dSBarry Smith PetscMPIInt count2, err; 25456497c311SBarry Smith 2546462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2547462c564dSBarry Smith err = MPI_Send((void *)buf, count2, dtype, dest, tag, comm); 2548462c564dSBarry Smith return err; 25496497c311SBarry Smith } 25506497c311SBarry Smith 2551462c564dSBarry Smith static inline PetscMPIInt MPIU_Send_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request) 25526497c311SBarry Smith { 2553462c564dSBarry Smith PetscMPIInt count2, err; 25546497c311SBarry Smith 2555462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2556462c564dSBarry Smith err = MPI_Send_init((void *)buf, count2, dtype, dest, tag, comm, request); 2557462c564dSBarry Smith return err; 25586497c311SBarry Smith } 25596497c311SBarry Smith 2560462c564dSBarry Smith static inline PetscMPIInt MPIU_Isend(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request) 25616497c311SBarry Smith { 2562462c564dSBarry Smith PetscMPIInt count2, err; 25636497c311SBarry Smith 2564462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2565462c564dSBarry Smith err = MPI_Isend((void *)buf, count2, dtype, dest, tag, comm, request); 2566462c564dSBarry Smith return err; 25676497c311SBarry Smith } 25686497c311SBarry Smith 2569462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Status *status) 25706497c311SBarry Smith { 2571462c564dSBarry Smith PetscMPIInt count2, err; 25726497c311SBarry Smith 2573462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2574462c564dSBarry Smith err = MPI_Recv((void *)buf, count2, dtype, source, tag, comm, status); 2575462c564dSBarry Smith return err; 25766497c311SBarry Smith } 25776497c311SBarry Smith 2578462c564dSBarry Smith static inline PetscMPIInt MPIU_Recv_init(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request) 25796497c311SBarry Smith { 2580462c564dSBarry Smith PetscMPIInt count2, err; 25816497c311SBarry Smith 2582462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2583462c564dSBarry Smith err = MPI_Recv_init((void *)buf, count2, dtype, source, tag, comm, request); 2584462c564dSBarry Smith return err; 25856497c311SBarry Smith } 25866497c311SBarry Smith 2587462c564dSBarry Smith static inline PetscMPIInt MPIU_Irecv(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request) 25886497c311SBarry Smith { 2589462c564dSBarry Smith PetscMPIInt count2, err; 25906497c311SBarry Smith 2591462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2592462c564dSBarry Smith err = MPI_Irecv((void *)buf, count2, dtype, source, tag, comm, request); 2593462c564dSBarry Smith return err; 25946497c311SBarry Smith } 25956497c311SBarry Smith 2596462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce(const void *inbuf, void *outbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op, PetscMPIInt root, MPI_Comm comm) 25976497c311SBarry Smith { 2598462c564dSBarry Smith PetscMPIInt count2, err; 25996497c311SBarry Smith 2600462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2601462c564dSBarry Smith err = MPI_Reduce((void *)inbuf, outbuf, count2, dtype, op, root, comm); 2602462c564dSBarry Smith return err; 26036497c311SBarry Smith } 26046497c311SBarry Smith 26056497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL) 2606462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op) 26076497c311SBarry Smith { 2608462c564dSBarry Smith PetscMPIInt count2, err; 26096497c311SBarry Smith 2610462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2611462c564dSBarry Smith err = MPI_Reduce_local((void *)inbuf, inoutbuf, count2, dtype, op); 2612462c564dSBarry Smith return err; 26136497c311SBarry Smith } 26146497c311SBarry Smith #endif 26156497c311SBarry Smith 26163fa2bd1cSBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 26173fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) 26183fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) 26193fa2bd1cSBarry Smith #else 26203fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \ 2621*bc8457a1SJose E. Roman ((PetscMPIInt)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT) 26223fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \ 2623*bc8457a1SJose E. Roman ((PetscMPIInt)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_SUP, PETSC_ERROR_INITIAL, "Must have MPI 4 support for MPI_Scatterv_c() for this functionality, upgrade your MPI"), MPI_ERR_COUNT) 26243fa2bd1cSBarry Smith #endif 26253fa2bd1cSBarry Smith 26266497c311SBarry Smith #else 26276497c311SBarry Smith 26286497c311SBarry Smith /* on 32 bit systems MPI_Count maybe 64-bit while PetscCount is 32-bit */ 2629462c564dSBarry Smith #define PetscCountCast_Internal(a, b) \ 2630462c564dSBarry Smith do { \ 2631462c564dSBarry Smith *b = 0; \ 2632462c564dSBarry Smith if (PetscUnlikely(a > (MPI_Count)PETSC_COUNT_MAX)) return MPI_ERR_COUNT; \ 2633462c564dSBarry Smith *b = (PetscMPIInt)a; \ 2634462c564dSBarry Smith } while (0) 26356497c311SBarry Smith 26366497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count) 26376497c311SBarry Smith { 26386497c311SBarry Smith MPI_Count count2; 2639462c564dSBarry Smith PetscMPIInt err; 26406497c311SBarry Smith 26416497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */ 2642462c564dSBarry Smith err = MPI_Get_count_c(status, dtype, &count2); 2643462c564dSBarry Smith if (err) return err; 2644462c564dSBarry Smith PetscCountCast_Internal(count2, count); 2645462c564dSBarry Smith return MPI_SUCCESS; 26466497c311SBarry Smith } 26476497c311SBarry Smith 26486497c311SBarry Smith #define MPIU_Reduce(inbuf, outbuf, count, dtype, op, root, comm) MPI_Reduce_c(inbuf, outbuf, (MPI_Count)(count), dtype, op, root, comm) 26496497c311SBarry Smith #define MPIU_Send(buf, count, dtype, dest, tag, comm) MPI_Send_c(buf, (MPI_Count)(count), dtype, dest, tag, comm) 26506497c311SBarry Smith #define MPIU_Send_init(buf, count, dtype, dest, tag, comm, request) MPI_Send_init_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request) 26516497c311SBarry Smith #define MPIU_Isend(buf, count, dtype, dest, tag, comm, request) MPI_Isend_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request) 26526497c311SBarry Smith #define MPIU_Recv(buf, count, dtype, source, tag, comm, status) MPI_Recv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, status) 26536497c311SBarry Smith #define MPIU_Recv_init(buf, count, dtype, source, tag, comm, request) MPI_Recv_init_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request) 26546497c311SBarry Smith #define MPIU_Irecv(buf, count, dtype, source, tag, comm, request) MPI_Irecv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request) 26556497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL) 26566a210b70SBarry Smith #define MPIU_Reduce_local(inbuf, inoutbuf, count, dtype, op) MPI_Reduce_local_c(inbuf, inoutbuf, (MPI_Count)(count), dtype, op) 26576497c311SBarry Smith #endif 26583fa2bd1cSBarry Smith 26593fa2bd1cSBarry Smith /*MC 26603fa2bd1cSBarry Smith MPIU_Scatterv - A replacement for `MPI_Scatterv()` that can be called with `PetscInt` types when PETSc is built for either 32-bit indices or 64-bit indices. 26613fa2bd1cSBarry Smith 26623fa2bd1cSBarry Smith Synopsis: 26633fa2bd1cSBarry Smith #include <petscsys.h> 26643fa2bd1cSBarry Smith PetscMPIInt MPIU_Scatterv(const void *sendbuf, const PetscInt sendcounts[], const PetscInt displs[], MPI_Datatype sendtype, void *recvbuf, PetscInt recvcount, MPI_Datatype recvtype, PetscMPIInt root, MPI_Comm comm) 26653fa2bd1cSBarry Smith 26663fa2bd1cSBarry Smith Collective 26673fa2bd1cSBarry Smith 26683fa2bd1cSBarry Smith Input Parameters: 26693fa2bd1cSBarry Smith + sendbuf - address of send buffer 26703fa2bd1cSBarry Smith . sendcounts - non-negative `PetscInt` array (of length `comm` group size) specifying the number of elements to send to each MPI process 26713fa2bd1cSBarry Smith . displs - `PetscInt` array (of length `comm` group size). Entry i specifies the displacement (relative to `sendbuf`) from which to take the outgoing data to process i 26723fa2bd1cSBarry Smith . sendtype - data type of `sendbuf` elements 26733fa2bd1cSBarry Smith . recvcount - number of elements in `recvbuf` (non-negative integer) 26743fa2bd1cSBarry Smith . recvtype - data type of `recvbuf` elements 26753fa2bd1cSBarry Smith . root - Rank of the MPI root process, which will dispatch the data to scatter 26763fa2bd1cSBarry Smith - comm - `MPI_Comm` communicator 26773fa2bd1cSBarry Smith 26783fa2bd1cSBarry Smith Output Parameter: 26793fa2bd1cSBarry Smith . recvbuf - the resulting scattered values on this MPI process 26803fa2bd1cSBarry Smith 26813fa2bd1cSBarry Smith Level: developer 26823fa2bd1cSBarry Smith 26833fa2bd1cSBarry Smith Notes: 26843fa2bd1cSBarry Smith Should be wrapped with `PetscCallMPI()` for error checking 26853fa2bd1cSBarry Smith 26863fa2bd1cSBarry Smith This is different than most of the `MPIU_` wrappers in that all the count arguments are in `PetscInt` 26873fa2bd1cSBarry Smith 26883fa2bd1cSBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()`, `MPIU_Gatherv()` 26893fa2bd1cSBarry Smith M*/ 26903fa2bd1cSBarry Smith 26913fa2bd1cSBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 26923fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) 26933fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) 26943fa2bd1cSBarry Smith #else 26953fa2bd1cSBarry Smith #define MPIU_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) MPI_Scatterv_c(sendbuf, (const MPI_Count *)(sendcounts), (const MPI_Aint *)(displs), sendtype, recvbuf, recvcount, recvtype, root, comm) 26963fa2bd1cSBarry Smith #define MPIU_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) MPI_Gatherv_c(sendbuf, sendcount, sendtype, recvbuf, (const MPI_Count *)(recvcounts), (const MPI_Aint *)(displs), recvtype, root, comm) 26973fa2bd1cSBarry Smith #endif 26983fa2bd1cSBarry Smith 26996497c311SBarry Smith #endif 27006497c311SBarry Smith 2701462c564dSBarry Smith PETSC_EXTERN PetscMPIInt MPIU_Allreduce_Private(const void *, void *, MPIU_Count, MPI_Datatype, MPI_Op, MPI_Comm); 27026a210b70SBarry Smith 2703b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2704d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2705d71ae5a4SJacob Faibussowitsch { 2706df05ca09SBarry Smith unsigned int c, hash = 5381; 2707df05ca09SBarry Smith 2708503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2709df05ca09SBarry Smith return hash; 2710df05ca09SBarry Smith } 27116497c311SBarry Smith #endif 271277a5e07dSBarry Smith 271377a5e07dSBarry Smith /*MC 2714462c564dSBarry Smith MPIU_Allreduce - A replacement for `MPI_Allreduce()` that (1) performs single-count `MPIU_INT` operations in `PetscInt64` to detect 2715462c564dSBarry Smith integer overflows and (2) tries to determine if the call from all the MPI ranks occur in the 271687497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 271787497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 271877a5e07dSBarry Smith 271977a5e07dSBarry Smith Synopsis: 272077a5e07dSBarry Smith #include <petscsys.h> 2721462c564dSBarry Smith PetscMPIInt MPIU_Allreduce(void *indata,void *outdata,PetscCount count,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm); 272277a5e07dSBarry Smith 27237cdbe19fSJose E. Roman Collective 27247cdbe19fSJose E. Roman 272577a5e07dSBarry Smith Input Parameters: 27266a210b70SBarry Smith + a - pointer to the input data to be reduced 27276a210b70SBarry Smith . count - the number of MPI data items in `a` and `b` 27286497c311SBarry Smith . dtype - the MPI datatype, for example `MPI_INT` 27296497c311SBarry Smith . op - the MPI operation, for example `MPI_SUM` 27306497c311SBarry Smith - comm - the MPI communicator on which the operation occurs 273177a5e07dSBarry Smith 273277a5e07dSBarry Smith Output Parameter: 27336a210b70SBarry Smith . b - the reduced values 273477a5e07dSBarry Smith 2735667f096bSBarry Smith Level: developer 2736667f096bSBarry Smith 2737462c564dSBarry Smith Note: 2738462c564dSBarry Smith Should be wrapped with `PetscCallMPI()` for error checking 2739462c564dSBarry Smith 27406497c311SBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()` 274177a5e07dSBarry Smith M*/ 27426497c311SBarry Smith #if defined(PETSC_USE_DEBUG) 27439371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 27443ba16761SJacob Faibussowitsch PetscMacroReturnStandard( \ 27453ba16761SJacob Faibussowitsch PetscMPIInt a_b1[6], a_b2[6]; \ 27463ba16761SJacob Faibussowitsch int _mpiu_allreduce_c_int = (int)(c); \ 27473ba16761SJacob Faibussowitsch a_b1[0] = -(PetscMPIInt)__LINE__; \ 27483ba16761SJacob Faibussowitsch a_b1[1] = -a_b1[0]; \ 27493ba16761SJacob Faibussowitsch a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \ 27503ba16761SJacob Faibussowitsch a_b1[3] = -a_b1[2]; \ 27513ba16761SJacob Faibussowitsch a_b1[4] = -(PetscMPIInt)(c); \ 27523ba16761SJacob Faibussowitsch a_b1[5] = -a_b1[4]; \ 27533ba16761SJacob Faibussowitsch \ 27543ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \ 2755462c564dSBarry Smith PetscCheck(-a_b2[0] == a_b2[1], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (code lines) on different processors"); \ 2756462c564dSBarry Smith PetscCheck(-a_b2[2] == a_b2[3], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (functions) on different processors"); \ 2757462c564dSBarry Smith PetscCheck(-a_b2[4] == a_b2[5], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); \ 27586a210b70SBarry Smith PetscCallMPI(MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)));) 2759b2566f29SBarry Smith #else 2760462c564dSBarry Smith #define MPIU_Allreduce(a, b, c, d, e, fcomm) MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)) 2761b2566f29SBarry Smith #endif 2762b2566f29SBarry Smith 2763b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 27648198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 27658198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 27662f065d89SBarry Smith #endif 27678198064fSBarry Smith 2768cd88fca5SStefano Zampini /* this is a vile hack */ 2769cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 27709371c9d4SSatish Balay #if !defined(PETSC_NECMPI_VERSION_MAJOR) || !defined(PETSC_NECMPI_VERSION_MINOR) || PETSC_NECMPI_VERSION_MAJOR < 2 || (PETSC_NECMPI_VERSION_MAJOR == 2 && PETSC_NECMPI_VERSION_MINOR < 18) 2771cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2772cd88fca5SStefano Zampini #endif 2773961fb248SStefano Zampini #endif 2774cd88fca5SStefano Zampini 277512801b39SBarry Smith /* 277660fbe2beSVaclav Hapla List of external packages and queries on it 277760fbe2beSVaclav Hapla */ 277860fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 277960fbe2beSVaclav Hapla 2780f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2781f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2782f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 27837a99bfcaSBarry Smith PETSC_EXTERN PetscBool PCMPIServerActive; 27849f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerInSolve; 27859f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerUseShmget; 27869f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAllocateArray(size_t, size_t, void **); 27879f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetDeallocateArray(void **); 27889f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetMapAddresses(MPI_Comm, PetscInt, const void **, void **); 27899f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetUnmapAddresses(PetscInt, void **); 27909f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAddressesFinalize(void); 27919f0612e4SBarry Smith 27929f0612e4SBarry Smith typedef struct { 27939f0612e4SBarry Smith PetscInt n; 27949f0612e4SBarry Smith void *addr[3]; 27959f0612e4SBarry Smith } PCMPIServerAddresses; 279649abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PCMPIServerAddressesDestroy; 2797fbf9dbe5SBarry Smith 2798edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS 2799046ed546SBarry Smith 2800046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt); 2801046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *); 28028e3a54c0SPierre Jolivet 28038e3a54c0SPierre Jolivet /*MC 28048e3a54c0SPierre Jolivet PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset 28058e3a54c0SPierre Jolivet 28068e3a54c0SPierre Jolivet Level: beginner 28078e3a54c0SPierre Jolivet 28088e3a54c0SPierre Jolivet Note: 28098e3a54c0SPierre Jolivet This is needed to avoid errors with undefined-behavior sanitizers such as 28108e3a54c0SPierre Jolivet UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags 28118e3a54c0SPierre Jolivet M*/ 28128e3a54c0SPierre Jolivet #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL) 2813