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