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