1 /* 2 This is the main PETSc include file (for C and C++). It is included by all 3 other PETSc include files, so it almost never has to be specifically included. 4 Portions of this code are under: 5 Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. 6 */ 7 #pragma once 8 9 /* ========================================================================== */ 10 /* 11 petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 12 found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that 13 PETSc's makefiles add to the compiler rules. 14 For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same 15 directory as the other PETSc include files. 16 */ 17 #include <petscconf.h> 18 #include <petscconf_poison.h> 19 #include <petscfix.h> 20 #include <petscmacros.h> 21 22 /* SUBMANSEC = Sys */ 23 24 #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS) 25 /* 26 Feature test macros must be included before headers defined by IEEE Std 1003.1-2001 27 We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS 28 */ 29 #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE) 30 #define _POSIX_C_SOURCE 200112L 31 #endif 32 #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE) 33 #define _BSD_SOURCE 34 #endif 35 #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE) 36 #define _DEFAULT_SOURCE 37 #endif 38 #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE) 39 #define _GNU_SOURCE 40 #endif 41 #endif 42 43 #include <petscsystypes.h> 44 45 /* ========================================================================== */ 46 47 /* 48 Defines the interface to MPI allowing the use of all MPI functions. 49 50 PETSc does not use the C++ binding of MPI at ALL. The following flag 51 makes sure the C++ bindings are not included. The C++ bindings REQUIRE 52 putting mpi.h before ANY C++ include files, we cannot control this 53 with all PETSc users. Users who want to use the MPI C++ bindings can include 54 mpicxx.h directly in their code 55 */ 56 #if !defined(MPICH_SKIP_MPICXX) 57 #define MPICH_SKIP_MPICXX 1 58 #endif 59 #if !defined(OMPI_SKIP_MPICXX) 60 #define OMPI_SKIP_MPICXX 1 61 #endif 62 #if defined(PETSC_HAVE_MPIUNI) 63 #include <petsc/mpiuni/mpi.h> 64 #else 65 #include <mpi.h> 66 #endif 67 68 /* 69 Perform various sanity checks that the correct mpi.h is being included at compile time. 70 This usually happens because 71 * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or 72 * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler 73 */ 74 #if defined(PETSC_HAVE_MPIUNI) 75 #ifndef MPIUNI_H 76 #error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h" 77 #endif 78 #elif defined(PETSC_HAVE_I_MPI_NUMVERSION) 79 #if !defined(I_MPI_NUMVERSION) 80 #error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h" 81 #elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION 82 #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" 83 #endif 84 #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION) 85 #if !defined(MVAPICH2_NUMVERSION) 86 #error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h" 87 #elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION 88 #error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version" 89 #endif 90 #elif defined(PETSC_HAVE_MPICH_NUMVERSION) 91 #if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION) 92 #error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h" 93 #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) 94 #error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version" 95 #endif 96 #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 97 #if !defined(OMPI_MAJOR_VERSION) 98 #error "PETSc was configured with Open MPI but now appears to be compiling using a non-Open MPI mpi.h" 99 #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) 100 #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" 101 #endif 102 #elif defined(PETSC_HAVE_MSMPI_VERSION) 103 #if !defined(MSMPI_VER) 104 #error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h" 105 #elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION) 106 #error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version" 107 #endif 108 #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER) 109 #error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of Open MPI, MS-MPI or a MPICH variant" 110 #endif 111 112 /* 113 Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 114 see the top of mpicxx.h in the MPICH2 distribution. 115 */ 116 #include <stdio.h> 117 118 /* MSMPI on 32-bit Microsoft Windows requires this yukky hack - that breaks MPI standard compliance */ 119 #if !defined(MPIAPI) 120 #define MPIAPI 121 #endif 122 123 PETSC_EXTERN MPI_Datatype MPIU_ENUM PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscEnum); 124 PETSC_EXTERN MPI_Datatype MPIU_BOOL PETSC_ATTRIBUTE_MPI_TYPE_TAG(PetscBool); 125 126 /*MC 127 MPIU_INT - Portable MPI datatype corresponding to `PetscInt` independent of the precision of `PetscInt` 128 129 Level: beginner 130 131 Note: 132 In MPI calls that require an MPI datatype that matches a `PetscInt` or array of `PetscInt` values, pass this value. 133 134 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_COUNT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 135 M*/ 136 137 PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR; 138 139 #if defined(PETSC_USE_64BIT_INDICES) 140 #define MPIU_INT MPIU_INT64 141 #else 142 #define MPIU_INT MPI_INT 143 #endif 144 145 /*MC 146 MPIU_COUNT - Portable MPI datatype corresponding to `PetscCount` independent of the precision of `PetscCount` 147 148 Level: beginner 149 150 Note: 151 In MPI calls that require an MPI datatype that matches a `PetscCount` or array of `PetscCount` values, pass this value. 152 153 Developer Note: 154 It seems `MPI_AINT` is unsigned so this may be the wrong choice here since `PetscCount` is signed 155 156 .seealso: `PetscReal`, `PetscScalar`, `PetscComplex`, `PetscInt`, `MPIU_INT`, `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 157 M*/ 158 #define MPIU_COUNT MPI_AINT 159 160 /* 161 For the rare cases when one needs to send a size_t object with MPI 162 */ 163 PETSC_EXTERN MPI_Datatype MPIU_SIZE_T PETSC_ATTRIBUTE_MPI_TYPE_TAG(size_t); 164 165 /* 166 You can use PETSC_STDOUT as a replacement of stdout. You can also change 167 the value of PETSC_STDOUT to redirect all standard output elsewhere 168 */ 169 PETSC_EXTERN FILE *PETSC_STDOUT; 170 171 /* 172 You can use PETSC_STDERR as a replacement of stderr. You can also change 173 the value of PETSC_STDERR to redirect all standard error elsewhere 174 */ 175 PETSC_EXTERN FILE *PETSC_STDERR; 176 177 /* 178 Handle inclusion when using clang compiler with CUDA support 179 __float128 is not available for the device 180 */ 181 #if defined(__clang__) && defined(__CUDA_ARCH__) 182 #define PETSC_SKIP_REAL___FLOAT128 183 #endif 184 185 /* 186 Declare extern C stuff after including external header files 187 */ 188 189 PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND; 190 /* 191 Defines elementary mathematics functions and constants. 192 */ 193 #include <petscmath.h> 194 195 /*MC 196 PETSC_IGNORE - same as `NULL`, means PETSc will ignore this argument 197 198 Level: beginner 199 200 Note: 201 Accepted by many PETSc functions to not set a parameter and instead use a default value 202 203 Fortran Note: 204 Use `PETSC_NULL_INTEGER`, `PETSC_NULL_DOUBLE_PRECISION` etc 205 206 .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_DETERMINE` 207 M*/ 208 #define PETSC_IGNORE PETSC_NULLPTR 209 #define PETSC_NULL PETSC_DEPRECATED_MACRO(3, 19, 0, "PETSC_NULLPTR", ) PETSC_NULLPTR 210 211 /*MC 212 PETSC_DECIDE - standard way of passing in integer or floating point parameter 213 where you wish PETSc to use the default. 214 215 Level: beginner 216 217 .seealso: `PETSC_DEFAULT`, `PETSC_IGNORE`, `PETSC_DETERMINE` 218 M*/ 219 220 /*MC 221 PETSC_DETERMINE - standard way of passing in integer or floating point parameter where you wish PETSc to compute the required value. 222 223 Level: beginner 224 225 Developer Note: 226 I would like to use const `PetscInt` `PETSC_DETERMINE` = `PETSC_DECIDE`; but for 227 some reason this is not allowed by the standard even though `PETSC_DECIDE` is a constant value. 228 229 .seealso: `PETSC_DECIDE`, `PETSC_DEFAULT`, `PETSC_IGNORE`, `VecSetSizes()` 230 M*/ 231 232 /*MC 233 PETSC_DEFAULT - standard way of passing in integer or floating point parameter where you wish PETSc to use the default. 234 235 Level: beginner 236 237 Fortran Note: 238 You need to use `PETSC_DEFAULT_INTEGER` or `PETSC_DEFAULT_REAL`. 239 240 .seealso: `PETSC_DECIDE`, `PETSC_IGNORE`, `PETSC_DETERMINE` 241 M*/ 242 243 /* These MUST be preprocessor defines! see https://gitlab.com/petsc/petsc/-/issues/1370 */ 244 #define PETSC_DECIDE (-1) 245 #define PETSC_DETERMINE PETSC_DECIDE 246 #define PETSC_DEFAULT (-2) 247 248 /*MC 249 PETSC_COMM_WORLD - the equivalent of the `MPI_COMM_WORLD` communicator which represents all the processes that PETSc knows about. 250 251 Level: beginner 252 253 Notes: 254 By default `PETSC_COMM_WORLD` and `MPI_COMM_WORLD` are identical unless you wish to 255 run PETSc on ONLY a subset of `MPI_COMM_WORLD`. In that case create your new (smaller) 256 communicator, call it, say comm, and set `PETSC_COMM_WORLD` = comm BEFORE calling 257 `PetscInitialize()`, but after `MPI_Init()` has been called. 258 259 The value of `PETSC_COMM_WORLD` should never be used or accessed before `PetscInitialize()` 260 is called because it may not have a valid value yet. 261 262 .seealso: `PETSC_COMM_SELF` 263 M*/ 264 PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD; 265 266 /*MC 267 PETSC_COMM_SELF - This is always `MPI_COMM_SELF` 268 269 Level: beginner 270 271 Note: 272 Do not USE/access or set this variable before `PetscInitialize()` has been called. 273 274 .seealso: `PETSC_COMM_WORLD` 275 M*/ 276 #define PETSC_COMM_SELF MPI_COMM_SELF 277 278 /*MC 279 PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes MPI with `MPI_Init_thread()`. 280 281 Level: beginner 282 283 Note: 284 By default `PETSC_MPI_THREAD_REQUIRED` equals `MPI_THREAD_FUNNELED` when the MPI implementation provides MPI_Init_thread(), otherwise it equals `MPI_THREAD_SINGLE` 285 286 .seealso: `PetscInitialize()` 287 M*/ 288 PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED; 289 290 PETSC_EXTERN PetscBool PetscBeganMPI; 291 PETSC_EXTERN PetscBool PetscErrorHandlingInitialized; 292 PETSC_EXTERN PetscBool PetscInitializeCalled; 293 PETSC_EXTERN PetscBool PetscFinalizeCalled; 294 PETSC_EXTERN PetscBool PetscViennaCLSynchronize; 295 296 PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm), PetscErrorCode (*)(MPI_Comm)); 297 PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm, MPI_Comm *, int *); 298 PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm *); 299 PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm, MPI_Comm *); 300 PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm, MPI_Comm *); 301 302 #if defined(PETSC_HAVE_KOKKOS) 303 PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void); /* Initialize Kokkos if not yet. */ 304 #endif 305 306 #if defined(PETSC_HAVE_NVSHMEM) 307 PETSC_EXTERN PetscBool PetscBeganNvshmem; 308 PETSC_EXTERN PetscBool PetscNvshmemInitialized; 309 PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void); 310 #endif 311 312 #if defined(PETSC_HAVE_ELEMENTAL) 313 PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void); 314 PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool *); 315 PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void); 316 #endif 317 318 /*MC 319 PetscMalloc - Allocates memory, One should use `PetscNew()`, `PetscMalloc1()` or `PetscCalloc1()` usually instead of this 320 321 Synopsis: 322 #include <petscsys.h> 323 PetscErrorCode PetscMalloc(size_t m,void **result) 324 325 Not Collective 326 327 Input Parameter: 328 . m - number of bytes to allocate 329 330 Output Parameter: 331 . result - memory allocated 332 333 Level: beginner 334 335 Notes: 336 Memory is always allocated at least double aligned 337 338 It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 339 340 .seealso: `PetscFree()`, `PetscNew()` 341 M*/ 342 #define PetscMalloc(a, b) ((*PetscTrMalloc)((a), PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 343 344 /*MC 345 PetscRealloc - Reallocates memory 346 347 Synopsis: 348 #include <petscsys.h> 349 PetscErrorCode PetscRealloc(size_t m,void **result) 350 351 Not Collective 352 353 Input Parameters: 354 + m - number of bytes to allocate 355 - result - previous memory 356 357 Output Parameter: 358 . result - new memory allocated 359 360 Level: developer 361 362 Note: 363 Memory is always allocated at least double aligned 364 365 .seealso: `PetscMalloc()`, `PetscFree()`, `PetscNew()` 366 M*/ 367 #define PetscRealloc(a, b) ((*PetscTrRealloc)((a), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (void **)(b))) 368 369 /*MC 370 PetscAddrAlign - Rounds up an address to `PETSC_MEMALIGN` alignment 371 372 Synopsis: 373 #include <petscsys.h> 374 void *PetscAddrAlign(void *addr) 375 376 Not Collective 377 378 Input Parameter: 379 . addr - address to align (any pointer type) 380 381 Level: developer 382 383 .seealso: `PetscMallocAlign()` 384 M*/ 385 #define PetscAddrAlign(a) ((void *)((((PETSC_UINTPTR_T)(a)) + (PETSC_MEMALIGN - 1)) & ~(PETSC_MEMALIGN - 1))) 386 387 /*MC 388 PetscCalloc - Allocates a cleared (zeroed) memory region aligned to `PETSC_MEMALIGN` 389 390 Synopsis: 391 #include <petscsys.h> 392 PetscErrorCode PetscCalloc(size_t m,void **result) 393 394 Not Collective 395 396 Input Parameter: 397 . m - number of bytes to allocate 398 399 Output Parameter: 400 . result - memory allocated 401 402 Level: beginner 403 404 Notes: 405 Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers 406 407 It is safe to allocate size 0 and pass the resulting pointer (which may or may not be `NULL`) to `PetscFree()`. 408 409 .seealso: `PetscFree()`, `PetscNew()` 410 M*/ 411 #define PetscCalloc(m, result) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)m), (result)) 412 413 /*MC 414 PetscMalloc1 - Allocates an array of memory aligned to `PETSC_MEMALIGN` 415 416 Synopsis: 417 #include <petscsys.h> 418 PetscErrorCode PetscMalloc1(size_t m1,type **r1) 419 420 Not Collective 421 422 Input Parameter: 423 . m1 - number of elements to allocate (may be zero) 424 425 Output Parameter: 426 . r1 - memory allocated 427 428 Level: beginner 429 430 Note: 431 This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not 432 multiply the number of elements requested by the `sizeof()` the type. For example use 433 .vb 434 PetscInt *id; 435 PetscMalloc1(10,&id); 436 .ve 437 not 438 .vb 439 PetscInt *id; 440 PetscMalloc1(10*sizeof(PetscInt),&id); 441 .ve 442 443 Does not zero the memory allocated, use `PetscCalloc1()` to obtain memory that has been zeroed. 444 445 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 446 M*/ 447 #define PetscMalloc1(m1, r1) PetscMallocA(1, PETSC_FALSE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 448 449 /*MC 450 PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to `PETSC_MEMALIGN` 451 452 Synopsis: 453 #include <petscsys.h> 454 PetscErrorCode PetscCalloc1(size_t m1,type **r1) 455 456 Not Collective 457 458 Input Parameter: 459 . m1 - number of elements to allocate in 1st chunk (may be zero) 460 461 Output Parameter: 462 . r1 - memory allocated 463 464 Level: beginner 465 466 Note: 467 See `PetsMalloc1()` for more details on usage. 468 469 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 470 M*/ 471 #define PetscCalloc1(m1, r1) PetscMallocA(1, PETSC_TRUE, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ((size_t)((size_t)m1) * sizeof(**(r1))), (r1)) 472 473 /*MC 474 PetscMalloc2 - Allocates 2 arrays of memory both aligned to `PETSC_MEMALIGN` 475 476 Synopsis: 477 #include <petscsys.h> 478 PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2) 479 480 Not Collective 481 482 Input Parameters: 483 + m1 - number of elements to allocate in 1st chunk (may be zero) 484 - m2 - number of elements to allocate in 2nd chunk (may be zero) 485 486 Output Parameters: 487 + r1 - memory allocated in first chunk 488 - r2 - memory allocated in second chunk 489 490 Level: developer 491 492 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc2()` 493 M*/ 494 #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)) 495 496 /*MC 497 PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to `PETSC_MEMALIGN` 498 499 Synopsis: 500 #include <petscsys.h> 501 PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2) 502 503 Not Collective 504 505 Input Parameters: 506 + m1 - number of elements to allocate in 1st chunk (may be zero) 507 - m2 - number of elements to allocate in 2nd chunk (may be zero) 508 509 Output Parameters: 510 + r1 - memory allocated in first chunk 511 - r2 - memory allocated in second chunk 512 513 Level: developer 514 515 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc2()` 516 M*/ 517 #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)) 518 519 /*MC 520 PetscMalloc3 - Allocates 3 arrays of memory, all aligned to `PETSC_MEMALIGN` 521 522 Synopsis: 523 #include <petscsys.h> 524 PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 525 526 Not Collective 527 528 Input Parameters: 529 + m1 - number of elements to allocate in 1st chunk (may be zero) 530 . m2 - number of elements to allocate in 2nd chunk (may be zero) 531 - m3 - number of elements to allocate in 3rd chunk (may be zero) 532 533 Output Parameters: 534 + r1 - memory allocated in first chunk 535 . r2 - memory allocated in second chunk 536 - r3 - memory allocated in third chunk 537 538 Level: developer 539 540 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc3()`, `PetscFree3()` 541 M*/ 542 #define PetscMalloc3(m1, r1, m2, r2, m3, r3) \ 543 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)) 544 545 /*MC 546 PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 547 548 Synopsis: 549 #include <petscsys.h> 550 PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3) 551 552 Not Collective 553 554 Input Parameters: 555 + m1 - number of elements to allocate in 1st chunk (may be zero) 556 . m2 - number of elements to allocate in 2nd chunk (may be zero) 557 - m3 - number of elements to allocate in 3rd chunk (may be zero) 558 559 Output Parameters: 560 + r1 - memory allocated in first chunk 561 . r2 - memory allocated in second chunk 562 - r3 - memory allocated in third chunk 563 564 Level: developer 565 566 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscCalloc2()`, `PetscMalloc3()`, `PetscFree3()` 567 M*/ 568 #define PetscCalloc3(m1, r1, m2, r2, m3, r3) \ 569 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)) 570 571 /*MC 572 PetscMalloc4 - Allocates 4 arrays of memory, all aligned to `PETSC_MEMALIGN` 573 574 Synopsis: 575 #include <petscsys.h> 576 PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 577 578 Not Collective 579 580 Input Parameters: 581 + m1 - number of elements to allocate in 1st chunk (may be zero) 582 . m2 - number of elements to allocate in 2nd chunk (may be zero) 583 . m3 - number of elements to allocate in 3rd chunk (may be zero) 584 - m4 - number of elements to allocate in 4th chunk (may be zero) 585 586 Output Parameters: 587 + r1 - memory allocated in first chunk 588 . r2 - memory allocated in second chunk 589 . r3 - memory allocated in third chunk 590 - r4 - memory allocated in fourth chunk 591 592 Level: developer 593 594 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 595 M*/ 596 #define PetscMalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 597 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)) 598 599 /*MC 600 PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 601 602 Synopsis: 603 #include <petscsys.h> 604 PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4) 605 606 Not Collective 607 608 Input Parameters: 609 + m1 - number of elements to allocate in 1st chunk (may be zero) 610 . m2 - number of elements to allocate in 2nd chunk (may be zero) 611 . m3 - number of elements to allocate in 3rd chunk (may be zero) 612 - m4 - number of elements to allocate in 4th chunk (may be zero) 613 614 Output Parameters: 615 + r1 - memory allocated in first chunk 616 . r2 - memory allocated in second chunk 617 . r3 - memory allocated in third chunk 618 - r4 - memory allocated in fourth chunk 619 620 Level: developer 621 622 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc4()`, `PetscFree4()` 623 M*/ 624 #define PetscCalloc4(m1, r1, m2, r2, m3, r3, m4, r4) \ 625 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)) 626 627 /*MC 628 PetscMalloc5 - Allocates 5 arrays of memory, all aligned to `PETSC_MEMALIGN` 629 630 Synopsis: 631 #include <petscsys.h> 632 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) 633 634 Not Collective 635 636 Input Parameters: 637 + m1 - number of elements to allocate in 1st chunk (may be zero) 638 . m2 - number of elements to allocate in 2nd chunk (may be zero) 639 . m3 - number of elements to allocate in 3rd chunk (may be zero) 640 . m4 - number of elements to allocate in 4th chunk (may be zero) 641 - m5 - number of elements to allocate in 5th chunk (may be zero) 642 643 Output Parameters: 644 + r1 - memory allocated in first chunk 645 . r2 - memory allocated in second chunk 646 . r3 - memory allocated in third chunk 647 . r4 - memory allocated in fourth chunk 648 - r5 - memory allocated in fifth chunk 649 650 Level: developer 651 652 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc5()`, `PetscFree5()` 653 M*/ 654 #define PetscMalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 655 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)) 656 657 /*MC 658 PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 659 660 Synopsis: 661 #include <petscsys.h> 662 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) 663 664 Not Collective 665 666 Input Parameters: 667 + m1 - number of elements to allocate in 1st chunk (may be zero) 668 . m2 - number of elements to allocate in 2nd chunk (may be zero) 669 . m3 - number of elements to allocate in 3rd chunk (may be zero) 670 . m4 - number of elements to allocate in 4th chunk (may be zero) 671 - m5 - number of elements to allocate in 5th chunk (may be zero) 672 673 Output Parameters: 674 + r1 - memory allocated in first chunk 675 . r2 - memory allocated in second chunk 676 . r3 - memory allocated in third chunk 677 . r4 - memory allocated in fourth chunk 678 - r5 - memory allocated in fifth chunk 679 680 Level: developer 681 682 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc5()`, `PetscFree5()` 683 M*/ 684 #define PetscCalloc5(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5) \ 685 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)) 686 687 /*MC 688 PetscMalloc6 - Allocates 6 arrays of memory, all aligned to `PETSC_MEMALIGN` 689 690 Synopsis: 691 #include <petscsys.h> 692 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) 693 694 Not Collective 695 696 Input Parameters: 697 + m1 - number of elements to allocate in 1st chunk (may be zero) 698 . m2 - number of elements to allocate in 2nd chunk (may be zero) 699 . m3 - number of elements to allocate in 3rd chunk (may be zero) 700 . m4 - number of elements to allocate in 4th chunk (may be zero) 701 . m5 - number of elements to allocate in 5th chunk (may be zero) 702 - m6 - number of elements to allocate in 6th chunk (may be zero) 703 704 Output Parameteasr: 705 + r1 - memory allocated in first chunk 706 . r2 - memory allocated in second chunk 707 . r3 - memory allocated in third chunk 708 . r4 - memory allocated in fourth chunk 709 . r5 - memory allocated in fifth chunk 710 - r6 - memory allocated in sixth chunk 711 712 Level: developer 713 714 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc6()`, `PetscFree3()`, `PetscFree4()`, `PetscFree5()`, `PetscFree6()` 715 M*/ 716 #define PetscMalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 717 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)) 718 719 /*MC 720 PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 721 722 Synopsis: 723 #include <petscsys.h> 724 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) 725 726 Not Collective 727 728 Input Parameters: 729 + m1 - number of elements to allocate in 1st chunk (may be zero) 730 . m2 - number of elements to allocate in 2nd chunk (may be zero) 731 . m3 - number of elements to allocate in 3rd chunk (may be zero) 732 . m4 - number of elements to allocate in 4th chunk (may be zero) 733 . m5 - number of elements to allocate in 5th chunk (may be zero) 734 - m6 - number of elements to allocate in 6th chunk (may be zero) 735 736 Output Parameters: 737 + r1 - memory allocated in first chunk 738 . r2 - memory allocated in second chunk 739 . r3 - memory allocated in third chunk 740 . r4 - memory allocated in fourth chunk 741 . r5 - memory allocated in fifth chunk 742 - r6 - memory allocated in sixth chunk 743 744 Level: developer 745 746 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc6()`, `PetscFree6()` 747 M*/ 748 #define PetscCalloc6(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6) \ 749 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)) 750 751 /*MC 752 PetscMalloc7 - Allocates 7 arrays of memory, all aligned to `PETSC_MEMALIGN` 753 754 Synopsis: 755 #include <petscsys.h> 756 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) 757 758 Not Collective 759 760 Input Parameters: 761 + m1 - number of elements to allocate in 1st chunk (may be zero) 762 . m2 - number of elements to allocate in 2nd chunk (may be zero) 763 . m3 - number of elements to allocate in 3rd chunk (may be zero) 764 . m4 - number of elements to allocate in 4th chunk (may be zero) 765 . m5 - number of elements to allocate in 5th chunk (may be zero) 766 . m6 - number of elements to allocate in 6th chunk (may be zero) 767 - m7 - number of elements to allocate in 7th chunk (may be zero) 768 769 Output Parameters: 770 + r1 - memory allocated in first chunk 771 . r2 - memory allocated in second chunk 772 . r3 - memory allocated in third chunk 773 . r4 - memory allocated in fourth chunk 774 . r5 - memory allocated in fifth chunk 775 . r6 - memory allocated in sixth chunk 776 - r7 - memory allocated in seventh chunk 777 778 Level: developer 779 780 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscCalloc7()`, `PetscFree7()` 781 M*/ 782 #define PetscMalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 783 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)) 784 785 /*MC 786 PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to `PETSC_MEMALIGN` 787 788 Synopsis: 789 #include <petscsys.h> 790 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) 791 792 Not Collective 793 794 Input Parameters: 795 + m1 - number of elements to allocate in 1st chunk (may be zero) 796 . m2 - number of elements to allocate in 2nd chunk (may be zero) 797 . m3 - number of elements to allocate in 3rd chunk (may be zero) 798 . m4 - number of elements to allocate in 4th chunk (may be zero) 799 . m5 - number of elements to allocate in 5th chunk (may be zero) 800 . m6 - number of elements to allocate in 6th chunk (may be zero) 801 - m7 - number of elements to allocate in 7th chunk (may be zero) 802 803 Output Parameters: 804 + r1 - memory allocated in first chunk 805 . r2 - memory allocated in second chunk 806 . r3 - memory allocated in third chunk 807 . r4 - memory allocated in fourth chunk 808 . r5 - memory allocated in fifth chunk 809 . r6 - memory allocated in sixth chunk 810 - r7 - memory allocated in seventh chunk 811 812 Level: developer 813 814 .seealso: `PetscFree()`, `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscMalloc7()`, `PetscFree7()` 815 M*/ 816 #define PetscCalloc7(m1, r1, m2, r2, m3, r3, m4, r4, m5, r5, m6, r6, m7, r7) \ 817 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)) 818 819 /*MC 820 PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to `PETSC_MEMALIGN` 821 822 Synopsis: 823 #include <petscsys.h> 824 PetscErrorCode PetscNew(type **result) 825 826 Not Collective 827 828 Output Parameter: 829 . result - memory allocated, sized to match pointer type 830 831 Level: beginner 832 833 .seealso: `PetscFree()`, `PetscMalloc()`, `PetscCalloc1()`, `PetscMalloc1()` 834 M*/ 835 #define PetscNew(b) PetscCalloc1(1, (b)) 836 837 #define PetscNewLog(o, b) PETSC_DEPRECATED_MACRO(3, 18, 0, "PetscNew()", ) PetscNew((b)) 838 839 /*MC 840 PetscFree - Frees memory 841 842 Synopsis: 843 #include <petscsys.h> 844 PetscErrorCode PetscFree(void *memory) 845 846 Not Collective 847 848 Input Parameter: 849 . memory - memory to free (the pointer is ALWAYS set to `NULL` upon success) 850 851 Level: beginner 852 853 Notes: 854 Do not free memory obtained with `PetscMalloc2()`, `PetscCalloc2()` etc, they must be freed with `PetscFree2()` etc. 855 856 It is safe to call `PetscFree()` on a `NULL` pointer. 857 858 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc1()`, `PetscCalloc1()` 859 M*/ 860 #define PetscFree(a) ((PetscErrorCode)((*PetscTrFree)((void *)(a), __LINE__, PETSC_FUNCTION_NAME, __FILE__) || ((a) = PETSC_NULLPTR, PETSC_SUCCESS))) 861 862 /*MC 863 PetscFree2 - Frees 2 chunks of memory obtained with `PetscMalloc2()` 864 865 Synopsis: 866 #include <petscsys.h> 867 PetscErrorCode PetscFree2(void *memory1,void *memory2) 868 869 Not Collective 870 871 Input Parameters: 872 + memory1 - memory to free 873 - memory2 - 2nd memory to free 874 875 Level: developer 876 877 Notes: 878 Memory must have been obtained with `PetscMalloc2()` 879 880 The arguments need to be in the same order as they were in the call to `PetscMalloc2()` 881 882 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()` 883 M*/ 884 #define PetscFree2(m1, m2) PetscFreeA(2, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2)) 885 886 /*MC 887 PetscFree3 - Frees 3 chunks of memory obtained with `PetscMalloc3()` 888 889 Synopsis: 890 #include <petscsys.h> 891 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 892 893 Not Collective 894 895 Input Parameters: 896 + memory1 - memory to free 897 . memory2 - 2nd memory to free 898 - memory3 - 3rd memory to free 899 900 Level: developer 901 902 Notes: 903 Memory must have been obtained with `PetscMalloc3()` 904 905 The arguments need to be in the same order as they were in the call to `PetscMalloc3()` 906 907 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()` 908 M*/ 909 #define PetscFree3(m1, m2, m3) PetscFreeA(3, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3)) 910 911 /*MC 912 PetscFree4 - Frees 4 chunks of memory obtained with `PetscMalloc4()` 913 914 Synopsis: 915 #include <petscsys.h> 916 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 917 918 Not Collective 919 920 Input Parameters: 921 + m1 - memory to free 922 . m2 - 2nd memory to free 923 . m3 - 3rd memory to free 924 - m4 - 4th memory to free 925 926 Level: developer 927 928 Notes: 929 Memory must have been obtained with `PetscMalloc4()` 930 931 The arguments need to be in the same order as they were in the call to `PetscMalloc4()` 932 933 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()` 934 M*/ 935 #define PetscFree4(m1, m2, m3, m4) PetscFreeA(4, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4)) 936 937 /*MC 938 PetscFree5 - Frees 5 chunks of memory obtained with `PetscMalloc5()` 939 940 Synopsis: 941 #include <petscsys.h> 942 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 943 944 Not Collective 945 946 Input Parameters: 947 + m1 - memory to free 948 . m2 - 2nd memory to free 949 . m3 - 3rd memory to free 950 . m4 - 4th memory to free 951 - m5 - 5th memory to free 952 953 Level: developer 954 955 Notes: 956 Memory must have been obtained with `PetscMalloc5()` 957 958 The arguments need to be in the same order as they were in the call to `PetscMalloc5()` 959 960 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()` 961 M*/ 962 #define PetscFree5(m1, m2, m3, m4, m5) PetscFreeA(5, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5)) 963 964 /*MC 965 PetscFree6 - Frees 6 chunks of memory obtained with `PetscMalloc6()` 966 967 Synopsis: 968 #include <petscsys.h> 969 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 970 971 Not Collective 972 973 Input Parameters: 974 + m1 - memory to free 975 . m2 - 2nd memory to free 976 . m3 - 3rd memory to free 977 . m4 - 4th memory to free 978 . m5 - 5th memory to free 979 - m6 - 6th memory to free 980 981 Level: developer 982 983 Notes: 984 Memory must have been obtained with `PetscMalloc6()` 985 986 The arguments need to be in the same order as they were in the call to `PetscMalloc6()` 987 988 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()` 989 M*/ 990 #define PetscFree6(m1, m2, m3, m4, m5, m6) PetscFreeA(6, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6)) 991 992 /*MC 993 PetscFree7 - Frees 7 chunks of memory obtained with `PetscMalloc7()` 994 995 Synopsis: 996 #include <petscsys.h> 997 PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 998 999 Not Collective 1000 1001 Input Parameters: 1002 + m1 - memory to free 1003 . m2 - 2nd memory to free 1004 . m3 - 3rd memory to free 1005 . m4 - 4th memory to free 1006 . m5 - 5th memory to free 1007 . m6 - 6th memory to free 1008 - m7 - 7th memory to free 1009 1010 Level: developer 1011 1012 Notes: 1013 Memory must have been obtained with `PetscMalloc7()` 1014 1015 The arguments need to be in the same order as they were in the call to `PetscMalloc7()` 1016 1017 .seealso: `PetscNew()`, `PetscMalloc()`, `PetscMalloc2()`, `PetscFree()`, `PetscMalloc3()`, `PetscMalloc4()`, `PetscMalloc5()`, `PetscMalloc6()`, 1018 `PetscMalloc7()` 1019 M*/ 1020 #define PetscFree7(m1, m2, m3, m4, m5, m6, m7) PetscFreeA(7, __LINE__, PETSC_FUNCTION_NAME, __FILE__, &(m1), &(m2), &(m3), &(m4), &(m5), &(m6), &(m7)) 1021 1022 PETSC_EXTERN PetscErrorCode PetscMallocA(int, PetscBool, int, const char *, const char *, size_t, void *, ...); 1023 PETSC_EXTERN PetscErrorCode PetscFreeA(int, int, const char *, const char *, void *, ...); 1024 PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t, PetscBool, int, const char[], const char[], void **); 1025 PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void *, int, const char[], const char[]); 1026 PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t, int, const char[], const char[], void **); 1027 PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool); 1028 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 **)); 1029 PETSC_EXTERN PetscErrorCode PetscMallocClear(void); 1030 1031 /* 1032 Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair. 1033 */ 1034 PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void); 1035 PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void); 1036 #if defined(PETSC_HAVE_CUDA) 1037 PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void); 1038 PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void); 1039 #endif 1040 #if defined(PETSC_HAVE_HIP) 1041 PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void); 1042 PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void); 1043 #endif 1044 1045 #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE 1046 #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION 1047 1048 /* 1049 Routines for tracing memory corruption/bleeding with default PETSc memory allocation 1050 */ 1051 PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *); 1052 PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *); 1053 PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 1054 PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 1055 PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int); 1056 PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int, PetscLogDouble *); 1057 PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool, PetscBool); 1058 PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool *, PetscBool *, PetscBool *); 1059 PETSC_EXTERN PetscErrorCode PetscMallocValidate(int, const char[], const char[]); 1060 PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble); 1061 PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool *); 1062 PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool); 1063 PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool *); 1064 1065 PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType, MPI_Datatype *); 1066 PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype, PetscDataType *); 1067 PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType, size_t *); 1068 PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char *, PetscDataType *, PetscBool *); 1069 1070 /* 1071 These are MPI operations for MPI_Allreduce() etc 1072 */ 1073 PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP; 1074 #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 1075 PETSC_EXTERN MPI_Op MPIU_SUM; 1076 PETSC_EXTERN MPI_Op MPIU_MAX; 1077 PETSC_EXTERN MPI_Op MPIU_MIN; 1078 #else 1079 #define MPIU_SUM MPI_SUM 1080 #define MPIU_MAX MPI_MAX 1081 #define MPIU_MIN MPI_MIN 1082 #endif 1083 PETSC_EXTERN MPI_Op Petsc_Garbage_SetIntersectOp; 1084 PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1085 1086 #if (defined(PETSC_HAVE_REAL___FLOAT128) && !defined(PETSC_SKIP_REAL___FLOAT128)) || (defined(PETSC_HAVE_REAL___FP16) && !defined(PETSC_SKIP_REAL___FP16)) 1087 /*MC 1088 MPIU_SUM___FP16___FLOAT128 - MPI_Op that acts as a replacement for `MPI_SUM` with 1089 custom `MPI_Datatype` `MPIU___FLOAT128`, `MPIU___COMPLEX128`, and `MPIU___FP16`. 1090 1091 Level: advanced 1092 1093 Developer Note: 1094 This should be unified with `MPIU_SUM` 1095 1096 .seealso: `MPIU_REAL`, `MPIU_SCALAR`, `MPIU_COMPLEX` 1097 M*/ 1098 PETSC_EXTERN MPI_Op MPIU_SUM___FP16___FLOAT128; 1099 #endif 1100 PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm, const PetscInt[], PetscInt *, PetscInt *); 1101 1102 PETSC_EXTERN PetscErrorCode MPIULong_Send(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1103 PETSC_EXTERN PetscErrorCode MPIULong_Recv(void *, PetscInt, MPI_Datatype, PetscMPIInt, PetscMPIInt, MPI_Comm) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(1, 3); 1104 1105 /* 1106 Defines PETSc error handling. 1107 */ 1108 #include <petscerror.h> 1109 1110 PETSC_EXTERN PetscBool PetscCIEnabled; /* code is running in the PETSc test harness CI */ 1111 PETSC_EXTERN PetscBool PetscCIEnabledPortableErrorOutput; /* error output is stripped to ensure portability of error messages across systems */ 1112 PETSC_EXTERN const char *PetscCIFilename(const char *); 1113 PETSC_EXTERN int PetscCILinenumber(int); 1114 1115 #define PETSC_SMALLEST_CLASSID ((PetscClassId)1211211) 1116 PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID; 1117 PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID; 1118 PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[], PetscClassId *); 1119 PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject, PetscObjectId *); 1120 PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject, PetscObjectId, PetscBool *); 1121 1122 /* 1123 Routines that get memory usage information from the OS 1124 */ 1125 PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 1126 PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 1127 PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 1128 PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]); 1129 1130 PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal); 1131 1132 /* 1133 Initialization of PETSc 1134 */ 1135 PETSC_EXTERN PetscErrorCode PetscInitialize(int *, char ***, const char[], const char[]); 1136 PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int, char **, const char[], const char[]); 1137 PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void); 1138 PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *); 1139 PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *); 1140 PETSC_EXTERN PetscErrorCode PetscFinalize(void); 1141 PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void); 1142 PETSC_EXTERN PetscErrorCode PetscGetArgs(int *, char ***); 1143 PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***); 1144 PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **); 1145 1146 PETSC_EXTERN PetscErrorCode PetscEnd(void); 1147 PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void); 1148 PETSC_EXTERN PetscErrorCode PetscSysFinalizePackage(void); 1149 1150 PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[], const char[]); 1151 PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void); 1152 PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void); 1153 PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject, const char[]); 1154 1155 PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscErrorCode (*)(void), void *, PetscErrorCode (*)(void **), PetscBool *); 1156 1157 /* 1158 These are so that in extern C code we can caste function pointers to non-extern C 1159 function pointers. Since the regular C++ code expects its function pointers to be C++ 1160 */ 1161 1162 /*S 1163 PetscVoidFn - A prototype of a void (fn)(void) function 1164 1165 Level: developer 1166 1167 Notes: 1168 The deprecated `PetscVoidFunction` works as a replacement for `PetscVoidFn` *. 1169 1170 The deprecated `PetscVoidStarFunction` works as a replacement for `PetscVoidFn` **. 1171 1172 .seealso: `PetscObject`, `PetscObjectDestroy()` 1173 S*/ 1174 PETSC_EXTERN_TYPEDEF typedef void(PetscVoidFn)(void); 1175 1176 PETSC_EXTERN_TYPEDEF typedef PetscVoidFn *PetscVoidFunction; 1177 PETSC_EXTERN_TYPEDEF typedef PetscVoidFn **PetscVoidStarFunction; 1178 1179 /*S 1180 PetscErrorCodeFn - A prototype of a PetscErrorCode (fn)(void) function 1181 1182 Level: developer 1183 1184 Notes: 1185 The deprecated `PetscErrorCodeFunction` works as a replacement for `PetscErrorCodeFn` *. 1186 1187 .seealso: `PetscObject`, `PetscObjectDestroy()` 1188 S*/ 1189 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(PetscErrorCodeFn)(void); 1190 1191 PETSC_EXTERN_TYPEDEF typedef PetscErrorCodeFn *PetscErrorCodeFunction; 1192 1193 /* 1194 Functions that can act on any PETSc object. 1195 */ 1196 PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject *); 1197 PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject, MPI_Comm *); 1198 PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject, PetscClassId *); 1199 PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject, const char *[]); 1200 PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject, const char *[]); 1201 PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject, const char[]); 1202 PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject, const char *[]); 1203 PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject, PetscInt); 1204 PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject, PetscInt *); 1205 PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject, PetscObject, PetscInt); 1206 PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject); 1207 PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject, PetscInt *); 1208 PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 1209 PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject, PetscMPIInt *); 1210 PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject, const char[], PetscObject); 1211 PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject, const char[]); 1212 PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject, const char[], PetscObject *); 1213 PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject, const char[], void (*)(void)); 1214 #define PetscObjectComposeFunction(a, b, ...) PetscObjectComposeFunction_Private((a), (b), (PetscVoidFn *)(__VA_ARGS__)) 1215 PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject); 1216 PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject); 1217 PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject); 1218 PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject, PetscObject); 1219 PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm, PetscMPIInt *); 1220 1221 #include <petscviewertypes.h> 1222 #include <petscoptions.h> 1223 1224 PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer, PetscBool, PetscLogDouble); 1225 PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool *); 1226 1227 PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm, PetscInt, PetscObject *, PetscInt *, PetscInt *); 1228 1229 PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer, const char[]); 1230 PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject, PetscViewer); 1231 PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject, PetscViewer); 1232 #define PetscObjectQueryFunction(obj, name, fptr) PetscObjectQueryFunction_Private((obj), (name), (PetscVoidFn **)(fptr)) 1233 PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject, const char[], void (**)(void)); 1234 PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject, const char[]); 1235 PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject, const char[]); 1236 PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject, const char[]); 1237 PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject, const char *[]); 1238 PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject, const char[]); 1239 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1240 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1241 PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject, PetscObject, const char[]); 1242 PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1243 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject, const char[], PetscBool *); 1244 PETSC_EXTERN PetscErrorCode PetscObjectObjectTypeCompare(PetscObject, PetscObject, PetscBool *); 1245 PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject, const char[], PetscBool *); 1246 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1247 PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject, PetscBool *, const char[], ...); 1248 PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1249 PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1250 1251 #if defined(PETSC_HAVE_SAWS) 1252 PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1253 PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1254 PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject, PetscBool); 1255 PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1256 PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1257 PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1258 PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1259 PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1260 PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1261 PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 1262 1263 #else 1264 #define PetscSAWsBlock() PETSC_SUCCESS 1265 #define PetscObjectSAWsViewOff(obj) PETSC_SUCCESS 1266 #define PetscObjectSAWsSetBlock(obj, flg) PETSC_SUCCESS 1267 #define PetscObjectSAWsBlock(obj) PETSC_SUCCESS 1268 #define PetscObjectSAWsGrantAccess(obj) PETSC_SUCCESS 1269 #define PetscObjectSAWsTakeAccess(obj) PETSC_SUCCESS 1270 #define PetscStackViewSAWs() PETSC_SUCCESS 1271 #define PetscStackSAWsViewOff() PETSC_SUCCESS 1272 #define PetscStackSAWsTakeAccess() 1273 #define PetscStackSAWsGrantAccess() 1274 1275 #endif 1276 1277 PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[], PetscDLMode, PetscDLHandle *); 1278 PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 1279 PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle, const char[], void **); 1280 PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **); 1281 #ifdef PETSC_HAVE_CXX 1282 PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **); 1283 #endif 1284 1285 PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void *, PetscStack **); 1286 1287 PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE *, PetscBool); 1288 PETSC_EXTERN PetscErrorCode PetscObjectsView(PetscViewer); 1289 PETSC_EXTERN PetscErrorCode PetscObjectsGetObject(const char *, PetscObject *, char **); 1290 PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList *); 1291 PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList, const char[], PetscObject *); 1292 PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList, PetscObject, char **, PetscBool *); 1293 PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *, const char[], PetscObject); 1294 PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *, const char[]); 1295 PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList, PetscObjectList *); 1296 1297 /* 1298 Dynamic library lists. Lists of names of routines in objects or in dynamic 1299 link libraries that will be loaded as needed. 1300 */ 1301 1302 #define PetscFunctionListAdd(list, name, fptr) PetscFunctionListAdd_Private((list), (name), (PetscVoidFn *)(fptr)) 1303 PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList *, const char[], PetscVoidFn *); 1304 PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList *); 1305 PETSC_EXTERN PetscErrorCode PetscFunctionListClear(PetscFunctionList); 1306 #define PetscFunctionListFind(list, name, fptr) PetscFunctionListFind_Private((list), (name), (PetscVoidFn **)(fptr)) 1307 PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList, const char[], PetscVoidFn **); 1308 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm, FILE *, const char[], const char[], const char[], const char[], PetscFunctionList, const char[], const char[]); 1309 PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList, PetscFunctionList *); 1310 PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList, PetscViewer); 1311 PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList, const char ***, int *); 1312 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintNonEmpty(PetscFunctionList); 1313 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintAll(void); 1314 1315 PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1316 PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm, PetscDLLibrary *, const char[]); 1317 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm, PetscDLLibrary *, const char[]); 1318 PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm, PetscDLLibrary *, const char[], const char[], void **); 1319 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1320 PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm, const char[], char *, size_t, PetscBool *); 1321 PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm, const char[], PetscDLLibrary *); 1322 PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1323 1324 /* 1325 Useful utility routines 1326 */ 1327 PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm, PetscInt *, PetscInt *); 1328 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm, PetscInt, PetscInt *, PetscInt *); 1329 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm, PetscInt *, PetscInt *); 1330 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm, PetscMPIInt); 1331 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm, PetscMPIInt); 1332 PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1333 PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE *); 1334 PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm, const PetscInt[2], PetscInt[2]); 1335 PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm, const PetscReal[2], PetscReal[2]); 1336 1337 /*MC 1338 PetscNot - negates a logical type value and returns result as a `PetscBool` 1339 1340 Level: beginner 1341 1342 Note: 1343 This is useful in cases like 1344 .vb 1345 int *a; 1346 PetscBool flag = PetscNot(a) 1347 .ve 1348 where !a would not return a `PetscBool` because we cannot provide a cast from int to `PetscBool` in C. 1349 1350 .seealso: `PetscBool`, `PETSC_TRUE`, `PETSC_FALSE` 1351 M*/ 1352 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1353 1354 /*MC 1355 PetscHelpPrintf - Prints help messages. 1356 1357 Synopsis: 1358 #include <petscsys.h> 1359 PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args); 1360 1361 Not Collective, only applies on MPI rank 0; No Fortran Support 1362 1363 Input Parameters: 1364 + comm - the MPI communicator over which the help message is printed 1365 . format - the usual printf() format string 1366 - args - arguments to be printed 1367 1368 Level: developer 1369 1370 Notes: 1371 You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout. 1372 1373 To use, write your own function, for example, 1374 .vb 1375 PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 1376 { 1377 PetscFunctionReturn(PETSC_SUCCESS); 1378 } 1379 .ve 1380 then do the assignment 1381 .vb 1382 PetscHelpPrintf = mypetschelpprintf; 1383 .ve 1384 1385 You can do the assignment before `PetscInitialize()`. 1386 1387 The default routine used is called `PetscHelpPrintfDefault()`. 1388 1389 .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscErrorPrintf()`, `PetscHelpPrintfDefault()` 1390 M*/ 1391 PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1392 1393 /* 1394 Defines PETSc profiling. 1395 */ 1396 #include <petsclog.h> 1397 1398 /* 1399 Simple PETSc parallel IO for ASCII printing 1400 */ 1401 PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[], char[]); 1402 PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm, const char[], const char[], FILE **); 1403 PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm, FILE *); 1404 PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1405 PETSC_EXTERN PetscErrorCode PetscFFlush(FILE *); 1406 PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1407 PETSC_EXTERN PetscErrorCode PetscSNPrintf(char *, size_t, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1408 PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char *, size_t, const char[], size_t *, ...) PETSC_ATTRIBUTE_FORMAT(3, 5); 1409 PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[], size_t, const char *, PetscInt, const PetscReal[]); 1410 1411 PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 1412 PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 1413 PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1414 1415 PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char *, size_t *); 1416 PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char *, char *); 1417 1418 #if defined(PETSC_HAVE_POPEN) 1419 PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm, const char[], const char[], const char[], FILE **); 1420 PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm, FILE *); 1421 PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1422 #endif 1423 1424 PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 1425 PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm, FILE *, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 1426 PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm, FILE *); 1427 PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm, FILE *, size_t, char[]); 1428 PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm, const char[], const char[], FILE **); 1429 PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char *[]); 1430 1431 PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1432 PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer, void **); 1433 PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer, void *); 1434 PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer *); 1435 PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm, PetscContainer *); 1436 PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void *)); 1437 PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void *); 1438 1439 /* 1440 For use in debuggers 1441 */ 1442 PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1443 PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1444 PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt, const PetscInt[], PetscViewer); 1445 PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt, const PetscReal[], PetscViewer); 1446 PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt, const PetscScalar[], PetscViewer); 1447 1448 /* 1449 Basic memory and string operations. These are usually simple wrappers 1450 around the basic Unix system calls, but a few of them have additional 1451 functionality and/or error checking. 1452 */ 1453 #include <petscstring.h> 1454 1455 #include <stddef.h> 1456 #include <stdlib.h> 1457 1458 #if defined(PETSC_CLANG_STATIC_ANALYZER) 1459 #define PetscPrefetchBlock(a, b, c, d) 1460 #else 1461 /*MC 1462 PetscPrefetchBlock - Prefetches a block of memory 1463 1464 Synopsis: 1465 #include <petscsys.h> 1466 void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1467 1468 Not Collective 1469 1470 Input Parameters: 1471 + a - pointer to first element to fetch (any type but usually `PetscInt` or `PetscScalar`) 1472 . n - number of elements to fetch 1473 . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 1474 - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1475 1476 Level: developer 1477 1478 Notes: 1479 The last two arguments (`rw` and `t`) must be compile-time constants. 1480 1481 Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 1482 equivalent locality hints, but the following macros are always defined to their closest analogue. 1483 + `PETSC_PREFETCH_HINT_NTA` - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 1484 . `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. 1485 . `PETSC_PREFETCH_HINT_T1` - Fetch to level 2 and higher (not L1). 1486 - `PETSC_PREFETCH_HINT_T2` - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1487 1488 This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1489 address). 1490 1491 M*/ 1492 #define PetscPrefetchBlock(a, n, rw, t) \ 1493 do { \ 1494 const char *_p = (const char *)(a), *_end = (const char *)((a) + (n)); \ 1495 for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p, (rw), (t)); \ 1496 } while (0) 1497 #endif 1498 /* 1499 Determine if some of the kernel computation routines use 1500 Fortran (rather than C) for the numerical calculations. On some machines 1501 and compilers (like complex numbers) the Fortran version of the routines 1502 is faster than the C/C++ versions. The flag --with-fortran-kernels 1503 should be used with ./configure to turn these on. 1504 */ 1505 #if defined(PETSC_USE_FORTRAN_KERNELS) 1506 1507 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1508 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1509 #endif 1510 1511 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1512 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1513 #endif 1514 1515 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1516 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1517 #endif 1518 1519 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1520 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1521 #endif 1522 1523 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1524 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1525 #endif 1526 1527 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1528 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1529 #endif 1530 1531 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1532 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1533 #endif 1534 1535 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1536 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1537 #endif 1538 1539 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1540 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1541 #endif 1542 1543 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1544 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1545 #endif 1546 1547 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1548 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1549 #endif 1550 1551 #endif 1552 1553 /* 1554 Macros for indicating code that should be compiled with a C interface, 1555 rather than a C++ interface. Any routines that are dynamically loaded 1556 (such as the PCCreate_XXX() routines) must be wrapped so that the name 1557 mangler does not change the functions symbol name. This just hides the 1558 ugly extern "C" {} wrappers. 1559 */ 1560 #if defined(__cplusplus) 1561 #define EXTERN_C_BEGIN extern "C" { 1562 #define EXTERN_C_END } 1563 #else 1564 #define EXTERN_C_BEGIN 1565 #define EXTERN_C_END 1566 #endif 1567 1568 /*MC 1569 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1570 communication 1571 1572 Level: beginner 1573 1574 Note: 1575 This manual page is a place-holder because MPICH does not have a manual page for `MPI_Comm` 1576 1577 .seealso: `PETSC_COMM_WORLD`, `PETSC_COMM_SELF` 1578 M*/ 1579 1580 #if defined(PETSC_HAVE_MPIIO) 1581 PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 1582 PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File, void *, PetscMPIInt, MPI_Datatype, MPI_Status *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(2, 4); 1583 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); 1584 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); 1585 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); 1586 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); 1587 #endif 1588 1589 /*@C 1590 PetscIntCast - casts a `PetscInt64` (which is 64 bits in size) to a `PetscInt` (which may be 32-bits in size), generates an 1591 error if the `PetscInt` is not large enough to hold the number. 1592 1593 Not Collective; No Fortran Support 1594 1595 Input Parameter: 1596 . a - the `PetscInt64` value 1597 1598 Output Parameter: 1599 . b - the resulting `PetscInt` value 1600 1601 Level: advanced 1602 1603 Note: 1604 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 1605 1606 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()` 1607 @*/ 1608 static inline PetscErrorCode PetscIntCast(PetscInt64 a, PetscInt *b) 1609 { 1610 PetscFunctionBegin; 1611 *b = 0; 1612 // if using 64-bit indices already then this comparison is tautologically true 1613 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); 1614 *b = (PetscInt)a; 1615 PetscFunctionReturn(PETSC_SUCCESS); 1616 } 1617 1618 /*@C 1619 PetscCountCast - casts a `PetscCount` to a `PetscInt` (which may be 32-bits in size), generates an 1620 error if the `PetscInt` is not large enough to hold the number. 1621 1622 Not Collective; No Fortran Support 1623 1624 Input Parameter: 1625 . a - the `PetscCount` value 1626 1627 Output Parameter: 1628 . b - the resulting `PetscInt` value 1629 1630 Level: advanced 1631 1632 Note: 1633 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 1634 1635 .seealso: `PetscCount`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscBLASIntCast()`, `PetscIntMultError()`, `PetscIntSumError()`, `PetscIntCast()` 1636 @*/ 1637 static inline PetscErrorCode PetscCountCast(PetscCount a, PetscInt *b) 1638 { 1639 PetscFunctionBegin; 1640 *b = 0; 1641 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); 1642 *b = (PetscInt)a; 1643 PetscFunctionReturn(PETSC_SUCCESS); 1644 } 1645 1646 /*@C 1647 PetscBLASIntCast - casts a `PetscInt` (which may be 64-bits in size) to a `PetscBLASInt` (which may be 32-bits in size), generates an 1648 error if the `PetscBLASInt` is not large enough to hold the number. 1649 1650 Not Collective; No Fortran Support 1651 1652 Input Parameter: 1653 . a - the `PetscInt` value 1654 1655 Output Parameter: 1656 . b - the resulting `PetscBLASInt` value 1657 1658 Level: advanced 1659 1660 Note: 1661 Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs 1662 1663 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`, `PetscCountCast()` 1664 @*/ 1665 static inline PetscErrorCode PetscBLASIntCast(PetscInt a, PetscBLASInt *b) 1666 { 1667 PetscFunctionBegin; 1668 *b = 0; 1669 if (PetscDefined(USE_64BIT_INDICES) && !PetscDefined(HAVE_64BIT_BLAS_INDICES)) { 1670 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); 1671 } 1672 PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer to BLAS/LAPACK routine"); 1673 *b = (PetscBLASInt)a; 1674 PetscFunctionReturn(PETSC_SUCCESS); 1675 } 1676 1677 /*@C 1678 PetscCuBLASIntCast - like `PetscBLASIntCast()`, but for `PetscCuBLASInt`. 1679 1680 Not Collective; No Fortran Support 1681 1682 Input Parameter: 1683 . a - the `PetscInt` value 1684 1685 Output Parameter: 1686 . b - the resulting `PetscCuBLASInt` value 1687 1688 Level: advanced 1689 1690 Note: 1691 Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs 1692 1693 .seealso: `PetscCuBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 1694 @*/ 1695 static inline PetscErrorCode PetscCuBLASIntCast(PetscInt a, PetscCuBLASInt *b) 1696 { 1697 PetscFunctionBegin; 1698 *b = 0; 1699 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); 1700 PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to cuBLAS routine", a); 1701 *b = (PetscCuBLASInt)a; 1702 PetscFunctionReturn(PETSC_SUCCESS); 1703 } 1704 1705 /*@C 1706 PetscHipBLASIntCast - like `PetscBLASIntCast()`, but for `PetscHipBLASInt`. 1707 1708 Not Collective; No Fortran Support 1709 1710 Input Parameter: 1711 . a - the `PetscInt` value 1712 1713 Output Parameter: 1714 . b - the resulting `PetscHipBLASInt` value 1715 1716 Level: advanced 1717 1718 Note: 1719 Errors if the integer is negative since PETSc calls to hipBLAS and friends never need to cast negative integer inputs 1720 1721 .seealso: `PetscHipBLASInt`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscMPIIntCast()`, `PetscIntCast()` 1722 @*/ 1723 static inline PetscErrorCode PetscHipBLASIntCast(PetscInt a, PetscHipBLASInt *b) 1724 { 1725 PetscFunctionBegin; 1726 *b = 0; 1727 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); 1728 PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer %" PetscInt_FMT "to hipBLAS routine", a); 1729 *b = (PetscHipBLASInt)a; 1730 PetscFunctionReturn(PETSC_SUCCESS); 1731 } 1732 1733 /*@C 1734 PetscMPIIntCast - casts a `PetscInt` (which may be 64-bits in size) to a `PetscMPIInt` (which may be 32-bits in size), generates an 1735 error if the `PetscMPIInt` is not large enough to hold the number. 1736 1737 Not Collective; No Fortran Support 1738 1739 Input Parameter: 1740 . a - the `PetscInt` value 1741 1742 Output Parameter: 1743 . b - the resulting `PetscMPIInt` value 1744 1745 Level: advanced 1746 1747 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()` 1748 @*/ 1749 static inline PetscErrorCode PetscMPIIntCast(PetscInt a, PetscMPIInt *b) 1750 { 1751 PetscFunctionBegin; 1752 *b = 0; 1753 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); 1754 *b = (PetscMPIInt)a; 1755 PetscFunctionReturn(PETSC_SUCCESS); 1756 } 1757 1758 #define PetscInt64Mult(a, b) (((PetscInt64)(a)) * ((PetscInt64)(b))) 1759 1760 /*@C 1761 PetscRealIntMultTruncate - Computes the product of a positive `PetscReal` and a positive 1762 `PetscInt` and truncates the value to slightly less than the maximal possible value. 1763 1764 Not Collective; No Fortran Support 1765 1766 Input Parameters: 1767 + a - The `PetscReal` value 1768 - b - The `PetscInt` value 1769 1770 Level: advanced 1771 1772 Notes: 1773 Returns the result as a `PetscInt` value. 1774 1775 Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64`. 1776 1777 Use `PetscIntMultTruncate()` to compute the product of two positive `PetscInt` and truncate 1778 to fit a `PetscInt`. 1779 1780 Use `PetscIntMultError()` to compute the product of two `PetscInt` if you wish to generate an 1781 error if the result will not fit in a `PetscInt`. 1782 1783 Developer Notes: 1784 We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but 1785 requires many more checks. 1786 1787 This is used where we compute approximate sizes for workspace and need to insure the 1788 workspace is index-able. 1789 1790 .seealso: `PetscReal`, `PetscInt`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()` 1791 @*/ 1792 static inline PetscInt PetscRealIntMultTruncate(PetscReal a, PetscInt b) 1793 { 1794 PetscInt64 r = (PetscInt64)(a * (PetscReal)b); 1795 if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 1796 return (PetscInt)r; 1797 } 1798 1799 /*@C 1800 PetscIntMultTruncate - Computes the product of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 1801 1802 Not Collective; No Fortran Support 1803 1804 Input Parameters: 1805 + a - the `PetscInt` value 1806 - b - the second value 1807 1808 Returns: 1809 The result as a `PetscInt` value 1810 1811 Level: advanced 1812 1813 Notes: 1814 Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1815 1816 Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1817 1818 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` 1819 1820 Developer Notes: 1821 We currently assume that `PetscInt` addition can never overflow, this is obviously wrong but requires many more checks. 1822 1823 This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 1824 1825 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()`, `PetscIntSumError()`, 1826 `PetscIntSumTruncate()` 1827 @*/ 1828 static inline PetscInt PetscIntMultTruncate(PetscInt a, PetscInt b) 1829 { 1830 PetscInt64 r = PetscInt64Mult(a, b); 1831 if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 1832 return (PetscInt)r; 1833 } 1834 1835 /*@C 1836 PetscIntSumTruncate - Computes the sum of two positive `PetscInt` and truncates the value to slightly less than the maximal possible value 1837 1838 Not Collective; No Fortran Support 1839 1840 Input Parameters: 1841 + a - the `PetscInt` value 1842 - b - the second value 1843 1844 Returns: 1845 The result as a `PetscInt` value 1846 1847 Level: advanced 1848 1849 Notes: 1850 Use `PetscInt64Mult()` to compute the product of two `PetscInt` as a `PetscInt64` 1851 1852 Use `PetscRealIntMultTruncate()` to compute the product of a `PetscReal` and a `PetscInt` and truncate to fit a `PetscInt` 1853 1854 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` 1855 1856 Developer Note: 1857 This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able. 1858 1859 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1860 @*/ 1861 static inline PetscInt PetscIntSumTruncate(PetscInt a, PetscInt b) 1862 { 1863 PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1864 if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100; 1865 return (PetscInt)r; 1866 } 1867 1868 /*@C 1869 PetscIntMultError - Computes the product of two positive `PetscInt` and generates an error with overflow. 1870 1871 Not Collective; No Fortran Support 1872 1873 Input Parameters: 1874 + a - the `PetscInt` value 1875 - b - the second value 1876 1877 Output Parameter: 1878 . result - the result as a `PetscInt` value, or `NULL` if you do not want the result, you just want to check if it overflows 1879 1880 Level: advanced 1881 1882 Notes: 1883 Use `PetscInt64Mult()` to compute the product of two `PetscInt` and store in a `PetscInt64` 1884 1885 Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1886 1887 Developer Note: 1888 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. 1889 `PetscIntSumError()` can be used to check for this situation. 1890 1891 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntMult64()`, `PetscIntSumError()` 1892 @*/ 1893 static inline PetscErrorCode PetscIntMultError(PetscInt a, PetscInt b, PetscInt *result) 1894 { 1895 PetscInt64 r = PetscInt64Mult(a, b); 1896 1897 PetscFunctionBegin; 1898 if (result) *result = (PetscInt)r; 1899 if (!PetscDefined(USE_64BIT_INDICES)) { 1900 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); 1901 } 1902 PetscFunctionReturn(PETSC_SUCCESS); 1903 } 1904 1905 /*@C 1906 1907 PetscIntSumError - Computes the sum of two positive `PetscInt` and generates an error with overflow. 1908 1909 Not Collective; No Fortran Support 1910 1911 Input Parameters: 1912 + a - the `PetscInt` value 1913 - b - the second value 1914 1915 Output Parameter: 1916 . c - the result as a `PetscInt` value, or `NULL` if you do not want the result, you just want to check if it overflows 1917 1918 Level: advanced 1919 1920 Notes: 1921 Use `PetscInt64Mult()` to compute the product of two 32-bit `PetscInt` and store in a `PetscInt64` 1922 1923 Use `PetscIntMultTruncate()` to compute the product of two `PetscInt` and truncate it to fit in a `PetscInt` 1924 1925 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscInt64Mult()`, `PetscIntMultError()` 1926 @*/ 1927 static inline PetscErrorCode PetscIntSumError(PetscInt a, PetscInt b, PetscInt *result) 1928 { 1929 PetscInt64 r = ((PetscInt64)a) + ((PetscInt64)b); 1930 1931 PetscFunctionBegin; 1932 if (result) *result = (PetscInt)r; 1933 if (!PetscDefined(USE_64BIT_INDICES)) { 1934 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); 1935 } 1936 PetscFunctionReturn(PETSC_SUCCESS); 1937 } 1938 1939 /* 1940 The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 1941 */ 1942 #if defined(hz) 1943 #undef hz 1944 #endif 1945 1946 #if defined(PETSC_HAVE_SYS_TYPES_H) 1947 #include <sys/types.h> 1948 #endif 1949 1950 /*MC 1951 1952 PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++ 1953 and Fortran compilers when `petscsys.h` is included. 1954 1955 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> 1956 1957 The complete version number is given as the triple PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z) 1958 1959 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 1960 where only a change in the major version number (x) indicates a change in the API. 1961 1962 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 1963 1964 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), 1965 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 1966 version number (x.y.z). 1967 1968 `PETSC_RELEASE_DATE` is the date the x.y version was released (i.e. the version before any patch releases) 1969 1970 `PETSC_VERSION_DATE` is the date the x.y.z version was released 1971 1972 `PETSC_VERSION_GIT` is the last git commit to the repository given in the form vx.y.z-wwwww 1973 1974 `PETSC_VERSION_DATE_GIT` is the date of the last git commit to the repository 1975 1976 `PETSC_VERSION_()` is deprecated and will eventually be removed. 1977 1978 Level: intermediate 1979 M*/ 1980 1981 PETSC_EXTERN PetscErrorCode PetscGetArchType(char[], size_t); 1982 PETSC_EXTERN PetscErrorCode PetscGetHostName(char[], size_t); 1983 PETSC_EXTERN PetscErrorCode PetscGetUserName(char[], size_t); 1984 PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[], size_t); 1985 PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 1986 PETSC_EXTERN PetscErrorCode PetscGetDate(char[], size_t); 1987 PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 1988 PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt *, PetscInt *, PetscInt *, PetscInt *); 1989 1990 PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt, const PetscInt[], PetscBool *); 1991 PETSC_EXTERN PetscErrorCode PetscSortedInt64(PetscInt, const PetscInt64[], PetscBool *); 1992 PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt, const PetscMPIInt[], PetscBool *); 1993 PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt, const PetscReal[], PetscBool *); 1994 PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt, PetscInt[]); 1995 PETSC_EXTERN PetscErrorCode PetscSortInt64(PetscInt, PetscInt64[]); 1996 PETSC_EXTERN PetscErrorCode PetscSortCount(PetscInt, PetscCount[]); 1997 PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt, PetscInt[]); 1998 PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt *, PetscInt[]); 1999 PETSC_EXTERN PetscErrorCode PetscSortedCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2000 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt *, PetscInt[]); 2001 PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt, const PetscInt[], PetscBool *); 2002 PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt *); 2003 PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt *); 2004 PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt, const PetscInt[], PetscInt[]); 2005 PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt, const char *[], PetscInt[]); 2006 PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt, PetscInt[], PetscInt[]); 2007 PETSC_EXTERN PetscErrorCode PetscSortIntWithCountArray(PetscCount, PetscInt[], PetscCount[]); 2008 PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt, PetscInt[], PetscInt[], PetscInt[]); 2009 PETSC_EXTERN PetscErrorCode PetscSortIntWithIntCountArrayPair(PetscCount, PetscInt[], PetscInt[], PetscCount[]); 2010 PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt, PetscMPIInt[]); 2011 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt *, PetscMPIInt[]); 2012 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt, PetscMPIInt[], PetscMPIInt[]); 2013 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt, PetscMPIInt[], PetscInt[]); 2014 PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt, PetscInt[], PetscScalar[]); 2015 PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt, PetscInt[], void *, size_t, void *); 2016 PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt, PetscReal[]); 2017 PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2018 PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt, const PetscReal[], PetscInt[]); 2019 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt *, PetscReal[]); 2020 PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal, PetscInt, const PetscReal[], PetscReal, PetscInt *); 2021 PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt, PetscInt, PetscScalar[], PetscInt[]); 2022 PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt, PetscInt, PetscReal[], PetscInt[]); 2023 PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt, const PetscBool[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **, PetscInt **, PetscInt **); 2024 PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt, const PetscInt[], const PetscInt[], PetscInt, const PetscInt[], const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 2025 PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscInt *, PetscInt **); 2026 PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt, const PetscMPIInt[], PetscInt, const PetscMPIInt[], PetscInt *, PetscMPIInt **); 2027 PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *); 2028 2029 PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt, void *, size_t, int (*)(const void *, const void *, void *), void *); 2030 PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt, PetscInt[]); 2031 PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt, PetscMPIInt[]); 2032 PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt, PetscReal[]); 2033 PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt, void *, size_t, void *, size_t, int (*)(const void *, const void *, void *), void *); 2034 PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt, PetscInt[], PetscInt[]); 2035 PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt, PetscMPIInt[], PetscMPIInt[]); 2036 PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt, PetscReal[], PetscInt[]); 2037 2038 PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2039 PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[], size_t); 2040 2041 /*J 2042 PetscRandomType - String with the name of a PETSc randomizer 2043 2044 Level: beginner 2045 2046 Note: 2047 To use `PETSCSPRNG` or `PETSCRANDOM123` you must have ./configure PETSc 2048 with the option `--download-sprng` or `--download-random123`. We recommend the default provided with PETSc. 2049 2050 .seealso: `PetscRandomSetType()`, `PetscRandom`, `PetscRandomCreate()` 2051 J*/ 2052 typedef const char *PetscRandomType; 2053 #define PETSCRAND "rand" 2054 #define PETSCRAND48 "rand48" 2055 #define PETSCSPRNG "sprng" 2056 #define PETSCRANDER48 "rander48" 2057 #define PETSCRANDOM123 "random123" 2058 #define PETSCCURAND "curand" 2059 2060 /* Logging support */ 2061 PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2062 2063 PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2064 PETSC_EXTERN PetscErrorCode PetscRandomFinalizePackage(void); 2065 2066 /* Dynamic creation and loading functions */ 2067 PETSC_EXTERN PetscFunctionList PetscRandomList; 2068 2069 PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[], PetscErrorCode (*)(PetscRandom)); 2070 PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2071 PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 2072 PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType *); 2073 PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom, PetscObject, const char[]); 2074 PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom, PetscViewer); 2075 2076 PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm, PetscRandom *); 2077 PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom, PetscScalar *); 2078 PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom, PetscReal *); 2079 PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom, PetscInt, PetscScalar *); 2080 PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom, PetscInt, PetscReal *); 2081 PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom, PetscScalar *, PetscScalar *); 2082 PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom, PetscScalar, PetscScalar); 2083 PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom, unsigned long); 2084 PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom, unsigned long *); 2085 PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2086 PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom *); 2087 2088 PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[], char[], size_t); 2089 PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[], char[], size_t); 2090 PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[], size_t); 2091 PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[], char[]); 2092 PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[], size_t); 2093 PETSC_EXTERN PetscErrorCode PetscTestFile(const char[], char, PetscBool *); 2094 PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[], char, PetscBool *); 2095 PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 2096 PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]); 2097 PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2098 2099 static inline PetscBool PetscBinaryBigEndian(void) 2100 { 2101 long _petsc_v = 1; 2102 return ((char *)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE; 2103 } 2104 2105 PETSC_EXTERN PetscErrorCode PetscBinaryRead(int, void *, PetscInt, PetscInt *, PetscDataType); 2106 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm, int, void *, PetscInt, PetscInt *, PetscDataType); 2107 PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int, const void *, PetscInt, PetscDataType); 2108 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm, int, const void *, PetscInt, PetscDataType); 2109 PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[], PetscFileMode, int *); 2110 PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2111 PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm, PetscBool *); 2112 PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm, PetscBool *); 2113 PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm, char[], size_t); 2114 PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm, const char[], char[], size_t, PetscBool *); 2115 PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm, const char[], char[], size_t, PetscBool *); 2116 #if defined(PETSC_USE_SOCKET_VIEWER) 2117 PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[], int, int *); 2118 #endif 2119 2120 PETSC_EXTERN PetscErrorCode PetscBinarySeek(int, off_t, PetscBinarySeekType, off_t *); 2121 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm, int, off_t, PetscBinarySeekType, off_t *); 2122 PETSC_EXTERN PetscErrorCode PetscByteSwap(void *, PetscDataType, PetscInt); 2123 2124 PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2125 PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[], PetscBool); 2126 PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2127 PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char *); 2128 PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2129 PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 2130 PETSC_EXTERN PetscErrorCode PetscWaitOnError(void); 2131 2132 PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt *); 2133 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **); 2134 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscMPIInt **, PetscMPIInt **, PetscMPIInt **); 2135 PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscInt ***, MPI_Request **); 2136 PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscMPIInt[], const PetscMPIInt[], PetscScalar ***, MPI_Request **); 2137 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); 2138 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); 2139 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); 2140 2141 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm, PetscBuildTwoSidedType); 2142 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm, PetscBuildTwoSidedType *); 2143 2144 PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm, PetscBool *, PetscBool *); 2145 2146 PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2147 2148 struct _n_PetscSubcomm { 2149 MPI_Comm parent; /* parent communicator */ 2150 MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2151 MPI_Comm child; /* the sub-communicator */ 2152 PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 2153 PetscMPIInt color; /* color of processors belong to this communicator */ 2154 PetscMPIInt *subsize; /* size of subcommunicator[color] */ 2155 PetscSubcommType type; 2156 char *subcommprefix; 2157 }; 2158 2159 static inline MPI_Comm PetscSubcommParent(PetscSubcomm scomm) 2160 { 2161 return scomm->parent; 2162 } 2163 static inline MPI_Comm PetscSubcommChild(PetscSubcomm scomm) 2164 { 2165 return scomm->child; 2166 } 2167 static inline MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) 2168 { 2169 return scomm->dupparent; 2170 } 2171 PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm, PetscSubcomm *); 2172 PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm *); 2173 PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm, PetscInt); 2174 PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm, PetscSubcommType); 2175 PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm, PetscMPIInt, PetscMPIInt); 2176 PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm, PetscViewer); 2177 PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2178 PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm, const char[]); 2179 PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm, MPI_Comm *); 2180 PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm, MPI_Comm *); 2181 PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm, MPI_Comm *); 2182 2183 PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt, PetscHeap *); 2184 PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap, PetscInt, PetscInt); 2185 PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap, PetscInt *, PetscInt *); 2186 PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap, PetscInt *, PetscInt *); 2187 PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap, PetscInt, PetscInt); 2188 PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap); 2189 PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap *); 2190 PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap, PetscViewer); 2191 2192 PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer); 2193 PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm, PetscShmComm *); 2194 PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 2195 PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm, PetscMPIInt, PetscMPIInt *); 2196 PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm, MPI_Comm *); 2197 2198 /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */ 2199 PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm, PetscInt, PetscOmpCtrl *); 2200 PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl, MPI_Comm *, MPI_Comm *, PetscBool *); 2201 PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl *); 2202 PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl); 2203 PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl); 2204 PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl); 2205 2206 PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t, size_t, PetscSegBuffer *); 2207 PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer *); 2208 PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer, size_t, void *); 2209 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer, void *); 2210 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer, void *); 2211 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer, void *); 2212 PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer, size_t *); 2213 PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer, size_t); 2214 2215 /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2216 * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2217 * possible. */ 2218 static inline PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg, size_t count, PetscInt *PETSC_RESTRICT *slot) 2219 { 2220 return PetscSegBufferGet(seg, count, (void **)slot); 2221 } 2222 2223 extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton; 2224 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *); 2225 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *); 2226 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted, const char *, const char *, PetscBool *); 2227 2228 #include <stdarg.h> 2229 PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char *, size_t, const char[], size_t *, va_list); 2230 PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list); 2231 2232 PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2233 2234 /*@C 2235 PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 2236 2237 Not Collective; No Fortran Support 2238 2239 Input Parameters: 2240 + cite - the bibtex item, formatted to displayed on multiple lines nicely 2241 - set - a boolean variable initially set to `PETSC_FALSE`; this is used to insure only a single registration of the citation 2242 2243 Options Database Key: 2244 . -citations [filename] - print out the bibtex entries for the given computation 2245 2246 Level: intermediate 2247 @*/ 2248 static inline PetscErrorCode PetscCitationsRegister(const char cit[], PetscBool *set) 2249 { 2250 size_t len; 2251 char *vstring; 2252 2253 PetscFunctionBegin; 2254 if (set && *set) PetscFunctionReturn(PETSC_SUCCESS); 2255 PetscCall(PetscStrlen(cit, &len)); 2256 PetscCall(PetscSegBufferGet(PetscCitationsList, len, &vstring)); 2257 PetscCall(PetscArraycpy(vstring, cit, len)); 2258 if (set) *set = PETSC_TRUE; 2259 PetscFunctionReturn(PETSC_SUCCESS); 2260 } 2261 2262 PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm, char[], char[], size_t); 2263 PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm, const char[], char[], size_t); 2264 PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm, const char[], const char[]); 2265 2266 PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm, char[], char[], size_t); 2267 PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm, const char[], char[], char[], size_t); 2268 PETSC_EXTERN PetscErrorCode PetscBoxUpload(MPI_Comm, const char[], const char[]); 2269 2270 PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm, const char[], char[], size_t); 2271 PETSC_EXTERN PetscErrorCode PetscGlobusAuthorize(MPI_Comm, char[], size_t); 2272 PETSC_EXTERN PetscErrorCode PetscGlobusUpload(MPI_Comm, const char[], const char[]); 2273 2274 PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[], const char[], char[], size_t, PetscBool *); 2275 PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[], const char[], const char[], size_t); 2276 2277 #if defined(PETSC_USE_DEBUG) 2278 static inline unsigned int PetscStrHash(const char *str) 2279 { 2280 unsigned int c, hash = 5381; 2281 2282 while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 2283 return hash; 2284 } 2285 2286 /*MC 2287 MPIU_Allreduce - a PETSc replacement for `MPI_Allreduce()` that tries to determine if the call from all the MPI ranks occur from the 2288 same place in the PETSc code. This helps to detect bugs where different MPI ranks follow different code paths 2289 resulting in inconsistent and incorrect calls to `MPI_Allreduce()`. 2290 2291 Synopsis: 2292 #include <petscsys.h> 2293 PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); 2294 2295 Collective 2296 2297 Input Parameters: 2298 + a - pointer to the input data to be reduced 2299 . c - the number of MPI data items in a and b 2300 . d - the MPI datatype, for example `MPI_INT` 2301 . e - the MPI operation, for example `MPI_SUM` 2302 - fcomm - the MPI communicator on which the operation occurs 2303 2304 Output Parameter: 2305 . b - the reduced values 2306 2307 Level: developer 2308 2309 Notes: 2310 In optimized mode this directly calls `MPI_Allreduce()` 2311 2312 This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void. 2313 2314 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 2315 2316 .seealso: `MPI_Allreduce()` 2317 M*/ 2318 #define MPIU_Allreduce(a, b, c, d, e, fcomm) \ 2319 PetscMacroReturnStandard( \ 2320 PetscMPIInt a_b1[6], a_b2[6]; \ 2321 int _mpiu_allreduce_c_int = (int)(c); \ 2322 a_b1[0] = -(PetscMPIInt)__LINE__; \ 2323 a_b1[1] = -a_b1[0]; \ 2324 a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); \ 2325 a_b1[3] = -a_b1[2]; \ 2326 a_b1[4] = -(PetscMPIInt)(c); \ 2327 a_b1[5] = -a_b1[4]; \ 2328 \ 2329 PetscCallMPI(MPI_Allreduce(a_b1, a_b2, 6, MPI_INT, MPI_MAX, fcomm)); \ 2330 PetscCheck(-a_b2[0] == a_b2[1], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (code lines) on different processors"); \ 2331 PetscCheck(-a_b2[2] == a_b2[3], PETSC_COMM_SELF, PETSC_ERR_PLIB, "MPI_Allreduce() called in different locations (functions) on different processors"); \ 2332 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); \ 2333 PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)));) 2334 #else 2335 #define MPIU_Allreduce(a, b, c, d, e, fcomm) PetscMacroReturnStandard(PetscCallMPI(MPI_Allreduce((a), (b), (c), (d), (e), (fcomm)))) 2336 #endif 2337 2338 #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) 2339 PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint, PetscMPIInt, MPI_Info, MPI_Comm, void *, MPI_Win *); 2340 PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win, PetscMPIInt, MPI_Aint *, PetscMPIInt *, void *); 2341 #endif 2342 2343 /* this is a vile hack */ 2344 #if defined(PETSC_HAVE_NECMPI) 2345 #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) 2346 #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL, 0); 2347 #endif 2348 #endif 2349 2350 /* 2351 List of external packages and queries on it 2352 */ 2353 PETSC_EXTERN PetscErrorCode PetscHasExternalPackage(const char[], PetscBool *); 2354 2355 /* this cannot go here because it may be in a different shared library */ 2356 PETSC_EXTERN PetscErrorCode PCMPIServerBegin(void); 2357 PETSC_EXTERN PetscErrorCode PCMPIServerEnd(void); 2358 PETSC_EXTERN PetscErrorCode PCMPICommsDestroy(void); 2359 PETSC_EXTERN PetscBool PCMPIServerActive; 2360 2361 #define PETSC_HAVE_FORTRAN PETSC_DEPRECATED_MACRO(3, 20, 0, "PETSC_USE_FORTRAN_BINDINGS", ) PETSC_USE_FORTRAN_BINDINGS 2362 2363 PETSC_EXTERN PetscErrorCode PetscBLASSetNumThreads(PetscInt); 2364 PETSC_EXTERN PetscErrorCode PetscBLASGetNumThreads(PetscInt *); 2365 2366 /*MC 2367 PetscSafePointerPlusOffset - Checks that a pointer is not `NULL` before applying an offset 2368 2369 Level: beginner 2370 2371 Note: 2372 This is needed to avoid errors with undefined-behavior sanitizers such as 2373 UBSan, assuming PETSc has been configured with `-fsanitize=undefined` as part of the compiler flags 2374 M*/ 2375 #define PetscSafePointerPlusOffset(ptr, offset) ((ptr) ? (ptr) + (offset) : NULL) 2376