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(__PETSC_H) 6 #define __PETSC_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 /* ========================================================================== */ 17 /* 18 This facilitates using C version of PETSc from C++ and 19 C++ version from C. Use --with-c-support --with-clanguage=c++ with config/configure.py for the latter) 20 */ 21 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) && !defined(__cplusplus) 22 #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler" 23 #endif 24 25 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 26 #define PETSC_EXTERN_CXX_BEGIN extern "C" { 27 #define PETSC_EXTERN_CXX_END } 28 #else 29 #define PETSC_EXTERN_CXX_BEGIN 30 #define PETSC_EXTERN_CXX_END 31 #endif 32 /* ========================================================================== */ 33 /* 34 Current PETSc version number and release date. Also listed in 35 Web page 36 src/docs/tex/manual/intro.tex, 37 src/docs/tex/manual/manual.tex. 38 src/docs/website/index.html. 39 */ 40 #include "petscversion.h" 41 #define PETSC_AUTHOR_INFO "\ 42 The PETSc Team\n\ 43 petsc-maint@mcs.anl.gov\n\ 44 http://www.mcs.anl.gov/petsc/\n" 45 #if (PETSC_VERSION_RELEASE == 1) 46 #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Release Version %d.%d.%d, Patch %d, ", \ 47 PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \ 48 PETSC_VERSION_PATCH),PetscStrcat(version,PETSC_VERSION_PATCH_DATE)) 49 #else 50 #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Development"), \ 51 PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG), \ 52 PetscStrcat(version," HG Date: "),PetscStrcat(version,PETSC_VERSION_DATE_HG)) 53 #endif 54 55 /*MC 56 PetscGetVersion - Gets the PETSc version information in a string. 57 58 Input Parameter: 59 . len - length of the string 60 61 Output Parameter: 62 . version - version string 63 64 Level: developer 65 66 Usage: 67 char version[256]; 68 ierr = PetscGetVersion(version,256);CHKERRQ(ierr) 69 70 Fortran Note: 71 This routine is not supported in Fortran. 72 73 .seealso: PetscGetProgramName() 74 75 M*/ 76 77 /* ========================================================================== */ 78 79 /* 80 Currently cannot check formatting for PETSc print statements because we have our 81 own format %D and %G 82 */ 83 #undef PETSC_PRINTF_FORMAT_CHECK 84 #define PETSC_PRINTF_FORMAT_CHECK(a,b) 85 #undef PETSC_FPRINTF_FORMAT_CHECK 86 #define PETSC_FPRINTF_FORMAT_CHECK(a,b) 87 88 /* 89 Fixes for config/configure.py time choices which impact our interface. Currently only 90 calling conventions and extra compiler checking falls under this category. 91 */ 92 #if !defined(PETSC_STDCALL) 93 #define PETSC_STDCALL 94 #endif 95 #if !defined(PETSC_TEMPLATE) 96 #define PETSC_TEMPLATE 97 #endif 98 #if !defined(PETSC_HAVE_DLL_EXPORT) 99 #define PETSC_DLL_EXPORT 100 #define PETSC_DLL_IMPORT 101 #endif 102 #if !defined(PETSC_DLLEXPORT) 103 #define PETSC_DLLEXPORT 104 #endif 105 #if !defined(PETSCVEC_DLLEXPORT) 106 #define PETSCVEC_DLLEXPORT 107 #endif 108 #if !defined(PETSCMAT_DLLEXPORT) 109 #define PETSCMAT_DLLEXPORT 110 #endif 111 #if !defined(PETSCDM_DLLEXPORT) 112 #define PETSCDM_DLLEXPORT 113 #endif 114 #if !defined(PETSCKSP_DLLEXPORT) 115 #define PETSCKSP_DLLEXPORT 116 #endif 117 #if !defined(PETSCSNES_DLLEXPORT) 118 #define PETSCSNES_DLLEXPORT 119 #endif 120 #if !defined(PETSCTS_DLLEXPORT) 121 #define PETSCTS_DLLEXPORT 122 #endif 123 #if !defined(PETSCFORTRAN_DLLEXPORT) 124 #define PETSCFORTRAN_DLLEXPORT 125 #endif 126 /* ========================================================================== */ 127 128 /* 129 Defines the interface to MPI allowing the use of all MPI functions. 130 131 PETSc does not use the C++ binding of MPI at ALL. The following flag 132 makes sure the C++ bindings are not included. The C++ bindings REQUIRE 133 putting mpi.h before ANY C++ include files, we cannot control this 134 with all PETSc users. Users who want to use the MPI C++ bindings can include 135 mpicxx.h directly in their code 136 */ 137 #define MPICH_SKIP_MPICXX 1 138 #define OMPI_SKIP_MPICXX 1 139 #include "mpi.h" 140 /* 141 Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 142 see the top of mpicxx.h in the MPICH2 distribution. 143 144 The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense. 145 */ 146 #include <stdio.h> 147 148 /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 149 #if !defined(MPIAPI) 150 #define MPIAPI 151 #endif 152 153 /*MC 154 PetscErrorCode - datatype used for return error code from all PETSc functions 155 156 Level: beginner 157 158 .seealso: CHKERRQ, SETERRQ 159 M*/ 160 typedef int PetscErrorCode; 161 162 /*MC 163 164 PetscCookie - A unique id used to identify each PETSc object. 165 (internal integer in the data structure used for error 166 checking). These are all defined by an offset from the lowest 167 one, PETSC_SMALLEST_COOKIE. 168 169 Level: advanced 170 171 .seealso: PetscCookieRegister(), PetscLogEventRegister(), PetscHeaderCreate() 172 M*/ 173 typedef int PetscCookie; 174 175 /*MC 176 PetscLogEvent - id used to identify PETSc or user events - primarily for logging 177 178 Level: intermediate 179 180 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage 181 M*/ 182 typedef int PetscLogEvent; 183 184 /*MC 185 PetscLogStage - id used to identify user stages of runs - for logging 186 187 Level: intermediate 188 189 .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent 190 M*/ 191 typedef int PetscLogStage; 192 193 /*MC 194 PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions. 195 196 Level: intermediate 197 198 Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 199 standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt 200 201 .seealso: PetscMPIInt, PetscInt 202 203 M*/ 204 typedef int PetscBLASInt; 205 206 /*MC 207 PetscMPIInt - datatype used to represent 'int' parameters to MPI functions. 208 209 Level: intermediate 210 211 Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 212 standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt 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 .seealso: PetscBLASInt, PetscInt 221 222 M*/ 223 typedef int PetscMPIInt; 224 225 /*MC 226 PetscEnum - datatype used to pass enum types within PETSc functions. 227 228 Level: intermediate 229 230 PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a 231 PETSC_ERR_ARG_OUTOFRANGE. 232 233 PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it 234 generates a PETSC_ERR_ARG_OUTOFRANGE 235 236 .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum() 237 M*/ 238 typedef enum { ENUM_DUMMY } PetscEnum; 239 240 /*MC 241 PetscInt - PETSc type that represents integer - used primarily to 242 represent size of objects. Its size can be configured with the option 243 --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints] 244 245 Level: intermediate 246 247 248 .seealso: PetscScalar, PetscBLASInt, PetscMPIInt 249 M*/ 250 #if defined(PETSC_USE_64BIT_INDICES) 251 typedef long long PetscInt; 252 #define MPIU_INT MPI_LONG_LONG_INT 253 #else 254 typedef int PetscInt; 255 #define MPIU_INT MPI_INT 256 #endif 257 258 /* 259 You can use PETSC_STDOUT as a replacement of stdout. You can also change 260 the value of PETSC_STDOUT to redirect all standard output elsewhere 261 */ 262 263 extern FILE* PETSC_STDOUT; 264 265 /* 266 You can use PETSC_STDERR as a replacement of stderr. You can also change 267 the value of PETSC_STDERR to redirect all standard error elsewhere 268 */ 269 extern FILE* PETSC_STDERR; 270 271 /* 272 PETSC_ZOPEFD is used to send data to the PETSc webpage. It can be used 273 in conjunction with PETSC_STDOUT, or by itself. 274 */ 275 extern FILE* PETSC_ZOPEFD; 276 277 #if !defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 278 /*MC 279 PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of 280 a PETSc function that remove certain optional arguments for a simplier user interface 281 282 Not collective 283 284 Synopsis: 285 PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function)) 286 287 Level: developer 288 289 Example: 290 PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine 291 PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r) 292 293 .seealso: PetscPolymorphicFunction() 294 295 M*/ 296 #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;} 297 298 /*MC 299 PetscPolymorphicScalar - allows defining a C++ polymorphic version of 300 a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument 301 302 Not collective 303 304 Synopsis: 305 PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function)) 306 307 Level: developer 308 309 Example: 310 PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine 311 PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);} 312 313 .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine() 314 315 M*/ 316 #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;} 317 318 /*MC 319 PetscPolymorphicFunction - allows defining a C++ polymorphic version of 320 a PETSc function that remove certain optional arguments for a simplier user interface 321 and returns the computed value (istead of an error code) 322 323 Not collective 324 325 Synopsis: 326 PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name) 327 328 Level: developer 329 330 Example: 331 PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine 332 PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;} 333 334 .seealso: PetscPolymorphicSubroutine() 335 336 M*/ 337 #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;} 338 339 #else 340 #define PetscPolymorphicSubroutine(A,B,C) 341 #define PetscPolymorphicScalar(A,B,C) 342 #define PetscPolymorphicFunction(A,B,C,D,E) 343 #endif 344 345 /*MC 346 PetscUnlikely - hints the compiler that the given condition is usually FALSE 347 348 Not Collective 349 350 Synopsis: 351 PetscTruth PetscUnlikely(PetscTruth cond) 352 353 Input Parameters: 354 . cond - condition or expression 355 356 Note: This returns the same truth value, it is only a hint to compilers that the resulting 357 branch is unlikely. 358 359 Level: advanced 360 361 .seealso: PetscLikely(), CHKERRQ 362 M*/ 363 364 /*MC 365 PetscLikely - hints the compiler that the given condition is usually TRUE 366 367 Not Collective 368 369 Synopsis: 370 PetscTruth PetscUnlikely(PetscTruth cond) 371 372 Input Parameters: 373 . cond - condition or expression 374 375 Note: This returns the same truth value, it is only a hint to compilers that the resulting 376 branch is likely. 377 378 Level: advanced 379 380 .seealso: PetscUnlikely() 381 M*/ 382 #if defined(PETSC_HAVE_BUILTIN_EXPECT) 383 # define PetscUnlikely(cond) __builtin_expect(!!(cond),0) 384 # define PetscLikely(cond) __builtin_expect(!!(cond),1) 385 #else 386 # define PetscUnlikely(cond) cond 387 # define PetscLikely(cond) cond 388 #endif 389 390 /* 391 Extern indicates a PETSc function defined elsewhere 392 */ 393 #if !defined(EXTERN) 394 #define EXTERN extern 395 #endif 396 397 /* 398 Defines some elementary mathematics functions and constants. 399 */ 400 #include "petscmath.h" 401 402 /* 403 Declare extern C stuff after including external header files 404 */ 405 406 PETSC_EXTERN_CXX_BEGIN 407 408 /* 409 Basic PETSc constants 410 */ 411 412 /*E 413 PetscTruth - Logical variable. Actually an integer 414 415 Level: beginner 416 417 E*/ 418 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth; 419 extern const char *PetscTruths[]; 420 421 /*MC 422 PETSC_FALSE - False value of PetscTruth 423 424 Level: beginner 425 426 Note: Zero integer 427 428 .seealso: PetscTruth, PETSC_TRUE 429 M*/ 430 431 /*MC 432 PETSC_TRUE - True value of PetscTruth 433 434 Level: beginner 435 436 Note: Nonzero integer 437 438 .seealso: PetscTruth, PETSC_FALSE 439 M*/ 440 441 /*MC 442 PETSC_YES - Alias for PETSC_TRUE 443 444 Level: beginner 445 446 Note: Zero integer 447 448 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO 449 M*/ 450 #define PETSC_YES PETSC_TRUE 451 452 /*MC 453 PETSC_NO - Alias for PETSC_FALSE 454 455 Level: beginner 456 457 Note: Nonzero integer 458 459 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES 460 M*/ 461 #define PETSC_NO PETSC_FALSE 462 463 /*MC 464 PETSC_NULL - standard way of passing in a null or array or pointer 465 466 Level: beginner 467 468 Notes: accepted by many PETSc functions to not set a parameter and instead use 469 some default 470 471 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 472 PETSC_NULL_DOUBLE_PRECISION etc 473 474 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 475 476 M*/ 477 #define PETSC_NULL 0 478 479 /*MC 480 PETSC_DECIDE - standard way of passing in integer or floating point parameter 481 where you wish PETSc to use the default. 482 483 Level: beginner 484 485 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 486 487 M*/ 488 #define PETSC_DECIDE -1 489 490 /*MC 491 PETSC_DEFAULT - standard way of passing in integer or floating point parameter 492 where you wish PETSc to use the default. 493 494 Level: beginner 495 496 Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION. 497 498 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE 499 500 M*/ 501 #define PETSC_DEFAULT -2 502 503 504 /*MC 505 PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument 506 507 Level: beginner 508 509 Note: accepted by many PETSc functions to not set a parameter and instead use 510 some default 511 512 Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 513 PETSC_NULL_DOUBLE_PRECISION etc 514 515 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE 516 517 M*/ 518 #define PETSC_IGNORE PETSC_NULL 519 520 /*MC 521 PETSC_DETERMINE - standard way of passing in integer or floating point parameter 522 where you wish PETSc to compute the required value. 523 524 Level: beginner 525 526 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes() 527 528 M*/ 529 #define PETSC_DETERMINE PETSC_DECIDE 530 531 /*MC 532 PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents 533 all the processs that PETSc knows about. 534 535 Level: beginner 536 537 Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 538 run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller) 539 communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling 540 PetscInitialize() 541 542 .seealso: PETSC_COMM_SELF 543 544 M*/ 545 extern MPI_Comm PETSC_COMM_WORLD; 546 547 /*MC 548 PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents 549 the current process 550 551 Level: beginner 552 553 Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent. 554 555 .seealso: PETSC_COMM_WORLD 556 557 M*/ 558 #define PETSC_COMM_SELF MPI_COMM_SELF 559 560 extern PETSC_DLLEXPORT PetscTruth PetscInitializeCalled; 561 extern PETSC_DLLEXPORT PetscTruth PetscFinalizeCalled; 562 563 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 564 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 565 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDestroy(MPI_Comm*); 566 567 /*MC 568 PetscMalloc - Allocates memory 569 570 Input Parameter: 571 . m - number of bytes to allocate 572 573 Output Parameter: 574 . result - memory allocated 575 576 Synopsis: 577 PetscErrorCode PetscMalloc(size_t m,void **result) 578 579 Level: beginner 580 581 Notes: Memory is always allocated at least double aligned 582 583 If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 584 properly handle not freeing the null pointer. 585 586 .seealso: PetscFree(), PetscNew() 587 588 Concepts: memory allocation 589 590 M*/ 591 #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) ) 592 593 /*MC 594 PetscAddrAlign - Returns an address with PETSC_MEMALIGN alignment 595 596 Input Parameters: 597 . addr - address to align (any pointer type) 598 599 Synopsis: 600 void *PetscAddrAlign(void *addr) 601 602 Level: developer 603 .seealso: PetscMallocAlign() 604 Concepts: memory allocation 605 M*/ 606 #if defined PETSC_UINTPTR_T 607 # define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1)) 608 #else 609 # define PetscAddrAlign(a) (void*)(a) 610 #endif 611 612 /*MC 613 PetscMalloc2 - Allocates 2 chunks of memory 614 615 Input Parameter: 616 + m1 - number of elements to allocate in 1st chunk (may be zero) 617 . t1 - type of first memory elements 618 . m2 - number of elements to allocate in 2nd chunk (may be zero) 619 - t2 - type of second memory elements 620 621 Output Parameter: 622 + r1 - memory allocated in first chunk 623 - r2 - memory allocated in second chunk 624 625 Synopsis: 626 PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2) 627 628 Level: developer 629 630 Notes: Memory of first chunk is always allocated at least double aligned 631 632 .seealso: PetscFree(), PetscNew(), PetscMalloc() 633 634 Concepts: memory allocation 635 636 M*/ 637 #if defined(PETSC_USE_DEBUG) 638 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2)) 639 #else 640 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(PETSC_MEMALIGN-1),r1) \ 641 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),0)) 642 #endif 643 644 /*MC 645 PetscMalloc3 - Allocates 3 chunks of memory 646 647 Input Parameter: 648 + m1 - number of elements to allocate in 1st chunk (may be zero) 649 . t1 - type of first memory elements 650 . m2 - number of elements to allocate in 2nd chunk (may be zero) 651 . t2 - type of second memory elements 652 . m3 - number of elements to allocate in 3rd chunk (may be zero) 653 - t3 - type of third memory elements 654 655 Output Parameter: 656 + r1 - memory allocated in first chunk 657 . r2 - memory allocated in second chunk 658 - r3 - memory allocated in third chunk 659 660 Synopsis: 661 PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3) 662 663 Level: developer 664 665 Notes: Memory of first chunk is always allocated at least double aligned 666 667 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3() 668 669 Concepts: memory allocation 670 671 M*/ 672 #if defined(PETSC_USE_DEBUG) 673 #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)) 674 #else 675 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+2*(PETSC_MEMALIGN-1),r1) \ 676 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),0)) 677 #endif 678 679 /*MC 680 PetscMalloc4 - Allocates 4 chunks of memory 681 682 Input Parameter: 683 + m1 - number of elements to allocate in 1st chunk (may be zero) 684 . t1 - type of first memory elements 685 . m2 - number of elements to allocate in 2nd chunk (may be zero) 686 . t2 - type of second memory elements 687 . m3 - number of elements to allocate in 3rd chunk (may be zero) 688 . t3 - type of third memory elements 689 . m4 - number of elements to allocate in 4th chunk (may be zero) 690 - t4 - type of fourth memory elements 691 692 Output Parameter: 693 + r1 - memory allocated in first chunk 694 . r2 - memory allocated in second chunk 695 . r3 - memory allocated in third chunk 696 - r4 - memory allocated in fourth chunk 697 698 Synopsis: 699 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) 700 701 Level: developer 702 703 Notes: Memory of first chunk is always allocated at least double aligned 704 705 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4() 706 707 Concepts: memory allocation 708 709 M*/ 710 #if defined(PETSC_USE_DEBUG) 711 #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)) 712 #else 713 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) \ 714 (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+3*(PETSC_MEMALIGN-1),r1) \ 715 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),0)) 716 #endif 717 718 /*MC 719 PetscMalloc5 - Allocates 5 chunks of memory 720 721 Input Parameter: 722 + m1 - number of elements to allocate in 1st chunk (may be zero) 723 . t1 - type of first memory elements 724 . m2 - number of elements to allocate in 2nd chunk (may be zero) 725 . t2 - type of second memory elements 726 . m3 - number of elements to allocate in 3rd chunk (may be zero) 727 . t3 - type of third memory elements 728 . m4 - number of elements to allocate in 4th chunk (may be zero) 729 . t4 - type of fourth memory elements 730 . m5 - number of elements to allocate in 5th chunk (may be zero) 731 - t5 - type of fifth memory elements 732 733 Output Parameter: 734 + r1 - memory allocated in first chunk 735 . r2 - memory allocated in second chunk 736 . r3 - memory allocated in third chunk 737 . r4 - memory allocated in fourth chunk 738 - r5 - memory allocated in fifth chunk 739 740 Synopsis: 741 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) 742 743 Level: developer 744 745 Notes: Memory of first chunk is always allocated at least double aligned 746 747 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5() 748 749 Concepts: memory allocation 750 751 M*/ 752 #if defined(PETSC_USE_DEBUG) 753 #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)) 754 #else 755 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) \ 756 (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+4*(PETSC_MEMALIGN-1),r1) \ 757 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),0)) 758 #endif 759 760 761 /*MC 762 PetscMalloc6 - Allocates 6 chunks of memory 763 764 Input Parameter: 765 + m1 - number of elements to allocate in 1st chunk (may be zero) 766 . t1 - type of first memory elements 767 . m2 - number of elements to allocate in 2nd chunk (may be zero) 768 . t2 - type of second memory elements 769 . m3 - number of elements to allocate in 3rd chunk (may be zero) 770 . t3 - type of third memory elements 771 . m4 - number of elements to allocate in 4th chunk (may be zero) 772 . t4 - type of fourth memory elements 773 . m5 - number of elements to allocate in 5th chunk (may be zero) 774 . t5 - type of fifth memory elements 775 . m6 - number of elements to allocate in 6th chunk (may be zero) 776 - t6 - type of sixth memory elements 777 778 Output Parameter: 779 + r1 - memory allocated in first chunk 780 . r2 - memory allocated in second chunk 781 . r3 - memory allocated in third chunk 782 . r4 - memory allocated in fourth chunk 783 . r5 - memory allocated in fifth chunk 784 - r6 - memory allocated in sixth chunk 785 786 Synopsis: 787 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) 788 789 Level: developer 790 791 Notes: Memory of first chunk is always allocated at least double aligned 792 793 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6() 794 795 Concepts: memory allocation 796 797 M*/ 798 #if defined(PETSC_USE_DEBUG) 799 #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)) 800 #else 801 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) \ 802 (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+5*(PETSC_MEMALIGN-1),r1) \ 803 || (*(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)) 804 #endif 805 806 /*MC 807 PetscMalloc7 - Allocates 7 chunks of memory 808 809 Input Parameter: 810 + m1 - number of elements to allocate in 1st chunk (may be zero) 811 . t1 - type of first memory elements 812 . m2 - number of elements to allocate in 2nd chunk (may be zero) 813 . t2 - type of second memory elements 814 . m3 - number of elements to allocate in 3rd chunk (may be zero) 815 . t3 - type of third memory elements 816 . m4 - number of elements to allocate in 4th chunk (may be zero) 817 . t4 - type of fourth memory elements 818 . m5 - number of elements to allocate in 5th chunk (may be zero) 819 . t5 - type of fifth memory elements 820 . m6 - number of elements to allocate in 6th chunk (may be zero) 821 . t6 - type of sixth memory elements 822 . m7 - number of elements to allocate in 7th chunk (may be zero) 823 - t7 - type of sixth memory elements 824 825 Output Parameter: 826 + r1 - memory allocated in first chunk 827 . r2 - memory allocated in second chunk 828 . r3 - memory allocated in third chunk 829 . r4 - memory allocated in fourth chunk 830 . r5 - memory allocated in fifth chunk 831 . r6 - memory allocated in sixth chunk 832 - r7 - memory allocated in sixth chunk 833 834 Synopsis: 835 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) 836 837 Level: developer 838 839 Notes: Memory of first chunk is always allocated at least double aligned 840 841 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7() 842 843 Concepts: memory allocation 844 845 M*/ 846 #if defined(PETSC_USE_DEBUG) 847 #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)) 848 #else 849 #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) \ 850 (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) \ 851 || (*(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)) 852 #endif 853 854 /*MC 855 PetscNew - Allocates memory of a particular type, zeros the memory! 856 857 Input Parameter: 858 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 859 860 Output Parameter: 861 . result - memory allocated 862 863 Synopsis: 864 PetscErrorCode PetscNew(struct type,((type *))result) 865 866 Level: beginner 867 868 .seealso: PetscFree(), PetscMalloc() 869 870 Concepts: memory allocation 871 872 M*/ 873 #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A))) 874 #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0)) 875 876 /*MC 877 PetscFree - Frees memory 878 879 Input Parameter: 880 . memory - memory to free (the pointer is ALWAYS set to 0 upon sucess) 881 882 Synopsis: 883 PetscErrorCode PetscFree(void *memory) 884 885 Level: beginner 886 887 Notes: Memory must have been obtained with PetscNew() or PetscMalloc() 888 889 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid() 890 891 Concepts: memory allocation 892 893 M*/ 894 #define PetscFree(a) ((a) ? ((*PetscTrFree)((void*)(a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0) 895 896 /*MC 897 PetscFreeVoid - Frees memory 898 899 Input Parameter: 900 . memory - memory to free 901 902 Synopsis: 903 void PetscFreeVoid(void *memory) 904 905 Level: beginner 906 907 Notes: This is different from PetscFree() in that no error code is returned 908 909 .seealso: PetscFree(), PetscNew(), PetscMalloc() 910 911 Concepts: memory allocation 912 913 M*/ 914 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0) 915 916 917 /*MC 918 PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 919 920 Input Parameter: 921 + memory1 - memory to free 922 - memory2 - 2nd memory to free 923 924 925 Synopsis: 926 PetscErrorCode PetscFree2(void *memory1,void *memory2) 927 928 Level: developer 929 930 Notes: Memory must have been obtained with PetscMalloc2() 931 932 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree() 933 934 Concepts: memory allocation 935 936 M*/ 937 #if defined(PETSC_USE_DEBUG) 938 #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1)) 939 #else 940 #define PetscFree2(m1,m2) (PetscFree(m1)) 941 #endif 942 943 /*MC 944 PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 945 946 Input Parameter: 947 + memory1 - memory to free 948 . memory2 - 2nd memory to free 949 - memory3 - 3rd memory to free 950 951 952 Synopsis: 953 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 954 955 Level: developer 956 957 Notes: Memory must have been obtained with PetscMalloc3() 958 959 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3() 960 961 Concepts: memory allocation 962 963 M*/ 964 #if defined(PETSC_USE_DEBUG) 965 #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 966 #else 967 #define PetscFree3(m1,m2,m3) (PetscFree(m1)) 968 #endif 969 970 /*MC 971 PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 972 973 Input Parameter: 974 + m1 - memory to free 975 . m2 - 2nd memory to free 976 . m3 - 3rd memory to free 977 - m4 - 4th memory to free 978 979 980 Synopsis: 981 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 982 983 Level: developer 984 985 Notes: Memory must have been obtained with PetscMalloc4() 986 987 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4() 988 989 Concepts: memory allocation 990 991 M*/ 992 #if defined(PETSC_USE_DEBUG) 993 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 994 #else 995 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1)) 996 #endif 997 998 /*MC 999 PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 1000 1001 Input Parameter: 1002 + m1 - memory to free 1003 . m2 - 2nd memory to free 1004 . m3 - 3rd memory to free 1005 . m4 - 4th memory to free 1006 - m5 - 5th memory to free 1007 1008 1009 Synopsis: 1010 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 1011 1012 Level: developer 1013 1014 Notes: Memory must have been obtained with PetscMalloc5() 1015 1016 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5() 1017 1018 Concepts: memory allocation 1019 1020 M*/ 1021 #if defined(PETSC_USE_DEBUG) 1022 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1023 #else 1024 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1)) 1025 #endif 1026 1027 1028 /*MC 1029 PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 1030 1031 Input Parameter: 1032 + m1 - memory to free 1033 . m2 - 2nd memory to free 1034 . m3 - 3rd memory to free 1035 . m4 - 4th memory to free 1036 . m5 - 5th memory to free 1037 - m6 - 6th memory to free 1038 1039 1040 Synopsis: 1041 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1042 1043 Level: developer 1044 1045 Notes: Memory must have been obtained with PetscMalloc6() 1046 1047 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6() 1048 1049 Concepts: memory allocation 1050 1051 M*/ 1052 #if defined(PETSC_USE_DEBUG) 1053 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1054 #else 1055 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1)) 1056 #endif 1057 1058 /*MC 1059 PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7() 1060 1061 Input Parameter: 1062 + m1 - memory to free 1063 . m2 - 2nd memory to free 1064 . m3 - 3rd memory to free 1065 . m4 - 4th memory to free 1066 . m5 - 5th memory to free 1067 . m6 - 6th memory to free 1068 - m7 - 7th memory to free 1069 1070 1071 Synopsis: 1072 PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1073 1074 Level: developer 1075 1076 Notes: Memory must have been obtained with PetscMalloc7() 1077 1078 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(), 1079 PetscMalloc7() 1080 1081 Concepts: memory allocation 1082 1083 M*/ 1084 #if defined(PETSC_USE_DEBUG) 1085 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1086 #else 1087 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m1)) 1088 #endif 1089 1090 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**); 1091 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]); 1092 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[])); 1093 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocClear(void); 1094 1095 /* 1096 Routines for tracing memory corruption/bleeding with default PETSc 1097 memory allocation 1098 */ 1099 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDump(FILE *); 1100 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDumpLog(FILE *); 1101 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetCurrentUsage(PetscLogDouble *); 1102 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetMaximumUsage(PetscLogDouble *); 1103 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDebug(PetscTruth); 1104 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocValidate(int,const char[],const char[],const char[]); 1105 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocSetDumpLog(void); 1106 1107 1108 /* 1109 Variable type where we stash PETSc object pointers in Fortran. 1110 On most machines size(pointer) == sizeof(long) - except windows 1111 where its sizeof(long long) 1112 */ 1113 1114 #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG) 1115 #define PetscFortranAddr long 1116 #elif (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG) 1117 #define PetscFortranAddr long long 1118 #else 1119 #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov" 1120 #endif 1121 1122 /*E 1123 PetscDataType - Used for handling different basic data types. 1124 1125 Level: beginner 1126 1127 Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not? 1128 1129 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(), 1130 PetscDataTypeGetSize() 1131 1132 E*/ 1133 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5, 1134 PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType; 1135 extern const char *PetscDataTypes[]; 1136 1137 #if defined(PETSC_USE_COMPLEX) 1138 #define PETSC_SCALAR PETSC_COMPLEX 1139 #else 1140 #if defined(PETSC_USE_SCALAR_SINGLE) 1141 #define PETSC_SCALAR PETSC_FLOAT 1142 #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 1143 #define PETSC_SCALAR PETSC_LONG_DOUBLE 1144 #elif defined(PETSC_USE_SCALAR_INT) 1145 #define PETSC_SCALAR PETSC_INT 1146 #else 1147 #define PETSC_SCALAR PETSC_DOUBLE 1148 #endif 1149 #endif 1150 #if defined(PETSC_USE_SCALAR_SINGLE) 1151 #define PETSC_REAL PETSC_FLOAT 1152 #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 1153 #define PETSC_REAL PETSC_LONG_DOUBLE 1154 #elif defined(PETSC_USE_SCALAR_INT) 1155 #define PETSC_REAL PETSC_INT 1156 #else 1157 #define PETSC_REAL PETSC_DOUBLE 1158 #endif 1159 #define PETSC_FORTRANADDR PETSC_LONG 1160 1161 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 1162 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*); 1163 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,size_t*); 1164 1165 /* 1166 Basic memory and string operations. These are usually simple wrappers 1167 around the basic Unix system calls, but a few of them have additional 1168 functionality and/or error checking. 1169 */ 1170 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType); 1171 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemmove(void*,void *,size_t); 1172 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemcmp(const void*,const void*,size_t,PetscTruth *); 1173 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrlen(const char[],size_t*); 1174 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcmp(const char[],const char[],PetscTruth *); 1175 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrgrt(const char[],const char[],PetscTruth *); 1176 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcasecmp(const char[],const char[],PetscTruth*); 1177 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncmp(const char[],const char[],size_t,PetscTruth*); 1178 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcpy(char[],const char[]); 1179 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcat(char[],const char[]); 1180 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncat(char[],const char[],size_t); 1181 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncpy(char[],const char[],size_t); 1182 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrchr(const char[],char,char *[]); 1183 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrtolower(char[]); 1184 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrrchr(const char[],char,char *[]); 1185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrstr(const char[],const char[],char *[]); 1186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrrstr(const char[],const char[],char *[]); 1187 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrallocpy(const char[],char *[]); 1188 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrreplace(MPI_Comm,const char[],char[],size_t); 1189 #define PetscStrfree(a) ((a) ? PetscFree(a) : 0) 1190 1191 1192 /*S 1193 PetscToken - 'Token' used for managing tokenizing strings 1194 1195 Level: intermediate 1196 1197 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy() 1198 S*/ 1199 typedef struct _p_PetscToken* PetscToken; 1200 1201 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenCreate(const char[],const char,PetscToken*); 1202 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenFind(PetscToken,char *[]); 1203 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenDestroy(PetscToken); 1204 1205 /* 1206 These are MPI operations for MPI_Allreduce() etc 1207 */ 1208 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op; 1209 #if defined(PETSC_USE_COMPLEX) 1210 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op; 1211 #else 1212 #define PetscSum_Op MPI_SUM 1213 #endif 1214 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 1215 1216 /*S 1217 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 1218 1219 Level: beginner 1220 1221 Note: This is the base class from which all objects appear. 1222 1223 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName() 1224 S*/ 1225 typedef struct _p_PetscObject* PetscObject; 1226 1227 /*S 1228 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 1229 by string name 1230 1231 Level: advanced 1232 1233 .seealso: PetscFListAdd(), PetscFListDestroy() 1234 S*/ 1235 typedef struct _n_PetscFList *PetscFList; 1236 1237 /*E 1238 PetscFileMode - Access mode for a file. 1239 1240 Level: beginner 1241 1242 FILE_MODE_READ - open a file at its beginning for reading 1243 1244 FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist) 1245 1246 FILE_MODE_APPEND - open a file at end for writing 1247 1248 FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing 1249 1250 FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end 1251 1252 .seealso: PetscViewerFileSetMode() 1253 E*/ 1254 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode; 1255 1256 #include "petscviewer.h" 1257 #include "petscoptions.h" 1258 1259 #define PETSC_SMALLEST_COOKIE 1211211 1260 extern PETSC_DLLEXPORT PetscCookie PETSC_LARGEST_COOKIE; 1261 extern PETSC_DLLEXPORT PetscCookie PETSC_OBJECT_COOKIE; 1262 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCookieRegister(const char[],PetscCookie *); 1263 1264 /* 1265 Routines that get memory usage information from the OS 1266 */ 1267 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *); 1268 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *); 1269 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void); 1270 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]); 1271 1272 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoAllow(PetscTruth,const char []); 1273 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*); 1274 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*); 1275 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(PetscReal); 1276 1277 /* 1278 Initialization of PETSc 1279 */ 1280 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]); 1281 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL)) 1282 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void); 1283 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *); 1284 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *); 1285 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void); 1286 EXTERN PetscErrorCode PetscInitializeFortran(void); 1287 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***); 1288 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArguments(char ***); 1289 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFreeArguments(char **); 1290 1291 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void); 1292 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(const char[]); 1293 1294 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPMerge(PetscMPIInt); 1295 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPSpawn(PetscMPIInt); 1296 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFinalize(void); 1297 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*); 1298 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFree(MPI_Comm,void*); 1299 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPNew(MPI_Comm,PetscInt,void**); 1300 1301 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPythonInitialize(const char[],const char[]); 1302 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPythonFinalize(void); 1303 1304 /* 1305 These are so that in extern C code we can caste function pointers to non-extern C 1306 function pointers. Since the regular C++ code expects its function pointers to be 1307 C++. 1308 */ 1309 typedef void (**PetscVoidStarFunction)(void); 1310 typedef void (*PetscVoidFunction)(void); 1311 typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1312 1313 /* 1314 PetscTryMethod - Queries an object for a method, if it exists then calls it. 1315 These are intended to be used only inside PETSc functions. 1316 */ 1317 #define PetscTryMethod(obj,A,B,C) \ 1318 0;{ PetscErrorCode (*f)B, __ierr; \ 1319 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1320 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1321 } 1322 #define PetscUseMethod(obj,A,B,C) \ 1323 0;{ PetscErrorCode (*f)B, __ierr; \ 1324 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1325 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1326 else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \ 1327 } 1328 /* 1329 Functions that can act on any PETSc object. 1330 */ 1331 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreate(MPI_Comm,PetscObject*); 1332 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *); 1333 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject); 1334 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*); 1335 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *); 1336 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,PetscCookie *); 1337 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetType(PetscObject,const char []); 1338 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,const char *[]); 1339 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]); 1340 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,const char*[]); 1341 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetTabLevel(PetscObject,PetscInt); 1342 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetTabLevel(PetscObject,PetscInt*); 1343 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt); 1344 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject); 1345 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*); 1346 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject); 1347 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *); 1348 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer); 1349 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject); 1350 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *); 1351 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 1352 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetFromOptions(PetscObject); 1353 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetUp(PetscObject); 1354 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *); 1355 1356 /*MC 1357 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 1358 1359 Collective on PetscObject 1360 1361 Input Parameters: 1362 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 1363 PetscObjectCompose((PetscObject)mat,...); 1364 . name - name associated with the child function 1365 . fname - name of the function 1366 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 1367 1368 Level: advanced 1369 1370 Synopsis: 1371 PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 1372 1373 Notes: 1374 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 1375 1376 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 1377 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 1378 1379 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 1380 work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic) 1381 enabled. 1382 1383 Concepts: objects^composing functions 1384 Concepts: composing functions 1385 Concepts: functions^querying 1386 Concepts: objects^querying 1387 Concepts: querying objects 1388 1389 .seealso: PetscObjectQueryFunction() 1390 M*/ 1391 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1392 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 1393 #else 1394 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d)) 1395 #endif 1396 1397 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 1398 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1399 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1400 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1401 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,const char*[]); 1402 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject); 1403 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]); 1404 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject); 1405 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void); 1406 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject); 1407 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*); 1408 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalize(PetscErrorCode (*)(void)); 1409 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalizeAll(void); 1410 1411 /* 1412 Defines PETSc error handling. 1413 */ 1414 #include "petscerror.h" 1415 1416 /*S 1417 PetscOList - Linked list of PETSc objects, accessable by string name 1418 1419 Level: advanced 1420 1421 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind() 1422 S*/ 1423 typedef struct _n_PetscOList *PetscOList; 1424 1425 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList); 1426 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*); 1427 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**); 1428 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject); 1429 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *); 1430 1431 /* 1432 Dynamic library lists. Lists of names of routines in dynamic 1433 link libraries that will be loaded as needed. 1434 */ 1435 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 1436 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*); 1437 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void)); 1438 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(PetscFList,MPI_Comm,FILE*,const char[],const char[],const char[],const char[]); 1439 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1440 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 1441 #else 1442 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 1443 #endif 1444 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *); 1445 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer); 1446 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []); 1447 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*); 1448 1449 /*S 1450 PetscDLLibrary - Linked list of dynamics libraries to search for functions 1451 1452 Level: advanced 1453 1454 --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries 1455 1456 .seealso: PetscDLLibraryOpen() 1457 S*/ 1458 typedef struct _n_PetscDLLibrary *PetscDLLibrary; 1459 extern PETSC_DLLEXPORT PetscDLLibrary DLLibrariesLoaded; 1460 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1461 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]); 1462 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **); 1463 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(PetscDLLibrary); 1464 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscTruth *); 1465 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *); 1466 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibrary); 1467 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1468 1469 /* 1470 Useful utility routines 1471 */ 1472 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1473 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1474 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1475 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1)) 1476 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1)) 1477 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1478 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1)) 1479 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1)) 1480 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject); 1481 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*); 1482 1483 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1484 /* 1485 Defines basic graphics available from PETSc. 1486 */ 1487 #include "petscdraw.h" 1488 1489 /* 1490 Defines the base data structures for all PETSc objects 1491 */ 1492 #include "private/petscimpl.h" 1493 /* 1494 Defines PETSc profiling. 1495 */ 1496 #include "petsclog.h" 1497 1498 /* 1499 For locking, unlocking and destroying AMS memories associated with 1500 PETSc objects. Not currently used. 1501 */ 1502 #define PetscPublishAll(v) 0 1503 #define PetscObjectTakeAccess(obj) 0 1504 #define PetscObjectGrantAccess(obj) 0 1505 #define PetscObjectDepublish(obj) 0 1506 1507 /* 1508 Simple PETSc parallel IO for ASCII printing 1509 */ 1510 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFixFilename(const char[],char[]); 1511 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1512 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFClose(MPI_Comm,FILE*); 1513 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1514 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1515 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSNPrintf(char*,size_t,const char [],...); 1516 1517 /* These are used internally by PETSc ASCII IO routines*/ 1518 #include <stdarg.h> 1519 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVSNPrintf(char*,size_t,const char[],int*,va_list); 1520 EXTERN PetscErrorCode PETSC_DLLEXPORT (*PetscVFPrintf)(FILE*,const char[],va_list); 1521 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVFPrintfDefault(FILE*,const char[],va_list); 1522 1523 /*MC 1524 PetscErrorPrintf - Prints error messages. 1525 1526 Not Collective 1527 1528 Synopsis: 1529 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1530 1531 Input Parameters: 1532 . format - the usual printf() format string 1533 1534 Options Database Keys: 1535 + -error_output_stdout - cause error messages to be printed to stdout instead of the 1536 (default) stderr 1537 - -error_output_none to turn off all printing of error messages (does not change the way the 1538 error is handled.) 1539 1540 Notes: Use 1541 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 1542 $ error is handled.) and 1543 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on 1544 1545 Use 1546 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 1547 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 1548 1549 Use 1550 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 1551 1552 Level: developer 1553 1554 Fortran Note: 1555 This routine is not supported in Fortran. 1556 1557 Concepts: error messages^printing 1558 Concepts: printing^error messages 1559 1560 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush() 1561 M*/ 1562 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...); 1563 1564 /*MC 1565 PetscHelpPrintf - Prints help messages. 1566 1567 Not Collective 1568 1569 Synopsis: 1570 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1571 1572 Input Parameters: 1573 . format - the usual printf() format string 1574 1575 Level: developer 1576 1577 Fortran Note: 1578 This routine is not supported in Fortran. 1579 1580 Concepts: help messages^printing 1581 Concepts: printing^help messages 1582 1583 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1584 M*/ 1585 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1586 1587 EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...); 1588 EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...); 1589 EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...); 1590 1591 #if defined(PETSC_HAVE_POPEN) 1592 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1593 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPClose(MPI_Comm,FILE*); 1594 #endif 1595 1596 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1597 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1598 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFlush(MPI_Comm); 1599 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1600 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1601 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1602 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetPetscDir(const char*[]); 1603 1604 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*); 1605 1606 /*S 1607 PetscContainer - Simple PETSc object that contains a pointer to any required data 1608 1609 Level: advanced 1610 1611 .seealso: PetscObject, PetscContainerCreate() 1612 S*/ 1613 extern PetscCookie PETSC_DLLEXPORT PETSC_CONTAINER_COOKIE; 1614 typedef struct _p_PetscContainer* PetscContainer; 1615 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerGetPointer(PetscContainer,void **); 1616 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetPointer(PetscContainer,void *); 1617 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerDestroy(PetscContainer); 1618 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerCreate(MPI_Comm,PetscContainer *); 1619 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*)); 1620 1621 /* 1622 For use in debuggers 1623 */ 1624 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank; 1625 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize; 1626 1627 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,const PetscInt[],PetscViewer); 1628 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,const PetscReal[],PetscViewer); 1629 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,const PetscScalar[],PetscViewer); 1630 1631 #if defined(PETSC_HAVE_MEMORY_H) 1632 #include <memory.h> 1633 #endif 1634 #if defined(PETSC_HAVE_STDLIB_H) 1635 #include <stdlib.h> 1636 #endif 1637 #if defined(PETSC_HAVE_STRINGS_H) 1638 #include <strings.h> 1639 #endif 1640 #if defined(PETSC_HAVE_STRING_H) 1641 #include <string.h> 1642 #endif 1643 #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1644 #include "petscblaslapack.h" 1645 #endif 1646 #if defined(PETSC_HAVE_XMMINTRIN_H) 1647 #include <xmmintrin.h> 1648 #endif 1649 #if defined(PETSC_HAVE_STDINT_H) 1650 #include <stdint.h> 1651 #endif 1652 1653 /*@C 1654 PetscMemcpy - Copies n bytes, beginning at location b, to the space 1655 beginning at location a. The two memory regions CANNOT overlap, use 1656 PetscMemmove() in that case. 1657 1658 Not Collective 1659 1660 Input Parameters: 1661 + b - pointer to initial memory space 1662 - n - length (in bytes) of space to copy 1663 1664 Output Parameter: 1665 . a - pointer to copy space 1666 1667 Level: intermediate 1668 1669 Compile Option: 1670 PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used 1671 for memory copies on double precision values. 1672 PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used 1673 for memory copies on double precision values. 1674 PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used 1675 for memory copies on double precision values. 1676 1677 Note: 1678 This routine is analogous to memcpy(). 1679 1680 Concepts: memory^copying 1681 Concepts: copying^memory 1682 1683 .seealso: PetscMemmove() 1684 1685 @*/ 1686 PETSC_STATIC_INLINE PetscErrorCode PETSC_DLLEXPORT PetscMemcpy(void *a,const void *b,size_t n) 1687 { 1688 #if defined(PETSC_USE_DEBUG) 1689 unsigned long al = (unsigned long) a,bl = (unsigned long) b; 1690 unsigned long nl = (unsigned long) n; 1691 if (n > 0 && !b) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer"); 1692 if (n > 0 && !a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer"); 1693 #endif 1694 PetscFunctionBegin; 1695 if (a != b) { 1696 #if defined(PETSC_USE_DEBUG) 1697 if ((al > bl && (al - bl) < nl) || (bl - al) < nl) { 1698 SETERRQ3(PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\ 1699 or make sure your copy regions and lengths are correct. \n\ 1700 Length (bytes) %ld first address %ld second address %ld",nl,al,bl); 1701 } 1702 #endif 1703 #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1704 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1705 size_t len = n/sizeof(PetscScalar); 1706 #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1707 PetscBLASInt one = 1,blen = PetscBLASIntCast(len); 1708 BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one); 1709 #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1710 fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a); 1711 #else 1712 size_t i; 1713 PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a; 1714 for (i=0; i<len; i++) y[i] = x[i]; 1715 #endif 1716 } else { 1717 memcpy((char*)(a),(char*)(b),n); 1718 } 1719 #elif defined(PETSC_HAVE__INTEL_FAST_MEMCPY) 1720 _intel_fast_memcpy((char*)(a),(char*)(b),n); 1721 #else 1722 memcpy((char*)(a),(char*)(b),n); 1723 #endif 1724 } 1725 PetscFunctionReturn(0); 1726 } 1727 1728 /*@C 1729 PetscMemzero - Zeros the specified memory. 1730 1731 Not Collective 1732 1733 Input Parameters: 1734 + a - pointer to beginning memory location 1735 - n - length (in bytes) of memory to initialize 1736 1737 Level: intermediate 1738 1739 Compile Option: 1740 PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens 1741 to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1742 1743 Concepts: memory^zeroing 1744 Concepts: zeroing^memory 1745 1746 .seealso: PetscMemcpy() 1747 @*/ 1748 PETSC_STATIC_INLINE PetscErrorCode PETSC_DLLEXPORT PetscMemzero(void *a,size_t n) 1749 { 1750 if (n > 0) { 1751 #if defined(PETSC_USE_DEBUG) 1752 if (!a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer"); 1753 #endif 1754 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1755 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1756 size_t i,len = n/sizeof(PetscScalar); 1757 PetscScalar *x = (PetscScalar*)a; 1758 for (i=0; i<len; i++) x[i] = 0.0; 1759 } else { 1760 #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1761 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1762 PetscInt len = n/sizeof(PetscScalar); 1763 fortranzero_(&len,(PetscScalar*)a); 1764 } else { 1765 #endif 1766 #if defined(PETSC_PREFER_BZERO) 1767 bzero((char *)a,n); 1768 #elif defined (PETSC_HAVE__INTEL_FAST_MEMSET) 1769 _intel_fast_memset((char*)a,0,n); 1770 #else 1771 memset((char*)a,0,n); 1772 #endif 1773 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1774 } 1775 #endif 1776 } 1777 return 0; 1778 } 1779 1780 /* 1781 Allows accessing Matlab Engine 1782 */ 1783 #include "petscmatlab.h" 1784 1785 /* 1786 Determine if some of the kernel computation routines use 1787 Fortran (rather than C) for the numerical calculations. On some machines 1788 and compilers (like complex numbers) the Fortran version of the routines 1789 is faster than the C/C++ versions. The flag --with-fortran-kernels 1790 should be used with config/configure.py to turn these on. 1791 */ 1792 #if defined(PETSC_USE_FORTRAN_KERNELS) 1793 1794 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1795 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1796 #endif 1797 1798 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM) 1799 #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM 1800 #endif 1801 1802 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1803 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1804 #endif 1805 1806 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1807 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1808 #endif 1809 1810 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1811 #define PETSC_USE_FORTRAN_KERNEL_NORM 1812 #endif 1813 1814 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1815 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1816 #endif 1817 1818 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1819 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1820 #endif 1821 1822 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1823 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1824 #endif 1825 1826 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1827 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1828 #endif 1829 1830 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1831 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1832 #endif 1833 1834 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1835 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1836 #endif 1837 1838 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1839 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1840 #endif 1841 1842 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1843 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1844 #endif 1845 1846 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1847 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1848 #endif 1849 1850 #endif 1851 1852 /* 1853 Macros for indicating code that should be compiled with a C interface, 1854 rather than a C++ interface. Any routines that are dynamically loaded 1855 (such as the PCCreate_XXX() routines) must be wrapped so that the name 1856 mangler does not change the functions symbol name. This just hides the 1857 ugly extern "C" {} wrappers. 1858 */ 1859 #if defined(__cplusplus) 1860 #define EXTERN_C_BEGIN extern "C" { 1861 #define EXTERN_C_END } 1862 #else 1863 #define EXTERN_C_BEGIN 1864 #define EXTERN_C_END 1865 #endif 1866 1867 /* --------------------------------------------------------------------*/ 1868 1869 /*MC 1870 size - integer variable used to contain the number of processors in 1871 the relevent MPI_Comm 1872 1873 Level: beginner 1874 1875 .seealso: rank, comm 1876 M*/ 1877 1878 /*MC 1879 rank - integer variable used to contain the number of this processor relative 1880 to all in the relevent MPI_Comm 1881 1882 Level: beginner 1883 1884 .seealso: size, comm 1885 M*/ 1886 1887 /*MC 1888 comm - MPI_Comm used in the current routine or object 1889 1890 Level: beginner 1891 1892 .seealso: size, rank 1893 M*/ 1894 1895 /*MC 1896 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1897 communication 1898 1899 Level: beginner 1900 1901 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1902 1903 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF 1904 M*/ 1905 1906 /*MC 1907 PetscScalar - PETSc type that represents either a double precision real number, a double precision 1908 complex number, a single precision real number, a long double or an int - if the code is configured 1909 with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle 1910 1911 1912 Level: beginner 1913 1914 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt 1915 M*/ 1916 1917 /*MC 1918 PetscReal - PETSc type that represents a real number version of PetscScalar 1919 1920 Level: beginner 1921 1922 .seealso: PetscScalar, PassiveReal, PassiveScalar 1923 M*/ 1924 1925 /*MC 1926 PassiveScalar - PETSc type that represents a PetscScalar 1927 Level: beginner 1928 1929 This is the same as a PetscScalar except in code that is automatically differentiated it is 1930 treated as a constant (not an indendent or dependent variable) 1931 1932 .seealso: PetscReal, PassiveReal, PetscScalar 1933 M*/ 1934 1935 /*MC 1936 PassiveReal - PETSc type that represents a PetscReal 1937 1938 Level: beginner 1939 1940 This is the same as a PetscReal except in code that is automatically differentiated it is 1941 treated as a constant (not an indendent or dependent variable) 1942 1943 .seealso: PetscScalar, PetscReal, PassiveScalar 1944 M*/ 1945 1946 /*MC 1947 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 1948 1949 Level: beginner 1950 1951 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 1952 pass this value 1953 1954 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT 1955 M*/ 1956 1957 #if defined(PETSC_HAVE_MPIIO) 1958 #if !defined(PETSC_WORDS_BIGENDIAN) 1959 extern PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1960 extern PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1961 #else 1962 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e) 1963 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e) 1964 #endif 1965 #endif 1966 1967 /* the following petsc_static_inline require petscerror.h */ 1968 1969 /* Limit MPI to 32-bits */ 1970 #define PETSC_MPI_INT_MAX 2147483647 1971 #define PETSC_MPI_INT_MIN -2147483647 1972 /* Limit BLAS to 32-bits */ 1973 #define PETSC_BLAS_INT_MAX 2147483647 1974 #define PETSC_BLAS_INT_MIN -2147483647 1975 /* On 32 bit systems HDF5 is limited by size of integer, because hsize_t is defined as size_t */ 1976 #define PETSC_HDF5_INT_MAX 2147483647 1977 #define PETSC_HDF5_INT_MIN -2147483647 1978 1979 #if defined(PETSC_USE_64BIT_INDICES) 1980 #define PetscMPIIntCheck(a) if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI") 1981 #define PetscBLASIntCheck(a) if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK") 1982 #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a) 1983 #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a) 1984 1985 #if (PETSC_SIZEOF_SIZE_T == 4) 1986 #define PetscHDF5IntCheck(a) if ((a) > PETSC_HDF5_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for HDF5") 1987 #define PetscHDF5IntCast(a) (a);PetscHDF5IntCheck(a) 1988 #else 1989 #define PetscHDF5IntCheck(a) 1990 #define PetscHDF5IntCast(a) a 1991 #endif 1992 1993 #else 1994 #define PetscMPIIntCheck(a) 1995 #define PetscBLASIntCheck(a) 1996 #define PetscHDF5IntCheck(a) 1997 #define PetscMPIIntCast(a) a 1998 #define PetscBLASIntCast(a) a 1999 #define PetscHDF5IntCast(a) a 2000 #endif 2001 2002 2003 /* 2004 The IBM include files define hz, here we hide it so that it may be used 2005 as a regular user variable. 2006 */ 2007 #if defined(hz) 2008 #undef hz 2009 #endif 2010 2011 /* For arrays that contain filenames or paths */ 2012 2013 2014 #if defined(PETSC_HAVE_LIMITS_H) 2015 #include <limits.h> 2016 #endif 2017 #if defined(PETSC_HAVE_SYS_PARAM_H) 2018 #include <sys/param.h> 2019 #endif 2020 #if defined(PETSC_HAVE_SYS_TYPES_H) 2021 #include <sys/types.h> 2022 #endif 2023 #if defined(MAXPATHLEN) 2024 # define PETSC_MAX_PATH_LEN MAXPATHLEN 2025 #elif defined(MAX_PATH) 2026 # define PETSC_MAX_PATH_LEN MAX_PATH 2027 #elif defined(_MAX_PATH) 2028 # define PETSC_MAX_PATH_LEN _MAX_PATH 2029 #else 2030 # define PETSC_MAX_PATH_LEN 4096 2031 #endif 2032 2033 /* Special support for C++ */ 2034 #include "petsc.hh" 2035 2036 /*MC 2037 2038 UsingFortran - Fortran can be used with PETSc in four distinct approaches 2039 2040 $ 1) classic Fortran 77 style 2041 $#include "petscXXX.h" to work with material from the XXX component of PETSc 2042 $ XXX variablename 2043 $ You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines 2044 $ which end in F90; such as VecGetArrayF90() 2045 $ 2046 $ 2) classic Fortran 90 style 2047 $#include "petscXXX.h" 2048 $#include "petscXXX.h90" to work with material from the XXX component of PETSc 2049 $ XXX variablename 2050 $ 2051 $ 3) Using Fortran modules 2052 $#include "petscXXXdef.h" 2053 $ use petscXXXX 2054 $ XXX variablename 2055 $ 2056 $ 4) Use Fortran modules and Fortran data types for PETSc types 2057 $#include "petscXXXdef.h" 2058 $ use petscXXXX 2059 $ type(XXX) variablename 2060 $ To use this approach you must config/configure.py PETSc with the additional 2061 $ option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules 2062 2063 Finally if you absolutely do not want to use any #include you can use either 2064 2065 $ 3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc 2066 $ and you must declare the variables as integer, for example 2067 $ integer variablename 2068 $ 2069 $ 4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type 2070 $ names like PetscErrorCode, PetscInt etc. again for those you must use integer 2071 2072 We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking 2073 for only a few PETSc functions. 2074 2075 Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value 2076 is expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues() 2077 you cannot have something like 2078 $ PetscInt row,col 2079 $ PetscScalar val 2080 $ ... 2081 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2082 You must instead have 2083 $ PetscInt row(1),col(1) 2084 $ PetscScalar val(1) 2085 $ ... 2086 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2087 2088 2089 See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches 2090 2091 Developer Notes: The finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these 2092 automatically include their predecessors; for example finclude/petscvecdef.h includes finclude/petscisdef.h 2093 2094 The finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include 2095 their finclude/petscXXXdef.h file but DO NOT automatically include their predecessors; for example 2096 finclude/petscvec.h does NOT automatically include finclude/petscis.h 2097 2098 The finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the 2099 Fortran data type type(XXX) (for example type(Vec)) when PETSc is config/configure.py with the --with-fortran-datatypes option. 2100 2101 The finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for 2102 the PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90). 2103 2104 The finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated 2105 automatically by "make allfortranstubs". 2106 2107 The finclude/petscXXX.h90 includes the custom finclude/ftn-custom/petscXXX.h90 and if config/configure.py 2108 was run with --with-fortran-interfaces it also includes the finclude/ftn-auto/petscXXX.h90 These DO NOT automatically 2109 include their predecessors 2110 2111 Level: beginner 2112 2113 M*/ 2114 PETSC_EXTERN_CXX_END 2115 #endif 2116