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 PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG)) 50 #else 51 #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Development Version %d.%d.%d, Patch %d, ", \ 52 PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \ 53 PETSC_VERSION_PATCH),PetscStrcat(version,PETSC_VERSION_PATCH_DATE), \ 54 PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG)) 55 #endif 56 57 /*MC 58 PetscGetVersion - Gets the PETSc version information in a string. 59 60 Input Parameter: 61 . len - length of the string 62 63 Output Parameter: 64 . version - version string 65 66 Level: developer 67 68 Usage: 69 char version[256]; 70 ierr = PetscGetVersion(version,256);CHKERRQ(ierr) 71 72 Fortran Note: 73 This routine is not supported in Fortran. 74 75 .seealso: PetscGetProgramName() 76 77 M*/ 78 79 /* ========================================================================== */ 80 81 /* 82 Currently cannot check formatting for PETSc print statements because we have our 83 own format %D and %G 84 */ 85 #undef PETSC_PRINTF_FORMAT_CHECK 86 #define PETSC_PRINTF_FORMAT_CHECK(a,b) 87 #undef PETSC_FPRINTF_FORMAT_CHECK 88 #define PETSC_FPRINTF_FORMAT_CHECK(a,b) 89 90 /* 91 Fixes for config/configure.py time choices which impact our interface. Currently only 92 calling conventions and extra compiler checking falls under this category. 93 */ 94 #if !defined(PETSC_STDCALL) 95 #define PETSC_STDCALL 96 #endif 97 #if !defined(PETSC_TEMPLATE) 98 #define PETSC_TEMPLATE 99 #endif 100 #if !defined(PETSC_HAVE_DLL_EXPORT) 101 #define PETSC_DLL_EXPORT 102 #define PETSC_DLL_IMPORT 103 #endif 104 #if !defined(PETSC_DLLEXPORT) 105 #define PETSC_DLLEXPORT 106 #endif 107 #if !defined(PETSCVEC_DLLEXPORT) 108 #define PETSCVEC_DLLEXPORT 109 #endif 110 #if !defined(PETSCMAT_DLLEXPORT) 111 #define PETSCMAT_DLLEXPORT 112 #endif 113 #if !defined(PETSCDM_DLLEXPORT) 114 #define PETSCDM_DLLEXPORT 115 #endif 116 #if !defined(PETSCKSP_DLLEXPORT) 117 #define PETSCKSP_DLLEXPORT 118 #endif 119 #if !defined(PETSCSNES_DLLEXPORT) 120 #define PETSCSNES_DLLEXPORT 121 #endif 122 #if !defined(PETSCTS_DLLEXPORT) 123 #define PETSCTS_DLLEXPORT 124 #endif 125 #if !defined(PETSCFORTRAN_DLLEXPORT) 126 #define PETSCFORTRAN_DLLEXPORT 127 #endif 128 /* ========================================================================== */ 129 130 /* 131 Defines the interface to MPI allowing the use of all MPI functions. 132 133 PETSc does not use the C++ binding of MPI at ALL. The following flag 134 makes sure the C++ bindings are not included. The C++ bindings REQUIRE 135 putting mpi.h before ANY C++ include files, we cannot control this 136 with all PETSc users. 137 */ 138 #define MPICH_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 /* 346 Extern indicates a PETSc function defined elsewhere 347 */ 348 #if !defined(EXTERN) 349 #define EXTERN extern 350 #endif 351 352 /* 353 Defines some elementary mathematics functions and constants. 354 */ 355 #include "petscmath.h" 356 357 /* 358 Declare extern C stuff after including external header files 359 */ 360 361 PETSC_EXTERN_CXX_BEGIN 362 363 /* 364 Basic PETSc constants 365 */ 366 367 /*E 368 PetscTruth - Logical variable. Actually an integer 369 370 Level: beginner 371 372 E*/ 373 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth; 374 extern const char *PetscTruths[]; 375 376 /*MC 377 PETSC_FALSE - False value of PetscTruth 378 379 Level: beginner 380 381 Note: Zero integer 382 383 .seealso: PetscTruth, PETSC_TRUE 384 M*/ 385 386 /*MC 387 PETSC_TRUE - True value of PetscTruth 388 389 Level: beginner 390 391 Note: Nonzero integer 392 393 .seealso: PetscTruth, PETSC_FALSE 394 M*/ 395 396 /*MC 397 PETSC_YES - Alias for PETSC_TRUE 398 399 Level: beginner 400 401 Note: Zero integer 402 403 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO 404 M*/ 405 #define PETSC_YES PETSC_TRUE 406 407 /*MC 408 PETSC_NO - Alias for PETSC_FALSE 409 410 Level: beginner 411 412 Note: Nonzero integer 413 414 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES 415 M*/ 416 #define PETSC_NO PETSC_FALSE 417 418 /*MC 419 PETSC_NULL - standard way of passing in a null or array or pointer 420 421 Level: beginner 422 423 Notes: accepted by many PETSc functions to not set a parameter and instead use 424 some default 425 426 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 427 PETSC_NULL_DOUBLE_PRECISION etc 428 429 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 430 431 M*/ 432 #define PETSC_NULL 0 433 434 /*MC 435 PETSC_DECIDE - standard way of passing in integer or floating point parameter 436 where you wish PETSc to use the default. 437 438 Level: beginner 439 440 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 441 442 M*/ 443 #define PETSC_DECIDE -1 444 445 /*MC 446 PETSC_DEFAULT - standard way of passing in integer or floating point parameter 447 where you wish PETSc to use the default. 448 449 Level: beginner 450 451 Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION. 452 453 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE 454 455 M*/ 456 #define PETSC_DEFAULT -2 457 458 459 /*MC 460 PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument 461 462 Level: beginner 463 464 Note: accepted by many PETSc functions to not set a parameter and instead use 465 some default 466 467 Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 468 PETSC_NULL_DOUBLE_PRECISION etc 469 470 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE 471 472 M*/ 473 #define PETSC_IGNORE PETSC_NULL 474 475 /*MC 476 PETSC_DETERMINE - standard way of passing in integer or floating point parameter 477 where you wish PETSc to compute the required value. 478 479 Level: beginner 480 481 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes() 482 483 M*/ 484 #define PETSC_DETERMINE PETSC_DECIDE 485 486 /*MC 487 PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents 488 all the processs that PETSc knows about. 489 490 Level: beginner 491 492 Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 493 run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller) 494 communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling 495 PetscInitialize() 496 497 .seealso: PETSC_COMM_SELF 498 499 M*/ 500 extern MPI_Comm PETSC_COMM_WORLD; 501 502 /*MC 503 PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents 504 the current process 505 506 Level: beginner 507 508 Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent. 509 510 .seealso: PETSC_COMM_WORLD 511 512 M*/ 513 #define PETSC_COMM_SELF MPI_COMM_SELF 514 515 extern PETSC_DLLEXPORT PetscTruth PetscInitializeCalled; 516 extern PETSC_DLLEXPORT PetscTruth PetscFinalizeCalled; 517 518 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 519 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 520 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDestroy(MPI_Comm*); 521 522 /*MC 523 PetscMalloc - Allocates memory 524 525 Input Parameter: 526 . m - number of bytes to allocate 527 528 Output Parameter: 529 . result - memory allocated 530 531 Synopsis: 532 PetscErrorCode PetscMalloc(size_t m,void **result) 533 534 Level: beginner 535 536 Notes: Memory is always allocated at least double aligned 537 538 If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 539 properly handle not freeing the null pointer. 540 541 .seealso: PetscFree(), PetscNew() 542 543 Concepts: memory allocation 544 545 M*/ 546 #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) ) 547 548 /*MC 549 PetscMalloc2 - Allocates 2 chunks of memory 550 551 Input Parameter: 552 + m1 - number of elements to allocate in 1st chunk (may be zero) 553 . t1 - type of first memory elements 554 . m2 - number of elements to allocate in 2nd chunk (may be zero) 555 - t2 - type of second memory elements 556 557 Output Parameter: 558 + r1 - memory allocated in first chunk 559 - r2 - memory allocated in second chunk 560 561 Synopsis: 562 PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2) 563 564 Level: developer 565 566 Notes: Memory of first chunk is always allocated at least double aligned 567 568 .seealso: PetscFree(), PetscNew(), PetscMalloc() 569 570 Concepts: memory allocation 571 572 M*/ 573 #if defined(PETSC_USE_DEBUG) 574 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2)) 575 #else 576 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0)) 577 #endif 578 579 /*MC 580 PetscMalloc3 - Allocates 3 chunks of memory 581 582 Input Parameter: 583 + m1 - number of elements to allocate in 1st chunk (may be zero) 584 . t1 - type of first memory elements 585 . m2 - number of elements to allocate in 2nd chunk (may be zero) 586 . t2 - type of second memory elements 587 . m3 - number of elements to allocate in 3rd chunk (may be zero) 588 - t3 - type of third memory elements 589 590 Output Parameter: 591 + r1 - memory allocated in first chunk 592 . r2 - memory allocated in second chunk 593 - r3 - memory allocated in third chunk 594 595 Synopsis: 596 PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3) 597 598 Level: developer 599 600 Notes: Memory of first chunk is always allocated at least double aligned 601 602 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3() 603 604 Concepts: memory allocation 605 606 M*/ 607 #if defined(PETSC_USE_DEBUG) 608 #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)) 609 #else 610 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),0)) 611 #endif 612 613 /*MC 614 PetscMalloc4 - Allocates 4 chunks of memory 615 616 Input Parameter: 617 + m1 - number of elements to allocate in 1st chunk (may be zero) 618 . t1 - type of first memory elements 619 . m2 - number of elements to allocate in 2nd chunk (may be zero) 620 . t2 - type of second memory elements 621 . m3 - number of elements to allocate in 3rd chunk (may be zero) 622 . t3 - type of third memory elements 623 . m4 - number of elements to allocate in 4th chunk (may be zero) 624 - t4 - type of fourth memory elements 625 626 Output Parameter: 627 + r1 - memory allocated in first chunk 628 . r2 - memory allocated in second chunk 629 . r3 - memory allocated in third chunk 630 - r4 - memory allocated in fourth chunk 631 632 Synopsis: 633 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) 634 635 Level: developer 636 637 Notes: Memory of first chunk is always allocated at least double aligned 638 639 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4() 640 641 Concepts: memory allocation 642 643 M*/ 644 #if defined(PETSC_USE_DEBUG) 645 #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)) 646 #else 647 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),0)) 648 #endif 649 650 /*MC 651 PetscMalloc5 - Allocates 5 chunks of memory 652 653 Input Parameter: 654 + m1 - number of elements to allocate in 1st chunk (may be zero) 655 . t1 - type of first memory elements 656 . m2 - number of elements to allocate in 2nd chunk (may be zero) 657 . t2 - type of second memory elements 658 . m3 - number of elements to allocate in 3rd chunk (may be zero) 659 . t3 - type of third memory elements 660 . m4 - number of elements to allocate in 4th chunk (may be zero) 661 . t4 - type of fourth memory elements 662 . m5 - number of elements to allocate in 5th chunk (may be zero) 663 - t5 - type of fifth memory elements 664 665 Output Parameter: 666 + r1 - memory allocated in first chunk 667 . r2 - memory allocated in second chunk 668 . r3 - memory allocated in third chunk 669 . r4 - memory allocated in fourth chunk 670 - r5 - memory allocated in fifth chunk 671 672 Synopsis: 673 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) 674 675 Level: developer 676 677 Notes: Memory of first chunk is always allocated at least double aligned 678 679 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5() 680 681 Concepts: memory allocation 682 683 M*/ 684 #if defined(PETSC_USE_DEBUG) 685 #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)) 686 #else 687 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),0)) 688 #endif 689 690 691 /*MC 692 PetscMalloc6 - Allocates 6 chunks of memory 693 694 Input Parameter: 695 + m1 - number of elements to allocate in 1st chunk (may be zero) 696 . t1 - type of first memory elements 697 . m2 - number of elements to allocate in 2nd chunk (may be zero) 698 . t2 - type of second memory elements 699 . m3 - number of elements to allocate in 3rd chunk (may be zero) 700 . t3 - type of third memory elements 701 . m4 - number of elements to allocate in 4th chunk (may be zero) 702 . t4 - type of fourth memory elements 703 . m5 - number of elements to allocate in 5th chunk (may be zero) 704 . t5 - type of fifth memory elements 705 . m6 - number of elements to allocate in 6th chunk (may be zero) 706 - t6 - type of sixth memory elements 707 708 Output Parameter: 709 + r1 - memory allocated in first chunk 710 . r2 - memory allocated in second chunk 711 . r3 - memory allocated in third chunk 712 . r4 - memory allocated in fourth chunk 713 . r5 - memory allocated in fifth chunk 714 - r6 - memory allocated in sixth chunk 715 716 Synopsis: 717 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) 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(), PetscFree5(), PetscFree6() 724 725 Concepts: memory allocation 726 727 M*/ 728 #if defined(PETSC_USE_DEBUG) 729 #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)) 730 #else 731 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),0)) 732 #endif 733 734 /*MC 735 PetscMalloc7 - Allocates 7 chunks of memory 736 737 Input Parameter: 738 + m1 - number of elements to allocate in 1st chunk (may be zero) 739 . t1 - type of first memory elements 740 . m2 - number of elements to allocate in 2nd chunk (may be zero) 741 . t2 - type of second memory elements 742 . m3 - number of elements to allocate in 3rd chunk (may be zero) 743 . t3 - type of third memory elements 744 . m4 - number of elements to allocate in 4th chunk (may be zero) 745 . t4 - type of fourth memory elements 746 . m5 - number of elements to allocate in 5th chunk (may be zero) 747 . t5 - type of fifth memory elements 748 . m6 - number of elements to allocate in 6th chunk (may be zero) 749 . t6 - type of sixth memory elements 750 . m7 - number of elements to allocate in 7th chunk (may be zero) 751 - t7 - type of sixth memory elements 752 753 Output Parameter: 754 + r1 - memory allocated in first chunk 755 . r2 - memory allocated in second chunk 756 . r3 - memory allocated in third chunk 757 . r4 - memory allocated in fourth chunk 758 . r5 - memory allocated in fifth chunk 759 . r6 - memory allocated in sixth chunk 760 - r7 - memory allocated in sixth chunk 761 762 Synopsis: 763 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) 764 765 Level: developer 766 767 Notes: Memory of first chunk is always allocated at least double aligned 768 769 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7() 770 771 Concepts: memory allocation 772 773 M*/ 774 #if defined(PETSC_USE_DEBUG) 775 #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)) 776 #else 777 #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)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),*(r7) = (t7*)(*(r6)+m6),0)) 778 #endif 779 780 /*MC 781 PetscNew - Allocates memory of a particular type, zeros the memory! 782 783 Input Parameter: 784 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 785 786 Output Parameter: 787 . result - memory allocated 788 789 Synopsis: 790 PetscErrorCode PetscNew(struct type,((type *))result) 791 792 Level: beginner 793 794 .seealso: PetscFree(), PetscMalloc() 795 796 Concepts: memory allocation 797 798 M*/ 799 #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A))) 800 #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0)) 801 802 /*MC 803 PetscFree - Frees memory 804 805 Input Parameter: 806 . memory - memory to free (the pointer is ALWAYS set to 0 upon sucess) 807 808 Synopsis: 809 PetscErrorCode PetscFree(void *memory) 810 811 Level: beginner 812 813 Notes: Memory must have been obtained with PetscNew() or PetscMalloc() 814 815 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid() 816 817 Concepts: memory allocation 818 819 M*/ 820 #define PetscFree(a) ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0) 821 822 /*MC 823 PetscFreeVoid - Frees memory 824 825 Input Parameter: 826 . memory - memory to free 827 828 Synopsis: 829 void PetscFreeVoid(void *memory) 830 831 Level: beginner 832 833 Notes: This is different from PetscFree() in that no error code is returned 834 835 .seealso: PetscFree(), PetscNew(), PetscMalloc() 836 837 Concepts: memory allocation 838 839 M*/ 840 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0) 841 842 843 /*MC 844 PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 845 846 Input Parameter: 847 + memory1 - memory to free 848 - memory2 - 2nd memory to free 849 850 851 Synopsis: 852 PetscErrorCode PetscFree2(void *memory1,void *memory2) 853 854 Level: developer 855 856 Notes: Memory must have been obtained with PetscMalloc2() 857 858 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree() 859 860 Concepts: memory allocation 861 862 M*/ 863 #if defined(PETSC_USE_DEBUG) 864 #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1)) 865 #else 866 #define PetscFree2(m1,m2) (PetscFree(m1)) 867 #endif 868 869 /*MC 870 PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 871 872 Input Parameter: 873 + memory1 - memory to free 874 . memory2 - 2nd memory to free 875 - memory3 - 3rd memory to free 876 877 878 Synopsis: 879 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 880 881 Level: developer 882 883 Notes: Memory must have been obtained with PetscMalloc3() 884 885 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3() 886 887 Concepts: memory allocation 888 889 M*/ 890 #if defined(PETSC_USE_DEBUG) 891 #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 892 #else 893 #define PetscFree3(m1,m2,m3) (PetscFree(m1)) 894 #endif 895 896 /*MC 897 PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 898 899 Input Parameter: 900 + m1 - memory to free 901 . m2 - 2nd memory to free 902 . m3 - 3rd memory to free 903 - m4 - 4th memory to free 904 905 906 Synopsis: 907 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 908 909 Level: developer 910 911 Notes: Memory must have been obtained with PetscMalloc4() 912 913 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4() 914 915 Concepts: memory allocation 916 917 M*/ 918 #if defined(PETSC_USE_DEBUG) 919 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 920 #else 921 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1)) 922 #endif 923 924 /*MC 925 PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 926 927 Input Parameter: 928 + m1 - memory to free 929 . m2 - 2nd memory to free 930 . m3 - 3rd memory to free 931 . m4 - 4th memory to free 932 - m5 - 5th memory to free 933 934 935 Synopsis: 936 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 937 938 Level: developer 939 940 Notes: Memory must have been obtained with PetscMalloc5() 941 942 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5() 943 944 Concepts: memory allocation 945 946 M*/ 947 #if defined(PETSC_USE_DEBUG) 948 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 949 #else 950 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1)) 951 #endif 952 953 954 /*MC 955 PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 956 957 Input Parameter: 958 + m1 - memory to free 959 . m2 - 2nd memory to free 960 . m3 - 3rd memory to free 961 . m4 - 4th memory to free 962 . m5 - 5th memory to free 963 - m6 - 6th memory to free 964 965 966 Synopsis: 967 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 968 969 Level: developer 970 971 Notes: Memory must have been obtained with PetscMalloc6() 972 973 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6() 974 975 Concepts: memory allocation 976 977 M*/ 978 #if defined(PETSC_USE_DEBUG) 979 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 980 #else 981 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1)) 982 #endif 983 984 /*MC 985 PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7() 986 987 Input Parameter: 988 + m1 - memory to free 989 . m2 - 2nd memory to free 990 . m3 - 3rd memory to free 991 . m4 - 4th memory to free 992 . m5 - 5th memory to free 993 . m6 - 6th memory to free 994 - m7 - 7th memory to free 995 996 997 Synopsis: 998 PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 999 1000 Level: developer 1001 1002 Notes: Memory must have been obtained with PetscMalloc7() 1003 1004 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(), 1005 PetscMalloc7() 1006 1007 Concepts: memory allocation 1008 1009 M*/ 1010 #if defined(PETSC_USE_DEBUG) 1011 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1012 #else 1013 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m1)) 1014 #endif 1015 1016 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**); 1017 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]); 1018 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[])); 1019 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocClear(void); 1020 1021 /* 1022 Routines for tracing memory corruption/bleeding with default PETSc 1023 memory allocation 1024 */ 1025 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDump(FILE *); 1026 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDumpLog(FILE *); 1027 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetCurrentUsage(PetscLogDouble *); 1028 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetMaximumUsage(PetscLogDouble *); 1029 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDebug(PetscTruth); 1030 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocValidate(int,const char[],const char[],const char[]); 1031 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocSetDumpLog(void); 1032 1033 1034 /* 1035 Variable type where we stash PETSc object pointers in Fortran. 1036 On most machines size(pointer) == sizeof(long) - except windows 1037 where its sizeof(long long) 1038 */ 1039 1040 #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG) 1041 #define PetscFortranAddr long 1042 #elif (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG) 1043 #define PetscFortranAddr long long 1044 #else 1045 #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov" 1046 #endif 1047 1048 /*E 1049 PetscDataType - Used for handling different basic data types. 1050 1051 Level: beginner 1052 1053 Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not? 1054 1055 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(), 1056 PetscDataTypeGetSize() 1057 1058 E*/ 1059 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5, 1060 PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType; 1061 extern const char *PetscDataTypes[]; 1062 1063 #if defined(PETSC_USE_COMPLEX) 1064 #define PETSC_SCALAR PETSC_COMPLEX 1065 #else 1066 #if defined(PETSC_USE_SINGLE) 1067 #define PETSC_SCALAR PETSC_FLOAT 1068 #elif defined(PETSC_USE_LONG_DOUBLE) 1069 #define PETSC_SCALAR PETSC_LONG_DOUBLE 1070 #elif defined(PETSC_USE_INT) 1071 #define PETSC_SCALAR PETSC_INT 1072 #else 1073 #define PETSC_SCALAR PETSC_DOUBLE 1074 #endif 1075 #endif 1076 #if defined(PETSC_USE_SINGLE) 1077 #define PETSC_REAL PETSC_FLOAT 1078 #elif defined(PETSC_USE_LONG_DOUBLE) 1079 #define PETSC_REAL PETSC_LONG_DOUBLE 1080 #elif defined(PETSC_USE_INT) 1081 #define PETSC_REAL PETSC_INT 1082 #else 1083 #define PETSC_REAL PETSC_DOUBLE 1084 #endif 1085 #define PETSC_FORTRANADDR PETSC_LONG 1086 1087 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 1088 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*); 1089 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,size_t*); 1090 1091 /* 1092 Basic memory and string operations. These are usually simple wrappers 1093 around the basic Unix system calls, but a few of them have additional 1094 functionality and/or error checking. 1095 */ 1096 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemcpy(void*,const void *,size_t); 1097 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType); 1098 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemmove(void*,void *,size_t); 1099 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemzero(void*,size_t); 1100 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemcmp(const void*,const void*,size_t,PetscTruth *); 1101 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrlen(const char[],size_t*); 1102 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcmp(const char[],const char[],PetscTruth *); 1103 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrgrt(const char[],const char[],PetscTruth *); 1104 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcasecmp(const char[],const char[],PetscTruth*); 1105 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncmp(const char[],const char[],size_t,PetscTruth*); 1106 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcpy(char[],const char[]); 1107 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcat(char[],const char[]); 1108 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncat(char[],const char[],size_t); 1109 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncpy(char[],const char[],size_t); 1110 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrchr(const char[],char,char *[]); 1111 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrtolower(char[]); 1112 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrrchr(const char[],char,char *[]); 1113 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrstr(const char[],const char[],char *[]); 1114 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrrstr(const char[],const char[],char *[]); 1115 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrallocpy(const char[],char *[]); 1116 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrreplace(MPI_Comm,const char[],char[],size_t); 1117 #define PetscStrfree(a) ((a) ? PetscFree(a) : 0) 1118 1119 /*S 1120 PetscToken - 'Token' used for managing tokenizing strings 1121 1122 Level: intermediate 1123 1124 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy() 1125 S*/ 1126 typedef struct _p_PetscToken* PetscToken; 1127 1128 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenCreate(const char[],const char,PetscToken*); 1129 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenFind(PetscToken,char *[]); 1130 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenDestroy(PetscToken); 1131 1132 /* 1133 These are MPI operations for MPI_Allreduce() etc 1134 */ 1135 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op; 1136 #if defined(PETSC_USE_COMPLEX) 1137 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op; 1138 #else 1139 #define PetscSum_Op MPI_SUM 1140 #endif 1141 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 1142 1143 /*S 1144 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 1145 1146 Level: beginner 1147 1148 Note: This is the base class from which all objects appear. 1149 1150 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName() 1151 S*/ 1152 typedef struct _p_PetscObject* PetscObject; 1153 1154 /*S 1155 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 1156 by string name 1157 1158 Level: advanced 1159 1160 .seealso: PetscFListAdd(), PetscFListDestroy() 1161 S*/ 1162 typedef struct _n_PetscFList *PetscFList; 1163 1164 /*E 1165 PetscFileMode - Access mode for a file. 1166 1167 Level: beginner 1168 1169 FILE_MODE_READ - open a file at its beginning for reading 1170 1171 FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist) 1172 1173 FILE_MODE_APPEND - open a file at end for writing 1174 1175 FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing 1176 1177 FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end 1178 1179 .seealso: PetscViewerFileSetMode() 1180 E*/ 1181 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode; 1182 1183 #include "petscviewer.h" 1184 #include "petscoptions.h" 1185 1186 #define PETSC_SMALLEST_COOKIE 1211211 1187 extern PETSC_DLLEXPORT PetscCookie PETSC_LARGEST_COOKIE; 1188 extern PETSC_DLLEXPORT PetscCookie PETSC_OBJECT_COOKIE; 1189 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCookieRegister(const char[],PetscCookie *); 1190 1191 /* 1192 Routines that get memory usage information from the OS 1193 */ 1194 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *); 1195 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *); 1196 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void); 1197 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]); 1198 1199 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoAllow(PetscTruth,const char []); 1200 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*); 1201 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*); 1202 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int); 1203 1204 /* 1205 Initialization of PETSc 1206 */ 1207 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]); 1208 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL)) 1209 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void); 1210 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *); 1211 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *); 1212 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void); 1213 EXTERN PetscErrorCode PetscInitializeFortran(void); 1214 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***); 1215 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArguments(char ***); 1216 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFreeArguments(char **); 1217 1218 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void); 1219 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(const char[]); 1220 1221 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPMerge(PetscMPIInt); 1222 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPSpawn(PetscMPIInt); 1223 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFinalize(void); 1224 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*); 1225 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFree(MPI_Comm,void*); 1226 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPNew(MPI_Comm,PetscInt,void**); 1227 1228 /* 1229 These are so that in extern C code we can caste function pointers to non-extern C 1230 function pointers. Since the regular C++ code expects its function pointers to be 1231 C++. 1232 */ 1233 typedef void (**PetscVoidStarFunction)(void); 1234 typedef void (*PetscVoidFunction)(void); 1235 typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1236 1237 /* 1238 PetscTryMethod - Queries an object for a method, if it exists then calls it. 1239 These are intended to be used only inside PETSc functions. 1240 */ 1241 #define PetscTryMethod(obj,A,B,C) \ 1242 0;{ PetscErrorCode (*f)B, __ierr; \ 1243 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1244 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1245 } 1246 #define PetscUseMethod(obj,A,B,C) \ 1247 0;{ PetscErrorCode (*f)B, __ierr; \ 1248 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1249 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1250 else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \ 1251 } 1252 /* 1253 Functions that can act on any PETSc object. 1254 */ 1255 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreate(MPI_Comm,PetscObject*); 1256 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *); 1257 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject); 1258 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*); 1259 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *); 1260 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,PetscCookie *); 1261 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetType(PetscObject,const char []); 1262 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,const char *[]); 1263 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]); 1264 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,const char*[]); 1265 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject); 1266 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*); 1267 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject); 1268 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *); 1269 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer); 1270 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject); 1271 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *); 1272 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 1273 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetFromOptions(PetscObject); 1274 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetUp(PetscObject); 1275 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *); 1276 1277 /*MC 1278 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 1279 1280 Collective on PetscObject 1281 1282 Input Parameters: 1283 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 1284 PetscObjectCompose((PetscObject)mat,...); 1285 . name - name associated with the child function 1286 . fname - name of the function 1287 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 1288 1289 Level: advanced 1290 1291 Synopsis: 1292 PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 1293 1294 Notes: 1295 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 1296 1297 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 1298 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 1299 1300 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 1301 work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic) 1302 enabled. 1303 1304 Concepts: objects^composing functions 1305 Concepts: composing functions 1306 Concepts: functions^querying 1307 Concepts: objects^querying 1308 Concepts: querying objects 1309 1310 .seealso: PetscObjectQueryFunction() 1311 M*/ 1312 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1313 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 1314 #else 1315 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d)) 1316 #endif 1317 1318 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 1319 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1320 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1321 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1322 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,const char*[]); 1323 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject); 1324 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]); 1325 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject); 1326 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void); 1327 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject); 1328 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*); 1329 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalize(PetscErrorCode (*)(void)); 1330 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalizeAll(void); 1331 1332 /* 1333 Defines PETSc error handling. 1334 */ 1335 #include "petscerror.h" 1336 1337 /*S 1338 PetscOList - Linked list of PETSc objects, accessable by string name 1339 1340 Level: advanced 1341 1342 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind() 1343 S*/ 1344 typedef struct _n_PetscOList *PetscOList; 1345 1346 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList); 1347 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*); 1348 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**); 1349 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject); 1350 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *); 1351 1352 /* 1353 Dynamic library lists. Lists of names of routines in dynamic 1354 link libraries that will be loaded as needed. 1355 */ 1356 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 1357 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*); 1358 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void)); 1359 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(PetscFList,MPI_Comm,FILE*,const char[],const char[],const char[],const char[]); 1360 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1361 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 1362 #else 1363 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 1364 #endif 1365 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *); 1366 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer); 1367 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []); 1368 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*); 1369 1370 /*S 1371 PetscDLLibrary - Linked list of dynamics libraries to search for functions 1372 1373 Level: advanced 1374 1375 --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries 1376 1377 .seealso: PetscDLLibraryOpen() 1378 S*/ 1379 typedef struct _n_PetscDLLibrary *PetscDLLibrary; 1380 extern PetscDLLibrary DLLibrariesLoaded; 1381 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *); 1382 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **); 1383 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **); 1384 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1385 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]); 1386 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibrary); 1387 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void); 1388 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]); 1389 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1390 1391 /* 1392 Useful utility routines 1393 */ 1394 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1395 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1396 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1397 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1)) 1398 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1)) 1399 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1400 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1)) 1401 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1)) 1402 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject); 1403 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*); 1404 1405 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1406 /* 1407 Defines basic graphics available from PETSc. 1408 */ 1409 #include "petscdraw.h" 1410 1411 /* 1412 Defines the base data structures for all PETSc objects 1413 */ 1414 #include "private/petscimpl.h" 1415 /* 1416 Defines PETSc profiling. 1417 */ 1418 #include "petsclog.h" 1419 1420 /* 1421 For locking, unlocking and destroying AMS memories associated with 1422 PETSc objects. Not currently used. 1423 */ 1424 #define PetscPublishAll(v) 0 1425 #define PetscObjectTakeAccess(obj) 0 1426 #define PetscObjectGrantAccess(obj) 0 1427 #define PetscObjectDepublish(obj) 0 1428 1429 /* 1430 Simple PETSc parallel IO for ASCII printing 1431 */ 1432 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFixFilename(const char[],char[]); 1433 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1434 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFClose(MPI_Comm,FILE*); 1435 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1436 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1437 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSNPrintf(char*,size_t,const char [],...); 1438 1439 /* These are used internally by PETSc ASCII IO routines*/ 1440 #include <stdarg.h> 1441 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVSNPrintf(char*,size_t,const char[],int*,va_list); 1442 EXTERN PetscErrorCode PETSC_DLLEXPORT (*PetscVFPrintf)(FILE*,const char[],va_list); 1443 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVFPrintfDefault(FILE*,const char[],va_list); 1444 1445 /*MC 1446 PetscErrorPrintf - Prints error messages. 1447 1448 Not Collective 1449 1450 Synopsis: 1451 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1452 1453 Input Parameters: 1454 . format - the usual printf() format string 1455 1456 Options Database Keys: 1457 + -error_output_stdout - cause error messages to be printed to stdout instead of the 1458 (default) stderr 1459 - -error_output_none to turn off all printing of error messages (does not change the way the 1460 error is handled.) 1461 1462 Notes: Use 1463 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 1464 $ error is handled.) and 1465 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on 1466 1467 Use 1468 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 1469 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 1470 1471 Use 1472 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 1473 1474 Level: developer 1475 1476 Fortran Note: 1477 This routine is not supported in Fortran. 1478 1479 Concepts: error messages^printing 1480 Concepts: printing^error messages 1481 1482 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush() 1483 M*/ 1484 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...); 1485 1486 /*MC 1487 PetscHelpPrintf - Prints help messages. 1488 1489 Not Collective 1490 1491 Synopsis: 1492 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1493 1494 Input Parameters: 1495 . format - the usual printf() format string 1496 1497 Level: developer 1498 1499 Fortran Note: 1500 This routine is not supported in Fortran. 1501 1502 Concepts: help messages^printing 1503 Concepts: printing^help messages 1504 1505 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1506 M*/ 1507 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1508 1509 EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...); 1510 EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...); 1511 EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...); 1512 1513 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1514 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPClose(MPI_Comm,FILE*); 1515 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1516 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1517 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFlush(MPI_Comm); 1518 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1519 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1520 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1521 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetPetscDir(const char*[]); 1522 1523 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*); 1524 1525 /*S 1526 PetscContainer - Simple PETSc object that contains a pointer to any required data 1527 1528 Level: advanced 1529 1530 .seealso: PetscObject, PetscContainerCreate() 1531 S*/ 1532 extern PetscCookie PETSC_DLLEXPORT PETSC_CONTAINER_COOKIE; 1533 typedef struct _p_PetscContainer* PetscContainer; 1534 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerGetPointer(PetscContainer,void **); 1535 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetPointer(PetscContainer,void *); 1536 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerDestroy(PetscContainer); 1537 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerCreate(MPI_Comm,PetscContainer *); 1538 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*)); 1539 1540 /* 1541 For use in debuggers 1542 */ 1543 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank; 1544 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize; 1545 1546 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer); 1547 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer); 1548 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer); 1549 1550 /* 1551 Allows accessing Matlab Engine 1552 */ 1553 #include "petscmatlab.h" 1554 1555 /* 1556 Determine if some of the kernel computation routines use 1557 Fortran (rather than C) for the numerical calculations. On some machines 1558 and compilers (like complex numbers) the Fortran version of the routines 1559 is faster than the C/C++ versions. The flag --with-fortran-kernels 1560 should be used with config/configure.py to turn these on. 1561 */ 1562 #if defined(PETSC_USE_FORTRAN_KERNELS) 1563 1564 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1565 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1566 #endif 1567 1568 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM) 1569 #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM 1570 #endif 1571 1572 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1573 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1574 #endif 1575 1576 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1577 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1578 #endif 1579 1580 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1581 #define PETSC_USE_FORTRAN_KERNEL_NORM 1582 #endif 1583 1584 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1585 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1586 #endif 1587 1588 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1589 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1590 #endif 1591 1592 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1593 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1594 #endif 1595 1596 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1597 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1598 #endif 1599 1600 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1601 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1602 #endif 1603 1604 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1605 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1606 #endif 1607 1608 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1609 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1610 #endif 1611 1612 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1613 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1614 #endif 1615 1616 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1617 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1618 #endif 1619 1620 #endif 1621 1622 /* 1623 Macros for indicating code that should be compiled with a C interface, 1624 rather than a C++ interface. Any routines that are dynamically loaded 1625 (such as the PCCreate_XXX() routines) must be wrapped so that the name 1626 mangler does not change the functions symbol name. This just hides the 1627 ugly extern "C" {} wrappers. 1628 */ 1629 #if defined(__cplusplus) 1630 #define EXTERN_C_BEGIN extern "C" { 1631 #define EXTERN_C_END } 1632 #else 1633 #define EXTERN_C_BEGIN 1634 #define EXTERN_C_END 1635 #endif 1636 1637 /* --------------------------------------------------------------------*/ 1638 1639 /*MC 1640 size - integer variable used to contain the number of processors in 1641 the relevent MPI_Comm 1642 1643 Level: beginner 1644 1645 .seealso: rank, comm 1646 M*/ 1647 1648 /*MC 1649 rank - integer variable used to contain the number of this processor relative 1650 to all in the relevent MPI_Comm 1651 1652 Level: beginner 1653 1654 .seealso: size, comm 1655 M*/ 1656 1657 /*MC 1658 comm - MPI_Comm used in the current routine or object 1659 1660 Level: beginner 1661 1662 .seealso: size, rank 1663 M*/ 1664 1665 /*MC 1666 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1667 communication 1668 1669 Level: beginner 1670 1671 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1672 1673 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF 1674 M*/ 1675 1676 /*MC 1677 PetscScalar - PETSc type that represents either a double precision real number, a double precision 1678 complex number, a single precision real number, a long double or an int - if the code is configured 1679 with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle 1680 1681 1682 Level: beginner 1683 1684 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt 1685 M*/ 1686 1687 /*MC 1688 PetscReal - PETSc type that represents a real number version of PetscScalar 1689 1690 Level: beginner 1691 1692 .seealso: PetscScalar, PassiveReal, PassiveScalar 1693 M*/ 1694 1695 /*MC 1696 PassiveScalar - PETSc type that represents a PetscScalar 1697 Level: beginner 1698 1699 This is the same as a PetscScalar except in code that is automatically differentiated it is 1700 treated as a constant (not an indendent or dependent variable) 1701 1702 .seealso: PetscReal, PassiveReal, PetscScalar 1703 M*/ 1704 1705 /*MC 1706 PassiveReal - PETSc type that represents a PetscReal 1707 1708 Level: beginner 1709 1710 This is the same as a PetscReal except in code that is automatically differentiated it is 1711 treated as a constant (not an indendent or dependent variable) 1712 1713 .seealso: PetscScalar, PetscReal, PassiveScalar 1714 M*/ 1715 1716 /*MC 1717 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 1718 1719 Level: beginner 1720 1721 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 1722 pass this value 1723 1724 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT 1725 M*/ 1726 1727 #if defined(PETSC_HAVE_MPIIO) 1728 #if !defined(PETSC_WORDS_BIGENDIAN) 1729 extern PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1730 extern PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 1731 #else 1732 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e) 1733 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e) 1734 #endif 1735 #endif 1736 1737 /* the following petsc_static_inline require petscerror.h */ 1738 1739 #if defined(PETSC_USE_64BIT_INDICES) 1740 #define PETSC_MPI_INT_MAX 2147483647 1741 #define PETSC_BLAS_INT_MAX 2147483647 1742 #define PetscMPIIntCheck(a) if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI") 1743 #define PetscBLASIntCheck(a) if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK") 1744 #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a) 1745 #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a) 1746 #else 1747 #define PetscMPIIntCheck(a) 1748 #define PetscBLASIntCheck(a) 1749 #define PetscMPIIntCast(a) a 1750 #define PetscBLASIntCast(a) a 1751 #endif 1752 1753 1754 /* 1755 The IBM include files define hz, here we hide it so that it may be used 1756 as a regular user variable. 1757 */ 1758 #if defined(hz) 1759 #undef hz 1760 #endif 1761 1762 /* For arrays that contain filenames or paths */ 1763 1764 1765 #if defined(PETSC_HAVE_LIMITS_H) 1766 #include <limits.h> 1767 #endif 1768 #if defined(PETSC_HAVE_SYS_PARAM_H) 1769 #include <sys/param.h> 1770 #endif 1771 #if defined(PETSC_HAVE_SYS_TYPES_H) 1772 #include <sys/types.h> 1773 #endif 1774 #if defined(MAXPATHLEN) 1775 # define PETSC_MAX_PATH_LEN MAXPATHLEN 1776 #elif defined(MAX_PATH) 1777 # define PETSC_MAX_PATH_LEN MAX_PATH 1778 #elif defined(_MAX_PATH) 1779 # define PETSC_MAX_PATH_LEN _MAX_PATH 1780 #else 1781 # define PETSC_MAX_PATH_LEN 4096 1782 #endif 1783 1784 /* Special support for C++ */ 1785 #include "petsc.hh" 1786 1787 /*MC 1788 1789 FortranModules - it is possible to use PETSc from Fortran using Fortran 90 modules instead of C style include macros. 1790 1791 $ Objects are named type(XXXX) instead of XXXX, for example 1792 $ use petscvec 1793 $ type(Vec) v instead of 1794 $ 1795 $#include "finclude/petsc.h" 1796 $#include "finclude/petscvec.h" 1797 $ Vec v 1798 1799 The PETSc macros, PetscInt, PetscErrorCode etc are not available, you should use integer for these 1800 1801 See the example src/vec/vec/examples/tutorials/ex20f90.F90 1802 1803 Level: beginner 1804 1805 M*/ 1806 PETSC_EXTERN_CXX_END 1807 #endif 1808