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