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 PETSC_EXTERN PetscErrorCode PetscObjectAddOptionsHandler(PetscObject,PetscErrorCode (*)(PetscOptions*,PetscObject,void*),PetscErrorCode (*)(PetscObject,void*),void*); 1651 PETSC_EXTERN PetscErrorCode PetscObjectProcessOptionsHandlers(PetscOptions*,PetscObject); 1652 PETSC_EXTERN PetscErrorCode PetscObjectDestroyOptionsHandlers(PetscObject); 1653 PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm,PetscInt,PetscObject*,PetscInt*,PetscInt*); 1654 1655 PETSC_EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]); 1656 PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer,const char[]); 1657 PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject,PetscViewer); 1658 PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer); 1659 #define PetscObjectQueryFunction(obj,name,fptr) PetscObjectQueryFunction_Private((obj),(name),(PetscVoidFunction*)(fptr)) 1660 PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject,const char[],void (**)(void)); 1661 PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1662 PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1663 PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1664 PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]); 1665 PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]); 1666 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 1667 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 1668 PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject,PetscObject,const char[]); 1669 PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject); 1670 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject,const char[],PetscBool *); 1671 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject,PetscBool*,const char[],...); 1672 PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void)); 1673 PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void); 1674 1675 #if defined(PETSC_HAVE_SAWS) 1676 PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void); 1677 PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject); 1678 PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject,PetscBool); 1679 PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject); 1680 PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject); 1681 PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject); 1682 PETSC_EXTERN void PetscStackSAWsGrantAccess(void); 1683 PETSC_EXTERN void PetscStackSAWsTakeAccess(void); 1684 PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void); 1685 PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void); 1686 1687 #else 1688 #define PetscSAWsBlock() 0 1689 #define PetscObjectSAWsViewOff(obj) 0 1690 #define PetscObjectSAWsSetBlock(obj,flg) 0 1691 #define PetscObjectSAWsBlock(obj) 0 1692 #define PetscObjectSAWsGrantAccess(obj) 0 1693 #define PetscObjectSAWsTakeAccess(obj) 0 1694 #define PetscStackViewSAWs() 0 1695 #define PetscStackSAWsViewOff() 0 1696 #define PetscStackSAWsTakeAccess() 1697 #define PetscStackSAWsGrantAccess() 1698 1699 #endif 1700 1701 typedef void* PetscDLHandle; 1702 typedef enum {PETSC_DL_DECIDE=0,PETSC_DL_NOW=1,PETSC_DL_LOCAL=2} PetscDLMode; 1703 PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[],PetscDLMode,PetscDLHandle *); 1704 PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *); 1705 PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle,const char[],void **); 1706 1707 1708 #if defined(PETSC_USE_DEBUG) 1709 PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void*,PetscStack**); 1710 #endif 1711 PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE*,PetscBool); 1712 1713 /*S 1714 PetscObjectList - Linked list of PETSc objects, each accessable by string name 1715 1716 Level: developer 1717 1718 Notes: Used by PetscObjectCompose() and PetscObjectQuery() 1719 1720 .seealso: PetscObjectListAdd(), PetscObjectListDestroy(), PetscObjectListFind(), PetscObjectCompose(), PetscObjectQuery(), PetscFunctionList 1721 S*/ 1722 typedef struct _n_PetscObjectList *PetscObjectList; 1723 1724 PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList*); 1725 PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList,const char[],PetscObject*); 1726 PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList,PetscObject,char**,PetscBool*); 1727 PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *,const char[],PetscObject); 1728 PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *,const char[]); 1729 PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList,PetscObjectList *); 1730 1731 /* 1732 Dynamic library lists. Lists of names of routines in objects or in dynamic 1733 link libraries that will be loaded as needed. 1734 */ 1735 1736 #define PetscFunctionListAdd(list,name,fptr) PetscFunctionListAdd_Private((list),(name),(PetscVoidFunction)(fptr)) 1737 PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList*,const char[],void (*)(void)); 1738 PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList*); 1739 #define PetscFunctionListFind(list,name,fptr) PetscFunctionListFind_Private((list),(name),(PetscVoidFunction*)(fptr)) 1740 PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList,const char[],void (**)(void)); 1741 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFunctionList,const char[]); 1742 PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList,PetscFunctionList *); 1743 PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList,PetscViewer); 1744 PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList,const char ***,int*); 1745 1746 /*S 1747 PetscDLLibrary - Linked list of dynamics libraries to search for functions 1748 1749 Level: advanced 1750 1751 .seealso: PetscDLLibraryOpen() 1752 S*/ 1753 typedef struct _n_PetscDLLibrary *PetscDLLibrary; 1754 PETSC_EXTERN PetscDLLibrary PetscDLLibrariesLoaded; 1755 PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1756 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]); 1757 PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **); 1758 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary); 1759 PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscBool *); 1760 PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *); 1761 PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary); 1762 1763 /* 1764 Useful utility routines 1765 */ 1766 PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1767 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1768 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1769 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1770 PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject); 1771 PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE*); 1772 1773 /* 1774 PetscNot - negates a logical type value and returns result as a PetscBool 1775 1776 Notes: This is useful in cases like 1777 $ int *a; 1778 $ PetscBool flag = PetscNot(a) 1779 where !a does not return a PetscBool because we cannot provide a cast from int to PetscBool in C. 1780 */ 1781 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1782 1783 /*MC 1784 PetscHelpPrintf - Prints help messages. 1785 1786 Synopsis: 1787 #include <petscsys.h> 1788 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1789 1790 Not Collective 1791 1792 Input Parameters: 1793 . format - the usual printf() format string 1794 1795 Level: developer 1796 1797 Fortran Note: 1798 This routine is not supported in Fortran. 1799 1800 Concepts: help messages^printing 1801 Concepts: printing^help messages 1802 1803 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1804 M*/ 1805 PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1806 1807 /* 1808 Defines PETSc profiling. 1809 */ 1810 #include <petsclog.h> 1811 1812 1813 1814 /* 1815 Simple PETSc parallel IO for ASCII printing 1816 */ 1817 PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[],char[]); 1818 PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1819 PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*); 1820 PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...); 1821 PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...); 1822 PETSC_EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...); 1823 PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char*,size_t,const char [],size_t*,...); 1824 1825 /* These are used internally by PETSc ASCII IO routines*/ 1826 #include <stdarg.h> 1827 PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],size_t*,va_list); 1828 PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list); 1829 PETSC_EXTERN PetscErrorCode PetscVFPrintfDefault(FILE*,const char[],va_list); 1830 1831 #if defined(PETSC_HAVE_MATLAB_ENGINE) 1832 PETSC_EXTERN PetscErrorCode PetscVFPrintf_Matlab(FILE*,const char[],va_list); 1833 #endif 1834 1835 #if defined(PETSC_HAVE_CLOSURES) 1836 PETSC_EXTERN PetscErrorCode PetscVFPrintfSetClosure(int (^)(const char*)); 1837 #endif 1838 1839 PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...); 1840 PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...); 1841 PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...); 1842 1843 #if defined(PETSC_HAVE_POPEN) 1844 PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1845 PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*,int*); 1846 PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]); 1847 #endif 1848 1849 PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...); 1850 PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...); 1851 PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm,FILE*); 1852 PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1853 PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1854 PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1855 PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char*[]); 1856 1857 PETSC_EXTERN PetscErrorCode PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*); 1858 1859 /*S 1860 PetscContainer - Simple PETSc object that contains a pointer to any required data 1861 1862 Level: advanced 1863 1864 .seealso: PetscObject, PetscContainerCreate() 1865 S*/ 1866 PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID; 1867 typedef struct _p_PetscContainer* PetscContainer; 1868 PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void **); 1869 PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void *); 1870 PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer*); 1871 PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer *); 1872 PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*)); 1873 1874 /* 1875 For use in debuggers 1876 */ 1877 PETSC_EXTERN PetscMPIInt PetscGlobalRank; 1878 PETSC_EXTERN PetscMPIInt PetscGlobalSize; 1879 PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt,const PetscInt[],PetscViewer); 1880 PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt,const PetscReal[],PetscViewer); 1881 PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt,const PetscScalar[],PetscViewer); 1882 1883 #include <stddef.h> 1884 #include <string.h> /* for memcpy, memset */ 1885 #if defined(PETSC_HAVE_STDLIB_H) 1886 #include <stdlib.h> 1887 #endif 1888 1889 #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__) 1890 #include <xmmintrin.h> 1891 #endif 1892 1893 #undef __FUNCT__ 1894 #define __FUNCT__ "PetscMemcpy" 1895 /*@C 1896 PetscMemcpy - Copies n bytes, beginning at location b, to the space 1897 beginning at location a. The two memory regions CANNOT overlap, use 1898 PetscMemmove() in that case. 1899 1900 Not Collective 1901 1902 Input Parameters: 1903 + b - pointer to initial memory space 1904 - n - length (in bytes) of space to copy 1905 1906 Output Parameter: 1907 . a - pointer to copy space 1908 1909 Level: intermediate 1910 1911 Compile Option: 1912 PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used 1913 for memory copies on double precision values. 1914 PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used 1915 for memory copies on double precision values. 1916 PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used 1917 for memory copies on double precision values. 1918 1919 Note: 1920 This routine is analogous to memcpy(). 1921 1922 Developer Note: this is inlined for fastest performance 1923 1924 Concepts: memory^copying 1925 Concepts: copying^memory 1926 1927 .seealso: PetscMemmove() 1928 1929 @*/ 1930 PETSC_STATIC_INLINE PetscErrorCode PetscMemcpy(void *a,const void *b,size_t n) 1931 { 1932 #if defined(PETSC_USE_DEBUG) 1933 size_t al = (size_t) a,bl = (size_t) b; 1934 size_t nl = (size_t) n; 1935 PetscFunctionBegin; 1936 if (n > 0 && !b) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer"); 1937 if (n > 0 && !a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer"); 1938 #else 1939 PetscFunctionBegin; 1940 #endif 1941 if (a != b && n > 0) { 1942 #if defined(PETSC_USE_DEBUG) 1943 if ((al > bl && (al - bl) < nl) || (bl - al) < nl) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\ 1944 or make sure your copy regions and lengths are correct. \n\ 1945 Length (bytes) %ld first address %ld second address %ld",nl,al,bl); 1946 #endif 1947 #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1948 if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1949 size_t len = n/sizeof(PetscScalar); 1950 #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1951 PetscBLASInt one = 1,blen; 1952 PetscErrorCode ierr; 1953 ierr = PetscBLASIntCast(len,&blen);CHKERRQ(ierr); 1954 PetscStackCallBLAS("BLAScopy",BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one)); 1955 #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1956 fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a); 1957 #else 1958 size_t i; 1959 PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a; 1960 for (i=0; i<len; i++) y[i] = x[i]; 1961 #endif 1962 } else { 1963 memcpy((char*)(a),(char*)(b),n); 1964 } 1965 #else 1966 memcpy((char*)(a),(char*)(b),n); 1967 #endif 1968 } 1969 PetscFunctionReturn(0); 1970 } 1971 1972 /*@C 1973 PetscMemzero - Zeros the specified memory. 1974 1975 Not Collective 1976 1977 Input Parameters: 1978 + a - pointer to beginning memory location 1979 - n - length (in bytes) of memory to initialize 1980 1981 Level: intermediate 1982 1983 Compile Option: 1984 PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens 1985 to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1986 1987 Developer Note: this is inlined for fastest performance 1988 1989 Concepts: memory^zeroing 1990 Concepts: zeroing^memory 1991 1992 .seealso: PetscMemcpy() 1993 @*/ 1994 PETSC_STATIC_INLINE PetscErrorCode PetscMemzero(void *a,size_t n) 1995 { 1996 if (n > 0) { 1997 #if defined(PETSC_USE_DEBUG) 1998 if (!a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer"); 1999 #endif 2000 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 2001 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 2002 size_t i,len = n/sizeof(PetscScalar); 2003 PetscScalar *x = (PetscScalar*)a; 2004 for (i=0; i<len; i++) x[i] = 0.0; 2005 } else { 2006 #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 2007 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 2008 PetscInt len = n/sizeof(PetscScalar); 2009 fortranzero_(&len,(PetscScalar*)a); 2010 } else { 2011 #endif 2012 #if defined(PETSC_PREFER_BZERO) 2013 bzero((char *)a,n); 2014 #else 2015 memset((char*)a,0,n); 2016 #endif 2017 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 2018 } 2019 #endif 2020 } 2021 return 0; 2022 } 2023 2024 /*MC 2025 PetscPrefetchBlock - Prefetches a block of memory 2026 2027 Synopsis: 2028 #include <petscsys.h> 2029 void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 2030 2031 Not Collective 2032 2033 Input Parameters: 2034 + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 2035 . n - number of elements to fetch 2036 . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 2037 - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 2038 2039 Level: developer 2040 2041 Notes: 2042 The last two arguments (rw and t) must be compile-time constants. 2043 2044 Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 2045 equivalent locality hints, but the following macros are always defined to their closest analogue. 2046 + PETSC_PREFETCH_HINT_NTA - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 2047 . 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. 2048 . PETSC_PREFETCH_HINT_T1 - Fetch to level 2 and higher (not L1). 2049 - PETSC_PREFETCH_HINT_T2 - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 2050 2051 This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 2052 address). 2053 2054 Concepts: memory 2055 M*/ 2056 #define PetscPrefetchBlock(a,n,rw,t) do { \ 2057 const char *_p = (const char*)(a),*_end = (const char*)((a)+(n)); \ 2058 for ( ; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \ 2059 } while (0) 2060 2061 /* 2062 Determine if some of the kernel computation routines use 2063 Fortran (rather than C) for the numerical calculations. On some machines 2064 and compilers (like complex numbers) the Fortran version of the routines 2065 is faster than the C/C++ versions. The flag --with-fortran-kernels 2066 should be used with ./configure to turn these on. 2067 */ 2068 #if defined(PETSC_USE_FORTRAN_KERNELS) 2069 2070 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 2071 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 2072 #endif 2073 2074 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 2075 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 2076 #endif 2077 2078 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 2079 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 2080 #endif 2081 2082 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 2083 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 2084 #endif 2085 2086 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 2087 #define PETSC_USE_FORTRAN_KERNEL_NORM 2088 #endif 2089 2090 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 2091 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 2092 #endif 2093 2094 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 2095 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 2096 #endif 2097 2098 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 2099 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 2100 #endif 2101 2102 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 2103 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 2104 #endif 2105 2106 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 2107 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 2108 #endif 2109 2110 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 2111 #define PETSC_USE_FORTRAN_KERNEL_MDOT 2112 #endif 2113 2114 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 2115 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 2116 #endif 2117 2118 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 2119 #define PETSC_USE_FORTRAN_KERNEL_AYPX 2120 #endif 2121 2122 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 2123 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 2124 #endif 2125 2126 #endif 2127 2128 /* 2129 Macros for indicating code that should be compiled with a C interface, 2130 rather than a C++ interface. Any routines that are dynamically loaded 2131 (such as the PCCreate_XXX() routines) must be wrapped so that the name 2132 mangler does not change the functions symbol name. This just hides the 2133 ugly extern "C" {} wrappers. 2134 */ 2135 #if defined(__cplusplus) 2136 #define EXTERN_C_BEGIN extern "C" { 2137 #define EXTERN_C_END } 2138 #else 2139 #define EXTERN_C_BEGIN 2140 #define EXTERN_C_END 2141 #endif 2142 2143 /* --------------------------------------------------------------------*/ 2144 2145 /*MC 2146 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 2147 communication 2148 2149 Level: beginner 2150 2151 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 2152 2153 .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF 2154 M*/ 2155 2156 /*MC 2157 PetscScalar - PETSc type that represents either a double precision real number, a double precision 2158 complex number, a single precision real number, a long double or an int - if the code is configured 2159 with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle 2160 2161 2162 Level: beginner 2163 2164 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt 2165 M*/ 2166 2167 /*MC 2168 PetscComplex - PETSc type that represents a complex number with precision matching that of PetscReal. 2169 2170 Synopsis: 2171 #include <petscsys.h> 2172 PetscComplex number = 1. + 2.*PETSC_i; 2173 2174 Level: beginner 2175 2176 Note: 2177 Complex numbers are automatically available if PETSc was able to find a working complex implementation 2178 2179 .seealso: PetscReal, PetscComplex, MPIU_COMPLEX, PetscInt, PETSC_i 2180 M*/ 2181 2182 /*MC 2183 PetscReal - PETSc type that represents a real number version of PetscScalar 2184 2185 Level: beginner 2186 2187 .seealso: PetscScalar, PassiveReal, PassiveScalar 2188 M*/ 2189 2190 /*MC 2191 PassiveScalar - PETSc type that represents a PetscScalar 2192 Level: beginner 2193 2194 This is the same as a PetscScalar except in code that is automatically differentiated it is 2195 treated as a constant (not an indendent or dependent variable) 2196 2197 .seealso: PetscReal, PassiveReal, PetscScalar 2198 M*/ 2199 2200 /*MC 2201 PassiveReal - PETSc type that represents a PetscReal 2202 2203 Level: beginner 2204 2205 This is the same as a PetscReal except in code that is automatically differentiated it is 2206 treated as a constant (not an indendent or dependent variable) 2207 2208 .seealso: PetscScalar, PetscReal, PassiveScalar 2209 M*/ 2210 2211 /*MC 2212 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 2213 2214 Level: beginner 2215 2216 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 2217 pass this value 2218 2219 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT 2220 M*/ 2221 2222 #if defined(PETSC_HAVE_MPIIO) 2223 #if !defined(PETSC_WORDS_BIGENDIAN) 2224 PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 2225 PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 2226 #else 2227 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e) 2228 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e) 2229 #endif 2230 #endif 2231 2232 /* the following petsc_static_inline require petscerror.h */ 2233 2234 /* Limit MPI to 32-bits */ 2235 #define PETSC_MPI_INT_MAX 2147483647 2236 #define PETSC_MPI_INT_MIN -2147483647 2237 /* Limit BLAS to 32-bits */ 2238 #define PETSC_BLAS_INT_MAX 2147483647 2239 #define PETSC_BLAS_INT_MIN -2147483647 2240 2241 #undef __FUNCT__ 2242 #define __FUNCT__ "PetscBLASIntCast" 2243 /*@C 2244 PetscBLASIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscBLASInt (which may be 32 bits in size), generates an 2245 error if the PetscBLASInt is not large enough to hold the number. 2246 2247 Not Collective 2248 2249 Input Parameter: 2250 . a - the PetscInt value 2251 2252 Output Parameter: 2253 . b - the resulting PetscBLASInt value 2254 2255 Level: advanced 2256 2257 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscMPIIntCast() 2258 @*/ 2259 PETSC_STATIC_INLINE PetscErrorCode PetscBLASIntCast(PetscInt a,PetscBLASInt *b) 2260 { 2261 PetscFunctionBegin; 2262 *b = (PetscBLASInt)(a); 2263 #if defined(PETSC_USE_64BIT_INDICES) && !defined(PETSC_HAVE_64BIT_BLAS_INDICES) 2264 if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK"); 2265 #endif 2266 PetscFunctionReturn(0); 2267 } 2268 2269 #undef __FUNCT__ 2270 #define __FUNCT__ "PetscMPIIntCast" 2271 /*@C 2272 PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an 2273 error if the PetscMPIInt is not large enough to hold the number. 2274 2275 Not Collective 2276 2277 Input Parameter: 2278 . a - the PetscInt value 2279 2280 Output Parameter: 2281 . b - the resulting PetscMPIInt value 2282 2283 Level: advanced 2284 2285 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast() 2286 @*/ 2287 PETSC_STATIC_INLINE PetscErrorCode PetscMPIIntCast(PetscInt a,PetscMPIInt *b) 2288 { 2289 PetscFunctionBegin; 2290 *b = (PetscMPIInt)(a); 2291 #if defined(PETSC_USE_64BIT_INDICES) 2292 if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for MPI"); 2293 #endif 2294 PetscFunctionReturn(0); 2295 } 2296 2297 2298 /* 2299 The IBM include files define hz, here we hide it so that it may be used as a regular user variable. 2300 */ 2301 #if defined(hz) 2302 #undef hz 2303 #endif 2304 2305 /* For arrays that contain filenames or paths */ 2306 2307 2308 #if defined(PETSC_HAVE_LIMITS_H) 2309 #include <limits.h> 2310 #endif 2311 #if defined(PETSC_HAVE_SYS_PARAM_H) 2312 #include <sys/param.h> 2313 #endif 2314 #if defined(PETSC_HAVE_SYS_TYPES_H) 2315 #include <sys/types.h> 2316 #endif 2317 #if defined(MAXPATHLEN) 2318 # define PETSC_MAX_PATH_LEN MAXPATHLEN 2319 #elif defined(MAX_PATH) 2320 # define PETSC_MAX_PATH_LEN MAX_PATH 2321 #elif defined(_MAX_PATH) 2322 # define PETSC_MAX_PATH_LEN _MAX_PATH 2323 #else 2324 # define PETSC_MAX_PATH_LEN 4096 2325 #endif 2326 2327 /*MC 2328 2329 UsingFortran - Fortran can be used with PETSc in four distinct approaches 2330 2331 $ 1) classic Fortran 77 style 2332 $#include "petsc/finclude/petscXXX.h" to work with material from the XXX component of PETSc 2333 $ XXX variablename 2334 $ You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines 2335 $ which end in F90; such as VecGetArrayF90() 2336 $ 2337 $ 2) classic Fortran 90 style 2338 $#include "petsc/finclude/petscXXX.h" 2339 $#include "petsc/finclude/petscXXX.h90" to work with material from the XXX component of PETSc 2340 $ XXX variablename 2341 $ 2342 $ 3) Using Fortran modules 2343 $#include "petsc/finclude/petscXXXdef.h" 2344 $ use petscXXXX 2345 $ XXX variablename 2346 $ 2347 $ 4) Use Fortran modules and Fortran data types for PETSc types 2348 $#include "petsc/finclude/petscXXXdef.h" 2349 $ use petscXXXX 2350 $ type(XXX) variablename 2351 $ To use this approach you must ./configure PETSc with the additional 2352 $ option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules 2353 2354 Finally if you absolutely do not want to use any #include you can use either 2355 2356 $ 3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc 2357 $ and you must declare the variables as integer, for example 2358 $ integer variablename 2359 $ 2360 $ 4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type 2361 $ names like PetscErrorCode, PetscInt etc. again for those you must use integer 2362 2363 We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking 2364 for only a few PETSc functions. 2365 2366 Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value 2367 is expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues() 2368 you cannot have something like 2369 $ PetscInt row,col 2370 $ PetscScalar val 2371 $ ... 2372 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2373 You must instead have 2374 $ PetscInt row(1),col(1) 2375 $ PetscScalar val(1) 2376 $ ... 2377 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2378 2379 2380 See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches 2381 2382 Developer Notes: The petsc/finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these 2383 automatically include their predecessors; for example petsc/finclude/petscvecdef.h includes petsc/finclude/petscisdef.h 2384 2385 The petsc/finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include 2386 their petsc/finclude/petscXXXdef.h file but DO NOT automatically include their predecessors; for example 2387 petsc/finclude/petscvec.h does NOT automatically include petsc/finclude/petscis.h 2388 2389 The petsc/finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the 2390 Fortran data type type(XXX) (for example type(Vec)) when PETSc is ./configure with the --with-fortran-datatypes option. 2391 2392 The petsc/finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for 2393 the PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90). 2394 2395 The petsc/finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated 2396 automatically by "make allfortranstubs". 2397 2398 The petsc/finclude/petscXXX.h90 includes the custom petsc/finclude/ftn-custom/petscXXX.h90 and if ./configure 2399 was run with --with-fortran-interfaces it also includes the petsc/finclude/ftn-auto/petscXXX.h90 These DO NOT automatically 2400 include their predecessors 2401 2402 Level: beginner 2403 2404 M*/ 2405 2406 PETSC_EXTERN PetscErrorCode PetscGetArchType(char[],size_t); 2407 PETSC_EXTERN PetscErrorCode PetscGetHostName(char[],size_t); 2408 PETSC_EXTERN PetscErrorCode PetscGetUserName(char[],size_t); 2409 PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[],size_t); 2410 PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]); 2411 PETSC_EXTERN PetscErrorCode PetscGetDate(char[],size_t); 2412 PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t); 2413 2414 PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]); 2415 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt*,PetscInt[]); 2416 PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt*); 2417 PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]); 2418 PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]); 2419 PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]); 2420 PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt,PetscInt*,PetscInt*,PetscInt*); 2421 PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt,PetscMPIInt[]); 2422 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt*,PetscMPIInt[]); 2423 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]); 2424 PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]); 2425 PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt,PetscInt[],void*,size_t,void*); 2426 PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]); 2427 PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]); 2428 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt*,PetscReal[]); 2429 PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]); 2430 PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]); 2431 PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt,const PetscBool [],const PetscInt[],PetscInt*,PetscInt**,PetscInt**,PetscInt**,PetscInt**); 2432 PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt,const PetscInt*,const PetscInt*,PetscInt,const PetscInt*,const PetscInt*,PetscInt*,PetscInt**,PetscInt**); 2433 PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt,const PetscInt*,PetscInt,const PetscInt*,PetscInt*,PetscInt**); 2434 PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt,const PetscMPIInt[],PetscInt,const PetscMPIInt[],PetscInt*,PetscMPIInt**); 2435 2436 PETSC_EXTERN PetscErrorCode PetscSetDisplay(void); 2437 PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[],size_t); 2438 2439 /*J 2440 PetscRandomType - String with the name of a PETSc randomizer 2441 2442 Level: beginner 2443 2444 Notes: to use the SPRNG you must have ./configure PETSc 2445 with the option --download-sprng 2446 2447 .seealso: PetscRandomSetType(), PetscRandom, PetscRandomCreate() 2448 J*/ 2449 typedef const char* PetscRandomType; 2450 #define PETSCRAND "rand" 2451 #define PETSCRAND48 "rand48" 2452 #define PETSCSPRNG "sprng" 2453 #define PETSCRANDER48 "rander48" 2454 2455 /* Logging support */ 2456 PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID; 2457 2458 PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void); 2459 2460 /*S 2461 PetscRandom - Abstract PETSc object that manages generating random numbers 2462 2463 Level: intermediate 2464 2465 Concepts: random numbers 2466 2467 .seealso: PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType 2468 S*/ 2469 typedef struct _p_PetscRandom* PetscRandom; 2470 2471 /* Dynamic creation and loading functions */ 2472 PETSC_EXTERN PetscFunctionList PetscRandomList; 2473 2474 PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[],PetscErrorCode (*)(PetscRandom)); 2475 PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType); 2476 PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom); 2477 PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType*); 2478 PETSC_STATIC_INLINE PetscErrorCode PetscRandomViewFromOptions(PetscRandom A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);} 2479 PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer); 2480 2481 PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*); 2482 PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*); 2483 PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom,PetscReal*); 2484 PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*); 2485 PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar); 2486 PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom,unsigned long); 2487 PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom,unsigned long *); 2488 PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom); 2489 PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom*); 2490 2491 PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t); 2492 PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t); 2493 PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t); 2494 PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[],char[]); 2495 PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t); 2496 PETSC_EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscBool *); 2497 PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscBool *); 2498 PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]); 2499 PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]); 2500 2501 PETSC_EXTERN PetscErrorCode PetscBinaryRead(int,void*,PetscInt,PetscDataType); 2502 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType); 2503 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscBool ); 2504 PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscBool ); 2505 PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[],PetscFileMode,int *); 2506 PETSC_EXTERN PetscErrorCode PetscBinaryClose(int); 2507 PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscBool *); 2508 PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscBool *); 2509 PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char[],size_t); 2510 PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscBool *); 2511 PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char[],size_t,PetscBool *); 2512 PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[],int,int*); 2513 2514 /* 2515 In binary files variables are stored using the following lengths, 2516 regardless of how they are stored in memory on any one particular 2517 machine. Use these rather then sizeof() in computing sizes for 2518 PetscBinarySeek(). 2519 */ 2520 #define PETSC_BINARY_INT_SIZE (32/8) 2521 #define PETSC_BINARY_FLOAT_SIZE (32/8) 2522 #define PETSC_BINARY_CHAR_SIZE (8/8) 2523 #define PETSC_BINARY_SHORT_SIZE (16/8) 2524 #define PETSC_BINARY_DOUBLE_SIZE (64/8) 2525 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar) 2526 2527 /*E 2528 PetscBinarySeekType - argument to PetscBinarySeek() 2529 2530 Level: advanced 2531 2532 .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek() 2533 E*/ 2534 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType; 2535 PETSC_EXTERN PetscErrorCode PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*); 2536 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*); 2537 PETSC_EXTERN PetscErrorCode PetscByteSwap(void *,PetscDataType,PetscInt); 2538 2539 PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]); 2540 PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscBool ); 2541 PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 2542 PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char*); 2543 PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void); 2544 PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void); 2545 2546 PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*); 2547 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**); 2548 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**); 2549 PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**); 2550 PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**); 2551 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt*,const void*,PetscMPIInt*,PetscMPIInt**,void*) 2552 PetscAttrMPIPointerWithType(6,3); 2553 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt, 2554 PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*), 2555 PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx) 2556 PetscAttrMPIPointerWithType(6,3); 2557 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt, 2558 MPI_Request**,MPI_Request**, 2559 PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*), 2560 PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx) 2561 PetscAttrMPIPointerWithType(6,3); 2562 2563 /*E 2564 PetscBuildTwoSidedType - algorithm for setting up two-sided communication 2565 2566 $ PETSC_BUILDTWOSIDED_ALLREDUCE - classical algorithm using an MPI_Allreduce with 2567 $ a buffer of length equal to the communicator size. Not memory-scalable due to 2568 $ the large reduction size. Requires only MPI-1. 2569 $ PETSC_BUILDTWOSIDED_IBARRIER - nonblocking algorithm based on MPI_Issend and MPI_Ibarrier. 2570 $ Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires MPI-3. 2571 $ PETSC_BUILDTWOSIDED_REDSCATTER - similar to above, but use more optimized function 2572 $ that only communicates the part of the reduction that is necessary. Requires MPI-2. 2573 2574 Level: developer 2575 2576 .seealso: PetscCommBuildTwoSided(), PetscCommBuildTwoSidedSetType(), PetscCommBuildTwoSidedGetType() 2577 E*/ 2578 typedef enum { 2579 PETSC_BUILDTWOSIDED_NOTSET = -1, 2580 PETSC_BUILDTWOSIDED_ALLREDUCE = 0, 2581 PETSC_BUILDTWOSIDED_IBARRIER = 1, 2582 PETSC_BUILDTWOSIDED_REDSCATTER = 2 2583 /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */ 2584 } PetscBuildTwoSidedType; 2585 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[]; 2586 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm,PetscBuildTwoSidedType); 2587 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm,PetscBuildTwoSidedType*); 2588 2589 PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscBool *,PetscBool *); 2590 2591 /*E 2592 InsertMode - Whether entries are inserted or added into vectors or matrices 2593 2594 Level: beginner 2595 2596 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2597 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), 2598 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 2599 E*/ 2600 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES, INSERT_ALL_VALUES, ADD_ALL_VALUES, INSERT_BC_VALUES, ADD_BC_VALUES} InsertMode; 2601 2602 /*MC 2603 INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value 2604 2605 Level: beginner 2606 2607 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2608 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, 2609 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES 2610 2611 M*/ 2612 2613 /*MC 2614 ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the 2615 value into that location 2616 2617 Level: beginner 2618 2619 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2620 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), INSERT_VALUES, 2621 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES 2622 2623 M*/ 2624 2625 /*MC 2626 MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location 2627 2628 Level: beginner 2629 2630 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES 2631 2632 M*/ 2633 2634 PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject); 2635 2636 typedef enum {PETSC_SUBCOMM_GENERAL=0,PETSC_SUBCOMM_CONTIGUOUS=1,PETSC_SUBCOMM_INTERLACED=2} PetscSubcommType; 2637 PETSC_EXTERN const char *const PetscSubcommTypes[]; 2638 2639 /*S 2640 PetscSubcomm - A decomposition of an MPI communicator into subcommunicators 2641 2642 Notes: After a call to PetscSubcommSetType(), PetscSubcommSetTypeGeneral(), or PetscSubcommSetFromOptions() one may call 2643 $ PetscSubcommChild() returns the associated subcommunicator on this process 2644 $ PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiquous rank 2645 2646 Sample Usage: 2647 PetscSubcommCreate() 2648 PetscSubcommSetNumber() 2649 PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED); 2650 ccomm = PetscSubcommChild() 2651 PetscSubcommDestroy() 2652 2653 Level: advanced 2654 2655 Concepts: communicator, create 2656 2657 Notes: 2658 $ 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 2659 $ PETSC_SUBCOMM_CONTIGUOUS - each new communicator contains a set of process with contiquous ranks in the original MPI communicator 2660 $ PETSC_SUBCOMM_INTERLACED - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator 2661 2662 Examaple: Consider a communicator with six processes split into 3 subcommunicators. 2663 $ 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 2664 $ PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5 2665 2666 Developer Notes: This is used in objects such as PCREDUNDANT() to manage the subcommunicators on which the redundant computations 2667 are performed. 2668 2669 2670 .seealso: PetscSubcommCreate(), PetscSubcommSetNumber(), PetscSubcommSetType(), PetscSubcommView(), PetscSubcommSetFromOptions() 2671 2672 S*/ 2673 typedef struct _n_PetscSubcomm* PetscSubcomm; 2674 2675 struct _n_PetscSubcomm { 2676 MPI_Comm parent; /* parent communicator */ 2677 MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2678 MPI_Comm child; /* the sub-communicator */ 2679 PetscMPIInt n; /* num of subcommunicators under the parent communicator */ 2680 PetscMPIInt color; /* color of processors belong to this communicator */ 2681 PetscMPIInt *subsize; /* size of subcommunicator[color] */ 2682 PetscSubcommType type; 2683 }; 2684 2685 PETSC_STATIC_INLINE MPI_Comm PetscSubcommParent(PetscSubcomm scomm) {return scomm->parent;} 2686 PETSC_STATIC_INLINE MPI_Comm PetscSubcommChild(PetscSubcomm scomm) {return scomm->child;} 2687 PETSC_STATIC_INLINE MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) {return scomm->dupparent;} 2688 PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm,PetscSubcomm*); 2689 PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm*); 2690 PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm,PetscInt); 2691 PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm,PetscSubcommType); 2692 PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm,PetscMPIInt,PetscMPIInt); 2693 PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm,PetscViewer); 2694 PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm); 2695 2696 /*S 2697 PetscSegBuffer - a segmented extendable buffer 2698 2699 Level: developer 2700 2701 .seealso: PetscSegBufferCreate(), PetscSegBufferGet(), PetscSegBufferExtract(), PetscSegBufferDestroy() 2702 S*/ 2703 typedef struct _n_PetscSegBuffer *PetscSegBuffer; 2704 PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t,size_t,PetscSegBuffer*); 2705 PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer*); 2706 PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer,size_t,void*); 2707 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer,void*); 2708 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer,void*); 2709 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer,void*); 2710 PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer,size_t*); 2711 PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer,size_t); 2712 2713 /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling 2714 * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as 2715 * possible. */ 2716 PETSC_STATIC_INLINE PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg,PetscInt count,PetscInt *PETSC_RESTRICT *slot) {return PetscSegBufferGet(seg,(size_t)count,(void**)slot);} 2717 2718 PETSC_EXTERN PetscSegBuffer PetscCitationsList; 2719 #undef __FUNCT__ 2720 #define __FUNCT__ "PetscCitationsRegister" 2721 /*@C 2722 PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code. 2723 2724 Not Collective - only what is registered on rank 0 of PETSC_COMM_WORLD will be printed 2725 2726 Input Parameters: 2727 + cite - the bibtex item, formated to displayed on multiple lines nicely 2728 - set - a boolean variable initially set to PETSC_FALSE; this is used to insure only a single registration of the citation 2729 2730 Level: intermediate 2731 2732 Options Database: 2733 . -citations [filenmae] - print out the bibtex entries for the given computation 2734 @*/ 2735 PETSC_STATIC_INLINE PetscErrorCode PetscCitationsRegister(const char cit[],PetscBool *set) 2736 { 2737 size_t len; 2738 char *vstring; 2739 PetscErrorCode ierr; 2740 2741 PetscFunctionBegin; 2742 if (set && *set) PetscFunctionReturn(0); 2743 ierr = PetscStrlen(cit,&len);CHKERRQ(ierr); 2744 ierr = PetscSegBufferGet(PetscCitationsList,len,&vstring);CHKERRQ(ierr); 2745 ierr = PetscMemcpy(vstring,cit,len);CHKERRQ(ierr); 2746 if (set) *set = PETSC_TRUE; 2747 PetscFunctionReturn(0); 2748 } 2749 2750 PETSC_EXTERN PetscErrorCode PetscURLShorten(const char[],char[],size_t); 2751 PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm,char[],char[],size_t); 2752 PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm,const char[],char[],size_t); 2753 PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm,const char[],const char []); 2754 2755 PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm,char[],char[],size_t); 2756 PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm,const char[],char[],char[],size_t); 2757 2758 PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm,const char[],const char[],PetscBool*); 2759 2760 PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[],const char[],char[],size_t,PetscBool*); 2761 PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[],const char[],const char[],size_t); 2762 2763 2764 #if defined(PETSC_USE_DEBUG) 2765 2766 /* 2767 Verify that all processes in the communicator have called this from the same line of code 2768 */ 2769 PETSC_EXTERN PetscErrorCode PetscAllreduceBarrierCheck(MPI_Comm,PetscMPIInt,int,const char*,const char *); 2770 #define MPIU_Allreduce(a,b,c,d,e,fcomm) (PetscAllreduceBarrierCheck(fcomm,c,__LINE__,__FUNCT__,__FILE__) || MPI_Allreduce(a,b,c,d,e,fcomm)) 2771 #else 2772 #define MPIU_Allreduce(a,b,c,d,e,fcomm) MPI_Allreduce(a,b,c,d,e,fcomm) 2773 #endif 2774 2775 /* Reset __FUNCT__ in case the user does not define it themselves */ 2776 #undef __FUNCT__ 2777 #define __FUNCT__ "User provided function" 2778 2779 #endif 2780