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