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