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