1 /* $Id: petsc.h,v 1.260 1999/11/05 14:48:27 bsmith Exp bsmith $ */ 2 /* 3 This is the main PETSc include file (for C and C++). It is included by all 4 other PETSc include files, so it almost never has to be specifically included. 5 */ 6 #if !defined(__PETSC_H) 7 #define __PETSC_H 8 9 /* ========================================================================== */ 10 /* 11 Current PETSc version number and release date 12 */ 13 #include "petscversion.h" 14 15 /* ========================================================================== */ 16 /* 17 The PETSc configuration file. Contains various definitions that 18 handle portability issues and the presence of machine features. 19 20 petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is 21 found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH} 22 in the bmake/common definition of PETSC_INCLUDE 23 */ 24 #include "petscconf.h" 25 26 /* ========================================================================== */ 27 28 #include <stdio.h> 29 /* 30 Defines the interface to MPI allowing the use of all MPI functions. 31 */ 32 #include "mpi.h" 33 34 /* 35 Defines some elementary mathematics functions and constants. 36 */ 37 #include "petscmath.h" 38 39 /* 40 Variable type where we stash PETSc object pointers in Fortran. 41 Assumes that sizeof(long) == sizeof(void *) which is true on 42 all machines that we know. 43 */ 44 #define PetscFortranAddr long 45 46 extern MPI_Comm PETSC_COMM_WORLD; 47 extern MPI_Comm PETSC_COMM_SELF; 48 extern int PetscInitializedCalled; 49 extern int PetscSetCommWorld(MPI_Comm); 50 51 /* 52 Defines the malloc employed by PETSc. Users may use these routines as well. 53 */ 54 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 55 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 56 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 57 extern void *(*PetscTrMalloc)(int,int,char*,char*,char*); 58 extern int (*PetscTrFree)(void *,int,char*,char*,char*); 59 extern int PetscSetMalloc(void *(*)(int,int,char*,char*,char*), 60 int (*)(void *,int,char*,char*,char*)); 61 extern int PetscClearMalloc(void); 62 63 /* 64 Routines for tracing memory corruption/bleeding with default PETSc 65 memory allocation 66 */ 67 extern int PetscTrDump(FILE *); 68 extern int PetscTrSpace(PLogDouble *, PLogDouble *,PLogDouble *); 69 extern int PetscTrValid(int,const char[],const char[],const char[]); 70 extern int PetscTrDebugLevel(int); 71 extern int PetscTrLog(void); 72 extern int PetscTrLogDump(FILE *); 73 extern int PetscGetResidentSetSize(PLogDouble *); 74 75 /* 76 Constants and functions used for handling different basic data types. 77 These are used, for example, in binary IO routines 78 */ 79 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3, 80 PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType; 81 #if defined(PETSC_USE_COMPLEX) 82 #define PETSC_SCALAR PETSC_COMPLEX 83 #else 84 #define PETSC_SCALAR PETSC_DOUBLE 85 #endif 86 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double), 87 PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double), 88 PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize; 89 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 90 extern int PetscDataTypeGetSize(PetscDataType,int*); 91 extern int PetscDataTypeGetName(PetscDataType,char*[]); 92 93 /* 94 Basic PETSc constants 95 */ 96 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 97 #define PETSC_YES PETSC_TRUE 98 #define PETSC_NO PETSC_FALSE 99 #define PETSC_NULL 0 100 #define PETSC_IGNORE PETSC_NULL 101 #define PETSC_DECIDE -1 102 #define PETSC_DETERMINE PETSC_DECIDE 103 #define PETSC_DEFAULT -2 104 105 /* 106 Basic memory and string operations. These are usually simple wrappers 107 around the basic Unix system calls, but a few of them have additional 108 functionality and/or error checking. 109 */ 110 extern int PetscMemcpy(void *,const void *,int); 111 extern int PetscBitMemcpy(void*,int,const void*,int,int,PetscDataType); 112 extern int PetscMemmove(void *,void *,int); 113 extern int PetscMemzero(void *,int); 114 extern int PetscMemcmp(const void*,const void*, int,PetscTruth *); 115 extern int PetscStrlen(const char[],int*); 116 extern int PetscStrcmp(const char[],const char[],PetscTruth *); 117 extern int PetscStrgrt(const char[],const char[],PetscTruth *); 118 extern int PetscStrcasecmp(const char[],const char[],PetscTruth*); 119 extern int PetscStrncmp(const char[],const char[],int,PetscTruth*); 120 extern int PetscStrcpy(char[],const char[]); 121 extern int PetscStrcat(char[],const char[]); 122 extern int PetscStrncat(char[],const char[],int); 123 extern int PetscStrncpy(char[],const char[],int); 124 extern int PetscStrchr(const char[],char,char **); 125 extern int PetscStrrchr(const char[],char,char **); 126 extern int PetscStrstr(const char[],const char[],char **); 127 extern int PetscStrtok(const char[],const char[],char **); 128 extern int PetscStrallocpy(const char[],char **); 129 130 131 extern MPI_Op PetscMaxSum_Op; 132 #if defined(PETSC_USE_COMPLEX) 133 extern MPI_Op PetscSum_Op; 134 #else 135 #define PetscSum_Op MPI_SUM 136 #endif 137 138 /* 139 Each PETSc object class has it's own cookie (internal integer in the 140 data structure used for error checking). These are all defined by an offset 141 from the lowest one, PETSC_COOKIE. If you increase these you must 142 increase the field sizes in petsc/src/sys/src/plog/plog.c 143 */ 144 #define PETSC_COOKIE 1211211 145 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 146 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 147 extern int LARGEST_PETSC_COOKIE; 148 149 typedef struct _p_PetscObject* PetscObject; 150 typedef struct _FList *FList; 151 152 #include "viewer.h" 153 #include "options.h" 154 155 extern int PetscGetTime(PLogDouble*); 156 extern int PetscGetCPUTime(PLogDouble*); 157 extern int PetscSleep(int); 158 159 /* 160 Initialization of PETSc 161 */ 162 extern int PetscInitialize(int*,char***,char[],const char[]); 163 extern int PetscInitializeNoArguments(void); 164 extern int PetscFinalize(void); 165 extern int PetscInitializeFortran(void); 166 167 /* 168 Functions that can act on any PETSc object. 169 */ 170 extern int PetscObjectDestroy(PetscObject); 171 extern int PetscObjectExists(PetscObject,PetscTruth*); 172 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 173 extern int PetscObjectGetCookie(PetscObject,int *cookie); 174 extern int PetscObjectGetType(PetscObject,int *type); 175 extern int PetscObjectSetName(PetscObject,const char[]); 176 extern int PetscObjectGetName(PetscObject,char*[]); 177 extern int PetscObjectReference(PetscObject); 178 extern int PetscObjectGetReference(PetscObject,int*); 179 extern int PetscObjectDereference(PetscObject); 180 extern int PetscObjectGetNewTag(PetscObject,int *); 181 extern int PetscObjectRestoreNewTag(PetscObject,int *); 182 extern int PetscCommGetNewTag(MPI_Comm,int *); 183 extern int PetscCommRestoreNewTag(MPI_Comm,int *); 184 extern int PetscObjectView(PetscObject,Viewer); 185 extern int PetscObjectCompose(PetscObject,const char[],PetscObject); 186 extern int PetscObjectQuery(PetscObject,const char[],PetscObject *); 187 extern int PetscObjectComposeFunction(PetscObject,const char[],const char[],void *); 188 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 189 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 190 #else 191 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,d) 192 #endif 193 extern int PetscObjectQueryFunction(PetscObject,const char[],void **); 194 extern int PetscObjectSetOptionsPrefix(PetscObject,const char[]); 195 extern int PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 196 extern int PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 197 extern int PetscObjectGetOptionsPrefix(PetscObject,char*[]); 198 extern int PetscObjectPublish(PetscObject); 199 extern int PetscObjectChangeTypeName(PetscObject,char *); 200 extern int PetscTypeCompare(PetscObject,char*,PetscTruth*); 201 202 /* 203 Defines PETSc error handling. 204 */ 205 #include "petscerror.h" 206 207 /* 208 Mechanism for managing lists of objects attached (composed) with 209 a PETSc object. 210 */ 211 typedef struct _OList *OList; 212 extern int OListDestroy(OList *); 213 extern int OListFind(OList,const char[],PetscObject*); 214 extern int OListReverseFind(OList,PetscObject,char**); 215 extern int OListAdd(OList *,const char[],PetscObject); 216 extern int OListDuplicate(OList,OList *); 217 218 /* 219 Dynamic library lists. Lists of names of routines in dynamic 220 link libraries that will be loaded as needed. 221 */ 222 extern int FListAdd(FList*,const char[],const char[],int (*)(void *)); 223 extern int FListDestroy(FList); 224 extern int FListFind(MPI_Comm,FList,const char[],int (**)(void*)); 225 extern int FListPrintTypes(MPI_Comm,FILE*,const char[],const char[],FList); 226 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 227 #define FListAddDynamic(a,b,p,c) FListAdd(a,b,p,0) 228 #else 229 #define FListAddDynamic(a,b,p,c) FListAdd(a,b,p,(int (*)(void *))c) 230 #endif 231 extern int FListDuplicate(FList,FList *); 232 extern int FListView(FList,Viewer); 233 extern int FListConcat(const char [],const char [], char []); 234 235 /* 236 Routines for handling dynamic libraries. PETSc uses dynamic libraries 237 by default on most machines (except IBM). This is controlled by the 238 flag PETSC_USE_DYNAMIC_LIBRARIES in petscconf.h 239 */ 240 typedef struct _DLLibraryList *DLLibraryList; 241 extern DLLibraryList DLLibrariesLoaded; 242 extern int DLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *); 243 extern int DLLibraryOpen(MPI_Comm,const char[],void **); 244 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,const char[],const char[],void **); 245 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,const char[]); 246 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,const char[]); 247 extern int DLLibraryClose(DLLibraryList); 248 extern int DLLibraryPrintPath(void); 249 extern int DLLibraryGetInfo(void *,char *,char **); 250 251 /* 252 Mechanism for translating PETSc object representations between languages 253 Not currently used. 254 */ 255 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CPP} PetscLanguage; 256 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C 257 extern int PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *); 258 extern int PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **); 259 260 /* 261 Useful utility routines 262 */ 263 extern int PetscSplitOwnership(MPI_Comm,int*,int*); 264 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 265 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 266 extern int PetscBarrier(PetscObject); 267 extern int PetscMPIDump(FILE*); 268 269 /* 270 Defines basic graphics available from PETSc. 271 */ 272 #include "draw.h" 273 274 /* 275 Defines the base data structures for all PETSc objects 276 */ 277 #include "petschead.h" 278 279 /* 280 Defines PETSc profiling. 281 */ 282 #include "petsclog.h" 283 284 #if defined(PETSC_HAVE_AMS) 285 extern PetscTruth PetscAMSPublishAll; 286 #define PetscPublishAll(v)\ 287 { if (PetscAMSPublishAll) { \ 288 int __ierr;\ 289 __ierr = PetscObjectPublish((PetscObject)v);CHKERRQ(__ierr);\ 290 }} 291 #else 292 #define PetscPublishAll(v) 293 #endif 294 295 /* 296 This code allows one to pass a MPI communicator between 297 C and Fortran. MPI 2.0 defines a standard API for doing this. 298 The code here is provided to allow PETSc to work with MPI 1.1 299 standard MPI libraries. 300 */ 301 extern int MPICCommToFortranComm(MPI_Comm,int *); 302 extern int MPIFortranCommToCComm(int,MPI_Comm*); 303 304 /* 305 Simple PETSc parallel IO for ASCII printing 306 */ 307 extern int PetscFixFilename(const char[],char[]); 308 extern FILE *PetscFOpen(MPI_Comm,const char[],const char[]); 309 extern int PetscFClose(MPI_Comm,FILE*); 310 extern int PetscFPrintf(MPI_Comm,FILE*,const char[],...); 311 extern int PetscPrintf(MPI_Comm,const char[],...); 312 extern int (*PetscErrorPrintf)(const char[],...); 313 extern int (*PetscHelpPrintf)(MPI_Comm,const char[],...); 314 315 extern int PetscSynchronizedPrintf(MPI_Comm,const char[],...); 316 extern int PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...); 317 extern int PetscSynchronizedFlush(MPI_Comm); 318 319 /* 320 Simple PETSc object that contains a pointer to any required data 321 */ 322 typedef struct _p_PetscObjectContainer* PetscObjectContainer; 323 extern int PetscObjectContainerGetPointer(PetscObjectContainer,void **); 324 extern int PetscObjectContainerSetPointer(PetscObjectContainer,void *); 325 extern int PetscObjectContainerDestroy(PetscObjectContainer); 326 extern int PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *); 327 328 /* 329 For incremental debugging 330 */ 331 extern int PetscCompare; 332 extern int PetscCompareDouble(double); 333 extern int PetscCompareScalar(Scalar); 334 extern int PetscCompareInt(int); 335 336 /* 337 For use in debuggers 338 */ 339 extern int PetscGlobalRank,PetscGlobalSize; 340 extern int PetscIntView(int,int[],Viewer); 341 extern int PetscDoubleView(int,double[],Viewer); 342 extern int PetscScalarView(int,Scalar[],Viewer); 343 344 /* 345 C code optimization is often enhanced by telling the compiler 346 that certain pointer arguments to functions are not aliased to 347 to other arguments. This is not yet ANSI C standard so we define 348 the macro "restrict" to indicate that the variable is not aliased 349 to any other argument. 350 */ 351 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus) 352 #define restrict _Restrict 353 #else 354 #define restrict 355 #endif 356 357 /* 358 Determine if some of the kernel computation routines use 359 Fortran (rather than C) for the numerical calculations. On some machines 360 and compilers (like complex numbers) the Fortran version of the routines 361 is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS 362 would be set in the petscconf.h file 363 */ 364 #if defined(PETSC_USE_FORTRAN_KERNELS) 365 366 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 367 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 368 #endif 369 370 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORMSQR) 371 #define PETSC_USE_FORTRAN_KERNEL_NORMSQR 372 #endif 373 374 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 375 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 376 #endif 377 378 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 379 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 380 #endif 381 382 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 383 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 384 #endif 385 386 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 387 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 388 #endif 389 390 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 391 #define PETSC_USE_FORTRAN_KERNEL_MDOT 392 #endif 393 394 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 395 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 396 #endif 397 398 #endif 399 400 /* 401 Macros for indicating code that should be compiled with a C interface, 402 rather than a C++ interface. Any routines that are dynamically loaded 403 (such as the PCCreate_XXX() routines) must be wrapped so that the name 404 mangler does not change the functions symbol name. This just hides the 405 ugly extern "C" {} wrappers. 406 */ 407 #if defined(__cplusplus) 408 #define EXTERN_C_BEGIN extern "C" { 409 #define EXTERN_C_END } 410 #else 411 #define EXTERN_C_BEGIN 412 #define EXTERN_C_END 413 #endif 414 415 /* --------------------------------------------------------------------*/ 416 /* 417 DVF (win32) uses STDCALL calling convention by default. 418 The following is used by the fortran interface. 419 */ 420 #if defined (PETSC_USE_FORTRAN_STDCALL) 421 #define PETSC_STDCALL __stdcall 422 #else 423 #define PETSC_STDCALL 424 #endif 425 426 #endif 427