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 74a7886beaSBarry Smith */ 75a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 766524c165SJacob Faibussowitsch #ifndef MPIUNI_H 77a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 78a7886beaSBarry Smith #endif 790f85934cSJunchao Zhang #elif defined(PETSC_HAVE_I_MPI) 8041f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 8141f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 820f85934cSJunchao Zhang #elif I_MPI_NUMVERSION != PETSC_PKG_I_MPI_NUMVERSION 8341f4af4cSSatish Balay #error "PETSc was configured with one I_MPI mpi.h version but now appears to be compiling using a different I_MPI mpi.h version" 8441f4af4cSSatish Balay #endif 850f85934cSJunchao Zhang #elif defined(PETSC_HAVE_MVAPICH2) 8641f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8741f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 880f85934cSJunchao Zhang #elif MVAPICH2_NUMVERSION != PETSC_PKG_MVAPICH2_NUMVERSION 8941f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 9041f4af4cSSatish Balay #endif 91e3c15826SJunchao Zhang #elif defined(PETSC_HAVE_MPICH) 9241f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 93a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 94e3c15826SJunchao Zhang #elif !PETSC_PKG_MPICH_VERSION_EQ(MPICH_NUMVERSION / 10000000, MPICH_NUMVERSION / 100000 % 100, MPICH_NUMVERSION / 1000 % 100) 95a7886beaSBarry Smith #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 96a7886beaSBarry Smith #endif 97100ffedbSJunchao Zhang #elif defined(PETSC_HAVE_OPENMPI) 98a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 99a7886beaSBarry Smith #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h" 100100ffedbSJunchao Zhang #elif !PETSC_PKG_OPENMPI_VERSION_EQ(OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION) 101c3ac57cfSSatish Balay #error "PETSc was configured with one Open MPI mpi.h version but now appears to be compiling using a different Open MPI mpi.h version" 102a7886beaSBarry Smith #endif 103d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 104d97fd468SStefano Zampini #if !defined(MSMPI_VER) 105d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 106d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 107d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 108d97fd468SStefano Zampini #endif 109d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 110d97fd468SStefano Zampini #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of Open MPI, MS-MPI or a MPICH variant" 111a7886beaSBarry Smith #endif 112a7886beaSBarry Smith 113a7886beaSBarry Smith /* 1142981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 115d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 116d382aafbSBarry Smith */ 117d382aafbSBarry Smith #include <stdio.h> 118d382aafbSBarry Smith 1197de69702SBarry Smith /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */ 120d382aafbSBarry Smith #if !defined(MPIAPI) 121d382aafbSBarry Smith #define MPIAPI 122d382aafbSBarry Smith #endif 123d382aafbSBarry Smith 12493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 12593d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 126e28ce29aSPatrick Sanan 127e28ce29aSPatrick Sanan /*MC 12887497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 129e28ce29aSPatrick Sanan 130667f096bSBarry Smith Level: beginner 131667f096bSBarry Smith 13238b83642SBarry Smith Note: 13387497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 134e28ce29aSPatrick Sanan 13538b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 136e28ce29aSPatrick Sanan M*/ 137e28ce29aSPatrick Sanan 1387cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 139b7b8f77aSBarry Smith 140d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 141bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 142d382aafbSBarry Smith #else 143d382aafbSBarry Smith #define MPIU_INT MPI_INT 144d382aafbSBarry Smith #endif 145d382aafbSBarry Smith 14638b83642SBarry Smith /*MC 14738b83642SBarry Smith MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount` 14838b83642SBarry Smith 14938b83642SBarry Smith Level: beginner 15038b83642SBarry Smith 15138b83642SBarry Smith Note: 15238b83642SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value. 15338b83642SBarry Smith 15438b83642SBarry Smith Developer Note: 15595bd0b28SBarry Smith It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed 15638b83642SBarry Smith 15738b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 15838b83642SBarry Smith M*/ 15938b83642SBarry Smith #define MPIU_COUNT MPI_AINT 16038b83642SBarry Smith 161503cfb0cSBarry Smith /* 162503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 163503cfb0cSBarry Smith */ 16493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 165d382aafbSBarry Smith 166d382aafbSBarry Smith /* 167d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 168d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 169d382aafbSBarry Smith */ 170014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 171d382aafbSBarry Smith 172d382aafbSBarry Smith /* 173d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 174d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 175d382aafbSBarry Smith */ 176014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 177d382aafbSBarry Smith 178d382aafbSBarry Smith /* 179dc07da0dSStefano Zampini Handle inclusion when using clang compiler with CUDA support 180dc07da0dSStefano Zampini __float128 is not available for the device 181dc07da0dSStefano Zampini */ 182731341e5SJunchao Zhang #if defined(__clang__) && (defined(__CUDA_ARCH__) || defined(__HIPCC__)) 183dc07da0dSStefano Zampini #define PETSC_SKIP_REAL___FLOAT128 184dc07da0dSStefano Zampini #endif 185dc07da0dSStefano Zampini 186dc07da0dSStefano Zampini /* 187d382aafbSBarry Smith Declare extern C stuff after including external header files 188d382aafbSBarry Smith */ 189d382aafbSBarry Smith 1906edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 1918b49ba18SBarry Smith /* 192390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 1938b49ba18SBarry Smith */ 1948b49ba18SBarry Smith #include <petscmath.h> 1958b49ba18SBarry Smith 196d382aafbSBarry Smith /*MC 197667f096bSBarry Smith PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument 198d382aafbSBarry Smith 199d382aafbSBarry Smith Level: beginner 200d382aafbSBarry Smith 201e28ce29aSPatrick Sanan Note: 202667f096bSBarry Smith Accepted by many PETSc functions to not set a parameter and instead use a default value 203d382aafbSBarry Smith 20487497f52SBarry Smith Fortran Note: 205667f096bSBarry Smith Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 206d382aafbSBarry Smith 207db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 208d382aafbSBarry Smith M*/ 209f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR 210edd03b47SJacob Faibussowitsch #define PETSC_NULL PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR 211c528d872SBarry Smith 212d382aafbSBarry Smith /*MC 213b3480c81SBarry Smith PETSC_UNLIMITED - standard way of passing an integer or floating point parameter to indicate PETSc there is no bound on the value allowed 214557d4da8SBarry Smith 215557d4da8SBarry Smith Level: beginner 216557d4da8SBarry Smith 217b3480c81SBarry Smith Example Usage: 218b3480c81SBarry Smith .vb 219b3480c81SBarry Smith KSPSetTolerances(ksp, PETSC_CURRENT, PETSC_CURRENT, PETSC_UNLIMITED, PETSC_UNLIMITED); 220b3480c81SBarry Smith .ve 221b3480c81SBarry Smith indicates that the solver is allowed to take any number of iterations and will not stop early no matter how the residual gets. 222b3480c81SBarry Smith 223b3480c81SBarry Smith Fortran Note: 224b3480c81SBarry Smith Use `PETSC_UNLIMITED_INTEGER` or `PETSC_UNLIMITED_REAL`. 225b3480c81SBarry Smith 226b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DECIDE` 227557d4da8SBarry Smith M*/ 228557d4da8SBarry Smith 229557d4da8SBarry Smith /*MC 230b3480c81SBarry Smith PETSC_DECIDE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value 231d382aafbSBarry Smith 232d382aafbSBarry Smith Level: beginner 233d382aafbSBarry Smith 234b3480c81SBarry Smith Example Usage: 235b3480c81SBarry Smith .vb 236b3480c81SBarry Smith VecSetSizes(ksp, PETSC_DECIDE, 10); 237b3480c81SBarry Smith .ve 238b3480c81SBarry 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 239b3480c81SBarry Smith local sizes is the global size, see `PetscSplitOwnership()`. 240b3480c81SBarry Smith 241b3480c81SBarry Smith Fortran Note: 242b3480c81SBarry Smith Use `PETSC_DECIDE_INTEGER` or `PETSC_DECIDE_REAL`. 243b3480c81SBarry Smith 244b3480c81SBarry Smith .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_UNLIMITED' 245b3480c81SBarry Smith M*/ 246b3480c81SBarry Smith 247b3480c81SBarry Smith /*MC 248b3480c81SBarry Smith PETSC_DETERMINE - standard way of passing an integer or floating point parameter to indicate PETSc should determine an appropriate value 249b3480c81SBarry Smith 250b3480c81SBarry Smith Level: beginner 251b3480c81SBarry Smith 252b3480c81SBarry Smith Example Usage: 253b3480c81SBarry Smith .vb 254b3480c81SBarry Smith VecSetSizes(ksp, 10, PETSC_DETERMINE); 255b3480c81SBarry Smith .ve 256b3480c81SBarry Smith indicates that the local size of the vector is 10 and the global size will be automatically summing up all the local sizes. 257b3480c81SBarry Smith 258b3480c81SBarry Smith Note: 259b3480c81SBarry Smith Same as `PETSC_DECIDE` 260b3480c81SBarry Smith 261b3480c81SBarry Smith Fortran Note: 262b3480c81SBarry Smith Use `PETSC_DETERMINE_INTEGER` or `PETSC_DETERMINE_REAL`. 263b3480c81SBarry Smith 264e28ce29aSPatrick Sanan Developer Note: 26587497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 26687497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 267557d4da8SBarry Smith 268b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()`, `PETSC_UNLIMITED' 269d382aafbSBarry Smith M*/ 270d382aafbSBarry Smith 271d382aafbSBarry Smith /*MC 272b3480c81SBarry Smith PETSC_CURRENT - standard way of indicating to an object not to change the current value of the parameter in the object 273557d4da8SBarry Smith 274557d4da8SBarry Smith Level: beginner 275557d4da8SBarry Smith 276b3480c81SBarry Smith Note: 277b3480c81SBarry Smith Use `PETSC_DECIDE` to use the value that was set by PETSc when the object's type was set 278557d4da8SBarry Smith 279b3480c81SBarry Smith Fortran Note: 280b3480c81SBarry Smith Use `PETSC_CURRENT_INTEGER` or `PETSC_CURRENT_REAL`. 281b3480c81SBarry Smith 282b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_DEFAULT`, `PETSC_UNLIMITED' 283b3480c81SBarry Smith M*/ 284b3480c81SBarry Smith 285b3480c81SBarry Smith /*MC 286b3480c81SBarry Smith PETSC_DEFAULT - deprecated, see `PETSC_CURRENT` and `PETSC_DETERMINE` 287b3480c81SBarry Smith 288b3480c81SBarry Smith Level: beginner 289b3480c81SBarry Smith 290b3480c81SBarry Smith Note: 291b3480c81SBarry 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. 292b3480c81SBarry Smith 293b3480c81SBarry Smith Developer Note: 294b3480c81SBarry 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 295b3480c81SBarry Smith use of currently set value (in, for example, `KSPSetTolerances()`. 296b3480c81SBarry Smith 297b3480c81SBarry Smith .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE`, `PETSC_CURRENT`, `PETSC_UNLIMITED' 298557d4da8SBarry Smith M*/ 29905c2f48cSJacob Faibussowitsch 30005c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */ 30105c2f48cSJacob Faibussowitsch #define PETSC_DECIDE (-1) 30205c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE 303b3480c81SBarry Smith #define PETSC_CURRENT (-2) 304b3480c81SBarry Smith #define PETSC_UNLIMITED (-3) 305b3480c81SBarry Smith /* PETSC_DEFAULT is deprecated in favor of PETSC_CURRENT for use in KSPSetTolerances() and similar functions */ 306b3480c81SBarry Smith #define PETSC_DEFAULT PETSC_CURRENT 307557d4da8SBarry Smith 308557d4da8SBarry Smith /*MC 309af27ebaaSBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about. 310d382aafbSBarry Smith 311d382aafbSBarry Smith Level: beginner 312d382aafbSBarry Smith 313e28ce29aSPatrick Sanan Notes: 31487497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 31587497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 31687497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 317af27ebaaSBarry Smith `PetscInitialize()`, but after `MPI_Init()` has been called. 318a990b902SBarry Smith 319af27ebaaSBarry Smith The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()` 320a990b902SBarry Smith is called because it may not have a valid value yet. 321d382aafbSBarry Smith 322db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 323d382aafbSBarry Smith M*/ 324014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 325d382aafbSBarry Smith 326d382aafbSBarry Smith /*MC 32787497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 328d382aafbSBarry Smith 329d382aafbSBarry Smith Level: beginner 330d382aafbSBarry Smith 33195bd0b28SBarry Smith Note: 33216a05f60SBarry Smith Do not USE/access or set this variable before `PetscInitialize()` has been called. 333a990b902SBarry Smith 334db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 335d382aafbSBarry Smith M*/ 336d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 337d382aafbSBarry Smith 3386de5d289SStefano Zampini /*MC 339af27ebaaSBarry Smith PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`. 3406de5d289SStefano Zampini 341d598313aSBarry Smith No Fortran Support 342d598313aSBarry Smith 3436de5d289SStefano Zampini Level: beginner 3446de5d289SStefano Zampini 34595bd0b28SBarry Smith Note: 346d598313aSBarry 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` 3476de5d289SStefano Zampini 348db781477SPatrick Sanan .seealso: `PetscInitialize()` 3496de5d289SStefano Zampini M*/ 3506de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 3516de5d289SStefano Zampini 352d598313aSBarry Smith /*MC 353d598313aSBarry Smith PetscBeganMPI - indicates if PETSc initialized MPI during `PetscInitialize()` or if MPI was already initialized. 354d598313aSBarry Smith 355d598313aSBarry Smith Synopsis: 356d598313aSBarry Smith #include <petscsys.h> 357d598313aSBarry Smith PetscBool PetscBeganMPI; 358d598313aSBarry Smith 359d598313aSBarry Smith No Fortran Support 360d598313aSBarry Smith 361d598313aSBarry Smith Level: developer 362d598313aSBarry Smith 3630241b274SPierre Jolivet .seealso: `PetscInitialize()`, `PetscInitializeCalled` 364d598313aSBarry Smith M*/ 365d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 366d598313aSBarry Smith 3678ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 368014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 369014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 3704cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 371d382aafbSBarry Smith 372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 37557f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 37657f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 377d382aafbSBarry Smith 37859e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 37959e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 38059e55d94SJunchao Zhang #endif 38159e55d94SJunchao Zhang 38271438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 38371438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 38471438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 38571438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 38671438e86SJunchao Zhang #endif 38771438e86SJunchao Zhang 388540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 389540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 390540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 391540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 392540e20f2SPierre Jolivet #endif 393540e20f2SPierre Jolivet 394d382aafbSBarry Smith /*MC 39587497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 396d382aafbSBarry Smith 397eca87e8dSBarry Smith Synopsis: 398aaa7dc30SBarry Smith #include <petscsys.h> 399eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 400eca87e8dSBarry Smith 401eca87e8dSBarry Smith Not Collective 402eca87e8dSBarry Smith 403d382aafbSBarry Smith Input Parameter: 404d382aafbSBarry Smith . m - number of bytes to allocate 405d382aafbSBarry Smith 406d382aafbSBarry Smith Output Parameter: 407d382aafbSBarry Smith . result - memory allocated 408d382aafbSBarry Smith 409d382aafbSBarry Smith Level: beginner 410d382aafbSBarry Smith 41149d7da52SJed Brown Notes: 41249d7da52SJed Brown Memory is always allocated at least double aligned 413d382aafbSBarry Smith 41416a05f60SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 415d382aafbSBarry Smith 416db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 417d382aafbSBarry Smith M*/ 418071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 419d382aafbSBarry Smith 420d382aafbSBarry Smith /*MC 421d5b43468SJose E. Roman PetscRealloc - Reallocates memory 4223221ece2SMatthew G. Knepley 4233221ece2SMatthew G. Knepley Synopsis: 4243221ece2SMatthew G. Knepley #include <petscsys.h> 4253221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 4263221ece2SMatthew G. Knepley 4273221ece2SMatthew G. Knepley Not Collective 4283221ece2SMatthew G. Knepley 4293221ece2SMatthew G. Knepley Input Parameters: 4303221ece2SMatthew G. Knepley + m - number of bytes to allocate 43192f119d6SBarry Smith - result - previous memory 4323221ece2SMatthew G. Knepley 4333221ece2SMatthew G. Knepley Output Parameter: 4343221ece2SMatthew G. Knepley . result - new memory allocated 4353221ece2SMatthew G. Knepley 4363221ece2SMatthew G. Knepley Level: developer 4373221ece2SMatthew G. Knepley 43895bd0b28SBarry Smith Note: 4393221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 4403221ece2SMatthew G. Knepley 441db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 4423221ece2SMatthew G. Knepley M*/ 4433221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 4443221ece2SMatthew G. Knepley 4453221ece2SMatthew G. Knepley /*MC 44687497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 447d382aafbSBarry Smith 448d382aafbSBarry Smith Synopsis: 449aaa7dc30SBarry Smith #include <petscsys.h> 450d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 451d382aafbSBarry Smith 452eca87e8dSBarry Smith Not Collective 453eca87e8dSBarry Smith 4542fe279fdSBarry Smith Input Parameter: 455eca87e8dSBarry Smith . addr - address to align (any pointer type) 456eca87e8dSBarry Smith 457d382aafbSBarry Smith Level: developer 458d382aafbSBarry Smith 459db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 460d382aafbSBarry Smith M*/ 461f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))) 462d382aafbSBarry Smith 463d382aafbSBarry Smith /*MC 46487497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 4658f51dc47SJunchao Zhang 4668f51dc47SJunchao Zhang Synopsis: 4678f51dc47SJunchao Zhang #include <petscsys.h> 4688f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 4698f51dc47SJunchao Zhang 4708f51dc47SJunchao Zhang Not Collective 4718f51dc47SJunchao Zhang 4728f51dc47SJunchao Zhang Input Parameter: 4738f51dc47SJunchao Zhang . m - number of bytes to allocate 4748f51dc47SJunchao Zhang 4758f51dc47SJunchao Zhang Output Parameter: 4768f51dc47SJunchao Zhang . result - memory allocated 4778f51dc47SJunchao Zhang 4788f51dc47SJunchao Zhang Level: beginner 4798f51dc47SJunchao Zhang 4808f51dc47SJunchao Zhang Notes: 4818f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4828f51dc47SJunchao Zhang 48316a05f60SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 4848f51dc47SJunchao Zhang 485db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4868f51dc47SJunchao Zhang M*/ 487b67aa78dSSatish Balay #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result)) 4888f51dc47SJunchao Zhang 4898f51dc47SJunchao Zhang /*MC 49087497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 491d382aafbSBarry Smith 492eca87e8dSBarry Smith Synopsis: 493aaa7dc30SBarry Smith #include <petscsys.h> 494785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 495785e854fSJed Brown 496785e854fSJed Brown Not Collective 497785e854fSJed Brown 498785e854fSJed Brown Input Parameter: 499390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 500785e854fSJed Brown 501785e854fSJed Brown Output Parameter: 5021fe1b817SJunchao Zhang . r1 - memory allocated 503785e854fSJed Brown 50416a05f60SBarry Smith Level: beginner 50516a05f60SBarry Smith 506e28ce29aSPatrick Sanan Note: 507e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 50887497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 50916a05f60SBarry Smith .vb 51016a05f60SBarry Smith PetscInt *id; 51116a05f60SBarry Smith PetscMalloc1(10,&id); 51216a05f60SBarry Smith .ve 513390e1bf2SBarry Smith not 51416a05f60SBarry Smith .vb 51516a05f60SBarry Smith PetscInt *id; 51616a05f60SBarry Smith PetscMalloc1(10*sizeof(PetscInt),&id); 51716a05f60SBarry Smith .ve 518390e1bf2SBarry Smith 51987497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 520390e1bf2SBarry Smith 521db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 522785e854fSJed Brown M*/ 523b67aa78dSSatish Balay #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 524785e854fSJed Brown 525785e854fSJed Brown /*MC 52687497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 5271795a4d1SJed Brown 5281795a4d1SJed Brown Synopsis: 529aaa7dc30SBarry Smith #include <petscsys.h> 5301795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 5311795a4d1SJed Brown 5321795a4d1SJed Brown Not Collective 5331795a4d1SJed Brown 5341795a4d1SJed Brown Input Parameter: 5351795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 5361795a4d1SJed Brown 5371795a4d1SJed Brown Output Parameter: 5381fe1b817SJunchao Zhang . r1 - memory allocated 5391795a4d1SJed Brown 54016a05f60SBarry Smith Level: beginner 54116a05f60SBarry Smith 54295bd0b28SBarry Smith Note: 54387497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 544390e1bf2SBarry Smith 545db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 5461795a4d1SJed Brown M*/ 547b67aa78dSSatish Balay #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 5481795a4d1SJed Brown 5491795a4d1SJed Brown /*MC 55087497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 551d382aafbSBarry Smith 552eca87e8dSBarry Smith Synopsis: 553aaa7dc30SBarry Smith #include <petscsys.h> 554dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 555eca87e8dSBarry Smith 556eca87e8dSBarry Smith Not Collective 557eca87e8dSBarry Smith 558d8d19677SJose E. Roman Input Parameters: 559d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 560dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 561d382aafbSBarry Smith 562d8d19677SJose E. Roman Output Parameters: 563d382aafbSBarry Smith + r1 - memory allocated in first chunk 564d382aafbSBarry Smith - r2 - memory allocated in second chunk 565d382aafbSBarry Smith 566d382aafbSBarry Smith Level: developer 567d382aafbSBarry Smith 568db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 569d382aafbSBarry Smith M*/ 570b67aa78dSSatish 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)) 571d382aafbSBarry Smith 572d382aafbSBarry Smith /*MC 57387497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 574d382aafbSBarry Smith 575eca87e8dSBarry Smith Synopsis: 576aaa7dc30SBarry Smith #include <petscsys.h> 5771795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 578eca87e8dSBarry Smith 579eca87e8dSBarry Smith Not Collective 580eca87e8dSBarry Smith 581d8d19677SJose E. Roman Input Parameters: 582d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5831795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5841795a4d1SJed Brown 585d8d19677SJose E. Roman Output Parameters: 5861795a4d1SJed Brown + r1 - memory allocated in first chunk 5871795a4d1SJed Brown - r2 - memory allocated in second chunk 5881795a4d1SJed Brown 5891795a4d1SJed Brown Level: developer 5901795a4d1SJed Brown 591db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5921795a4d1SJed Brown M*/ 593b67aa78dSSatish 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)) 5941795a4d1SJed Brown 5951795a4d1SJed Brown /*MC 59687497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 597d382aafbSBarry Smith 598d382aafbSBarry Smith Synopsis: 599aaa7dc30SBarry Smith #include <petscsys.h> 600dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 601d382aafbSBarry Smith 602d382aafbSBarry Smith Not Collective 603d382aafbSBarry Smith 604d8d19677SJose E. Roman Input Parameters: 605d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 606d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 607dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 608d382aafbSBarry Smith 609d8d19677SJose E. Roman Output Parameters: 610d382aafbSBarry Smith + r1 - memory allocated in first chunk 611d382aafbSBarry Smith . r2 - memory allocated in second chunk 612d382aafbSBarry Smith - r3 - memory allocated in third chunk 613d382aafbSBarry Smith 614d382aafbSBarry Smith Level: developer 615d382aafbSBarry Smith 616db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 617d382aafbSBarry Smith M*/ 618f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \ 619b67aa78dSSatish 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)) 620d382aafbSBarry Smith 621d382aafbSBarry Smith /*MC 62287497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 623d382aafbSBarry Smith 624eca87e8dSBarry Smith Synopsis: 625aaa7dc30SBarry Smith #include <petscsys.h> 6261795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 627eca87e8dSBarry Smith 628eca87e8dSBarry Smith Not Collective 629eca87e8dSBarry Smith 630d8d19677SJose E. Roman Input Parameters: 631d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 632d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 6331795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 6341795a4d1SJed Brown 635d8d19677SJose E. Roman Output Parameters: 6361795a4d1SJed Brown + r1 - memory allocated in first chunk 6371795a4d1SJed Brown . r2 - memory allocated in second chunk 6381795a4d1SJed Brown - r3 - memory allocated in third chunk 6391795a4d1SJed Brown 6401795a4d1SJed Brown Level: developer 6411795a4d1SJed Brown 642db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 6431795a4d1SJed Brown M*/ 644f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \ 645b67aa78dSSatish 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)) 6461795a4d1SJed Brown 6471795a4d1SJed Brown /*MC 64887497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 649d382aafbSBarry Smith 650d382aafbSBarry Smith Synopsis: 651aaa7dc30SBarry Smith #include <petscsys.h> 652dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 653d382aafbSBarry Smith 654d382aafbSBarry Smith Not Collective 655d382aafbSBarry Smith 656d8d19677SJose E. Roman Input Parameters: 657d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 658d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 659d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 660dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 661d382aafbSBarry Smith 662d8d19677SJose E. Roman Output Parameters: 663d382aafbSBarry Smith + r1 - memory allocated in first chunk 664d382aafbSBarry Smith . r2 - memory allocated in second chunk 665d382aafbSBarry Smith . r3 - memory allocated in third chunk 666d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 667d382aafbSBarry Smith 668d382aafbSBarry Smith Level: developer 669d382aafbSBarry Smith 670db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 671d382aafbSBarry Smith M*/ 6729371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 673b67aa78dSSatish 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)) 674d382aafbSBarry Smith 675d382aafbSBarry Smith /*MC 67687497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 677d382aafbSBarry Smith 678eca87e8dSBarry Smith Synopsis: 679aaa7dc30SBarry Smith #include <petscsys.h> 6801795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 681eca87e8dSBarry Smith 682eca87e8dSBarry Smith Not Collective 683eca87e8dSBarry Smith 684e28ce29aSPatrick Sanan Input Parameters: 685d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 686d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 687d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6881795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6891795a4d1SJed Brown 690e28ce29aSPatrick Sanan Output Parameters: 6911795a4d1SJed Brown + r1 - memory allocated in first chunk 6921795a4d1SJed Brown . r2 - memory allocated in second chunk 6931795a4d1SJed Brown . r3 - memory allocated in third chunk 6941795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6951795a4d1SJed Brown 6961795a4d1SJed Brown Level: developer 6971795a4d1SJed Brown 698db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6991795a4d1SJed Brown M*/ 7009371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 701b67aa78dSSatish 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)) 7021795a4d1SJed Brown 7031795a4d1SJed Brown /*MC 70487497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 705d382aafbSBarry Smith 706d382aafbSBarry Smith Synopsis: 707aaa7dc30SBarry Smith #include <petscsys.h> 708dcca6d9dSJed 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) 709d382aafbSBarry Smith 710d382aafbSBarry Smith Not Collective 711d382aafbSBarry Smith 712e28ce29aSPatrick Sanan Input Parameters: 713d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 714d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 715d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 716d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 717dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 718d382aafbSBarry Smith 719e28ce29aSPatrick Sanan Output Parameters: 720d382aafbSBarry Smith + r1 - memory allocated in first chunk 721d382aafbSBarry Smith . r2 - memory allocated in second chunk 722d382aafbSBarry Smith . r3 - memory allocated in third chunk 723d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 724d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 725d382aafbSBarry Smith 726d382aafbSBarry Smith Level: developer 727d382aafbSBarry Smith 728db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 729d382aafbSBarry Smith M*/ 7309371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 731b67aa78dSSatish 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)) 732d382aafbSBarry Smith 733d382aafbSBarry Smith /*MC 73487497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 735d382aafbSBarry Smith 736eca87e8dSBarry Smith Synopsis: 737aaa7dc30SBarry Smith #include <petscsys.h> 7381795a4d1SJed 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) 739eca87e8dSBarry Smith 740eca87e8dSBarry Smith Not Collective 741eca87e8dSBarry Smith 742e28ce29aSPatrick Sanan Input Parameters: 743d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 744d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 745d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 746d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 7471795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 7481795a4d1SJed Brown 749e28ce29aSPatrick Sanan Output Parameters: 7501795a4d1SJed Brown + r1 - memory allocated in first chunk 7511795a4d1SJed Brown . r2 - memory allocated in second chunk 7521795a4d1SJed Brown . r3 - memory allocated in third chunk 7531795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7541795a4d1SJed Brown - r5 - memory allocated in fifth chunk 7551795a4d1SJed Brown 7561795a4d1SJed Brown Level: developer 7571795a4d1SJed Brown 758db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 7591795a4d1SJed Brown M*/ 7609371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 761b67aa78dSSatish 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)) 762d382aafbSBarry Smith 763d382aafbSBarry Smith /*MC 76487497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 765d382aafbSBarry Smith 766d382aafbSBarry Smith Synopsis: 767aaa7dc30SBarry Smith #include <petscsys.h> 768dcca6d9dSJed 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) 769d382aafbSBarry Smith 770d382aafbSBarry Smith Not Collective 771d382aafbSBarry Smith 772e28ce29aSPatrick Sanan Input Parameters: 773d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 774d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 775d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 776d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 777d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 778dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 779d382aafbSBarry Smith 780e28ce29aSPatrick Sanan Output Parameteasr: 781d382aafbSBarry Smith + r1 - memory allocated in first chunk 782d382aafbSBarry Smith . r2 - memory allocated in second chunk 783d382aafbSBarry Smith . r3 - memory allocated in third chunk 784d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 785d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 786d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 787d382aafbSBarry Smith 788d382aafbSBarry Smith Level: developer 789d382aafbSBarry Smith 790db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 791d382aafbSBarry Smith M*/ 7929371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 793b67aa78dSSatish 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)) 794d382aafbSBarry Smith 795d382aafbSBarry Smith /*MC 79687497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 797d382aafbSBarry Smith 798eca87e8dSBarry Smith Synopsis: 799aaa7dc30SBarry Smith #include <petscsys.h> 8001795a4d1SJed 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) 801eca87e8dSBarry Smith 802eca87e8dSBarry Smith Not Collective 803eca87e8dSBarry Smith 804e28ce29aSPatrick Sanan Input Parameters: 805d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 806d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 807d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 808d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 809d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 8101795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 8111795a4d1SJed Brown 812e28ce29aSPatrick Sanan Output Parameters: 8131795a4d1SJed Brown + r1 - memory allocated in first chunk 8141795a4d1SJed Brown . r2 - memory allocated in second chunk 8151795a4d1SJed Brown . r3 - memory allocated in third chunk 8161795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8171795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8181795a4d1SJed Brown - r6 - memory allocated in sixth chunk 8191795a4d1SJed Brown 8201795a4d1SJed Brown Level: developer 8211795a4d1SJed Brown 822db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 8231795a4d1SJed Brown M*/ 8249371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 825b67aa78dSSatish 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)) 8261795a4d1SJed Brown 8271795a4d1SJed Brown /*MC 82887497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 829d382aafbSBarry Smith 830d382aafbSBarry Smith Synopsis: 831aaa7dc30SBarry Smith #include <petscsys.h> 832dcca6d9dSJed 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) 833d382aafbSBarry Smith 834d382aafbSBarry Smith Not Collective 835d382aafbSBarry Smith 836e28ce29aSPatrick Sanan Input Parameters: 837d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 838d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 839d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 840d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 841d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 842d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 843dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 844d382aafbSBarry Smith 845e28ce29aSPatrick Sanan Output Parameters: 846d382aafbSBarry Smith + r1 - memory allocated in first chunk 847d382aafbSBarry Smith . r2 - memory allocated in second chunk 848d382aafbSBarry Smith . r3 - memory allocated in third chunk 849d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 850d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 851d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 852eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 853d382aafbSBarry Smith 854d382aafbSBarry Smith Level: developer 855d382aafbSBarry Smith 856db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 857d382aafbSBarry Smith M*/ 8589371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 859b67aa78dSSatish 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)) 860d382aafbSBarry Smith 861d382aafbSBarry Smith /*MC 86287497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 8631795a4d1SJed Brown 8641795a4d1SJed Brown Synopsis: 865aaa7dc30SBarry Smith #include <petscsys.h> 8661795a4d1SJed 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) 8671795a4d1SJed Brown 8681795a4d1SJed Brown Not Collective 8691795a4d1SJed Brown 870e28ce29aSPatrick Sanan Input Parameters: 8711795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 8721795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 8731795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 8741795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 8751795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8761795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8771795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8781795a4d1SJed Brown 879e28ce29aSPatrick Sanan Output Parameters: 8801795a4d1SJed Brown + r1 - memory allocated in first chunk 8811795a4d1SJed Brown . r2 - memory allocated in second chunk 8821795a4d1SJed Brown . r3 - memory allocated in third chunk 8831795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8841795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8851795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8861795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8871795a4d1SJed Brown 8881795a4d1SJed Brown Level: developer 8891795a4d1SJed Brown 890db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8911795a4d1SJed Brown M*/ 8929371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 893b67aa78dSSatish 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)) 8941795a4d1SJed Brown 8951795a4d1SJed Brown /*MC 89687497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 897d382aafbSBarry Smith 898eca87e8dSBarry Smith Synopsis: 899aaa7dc30SBarry Smith #include <petscsys.h> 900b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 901eca87e8dSBarry Smith 902eca87e8dSBarry Smith Not Collective 903eca87e8dSBarry Smith 904d382aafbSBarry Smith Output Parameter: 905b00a9115SJed Brown . result - memory allocated, sized to match pointer type 906d382aafbSBarry Smith 907d382aafbSBarry Smith Level: beginner 908d382aafbSBarry Smith 909fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 910d382aafbSBarry Smith M*/ 911b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 912ad0619ddSBarry Smith 913f4f49eeaSPierre Jolivet #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b) 914d382aafbSBarry Smith 915d382aafbSBarry Smith /*MC 916d382aafbSBarry Smith PetscFree - Frees memory 917d382aafbSBarry Smith 918eca87e8dSBarry Smith Synopsis: 919aaa7dc30SBarry Smith #include <petscsys.h> 920eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 921eca87e8dSBarry Smith 922eca87e8dSBarry Smith Not Collective 923eca87e8dSBarry Smith 924d382aafbSBarry Smith Input Parameter: 92516a05f60SBarry Smith . memory - memory to free (the pointer is ALWAYS set to `NULL` upon success) 926d382aafbSBarry Smith 927d382aafbSBarry Smith Level: beginner 928d382aafbSBarry Smith 92995bd0b28SBarry Smith Notes: 93087497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 931390e1bf2SBarry Smith 93216a05f60SBarry Smith It is safe to call `PetscFree()` on a `NULL` pointer. 933d382aafbSBarry Smith 934fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 935d382aafbSBarry Smith M*/ 9363ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS))) 937d382aafbSBarry Smith 938d382aafbSBarry Smith /*MC 93987497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 940d382aafbSBarry Smith 941eca87e8dSBarry Smith Synopsis: 942aaa7dc30SBarry Smith #include <petscsys.h> 943eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 944eca87e8dSBarry Smith 945eca87e8dSBarry Smith Not Collective 946eca87e8dSBarry Smith 947e28ce29aSPatrick Sanan Input Parameters: 948d382aafbSBarry Smith + memory1 - memory to free 949d382aafbSBarry Smith - memory2 - 2nd memory to free 950d382aafbSBarry Smith 951d382aafbSBarry Smith Level: developer 952d382aafbSBarry Smith 9537e17494fSJames Wright Notes: 95487497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 955d382aafbSBarry Smith 9567e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc2()` 9577e17494fSJames Wright 958db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 959d382aafbSBarry Smith M*/ 960ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 961d382aafbSBarry Smith 962d382aafbSBarry Smith /*MC 96387497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 964d382aafbSBarry Smith 965eca87e8dSBarry Smith Synopsis: 966aaa7dc30SBarry Smith #include <petscsys.h> 967eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 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 - memory3 - 3rd memory to free 975d382aafbSBarry Smith 976d382aafbSBarry Smith Level: developer 977d382aafbSBarry Smith 9787e17494fSJames Wright Notes: 97987497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 980d382aafbSBarry Smith 9817e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc3()` 9827e17494fSJames Wright 983db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 984d382aafbSBarry Smith M*/ 985ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 986d382aafbSBarry Smith 987d382aafbSBarry Smith /*MC 98887497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 989d382aafbSBarry Smith 990eca87e8dSBarry Smith Synopsis: 991aaa7dc30SBarry Smith #include <petscsys.h> 992eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 993eca87e8dSBarry Smith 994eca87e8dSBarry Smith Not Collective 995eca87e8dSBarry Smith 996e28ce29aSPatrick Sanan Input Parameters: 997d382aafbSBarry Smith + m1 - memory to free 998d382aafbSBarry Smith . m2 - 2nd memory to free 999d382aafbSBarry Smith . m3 - 3rd memory to free 1000d382aafbSBarry Smith - m4 - 4th memory to free 1001d382aafbSBarry Smith 1002d382aafbSBarry Smith Level: developer 1003d382aafbSBarry Smith 10047e17494fSJames Wright Notes: 100587497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 1006d382aafbSBarry Smith 10077e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc4()` 10087e17494fSJames Wright 1009db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 1010d382aafbSBarry Smith M*/ 1011ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 1012d382aafbSBarry Smith 1013d382aafbSBarry Smith /*MC 101487497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 1015d382aafbSBarry Smith 1016eca87e8dSBarry Smith Synopsis: 1017aaa7dc30SBarry Smith #include <petscsys.h> 1018eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 1019eca87e8dSBarry Smith 1020eca87e8dSBarry Smith Not Collective 1021eca87e8dSBarry Smith 1022e28ce29aSPatrick Sanan Input Parameters: 1023d382aafbSBarry Smith + m1 - memory to free 1024d382aafbSBarry Smith . m2 - 2nd memory to free 1025d382aafbSBarry Smith . m3 - 3rd memory to free 1026d382aafbSBarry Smith . m4 - 4th memory to free 1027d382aafbSBarry Smith - m5 - 5th memory to free 1028d382aafbSBarry Smith 1029d382aafbSBarry Smith Level: developer 1030d382aafbSBarry Smith 10317e17494fSJames Wright Notes: 103287497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 1033d382aafbSBarry Smith 10347e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc5()` 10357e17494fSJames Wright 1036db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 1037d382aafbSBarry Smith M*/ 1038ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 1039d382aafbSBarry Smith 1040d382aafbSBarry Smith /*MC 104187497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 1042d382aafbSBarry Smith 1043eca87e8dSBarry Smith Synopsis: 1044aaa7dc30SBarry Smith #include <petscsys.h> 1045eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1046eca87e8dSBarry Smith 1047eca87e8dSBarry Smith Not Collective 1048eca87e8dSBarry Smith 1049e28ce29aSPatrick Sanan Input Parameters: 1050d382aafbSBarry Smith + m1 - memory to free 1051d382aafbSBarry Smith . m2 - 2nd memory to free 1052d382aafbSBarry Smith . m3 - 3rd memory to free 1053d382aafbSBarry Smith . m4 - 4th memory to free 1054d382aafbSBarry Smith . m5 - 5th memory to free 1055d382aafbSBarry Smith - m6 - 6th memory to free 1056d382aafbSBarry Smith 1057d382aafbSBarry Smith Level: developer 1058d382aafbSBarry Smith 10597e17494fSJames Wright Notes: 106087497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 1061d382aafbSBarry Smith 10627e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc6()` 10637e17494fSJames Wright 1064db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 1065d382aafbSBarry Smith M*/ 1066ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 1067d382aafbSBarry Smith 1068d382aafbSBarry Smith /*MC 106987497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 1070d382aafbSBarry Smith 1071eca87e8dSBarry Smith Synopsis: 1072aaa7dc30SBarry Smith #include <petscsys.h> 1073eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1074eca87e8dSBarry Smith 1075eca87e8dSBarry Smith Not Collective 1076eca87e8dSBarry Smith 1077e28ce29aSPatrick Sanan Input Parameters: 1078d382aafbSBarry Smith + m1 - memory to free 1079d382aafbSBarry Smith . m2 - 2nd memory to free 1080d382aafbSBarry Smith . m3 - 3rd memory to free 1081d382aafbSBarry Smith . m4 - 4th memory to free 1082d382aafbSBarry Smith . m5 - 5th memory to free 1083d382aafbSBarry Smith . m6 - 6th memory to free 1084d382aafbSBarry Smith - m7 - 7th memory to free 1085d382aafbSBarry Smith 1086d382aafbSBarry Smith Level: developer 1087d382aafbSBarry Smith 10887e17494fSJames Wright Notes: 108987497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1090d382aafbSBarry Smith 10917e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc7()` 10927e17494fSJames Wright 1093db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1094db781477SPatrick Sanan `PetscMalloc7()` 1095d382aafbSBarry Smith M*/ 1096ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1097d382aafbSBarry Smith 1098ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1099ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1100071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1101efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 11023221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1103ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 110492f119d6SBarry 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 **)); 1105014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1106d382aafbSBarry Smith 1107d382aafbSBarry Smith /* 1108c1706be6SHong 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. 1109c1706be6SHong Zhang */ 1110c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1111c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 111231f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 111331f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 111431f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 111531f06eaaSHong Zhang #endif 111659af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 111759af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 111859af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 111959af0bd3SScott Kruger #endif 112059af0bd3SScott Kruger 1121a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 112236763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1123a5057860SBarry Smith 1124a5057860SBarry Smith /* 112566d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1126d382aafbSBarry Smith */ 1127014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 112892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1131e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1132e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 113392f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 113492f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1135efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 113692f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 113792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1138608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1139608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1140d382aafbSBarry Smith 1141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 11448e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1145d382aafbSBarry Smith 1146d382aafbSBarry Smith /* 1147d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1148d382aafbSBarry Smith */ 1149367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1150570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1151de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1152014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1153014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1154d9822059SBarry Smith #else 1155de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1156d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1157d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1158d9822059SBarry Smith #endif 115962e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 116062e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 116162e5d2d2SJDBetteridge 1162a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16)) 1163613bf2b2SPierre Jolivet /*MC 116416a05f60SBarry Smith MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with 116516a05f60SBarry Smith custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1166613bf2b2SPierre Jolivet 1167613bf2b2SPierre Jolivet Level: advanced 1168613bf2b2SPierre Jolivet 1169613bf2b2SPierre Jolivet Developer Note: 1170613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1171613bf2b2SPierre Jolivet 1172613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1173613bf2b2SPierre Jolivet M*/ 11749e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1175613bf2b2SPierre Jolivet #endif 1176014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1177d382aafbSBarry Smith 117893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 117993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1180eb3f98d2SBarry Smith 1181639ff905SBarry Smith /* 1182*49abdd8aSBarry Smith These are so that in extern C code we can cast function pointers to non-extern C 1183*49abdd8aSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1184*49abdd8aSBarry Smith */ 1185*49abdd8aSBarry Smith 1186*49abdd8aSBarry Smith /*S 1187*49abdd8aSBarry Smith PetscVoidFn - A prototype of a void (fn)(void) function 1188*49abdd8aSBarry Smith 1189*49abdd8aSBarry Smith Level: developer 1190*49abdd8aSBarry Smith 1191*49abdd8aSBarry Smith Notes: 1192*49abdd8aSBarry Smith The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *. 1193*49abdd8aSBarry Smith 1194*49abdd8aSBarry Smith The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **. 1195*49abdd8aSBarry Smith 1196*49abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 1197*49abdd8aSBarry Smith S*/ 1198*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void); 1199*49abdd8aSBarry Smith 1200*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn *PetscVoidFunction; 1201*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction; 1202*49abdd8aSBarry Smith 1203*49abdd8aSBarry Smith /*S 1204*49abdd8aSBarry Smith PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function 1205*49abdd8aSBarry Smith 1206*49abdd8aSBarry Smith Level: developer 1207*49abdd8aSBarry Smith 1208*49abdd8aSBarry Smith Notes: 1209*49abdd8aSBarry Smith The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *. 1210*49abdd8aSBarry Smith 1211*49abdd8aSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 1212*49abdd8aSBarry Smith S*/ 1213*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void); 1214*49abdd8aSBarry Smith 1215*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction; 1216*49abdd8aSBarry Smith 1217*49abdd8aSBarry Smith /*S 1218*49abdd8aSBarry Smith PetscCtxDestroyFn - A prototype of a `PetscErrorCode (*)(void *)` function that is used to free user contexts 1219*49abdd8aSBarry Smith 1220*49abdd8aSBarry Smith Level: intermediate 1221*49abdd8aSBarry Smith 1222*49abdd8aSBarry Smith Note: 1223*49abdd8aSBarry Smith Used in the prototype of functions such as `DMSetApplicationContextDestroy()` 1224*49abdd8aSBarry Smith 1225*49abdd8aSBarry Smith .seealso: `PetscObject`, `PetscCtxDestroyDefault()`, `PetscObjectDestroy()`, `DMSetApplicationContextDestroy()` 1226*49abdd8aSBarry Smith S*/ 1227*49abdd8aSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscCtxDestroyFn)(void **); 1228*49abdd8aSBarry Smith 1229*49abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PetscCtxDestroyDefault; 1230*49abdd8aSBarry Smith 1231*49abdd8aSBarry Smith /* 1232639ff905SBarry Smith Defines PETSc error handling. 1233639ff905SBarry Smith */ 1234639ff905SBarry Smith #include <petscerror.h> 1235d382aafbSBarry Smith 1236660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1237660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1238660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1239660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1240660278c0SBarry Smith 1241f3fa974cSJacob Faibussowitsch #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211) 1242014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1243014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 124581256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 124681256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 124781256985SMatthew G. Knepley 1248d382aafbSBarry Smith /* 1249d382aafbSBarry Smith Routines that get memory usage information from the OS 1250d382aafbSBarry Smith */ 1251014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1252014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1253014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1254b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1255d382aafbSBarry Smith 1256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1257d382aafbSBarry Smith 1258d382aafbSBarry Smith /* 1259d382aafbSBarry Smith Initialization of PETSc 1260d382aafbSBarry Smith */ 1261014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1263014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1264014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1265014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1266014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1267014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1268014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1269014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1270014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1271d382aafbSBarry Smith 1272014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1273607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 12744bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void); 1275d382aafbSBarry Smith 1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1277014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1278014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1279014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1280d382aafbSBarry Smith 1281*49abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscErrorCode (*)(void), void *, PetscCtxDestroyFn *, PetscBool *); 1282d382aafbSBarry Smith 1283d382aafbSBarry Smith /* 1284d382aafbSBarry Smith Functions that can act on any PETSc object. 1285d382aafbSBarry Smith */ 1286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1299014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1303bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 13048434afd1SBarry Smith #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__)) 1305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1306014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 13070eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 13080eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1310d382aafbSBarry Smith 1311b3480c81SBarry Smith /*MC 1312b3480c81SBarry Smith PetscObjectParameterSetDefault - sets a parameter default value in a `PetscObject` to a new default value. 1313b3480c81SBarry Smith If the current value matches the old default value, then the current value is also set to the new value. 1314b3480c81SBarry Smith 1315b3480c81SBarry Smith No Fortran Support 1316b3480c81SBarry Smith 1317b3480c81SBarry Smith Synopsis: 1318b3480c81SBarry Smith #include <petscsys.h> 1319b3480c81SBarry Smith PetscBool PetscObjectParameterSetDefault(PetscObject obj, char* NAME, PetscReal value); 1320b3480c81SBarry Smith 1321b3480c81SBarry Smith Input Parameters: 1322b3480c81SBarry Smith + obj - the `PetscObject` 1323b3480c81SBarry Smith . NAME - the name of the parameter, unquoted 1324b3480c81SBarry Smith - value - the new value 1325b3480c81SBarry Smith 1326b3480c81SBarry Smith Level: developer 1327b3480c81SBarry Smith 1328b3480c81SBarry Smith Notes: 1329b3480c81SBarry Smith The defaults for an object are the values set when the object's type is set. 1330b3480c81SBarry Smith 1331b3480c81SBarry Smith This should only be used in object constructors, such as, `SNESCreate_NGS()`. 1332b3480c81SBarry Smith 1333b3480c81SBarry Smith This only works for parameters that are declared in the struct with `PetscObjectParameterDeclare()` 1334b3480c81SBarry Smith 1335b3480c81SBarry Smith .seealso: `PetscObjectParameterDeclare()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()` 1336b3480c81SBarry Smith M*/ 1337b3480c81SBarry Smith #define PetscObjectParameterSetDefault(obj, NAME, value) \ 1338b3480c81SBarry Smith do { \ 1339b3480c81SBarry Smith if (obj->NAME == obj->default_##NAME) obj->NAME = value; \ 1340b3480c81SBarry Smith obj->default_##NAME = value; \ 1341b3480c81SBarry Smith } while (0) 1342b3480c81SBarry Smith 1343b3480c81SBarry Smith /*MC 1344b3480c81SBarry Smith PetscObjectParameterDeclare - declares a parameter in a `PetscObject` and a location to store its default 1345b3480c81SBarry Smith 1346b3480c81SBarry Smith No Fortran Support 1347b3480c81SBarry Smith 1348b3480c81SBarry Smith Synopsis: 1349b3480c81SBarry Smith #include <petscsys.h> 1350b3480c81SBarry Smith PetscBool PetscObjectParameterDeclare(type, char* NAME) 1351b3480c81SBarry Smith 1352b3480c81SBarry Smith Input Parameters: 1353b3480c81SBarry Smith + type - the type of the parameter, for example `PetscInt` 1354b3480c81SBarry Smith - NAME - the name of the parameter, unquoted 1355b3480c81SBarry Smith 1356b3480c81SBarry Smith Level: developer. 1357b3480c81SBarry Smith 1358b3480c81SBarry Smith .seealso: `PetscObjectParameterSetDefault()`, `PetscInitialize()`, `PetscFinalize()`, `PetscObject`, `SNESParametersInitialize()` 1359b3480c81SBarry Smith M*/ 1360b3480c81SBarry Smith #define PetscObjectParameterDeclare(type, NAME) type NAME, default_##NAME 1361b3480c81SBarry Smith 1362665c2dedSJed Brown #include <petscviewertypes.h> 1363639ff905SBarry Smith #include <petscoptions.h> 1364639ff905SBarry Smith 1365608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1366608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1367608c71bfSMatthew G. Knepley 13680633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 13690633abcbSJed Brown 1370c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1371dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1372639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 13738434afd1SBarry Smith #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr)) 13740cd8b6e2SStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectHasFunction(PetscObject, const char[], PetscBool *); 13750005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1383685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1386013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 13874099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1389b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1392d382aafbSBarry Smith 1393e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 13947aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1395e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1396e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1397e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1398e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1399e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1400e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1401e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1402e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1403e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 140415681b3cSBarry Smith 1405ec7429eaSBarry Smith #else 14063ba16761SJacob Faibussowitsch #define PetscSAWsBlock() PETSC_SUCCESS 14073ba16761SJacob Faibussowitsch #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS 14083ba16761SJacob Faibussowitsch #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS 14093ba16761SJacob Faibussowitsch #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS 14103ba16761SJacob Faibussowitsch #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS 14113ba16761SJacob Faibussowitsch #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS 14123ba16761SJacob Faibussowitsch #define PetscStackViewSAWs() PETSC_SUCCESS 14133ba16761SJacob Faibussowitsch #define PetscStackSAWsViewOff() PETSC_SUCCESS 1414e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1415e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 141615681b3cSBarry Smith 1417ec7429eaSBarry Smith #endif 1418b90c6cbeSBarry Smith 141982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 142082b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 142182b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1422258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1423258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1424258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1425258ec3d2SMatthew G. Knepley #endif 14267d5d4d99SBarry Smith 1427a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1428a64a8e02SBarry Smith 1429dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 14304bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer); 14315d83a8b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, const char **); 1432140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1433140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1434140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1435140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1436140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1437140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1438d382aafbSBarry Smith 1439d382aafbSBarry Smith /* 1440503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1441d382aafbSBarry Smith link libraries that will be loaded as needed. 1442d382aafbSBarry Smith */ 1443a240a19fSJed Brown 14448434afd1SBarry Smith #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr)) 14458434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *); 1446140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 14470e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 14488434afd1SBarry Smith #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr)) 14498434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **); 145044ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1451140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1452140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1453140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 14542e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 14552e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1456d382aafbSBarry Smith 1457014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1458014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1459014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1464014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1465d382aafbSBarry Smith 1466d382aafbSBarry Smith /* 1467d382aafbSBarry Smith Useful utility routines 1468d382aafbSBarry Smith */ 1469014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1470014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1471d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1475014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 147658b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 147758b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1478d382aafbSBarry Smith 147964ac3b0dSPatrick Sanan /*MC 148087497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1481503cfb0cSBarry Smith 148264ac3b0dSPatrick Sanan Level: beginner 148364ac3b0dSPatrick Sanan 1484a1cb98faSBarry Smith Note: 1485a1cb98faSBarry Smith This is useful in cases like 1486a1cb98faSBarry Smith .vb 1487a1cb98faSBarry Smith int *a; 1488a1cb98faSBarry Smith PetscBool flag = PetscNot(a) 1489a1cb98faSBarry Smith .ve 1490a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1491a1cb98faSBarry Smith 1492a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 149364ac3b0dSPatrick Sanan M*/ 1494d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1495503cfb0cSBarry Smith 1496d382aafbSBarry Smith /*MC 1497d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1498d382aafbSBarry Smith 1499d382aafbSBarry Smith Synopsis: 1500aaa7dc30SBarry Smith #include <petscsys.h> 1501659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1502d382aafbSBarry Smith 15037cdbe19fSJose E. Roman Not Collective, only applies on MPI rank 0; No Fortran Support 15047cdbe19fSJose E. Roman 1505d382aafbSBarry Smith Input Parameters: 1506659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1507d382aafbSBarry Smith . format - the usual printf() format string 1508659f7ba0SBarry Smith - args - arguments to be printed 1509d382aafbSBarry Smith 1510d382aafbSBarry Smith Level: developer 1511d382aafbSBarry Smith 151295bd0b28SBarry Smith Notes: 1513659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1514659f7ba0SBarry Smith 1515659f7ba0SBarry Smith To use, write your own function, for example, 151616a05f60SBarry Smith .vb 151716a05f60SBarry Smith PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 151816a05f60SBarry Smith { 151916a05f60SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 152016a05f60SBarry Smith } 152116a05f60SBarry Smith .ve 1522d5b43468SJose E. Roman then do the assignment 1523af27ebaaSBarry Smith .vb 1524af27ebaaSBarry Smith PetscHelpPrintf = mypetschelpprintf; 1525af27ebaaSBarry Smith .ve 1526af27ebaaSBarry Smith 152787497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1528659f7ba0SBarry Smith 152987497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1530d382aafbSBarry Smith 153116a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()` 1532d382aafbSBarry Smith M*/ 15333ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1534d382aafbSBarry Smith 1535fcfd50ebSBarry Smith /* 1536fcfd50ebSBarry Smith Defines PETSc profiling. 1537fcfd50ebSBarry Smith */ 15382c8e378dSBarry Smith #include <petsclog.h> 1539fcfd50ebSBarry Smith 1540fcfd50ebSBarry Smith /* 1541fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1542fcfd50ebSBarry Smith */ 1543014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1544014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1545014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 15463ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1547c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *); 15483ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 15493ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 15503ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 15511b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1552fcfd50ebSBarry Smith 15533ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 15543ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 15553ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1556d382aafbSBarry Smith 1557d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1558d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1559d781fa04SBarry Smith 1560014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1561016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 156274ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1563d382aafbSBarry Smith 15643ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 15653ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 15660ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1567014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1568014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1569014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1570d382aafbSBarry Smith 1571014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1572014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1573014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1574014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1575014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1576*49abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscContainerSetCtxDestroy(PetscContainer, PetscCtxDestroyFn *); 1577*49abdd8aSBarry Smith PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscContainerSetCtxDestroy()", ) PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1578*49abdd8aSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerCompose(PetscObject, const char *name, void *, PetscCtxDestroyFn *); 15798a085367SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectContainerQuery(PetscObject, const char *, void **); 1580d382aafbSBarry Smith 1581*49abdd8aSBarry Smith PETSC_DEPRECATED_FUNCTION(3, 23, 0, "PetscCtxDestroyDefault()", ) static inline PetscErrorCode PetscContainerCtxDestroyDefault(void **a) 1582*49abdd8aSBarry Smith { 1583*49abdd8aSBarry Smith return PetscCtxDestroyDefault(a); 1584*49abdd8aSBarry Smith } 1585*49abdd8aSBarry Smith 1586d382aafbSBarry Smith /* 1587d382aafbSBarry Smith For use in debuggers 1588d382aafbSBarry Smith */ 1589014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1590014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1591014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1592014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1593014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1594d382aafbSBarry Smith 1595bbcf679cSJacob Faibussowitsch /* 1596bbcf679cSJacob Faibussowitsch Basic memory and string operations. These are usually simple wrappers 1597bbcf679cSJacob Faibussowitsch around the basic Unix system calls, but a few of them have additional 1598bbcf679cSJacob Faibussowitsch functionality and/or error checking. 1599bbcf679cSJacob Faibussowitsch */ 1600bbcf679cSJacob Faibussowitsch #include <petscstring.h> 1601bbcf679cSJacob Faibussowitsch 1602a663daf8SBarry Smith #include <stddef.h> 1603d382aafbSBarry Smith #include <stdlib.h> 16046c7e564aSBarry Smith 1605447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER) 1606447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d) 1607447bcd8fSJacob Faibussowitsch #else 1608d382aafbSBarry Smith /*MC 1609d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1610d382aafbSBarry Smith 1611eca87e8dSBarry Smith Synopsis: 1612aaa7dc30SBarry Smith #include <petscsys.h> 1613eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1614eca87e8dSBarry Smith 1615d382aafbSBarry Smith Not Collective 1616d382aafbSBarry Smith 1617d382aafbSBarry Smith Input Parameters: 161816a05f60SBarry Smith + a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`) 1619d382aafbSBarry Smith . n - number of elements to fetch 1620d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 162150d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1622d382aafbSBarry Smith 1623d382aafbSBarry Smith Level: developer 1624d382aafbSBarry Smith 1625d382aafbSBarry Smith Notes: 162616a05f60SBarry Smith The last two arguments (`rw` and `t`) must be compile-time constants. 1627d382aafbSBarry Smith 162850d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 162950d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 163087497f52SBarry 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). 163187497f52SBarry 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. 163287497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 163387497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1634d382aafbSBarry Smith 1635d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1636d382aafbSBarry Smith address). 1637d382aafbSBarry Smith 1638d382aafbSBarry Smith M*/ 16399371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 16409371c9d4SSatish Balay do { \ 1641d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1642d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1643d382aafbSBarry Smith } while (0) 1644447bcd8fSJacob Faibussowitsch #endif 1645d382aafbSBarry Smith /* 1646d382aafbSBarry Smith Determine if some of the kernel computation routines use 1647d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1648d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1649d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1650e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1651d382aafbSBarry Smith */ 1652d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1653d382aafbSBarry Smith 1654d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1655d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1656d382aafbSBarry Smith #endif 1657d382aafbSBarry Smith 1658d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1659d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1660d382aafbSBarry Smith #endif 1661d382aafbSBarry Smith 1662d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1663d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1664d382aafbSBarry Smith #endif 1665d382aafbSBarry Smith 1666d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1667d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1668d382aafbSBarry Smith #endif 1669d382aafbSBarry Smith 1670d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1671d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1672d382aafbSBarry Smith #endif 1673d382aafbSBarry Smith 1674d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1675d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1676d382aafbSBarry Smith #endif 1677d382aafbSBarry Smith 1678d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1679d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1680d382aafbSBarry Smith #endif 1681d382aafbSBarry Smith 1682d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1683d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1684d382aafbSBarry Smith #endif 1685d382aafbSBarry Smith 1686d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1687d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1688d382aafbSBarry Smith #endif 1689d382aafbSBarry Smith 1690d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1691d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1692d382aafbSBarry Smith #endif 1693d382aafbSBarry Smith 1694d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1695d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1696d382aafbSBarry Smith #endif 1697d382aafbSBarry Smith 1698d382aafbSBarry Smith #endif 1699d382aafbSBarry Smith 1700d382aafbSBarry Smith /* 1701d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1702d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1703d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1704d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1705d382aafbSBarry Smith ugly extern "C" {} wrappers. 1706d382aafbSBarry Smith */ 1707d382aafbSBarry Smith #if defined(__cplusplus) 1708d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1709d382aafbSBarry Smith #define EXTERN_C_END } 1710d382aafbSBarry Smith #else 1711d382aafbSBarry Smith #define EXTERN_C_BEGIN 1712d382aafbSBarry Smith #define EXTERN_C_END 1713d382aafbSBarry Smith #endif 1714d382aafbSBarry Smith 1715d382aafbSBarry Smith /*MC 1716d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1717d382aafbSBarry Smith communication 1718d382aafbSBarry Smith 1719d382aafbSBarry Smith Level: beginner 1720d382aafbSBarry Smith 172116a05f60SBarry Smith Note: 172216a05f60SBarry Smith This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm` 1723d382aafbSBarry Smith 1724db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1725d382aafbSBarry Smith M*/ 1726d382aafbSBarry Smith 1727d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 172893d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 172993d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 173093d501b3SJacob 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); 173193d501b3SJacob 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); 173293d501b3SJacob 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); 173393d501b3SJacob 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); 1734d382aafbSBarry Smith #endif 1735d382aafbSBarry Smith 1736462c564dSBarry Smith #if defined(PETSC_HAVE_MPI_COUNT) 1737462c564dSBarry Smith typedef MPI_Count MPIU_Count; 1738462c564dSBarry Smith #else 1739462c564dSBarry Smith typedef PetscInt64 MPIU_Count; 1740462c564dSBarry Smith #endif 1741462c564dSBarry Smith 174261b0d812SBarry Smith /*@C 1743462c564dSBarry Smith PetscIntCast - casts a `MPI_Count`, `PetscInt64`, `PetscCount`, or `size_t` to a `PetscInt` (which may be 32-bits in size), generates an 174487497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1745c73702f5SBarry Smith 174620f4b53cSBarry Smith Not Collective; No Fortran Support 1747c73702f5SBarry Smith 1748c73702f5SBarry Smith Input Parameter: 174987497f52SBarry Smith . a - the `PetscInt64` value 1750c73702f5SBarry Smith 1751c73702f5SBarry Smith Output Parameter: 17526497c311SBarry Smith . b - the resulting `PetscInt` value, or `NULL` if the result is not needed 1753c73702f5SBarry Smith 1754c73702f5SBarry Smith Level: advanced 1755c73702f5SBarry Smith 175695bd0b28SBarry Smith Note: 17577de69702SBarry 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 1758c73702f5SBarry Smith 1759784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscCIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1760c73702f5SBarry Smith @*/ 1761462c564dSBarry Smith static inline PetscErrorCode PetscIntCast(MPIU_Count a, PetscInt *b) 1762d71ae5a4SJacob Faibussowitsch { 1763c73702f5SBarry Smith PetscFunctionBegin; 17646497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1765462c564dSBarry 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); 1766377f809aSBarry Smith if (b) *b = (PetscInt)a; 17673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1768c73702f5SBarry Smith } 1769c73702f5SBarry Smith 1770c73702f5SBarry Smith /*@C 1771462c564dSBarry Smith PetscBLASIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount` or `PetscInt64` to a `PetscBLASInt` (which may be 32-bits in size), generates an 177287497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 177361b0d812SBarry Smith 1774667f096bSBarry Smith Not Collective; No Fortran Support 177561b0d812SBarry Smith 177661b0d812SBarry Smith Input Parameter: 177787497f52SBarry Smith . a - the `PetscInt` value 177861b0d812SBarry Smith 177961b0d812SBarry Smith Output Parameter: 17806497c311SBarry Smith . b - the resulting `PetscBLASInt` value, or `NULL` if the result is not needed 178161b0d812SBarry Smith 178261b0d812SBarry Smith Level: advanced 178361b0d812SBarry Smith 1784667f096bSBarry Smith Note: 1785f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 17861fd49c25SBarry Smith 1787784a7648SPierre Jolivet .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 178861b0d812SBarry Smith @*/ 1789462c564dSBarry Smith static inline PetscErrorCode PetscBLASIntCast(MPIU_Count a, PetscBLASInt *b) 1790d71ae5a4SJacob Faibussowitsch { 1791c5df96a5SBarry Smith PetscFunctionBegin; 17926497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1793462c564dSBarry 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); 179454c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 17956497c311SBarry Smith if (b) *b = (PetscBLASInt)a; 17963ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1797c5df96a5SBarry Smith } 1798c5df96a5SBarry Smith 179961b0d812SBarry Smith /*@C 180087497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 1801eee0c0a6SToby Isaac 1802667f096bSBarry Smith Not Collective; No Fortran Support 1803eee0c0a6SToby Isaac 1804eee0c0a6SToby Isaac Input Parameter: 180587497f52SBarry Smith . a - the `PetscInt` value 1806eee0c0a6SToby Isaac 1807eee0c0a6SToby Isaac Output Parameter: 18086497c311SBarry Smith . b - the resulting `PetscCuBLASInt` value, or `NULL` if the result is not needed 1809eee0c0a6SToby Isaac 1810eee0c0a6SToby Isaac Level: advanced 1811eee0c0a6SToby Isaac 1812667f096bSBarry Smith Note: 1813eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 1814eee0c0a6SToby Isaac 1815784a7648SPierre Jolivet .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 1816eee0c0a6SToby Isaac @*/ 1817462c564dSBarry Smith static inline PetscErrorCode PetscCuBLASIntCast(MPIU_Count a, PetscCuBLASInt *b) 1818d71ae5a4SJacob Faibussowitsch { 1819eee0c0a6SToby Isaac PetscFunctionBegin; 18206497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1821462c564dSBarry 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); 1822462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to cuBLAS routine", (PetscInt64)a); 18236497c311SBarry Smith if (b) *b = (PetscCuBLASInt)a; 18243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1825eee0c0a6SToby Isaac } 1826eee0c0a6SToby Isaac 1827eee0c0a6SToby Isaac /*@C 182847d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 182947d993e7Ssuyashtn 1830667f096bSBarry Smith Not Collective; No Fortran Support 183147d993e7Ssuyashtn 183247d993e7Ssuyashtn Input Parameter: 183347d993e7Ssuyashtn . a - the `PetscInt` value 183447d993e7Ssuyashtn 183547d993e7Ssuyashtn Output Parameter: 18366497c311SBarry Smith . b - the resulting `PetscHipBLASInt` value, or `NULL` if the result is not needed 183747d993e7Ssuyashtn 183847d993e7Ssuyashtn Level: advanced 183947d993e7Ssuyashtn 1840667f096bSBarry Smith Note: 184147d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 184247d993e7Ssuyashtn 1843784a7648SPierre Jolivet .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscCIntCast()`, `PetscIntCast()` 184447d993e7Ssuyashtn @*/ 1845462c564dSBarry Smith static inline PetscErrorCode PetscHipBLASIntCast(MPIU_Count a, PetscHipBLASInt *b) 184647d993e7Ssuyashtn { 184747d993e7Ssuyashtn PetscFunctionBegin; 18486497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1849462c564dSBarry 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); 1850462c564dSBarry Smith PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt64_FMT "to hipBLAS routine", (PetscInt64)a); 18516497c311SBarry Smith if (b) *b = (PetscHipBLASInt)a; 18523ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 185347d993e7Ssuyashtn } 185447d993e7Ssuyashtn 185547d993e7Ssuyashtn /*@C 1856462c564dSBarry Smith PetscMPIIntCast - casts a `MPI_Count`, `PetscInt`, `PetscCount`, or `PetscInt64` to a `PetscMPIInt` (which is always 32-bits in size), generates an 1857667f096bSBarry Smith error if the `PetscMPIInt` is not large enough to hold the number. 185861b0d812SBarry Smith 1859667f096bSBarry Smith Not Collective; No Fortran Support 186061b0d812SBarry Smith 186161b0d812SBarry Smith Input Parameter: 186287497f52SBarry Smith . a - the `PetscInt` value 186361b0d812SBarry Smith 186461b0d812SBarry Smith Output Parameter: 18656497c311SBarry Smith . b - the resulting `PetscMPIInt` value, or `NULL` if the result is not needed 186661b0d812SBarry Smith 186761b0d812SBarry Smith Level: advanced 186861b0d812SBarry Smith 18696a210b70SBarry Smith .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 187061b0d812SBarry Smith @*/ 1871462c564dSBarry Smith static inline PetscErrorCode PetscMPIIntCast(MPIU_Count a, PetscMPIInt *b) 1872d71ae5a4SJacob Faibussowitsch { 18734dc2109aSBarry Smith PetscFunctionBegin; 18746497c311SBarry Smith if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1875462c564dSBarry 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); 18766497c311SBarry Smith if (b) *b = (PetscMPIInt)a; 18773ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 18784dc2109aSBarry Smith } 18794dc2109aSBarry Smith 1880784a7648SPierre Jolivet /*@C 1881784a7648SPierre 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. 1882784a7648SPierre Jolivet 1883784a7648SPierre Jolivet Not Collective; No Fortran Support 1884784a7648SPierre Jolivet 1885784a7648SPierre Jolivet Input Parameter: 1886784a7648SPierre Jolivet . a - the `PetscInt` value 1887784a7648SPierre Jolivet 1888784a7648SPierre Jolivet Output Parameter: 1889784a7648SPierre Jolivet . b - the resulting `int` value, or `NULL` if the result is not needed 1890784a7648SPierre Jolivet 1891784a7648SPierre Jolivet Level: advanced 1892784a7648SPierre Jolivet 1893784a7648SPierre Jolivet .seealso: [](stylePetscCount), `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntCast()` 1894784a7648SPierre Jolivet @*/ 1895784a7648SPierre Jolivet static inline PetscErrorCode PetscCIntCast(MPIU_Count a, int *b) 1896784a7648SPierre Jolivet { 1897784a7648SPierre Jolivet PetscFunctionBegin; 1898784a7648SPierre Jolivet if (b) *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */ 1899784a7648SPierre 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); 1900784a7648SPierre Jolivet if (b) *b = (int)a; 1901784a7648SPierre Jolivet PetscFunctionReturn(PETSC_SUCCESS); 1902784a7648SPierre Jolivet } 1903784a7648SPierre Jolivet 1904f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b))) 19052f18eb33SBarry Smith 19062f18eb33SBarry Smith /*@C 1907f3fa974cSJacob Faibussowitsch PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive 1908f3fa974cSJacob Faibussowitsch `PetscInt` and truncates the value to slightly less than the maximal possible value. 19092f18eb33SBarry Smith 191020f4b53cSBarry Smith Not Collective; No Fortran Support 19112f18eb33SBarry Smith 1912d8d19677SJose E. Roman Input Parameters: 1913f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value 1914f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value 19152f18eb33SBarry Smith 1916667f096bSBarry Smith Level: advanced 1917667f096bSBarry Smith 1918f3fa974cSJacob Faibussowitsch Notes: 1919f3fa974cSJacob Faibussowitsch Returns the result as a `PetscInt` value. 19202f18eb33SBarry Smith 1921f3fa974cSJacob Faibussowitsch Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`. 1922667f096bSBarry Smith 1923f3fa974cSJacob Faibussowitsch Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate 1924f3fa974cSJacob Faibussowitsch to fit a `PetscInt`. 1925667f096bSBarry Smith 1926f3fa974cSJacob Faibussowitsch Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an 1927f3fa974cSJacob Faibussowitsch error if the result will not fit in a `PetscInt`. 19282f18eb33SBarry Smith 1929b5e6e808SPierre Jolivet Developer Notes: 1930f3fa974cSJacob Faibussowitsch We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but 1931f3fa974cSJacob Faibussowitsch requires many more checks. 19322f18eb33SBarry Smith 1933f3fa974cSJacob Faibussowitsch This is used where we compute approximate sizes for workspace and need to insure the 1934f3fa974cSJacob Faibussowitsch workspace is index-able. 19351fd49c25SBarry Smith 1936f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 19372f18eb33SBarry Smith @*/ 1938d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 1939d71ae5a4SJacob Faibussowitsch { 19405f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 19411690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 19422f18eb33SBarry Smith return (PetscInt)r; 19432f18eb33SBarry Smith } 19442f18eb33SBarry Smith 19452f18eb33SBarry Smith /*@C 194687497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 19472f18eb33SBarry Smith 1948667f096bSBarry Smith Not Collective; No Fortran Support 19492f18eb33SBarry Smith 1950d8d19677SJose E. Roman Input Parameters: 1951af27ebaaSBarry Smith + a - the `PetscInt` value 19522f18eb33SBarry Smith - b - the second value 19532f18eb33SBarry Smith 1954390e1bf2SBarry Smith Returns: 1955af27ebaaSBarry Smith The result as a `PetscInt` value 19562f18eb33SBarry Smith 1957667f096bSBarry Smith Level: advanced 1958667f096bSBarry Smith 1959667f096bSBarry Smith Notes: 196087497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1961667f096bSBarry Smith 196287497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1963667f096bSBarry Smith 196487497f52SBarry 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` 19652f18eb33SBarry Smith 1966b5e6e808SPierre Jolivet Developer Notes: 196787497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 19682f18eb33SBarry Smith 19692f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 19702f18eb33SBarry Smith 1971667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`, 1972667f096bSBarry Smith `PetscIntSumTruncate()` 19732f18eb33SBarry Smith @*/ 1974d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 1975d71ae5a4SJacob Faibussowitsch { 19765f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 19771690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 19782f18eb33SBarry Smith return (PetscInt)r; 19792f18eb33SBarry Smith } 19802f18eb33SBarry Smith 1981f91af8c7SBarry Smith /*@C 198287497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 1983f91af8c7SBarry Smith 1984667f096bSBarry Smith Not Collective; No Fortran Support 1985f91af8c7SBarry Smith 1986d8d19677SJose E. Roman Input Parameters: 198787497f52SBarry Smith + a - the `PetscInt` value 1988f91af8c7SBarry Smith - b - the second value 1989f91af8c7SBarry Smith 1990390e1bf2SBarry Smith Returns: 1991af27ebaaSBarry Smith The result as a `PetscInt` value 1992f91af8c7SBarry Smith 1993667f096bSBarry Smith Level: advanced 1994667f096bSBarry Smith 1995667f096bSBarry Smith Notes: 199687497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1997667f096bSBarry Smith 199887497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1999667f096bSBarry Smith 200087497f52SBarry 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` 2001f91af8c7SBarry Smith 2002b5e6e808SPierre Jolivet Developer Note: 2003f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 2004f91af8c7SBarry Smith 2005db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2006f91af8c7SBarry Smith @*/ 2007d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 2008d71ae5a4SJacob Faibussowitsch { 20095f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 20101690c2aeSBarry Smith if (r > PETSC_INT_MAX - 100) r = PETSC_INT_MAX - 100; 2011f91af8c7SBarry Smith return (PetscInt)r; 2012f91af8c7SBarry Smith } 2013f91af8c7SBarry Smith 20142f18eb33SBarry Smith /*@C 201587497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 20162f18eb33SBarry Smith 2017667f096bSBarry Smith Not Collective; No Fortran Support 20182f18eb33SBarry Smith 2019d8d19677SJose E. Roman Input Parameters: 202087497f52SBarry Smith + a - the `PetscInt` value 20212f18eb33SBarry Smith - b - the second value 20222f18eb33SBarry Smith 2023d8d19677SJose E. Roman Output Parameter: 202416a05f60SBarry 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 20252f18eb33SBarry Smith 2026667f096bSBarry Smith Level: advanced 20272f18eb33SBarry Smith 2028667f096bSBarry Smith Notes: 2029667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 2030667f096bSBarry Smith 2031667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2032f5f57ec0SBarry Smith 2033b5e6e808SPierre Jolivet Developer Note: 203416a05f60SBarry 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. 203516a05f60SBarry Smith `PetscIntSumError()` can be used to check for this situation. 20362f18eb33SBarry Smith 2037db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 20382f18eb33SBarry Smith @*/ 2039d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 2040d71ae5a4SJacob Faibussowitsch { 2041f3fa974cSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 20422f18eb33SBarry Smith 20432f18eb33SBarry Smith PetscFunctionBegin; 2044c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 2045f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 20461690c2aeSBarry 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); 2047f3fa974cSJacob Faibussowitsch } 20483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2049f91af8c7SBarry Smith } 2050f91af8c7SBarry Smith 2051f91af8c7SBarry Smith /*@C 2052f91af8c7SBarry Smith 205387497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 2054f91af8c7SBarry Smith 2055667f096bSBarry Smith Not Collective; No Fortran Support 2056f91af8c7SBarry Smith 2057d8d19677SJose E. Roman Input Parameters: 205887497f52SBarry Smith + a - the `PetscInt` value 2059f91af8c7SBarry Smith - b - the second value 2060f91af8c7SBarry Smith 2061d8d19677SJose E. Roman Output Parameter: 206216a05f60SBarry 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 2063f91af8c7SBarry Smith 2064f91af8c7SBarry Smith Level: advanced 2065f91af8c7SBarry Smith 2066667f096bSBarry Smith Notes: 20677de69702SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64` 2068667f096bSBarry Smith 2069667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 2070667f096bSBarry Smith 2071db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 2072f91af8c7SBarry Smith @*/ 2073d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 2074d71ae5a4SJacob Faibussowitsch { 2075f3fa974cSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 2076f91af8c7SBarry Smith 2077f91af8c7SBarry Smith PetscFunctionBegin; 2078c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 2079f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 20801690c2aeSBarry 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); 2081f3fa974cSJacob Faibussowitsch } 20823ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 20832f18eb33SBarry Smith } 2084c5df96a5SBarry Smith 2085d382aafbSBarry Smith /* 20862981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2087d382aafbSBarry Smith */ 2088d382aafbSBarry Smith #if defined(hz) 2089d382aafbSBarry Smith #undef hz 2090d382aafbSBarry Smith #endif 2091d382aafbSBarry Smith 2092d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 2093d382aafbSBarry Smith #include <sys/types.h> 2094d382aafbSBarry Smith #endif 2095d382aafbSBarry Smith 2096d382aafbSBarry Smith /*MC 2097d382aafbSBarry Smith 209866d79e26SBarry 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++ 209916a05f60SBarry Smith and Fortran compilers when `petscsys.h` is included. 210066d79e26SBarry Smith 2101baca6076SPierre 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> 210266d79e26SBarry Smith 210366d79e26SBarry 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) 210466d79e26SBarry Smith 210566d79e26SBarry 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 210666d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 210766d79e26SBarry Smith 210866d79e26SBarry 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 210966d79e26SBarry Smith 211066d79e26SBarry 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), 211166d79e26SBarry 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 211266d79e26SBarry Smith version number (x.y.z). 211366d79e26SBarry Smith 211487497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 211566d79e26SBarry Smith 211687497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 211766d79e26SBarry Smith 211887497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 211966d79e26SBarry Smith 212087497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 212166d79e26SBarry Smith 212287497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 212366d79e26SBarry Smith 2124cbc12506SBarry Smith Level: intermediate 212566d79e26SBarry Smith M*/ 212666d79e26SBarry Smith 2127014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 2128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 2129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 2130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 2131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 213327710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 21345f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 2135d382aafbSBarry Smith 21366497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscCount, const PetscInt[], PetscBool *); 21376497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscCount, const PetscInt64[], PetscBool *); 21386497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscCount, const PetscMPIInt[], PetscBool *); 21396497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscCount, const PetscReal[], PetscBool *); 21406497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt(PetscCount, PetscInt[]); 21416497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscCount, PetscInt64[]); 21426497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortCount(PetscCount, PetscCount[]); 21436497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscCount, PetscInt[]); 214422ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 21456497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscCount, const PetscInt[], PetscBool *); 2146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2147f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 21486497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscCount, const PetscInt[], PetscInt *); 21496497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscCount, const PetscMPIInt[], PetscInt *); 2150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 21526497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscCount, PetscInt[], PetscInt[]); 2153981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 21546497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithMPIIntArray(PetscCount, PetscInt[], PetscMPIInt[]); 21556497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscCount, PetscInt[], PetscInt[], PetscInt[]); 2156981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 21576497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscCount, PetscMPIInt[]); 215817d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 21596497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscCount, PetscMPIInt[], PetscMPIInt[]); 21606497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscCount, PetscMPIInt[], PetscInt[]); 21616497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscCount, PetscInt[], PetscScalar[]); 21626497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscCount, PetscInt[], void *, size_t, void *); 21636497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortReal(PetscCount, PetscReal[]); 21646497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscCount, PetscReal[], PetscInt[]); 2165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2166745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 21676497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscCount, const PetscReal[], PetscReal, PetscInt *); 2168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2169014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2170014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 21716c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 21726c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2173e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2174ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2175ce605777SToby Isaac 21764d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2177676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2178676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2179676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 21804d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2181676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2182676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2183676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2184676f2a66SJacob Faibussowitsch 2185014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2186014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2187d382aafbSBarry Smith 218876bdecfbSBarry Smith /*J 2189d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2190d382aafbSBarry Smith 2191d382aafbSBarry Smith Level: beginner 2192d382aafbSBarry Smith 2193667f096bSBarry Smith Note: 219487497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 219516a05f60SBarry Smith with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc. 2196d382aafbSBarry Smith 2197db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 219876bdecfbSBarry Smith J*/ 219919fd82e9SBarry Smith typedef const char *PetscRandomType; 2200d382aafbSBarry Smith #define PETSCRAND "rand" 2201d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2202d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2203c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 220425ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2205808ba619SStefano Zampini #define PETSCCURAND "curand" 2206d382aafbSBarry Smith 2207d382aafbSBarry Smith /* Logging support */ 2208014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2209d382aafbSBarry Smith 2210607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 22114bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void); 2212d382aafbSBarry Smith 2213d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2214140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2215d382aafbSBarry Smith 2216bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 221719fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 221844ffe595SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomSetOptionsPrefix(PetscRandom, const char[]); 2219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 222019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2221fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2222014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2223d382aafbSBarry Smith 2224014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2225014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2226014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2227808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2228808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2229014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2233014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2234014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2235d382aafbSBarry Smith 2236014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2238014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2241014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2242014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 224397540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 22448a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 224597540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2246d382aafbSBarry Smith 2247d598313aSBarry Smith /*MC 2248d598313aSBarry Smith PetscBinaryBigEndian - indicates if values in memory are stored with big endian format 2249d598313aSBarry Smith 2250d598313aSBarry Smith Synopsis: 2251d598313aSBarry Smith #include <petscsys.h> 2252d598313aSBarry Smith PetscBool PetscBinaryBigEndian(void); 2253d598313aSBarry Smith 2254d598313aSBarry Smith No Fortran Support 2255d598313aSBarry Smith 2256d598313aSBarry Smith Level: developer 2257d598313aSBarry Smith 2258d598313aSBarry Smith .seealso: `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled` 2259d598313aSBarry Smith M*/ 2260d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2261d71ae5a4SJacob Faibussowitsch { 22629371c9d4SSatish Balay long _petsc_v = 1; 22639371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 22649371c9d4SSatish Balay } 226530815ce0SLisandro Dalcin 22666497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscCount, PetscInt *, PetscDataType); 22679860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 22686497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscCount, PetscDataType); 2269f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2270014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2271014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2272014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2273014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2277c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2278e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2279c891a504SStefano Zampini #endif 2280d382aafbSBarry Smith 2281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2282014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 22836497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscCount); 2284d382aafbSBarry Smith 2285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2286014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2287014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2288014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2289014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 22912a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2292d382aafbSBarry Smith 2293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 229893d501b3SJacob 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); 229993d501b3SJacob 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); 230093d501b3SJacob 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); 2301d382aafbSBarry Smith 23026145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 23036145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 23046145cd65SJed Brown 2305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2306d382aafbSBarry Smith 2307ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2308ce94432eSBarry Smith 2309d382aafbSBarry Smith struct _n_PetscSubcomm { 2310d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2311d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2312306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 231345487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 231445487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2315708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 231645487dadSJed Brown PetscSubcommType type; 2317e5acf8a4SHong Zhang char *subcommprefix; 2318d382aafbSBarry Smith }; 2319d382aafbSBarry Smith 2320d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2321d71ae5a4SJacob Faibussowitsch { 23229371c9d4SSatish Balay return scomm->parent; 23239371c9d4SSatish Balay } 2324d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2325d71ae5a4SJacob Faibussowitsch { 23269371c9d4SSatish Balay return scomm->child; 23279371c9d4SSatish Balay } 2328d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2329d71ae5a4SJacob Faibussowitsch { 23309371c9d4SSatish Balay return scomm->dupparent; 23319371c9d4SSatish Balay } 2332014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2333014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2334014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2335014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 233665d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2337053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2338f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2339e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2340a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2341a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2342a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2343d382aafbSBarry Smith 23449962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 23459962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 23469962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 23479962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 23489962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 23499962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 23509962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 23519962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 23529962606eSBarry Smith 23535e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 23545f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 23555f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 23565f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 23575f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 23585e71baefSBarry Smith 2359a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2360a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2361a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2362a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2363a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2364a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2365a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2366a32e93adSJunchao Zhang 23676497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, PetscCount, PetscSegBuffer *); 23680f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 23696497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, PetscCount, void *); 2370137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2371137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2372137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 23736497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, PetscCount *); 23746497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, PetscCount); 23750f453b92SJed Brown 2376d598313aSBarry Smith /*MC 2377d598313aSBarry Smith PetscSegBufferGetInts - access an array of `PetscInt` from a `PetscSegBuffer` 2378d598313aSBarry Smith 2379d598313aSBarry Smith Synopsis: 2380d598313aSBarry Smith #include <petscsys.h> 2381d598313aSBarry Smith PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot); 2382d598313aSBarry Smith 2383d598313aSBarry Smith No Fortran Support 2384d598313aSBarry Smith 2385d598313aSBarry Smith Input Parameters: 2386d598313aSBarry Smith + seg - `PetscSegBuffer` buffer 2387d598313aSBarry Smith - count - number of entries needed 2388d598313aSBarry Smith 2389d598313aSBarry Smith Output Parameter: 2390d598313aSBarry Smith . buf - address of new buffer for contiguous data 2391d598313aSBarry Smith 2392d598313aSBarry Smith Level: intermediate 2393d598313aSBarry Smith 2394d598313aSBarry Smith Developer Note: 2395d598313aSBarry Smith Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2396d598313aSBarry Smith prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2397d598313aSBarry Smith possible. 2398d598313aSBarry Smith 2399d598313aSBarry Smith .seealso: `PetscSegBuffer`, `PetscSegBufferGet()`, `PetscInitialize()`, `PetscFinalize()`, `PetscInitializeCalled` 2400d598313aSBarry Smith M*/ 2401d598313aSBarry Smith /* */ 24026497c311SBarry Smith static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, PetscCount count, PetscInt *PETSC_RESTRICT *slot) 2403d71ae5a4SJacob Faibussowitsch { 24049371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 24059371c9d4SSatish Balay } 2406d382aafbSBarry Smith 24079de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 24089de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 24099de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 24109de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 24119de0f6ecSBarry Smith 2412ace2fbaeSBarry Smith #include <stdarg.h> 2413ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2414ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2415ace2fbaeSBarry Smith 2416268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2417fbfcfee5SBarry Smith 24185d83a8b1SBarry Smith /*@ 24191f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 24201f817a21SBarry Smith 2421667f096bSBarry Smith Not Collective; No Fortran Support 24221f817a21SBarry Smith 24231f817a21SBarry Smith Input Parameters: 242435cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely 242587497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 24261f817a21SBarry Smith 2427667f096bSBarry Smith Options Database Key: 24283c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation 24293c7db156SBarry Smith 2430850545d0SSatish Balay Level: intermediate 24311f817a21SBarry Smith @*/ 2432d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2433d71ae5a4SJacob Faibussowitsch { 2434dff31646SBarry Smith size_t len; 2435dff31646SBarry Smith char *vstring; 2436dff31646SBarry Smith 24371f817a21SBarry Smith PetscFunctionBegin; 24383ba16761SJacob Faibussowitsch if (set && *set) PetscFunctionReturn(PETSC_SUCCESS); 24399566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 244035d731d1SLisandro Dalcin PetscCall(PetscSegBufferGet(PetscCitationsList, (PetscCount)len, &vstring)); 24419566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2442dff31646SBarry Smith if (set) *set = PETSC_TRUE; 24433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2444dff31646SBarry Smith } 2445dff31646SBarry Smith 2446fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2447fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2448f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2449fe278a28SBarry Smith 2450f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2451f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 24524bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]); 2453b967cddfSBarry Smith 24549f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 24554bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t); 24564bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]); 24579f4d3c52SBarry Smith 245868e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 24595dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2460dff31646SBarry Smith 24616497c311SBarry Smith #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 24626497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 24636497c311SBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 24646497c311SBarry Smith #endif 24656497c311SBarry Smith 24666497c311SBarry Smith #if !defined(PETSC_HAVE_MPI_LARGE_COUNT) 2467462c564dSBarry Smith /* 2468462c564dSBarry Smith Cast PetscCount <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines. 24696497c311SBarry Smith It is similar to PetscMPIIntCast() except that here it returns an MPI error code. 24706497c311SBarry Smith */ 2471462c564dSBarry Smith #define PetscMPIIntCast_Internal(a, b) \ 2472462c564dSBarry Smith do { \ 2473462c564dSBarry Smith *b = 0; \ 2474462c564dSBarry Smith if (PetscUnlikely(a > (MPIU_Count)PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT; \ 2475462c564dSBarry Smith *b = (PetscMPIInt)a; \ 2476462c564dSBarry Smith } while (0) 24776497c311SBarry Smith 24786497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count) 24796497c311SBarry Smith { 2480462c564dSBarry Smith PetscMPIInt count2, err; 24816497c311SBarry Smith 24826497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */ 2483462c564dSBarry Smith err = MPI_Get_count(status, dtype, &count2); 24846497c311SBarry Smith *count = count2; 2485462c564dSBarry Smith return err; 24866497c311SBarry Smith } 24876497c311SBarry Smith 2488462c564dSBarry Smith static inline PetscMPIInt MPIU_Send(const void *buf, MPIU_Count count, MPI_Datatype dtype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm) 24896497c311SBarry Smith { 2490462c564dSBarry Smith PetscMPIInt count2, err; 24916497c311SBarry Smith 2492462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2493462c564dSBarry Smith err = MPI_Send((void *)buf, count2, dtype, dest, tag, comm); 2494462c564dSBarry Smith return err; 24956497c311SBarry Smith } 24966497c311SBarry Smith 2497462c564dSBarry 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) 24986497c311SBarry Smith { 2499462c564dSBarry Smith PetscMPIInt count2, err; 25006497c311SBarry Smith 2501462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2502462c564dSBarry Smith err = MPI_Send_init((void *)buf, count2, dtype, dest, tag, comm, request); 2503462c564dSBarry Smith return err; 25046497c311SBarry Smith } 25056497c311SBarry Smith 2506462c564dSBarry 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) 25076497c311SBarry Smith { 2508462c564dSBarry Smith PetscMPIInt count2, err; 25096497c311SBarry Smith 2510462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2511462c564dSBarry Smith err = MPI_Isend((void *)buf, count2, dtype, dest, tag, comm, request); 2512462c564dSBarry Smith return err; 25136497c311SBarry Smith } 25146497c311SBarry Smith 2515462c564dSBarry 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) 25166497c311SBarry Smith { 2517462c564dSBarry Smith PetscMPIInt count2, err; 25186497c311SBarry Smith 2519462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2520462c564dSBarry Smith err = MPI_Recv((void *)buf, count2, dtype, source, tag, comm, status); 2521462c564dSBarry Smith return err; 25226497c311SBarry Smith } 25236497c311SBarry Smith 2524462c564dSBarry 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) 25256497c311SBarry Smith { 2526462c564dSBarry Smith PetscMPIInt count2, err; 25276497c311SBarry Smith 2528462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2529462c564dSBarry Smith err = MPI_Recv_init((void *)buf, count2, dtype, source, tag, comm, request); 2530462c564dSBarry Smith return err; 25316497c311SBarry Smith } 25326497c311SBarry Smith 2533462c564dSBarry 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) 25346497c311SBarry Smith { 2535462c564dSBarry Smith PetscMPIInt count2, err; 25366497c311SBarry Smith 2537462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2538462c564dSBarry Smith err = MPI_Irecv((void *)buf, count2, dtype, source, tag, comm, request); 2539462c564dSBarry Smith return err; 25406497c311SBarry Smith } 25416497c311SBarry Smith 2542462c564dSBarry 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) 25436497c311SBarry Smith { 2544462c564dSBarry Smith PetscMPIInt count2, err; 25456497c311SBarry Smith 2546462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2547462c564dSBarry Smith err = MPI_Reduce((void *)inbuf, outbuf, count2, dtype, op, root, comm); 2548462c564dSBarry Smith return err; 25496497c311SBarry Smith } 25506497c311SBarry Smith 25516497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL) 2552462c564dSBarry Smith static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, MPIU_Count count, MPI_Datatype dtype, MPI_Op op) 25536497c311SBarry Smith { 2554462c564dSBarry Smith PetscMPIInt count2, err; 25556497c311SBarry Smith 2556462c564dSBarry Smith PetscMPIIntCast_Internal(count, &count2); 2557462c564dSBarry Smith err = MPI_Reduce_local((void *)inbuf, inoutbuf, count2, dtype, op); 2558462c564dSBarry Smith return err; 25596497c311SBarry Smith } 25606497c311SBarry Smith #endif 25616497c311SBarry Smith 25626497c311SBarry Smith #else 25636497c311SBarry Smith 25646497c311SBarry Smith /* on 32 bit systems MPI_Count maybe 64-bit while PetscCount is 32-bit */ 2565462c564dSBarry Smith #define PetscCountCast_Internal(a, b) \ 2566462c564dSBarry Smith do { \ 2567462c564dSBarry Smith *b = 0; \ 2568462c564dSBarry Smith if (PetscUnlikely(a > (MPI_Count)PETSC_COUNT_MAX)) return MPI_ERR_COUNT; \ 2569462c564dSBarry Smith *b = (PetscMPIInt)a; \ 2570462c564dSBarry Smith } while (0) 25716497c311SBarry Smith 25726497c311SBarry Smith static inline PetscMPIInt MPIU_Get_count(MPI_Status *status, MPI_Datatype dtype, PetscCount *count) 25736497c311SBarry Smith { 25746497c311SBarry Smith MPI_Count count2; 2575462c564dSBarry Smith PetscMPIInt err; 25766497c311SBarry Smith 25776497c311SBarry Smith *count = 0; /* to prevent incorrect warnings of uninitialized variables */ 2578462c564dSBarry Smith err = MPI_Get_count_c(status, dtype, &count2); 2579462c564dSBarry Smith if (err) return err; 2580462c564dSBarry Smith PetscCountCast_Internal(count2, count); 2581462c564dSBarry Smith return MPI_SUCCESS; 25826497c311SBarry Smith } 25836497c311SBarry Smith 25846497c311SBarry Smith #define MPIU_Reduce(inbuf, outbuf, count, dtype, op, root, comm) MPI_Reduce_c(inbuf, outbuf, (MPI_Count)(count), dtype, op, root, comm) 25856497c311SBarry Smith #define MPIU_Send(buf, count, dtype, dest, tag, comm) MPI_Send_c(buf, (MPI_Count)(count), dtype, dest, tag, comm) 25866497c311SBarry 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) 25876497c311SBarry Smith #define MPIU_Isend(buf, count, dtype, dest, tag, comm, request) MPI_Isend_c(buf, (MPI_Count)(count), dtype, dest, tag, comm, request) 25886497c311SBarry Smith #define MPIU_Recv(buf, count, dtype, source, tag, comm, status) MPI_Recv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, status) 25896497c311SBarry 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) 25906497c311SBarry Smith #define MPIU_Irecv(buf, count, dtype, source, tag, comm, request) MPI_Irecv_c(buf, (MPI_Count)(count), dtype, source, tag, comm, request) 25916497c311SBarry Smith #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL) 25926a210b70SBarry Smith #define MPIU_Reduce_local(inbuf, inoutbuf, count, dtype, op) MPI_Reduce_local_c(inbuf, inoutbuf, (MPI_Count)(count), dtype, op) 25936497c311SBarry Smith #endif 25946497c311SBarry Smith #endif 25956497c311SBarry Smith 2596462c564dSBarry Smith PETSC_EXTERN PetscMPIInt MPIU_Allreduce_Private(const void *, void *, MPIU_Count, MPI_Datatype, MPI_Op, MPI_Comm); 25976a210b70SBarry Smith 2598b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2599d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2600d71ae5a4SJacob Faibussowitsch { 2601df05ca09SBarry Smith unsigned int c, hash = 5381; 2602df05ca09SBarry Smith 2603503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2604df05ca09SBarry Smith return hash; 2605df05ca09SBarry Smith } 26066497c311SBarry Smith #endif 260777a5e07dSBarry Smith 260877a5e07dSBarry Smith /*MC 2609462c564dSBarry Smith MPIU_Allreduce - A replacement for `MPI_Allreduce()` that (1) performs single-count `MPIU_INT` operations in `PetscInt64` to detect 2610462c564dSBarry Smith integer overflows and (2) tries to determine if the call from all the MPI ranks occur in the 261187497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 261287497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 261377a5e07dSBarry Smith 261477a5e07dSBarry Smith Synopsis: 261577a5e07dSBarry Smith #include <petscsys.h> 2616462c564dSBarry Smith PetscMPIInt MPIU_Allreduce(void *indata,void *outdata,PetscCount count,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm); 261777a5e07dSBarry Smith 26187cdbe19fSJose E. Roman Collective 26197cdbe19fSJose E. Roman 262077a5e07dSBarry Smith Input Parameters: 26216a210b70SBarry Smith + a - pointer to the input data to be reduced 26226a210b70SBarry Smith . count - the number of MPI data items in `a` and `b` 26236497c311SBarry Smith . dtype - the MPI datatype, for example `MPI_INT` 26246497c311SBarry Smith . op - the MPI operation, for example `MPI_SUM` 26256497c311SBarry Smith - comm - the MPI communicator on which the operation occurs 262677a5e07dSBarry Smith 262777a5e07dSBarry Smith Output Parameter: 26286a210b70SBarry Smith . b - the reduced values 262977a5e07dSBarry Smith 2630667f096bSBarry Smith Level: developer 2631667f096bSBarry Smith 2632462c564dSBarry Smith Note: 2633462c564dSBarry Smith Should be wrapped with `PetscCallMPI()` for error checking 2634462c564dSBarry Smith 26356497c311SBarry Smith .seealso: [](stylePetscCount), `MPI_Allreduce()` 263677a5e07dSBarry Smith M*/ 26376497c311SBarry Smith #if defined(PETSC_USE_DEBUG) 26389371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 26393ba16761SJacob Faibussowitsch PetscMacroReturnStandard( \ 26403ba16761SJacob Faibussowitsch PetscMPIInt a_b1[6], a_b2[6]; \ 26413ba16761SJacob Faibussowitsch int _mpiu_allreduce_c_int = (int)(c); \ 26423ba16761SJacob Faibussowitsch a_b1[0] = -(PetscMPIInt)__LINE__; \ 26433ba16761SJacob Faibussowitsch a_b1[1] = -a_b1[0]; \ 26443ba16761SJacob Faibussowitsch a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \ 26453ba16761SJacob Faibussowitsch a_b1[3] = -a_b1[2]; \ 26463ba16761SJacob Faibussowitsch a_b1[4] = -(PetscMPIInt)(c); \ 26473ba16761SJacob Faibussowitsch a_b1[5] = -a_b1[4]; \ 26483ba16761SJacob Faibussowitsch \ 26493ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \ 2650462c564dSBarry Smith PetscCheck(-a_b2[0] == a_b2[1], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (code lines) on different processors"); \ 2651462c564dSBarry Smith PetscCheck(-a_b2[2] == a_b2[3], (fcomm), PETSC_ERR_PLIB, "MPIU_Allreduce() called in different locations (functions) on different processors"); \ 2652462c564dSBarry 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); \ 26536a210b70SBarry Smith PetscCallMPI(MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)));) 2654b2566f29SBarry Smith #else 2655462c564dSBarry Smith #define MPIU_Allreduce(a, b, c, d, e, fcomm) MPIU_Allreduce_Private((a), (b), (c), (d), (e), (fcomm)) 2656b2566f29SBarry Smith #endif 2657b2566f29SBarry Smith 2658b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 26598198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 26608198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 26612f065d89SBarry Smith #endif 26628198064fSBarry Smith 2663cd88fca5SStefano Zampini /* this is a vile hack */ 2664cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 26659371c9d4SSatish 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) 2666cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2667cd88fca5SStefano Zampini #endif 2668961fb248SStefano Zampini #endif 2669cd88fca5SStefano Zampini 267012801b39SBarry Smith /* 267160fbe2beSVaclav Hapla List of external packages and queries on it 267260fbe2beSVaclav Hapla */ 267360fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 267460fbe2beSVaclav Hapla 2675f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2676f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2677f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 26787a99bfcaSBarry Smith PETSC_EXTERN PetscBool PCMPIServerActive; 26799f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerInSolve; 26809f0612e4SBarry Smith PETSC_EXTERN PetscBool PCMPIServerUseShmget; 26819f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAllocateArray(size_t, size_t, void **); 26829f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetDeallocateArray(void **); 26839f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetMapAddresses(MPI_Comm, PetscInt, const void **, void **); 26849f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetUnmapAddresses(PetscInt, void **); 26859f0612e4SBarry Smith PETSC_EXTERN PetscErrorCode PetscShmgetAddressesFinalize(void); 26869f0612e4SBarry Smith 26879f0612e4SBarry Smith typedef struct { 26889f0612e4SBarry Smith PetscInt n; 26899f0612e4SBarry Smith void *addr[3]; 26909f0612e4SBarry Smith } PCMPIServerAddresses; 2691*49abdd8aSBarry Smith PETSC_EXTERN PetscCtxDestroyFn PCMPIServerAddressesDestroy; 2692fbf9dbe5SBarry Smith 2693edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS 2694046ed546SBarry Smith 2695046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt); 2696046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *); 26978e3a54c0SPierre Jolivet 26988e3a54c0SPierre Jolivet /*MC 26998e3a54c0SPierre Jolivet PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset 27008e3a54c0SPierre Jolivet 27018e3a54c0SPierre Jolivet Level: beginner 27028e3a54c0SPierre Jolivet 27038e3a54c0SPierre Jolivet Note: 27048e3a54c0SPierre Jolivet This is needed to avoid errors with undefined-behavior sanitizers such as 27058e3a54c0SPierre Jolivet UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags 27068e3a54c0SPierre Jolivet M*/ 27078e3a54c0SPierre Jolivet #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL) 2708