1 /* $Id: petsc.h,v 1.207 1998/04/13 18:04:41 bsmith Exp bsmith $ */ 2 /* 3 This is the main PETSc include file (for C and C++). It is included by 4 all other PETSc include files so almost never has to be specifically included. 5 */ 6 #if !defined(__PETSC_PACKAGE) 7 #define __PETSC_PACKAGE 8 9 /* 10 Current PETSc Version 11 */ 12 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.22, Released April 21, 1998." 13 14 #define PETSC_VERSION_MAJOR 2 15 #define PETSC_VERSION_MINOR 0 16 #define PETSC_VERSION_SUBMINOR 22 17 #define PETSC_VERSION_DATE "April 21, 1998" 18 19 /* ========================================================================== */ 20 /* Before anything else, include the PETSc configuration file. This 21 contains various definitions that handle portability issues and the 22 presence of important features. 23 24 petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h 25 */ 26 #include "petscconf.h" 27 28 29 /* ========================================================================== */ 30 31 #include <stdio.h> 32 /* 33 Defines the interface to MPI allowing the use of all MPI functions. 34 */ 35 #include "mpi.h" 36 37 /* 38 Defines some elementary mathematics functions and constants. 39 */ 40 #include "petscmath.h" 41 /* 42 This shouuld be in petscmath.h? 43 */ 44 #if defined(HAVE_64BITS) && !defined(USE_POINTER_CONVERSION) 45 #define PetscFortranAddr long 46 #else 47 #define PetscFortranAddr int 48 #endif 49 50 extern MPI_Comm PETSC_COMM_WORLD; 51 extern MPI_Comm PETSC_COMM_SELF; 52 extern int PetscInitializedCalled; 53 extern int PetscSetCommWorld(MPI_Comm); 54 55 /* 56 Defines the malloc employed by PETSc. Users may use these routines as well. 57 */ 58 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 59 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 60 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 61 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*); 62 extern int (*PetscTrFree)(void *,int,char*,char*,char*); 63 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*), 64 int (*)(void *,int,char*,char*,char*)); 65 extern int PetscClearMalloc(void); 66 67 extern int PetscTrDump(FILE *); 68 extern int PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *); 69 extern int PetscTrValid(int,char *,char *,char *); 70 extern int PetscTrDebugLevel(int); 71 extern int PetscTrLog(void); 72 extern int PetscTrLogDump(FILE *); 73 extern int PetscGetResidentSetSize(PLogDouble *); 74 75 #include "src/inline/bitarray.h" 76 77 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3, 78 PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType; 79 #if defined(USE_PETSC_COMPLEX) 80 #define PETSC_SCALAR PETSC_COMPLEX 81 #else 82 #define PETSC_SCALAR PETSC_DOUBLE 83 #endif 84 85 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double), 86 PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double), 87 PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize; 88 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 89 extern int PetscDataTypeGetSize(PetscDataType,int*); 90 extern int PetscDataTypeGetName(PetscDataType,char**); 91 92 /* 93 Basic memory and string operations 94 */ 95 extern int PetscMemcpy(void *,void *,int); 96 extern int PetscBitMemcpy(void*,int,void*,int,int,PetscDataType); 97 extern int PetscMemmove(void *,void *,int); 98 extern int PetscMemzero(void *,int); 99 extern int PetscMemcmp(void*, void*, int); 100 extern int PetscStrlen(char *); 101 extern int PetscStrcmp(char *,char *); 102 extern int PetscStrcasecmp(char *,char *); 103 extern int PetscStrncmp(char *,char *,int ); 104 extern int PetscStrcpy(char *,char *); 105 extern int PetscStrcat(char *,char *); 106 extern int PetscStrncat(char *,char *,int); 107 extern int PetscStrncpy(char *,char *,int); 108 extern char* PetscStrchr(char *,char); 109 extern char* PetscStrrchr(char *,char); 110 extern char* PetscStrstr(char*,char*); 111 extern char* PetscStrtok(char*,char*); 112 extern char* PetscStrrtok(char*,char*); 113 114 /* 115 Basic PETSc constants 116 */ 117 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 118 #define PETSC_NULL 0 119 #define PETSC_DECIDE -1 120 #define PETSC_DETERMINE PETSC_DECIDE 121 #define PETSC_DEFAULT -2 122 123 /* 124 Each PETSc object class has it's own cookie (internal integer in the 125 data structure used for error checking). These are all defined by an offset 126 from the lowest one, PETSC_COOKIE. If you increase these you must 127 increase the field sizes in petsc/src/plog/src/plog.c 128 */ 129 #define PETSC_COOKIE 1211211 130 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 131 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 132 extern int LARGEST_PETSC_COOKIE; 133 134 #include "viewer.h" 135 #include "options.h" 136 137 /* 138 Defines basic graphics available from PETSc. 139 */ 140 #include "draw.h" 141 142 extern int PetscGetTime(PLogDouble*); 143 extern int PetscGetCPUTime(PLogDouble*); 144 extern int PetscSleep(int); 145 146 extern int PetscInitialize(int*,char***,char*,char*); 147 extern int PetscInitializeNoArguments(void); 148 extern int PetscFinalize(void); 149 extern void PetscInitializeFortran(void); 150 151 /* 152 Functions that can act on any PETSc object. 153 */ 154 typedef struct _p_PetscObject* PetscObject; 155 extern int PetscObjectDestroy(PetscObject); 156 extern int PetscObjectExists(PetscObject,int*); 157 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 158 extern int PetscObjectGetCookie(PetscObject,int *cookie); 159 extern int PetscObjectGetType(PetscObject,int *type); 160 extern int PetscObjectSetName(PetscObject,char*); 161 extern int PetscObjectGetName(PetscObject,char**); 162 extern int PetscObjectReference(PetscObject); 163 extern int PetscObjectGetReference(PetscObject,int*); 164 extern int PetscObjectDereference(PetscObject); 165 extern int PetscObjectGetNewTag(PetscObject,int *); 166 extern int PetscObjectRestoreNewTag(PetscObject,int *); 167 extern int PetscObjectView(PetscObject,Viewer); 168 169 extern int PetscObjectCompose(PetscObject,char *,PetscObject); 170 extern int PetscObjectQuery(PetscObject,char *,PetscObject *); 171 #if defined(USE_DYNAMIC_LIBRARIES) 172 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,0) 173 #else 174 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,d) 175 #endif 176 extern int PetscObjectComposeFunction_Private(PetscObject,char *,char *,void *); 177 extern int PetscObjectQueryFunction(PetscObject,char *,void **); 178 179 180 /* 181 Defines PETSc error handling. 182 */ 183 #include "petscerror.h" 184 185 /* 186 Mechanism for managing lists of objects attached (composed) with 187 a PETSc object. 188 */ 189 typedef struct _OList *OList; 190 extern int OListDestroy(OList *); 191 extern int OListFind(OList,char *,PetscObject*); 192 extern int OListAdd(OList *,char *,PetscObject); 193 extern int OListRemove(OList *,char *); 194 extern int OListDuplicate(OList,OList *); 195 196 /* 197 Dynamic library lists. Lists of names of routines in dynamic 198 link libraries that will be loaded as needed. 199 */ 200 typedef struct _DLList *DLList; 201 extern int DLRegister_Private(DLList*,char*,char*,int (*)(void *)); 202 extern int DLRegisterCreate(DLList *); 203 extern int DLRegisterDestroy(DLList); 204 extern int DLRegisterFind(MPI_Comm,DLList,char*,int (**)(void*)); 205 extern int DLRegisterPrintTypes(MPI_Comm,FILE*,char*,char *,DLList); 206 #if defined(USE_DYNAMIC_LIBRARIES) 207 #define DLRegister(a,b,p,c) DLRegister_Private(a,b,p,0) 208 #else 209 #define DLRegister(a,b,p,c) DLRegister_Private(a,b,p,(int (*)(void *))c) 210 #endif 211 212 typedef struct _DLLibraryList *DLLibraryList; 213 extern DLLibraryList DLLibrariesLoaded; 214 extern int DLLibraryOpen(MPI_Comm,char *,void **); 215 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,char*,char *, void **); 216 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,char *); 217 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,char *); 218 extern int DLLibraryClose(DLLibraryList); 219 220 221 #include "petschead.h" 222 223 /* 224 Defines PETSc profiling. 225 */ 226 #include "petsclog.h" 227 228 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 229 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 230 231 /*M 232 PetscBarrier - Blocks until this routine is executed by all 233 processors owning the object A. 234 235 Input Parameters: 236 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 237 238 Synopsis: 239 void PetscBarrier(PetscObject obj) 240 241 Notes: 242 This routine calls MPI_Barrier with the communicator 243 of the PETSc Object "A". 244 245 .keywords: barrier, petscobject 246 M*/ 247 248 #define PetscBarrier(A) \ 249 { \ 250 PetscValidHeader(A); \ 251 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 252 MPI_Barrier(((PetscObject)A)->comm); \ 253 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 254 } 255 256 extern int PetscMPIDump(FILE *); 257 258 /* 259 This code allows one to pass a PETSc object in C 260 to a Fortran routine, where (like all PETSc objects in 261 Fortran) it is treated as an integer. 262 */ 263 extern int PetscCObjectToFortranObject(void *,PetscFortranAddr *); 264 extern int PetscFortranObjectToCObject(PetscFortranAddr,void *); 265 extern int MPICCommToFortranComm(MPI_Comm,int *); 266 extern int MPIFortranCommToCComm(int,MPI_Comm*); 267 268 /* 269 Simple PETSc parallel IO for ASCII printing 270 */ 271 extern int PetscFixFilename(char*); 272 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 273 extern int PetscFClose(MPI_Comm,FILE*); 274 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 275 extern int PetscPrintf(MPI_Comm,char *,...); 276 extern int (*PetscErrorPrintf)(char *,...); 277 extern int (*PetscHelpPrintf)(MPI_Comm,char *,...); 278 279 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 280 extern int PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...); 281 extern int PetscSynchronizedFlush(MPI_Comm); 282 283 284 typedef struct _p_PetscObjectContainer* PetscObjectContainer; 285 extern int PetscObjectContainerGetPointer(PetscObjectContainer,void **); 286 extern int PetscObjectContainerSetPointer(PetscObjectContainer,void *); 287 extern int PetscObjectContainerDestroy(PetscObjectContainer); 288 extern int PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *); 289 290 /* 291 C code optimization is often enhanced by telling the compiler 292 that certain pointer arguments to functions are not aliased to 293 to other arguments. This is not yet ANSI C standard so we define 294 the macro "restrict" to indicate that the variable is not aliased 295 to any other argument. 296 */ 297 #if defined(HAVE_RESTRICT) && !defined(__cplusplus) 298 #define restrict _Restrict 299 #else 300 #define restrict 301 #endif 302 303 /* 304 For incremental debugging 305 */ 306 extern int PetscCompare; 307 extern int PetscCompareDouble(double); 308 extern int PetscCompareScalar(Scalar); 309 extern int PetscCompareInt(int); 310 311 /* 312 For use in debuggers 313 */ 314 extern int PetscGlobalRank,PetscGlobalSize; 315 extern int PetscIntView(int,int*,Viewer); 316 extern int PetscDoubleView(int,double *,Viewer); 317 318 #endif 319