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