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