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