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> 181c77a0c5SBarry Smith #include <petscconf_poison.h> 192c8e378dSBarry Smith #include <petscfix.h> 20bde483f2SJacob Faibussowitsch #include <petscmacros.h> 2133bb201bSJacob Faibussowitsch 22ac09b921SBarry Smith /* SUBMANSEC = Sys */ 23ac09b921SBarry Smith 2473fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 2573fca5a0SBarry Smith /* 2673fca5a0SBarry Smith Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 2773fca5a0SBarry Smith We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 2873fca5a0SBarry Smith */ 29216f1ae6SBarry Smith #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 3073fca5a0SBarry Smith #define _POSIX_C_SOURCE 200112L 3173fca5a0SBarry Smith #endif 32216f1ae6SBarry Smith #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 3373fca5a0SBarry Smith #define _BSD_SOURCE 3473fca5a0SBarry Smith #endif 3507f00807SSatish Balay #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 3607f00807SSatish Balay #define _DEFAULT_SOURCE 3707f00807SSatish Balay #endif 38ea0fecefSShri Abhyankar #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 39ea0fecefSShri Abhyankar #define _GNU_SOURCE 40ea0fecefSShri Abhyankar #endif 4173fca5a0SBarry Smith #endif 4273fca5a0SBarry Smith 43df4397b0SStefano Zampini #include <petscsystypes.h> 44df4397b0SStefano Zampini 45d382aafbSBarry Smith /* ========================================================================== */ 46d382aafbSBarry Smith 47d382aafbSBarry Smith /* 48d382aafbSBarry Smith Defines the interface to MPI allowing the use of all MPI functions. 49d382aafbSBarry Smith 50d382aafbSBarry Smith PETSc does not use the C++ binding of MPI at ALL. The following flag 51d382aafbSBarry Smith makes sure the C++ bindings are not included. The C++ bindings REQUIRE 52d382aafbSBarry Smith putting mpi.h before ANY C++ include files, we cannot control this 53d382aafbSBarry Smith with all PETSc users. Users who want to use the MPI C++ bindings can include 54d382aafbSBarry Smith mpicxx.h directly in their code 55d382aafbSBarry Smith */ 56fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX) 57d382aafbSBarry Smith #define MPICH_SKIP_MPICXX 1 58fa9e63e2SJed Brown #endif 59fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX) 60d382aafbSBarry Smith #define OMPI_SKIP_MPICXX 1 61fa9e63e2SJed Brown #endif 62e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI) 63e771154cSJed Brown #include <petsc/mpiuni/mpi.h> 64e771154cSJed Brown #else 652c8e378dSBarry Smith #include <mpi.h> 66e771154cSJed Brown #endif 6765013866SBarry Smith 68d382aafbSBarry Smith /* 69a7886beaSBarry Smith Perform various sanity checks that the correct mpi.h is being included at compile time. 70a7886beaSBarry Smith This usually happens because 71a7886beaSBarry Smith * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 72a7886beaSBarry Smith * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 73a7886beaSBarry Smith */ 74a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI) 756524c165SJacob Faibussowitsch #ifndef MPIUNI_H 76a7886beaSBarry Smith #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 77a7886beaSBarry Smith #endif 7841f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 7941f4af4cSSatish Balay #if !defined(I_MPI_NUMVERSION) 8041f4af4cSSatish Balay #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 8141f4af4cSSatish Balay #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 8241f4af4cSSatish 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" 8341f4af4cSSatish Balay #endif 8441f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 8541f4af4cSSatish Balay #if !defined(MVAPICH2_NUMVERSION) 8641f4af4cSSatish Balay #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 8741f4af4cSSatish Balay #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 8841f4af4cSSatish Balay #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 8941f4af4cSSatish Balay #endif 90a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 9141f4af4cSSatish Balay #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 92a7886beaSBarry Smith #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 931c284764SMin RK #elif (MPICH_NUMVERSION / 100000000 != PETSC_HAVE_MPICH_NUMVERSION / 100000000) || (MPICH_NUMVERSION / 100000 < PETSC_HAVE_MPICH_NUMVERSION / 100000) || (MPICH_NUMVERSION / 100000 == PETSC_HAVE_MPICH_NUMVERSION / 100000 && MPICH_NUMVERSION % 100000 / 1000 < PETSC_HAVE_MPICH_NUMVERSION % 100000 / 1000) 94a7886beaSBarry Smith #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 95a7886beaSBarry Smith #endif 96a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 97a7886beaSBarry Smith #if !defined(OMPI_MAJOR_VERSION) 98a7886beaSBarry Smith #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h" 991c284764SMin RK #elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION < PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_MINOR_VERSION == PETSC_HAVE_OMPI_MINOR_VERSION && OMPI_RELEASE_VERSION < PETSC_HAVE_OMPI_RELEASE_VERSION) 100c3ac57cfSSatish 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" 101a7886beaSBarry Smith #endif 102d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION) 103d97fd468SStefano Zampini #if !defined(MSMPI_VER) 104d97fd468SStefano Zampini #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 105d97fd468SStefano Zampini #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 106d97fd468SStefano Zampini #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 107d97fd468SStefano Zampini #endif 108d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 109d97fd468SStefano 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" 110a7886beaSBarry Smith #endif 111a7886beaSBarry Smith 112a7886beaSBarry Smith /* 1132981ebdbSBarry Smith Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 114d382aafbSBarry Smith see the top of mpicxx.h in the MPICH2 distribution. 115d382aafbSBarry Smith */ 116d382aafbSBarry Smith #include <stdio.h> 117d382aafbSBarry Smith 1187de69702SBarry Smith /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */ 119d382aafbSBarry Smith #if !defined(MPIAPI) 120d382aafbSBarry Smith #define MPIAPI 121d382aafbSBarry Smith #endif 122d382aafbSBarry Smith 12393d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 12493d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 125e28ce29aSPatrick Sanan 126e28ce29aSPatrick Sanan /*MC 12787497f52SBarry Smith MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 128e28ce29aSPatrick Sanan 129667f096bSBarry Smith Level: beginner 130667f096bSBarry Smith 13138b83642SBarry Smith Note: 13287497f52SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 133e28ce29aSPatrick Sanan 13438b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 135e28ce29aSPatrick Sanan M*/ 136e28ce29aSPatrick Sanan 1377cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 138b7b8f77aSBarry Smith 139d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 140bd84f1cfSSatish Balay #define MPIU_INT MPIU_INT64 141d382aafbSBarry Smith #else 142d382aafbSBarry Smith #define MPIU_INT MPI_INT 143d382aafbSBarry Smith #endif 144d382aafbSBarry Smith 14538b83642SBarry Smith /*MC 14638b83642SBarry Smith MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount` 14738b83642SBarry Smith 14838b83642SBarry Smith Level: beginner 14938b83642SBarry Smith 15038b83642SBarry Smith Note: 15138b83642SBarry Smith In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value. 15238b83642SBarry Smith 15338b83642SBarry Smith Developer Note: 15495bd0b28SBarry Smith It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed 15538b83642SBarry Smith 15638b83642SBarry Smith .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 15738b83642SBarry Smith M*/ 15838b83642SBarry Smith #define MPIU_COUNT MPI_AINT 15938b83642SBarry Smith 160503cfb0cSBarry Smith /* 161503cfb0cSBarry Smith For the rare cases when one needs to send a size_t object with MPI 162503cfb0cSBarry Smith */ 16393d501b3SJacob Faibussowitsch PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 164d382aafbSBarry Smith 165d382aafbSBarry Smith /* 166d382aafbSBarry Smith You can use PETSC_STDOUT as a replacement of stdout. You can also change 167d382aafbSBarry Smith the value of PETSC_STDOUT to redirect all standard output elsewhere 168d382aafbSBarry Smith */ 169014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDOUT; 170d382aafbSBarry Smith 171d382aafbSBarry Smith /* 172d382aafbSBarry Smith You can use PETSC_STDERR as a replacement of stderr. You can also change 173d382aafbSBarry Smith the value of PETSC_STDERR to redirect all standard error elsewhere 174d382aafbSBarry Smith */ 175014dd563SJed Brown PETSC_EXTERN FILE *PETSC_STDERR; 176d382aafbSBarry Smith 177d382aafbSBarry Smith /* 178dc07da0dSStefano Zampini Handle inclusion when using clang compiler with CUDA support 179dc07da0dSStefano Zampini __float128 is not available for the device 180dc07da0dSStefano Zampini */ 181dc07da0dSStefano Zampini #if defined(__clang__) && defined(__CUDA_ARCH__) 182dc07da0dSStefano Zampini #define PETSC_SKIP_REAL___FLOAT128 183dc07da0dSStefano Zampini #endif 184dc07da0dSStefano Zampini 185dc07da0dSStefano Zampini /* 186d382aafbSBarry Smith Declare extern C stuff after including external header files 187d382aafbSBarry Smith */ 188d382aafbSBarry Smith 1896edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 1908b49ba18SBarry Smith /* 191390e1bf2SBarry Smith Defines elementary mathematics functions and constants. 1928b49ba18SBarry Smith */ 1938b49ba18SBarry Smith #include <petscmath.h> 1948b49ba18SBarry Smith 195d382aafbSBarry Smith /*MC 196667f096bSBarry Smith PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument 197d382aafbSBarry Smith 198d382aafbSBarry Smith Level: beginner 199d382aafbSBarry Smith 200e28ce29aSPatrick Sanan Note: 201667f096bSBarry Smith Accepted by many PETSc functions to not set a parameter and instead use a default value 202d382aafbSBarry Smith 20387497f52SBarry Smith Fortran Note: 204667f096bSBarry Smith Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 205d382aafbSBarry Smith 206db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 207d382aafbSBarry Smith M*/ 208f3fa974cSJacob Faibussowitsch #define PETSC_IGNORE PETSC_NULLPTR 209edd03b47SJacob Faibussowitsch #define PETSC_NULL PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR 210c528d872SBarry Smith 211d382aafbSBarry Smith /*MC 212557d4da8SBarry Smith PETSC_DECIDE - standard way of passing in integer or floating point parameter 213557d4da8SBarry Smith where you wish PETSc to use the default. 214557d4da8SBarry Smith 215557d4da8SBarry Smith Level: beginner 216557d4da8SBarry Smith 217db781477SPatrick Sanan .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 218557d4da8SBarry Smith M*/ 219557d4da8SBarry Smith 220557d4da8SBarry Smith /*MC 221af27ebaaSBarry Smith PETSC_DETERMINE - standard way of passing in integer or floating point parameter where you wish PETSc to compute the required value. 222d382aafbSBarry Smith 223d382aafbSBarry Smith Level: beginner 224d382aafbSBarry Smith 225e28ce29aSPatrick Sanan Developer Note: 22687497f52SBarry Smith I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 22787497f52SBarry Smith some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 228557d4da8SBarry Smith 229db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 230d382aafbSBarry Smith M*/ 231d382aafbSBarry Smith 232d382aafbSBarry Smith /*MC 233af27ebaaSBarry Smith PETSC_DEFAULT - standard way of passing in integer or floating point parameter where you wish PETSc to use the default. 234557d4da8SBarry Smith 235557d4da8SBarry Smith Level: beginner 236557d4da8SBarry Smith 23787497f52SBarry Smith Fortran Note: 23887497f52SBarry Smith You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 239557d4da8SBarry Smith 240db781477SPatrick Sanan .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 241557d4da8SBarry Smith M*/ 24205c2f48cSJacob Faibussowitsch 24305c2f48cSJacob Faibussowitsch /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */ 24405c2f48cSJacob Faibussowitsch #define PETSC_DECIDE (-1) 24505c2f48cSJacob Faibussowitsch #define PETSC_DETERMINE PETSC_DECIDE 24605c2f48cSJacob Faibussowitsch #define PETSC_DEFAULT (-2) 247557d4da8SBarry Smith 248557d4da8SBarry Smith /*MC 249af27ebaaSBarry Smith PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about. 250d382aafbSBarry Smith 251d382aafbSBarry Smith Level: beginner 252d382aafbSBarry Smith 253e28ce29aSPatrick Sanan Notes: 25487497f52SBarry Smith By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 25587497f52SBarry Smith run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 25687497f52SBarry Smith communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 257af27ebaaSBarry Smith `PetscInitialize()`, but after `MPI_Init()` has been called. 258a990b902SBarry Smith 259af27ebaaSBarry Smith The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()` 260a990b902SBarry Smith is called because it may not have a valid value yet. 261d382aafbSBarry Smith 262db781477SPatrick Sanan .seealso: `PETSC_COMM_SELF` 263d382aafbSBarry Smith M*/ 264014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 265d382aafbSBarry Smith 266d382aafbSBarry Smith /*MC 26787497f52SBarry Smith PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 268d382aafbSBarry Smith 269d382aafbSBarry Smith Level: beginner 270d382aafbSBarry Smith 27195bd0b28SBarry Smith Note: 27216a05f60SBarry Smith Do not USE/access or set this variable before `PetscInitialize()` has been called. 273a990b902SBarry Smith 274db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD` 275d382aafbSBarry Smith M*/ 276d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF 277d382aafbSBarry Smith 2786de5d289SStefano Zampini /*MC 279af27ebaaSBarry Smith PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`. 2806de5d289SStefano Zampini 2816de5d289SStefano Zampini Level: beginner 2826de5d289SStefano Zampini 28395bd0b28SBarry Smith Note: 284835d5ba2SJunchao Zhang By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED` when the MPI implementation provides MPI_Init_thread(), otherwise it equals `MPI_THREAD_SINGLE` 2856de5d289SStefano Zampini 286db781477SPatrick Sanan .seealso: `PetscInitialize()` 2876de5d289SStefano Zampini M*/ 2886de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 2896de5d289SStefano Zampini 290d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI; 2918ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 292014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled; 293014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled; 2944cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 295d382aafbSBarry Smith 296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 297014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 298014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 29957f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 30057f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 301d382aafbSBarry Smith 30259e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 30359e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 30459e55d94SJunchao Zhang #endif 30559e55d94SJunchao Zhang 30671438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM) 30771438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscBeganNvshmem; 30871438e86SJunchao Zhang PETSC_EXTERN PetscBool PetscNvshmemInitialized; 30971438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 31071438e86SJunchao Zhang #endif 31171438e86SJunchao Zhang 312540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL) 313540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 314540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 315540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 316540e20f2SPierre Jolivet #endif 317540e20f2SPierre Jolivet 318d382aafbSBarry Smith /*MC 31987497f52SBarry Smith PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 320d382aafbSBarry Smith 321eca87e8dSBarry Smith Synopsis: 322aaa7dc30SBarry Smith #include <petscsys.h> 323eca87e8dSBarry Smith PetscErrorCode PetscMalloc(size_t m,void **result) 324eca87e8dSBarry Smith 325eca87e8dSBarry Smith Not Collective 326eca87e8dSBarry Smith 327d382aafbSBarry Smith Input Parameter: 328d382aafbSBarry Smith . m - number of bytes to allocate 329d382aafbSBarry Smith 330d382aafbSBarry Smith Output Parameter: 331d382aafbSBarry Smith . result - memory allocated 332d382aafbSBarry Smith 333d382aafbSBarry Smith Level: beginner 334d382aafbSBarry Smith 33549d7da52SJed Brown Notes: 33649d7da52SJed Brown Memory is always allocated at least double aligned 337d382aafbSBarry Smith 33816a05f60SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 339d382aafbSBarry Smith 340db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 341d382aafbSBarry Smith M*/ 342071fcb05SBarry Smith #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 343d382aafbSBarry Smith 344d382aafbSBarry Smith /*MC 345d5b43468SJose E. Roman PetscRealloc - Reallocates memory 3463221ece2SMatthew G. Knepley 3473221ece2SMatthew G. Knepley Synopsis: 3483221ece2SMatthew G. Knepley #include <petscsys.h> 3493221ece2SMatthew G. Knepley PetscErrorCode PetscRealloc(size_t m,void **result) 3503221ece2SMatthew G. Knepley 3513221ece2SMatthew G. Knepley Not Collective 3523221ece2SMatthew G. Knepley 3533221ece2SMatthew G. Knepley Input Parameters: 3543221ece2SMatthew G. Knepley + m - number of bytes to allocate 35592f119d6SBarry Smith - result - previous memory 3563221ece2SMatthew G. Knepley 3573221ece2SMatthew G. Knepley Output Parameter: 3583221ece2SMatthew G. Knepley . result - new memory allocated 3593221ece2SMatthew G. Knepley 3603221ece2SMatthew G. Knepley Level: developer 3613221ece2SMatthew G. Knepley 36295bd0b28SBarry Smith Note: 3633221ece2SMatthew G. Knepley Memory is always allocated at least double aligned 3643221ece2SMatthew G. Knepley 365db781477SPatrick Sanan .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 3663221ece2SMatthew G. Knepley M*/ 3673221ece2SMatthew G. Knepley #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 3683221ece2SMatthew G. Knepley 3693221ece2SMatthew G. Knepley /*MC 37087497f52SBarry Smith PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 371d382aafbSBarry Smith 372d382aafbSBarry Smith Synopsis: 373aaa7dc30SBarry Smith #include <petscsys.h> 374d382aafbSBarry Smith void *PetscAddrAlign(void *addr) 375d382aafbSBarry Smith 376eca87e8dSBarry Smith Not Collective 377eca87e8dSBarry Smith 3782fe279fdSBarry Smith Input Parameter: 379eca87e8dSBarry Smith . addr - address to align (any pointer type) 380eca87e8dSBarry Smith 381d382aafbSBarry Smith Level: developer 382d382aafbSBarry Smith 383db781477SPatrick Sanan .seealso: `PetscMallocAlign()` 384d382aafbSBarry Smith M*/ 385f3fa974cSJacob Faibussowitsch #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))) 386d382aafbSBarry Smith 387d382aafbSBarry Smith /*MC 38887497f52SBarry Smith PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 3898f51dc47SJunchao Zhang 3908f51dc47SJunchao Zhang Synopsis: 3918f51dc47SJunchao Zhang #include <petscsys.h> 3928f51dc47SJunchao Zhang PetscErrorCode PetscCalloc(size_t m,void **result) 3938f51dc47SJunchao Zhang 3948f51dc47SJunchao Zhang Not Collective 3958f51dc47SJunchao Zhang 3968f51dc47SJunchao Zhang Input Parameter: 3978f51dc47SJunchao Zhang . m - number of bytes to allocate 3988f51dc47SJunchao Zhang 3998f51dc47SJunchao Zhang Output Parameter: 4008f51dc47SJunchao Zhang . result - memory allocated 4018f51dc47SJunchao Zhang 4028f51dc47SJunchao Zhang Level: beginner 4038f51dc47SJunchao Zhang 4048f51dc47SJunchao Zhang Notes: 4058f51dc47SJunchao Zhang Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 4068f51dc47SJunchao Zhang 40716a05f60SBarry Smith It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 4088f51dc47SJunchao Zhang 409db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()` 4108f51dc47SJunchao Zhang M*/ 411f3fa974cSJacob Faibussowitsch #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result)) 4128f51dc47SJunchao Zhang 4138f51dc47SJunchao Zhang /*MC 41487497f52SBarry Smith PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 415d382aafbSBarry Smith 416eca87e8dSBarry Smith Synopsis: 417aaa7dc30SBarry Smith #include <petscsys.h> 418785e854fSJed Brown PetscErrorCode PetscMalloc1(size_t m1,type **r1) 419785e854fSJed Brown 420785e854fSJed Brown Not Collective 421785e854fSJed Brown 422785e854fSJed Brown Input Parameter: 423390e1bf2SBarry Smith . m1 - number of elements to allocate (may be zero) 424785e854fSJed Brown 425785e854fSJed Brown Output Parameter: 4261fe1b817SJunchao Zhang . r1 - memory allocated 427785e854fSJed Brown 42816a05f60SBarry Smith Level: beginner 42916a05f60SBarry Smith 430e28ce29aSPatrick Sanan Note: 431e28ce29aSPatrick Sanan This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 43287497f52SBarry Smith multiply the number of elements requested by the `sizeof()` the type. For example use 43316a05f60SBarry Smith .vb 43416a05f60SBarry Smith PetscInt *id; 43516a05f60SBarry Smith PetscMalloc1(10,&id); 43616a05f60SBarry Smith .ve 437390e1bf2SBarry Smith not 43816a05f60SBarry Smith .vb 43916a05f60SBarry Smith PetscInt *id; 44016a05f60SBarry Smith PetscMalloc1(10*sizeof(PetscInt),&id); 44116a05f60SBarry Smith .ve 442390e1bf2SBarry Smith 44387497f52SBarry Smith Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 444390e1bf2SBarry Smith 445db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 446785e854fSJed Brown M*/ 447f3fa974cSJacob Faibussowitsch #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 448785e854fSJed Brown 449785e854fSJed Brown /*MC 45087497f52SBarry Smith PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 4511795a4d1SJed Brown 4521795a4d1SJed Brown Synopsis: 453aaa7dc30SBarry Smith #include <petscsys.h> 4541795a4d1SJed Brown PetscErrorCode PetscCalloc1(size_t m1,type **r1) 4551795a4d1SJed Brown 4561795a4d1SJed Brown Not Collective 4571795a4d1SJed Brown 4581795a4d1SJed Brown Input Parameter: 4591795a4d1SJed Brown . m1 - number of elements to allocate in 1st chunk (may be zero) 4601795a4d1SJed Brown 4611795a4d1SJed Brown Output Parameter: 4621fe1b817SJunchao Zhang . r1 - memory allocated 4631795a4d1SJed Brown 46416a05f60SBarry Smith Level: beginner 46516a05f60SBarry Smith 46695bd0b28SBarry Smith Note: 46787497f52SBarry Smith See `PetsMalloc1()` for more details on usage. 468390e1bf2SBarry Smith 469db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 4701795a4d1SJed Brown M*/ 471f3fa974cSJacob Faibussowitsch #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 4721795a4d1SJed Brown 4731795a4d1SJed Brown /*MC 47487497f52SBarry Smith PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 475d382aafbSBarry Smith 476eca87e8dSBarry Smith Synopsis: 477aaa7dc30SBarry Smith #include <petscsys.h> 478dcca6d9dSJed Brown PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 479eca87e8dSBarry Smith 480eca87e8dSBarry Smith Not Collective 481eca87e8dSBarry Smith 482d8d19677SJose E. Roman Input Parameters: 483d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 484dcca6d9dSJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 485d382aafbSBarry Smith 486d8d19677SJose E. Roman Output Parameters: 487d382aafbSBarry Smith + r1 - memory allocated in first chunk 488d382aafbSBarry Smith - r2 - memory allocated in second chunk 489d382aafbSBarry Smith 490d382aafbSBarry Smith Level: developer 491d382aafbSBarry Smith 492db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 493d382aafbSBarry Smith M*/ 494f3fa974cSJacob Faibussowitsch #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)) 495d382aafbSBarry Smith 496d382aafbSBarry Smith /*MC 49787497f52SBarry Smith PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 498d382aafbSBarry Smith 499eca87e8dSBarry Smith Synopsis: 500aaa7dc30SBarry Smith #include <petscsys.h> 5011795a4d1SJed Brown PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 502eca87e8dSBarry Smith 503eca87e8dSBarry Smith Not Collective 504eca87e8dSBarry Smith 505d8d19677SJose E. Roman Input Parameters: 506d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 5071795a4d1SJed Brown - m2 - number of elements to allocate in 2nd chunk (may be zero) 5081795a4d1SJed Brown 509d8d19677SJose E. Roman Output Parameters: 5101795a4d1SJed Brown + r1 - memory allocated in first chunk 5111795a4d1SJed Brown - r2 - memory allocated in second chunk 5121795a4d1SJed Brown 5131795a4d1SJed Brown Level: developer 5141795a4d1SJed Brown 515db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 5161795a4d1SJed Brown M*/ 517f3fa974cSJacob Faibussowitsch #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)) 5181795a4d1SJed Brown 5191795a4d1SJed Brown /*MC 52087497f52SBarry Smith PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 521d382aafbSBarry Smith 522d382aafbSBarry Smith Synopsis: 523aaa7dc30SBarry Smith #include <petscsys.h> 524dcca6d9dSJed Brown PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 525d382aafbSBarry Smith 526d382aafbSBarry Smith Not Collective 527d382aafbSBarry Smith 528d8d19677SJose E. Roman Input Parameters: 529d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 530d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 531dcca6d9dSJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 532d382aafbSBarry Smith 533d8d19677SJose E. Roman Output Parameters: 534d382aafbSBarry Smith + r1 - memory allocated in first chunk 535d382aafbSBarry Smith . r2 - memory allocated in second chunk 536d382aafbSBarry Smith - r3 - memory allocated in third chunk 537d382aafbSBarry Smith 538d382aafbSBarry Smith Level: developer 539d382aafbSBarry Smith 540db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 541d382aafbSBarry Smith M*/ 542f3fa974cSJacob Faibussowitsch #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \ 543f3fa974cSJacob Faibussowitsch 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)) 544d382aafbSBarry Smith 545d382aafbSBarry Smith /*MC 54687497f52SBarry Smith PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 547d382aafbSBarry Smith 548eca87e8dSBarry Smith Synopsis: 549aaa7dc30SBarry Smith #include <petscsys.h> 5501795a4d1SJed Brown PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 551eca87e8dSBarry Smith 552eca87e8dSBarry Smith Not Collective 553eca87e8dSBarry Smith 554d8d19677SJose E. Roman Input Parameters: 555d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 556d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 5571795a4d1SJed Brown - m3 - number of elements to allocate in 3rd chunk (may be zero) 5581795a4d1SJed Brown 559d8d19677SJose E. Roman Output Parameters: 5601795a4d1SJed Brown + r1 - memory allocated in first chunk 5611795a4d1SJed Brown . r2 - memory allocated in second chunk 5621795a4d1SJed Brown - r3 - memory allocated in third chunk 5631795a4d1SJed Brown 5641795a4d1SJed Brown Level: developer 5651795a4d1SJed Brown 566db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 5671795a4d1SJed Brown M*/ 568f3fa974cSJacob Faibussowitsch #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \ 569f3fa974cSJacob Faibussowitsch 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)) 5701795a4d1SJed Brown 5711795a4d1SJed Brown /*MC 57287497f52SBarry Smith PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 573d382aafbSBarry Smith 574d382aafbSBarry Smith Synopsis: 575aaa7dc30SBarry Smith #include <petscsys.h> 576dcca6d9dSJed Brown PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 577d382aafbSBarry Smith 578d382aafbSBarry Smith Not Collective 579d382aafbSBarry Smith 580d8d19677SJose E. Roman Input Parameters: 581d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 582d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 583d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 584dcca6d9dSJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 585d382aafbSBarry Smith 586d8d19677SJose E. Roman Output Parameters: 587d382aafbSBarry Smith + r1 - memory allocated in first chunk 588d382aafbSBarry Smith . r2 - memory allocated in second chunk 589d382aafbSBarry Smith . r3 - memory allocated in third chunk 590d382aafbSBarry Smith - r4 - memory allocated in fourth chunk 591d382aafbSBarry Smith 592d382aafbSBarry Smith Level: developer 593d382aafbSBarry Smith 594db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 595d382aafbSBarry Smith M*/ 5969371c9d4SSatish Balay #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 597f3fa974cSJacob Faibussowitsch 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)) 598d382aafbSBarry Smith 599d382aafbSBarry Smith /*MC 60087497f52SBarry Smith PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 601d382aafbSBarry Smith 602eca87e8dSBarry Smith Synopsis: 603aaa7dc30SBarry Smith #include <petscsys.h> 6041795a4d1SJed Brown PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 605eca87e8dSBarry Smith 606eca87e8dSBarry Smith Not Collective 607eca87e8dSBarry Smith 608e28ce29aSPatrick Sanan Input Parameters: 609d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 610d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 611d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 6121795a4d1SJed Brown - m4 - number of elements to allocate in 4th chunk (may be zero) 6131795a4d1SJed Brown 614e28ce29aSPatrick Sanan Output Parameters: 6151795a4d1SJed Brown + r1 - memory allocated in first chunk 6161795a4d1SJed Brown . r2 - memory allocated in second chunk 6171795a4d1SJed Brown . r3 - memory allocated in third chunk 6181795a4d1SJed Brown - r4 - memory allocated in fourth chunk 6191795a4d1SJed Brown 6201795a4d1SJed Brown Level: developer 6211795a4d1SJed Brown 622db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 6231795a4d1SJed Brown M*/ 6249371c9d4SSatish Balay #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 625f3fa974cSJacob Faibussowitsch 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)) 6261795a4d1SJed Brown 6271795a4d1SJed Brown /*MC 62887497f52SBarry Smith PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 629d382aafbSBarry Smith 630d382aafbSBarry Smith Synopsis: 631aaa7dc30SBarry Smith #include <petscsys.h> 632dcca6d9dSJed 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) 633d382aafbSBarry Smith 634d382aafbSBarry Smith Not Collective 635d382aafbSBarry Smith 636e28ce29aSPatrick Sanan Input Parameters: 637d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 638d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 639d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 640d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 641dcca6d9dSJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 642d382aafbSBarry Smith 643e28ce29aSPatrick Sanan Output Parameters: 644d382aafbSBarry Smith + r1 - memory allocated in first chunk 645d382aafbSBarry Smith . r2 - memory allocated in second chunk 646d382aafbSBarry Smith . r3 - memory allocated in third chunk 647d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 648d382aafbSBarry Smith - r5 - memory allocated in fifth chunk 649d382aafbSBarry Smith 650d382aafbSBarry Smith Level: developer 651d382aafbSBarry Smith 652db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 653d382aafbSBarry Smith M*/ 6549371c9d4SSatish Balay #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 655f3fa974cSJacob Faibussowitsch 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)) 656d382aafbSBarry Smith 657d382aafbSBarry Smith /*MC 65887497f52SBarry Smith PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 659d382aafbSBarry Smith 660eca87e8dSBarry Smith Synopsis: 661aaa7dc30SBarry Smith #include <petscsys.h> 6621795a4d1SJed 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) 663eca87e8dSBarry Smith 664eca87e8dSBarry Smith Not Collective 665eca87e8dSBarry Smith 666e28ce29aSPatrick Sanan Input Parameters: 667d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 668d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 669d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 670d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 6711795a4d1SJed Brown - m5 - number of elements to allocate in 5th chunk (may be zero) 6721795a4d1SJed Brown 673e28ce29aSPatrick Sanan Output Parameters: 6741795a4d1SJed Brown + r1 - memory allocated in first chunk 6751795a4d1SJed Brown . r2 - memory allocated in second chunk 6761795a4d1SJed Brown . r3 - memory allocated in third chunk 6771795a4d1SJed Brown . r4 - memory allocated in fourth chunk 6781795a4d1SJed Brown - r5 - memory allocated in fifth chunk 6791795a4d1SJed Brown 6801795a4d1SJed Brown Level: developer 6811795a4d1SJed Brown 682db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 6831795a4d1SJed Brown M*/ 6849371c9d4SSatish Balay #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 685f3fa974cSJacob Faibussowitsch 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)) 686d382aafbSBarry Smith 687d382aafbSBarry Smith /*MC 68887497f52SBarry Smith PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 689d382aafbSBarry Smith 690d382aafbSBarry Smith Synopsis: 691aaa7dc30SBarry Smith #include <petscsys.h> 692dcca6d9dSJed 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) 693d382aafbSBarry Smith 694d382aafbSBarry Smith Not Collective 695d382aafbSBarry Smith 696e28ce29aSPatrick Sanan Input Parameters: 697d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 698d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 699d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 700d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 701d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 702dcca6d9dSJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 703d382aafbSBarry Smith 704e28ce29aSPatrick Sanan Output Parameteasr: 705d382aafbSBarry Smith + r1 - memory allocated in first chunk 706d382aafbSBarry Smith . r2 - memory allocated in second chunk 707d382aafbSBarry Smith . r3 - memory allocated in third chunk 708d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 709d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 710d382aafbSBarry Smith - r6 - memory allocated in sixth chunk 711d382aafbSBarry Smith 712d382aafbSBarry Smith Level: developer 713d382aafbSBarry Smith 714db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 715d382aafbSBarry Smith M*/ 7169371c9d4SSatish Balay #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 717f3fa974cSJacob Faibussowitsch 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)) 718d382aafbSBarry Smith 719d382aafbSBarry Smith /*MC 72087497f52SBarry Smith PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 721d382aafbSBarry Smith 722eca87e8dSBarry Smith Synopsis: 723aaa7dc30SBarry Smith #include <petscsys.h> 7241795a4d1SJed 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) 725eca87e8dSBarry Smith 726eca87e8dSBarry Smith Not Collective 727eca87e8dSBarry Smith 728e28ce29aSPatrick Sanan Input Parameters: 729d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 730d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 731d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 732d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 733d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 7341795a4d1SJed Brown - m6 - number of elements to allocate in 6th chunk (may be zero) 7351795a4d1SJed Brown 736e28ce29aSPatrick Sanan Output Parameters: 7371795a4d1SJed Brown + r1 - memory allocated in first chunk 7381795a4d1SJed Brown . r2 - memory allocated in second chunk 7391795a4d1SJed Brown . r3 - memory allocated in third chunk 7401795a4d1SJed Brown . r4 - memory allocated in fourth chunk 7411795a4d1SJed Brown . r5 - memory allocated in fifth chunk 7421795a4d1SJed Brown - r6 - memory allocated in sixth chunk 7431795a4d1SJed Brown 7441795a4d1SJed Brown Level: developer 7451795a4d1SJed Brown 746db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 7471795a4d1SJed Brown M*/ 7489371c9d4SSatish Balay #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 749f3fa974cSJacob Faibussowitsch 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)) 7501795a4d1SJed Brown 7511795a4d1SJed Brown /*MC 75287497f52SBarry Smith PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 753d382aafbSBarry Smith 754d382aafbSBarry Smith Synopsis: 755aaa7dc30SBarry Smith #include <petscsys.h> 756dcca6d9dSJed 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) 757d382aafbSBarry Smith 758d382aafbSBarry Smith Not Collective 759d382aafbSBarry Smith 760e28ce29aSPatrick Sanan Input Parameters: 761d382aafbSBarry Smith + m1 - number of elements to allocate in 1st chunk (may be zero) 762d382aafbSBarry Smith . m2 - number of elements to allocate in 2nd chunk (may be zero) 763d382aafbSBarry Smith . m3 - number of elements to allocate in 3rd chunk (may be zero) 764d382aafbSBarry Smith . m4 - number of elements to allocate in 4th chunk (may be zero) 765d382aafbSBarry Smith . m5 - number of elements to allocate in 5th chunk (may be zero) 766d382aafbSBarry Smith . m6 - number of elements to allocate in 6th chunk (may be zero) 767dcca6d9dSJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 768d382aafbSBarry Smith 769e28ce29aSPatrick Sanan Output Parameters: 770d382aafbSBarry Smith + r1 - memory allocated in first chunk 771d382aafbSBarry Smith . r2 - memory allocated in second chunk 772d382aafbSBarry Smith . r3 - memory allocated in third chunk 773d382aafbSBarry Smith . r4 - memory allocated in fourth chunk 774d382aafbSBarry Smith . r5 - memory allocated in fifth chunk 775d382aafbSBarry Smith . r6 - memory allocated in sixth chunk 776eca87e8dSBarry Smith - r7 - memory allocated in seventh chunk 777d382aafbSBarry Smith 778d382aafbSBarry Smith Level: developer 779d382aafbSBarry Smith 780db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 781d382aafbSBarry Smith M*/ 7829371c9d4SSatish Balay #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 783f3fa974cSJacob Faibussowitsch 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)) 784d382aafbSBarry Smith 785d382aafbSBarry Smith /*MC 78687497f52SBarry Smith PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 7871795a4d1SJed Brown 7881795a4d1SJed Brown Synopsis: 789aaa7dc30SBarry Smith #include <petscsys.h> 7901795a4d1SJed 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) 7911795a4d1SJed Brown 7921795a4d1SJed Brown Not Collective 7931795a4d1SJed Brown 794e28ce29aSPatrick Sanan Input Parameters: 7951795a4d1SJed Brown + m1 - number of elements to allocate in 1st chunk (may be zero) 7961795a4d1SJed Brown . m2 - number of elements to allocate in 2nd chunk (may be zero) 7971795a4d1SJed Brown . m3 - number of elements to allocate in 3rd chunk (may be zero) 7981795a4d1SJed Brown . m4 - number of elements to allocate in 4th chunk (may be zero) 7991795a4d1SJed Brown . m5 - number of elements to allocate in 5th chunk (may be zero) 8001795a4d1SJed Brown . m6 - number of elements to allocate in 6th chunk (may be zero) 8011795a4d1SJed Brown - m7 - number of elements to allocate in 7th chunk (may be zero) 8021795a4d1SJed Brown 803e28ce29aSPatrick Sanan Output Parameters: 8041795a4d1SJed Brown + r1 - memory allocated in first chunk 8051795a4d1SJed Brown . r2 - memory allocated in second chunk 8061795a4d1SJed Brown . r3 - memory allocated in third chunk 8071795a4d1SJed Brown . r4 - memory allocated in fourth chunk 8081795a4d1SJed Brown . r5 - memory allocated in fifth chunk 8091795a4d1SJed Brown . r6 - memory allocated in sixth chunk 8101795a4d1SJed Brown - r7 - memory allocated in seventh chunk 8111795a4d1SJed Brown 8121795a4d1SJed Brown Level: developer 8131795a4d1SJed Brown 814db781477SPatrick Sanan .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 8151795a4d1SJed Brown M*/ 8169371c9d4SSatish Balay #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 817f3fa974cSJacob Faibussowitsch 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)) 8181795a4d1SJed Brown 8191795a4d1SJed Brown /*MC 82087497f52SBarry Smith PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 821d382aafbSBarry Smith 822eca87e8dSBarry Smith Synopsis: 823aaa7dc30SBarry Smith #include <petscsys.h> 824b00a9115SJed Brown PetscErrorCode PetscNew(type **result) 825eca87e8dSBarry Smith 826eca87e8dSBarry Smith Not Collective 827eca87e8dSBarry Smith 828d382aafbSBarry Smith Output Parameter: 829b00a9115SJed Brown . result - memory allocated, sized to match pointer type 830d382aafbSBarry Smith 831d382aafbSBarry Smith Level: beginner 832d382aafbSBarry Smith 833fea72eb4SStefano Zampini .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 834d382aafbSBarry Smith M*/ 835b00a9115SJed Brown #define PetscNew(b) PetscCalloc1(1, (b)) 836ad0619ddSBarry Smith 837*f4f49eeaSPierre Jolivet #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew(b) 838d382aafbSBarry Smith 839d382aafbSBarry Smith /*MC 840d382aafbSBarry Smith PetscFree - Frees memory 841d382aafbSBarry Smith 842eca87e8dSBarry Smith Synopsis: 843aaa7dc30SBarry Smith #include <petscsys.h> 844eca87e8dSBarry Smith PetscErrorCode PetscFree(void *memory) 845eca87e8dSBarry Smith 846eca87e8dSBarry Smith Not Collective 847eca87e8dSBarry Smith 848d382aafbSBarry Smith Input Parameter: 84916a05f60SBarry Smith . memory - memory to free (the pointer is ALWAYS set to `NULL` upon success) 850d382aafbSBarry Smith 851d382aafbSBarry Smith Level: beginner 852d382aafbSBarry Smith 85395bd0b28SBarry Smith Notes: 85487497f52SBarry Smith Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 855390e1bf2SBarry Smith 85616a05f60SBarry Smith It is safe to call `PetscFree()` on a `NULL` pointer. 857d382aafbSBarry Smith 858fea72eb4SStefano Zampini .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 859d382aafbSBarry Smith M*/ 8603ba16761SJacob Faibussowitsch #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS))) 861d382aafbSBarry Smith 862d382aafbSBarry Smith /*MC 86387497f52SBarry Smith PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 864d382aafbSBarry Smith 865eca87e8dSBarry Smith Synopsis: 866aaa7dc30SBarry Smith #include <petscsys.h> 867eca87e8dSBarry Smith PetscErrorCode PetscFree2(void *memory1,void *memory2) 868eca87e8dSBarry Smith 869eca87e8dSBarry Smith Not Collective 870eca87e8dSBarry Smith 871e28ce29aSPatrick Sanan Input Parameters: 872d382aafbSBarry Smith + memory1 - memory to free 873d382aafbSBarry Smith - memory2 - 2nd memory to free 874d382aafbSBarry Smith 875d382aafbSBarry Smith Level: developer 876d382aafbSBarry Smith 8777e17494fSJames Wright Notes: 87887497f52SBarry Smith Memory must have been obtained with `PetscMalloc2()` 879d382aafbSBarry Smith 8807e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc2()` 8817e17494fSJames Wright 882db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 883d382aafbSBarry Smith M*/ 884ba282f50SJed Brown #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 885d382aafbSBarry Smith 886d382aafbSBarry Smith /*MC 88787497f52SBarry Smith PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 888d382aafbSBarry Smith 889eca87e8dSBarry Smith Synopsis: 890aaa7dc30SBarry Smith #include <petscsys.h> 891eca87e8dSBarry Smith PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 892eca87e8dSBarry Smith 893eca87e8dSBarry Smith Not Collective 894eca87e8dSBarry Smith 895e28ce29aSPatrick Sanan Input Parameters: 896d382aafbSBarry Smith + memory1 - memory to free 897d382aafbSBarry Smith . memory2 - 2nd memory to free 898d382aafbSBarry Smith - memory3 - 3rd memory to free 899d382aafbSBarry Smith 900d382aafbSBarry Smith Level: developer 901d382aafbSBarry Smith 9027e17494fSJames Wright Notes: 90387497f52SBarry Smith Memory must have been obtained with `PetscMalloc3()` 904d382aafbSBarry Smith 9057e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc3()` 9067e17494fSJames Wright 907db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 908d382aafbSBarry Smith M*/ 909ba282f50SJed Brown #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 910d382aafbSBarry Smith 911d382aafbSBarry Smith /*MC 91287497f52SBarry Smith PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 913d382aafbSBarry Smith 914eca87e8dSBarry Smith Synopsis: 915aaa7dc30SBarry Smith #include <petscsys.h> 916eca87e8dSBarry Smith PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 917eca87e8dSBarry Smith 918eca87e8dSBarry Smith Not Collective 919eca87e8dSBarry Smith 920e28ce29aSPatrick Sanan Input Parameters: 921d382aafbSBarry Smith + m1 - memory to free 922d382aafbSBarry Smith . m2 - 2nd memory to free 923d382aafbSBarry Smith . m3 - 3rd memory to free 924d382aafbSBarry Smith - m4 - 4th memory to free 925d382aafbSBarry Smith 926d382aafbSBarry Smith Level: developer 927d382aafbSBarry Smith 9287e17494fSJames Wright Notes: 92987497f52SBarry Smith Memory must have been obtained with `PetscMalloc4()` 930d382aafbSBarry Smith 9317e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc4()` 9327e17494fSJames Wright 933db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 934d382aafbSBarry Smith M*/ 935ba282f50SJed Brown #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 936d382aafbSBarry Smith 937d382aafbSBarry Smith /*MC 93887497f52SBarry Smith PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 939d382aafbSBarry Smith 940eca87e8dSBarry Smith Synopsis: 941aaa7dc30SBarry Smith #include <petscsys.h> 942eca87e8dSBarry Smith PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 943eca87e8dSBarry Smith 944eca87e8dSBarry Smith Not Collective 945eca87e8dSBarry Smith 946e28ce29aSPatrick Sanan Input Parameters: 947d382aafbSBarry Smith + m1 - memory to free 948d382aafbSBarry Smith . m2 - 2nd memory to free 949d382aafbSBarry Smith . m3 - 3rd memory to free 950d382aafbSBarry Smith . m4 - 4th memory to free 951d382aafbSBarry Smith - m5 - 5th memory to free 952d382aafbSBarry Smith 953d382aafbSBarry Smith Level: developer 954d382aafbSBarry Smith 9557e17494fSJames Wright Notes: 95687497f52SBarry Smith Memory must have been obtained with `PetscMalloc5()` 957d382aafbSBarry Smith 9587e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc5()` 9597e17494fSJames Wright 960db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 961d382aafbSBarry Smith M*/ 962ba282f50SJed Brown #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 963d382aafbSBarry Smith 964d382aafbSBarry Smith /*MC 96587497f52SBarry Smith PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 966d382aafbSBarry Smith 967eca87e8dSBarry Smith Synopsis: 968aaa7dc30SBarry Smith #include <petscsys.h> 969eca87e8dSBarry Smith PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 970eca87e8dSBarry Smith 971eca87e8dSBarry Smith Not Collective 972eca87e8dSBarry Smith 973e28ce29aSPatrick Sanan Input Parameters: 974d382aafbSBarry Smith + m1 - memory to free 975d382aafbSBarry Smith . m2 - 2nd memory to free 976d382aafbSBarry Smith . m3 - 3rd memory to free 977d382aafbSBarry Smith . m4 - 4th memory to free 978d382aafbSBarry Smith . m5 - 5th memory to free 979d382aafbSBarry Smith - m6 - 6th memory to free 980d382aafbSBarry Smith 981d382aafbSBarry Smith Level: developer 982d382aafbSBarry Smith 9837e17494fSJames Wright Notes: 98487497f52SBarry Smith Memory must have been obtained with `PetscMalloc6()` 985d382aafbSBarry Smith 9867e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc6()` 9877e17494fSJames Wright 988db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 989d382aafbSBarry Smith M*/ 990ba282f50SJed Brown #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 991d382aafbSBarry Smith 992d382aafbSBarry Smith /*MC 99387497f52SBarry Smith PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 994d382aafbSBarry Smith 995eca87e8dSBarry Smith Synopsis: 996aaa7dc30SBarry Smith #include <petscsys.h> 997eca87e8dSBarry Smith PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 998eca87e8dSBarry Smith 999eca87e8dSBarry Smith Not Collective 1000eca87e8dSBarry Smith 1001e28ce29aSPatrick Sanan Input Parameters: 1002d382aafbSBarry Smith + m1 - memory to free 1003d382aafbSBarry Smith . m2 - 2nd memory to free 1004d382aafbSBarry Smith . m3 - 3rd memory to free 1005d382aafbSBarry Smith . m4 - 4th memory to free 1006d382aafbSBarry Smith . m5 - 5th memory to free 1007d382aafbSBarry Smith . m6 - 6th memory to free 1008d382aafbSBarry Smith - m7 - 7th memory to free 1009d382aafbSBarry Smith 1010d382aafbSBarry Smith Level: developer 1011d382aafbSBarry Smith 10127e17494fSJames Wright Notes: 101387497f52SBarry Smith Memory must have been obtained with `PetscMalloc7()` 1014d382aafbSBarry Smith 10157e17494fSJames Wright The arguments need to be in the same order as they were in the call to `PetscMalloc7()` 10167e17494fSJames Wright 1017db781477SPatrick Sanan .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1018db781477SPatrick Sanan `PetscMalloc7()` 1019d382aafbSBarry Smith M*/ 1020ba282f50SJed Brown #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1021d382aafbSBarry Smith 1022ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1023ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1024071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1025efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 10263221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1027ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 102892f119d6SBarry 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 **)); 1029014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1030d382aafbSBarry Smith 1031d382aafbSBarry Smith /* 1032c1706be6SHong 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. 1033c1706be6SHong Zhang */ 1034c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1035c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 103631f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA) 103731f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 103831f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 103931f06eaaSHong Zhang #endif 104059af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP) 104159af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 104259af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 104359af0bd3SScott Kruger #endif 104459af0bd3SScott Kruger 1045a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 104636763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1047a5057860SBarry Smith 1048a5057860SBarry Smith /* 104966d669d6SBarry Smith Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1050d382aafbSBarry Smith */ 1051014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 105292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1053014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1054014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1055e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1056e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 105792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 105892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1059efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 106092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 106192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1062608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1063608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1064d382aafbSBarry Smith 1065014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1066014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1067014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 10688e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1069d382aafbSBarry Smith 1070d382aafbSBarry Smith /* 1071d382aafbSBarry Smith These are MPI operations for MPI_Allreduce() etc 1072d382aafbSBarry Smith */ 1073367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1074570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1075de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM; 1076014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX; 1077014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN; 1078d9822059SBarry Smith #else 1079de272c7aSSatish Balay #define MPIU_SUM MPI_SUM 1080d9822059SBarry Smith #define MPIU_MAX MPI_MAX 1081d9822059SBarry Smith #define MPIU_MIN MPI_MIN 1082d9822059SBarry Smith #endif 108362e5d2d2SJDBetteridge PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 108462e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 108562e5d2d2SJDBetteridge 1086a2498233SPierre Jolivet #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16)) 1087613bf2b2SPierre Jolivet /*MC 108816a05f60SBarry Smith MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with 108916a05f60SBarry Smith custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1090613bf2b2SPierre Jolivet 1091613bf2b2SPierre Jolivet Level: advanced 1092613bf2b2SPierre Jolivet 1093613bf2b2SPierre Jolivet Developer Note: 1094613bf2b2SPierre Jolivet This should be unified with `MPIU_SUM` 1095613bf2b2SPierre Jolivet 1096613bf2b2SPierre Jolivet .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1097613bf2b2SPierre Jolivet M*/ 10989e517322SPierre Jolivet PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1099613bf2b2SPierre Jolivet #endif 1100014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1101d382aafbSBarry Smith 110293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 110393d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1104eb3f98d2SBarry Smith 1105639ff905SBarry Smith /* 1106639ff905SBarry Smith Defines PETSc error handling. 1107639ff905SBarry Smith */ 1108639ff905SBarry Smith #include <petscerror.h> 1109d382aafbSBarry Smith 1110660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1111660278c0SBarry Smith PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1112660278c0SBarry Smith PETSC_EXTERN const char *PetscCIFilename(const char *); 1113660278c0SBarry Smith PETSC_EXTERN int PetscCILinenumber(int); 1114660278c0SBarry Smith 1115f3fa974cSJacob Faibussowitsch #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211) 1116014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1117014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1118014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 111981256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 112081256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 112181256985SMatthew G. Knepley 1122d382aafbSBarry Smith /* 1123d382aafbSBarry Smith Routines that get memory usage information from the OS 1124d382aafbSBarry Smith */ 1125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1126014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1127014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1128b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1129d382aafbSBarry Smith 1130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1131d382aafbSBarry Smith 1132d382aafbSBarry Smith /* 1133d382aafbSBarry Smith Initialization of PETSc 1134d382aafbSBarry Smith */ 1135014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1137014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1138014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1139014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1140014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1145d382aafbSBarry Smith 1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void); 1147607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 11484bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void); 1149d382aafbSBarry Smith 1150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1154d382aafbSBarry Smith 1155a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1156a50e088cSMatthew G. Knepley 1157d382aafbSBarry Smith /* 1158d382aafbSBarry Smith These are so that in extern C code we can caste function pointers to non-extern C 11592981ebdbSBarry Smith function pointers. Since the regular C++ code expects its function pointers to be C++ 1160d382aafbSBarry Smith */ 11615ddc805bSBarry Smith 11625ddc805bSBarry Smith /*S 11638434afd1SBarry Smith PetscVoidFn - A prototype of a void (fn)(void) function 11645ddc805bSBarry Smith 11655ddc805bSBarry Smith Level: developer 11665ddc805bSBarry Smith 11675ddc805bSBarry Smith Notes: 11688434afd1SBarry Smith The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *. 11695ddc805bSBarry Smith 11708434afd1SBarry Smith The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **. 11715ddc805bSBarry Smith 11725ddc805bSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 11735ddc805bSBarry Smith S*/ 11748434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void); 11755ddc805bSBarry Smith 11768434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn *PetscVoidFunction; 11778434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction; 11785ddc805bSBarry Smith 11795ddc805bSBarry Smith /*S 11808434afd1SBarry Smith PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function 11815ddc805bSBarry Smith 11825ddc805bSBarry Smith Level: developer 11835ddc805bSBarry Smith 11845ddc805bSBarry Smith Notes: 11858434afd1SBarry Smith The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *. 11865ddc805bSBarry Smith 11875ddc805bSBarry Smith .seealso: `PetscObject`, `PetscObjectDestroy()` 11885ddc805bSBarry Smith S*/ 11898434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void); 11905ddc805bSBarry Smith 11918434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction; 1192d382aafbSBarry Smith 1193d382aafbSBarry Smith /* 1194d382aafbSBarry Smith Functions that can act on any PETSc object. 1195d382aafbSBarry Smith */ 1196014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1197014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1198014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1199014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1201014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1202014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1203014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1206014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1209014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1210014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1212014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1213bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 12148434afd1SBarry Smith #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__)) 1215014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1216014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 12170eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 12180eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1220d382aafbSBarry Smith 1221665c2dedSJed Brown #include <petscviewertypes.h> 1222639ff905SBarry Smith #include <petscoptions.h> 1223639ff905SBarry Smith 1224608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1225608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1226608c71bfSMatthew G. Knepley 12270633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 12280633abcbSJed Brown 1229c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1230dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1231639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 12328434afd1SBarry Smith #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr)) 12330005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1234014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1235014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1236014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1238014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1241685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1242014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1243014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1244013e2dc7SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 12454099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1247b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1248014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1249014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1250d382aafbSBarry Smith 1251e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 12527aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1253e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1254e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1255e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1256e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1257e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1258e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1259e04113cfSBarry Smith PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1260e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1261e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 126215681b3cSBarry Smith 1263ec7429eaSBarry Smith #else 12643ba16761SJacob Faibussowitsch #define PetscSAWsBlock() PETSC_SUCCESS 12653ba16761SJacob Faibussowitsch #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS 12663ba16761SJacob Faibussowitsch #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS 12673ba16761SJacob Faibussowitsch #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS 12683ba16761SJacob Faibussowitsch #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS 12693ba16761SJacob Faibussowitsch #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS 12703ba16761SJacob Faibussowitsch #define PetscStackViewSAWs() PETSC_SUCCESS 12713ba16761SJacob Faibussowitsch #define PetscStackSAWsViewOff() PETSC_SUCCESS 1272e04113cfSBarry Smith #define PetscStackSAWsTakeAccess() 1273e04113cfSBarry Smith #define PetscStackSAWsGrantAccess() 127415681b3cSBarry Smith 1275ec7429eaSBarry Smith #endif 1276b90c6cbeSBarry Smith 127782b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 127882b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 127982b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1280258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1281258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX 1282258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1283258ec3d2SMatthew G. Knepley #endif 12847d5d4d99SBarry Smith 1285a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1286a64a8e02SBarry Smith 1287dfb7d7afSStefano Zampini PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 12884bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer); 12894bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, char **); 1290140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1291140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1292140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1293140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1294140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1295140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1296d382aafbSBarry Smith 1297d382aafbSBarry Smith /* 1298503cfb0cSBarry Smith Dynamic library lists. Lists of names of routines in objects or in dynamic 1299d382aafbSBarry Smith link libraries that will be loaded as needed. 1300d382aafbSBarry Smith */ 1301a240a19fSJed Brown 13028434afd1SBarry Smith #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr)) 13038434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *); 1304140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 13050e6b6b59SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 13068434afd1SBarry Smith #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr)) 13078434afd1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **); 130844ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1309140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1310140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1311140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 13122e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 13132e956fe4SStefano Zampini PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1314d382aafbSBarry Smith 1315014dd563SJed Brown PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1316014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1317014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1318014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1319014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1323d382aafbSBarry Smith 1324d382aafbSBarry Smith /* 1325d382aafbSBarry Smith Useful utility routines 1326d382aafbSBarry Smith */ 1327014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1328014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1329d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1330014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1331014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1332014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1333014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 133458b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 133558b5cd2aSSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1336d382aafbSBarry Smith 133764ac3b0dSPatrick Sanan /*MC 133887497f52SBarry Smith PetscNot - negates a logical type value and returns result as a `PetscBool` 1339503cfb0cSBarry Smith 134064ac3b0dSPatrick Sanan Level: beginner 134164ac3b0dSPatrick Sanan 1342a1cb98faSBarry Smith Note: 1343a1cb98faSBarry Smith This is useful in cases like 1344a1cb98faSBarry Smith .vb 1345a1cb98faSBarry Smith int *a; 1346a1cb98faSBarry Smith PetscBool flag = PetscNot(a) 1347a1cb98faSBarry Smith .ve 1348a1cb98faSBarry Smith where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1349a1cb98faSBarry Smith 1350a1cb98faSBarry Smith .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 135164ac3b0dSPatrick Sanan M*/ 1352d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1353503cfb0cSBarry Smith 1354d382aafbSBarry Smith /*MC 1355d382aafbSBarry Smith PetscHelpPrintf - Prints help messages. 1356d382aafbSBarry Smith 1357d382aafbSBarry Smith Synopsis: 1358aaa7dc30SBarry Smith #include <petscsys.h> 1359659f7ba0SBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1360d382aafbSBarry Smith 13617cdbe19fSJose E. Roman Not Collective, only applies on MPI rank 0; No Fortran Support 13627cdbe19fSJose E. Roman 1363d382aafbSBarry Smith Input Parameters: 1364659f7ba0SBarry Smith + comm - the MPI communicator over which the help message is printed 1365d382aafbSBarry Smith . format - the usual printf() format string 1366659f7ba0SBarry Smith - args - arguments to be printed 1367d382aafbSBarry Smith 1368d382aafbSBarry Smith Level: developer 1369d382aafbSBarry Smith 137095bd0b28SBarry Smith Notes: 1371659f7ba0SBarry Smith You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1372659f7ba0SBarry Smith 1373659f7ba0SBarry Smith To use, write your own function, for example, 137416a05f60SBarry Smith .vb 137516a05f60SBarry Smith PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 137616a05f60SBarry Smith { 137716a05f60SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 137816a05f60SBarry Smith } 137916a05f60SBarry Smith .ve 1380d5b43468SJose E. Roman then do the assignment 1381af27ebaaSBarry Smith .vb 1382af27ebaaSBarry Smith PetscHelpPrintf = mypetschelpprintf; 1383af27ebaaSBarry Smith .ve 1384af27ebaaSBarry Smith 138587497f52SBarry Smith You can do the assignment before `PetscInitialize()`. 1386659f7ba0SBarry Smith 138787497f52SBarry Smith The default routine used is called `PetscHelpPrintfDefault()`. 1388d382aafbSBarry Smith 138916a05f60SBarry Smith .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()` 1390d382aafbSBarry Smith M*/ 13913ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1392d382aafbSBarry Smith 1393fcfd50ebSBarry Smith /* 1394fcfd50ebSBarry Smith Defines PETSc profiling. 1395fcfd50ebSBarry Smith */ 13962c8e378dSBarry Smith #include <petsclog.h> 1397fcfd50ebSBarry Smith 1398fcfd50ebSBarry Smith /* 1399fcfd50ebSBarry Smith Simple PETSc parallel IO for ASCII printing 1400fcfd50ebSBarry Smith */ 1401014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1402014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1403014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 14043ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1405c69effb2SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *); 14063ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14073ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14083ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 14091b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1410fcfd50ebSBarry Smith 14113ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14123ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 14133ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1414d382aafbSBarry Smith 1415d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1416d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1417d781fa04SBarry Smith 1418d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN) 1419014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1420016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 142174ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1422d382aafbSBarry Smith #endif 1423d382aafbSBarry Smith 14243ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 14253ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 14260ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1427014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1428014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1429014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1430d382aafbSBarry Smith 1431014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1432014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1433014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1435014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1436014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1437b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1438d382aafbSBarry Smith 1439d382aafbSBarry Smith /* 1440d382aafbSBarry Smith For use in debuggers 1441d382aafbSBarry Smith */ 1442014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1443014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1444014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1445014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1446014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1447d382aafbSBarry Smith 1448bbcf679cSJacob Faibussowitsch /* 1449bbcf679cSJacob Faibussowitsch Basic memory and string operations. These are usually simple wrappers 1450bbcf679cSJacob Faibussowitsch around the basic Unix system calls, but a few of them have additional 1451bbcf679cSJacob Faibussowitsch functionality and/or error checking. 1452bbcf679cSJacob Faibussowitsch */ 1453bbcf679cSJacob Faibussowitsch #include <petscstring.h> 1454bbcf679cSJacob Faibussowitsch 1455a663daf8SBarry Smith #include <stddef.h> 1456d382aafbSBarry Smith #include <stdlib.h> 14576c7e564aSBarry Smith 1458447bcd8fSJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER) 1459447bcd8fSJacob Faibussowitsch #define PetscPrefetchBlock(a, b, c, d) 1460447bcd8fSJacob Faibussowitsch #else 1461d382aafbSBarry Smith /*MC 1462d382aafbSBarry Smith PetscPrefetchBlock - Prefetches a block of memory 1463d382aafbSBarry Smith 1464eca87e8dSBarry Smith Synopsis: 1465aaa7dc30SBarry Smith #include <petscsys.h> 1466eca87e8dSBarry Smith void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1467eca87e8dSBarry Smith 1468d382aafbSBarry Smith Not Collective 1469d382aafbSBarry Smith 1470d382aafbSBarry Smith Input Parameters: 147116a05f60SBarry Smith + a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`) 1472d382aafbSBarry Smith . n - number of elements to fetch 1473d382aafbSBarry Smith . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 147450d8bf02SJed Brown - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1475d382aafbSBarry Smith 1476d382aafbSBarry Smith Level: developer 1477d382aafbSBarry Smith 1478d382aafbSBarry Smith Notes: 147916a05f60SBarry Smith The last two arguments (`rw` and `t`) must be compile-time constants. 1480d382aafbSBarry Smith 148150d8bf02SJed Brown Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 148250d8bf02SJed Brown equivalent locality hints, but the following macros are always defined to their closest analogue. 148387497f52SBarry 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). 148487497f52SBarry 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. 148587497f52SBarry Smith . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 148687497f52SBarry Smith - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1487d382aafbSBarry Smith 1488d382aafbSBarry Smith This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1489d382aafbSBarry Smith address). 1490d382aafbSBarry Smith 1491d382aafbSBarry Smith M*/ 14929371c9d4SSatish Balay #define PetscPrefetchBlock(a, n, rw, t) \ 14939371c9d4SSatish Balay do { \ 1494d382aafbSBarry Smith const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1495d382aafbSBarry Smith for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1496d382aafbSBarry Smith } while (0) 1497447bcd8fSJacob Faibussowitsch #endif 1498d382aafbSBarry Smith /* 1499d382aafbSBarry Smith Determine if some of the kernel computation routines use 1500d382aafbSBarry Smith Fortran (rather than C) for the numerical calculations. On some machines 1501d382aafbSBarry Smith and compilers (like complex numbers) the Fortran version of the routines 1502d382aafbSBarry Smith is faster than the C/C++ versions. The flag --with-fortran-kernels 1503e2e64c6bSBarry Smith should be used with ./configure to turn these on. 1504d382aafbSBarry Smith */ 1505d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS) 1506d382aafbSBarry Smith 1507d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1508d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1509d382aafbSBarry Smith #endif 1510d382aafbSBarry Smith 1511d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1512d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1513d382aafbSBarry Smith #endif 1514d382aafbSBarry Smith 1515d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1516d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1517d382aafbSBarry Smith #endif 1518d382aafbSBarry Smith 1519d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1520d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1521d382aafbSBarry Smith #endif 1522d382aafbSBarry Smith 1523d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1524d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1525d382aafbSBarry Smith #endif 1526d382aafbSBarry Smith 1527d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1528d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1529d382aafbSBarry Smith #endif 1530d382aafbSBarry Smith 1531d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1532d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1533d382aafbSBarry Smith #endif 1534d382aafbSBarry Smith 1535d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1536d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT 1537d382aafbSBarry Smith #endif 1538d382aafbSBarry Smith 1539d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1540d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1541d382aafbSBarry Smith #endif 1542d382aafbSBarry Smith 1543d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1544d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX 1545d382aafbSBarry Smith #endif 1546d382aafbSBarry Smith 1547d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1548d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1549d382aafbSBarry Smith #endif 1550d382aafbSBarry Smith 1551d382aafbSBarry Smith #endif 1552d382aafbSBarry Smith 1553d382aafbSBarry Smith /* 1554d382aafbSBarry Smith Macros for indicating code that should be compiled with a C interface, 1555d382aafbSBarry Smith rather than a C++ interface. Any routines that are dynamically loaded 1556d382aafbSBarry Smith (such as the PCCreate_XXX() routines) must be wrapped so that the name 1557d382aafbSBarry Smith mangler does not change the functions symbol name. This just hides the 1558d382aafbSBarry Smith ugly extern "C" {} wrappers. 1559d382aafbSBarry Smith */ 1560d382aafbSBarry Smith #if defined(__cplusplus) 1561d382aafbSBarry Smith #define EXTERN_C_BEGIN extern "C" { 1562d382aafbSBarry Smith #define EXTERN_C_END } 1563d382aafbSBarry Smith #else 1564d382aafbSBarry Smith #define EXTERN_C_BEGIN 1565d382aafbSBarry Smith #define EXTERN_C_END 1566d382aafbSBarry Smith #endif 1567d382aafbSBarry Smith 1568d382aafbSBarry Smith /*MC 1569d382aafbSBarry Smith MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1570d382aafbSBarry Smith communication 1571d382aafbSBarry Smith 1572d382aafbSBarry Smith Level: beginner 1573d382aafbSBarry Smith 157416a05f60SBarry Smith Note: 157516a05f60SBarry Smith This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm` 1576d382aafbSBarry Smith 1577db781477SPatrick Sanan .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1578d382aafbSBarry Smith M*/ 1579d382aafbSBarry Smith 1580d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO) 158193d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 158293d501b3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 158393d501b3SJacob 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); 158493d501b3SJacob 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); 158593d501b3SJacob 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); 158693d501b3SJacob 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); 1587d382aafbSBarry Smith #endif 1588d382aafbSBarry Smith 158961b0d812SBarry Smith /*@C 15907de69702SBarry Smith PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32-bits in size), generates an 159187497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1592c73702f5SBarry Smith 159320f4b53cSBarry Smith Not Collective; No Fortran Support 1594c73702f5SBarry Smith 1595c73702f5SBarry Smith Input Parameter: 159687497f52SBarry Smith . a - the `PetscInt64` value 1597c73702f5SBarry Smith 1598c73702f5SBarry Smith Output Parameter: 159987497f52SBarry Smith . b - the resulting `PetscInt` value 1600c73702f5SBarry Smith 1601c73702f5SBarry Smith Level: advanced 1602c73702f5SBarry Smith 160395bd0b28SBarry Smith Note: 16047de69702SBarry 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 1605c73702f5SBarry Smith 1606db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1607c73702f5SBarry Smith @*/ 1608d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1609d71ae5a4SJacob Faibussowitsch { 1610c73702f5SBarry Smith PetscFunctionBegin; 16113ca90d2dSJacob Faibussowitsch *b = 0; 1612f3fa974cSJacob Faibussowitsch // if using 64-bit indices already then this comparison is tautologically true 1613f3fa974cSJacob Faibussowitsch PetscCheck(a < PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 1614f3fa974cSJacob Faibussowitsch *b = (PetscInt)a; 16153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1616c73702f5SBarry Smith } 1617c73702f5SBarry Smith 1618c73702f5SBarry Smith /*@C 16197de69702SBarry Smith PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32-bits in size), generates an 162087497f52SBarry Smith error if the `PetscInt` is not large enough to hold the number. 1621981bb840SJunchao Zhang 1622667f096bSBarry Smith Not Collective; No Fortran Support 1623981bb840SJunchao Zhang 1624981bb840SJunchao Zhang Input Parameter: 162587497f52SBarry Smith . a - the `PetscCount` value 1626981bb840SJunchao Zhang 1627981bb840SJunchao Zhang Output Parameter: 162887497f52SBarry Smith . b - the resulting `PetscInt` value 1629981bb840SJunchao Zhang 1630981bb840SJunchao Zhang Level: advanced 1631981bb840SJunchao Zhang 1632667f096bSBarry Smith Note: 16337de69702SBarry Smith If integers needed for the applications are too large to fit in 32-bit integers you can ./configure using `--with-64-bit-indices` to make `PetscInt` use 64-bit integers 1634981bb840SJunchao Zhang 1635667f096bSBarry Smith .seealso: `PetscCount`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1636981bb840SJunchao Zhang @*/ 1637d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 1638d71ae5a4SJacob Faibussowitsch { 1639981bb840SJunchao Zhang PetscFunctionBegin; 1640981bb840SJunchao Zhang *b = 0; 1641f3fa974cSJacob Faibussowitsch PetscCheck(sizeof(PetscCount) <= sizeof(PetscInt) || a <= PETSC_MAX_INT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices", a); 1642f3fa974cSJacob Faibussowitsch *b = (PetscInt)a; 16433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1644981bb840SJunchao Zhang } 1645981bb840SJunchao Zhang 1646981bb840SJunchao Zhang /*@C 16477de69702SBarry Smith PetscBLASIntCast - casts a `PetscInt` (which may be 64-bits in size) to a `PetscBLASInt` (which may be 32-bits in size), generates an 164887497f52SBarry Smith error if the `PetscBLASInt` is not large enough to hold the number. 164961b0d812SBarry Smith 1650667f096bSBarry Smith Not Collective; No Fortran Support 165161b0d812SBarry Smith 165261b0d812SBarry Smith Input Parameter: 165387497f52SBarry Smith . a - the `PetscInt` value 165461b0d812SBarry Smith 165561b0d812SBarry Smith Output Parameter: 165687497f52SBarry Smith . b - the resulting `PetscBLASInt` value 165761b0d812SBarry Smith 165861b0d812SBarry Smith Level: advanced 165961b0d812SBarry Smith 1660667f096bSBarry Smith Note: 1661f0b7f91aSBarry Smith Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 16621fd49c25SBarry Smith 1663db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 166461b0d812SBarry Smith @*/ 1665d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 1666d71ae5a4SJacob Faibussowitsch { 1667c5df96a5SBarry Smith PetscFunctionBegin; 166854c59aa7SJacob Faibussowitsch *b = 0; 166954c59aa7SJacob Faibussowitsch if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 16707de69702SBarry Smith PetscCheck(a <= PETSC_BLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for BLAS/LAPACK, which is restricted to 32-bit integers. Either you have an invalidly large integer error in your code or you must ./configure PETSc with --with-64-bit-blas-indices for the case you are running", a); 167154c59aa7SJacob Faibussowitsch } 167254c59aa7SJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 1673f3fa974cSJacob Faibussowitsch *b = (PetscBLASInt)a; 16743ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1675c5df96a5SBarry Smith } 1676c5df96a5SBarry Smith 167761b0d812SBarry Smith /*@C 167887497f52SBarry Smith PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 1679eee0c0a6SToby Isaac 1680667f096bSBarry Smith Not Collective; No Fortran Support 1681eee0c0a6SToby Isaac 1682eee0c0a6SToby Isaac Input Parameter: 168387497f52SBarry Smith . a - the `PetscInt` value 1684eee0c0a6SToby Isaac 1685eee0c0a6SToby Isaac Output Parameter: 168687497f52SBarry Smith . b - the resulting `PetscCuBLASInt` value 1687eee0c0a6SToby Isaac 1688eee0c0a6SToby Isaac Level: advanced 1689eee0c0a6SToby Isaac 1690667f096bSBarry Smith Note: 1691eee0c0a6SToby Isaac Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 1692eee0c0a6SToby Isaac 1693db781477SPatrick Sanan .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 1694eee0c0a6SToby Isaac @*/ 1695d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 1696d71ae5a4SJacob Faibussowitsch { 1697eee0c0a6SToby Isaac PetscFunctionBegin; 169854c59aa7SJacob Faibussowitsch *b = 0; 16997de69702SBarry Smith PetscCheck(a <= PETSC_CUBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32-bit integers.", a); 1700f3fa974cSJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to cuBLAS routine", a); 1701f3fa974cSJacob Faibussowitsch *b = (PetscCuBLASInt)a; 17023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1703eee0c0a6SToby Isaac } 1704eee0c0a6SToby Isaac 1705eee0c0a6SToby Isaac /*@C 170647d993e7Ssuyashtn PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 170747d993e7Ssuyashtn 1708667f096bSBarry Smith Not Collective; No Fortran Support 170947d993e7Ssuyashtn 171047d993e7Ssuyashtn Input Parameter: 171147d993e7Ssuyashtn . a - the `PetscInt` value 171247d993e7Ssuyashtn 171347d993e7Ssuyashtn Output Parameter: 171447d993e7Ssuyashtn . b - the resulting `PetscHipBLASInt` value 171547d993e7Ssuyashtn 171647d993e7Ssuyashtn Level: advanced 171747d993e7Ssuyashtn 1718667f096bSBarry Smith Note: 171947d993e7Ssuyashtn Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 172047d993e7Ssuyashtn 172147d993e7Ssuyashtn .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 172247d993e7Ssuyashtn @*/ 172347d993e7Ssuyashtn static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b) 172447d993e7Ssuyashtn { 172547d993e7Ssuyashtn PetscFunctionBegin; 172647d993e7Ssuyashtn *b = 0; 17277de69702SBarry Smith PetscCheck(a <= PETSC_HIPBLAS_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for hipBLAS, which is restricted to 32-bit integers.", a); 1728f3fa974cSJacob Faibussowitsch PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to hipBLAS routine", a); 1729f3fa974cSJacob Faibussowitsch *b = (PetscHipBLASInt)a; 17303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 173147d993e7Ssuyashtn } 173247d993e7Ssuyashtn 173347d993e7Ssuyashtn /*@C 1734af27ebaaSBarry Smith PetscMPIIntCast - casts a `PetscInt` (which may be 64-bits in size) to a `PetscMPIInt` (which may be 32-bits in size), generates an 1735667f096bSBarry Smith error if the `PetscMPIInt` is not large enough to hold the number. 173661b0d812SBarry Smith 1737667f096bSBarry Smith Not Collective; No Fortran Support 173861b0d812SBarry Smith 173961b0d812SBarry Smith Input Parameter: 174087497f52SBarry Smith . a - the `PetscInt` value 174161b0d812SBarry Smith 174261b0d812SBarry Smith Output Parameter: 174387497f52SBarry Smith . b - the resulting `PetscMPIInt` value 174461b0d812SBarry Smith 174561b0d812SBarry Smith Level: advanced 174661b0d812SBarry Smith 1747db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 174861b0d812SBarry Smith @*/ 1749d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 1750d71ae5a4SJacob Faibussowitsch { 17514dc2109aSBarry Smith PetscFunctionBegin; 175254c59aa7SJacob Faibussowitsch *b = 0; 1753f3fa974cSJacob Faibussowitsch PetscCheck(a <= PETSC_MPI_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT " is too big for MPI buffer length. Maximum supported value is %d", a, PETSC_MPI_INT_MAX); 1754f3fa974cSJacob Faibussowitsch *b = (PetscMPIInt)a; 17553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 17564dc2109aSBarry Smith } 17574dc2109aSBarry Smith 1758f3fa974cSJacob Faibussowitsch #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b))) 17592f18eb33SBarry Smith 17602f18eb33SBarry Smith /*@C 1761f3fa974cSJacob Faibussowitsch PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive 1762f3fa974cSJacob Faibussowitsch `PetscInt` and truncates the value to slightly less than the maximal possible value. 17632f18eb33SBarry Smith 176420f4b53cSBarry Smith Not Collective; No Fortran Support 17652f18eb33SBarry Smith 1766d8d19677SJose E. Roman Input Parameters: 1767f3fa974cSJacob Faibussowitsch + a - The `PetscReal` value 1768f3fa974cSJacob Faibussowitsch - b - The `PetscInt` value 17692f18eb33SBarry Smith 1770667f096bSBarry Smith Level: advanced 1771667f096bSBarry Smith 1772f3fa974cSJacob Faibussowitsch Notes: 1773f3fa974cSJacob Faibussowitsch Returns the result as a `PetscInt` value. 17742f18eb33SBarry Smith 1775f3fa974cSJacob Faibussowitsch Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`. 1776667f096bSBarry Smith 1777f3fa974cSJacob Faibussowitsch Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate 1778f3fa974cSJacob Faibussowitsch to fit a `PetscInt`. 1779667f096bSBarry Smith 1780f3fa974cSJacob Faibussowitsch Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an 1781f3fa974cSJacob Faibussowitsch error if the result will not fit in a `PetscInt`. 17822f18eb33SBarry Smith 1783b5e6e808SPierre Jolivet Developer Notes: 1784f3fa974cSJacob Faibussowitsch We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but 1785f3fa974cSJacob Faibussowitsch requires many more checks. 17862f18eb33SBarry Smith 1787f3fa974cSJacob Faibussowitsch This is used where we compute approximate sizes for workspace and need to insure the 1788f3fa974cSJacob Faibussowitsch workspace is index-able. 17891fd49c25SBarry Smith 1790f3fa974cSJacob Faibussowitsch .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 17912f18eb33SBarry Smith @*/ 1792d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 1793d71ae5a4SJacob Faibussowitsch { 17945f80ce2aSJacob Faibussowitsch PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 17952f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 17962f18eb33SBarry Smith return (PetscInt)r; 17972f18eb33SBarry Smith } 17982f18eb33SBarry Smith 17992f18eb33SBarry Smith /*@C 180087497f52SBarry Smith PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 18012f18eb33SBarry Smith 1802667f096bSBarry Smith Not Collective; No Fortran Support 18032f18eb33SBarry Smith 1804d8d19677SJose E. Roman Input Parameters: 1805af27ebaaSBarry Smith + a - the `PetscInt` value 18062f18eb33SBarry Smith - b - the second value 18072f18eb33SBarry Smith 1808390e1bf2SBarry Smith Returns: 1809af27ebaaSBarry Smith The result as a `PetscInt` value 18102f18eb33SBarry Smith 1811667f096bSBarry Smith Level: advanced 1812667f096bSBarry Smith 1813667f096bSBarry Smith Notes: 181487497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1815667f096bSBarry Smith 181687497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1817667f096bSBarry Smith 181887497f52SBarry 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` 18192f18eb33SBarry Smith 1820b5e6e808SPierre Jolivet Developer Notes: 182187497f52SBarry Smith We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 18222f18eb33SBarry Smith 18232f18eb33SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 18242f18eb33SBarry Smith 1825667f096bSBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`, 1826667f096bSBarry Smith `PetscIntSumTruncate()` 18272f18eb33SBarry Smith @*/ 1828d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 1829d71ae5a4SJacob Faibussowitsch { 18305f80ce2aSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 18312f18eb33SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 18322f18eb33SBarry Smith return (PetscInt)r; 18332f18eb33SBarry Smith } 18342f18eb33SBarry Smith 1835f91af8c7SBarry Smith /*@C 183687497f52SBarry Smith PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 1837f91af8c7SBarry Smith 1838667f096bSBarry Smith Not Collective; No Fortran Support 1839f91af8c7SBarry Smith 1840d8d19677SJose E. Roman Input Parameters: 184187497f52SBarry Smith + a - the `PetscInt` value 1842f91af8c7SBarry Smith - b - the second value 1843f91af8c7SBarry Smith 1844390e1bf2SBarry Smith Returns: 1845af27ebaaSBarry Smith The result as a `PetscInt` value 1846f91af8c7SBarry Smith 1847667f096bSBarry Smith Level: advanced 1848667f096bSBarry Smith 1849667f096bSBarry Smith Notes: 185087497f52SBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1851667f096bSBarry Smith 185287497f52SBarry Smith Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1853667f096bSBarry Smith 185487497f52SBarry 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` 1855f91af8c7SBarry Smith 1856b5e6e808SPierre Jolivet Developer Note: 1857f91af8c7SBarry Smith This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 1858f91af8c7SBarry Smith 1859db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1860f91af8c7SBarry Smith @*/ 1861d71ae5a4SJacob Faibussowitsch static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 1862d71ae5a4SJacob Faibussowitsch { 18635f80ce2aSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1864f91af8c7SBarry Smith if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 1865f91af8c7SBarry Smith return (PetscInt)r; 1866f91af8c7SBarry Smith } 1867f91af8c7SBarry Smith 18682f18eb33SBarry Smith /*@C 186987497f52SBarry Smith PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 18702f18eb33SBarry Smith 1871667f096bSBarry Smith Not Collective; No Fortran Support 18722f18eb33SBarry Smith 1873d8d19677SJose E. Roman Input Parameters: 187487497f52SBarry Smith + a - the `PetscInt` value 18752f18eb33SBarry Smith - b - the second value 18762f18eb33SBarry Smith 1877d8d19677SJose E. Roman Output Parameter: 187816a05f60SBarry 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 18792f18eb33SBarry Smith 1880667f096bSBarry Smith Level: advanced 18812f18eb33SBarry Smith 1882667f096bSBarry Smith Notes: 1883667f096bSBarry Smith Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 1884667f096bSBarry Smith 1885667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1886f5f57ec0SBarry Smith 1887b5e6e808SPierre Jolivet Developer Note: 188816a05f60SBarry 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. 188916a05f60SBarry Smith `PetscIntSumError()` can be used to check for this situation. 18902f18eb33SBarry Smith 1891db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 18922f18eb33SBarry Smith @*/ 1893d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 1894d71ae5a4SJacob Faibussowitsch { 1895f3fa974cSJacob Faibussowitsch PetscInt64 r = PetscInt64Mult(a, b); 18962f18eb33SBarry Smith 18972f18eb33SBarry Smith PetscFunctionBegin; 1898c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 1899f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 1900f3fa974cSJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, 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); 1901f3fa974cSJacob Faibussowitsch } 19023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1903f91af8c7SBarry Smith } 1904f91af8c7SBarry Smith 1905f91af8c7SBarry Smith /*@C 1906f91af8c7SBarry Smith 190787497f52SBarry Smith PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 1908f91af8c7SBarry Smith 1909667f096bSBarry Smith Not Collective; No Fortran Support 1910f91af8c7SBarry Smith 1911d8d19677SJose E. Roman Input Parameters: 191287497f52SBarry Smith + a - the `PetscInt` value 1913f91af8c7SBarry Smith - b - the second value 1914f91af8c7SBarry Smith 1915d8d19677SJose E. Roman Output Parameter: 191616a05f60SBarry 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 1917f91af8c7SBarry Smith 1918f91af8c7SBarry Smith Level: advanced 1919f91af8c7SBarry Smith 1920667f096bSBarry Smith Notes: 19217de69702SBarry Smith Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64` 1922667f096bSBarry Smith 1923667f096bSBarry Smith Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1924667f096bSBarry Smith 1925db781477SPatrick Sanan .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1926f91af8c7SBarry Smith @*/ 1927d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 1928d71ae5a4SJacob Faibussowitsch { 1929f3fa974cSJacob Faibussowitsch PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1930f91af8c7SBarry Smith 1931f91af8c7SBarry Smith PetscFunctionBegin; 1932c72d0b4cSJacob Faibussowitsch if (result) *result = (PetscInt)r; 1933f3fa974cSJacob Faibussowitsch if (!PetscDefined(USE_64BIT_INDICES)) { 1934f3fa974cSJacob Faibussowitsch PetscCheck(r <= PETSC_MAX_INT, 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); 1935f3fa974cSJacob Faibussowitsch } 19363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19372f18eb33SBarry Smith } 1938c5df96a5SBarry Smith 1939d382aafbSBarry Smith /* 19402981ebdbSBarry Smith The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 1941d382aafbSBarry Smith */ 1942d382aafbSBarry Smith #if defined(hz) 1943d382aafbSBarry Smith #undef hz 1944d382aafbSBarry Smith #endif 1945d382aafbSBarry Smith 1946d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H) 1947d382aafbSBarry Smith #include <sys/types.h> 1948d382aafbSBarry Smith #endif 1949d382aafbSBarry Smith 1950d382aafbSBarry Smith /*MC 1951d382aafbSBarry Smith 195266d79e26SBarry 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++ 195316a05f60SBarry Smith and Fortran compilers when `petscsys.h` is included. 195466d79e26SBarry Smith 1955baca6076SPierre 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> 195666d79e26SBarry Smith 195766d79e26SBarry 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) 195866d79e26SBarry Smith 195966d79e26SBarry 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 196066d79e26SBarry Smith where only a change in the major version number (x) indicates a change in the API. 196166d79e26SBarry Smith 196266d79e26SBarry 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 196366d79e26SBarry Smith 196466d79e26SBarry 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), 196566d79e26SBarry 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 196666d79e26SBarry Smith version number (x.y.z). 196766d79e26SBarry Smith 196887497f52SBarry Smith `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 196966d79e26SBarry Smith 197087497f52SBarry Smith `PETSC_VERSION_DATE` is the date the x.y.z version was released 197166d79e26SBarry Smith 197287497f52SBarry Smith `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 197366d79e26SBarry Smith 197487497f52SBarry Smith `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 197566d79e26SBarry Smith 197687497f52SBarry Smith `PETSC_VERSION_()` is deprecated and will eventually be removed. 197766d79e26SBarry Smith 1978cbc12506SBarry Smith Level: intermediate 197966d79e26SBarry Smith M*/ 198066d79e26SBarry Smith 1981014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 1982014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 1983014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 1984014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 1985014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 1986014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 198727710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 19885f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 1989d382aafbSBarry Smith 19906a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 199162e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 19926a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 19936a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 1994014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 199562e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 199662e5d2d2SJDBetteridge PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 1997ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 199822ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 1999b6a18d21SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2000014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2001f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 200260e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 2003d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 2004014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2005014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 2006014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 2007981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 20086c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 2009981bb840SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 201017d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 201117d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 2012014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 20135569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 2014014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 201517df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2016014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 201739f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2018014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2019745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 202039f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2021014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2022014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2023014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 20246c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 20256c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2026e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2027ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2028ce605777SToby Isaac 20294d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2030676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2031676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2032676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 20334d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2034676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2035676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2036676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2037676f2a66SJacob Faibussowitsch 2038014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2039014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2040d382aafbSBarry Smith 204176bdecfbSBarry Smith /*J 2042d382aafbSBarry Smith PetscRandomType - String with the name of a PETSc randomizer 2043d382aafbSBarry Smith 2044d382aafbSBarry Smith Level: beginner 2045d382aafbSBarry Smith 2046667f096bSBarry Smith Note: 204787497f52SBarry Smith To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 204816a05f60SBarry Smith with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc. 2049d382aafbSBarry Smith 2050db781477SPatrick Sanan .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 205176bdecfbSBarry Smith J*/ 205219fd82e9SBarry Smith typedef const char *PetscRandomType; 2053d382aafbSBarry Smith #define PETSCRAND "rand" 2054d382aafbSBarry Smith #define PETSCRAND48 "rand48" 2055d382aafbSBarry Smith #define PETSCSPRNG "sprng" 2056c5e4d11fSDmitry Karpeev #define PETSCRANDER48 "rander48" 205725ccb61fSToby Isaac #define PETSCRANDOM123 "random123" 2058808ba619SStefano Zampini #define PETSCCURAND "curand" 2059d382aafbSBarry Smith 2060d382aafbSBarry Smith /* Logging support */ 2061014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2062d382aafbSBarry Smith 2063607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 20644bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void); 2065d382aafbSBarry Smith 2066d382aafbSBarry Smith /* Dynamic creation and loading functions */ 2067140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList; 2068d382aafbSBarry Smith 2069bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 207019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2071014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 207219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2073fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2074014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2075d382aafbSBarry Smith 2076014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2077014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2078014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2079808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2080808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2081014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2082014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2083014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2084014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2085014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2086014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2087d382aafbSBarry Smith 2088014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2089014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2090014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2091014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2092014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2093014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2094014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 209597540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 20968a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 209797540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2098d382aafbSBarry Smith 2099d71ae5a4SJacob Faibussowitsch static inline PetscBool PetscBinaryBigEndian(void) 2100d71ae5a4SJacob Faibussowitsch { 21019371c9d4SSatish Balay long _petsc_v = 1; 21029371c9d4SSatish Balay return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 21039371c9d4SSatish Balay } 210430815ce0SLisandro Dalcin 21059860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 21069860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2107f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2108f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2109014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2113014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2114014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2115014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2116c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER) 2117e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2118c891a504SStefano Zampini #endif 2119d382aafbSBarry Smith 2120014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2122014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2123d382aafbSBarry Smith 2124014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2125014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2126014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2127014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2128014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2129014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 21302a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2131d382aafbSBarry Smith 2132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2133014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2135014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 213793d501b3SJacob 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); 213893d501b3SJacob 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); 213993d501b3SJacob 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); 2140d382aafbSBarry Smith 21416145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 21426145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 21436145cd65SJed Brown 2144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2145d382aafbSBarry Smith 2146ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2147ce94432eSBarry Smith 2148d382aafbSBarry Smith struct _n_PetscSubcomm { 2149d382aafbSBarry Smith MPI_Comm parent; /* parent communicator */ 2150d382aafbSBarry Smith MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2151306c2d5bSBarry Smith MPI_Comm child; /* the sub-communicator */ 215245487dadSJed Brown PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 215345487dadSJed Brown PetscMPIInt color; /* color of processors belong to this communicator */ 2154708d824cSJed Brown PetscMPIInt *subsize; /* size of subcommunicator[color] */ 215545487dadSJed Brown PetscSubcommType type; 2156e5acf8a4SHong Zhang char *subcommprefix; 2157d382aafbSBarry Smith }; 2158d382aafbSBarry Smith 2159d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2160d71ae5a4SJacob Faibussowitsch { 21619371c9d4SSatish Balay return scomm->parent; 21629371c9d4SSatish Balay } 2163d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2164d71ae5a4SJacob Faibussowitsch { 21659371c9d4SSatish Balay return scomm->child; 21669371c9d4SSatish Balay } 2167d71ae5a4SJacob Faibussowitsch static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2168d71ae5a4SJacob Faibussowitsch { 21699371c9d4SSatish Balay return scomm->dupparent; 21709371c9d4SSatish Balay } 2171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2173014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2174014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 217565d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2176053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2177f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2178e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2179a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2180a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2181a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2182d382aafbSBarry Smith 21839962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 21849962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 21859962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 21869962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 21879962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 21889962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 21899962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 21909962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 21919962606eSBarry Smith 21925e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 21935f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 21945f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 21955f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 21965f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 21975e71baefSBarry Smith 2198a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2199a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2200a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2201a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2202a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2203a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2204a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2205a32e93adSJunchao Zhang 220613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 22070f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 220813e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2209137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2210137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2211137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 221213e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 221313e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 22140f453b92SJed Brown 2215471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2216471ecdacSJed Brown * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2217471ecdacSJed Brown * possible. */ 2218d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2219d71ae5a4SJacob Faibussowitsch { 22209371c9d4SSatish Balay return PetscSegBufferGet(seg, count, (void **)slot); 22219371c9d4SSatish Balay } 2222d382aafbSBarry Smith 22239de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 22249de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 22259de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 22269de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 22279de0f6ecSBarry Smith 2228ace2fbaeSBarry Smith #include <stdarg.h> 2229ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2230ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2231ace2fbaeSBarry Smith 2232268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2233fbfcfee5SBarry Smith 22341f817a21SBarry Smith /*@C 22351f817a21SBarry Smith PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 22361f817a21SBarry Smith 2237667f096bSBarry Smith Not Collective; No Fortran Support 22381f817a21SBarry Smith 22391f817a21SBarry Smith Input Parameters: 224035cb6cd3SPierre Jolivet + cite - the bibtex item, formatted to displayed on multiple lines nicely 224187497f52SBarry Smith - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 22421f817a21SBarry Smith 2243667f096bSBarry Smith Options Database Key: 22443c7db156SBarry Smith . -citations [filename] - print out the bibtex entries for the given computation 22453c7db156SBarry Smith 2246850545d0SSatish Balay Level: intermediate 22471f817a21SBarry Smith @*/ 2248d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2249d71ae5a4SJacob Faibussowitsch { 2250dff31646SBarry Smith size_t len; 2251dff31646SBarry Smith char *vstring; 2252dff31646SBarry Smith 22531f817a21SBarry Smith PetscFunctionBegin; 22543ba16761SJacob Faibussowitsch if (set && *set) PetscFunctionReturn(PETSC_SUCCESS); 22559566063dSJacob Faibussowitsch PetscCall(PetscStrlen(cit, &len)); 22569566063dSJacob Faibussowitsch PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 22579566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(vstring, cit, len)); 2258dff31646SBarry Smith if (set) *set = PETSC_TRUE; 22593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2260dff31646SBarry Smith } 2261dff31646SBarry Smith 2262fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2263fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2264f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2265fe278a28SBarry Smith 2266f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2267f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 22684bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]); 2269b967cddfSBarry Smith 22709f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 22714bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t); 22724bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]); 22739f4d3c52SBarry Smith 227468e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 22755dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2276dff31646SBarry Smith 2277b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG) 2278d71ae5a4SJacob Faibussowitsch static inline unsigned int PetscStrHash(const char *str) 2279d71ae5a4SJacob Faibussowitsch { 2280df05ca09SBarry Smith unsigned int c, hash = 5381; 2281df05ca09SBarry Smith 2282503e1a2cSLisandro Dalcin while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2283df05ca09SBarry Smith return hash; 2284df05ca09SBarry Smith } 228577a5e07dSBarry Smith 228677a5e07dSBarry Smith /*MC 228787497f52SBarry Smith MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 228887497f52SBarry Smith same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 228987497f52SBarry Smith resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 229077a5e07dSBarry Smith 229177a5e07dSBarry Smith Synopsis: 229277a5e07dSBarry Smith #include <petscsys.h> 229377a5e07dSBarry Smith PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 229477a5e07dSBarry Smith 22957cdbe19fSJose E. Roman Collective 22967cdbe19fSJose E. Roman 229777a5e07dSBarry Smith Input Parameters: 2298df05ca09SBarry Smith + a - pointer to the input data to be reduced 2299df05ca09SBarry Smith . c - the number of MPI data items in a and b 230087497f52SBarry Smith . d - the MPI datatype, for example `MPI_INT` 230187497f52SBarry Smith . e - the MPI operation, for example `MPI_SUM` 2302df05ca09SBarry Smith - fcomm - the MPI communicator on which the operation occurs 230377a5e07dSBarry Smith 230477a5e07dSBarry Smith Output Parameter: 2305df05ca09SBarry Smith . b - the reduced values 230677a5e07dSBarry Smith 2307667f096bSBarry Smith Level: developer 2308667f096bSBarry Smith 2309e28ce29aSPatrick Sanan Notes: 231087497f52SBarry Smith In optimized mode this directly calls `MPI_Allreduce()` 231177a5e07dSBarry Smith 2312df05ca09SBarry Smith This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2313df05ca09SBarry Smith 231487497f52SBarry Smith The error code this returns should be checked with `PetscCall()` even though it looks like an MPI function because it always returns PETSc error codes 2315df05ca09SBarry Smith 2316db781477SPatrick Sanan .seealso: `MPI_Allreduce()` 231777a5e07dSBarry Smith M*/ 23189371c9d4SSatish Balay #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 23193ba16761SJacob Faibussowitsch PetscMacroReturnStandard( \ 23203ba16761SJacob Faibussowitsch PetscMPIInt a_b1[6], a_b2[6]; \ 23213ba16761SJacob Faibussowitsch int _mpiu_allreduce_c_int = (int)(c); \ 23223ba16761SJacob Faibussowitsch a_b1[0] = -(PetscMPIInt)__LINE__; \ 23233ba16761SJacob Faibussowitsch a_b1[1] = -a_b1[0]; \ 23243ba16761SJacob Faibussowitsch a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \ 23253ba16761SJacob Faibussowitsch a_b1[3] = -a_b1[2]; \ 23263ba16761SJacob Faibussowitsch a_b1[4] = -(PetscMPIInt)(c); \ 23273ba16761SJacob Faibussowitsch a_b1[5] = -a_b1[4]; \ 23283ba16761SJacob Faibussowitsch \ 23293ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \ 23303ba16761SJacob Faibussowitsch PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); \ 23313ba16761SJacob Faibussowitsch PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); \ 23323ba16761SJacob Faibussowitsch PetscCheck(-a_b2[4] == a_b2[5], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called with different counts %d on different processors", _mpiu_allreduce_c_int); \ 23333ba16761SJacob Faibussowitsch PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)));) 2334b2566f29SBarry Smith #else 2335f3fa974cSJacob Faibussowitsch #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)))) 2336b2566f29SBarry Smith #endif 2337b2566f29SBarry Smith 2338b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 23398198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 23408198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 23412f065d89SBarry Smith #endif 23428198064fSBarry Smith 2343cd88fca5SStefano Zampini /* this is a vile hack */ 2344cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI) 23459371c9d4SSatish 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) 2346cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2347cd88fca5SStefano Zampini #endif 2348961fb248SStefano Zampini #endif 2349cd88fca5SStefano Zampini 235012801b39SBarry Smith /* 235160fbe2beSVaclav Hapla List of external packages and queries on it 235260fbe2beSVaclav Hapla */ 235360fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 235460fbe2beSVaclav Hapla 2355f1f2ae84SBarry Smith /* this cannot go here because it may be in a different shared library */ 2356f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2357f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2358f1f2ae84SBarry Smith PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 23597a99bfcaSBarry Smith PETSC_EXTERN PetscBool PCMPIServerActive; 2360fbf9dbe5SBarry Smith 2361edd03b47SJacob Faibussowitsch #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS 2362046ed546SBarry Smith 2363046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt); 2364046ed546SBarry Smith PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *); 23658e3a54c0SPierre Jolivet 23668e3a54c0SPierre Jolivet /*MC 23678e3a54c0SPierre Jolivet PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset 23688e3a54c0SPierre Jolivet 23698e3a54c0SPierre Jolivet Level: beginner 23708e3a54c0SPierre Jolivet 23718e3a54c0SPierre Jolivet Note: 23728e3a54c0SPierre Jolivet This is needed to avoid errors with undefined-behavior sanitizers such as 23738e3a54c0SPierre Jolivet UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags 23748e3a54c0SPierre Jolivet M*/ 23758e3a54c0SPierre Jolivet #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL) 2376