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