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