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