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