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 PetscTrDebugLevel(int); 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 typedef struct {char token;char *array;char *current;} PetscToken; 373 EXTERN int PetscTokenCreate(const char[],const char,PetscToken**); 374 EXTERN int PetscTokenFind(PetscToken*,char *[]); 375 EXTERN int PetscTokenDestroy(PetscToken*); 376 377 /* 378 These are MPI operations for MPI_Allreduce() etc 379 */ 380 EXTERN MPI_Op PetscMaxSum_Op; 381 #if defined(PETSC_USE_COMPLEX) 382 EXTERN MPI_Op PetscSum_Op; 383 #else 384 #define PetscSum_Op MPI_SUM 385 #endif 386 EXTERN int PetscMaxSum(MPI_Comm,const int[],int*,int*); 387 388 /*S 389 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 390 391 Level: beginner 392 393 Note: This is the base class from which all objects appear. 394 395 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName() 396 S*/ 397 typedef struct _p_PetscObject* PetscObject; 398 399 /*S 400 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 401 by string name 402 403 Level: advanced 404 405 .seealso: PetscFListAdd(), PetscFListDestroy() 406 S*/ 407 typedef struct _PetscFList *PetscFList; 408 409 #include "petscviewer.h" 410 #include "petscoptions.h" 411 412 EXTERN int PetscShowMemoryUsage(PetscViewer,const char[]); 413 EXTERN int PetscGetTime(PetscLogDouble*); 414 EXTERN int PetscGetCPUTime(PetscLogDouble*); 415 EXTERN int PetscSleep(int); 416 417 /* 418 Initialization of PETSc 419 */ 420 EXTERN int PetscInitialize(int*,char***,const char[],const char[]); 421 EXTERN int PetscInitializeNoArguments(void); 422 EXTERN int PetscInitialized(PetscTruth *); 423 EXTERN int PetscFinalize(void); 424 EXTERN int PetscInitializeFortran(void); 425 EXTERN int PetscGetArgs(int*,char ***); 426 EXTERN int PetscEnd(void); 427 428 /* 429 ParameterDict is an abstraction for arguments to interface mechanisms 430 */ 431 extern int DICT_COOKIE; 432 typedef struct _p_Dict *ParameterDict; 433 434 typedef void (**PetscVoidFunction)(void); 435 436 /* 437 PetscTryMethod - Queries an object for a method, if it exists then calls it. 438 These are intended to be used only inside PETSc functions. 439 */ 440 #define PetscTryMethod(obj,A,B,C) \ 441 0;{ int (*f)B, __ierr; \ 442 __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 443 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 444 } 445 #define PetscUseMethod(obj,A,B,C) \ 446 0;{ int (*f)B, __ierr; \ 447 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 448 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 449 else {SETERRQ1(1,"Cannot locate function %s in object",A);} \ 450 } 451 /* 452 Functions that can act on any PETSc object. 453 */ 454 EXTERN int PetscObjectDestroy(PetscObject); 455 EXTERN int PetscObjectExists(PetscObject,PetscTruth*); 456 EXTERN int PetscObjectGetComm(PetscObject,MPI_Comm *); 457 EXTERN int PetscObjectGetCookie(PetscObject,int *); 458 EXTERN int PetscObjectGetType(PetscObject,int *); 459 EXTERN int PetscObjectSetName(PetscObject,const char[]); 460 EXTERN int PetscObjectGetName(PetscObject,char*[]); 461 EXTERN int PetscObjectReference(PetscObject); 462 EXTERN int PetscObjectGetReference(PetscObject,int*); 463 EXTERN int PetscObjectDereference(PetscObject); 464 EXTERN int PetscObjectGetNewTag(PetscObject,int *); 465 EXTERN int PetscObjectSetParameterDict(PetscObject,ParameterDict); 466 EXTERN int PetscObjectGetParameterDict(PetscObject,ParameterDict*); 467 EXTERN int PetscCommGetNewTag(MPI_Comm,int *); 468 EXTERN int PetscObjectView(PetscObject,PetscViewer); 469 EXTERN int PetscObjectCompose(PetscObject,const char[],PetscObject); 470 EXTERN int PetscObjectQuery(PetscObject,const char[],PetscObject *); 471 EXTERN int PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 472 473 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */ 474 typedef int (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */ 475 /*MC 476 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 477 478 Collective on PetscObject 479 480 Input Parameters: 481 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 482 PetscObjectCompose((PetscObject)mat,...); 483 . name - name associated with the child function 484 . fname - name of the function 485 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 486 487 Level: advanced 488 489 Synopsis: 490 int PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 491 492 Notes: 493 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 494 495 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 496 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 497 498 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 499 work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES) 500 enabled. 501 502 Concepts: objects^composing functions 503 Concepts: composing functions 504 Concepts: functions^querying 505 Concepts: objects^querying 506 Concepts: querying objects 507 508 .seealso: PetscObjectQueryFunction() 509 M*/ 510 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 511 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 512 #else 513 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d)) 514 #endif 515 516 EXTERN int PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 517 EXTERN int PetscObjectSetOptionsPrefix(PetscObject,const char[]); 518 EXTERN int PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 519 EXTERN int PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 520 EXTERN int PetscObjectGetOptionsPrefix(PetscObject,char*[]); 521 EXTERN int PetscObjectPublish(PetscObject); 522 EXTERN int PetscObjectChangeTypeName(PetscObject,const char[]); 523 EXTERN int PetscObjectRegisterDestroy(PetscObject); 524 EXTERN int PetscObjectRegisterDestroyAll(void); 525 EXTERN int PetscObjectName(PetscObject); 526 EXTERN int PetscTypeCompare(PetscObject,const char[],PetscTruth*); 527 528 /* 529 Defines PETSc error handling. 530 */ 531 #include "petscerror.h" 532 533 /*S 534 PetscOList - Linked list of PETSc objects, accessable by string name 535 536 Level: advanced 537 538 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind() 539 S*/ 540 typedef struct _PetscOList *PetscOList; 541 542 EXTERN int PetscOListDestroy(PetscOList *); 543 EXTERN int PetscOListFind(PetscOList,const char[],PetscObject*); 544 EXTERN int PetscOListReverseFind(PetscOList,PetscObject,char**); 545 EXTERN int PetscOListAdd(PetscOList *,const char[],PetscObject); 546 EXTERN int PetscOListDuplicate(PetscOList,PetscOList *); 547 548 /* 549 Dynamic library lists. Lists of names of routines in dynamic 550 link libraries that will be loaded as needed. 551 */ 552 EXTERN int PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 553 EXTERN int PetscFListDestroy(PetscFList*); 554 EXTERN int PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void)); 555 EXTERN int PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList); 556 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 557 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 558 #else 559 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 560 #endif 561 EXTERN int PetscFListDuplicate(PetscFList,PetscFList *); 562 EXTERN int PetscFListView(PetscFList,PetscViewer); 563 EXTERN int PetscFListConcat(const char [],const char [],char []); 564 EXTERN int PetscFListGet(PetscFList,char ***,int*); 565 566 /*S 567 PetscDLLibraryList - Linked list of dynamics libraries to search for functions 568 569 Level: advanced 570 571 PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries 572 573 .seealso: PetscDLLibraryOpen() 574 S*/ 575 typedef struct _PetscDLLibraryList *PetscDLLibraryList; 576 extern PetscDLLibraryList DLLibrariesLoaded; 577 EXTERN int PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *); 578 EXTERN int PetscDLLibraryOpen(MPI_Comm,const char[],void **); 579 EXTERN int PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **); 580 EXTERN int PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]); 581 EXTERN int PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]); 582 EXTERN int PetscDLLibraryClose(PetscDLLibraryList); 583 EXTERN int PetscDLLibraryPrintPath(void); 584 EXTERN int PetscDLLibraryGetInfo(void *,const char[],const char *[]); 585 586 /* 587 Mechanism for translating PETSc object representations between languages 588 Not currently used. 589 */ 590 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CPP} PetscLanguage; 591 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C 592 EXTERN int PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *); 593 EXTERN int PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **); 594 595 /* 596 Useful utility routines 597 */ 598 EXTERN int PetscSplitOwnership(MPI_Comm,int*,int*); 599 EXTERN int PetscSplitOwnershipBlock(MPI_Comm,int,int*,int*); 600 EXTERN int PetscSequentialPhaseBegin(MPI_Comm,int); 601 EXTERN int PetscSequentialPhaseEnd(MPI_Comm,int); 602 EXTERN int PetscBarrier(PetscObject); 603 EXTERN int PetscMPIDump(FILE*); 604 605 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 606 /* 607 Defines basic graphics available from PETSc. 608 */ 609 #include "petscdraw.h" 610 611 /* 612 Defines the base data structures for all PETSc objects 613 */ 614 #include "petschead.h" 615 616 /* 617 Defines PETSc profiling. 618 */ 619 #include "petsclog.h" 620 621 /* 622 For locking, unlocking and destroying AMS memories associated with 623 PETSc objects 624 */ 625 #if defined(PETSC_HAVE_AMS) 626 627 extern PetscTruth PetscAMSPublishAll; 628 #define PetscPublishAll(v) (PetscAMSPublishAll ? PetscObjectPublish((PetscObject)v) : 0) 629 #define PetscObjectTakeAccess(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem)) 630 #define PetscObjectGrantAccess(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem)) 631 #define PetscObjectDepublish(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem)); \ 632 ((PetscObject)(obj))->amem = -1; 633 634 #else 635 636 #define PetscPublishAll(v) 0 637 #define PetscObjectTakeAccess(obj) 0 638 #define PetscObjectGrantAccess(obj) 0 639 #define PetscObjectDepublish(obj) 0 640 641 #endif 642 643 644 645 /* 646 This code allows one to pass a MPI communicator between 647 C and Fortran. MPI 2.0 defines a standard API for doing this. 648 The code here is provided to allow PETSc to work with MPI 1.1 649 standard MPI libraries. 650 */ 651 EXTERN int MPICCommToFortranComm(MPI_Comm,int *); 652 EXTERN int MPIFortranCommToCComm(int,MPI_Comm*); 653 654 /* 655 Simple PETSc parallel IO for ASCII printing 656 */ 657 EXTERN int PetscFixFilename(const char[],char[]); 658 EXTERN int PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 659 EXTERN int PetscFClose(MPI_Comm,FILE*); 660 EXTERN int PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 661 EXTERN int PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 662 663 /*MC 664 PetscErrorPrintf - Prints error messages. 665 666 Not Collective 667 668 Synopsis: 669 int (*PetscErrorPrintf)(const char format[],...); 670 671 Input Parameters: 672 . format - the usual printf() format string 673 674 Options Database Keys: 675 . -error_output_stderr - cause error messages to be printed to stderr instead of the 676 (default) stdout 677 678 679 Level: developer 680 681 Fortran Note: 682 This routine is not supported in Fortran. 683 684 Concepts: error messages^printing 685 Concepts: printing^error messages 686 687 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf() 688 M*/ 689 EXTERN int (*PetscErrorPrintf)(const char[],...); 690 691 /*MC 692 PetscHelpPrintf - Prints help messages. 693 694 Not Collective 695 696 Synopsis: 697 int (*PetscHelpPrintf)(const char format[],...); 698 699 Input Parameters: 700 . format - the usual printf() format string 701 702 Level: developer 703 704 Fortran Note: 705 This routine is not supported in Fortran. 706 707 Concepts: help messages^printing 708 Concepts: printing^help messages 709 710 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 711 M*/ 712 EXTERN int (*PetscHelpPrintf)(MPI_Comm,const char[],...); 713 714 EXTERN int PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 715 EXTERN int PetscPClose(MPI_Comm,FILE*); 716 EXTERN int PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 717 EXTERN int PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 718 EXTERN int PetscSynchronizedFlush(MPI_Comm); 719 EXTERN int PetscSynchronizedFGets(MPI_Comm,FILE*,int,char[]); 720 EXTERN int PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 721 EXTERN int PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 722 EXTERN int PetscGetPetscDir(const char*[]); 723 724 EXTERN int PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*); 725 /*S 726 PetscObjectContainer - Simple PETSc object that contains a pointer to any required data 727 728 Level: advanced 729 730 .seealso: PetscObject, PetscObjectContainerCreate() 731 S*/ 732 typedef struct _p_PetscObjectContainer* PetscObjectContainer; 733 EXTERN int PetscObjectContainerGetPointer(PetscObjectContainer,void **); 734 EXTERN int PetscObjectContainerSetPointer(PetscObjectContainer,void *); 735 EXTERN int PetscObjectContainerDestroy(PetscObjectContainer); 736 EXTERN int PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *); 737 738 /* 739 For incremental debugging 740 */ 741 extern PetscTruth PetscCompare; 742 EXTERN int PetscCompareDouble(double); 743 EXTERN int PetscCompareScalar(PetscScalar); 744 EXTERN int PetscCompareInt(int); 745 746 /* 747 For use in debuggers 748 */ 749 extern int PetscGlobalRank,PetscGlobalSize; 750 EXTERN int PetscIntView(int,int[],PetscViewer); 751 EXTERN int PetscRealView(int,PetscReal[],PetscViewer); 752 EXTERN int PetscScalarView(int,PetscScalar[],PetscViewer); 753 754 /* 755 Allows accessing Matlab Engine 756 */ 757 #include "petscmatlab.h" 758 759 /* 760 C code optimization is often enhanced by telling the compiler 761 that certain pointer arguments to functions are not aliased to 762 to other arguments. This is not yet ANSI C standard so we define 763 the macro "restrict" to indicate that the variable is not aliased 764 to any other argument. 765 */ 766 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus) 767 #define restrict _Restrict 768 #else 769 #if defined(restrict) 770 #undef restrict 771 #endif 772 #define restrict 773 #endif 774 775 /* 776 Determine if some of the kernel computation routines use 777 Fortran (rather than C) for the numerical calculations. On some machines 778 and compilers (like complex numbers) the Fortran version of the routines 779 is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS 780 would be set in the petscconf.h file 781 */ 782 #if defined(PETSC_USE_FORTRAN_KERNELS) 783 784 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 785 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 786 #endif 787 788 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 789 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 790 #endif 791 792 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 793 #define PETSC_USE_FORTRAN_KERNEL_NORM 794 #endif 795 796 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 797 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 798 #endif 799 800 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 801 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 802 #endif 803 804 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 805 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 806 #endif 807 808 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 809 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 810 #endif 811 812 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 813 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 814 #endif 815 816 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 817 #define PETSC_USE_FORTRAN_KERNEL_MDOT 818 #endif 819 820 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 821 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 822 #endif 823 824 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 825 #define PETSC_USE_FORTRAN_KERNEL_AYPX 826 #endif 827 828 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 829 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 830 #endif 831 832 #endif 833 834 /* 835 Macros for indicating code that should be compiled with a C interface, 836 rather than a C++ interface. Any routines that are dynamically loaded 837 (such as the PCCreate_XXX() routines) must be wrapped so that the name 838 mangler does not change the functions symbol name. This just hides the 839 ugly extern "C" {} wrappers. 840 */ 841 #if defined(__cplusplus) 842 #define EXTERN_C_BEGIN extern "C" { 843 #define EXTERN_C_END } 844 #else 845 #define EXTERN_C_BEGIN 846 #define EXTERN_C_END 847 #endif 848 849 /* --------------------------------------------------------------------*/ 850 851 /*M 852 size - integer variable used to contain the number of processors in 853 the relevent MPI_Comm 854 855 Level: beginner 856 857 .seealso: rank, comm 858 M*/ 859 860 /*M 861 rank - integer variable used to contain the number of this processor relative 862 to all in the relevent MPI_Comm 863 864 Level: beginner 865 866 .seealso: size, comm 867 M*/ 868 869 /*M 870 comm - MPI_Comm used in the current routine or object 871 872 Level: beginner 873 874 .seealso: size, rank 875 M*/ 876 877 /*M 878 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 879 communication 880 881 Level: beginner 882 883 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 884 885 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF 886 M*/ 887 888 /*M 889 PetscScalar - PETSc type that represents either a double precision real number or 890 a double precision complex number if the code is compiled with BOPT=g_complex or O_complex 891 892 Level: beginner 893 894 .seealso: PetscReal, PassiveReal, PassiveScalar 895 M*/ 896 897 /*M 898 PetscReal - PETSc type that represents a double precision real number 899 900 Level: beginner 901 902 .seealso: PetscScalar, PassiveReal, PassiveScalar 903 M*/ 904 905 /*M 906 PassiveScalar - PETSc type that represents either a double precision real number or 907 a double precision complex number if the code is compiled with BOPT=g_complex or O_complex 908 909 Level: beginner 910 911 This is the same as a PetscScalar except in code that is automatically differentiated it is 912 treated as a constant (not an indendent or dependent variable) 913 914 .seealso: PetscReal, PassiveReal, PetscScalar 915 M*/ 916 917 /*M 918 PassiveReal - PETSc type that represents a double precision real number 919 920 Level: beginner 921 922 This is the same as a PetscReal except in code that is automatically differentiated it is 923 treated as a constant (not an indendent or dependent variable) 924 925 .seealso: PetscScalar, PetscReal, PassiveScalar 926 M*/ 927 928 /* 929 The IBM include files define hz, here we hide it so that it may be used 930 as a regular user variable. 931 */ 932 #if defined(hz) 933 #undef hz 934 #endif 935 936 /* For arrays that contain filenames or paths */ 937 938 939 #if defined(PETSC_HAVE_LIMITS_H) 940 #include <limits.h> 941 #endif 942 #if defined(PETSC_HAVE_SYS_PARAM_H) 943 #include <sys/param.h> 944 #endif 945 946 #if defined(MAXPATHLEN) 947 # define PETSC_MAX_PATH_LEN MAXPATHLEN 948 #elif defined(MAX_PATH) 949 # define PETSC_MAX_PATH_LEN MAX_PATH 950 #elif defined(_MAX_PATH) 951 # define PETSC_MAX_PATH_LEN _MAX_PATH 952 #else 953 # define PETSC_MAX_PATH_LEN 4096 954 #endif 955 956 PETSC_EXTERN_CXX_END 957 #endif 958 959 960