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 This facilitates using C version of PETSc from C++ 10 */ 11 12 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 13 #define PETSC_EXTERN_CXX_BEGIN extern "C" { 14 #define PETSC_EXTERN_CXX_END } 15 #else 16 #define PETSC_EXTERN_CXX_BEGIN 17 #define PETSC_EXTERN_CXX_END 18 #endif 19 /* ========================================================================== */ 20 /* 21 Current PETSc version number and release date 22 */ 23 #include "petscversion.h" 24 25 /* ========================================================================== */ 26 /* 27 petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is 28 found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH} 29 in the bmake/common_variables definition of PETSC_INCLUDE 30 */ 31 #include "petscconf.h" 32 33 /* 34 Currently cannot check formatting for PETSc print statements because we have our 35 own format %D 36 */ 37 #undef PETSC_PRINTF_FORMAT_CHECK 38 #define PETSC_PRINTF_FORMAT_CHECK(a,b) 39 #undef PETSC_FPRINTF_FORMAT_CHECK 40 #define PETSC_FPRINTF_FORMAT_CHECK(a,b) 41 42 /* 43 Fixes for configure time choices which impact our interface. Currently only 44 calling conventions and extra compiler checking falls under this category. 45 */ 46 #if !defined (PETSC_STDCALL) 47 #define PETSC_STDCALL 48 #endif 49 #if !defined (PETSC_TEMPLATE) 50 #define PETSC_TEMPLATE 51 #endif 52 53 /* ========================================================================== */ 54 55 /* 56 Defines the interface to MPI allowing the use of all MPI functions. 57 */ 58 #include "mpi.h" 59 /* 60 Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 61 see the top of mpicxx.h 62 63 The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense. 64 */ 65 #include <stdio.h> 66 67 /* 68 All PETSc C functions return this error code, it is the final argument of 69 all Fortran subroutines 70 */ 71 typedef int PetscErrorCode; 72 typedef int PetscCookie; 73 typedef int PetscEvent; 74 typedef int PetscBLASInt; 75 typedef int PetscMPIInt; 76 77 #if defined(PETSC_USE_64BIT_INT) 78 typedef long long PetscInt; 79 #define MPIU_INT MPI_LONG_LONG_INT 80 #else 81 typedef int PetscInt; 82 #define MPIU_INT MPI_INT 83 #endif 84 85 /* 86 Allows defining simple C++ polymorphic functions that remove certain 87 optional arguments for a simplier user interface. Also allows returning 88 an out argument instead of returning the error code. Eventually we should 89 check the error code and generate an exception. 90 */ 91 #if defined(__cplusplus) 92 #define PetscPolymorphicSubroutine(A,B,C) inline PetscErrorCode A B {return A C;} 93 #define PetscPolymorphicFunction(A,B,C,D,E) inline D A B {D E; A C;return E;} 94 #else 95 #define PetscPolymorphicSubroutine(A,B,C) 96 #define PetscPolymorphicFunction(A,B,C,D,E) 97 #endif 98 99 /* 100 Declare extern C stuff after incuding external header files 101 */ 102 103 PETSC_EXTERN_CXX_BEGIN 104 105 /* 106 EXTERN indicates a PETSc function defined elsewhere 107 */ 108 #if !defined(EXTERN) 109 #define EXTERN extern 110 #endif 111 112 /* 113 Defines some elementary mathematics functions and constants. 114 */ 115 #include "petscmath.h" 116 117 /* 118 Basic PETSc constants 119 */ 120 121 /*E 122 PetscTruth - Logical variable. Actually an integer 123 124 Level: beginner 125 126 E*/ 127 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth; 128 129 /*M 130 PETSC_FALSE - False value of PetscTruth 131 132 Level: beginner 133 134 Note: Zero integer 135 136 .seealso: PetscTruth 137 M*/ 138 139 /*M 140 PETSC_TRUE - True value of PetscTruth 141 142 Level: beginner 143 144 Note: Nonzero integer 145 146 .seealso: PetscTruth 147 M*/ 148 149 /*M 150 PETSC_YES - Alias for PETSC_TRUE 151 152 Level: beginner 153 154 Note: Zero integer 155 156 .seealso: PetscTruth 157 M*/ 158 159 /*M 160 PETSC_NO - Alias for PETSC_FALSE 161 162 Level: beginner 163 164 Note: Nonzero integer 165 166 .seealso: PetscTruth 167 M*/ 168 169 /*M 170 PETSC_NULL - standard way of passing in a null or array or pointer 171 172 Level: beginner 173 174 Notes: accepted by many PETSc functions to not set a parameter and instead use 175 some default 176 177 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 178 PETSC_NULL_DOUBLE_PRECISION etc 179 180 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 181 182 M*/ 183 #define PETSC_NULL 0 184 185 /*M 186 PETSC_DECIDE - standard way of passing in integer or floating point parameter 187 where you wish PETSc to use the default. 188 189 Level: beginner 190 191 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 192 193 M*/ 194 #define PETSC_DECIDE -1 195 196 /*M 197 PETSC_DEFAULT - standard way of passing in integer or floating point parameter 198 where you wish PETSc to use the default. 199 200 Level: beginner 201 202 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE 203 204 M*/ 205 #define PETSC_DEFAULT -2 206 207 #define PETSC_YES PETSC_TRUE 208 #define PETSC_NO PETSC_FALSE 209 210 /*M 211 PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument 212 213 Level: beginner 214 215 Notes: accepted by many PETSc functions to not set a parameter and instead use 216 some default 217 218 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 219 PETSC_NULL_DOUBLE_PRECISION etc 220 221 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE 222 223 M*/ 224 #define PETSC_IGNORE PETSC_NULL 225 226 /*M 227 PETSC_DETERMINE - standard way of passing in integer or floating point parameter 228 where you wish PETSc to compute the required value. 229 230 Level: beginner 231 232 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes() 233 234 M*/ 235 #define PETSC_DETERMINE PETSC_DECIDE 236 237 /*M 238 PETSC_COMM_WORLD - a duplicate of the MPI_COMM_WORLD communicator which represents 239 all the processs 240 241 Level: beginner 242 243 Notes: PETSC_COMM_WORLD and MPI_COMM_WORLD are equivalent except that passing MPI_COMM_WORLD 244 into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup() 245 will be done on it internally. We recommend always using PETSC_COMM_WORLD 246 247 .seealso: PETSC_COMM_SELF 248 249 M*/ 250 extern MPI_Comm PETSC_COMM_WORLD; 251 252 /*M 253 PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents 254 the current process 255 256 Level: beginner 257 258 Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent except that passint MPI_COMM_SELF 259 into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup() 260 will be done on it internally. We recommend always using PETSC_COMM_SELF 261 262 .seealso: PETSC_COMM_WORLD 263 264 M*/ 265 extern MPI_Comm PETSC_COMM_SELF; 266 267 extern PetscTruth PetscInitializeCalled; 268 extern PetscTruth PetscFinalizeCalled; 269 EXTERN PetscErrorCode PetscSetCommWorld(MPI_Comm); 270 EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 271 EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 272 EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*); 273 274 /*MC 275 PetscMalloc - Allocates memory 276 277 Input Parameter: 278 . m - number of bytes to allocate 279 280 Output Parameter: 281 . result - memory allocated 282 283 Synopsis: 284 PetscErrorCode PetscMalloc(size_t m,void **result) 285 286 Level: beginner 287 288 Notes: Memory is always allocated at least double aligned 289 290 If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 291 properly handle not freeing the null pointer. 292 293 .seealso: PetscFree(), PetscNew() 294 295 Concepts: memory allocation 296 297 M*/ 298 #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) ) 299 300 /*MC 301 PetscMalloc2 - Allocates 2 chunks of memory 302 303 Input Parameter: 304 + m1 - number of elements to allocate in 1st chunk (may be zero) 305 . t1 - type of first memory elements 306 . m2 - number of elements to allocate in 2nd chunk (may be zero) 307 - t2 - type of second memory elements 308 309 Output Parameter: 310 + r1 - memory allocated in first chunk 311 - r2 - memory allocated in second chunk 312 313 Synopsis: 314 PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2) 315 316 Level: developer 317 318 Notes: Memory of first chunk is always allocated at least double aligned 319 320 .seealso: PetscFree(), PetscNew(), PetscMalloc() 321 322 Concepts: memory allocation 323 324 M*/ 325 #if defined(PETSC_USE_DEBUG) 326 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2)) 327 #else 328 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0)) 329 #endif 330 331 /*MC 332 PetscMalloc3 - Allocates 3 chunks of memory 333 334 Input Parameter: 335 + m1 - number of elements to allocate in 1st chunk (may be zero) 336 . t1 - type of first memory elements 337 . m2 - number of elements to allocate in 2nd chunk (may be zero) 338 . t2 - type of second memory elements 339 . m3 - number of elements to allocate in 3rd chunk (may be zero) 340 - t3 - type of third memory elements 341 342 Output Parameter: 343 + r1 - memory allocated in first chunk 344 . r2 - memory allocated in second chunk 345 - r3 - memory allocated in third chunk 346 347 Synopsis: 348 PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3) 349 350 Level: developer 351 352 Notes: Memory of first chunk is always allocated at least double aligned 353 354 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3() 355 356 Concepts: memory allocation 357 358 M*/ 359 #if defined(PETSC_USE_DEBUG) 360 #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)) 361 #else 362 #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)) 363 #endif 364 365 /*MC 366 PetscMalloc4 - Allocates 4 chunks of memory 367 368 Input Parameter: 369 + m1 - number of elements to allocate in 1st chunk (may be zero) 370 . t1 - type of first memory elements 371 . m2 - number of elements to allocate in 2nd chunk (may be zero) 372 . t2 - type of second memory elements 373 . m3 - number of elements to allocate in 3rd chunk (may be zero) 374 . t3 - type of third memory elements 375 . m4 - number of elements to allocate in 4th chunk (may be zero) 376 - t4 - type of fourth memory elements 377 378 Output Parameter: 379 + r1 - memory allocated in first chunk 380 . r2 - memory allocated in second chunk 381 . r3 - memory allocated in third chunk 382 - r4 - memory allocated in fourth chunk 383 384 Synopsis: 385 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) 386 387 Level: developer 388 389 Notes: Memory of first chunk is always allocated at least double aligned 390 391 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4() 392 393 Concepts: memory allocation 394 395 M*/ 396 #if defined(PETSC_USE_DEBUG) 397 #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)) 398 #else 399 #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)) 400 #endif 401 402 /*MC 403 PetscMalloc5 - Allocates 5 chunks of memory 404 405 Input Parameter: 406 + m1 - number of elements to allocate in 1st chunk (may be zero) 407 . t1 - type of first memory elements 408 . m2 - number of elements to allocate in 2nd chunk (may be zero) 409 . t2 - type of second memory elements 410 . m3 - number of elements to allocate in 3rd chunk (may be zero) 411 . t3 - type of third memory elements 412 . m4 - number of elements to allocate in 4th chunk (may be zero) 413 . t4 - type of fourth memory elements 414 . m5 - number of elements to allocate in 5th chunk (may be zero) 415 - t5 - type of fifth memory elements 416 417 Output Parameter: 418 + r1 - memory allocated in first chunk 419 . r2 - memory allocated in second chunk 420 . r3 - memory allocated in third chunk 421 . r4 - memory allocated in fourth chunk 422 - r5 - memory allocated in fifth chunk 423 424 Synopsis: 425 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) 426 427 Level: developer 428 429 Notes: Memory of first chunk is always allocated at least double aligned 430 431 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5() 432 433 Concepts: memory allocation 434 435 M*/ 436 #if defined(PETSC_USE_DEBUG) 437 #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)) 438 #else 439 #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)) 440 #endif 441 442 443 /*MC 444 PetscMalloc6 - Allocates 6 chunks of memory 445 446 Input Parameter: 447 + m1 - number of elements to allocate in 1st chunk (may be zero) 448 . t1 - type of first memory elements 449 . m2 - number of elements to allocate in 2nd chunk (may be zero) 450 . t2 - type of second memory elements 451 . m3 - number of elements to allocate in 3rd chunk (may be zero) 452 . t3 - type of third memory elements 453 . m4 - number of elements to allocate in 4th chunk (may be zero) 454 . t4 - type of fourth memory elements 455 . m5 - number of elements to allocate in 5th chunk (may be zero) 456 . t5 - type of fifth memory elements 457 . m6 - number of elements to allocate in 6th chunk (may be zero) 458 - t6 - type of sixth memory elements 459 460 Output Parameter: 461 + r1 - memory allocated in first chunk 462 . r2 - memory allocated in second chunk 463 . r3 - memory allocated in third chunk 464 . r4 - memory allocated in fourth chunk 465 . r5 - memory allocated in fifth chunk 466 - r6 - memory allocated in sixth chunk 467 468 Synopsis: 469 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) 470 471 Level: developer 472 473 Notes: Memory of first chunk is always allocated at least double aligned 474 475 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6() 476 477 Concepts: memory allocation 478 479 M*/ 480 #if defined(PETSC_USE_DEBUG) 481 #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)) 482 #else 483 #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)) 484 #endif 485 486 /*MC 487 PetscNew - Allocates memory of a particular type, Zeros the memory! 488 489 Input Parameter: 490 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 491 492 Output Parameter: 493 . result - memory allocated 494 495 Synopsis: 496 PetscErrorCode PetscNew(struct type,((type *))result) 497 498 Level: beginner 499 500 .seealso: PetscFree(), PetscMalloc() 501 502 Concepts: memory allocation 503 504 M*/ 505 #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A))) 506 507 /*MC 508 PetscFree - Frees memory 509 510 Input Parameter: 511 . memory - memory to free 512 513 Synopsis: 514 PetscErrorCode PetscFree(void *memory) 515 516 Level: beginner 517 518 Notes: Memory must have been obtained with PetscNew() or PetscMalloc() 519 520 .seealso: PetscNew(), PetscMalloc() 521 522 Concepts: memory allocation 523 524 M*/ 525 #define PetscFree(a) ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0) 526 527 /*MC 528 PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 529 530 Input Parameter: 531 + memory1 - memory to free 532 - memory2 - 2nd memory to free 533 534 535 Synopsis: 536 PetscErrorCode PetscFree2(void *memory1,void *memory2) 537 538 Level: developer 539 540 Notes: Memory must have been obtained with PetscMalloc2() 541 542 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree() 543 544 Concepts: memory allocation 545 546 M*/ 547 #if defined(PETSC_USE_DEBUG) 548 #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1)) 549 #else 550 #define PetscFree2(m1,m2) (PetscFree(m1)) 551 #endif 552 553 /*MC 554 PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 555 556 Input Parameter: 557 + memory1 - memory to free 558 . memory2 - 2nd memory to free 559 - memory3 - 3rd memory to free 560 561 562 Synopsis: 563 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 564 565 Level: developer 566 567 Notes: Memory must have been obtained with PetscMalloc3() 568 569 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3() 570 571 Concepts: memory allocation 572 573 M*/ 574 #if defined(PETSC_USE_DEBUG) 575 #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 576 #else 577 #define PetscFree3(m1,m2,m3) (PetscFree(m1)) 578 #endif 579 580 /*MC 581 PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 582 583 Input Parameter: 584 + m1 - memory to free 585 . m2 - 2nd memory to free 586 . m3 - 3rd memory to free 587 - m4 - 4th memory to free 588 589 590 Synopsis: 591 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 592 593 Level: developer 594 595 Notes: Memory must have been obtained with PetscMalloc4() 596 597 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4() 598 599 Concepts: memory allocation 600 601 M*/ 602 #if defined(PETSC_USE_DEBUG) 603 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 604 #else 605 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1)) 606 #endif 607 608 /*MC 609 PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 610 611 Input Parameter: 612 + m1 - memory to free 613 . m2 - 2nd memory to free 614 . m3 - 3rd memory to free 615 . m4 - 4th memory to free 616 - m5 - 5th memory to free 617 618 619 Synopsis: 620 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 621 622 Level: developer 623 624 Notes: Memory must have been obtained with PetscMalloc5() 625 626 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5() 627 628 Concepts: memory allocation 629 630 M*/ 631 #if defined(PETSC_USE_DEBUG) 632 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 633 #else 634 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1)) 635 #endif 636 637 638 /*MC 639 PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 640 641 Input Parameter: 642 + m1 - memory to free 643 . m2 - 2nd memory to free 644 . m3 - 3rd memory to free 645 . m4 - 4th memory to free 646 . m5 - 5th memory to free 647 - m6 - 6th memory to free 648 649 650 Synopsis: 651 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 652 653 Level: developer 654 655 Notes: Memory must have been obtained with PetscMalloc6() 656 657 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6() 658 659 Concepts: memory allocation 660 661 M*/ 662 #if defined(PETSC_USE_DEBUG) 663 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 664 #else 665 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1)) 666 #endif 667 668 EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**); 669 EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]); 670 EXTERN PetscErrorCode PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[])); 671 EXTERN PetscErrorCode PetscClearMalloc(void); 672 673 /* 674 Routines for tracing memory corruption/bleeding with default PETSc 675 memory allocation 676 */ 677 EXTERN PetscErrorCode PetscMallocDump(FILE *); 678 EXTERN PetscErrorCode PetscMallocDumpLog(FILE *); 679 EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *); 680 EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *); 681 EXTERN PetscErrorCode PetscMallocDebug(PetscTruth); 682 EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[],const char[]); 683 EXTERN PetscErrorCode PetscMallocSetDumpLog(void); 684 685 686 /* 687 Variable type where we stash PETSc object pointers in Fortran. 688 Assumes that sizeof(long) == sizeof(void*)which is true on 689 all machines that we know. 690 */ 691 #define PetscFortranAddr long 692 693 /*E 694 PetscDataType - Used for handling different basic data types. 695 696 Level: beginner 697 698 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(), 699 PetscDataTypeGetSize(), PetscDataTypeGetName() 700 701 E*/ 702 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, 703 PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5, 704 PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType; 705 #if defined(PETSC_USE_COMPLEX) 706 #define PETSC_SCALAR PETSC_COMPLEX 707 #else 708 #if defined(PETSC_USE_SINGLE) 709 #define PETSC_SCALAR PETSC_FLOAT 710 #else 711 #define PETSC_SCALAR PETSC_DOUBLE 712 #endif 713 #endif 714 #if defined(PETSC_USE_SINGLE) 715 #define PETSC_REAL PETSC_FLOAT 716 #else 717 #define PETSC_REAL PETSC_DOUBLE 718 #endif 719 #define PETSC_FORTRANADDR PETSC_LONG 720 721 EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 722 EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,PetscInt*); 723 EXTERN PetscErrorCode PetscDataTypeGetName(PetscDataType,const char*[]); 724 725 /* 726 Basic memory and string operations. These are usually simple wrappers 727 around the basic Unix system calls, but a few of them have additional 728 functionality and/or error checking. 729 */ 730 EXTERN PetscErrorCode PetscMemcpy(void*,const void *,size_t); 731 EXTERN PetscErrorCode PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType); 732 EXTERN PetscErrorCode PetscMemmove(void*,void *,size_t); 733 EXTERN PetscErrorCode PetscMemzero(void*,size_t); 734 EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscTruth *); 735 EXTERN PetscErrorCode PetscStrlen(const char[],size_t*); 736 EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscTruth *); 737 EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscTruth *); 738 EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscTruth*); 739 EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscTruth*); 740 EXTERN PetscErrorCode PetscStrcpy(char[],const char[]); 741 EXTERN PetscErrorCode PetscStrcat(char[],const char[]); 742 EXTERN PetscErrorCode PetscStrncat(char[],const char[],size_t); 743 EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t); 744 EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]); 745 EXTERN PetscErrorCode PetscStrtolower(char[]); 746 EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]); 747 EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]); 748 EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]); 749 EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t); 750 #define PetscStrfree(a) ((a) ? PetscFree(a) : 0) 751 /*S 752 PetscToken - 'Token' used for managing tokenizing strings 753 754 Level: intermediate 755 756 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy() 757 S*/ 758 typedef struct {char token;char *array;char *current;} PetscToken; 759 760 EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken**); 761 EXTERN PetscErrorCode PetscTokenFind(PetscToken*,char *[]); 762 EXTERN PetscErrorCode PetscTokenDestroy(PetscToken*); 763 764 /* 765 These are MPI operations for MPI_Allreduce() etc 766 */ 767 EXTERN MPI_Op PetscMaxSum_Op; 768 #if defined(PETSC_USE_COMPLEX) 769 EXTERN MPI_Op PetscSum_Op; 770 #else 771 #define PetscSum_Op MPI_SUM 772 #endif 773 EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 774 775 /*S 776 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 777 778 Level: beginner 779 780 Note: This is the base class from which all objects appear. 781 782 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName() 783 S*/ 784 typedef struct _p_PetscObject* PetscObject; 785 786 /*S 787 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 788 by string name 789 790 Level: advanced 791 792 .seealso: PetscFListAdd(), PetscFListDestroy() 793 S*/ 794 typedef struct _PetscFList *PetscFList; 795 796 #include "petscviewer.h" 797 #include "petscoptions.h" 798 799 /* 800 Routines that get memory usage information from the OS 801 */ 802 EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *); 803 EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *); 804 EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void); 805 EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]); 806 807 EXTERN PetscErrorCode PetscLogInfoAllow(PetscTruth,const char []); 808 EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*); 809 EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*); 810 EXTERN PetscErrorCode PetscSleep(int); 811 812 /* 813 Initialization of PETSc 814 */ 815 EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]); 816 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL)) 817 EXTERN PetscErrorCode PetscInitializeNoArguments(void); 818 EXTERN PetscErrorCode PetscInitialized(PetscTruth *); 819 EXTERN PetscErrorCode PetscFinalized(PetscTruth *); 820 EXTERN PetscErrorCode PetscFinalize(void); 821 EXTERN PetscErrorCode PetscInitializeFortran(void); 822 EXTERN PetscErrorCode PetscGetArgs(int*,char ***); 823 EXTERN PetscErrorCode PetscEnd(void); 824 825 typedef void (**PetscVoidFunction)(void); 826 827 /* 828 PetscTryMethod - Queries an object for a method, if it exists then calls it. 829 These are intended to be used only inside PETSc functions. 830 */ 831 #define PetscTryMethod(obj,A,B,C) \ 832 0;{ PetscErrorCode (*f)B, __ierr; \ 833 __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 834 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 835 } 836 #define PetscUseMethod(obj,A,B,C) \ 837 0;{ PetscErrorCode (*f)B, __ierr; \ 838 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 839 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 840 else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \ 841 } 842 /* 843 Functions that can act on any PETSc object. 844 */ 845 EXTERN PetscErrorCode PetscObjectDestroy(PetscObject); 846 EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*); 847 EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *); 848 EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,int *); 849 EXTERN PetscErrorCode PetscObjectGetType(PetscObject,int *); 850 EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]); 851 EXTERN PetscErrorCode PetscObjectGetName(PetscObject,char*[]); 852 EXTERN PetscErrorCode PetscObjectReference(PetscObject); 853 EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*); 854 EXTERN PetscErrorCode PetscObjectDereference(PetscObject); 855 EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *); 856 EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *); 857 EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer); 858 EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject); 859 EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *); 860 EXTERN PetscErrorCode PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 861 862 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */ 863 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */ 864 /*MC 865 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 866 867 Collective on PetscObject 868 869 Input Parameters: 870 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 871 PetscObjectCompose((PetscObject)mat,...); 872 . name - name associated with the child function 873 . fname - name of the function 874 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 875 876 Level: advanced 877 878 Synopsis: 879 PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 880 881 Notes: 882 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 883 884 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 885 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 886 887 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 888 work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES) 889 enabled. 890 891 Concepts: objects^composing functions 892 Concepts: composing functions 893 Concepts: functions^querying 894 Concepts: objects^querying 895 Concepts: querying objects 896 897 .seealso: PetscObjectQueryFunction() 898 M*/ 899 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 900 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 901 #else 902 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d)) 903 #endif 904 905 EXTERN PetscErrorCode PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 906 EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]); 907 EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 908 EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 909 EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,char*[]); 910 EXTERN PetscErrorCode PetscObjectPublish(PetscObject); 911 EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]); 912 EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject); 913 EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void); 914 EXTERN PetscErrorCode PetscObjectName(PetscObject); 915 EXTERN PetscErrorCode PetscTypeCompare(PetscObject,const char[],PetscTruth*); 916 917 /* 918 Defines PETSc error handling. 919 */ 920 #include "petscerror.h" 921 922 /*S 923 PetscOList - Linked list of PETSc objects, accessable by string name 924 925 Level: advanced 926 927 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind() 928 S*/ 929 typedef struct _PetscOList *PetscOList; 930 931 EXTERN PetscErrorCode PetscOListDestroy(PetscOList *); 932 EXTERN PetscErrorCode PetscOListFind(PetscOList,const char[],PetscObject*); 933 EXTERN PetscErrorCode PetscOListReverseFind(PetscOList,PetscObject,char**); 934 EXTERN PetscErrorCode PetscOListAdd(PetscOList *,const char[],PetscObject); 935 EXTERN PetscErrorCode PetscOListDuplicate(PetscOList,PetscOList *); 936 937 /* 938 Dynamic library lists. Lists of names of routines in dynamic 939 link libraries that will be loaded as needed. 940 */ 941 EXTERN PetscErrorCode PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 942 EXTERN PetscErrorCode PetscFListDestroy(PetscFList*); 943 EXTERN PetscErrorCode PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void)); 944 EXTERN PetscErrorCode PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList); 945 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 946 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 947 #else 948 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 949 #endif 950 EXTERN PetscErrorCode PetscFListDuplicate(PetscFList,PetscFList *); 951 EXTERN PetscErrorCode PetscFListView(PetscFList,PetscViewer); 952 EXTERN PetscErrorCode PetscFListConcat(const char [],const char [],char []); 953 EXTERN PetscErrorCode PetscFListGet(PetscFList,char ***,int*); 954 955 /*S 956 PetscDLLibraryList - Linked list of dynamics libraries to search for functions 957 958 Level: advanced 959 960 PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries 961 962 .seealso: PetscDLLibraryOpen() 963 S*/ 964 typedef struct _PetscDLLibraryList *PetscDLLibraryList; 965 extern PetscDLLibraryList DLLibrariesLoaded; 966 EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *); 967 EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],void **); 968 EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **); 969 EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]); 970 EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]); 971 EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibraryList); 972 EXTERN PetscErrorCode PetscDLLibraryPrintPath(void); 973 EXTERN PetscErrorCode PetscDLLibraryGetInfo(void*,const char[],const char *[]); 974 975 /* 976 Mechanism for translating PETSc object representations between languages 977 Not currently used. 978 */ 979 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CXX} PetscLanguage; 980 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C 981 EXTERN PetscErrorCode PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *); 982 EXTERN PetscErrorCode PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **); 983 984 /* 985 Useful utility routines 986 */ 987 EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 988 EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 989 EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 990 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1)) 991 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1)) 992 EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 993 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1)) 994 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1)) 995 EXTERN PetscErrorCode PetscBarrier(PetscObject); 996 EXTERN PetscErrorCode PetscMPIDump(FILE*); 997 998 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 999 /* 1000 Defines basic graphics available from PETSc. 1001 */ 1002 #include "petscdraw.h" 1003 1004 /* 1005 Defines the base data structures for all PETSc objects 1006 */ 1007 #include "petschead.h" 1008 1009 /* 1010 Defines PETSc profiling. 1011 */ 1012 #include "petsclog.h" 1013 1014 /* 1015 For locking, unlocking and destroying AMS memories associated with 1016 PETSc objects. Not currently used. 1017 */ 1018 #define PetscPublishAll(v) 0 1019 #define PetscObjectTakeAccess(obj) 0 1020 #define PetscObjectGrantAccess(obj) 0 1021 #define PetscObjectDepublish(obj) 0 1022 1023 1024 1025 /* 1026 This code allows one to pass a MPI communicator between 1027 C and Fortran. MPI 2.0 defines a standard API for doing this. 1028 The code here is provided to allow PETSc to work with MPI 1.1 1029 standard MPI libraries. 1030 */ 1031 EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *); 1032 EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*); 1033 1034 /* 1035 Simple PETSc parallel IO for ASCII printing 1036 */ 1037 EXTERN PetscErrorCode PetscFixFilename(const char[],char[]); 1038 EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1039 EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*); 1040 EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1041 EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1042 1043 /* These are used internally by PETSc ASCII IO routines*/ 1044 #include <stdarg.h> 1045 EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char*,va_list); 1046 EXTERN PetscErrorCode PetscVFPrintf(FILE*,const char*,va_list); 1047 1048 /*MC 1049 PetscErrorPrintf - Prints error messages. 1050 1051 Not Collective 1052 1053 Synopsis: 1054 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1055 1056 Input Parameters: 1057 . format - the usual printf() format string 1058 1059 Options Database Keys: 1060 . -error_output_stderr - cause error messages to be printed to stderr instead of the 1061 (default) stdout 1062 1063 1064 Level: developer 1065 1066 Fortran Note: 1067 This routine is not supported in Fortran. 1068 1069 Concepts: error messages^printing 1070 Concepts: printing^error messages 1071 1072 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf() 1073 M*/ 1074 EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 1075 1076 /*MC 1077 PetscHelpPrintf - Prints help messages. 1078 1079 Not Collective 1080 1081 Synopsis: 1082 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1083 1084 Input Parameters: 1085 . format - the usual printf() format string 1086 1087 Level: developer 1088 1089 Fortran Note: 1090 This routine is not supported in Fortran. 1091 1092 Concepts: help messages^printing 1093 Concepts: printing^help messages 1094 1095 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1096 M*/ 1097 EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1098 1099 EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1100 EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*); 1101 EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1102 EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1103 EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm); 1104 EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1105 EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1106 EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1107 EXTERN PetscErrorCode PetscGetPetscDir(const char*[]); 1108 1109 EXTERN PetscErrorCode PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*); 1110 /*S 1111 PetscObjectContainer - Simple PETSc object that contains a pointer to any required data 1112 1113 Level: advanced 1114 1115 .seealso: PetscObject, PetscObjectContainerCreate() 1116 S*/ 1117 typedef struct _p_PetscObjectContainer* PetscObjectContainer; 1118 EXTERN PetscErrorCode PetscObjectContainerGetPointer(PetscObjectContainer,void **); 1119 EXTERN PetscErrorCode PetscObjectContainerSetPointer(PetscObjectContainer,void *); 1120 EXTERN PetscErrorCode PetscObjectContainerDestroy(PetscObjectContainer); 1121 EXTERN PetscErrorCode PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *); 1122 EXTERN PetscErrorCode PetscObjectContainerSetUserDestroy(PetscObjectContainer, PetscErrorCode (*)(void*)); 1123 1124 /* 1125 For incremental debugging 1126 */ 1127 extern PetscTruth PetscCompare; 1128 EXTERN PetscErrorCode PetscCompareDouble(double); 1129 EXTERN PetscErrorCode PetscCompareScalar(PetscScalar); 1130 EXTERN PetscErrorCode PetscCompareInt(PetscInt); 1131 1132 /* 1133 For use in debuggers 1134 */ 1135 extern int PetscGlobalRank,PetscGlobalSize; 1136 EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer); 1137 EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer); 1138 EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer); 1139 1140 /* 1141 Allows accessing Matlab Engine 1142 */ 1143 #include "petscmatlab.h" 1144 1145 /* 1146 C code optimization is often enhanced by telling the compiler 1147 that certain pointer arguments to functions are not aliased to 1148 to other arguments. This is not yet ANSI C standard so we define 1149 the macro "restrict" to indicate that the variable is not aliased 1150 to any other argument. 1151 */ 1152 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus) 1153 #define restrict _Restrict 1154 #else 1155 #if defined(restrict) 1156 #undef restrict 1157 #endif 1158 #define restrict 1159 #endif 1160 1161 /* 1162 Determine if some of the kernel computation routines use 1163 Fortran (rather than C) for the numerical calculations. On some machines 1164 and compilers (like complex numbers) the Fortran version of the routines 1165 is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS 1166 would be set in the petscconf.h file 1167 */ 1168 #if defined(PETSC_USE_FORTRAN_KERNELS) 1169 1170 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1171 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1172 #endif 1173 1174 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1175 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1176 #endif 1177 1178 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1179 #define PETSC_USE_FORTRAN_KERNEL_NORM 1180 #endif 1181 1182 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1183 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1184 #endif 1185 1186 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1187 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1188 #endif 1189 1190 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1191 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1192 #endif 1193 1194 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1195 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1196 #endif 1197 1198 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1199 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1200 #endif 1201 1202 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1203 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1204 #endif 1205 1206 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1207 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1208 #endif 1209 1210 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1211 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1212 #endif 1213 1214 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1215 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1216 #endif 1217 1218 #endif 1219 1220 /* 1221 Macros for indicating code that should be compiled with a C interface, 1222 rather than a C++ interface. Any routines that are dynamically loaded 1223 (such as the PCCreate_XXX() routines) must be wrapped so that the name 1224 mangler does not change the functions symbol name. This just hides the 1225 ugly extern "C" {} wrappers. 1226 */ 1227 #if defined(__cplusplus) 1228 #define EXTERN_C_BEGIN extern "C" { 1229 #define EXTERN_C_END } 1230 #else 1231 #define EXTERN_C_BEGIN 1232 #define EXTERN_C_END 1233 #endif 1234 1235 /* --------------------------------------------------------------------*/ 1236 1237 /*M 1238 size - integer variable used to contain the number of processors in 1239 the relevent MPI_Comm 1240 1241 Level: beginner 1242 1243 .seealso: rank, comm 1244 M*/ 1245 1246 /*M 1247 rank - integer variable used to contain the number of this processor relative 1248 to all in the relevent MPI_Comm 1249 1250 Level: beginner 1251 1252 .seealso: size, comm 1253 M*/ 1254 1255 /*M 1256 comm - MPI_Comm used in the current routine or object 1257 1258 Level: beginner 1259 1260 .seealso: size, rank 1261 M*/ 1262 1263 /*M 1264 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1265 communication 1266 1267 Level: beginner 1268 1269 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1270 1271 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF 1272 M*/ 1273 1274 /*M 1275 PetscScalar - PETSc type that represents either a double precision real number or 1276 a double precision complex number if the code is configured with --with-scalar-type=complex 1277 1278 Level: beginner 1279 1280 .seealso: PetscReal, PassiveReal, PassiveScalar 1281 M*/ 1282 1283 /*M 1284 PetscReal - PETSc type that represents a double precision real number 1285 1286 Level: beginner 1287 1288 .seealso: PetscScalar, PassiveReal, PassiveScalar 1289 M*/ 1290 1291 /*M 1292 PassiveScalar - PETSc type that represents either a double precision real number or 1293 a double precision complex number if the code is code is configured with --with-scalar-type=complex 1294 1295 Level: beginner 1296 1297 This is the same as a PetscScalar except in code that is automatically differentiated it is 1298 treated as a constant (not an indendent or dependent variable) 1299 1300 .seealso: PetscReal, PassiveReal, PetscScalar 1301 M*/ 1302 1303 /*M 1304 PassiveReal - PETSc type that represents a double precision real number 1305 1306 Level: beginner 1307 1308 This is the same as a PetscReal except in code that is automatically differentiated it is 1309 treated as a constant (not an indendent or dependent variable) 1310 1311 .seealso: PetscScalar, PetscReal, PassiveScalar 1312 M*/ 1313 1314 /*M 1315 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 1316 1317 Level: beginner 1318 1319 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 1320 pass this value 1321 1322 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar 1323 M*/ 1324 1325 /* 1326 The IBM include files define hz, here we hide it so that it may be used 1327 as a regular user variable. 1328 */ 1329 #if defined(hz) 1330 #undef hz 1331 #endif 1332 1333 /* For arrays that contain filenames or paths */ 1334 1335 1336 #if defined(PETSC_HAVE_LIMITS_H) 1337 #include <limits.h> 1338 #endif 1339 #if defined(PETSC_HAVE_SYS_PARAM_H) 1340 #include <sys/param.h> 1341 #endif 1342 #if defined(PETSC_HAVE_SYS_TYPES_H) 1343 #include <sys/types.h> 1344 #endif 1345 #if defined(MAXPATHLEN) 1346 # define PETSC_MAX_PATH_LEN MAXPATHLEN 1347 #elif defined(MAX_PATH) 1348 # define PETSC_MAX_PATH_LEN MAX_PATH 1349 #elif defined(_MAX_PATH) 1350 # define PETSC_MAX_PATH_LEN _MAX_PATH 1351 #else 1352 # define PETSC_MAX_PATH_LEN 4096 1353 #endif 1354 1355 PETSC_EXTERN_CXX_END 1356 #endif 1357 1358 1359