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