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