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