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