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