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