1 /* $Id: petsc.h,v 1.195 1998/01/04 20:54:50 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 ??? ??, 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 "??? ??, 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. For backward compatibility while 23 developing, this configuration is itself conditionally included. 24 */ 25 #ifdef HAVE_PETSCCONF_H 26 #include "petscconf.h" 27 #else 28 29 /* These are temporary; they contain PARCH_xxxx -> feature-specific 30 definitions */ 31 /* Common definitions (sometimes undef'ed below) */ 32 #define HAVE_READLINK 33 #define HAVE_MEMMOVE 34 35 #if defined(PARCH_sun4) 36 /* Fortran BLAS have slow dnrm2 */ 37 #define HAVE_SLOW_NRM2 38 /* Functions that we count on Sun4's having */ 39 #define HAVE_GETWD 40 #define HAVE_REALPATH 41 /* Functions that Sun4's don't have */ 42 #undef HAVE_MEMMOVE 43 #endif 44 45 #if defined(PARCH_rs6000) 46 /* Use bzero instead of memset( ,0, ) */ 47 #define PREFER_BZERO 48 /* Some versions of AIX require u_type definitions */ 49 /* #define NEED_UTYPE_TYPEDEFS */ 50 #endif 51 52 #if defined(PARCH_IRIX) || defined(PARCH_IRIX64) || defined(PARCH_IRIX5) 53 /* For some reason, we don't use readlink in grpath.c for IRIX */ 54 #undef HAVE_READLINK 55 /* gettimeofday required sys/resource.h and C++ prototype for gettimeof 56 day */ 57 #define NEEDS_GETTIMEOFDAY_PROTO 58 #endif 59 60 #if defined(PARCH_paragon) || defined(PARCH_alpha) 61 /* Some versions of these systems require u_type definitions */ 62 #define NEED_UTYPE_TYPEDEFS 63 #endif 64 #endif 65 66 /* ========================================================================== */ 67 68 #include <stdio.h> 69 /* 70 Defines the interface to MPI allowing the use of all MPI functions. 71 */ 72 #include "mpi.h" 73 74 /* 75 Defines some elementary mathematics functions and constants. 76 */ 77 #include "petscmath.h" 78 79 extern MPI_Comm PETSC_COMM_WORLD; 80 extern MPI_Comm PETSC_COMM_SELF; 81 extern int PetscInitializedCalled; 82 extern int PetscSetCommWorld(MPI_Comm); 83 84 /* 85 Defines the malloc employed by PETSc. Users may use these routines as well. 86 */ 87 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 88 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 89 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 90 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*); 91 extern int (*PetscTrFree)(void *,int,char*,char*,char*); 92 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*), 93 int (*)(void *,int,char*,char*,char*)); 94 extern int PetscClearMalloc(); 95 96 extern int PetscTrDump(FILE *); 97 extern int PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *); 98 extern int PetscTrValid(int,char *,char *,char *); 99 extern int PetscTrDebugLevel(int); 100 extern int PetscTrLog(); 101 extern int PetscTrLogDump(FILE *); 102 extern int PetscGetResidentSetSize(PLogDouble *); 103 104 #include "src/inline/bitarray.h" 105 106 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3, 107 PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType; 108 #if defined(USE_PETSC_COMPLEX) 109 #define PETSC_SCALAR PETSC_COMPLEX 110 #else 111 #define PETSC_SCALAR PETSC_DOUBLE 112 #endif 113 114 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double), 115 PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double), 116 PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize; 117 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 118 extern int PetscDataTypeGetSize(PetscDataType,int*); 119 extern int PetscDataTypeGetName(PetscDataType,char**); 120 121 /* 122 Basic memory and string operations 123 */ 124 extern int PetscMemcpy(void *,void *,int); 125 extern int PetscBitMemcpy(void*,int,void*,int,int,PetscDataType); 126 extern int PetscMemmove(void *,void *,int); 127 extern int PetscMemzero(void *,int); 128 extern int PetscMemcmp(void*, void*, int); 129 extern int PetscStrlen(char *); 130 extern int PetscStrcmp(char *,char *); 131 extern int PetscStrcasecmp(char *,char *); 132 extern int PetscStrncmp(char *,char *,int ); 133 extern int PetscStrcpy(char *,char *); 134 extern int PetscStrcat(char *,char *); 135 extern int PetscStrncat(char *,char *,int); 136 extern int PetscStrncpy(char *,char *,int); 137 extern char* PetscStrchr(char *,char); 138 extern char* PetscStrrchr(char *,char); 139 extern char* PetscStrstr(char*,char*); 140 extern char* PetscStrtok(char*,char*); 141 extern char* PetscStrrtok(char*,char*); 142 143 /* 144 Basic PETSc constants 145 */ 146 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 147 #define PETSC_NULL 0 148 #define PETSC_DECIDE -1 149 #define PETSC_DETERMINE PETSC_DECIDE 150 #define PETSC_DEFAULT -2 151 152 /* 153 Each PETSc object class has it's own cookie (internal integer in the 154 data structure used for error checking). These are all defined by an offset 155 from the lowest one, PETSC_COOKIE. If you increase these you must 156 increase the field sizes in petsc/src/plog/src/plog.c 157 */ 158 #define PETSC_COOKIE 1211211 159 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 160 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 161 extern int LARGEST_PETSC_COOKIE; 162 163 #include "viewer.h" 164 #include "options.h" 165 166 /* 167 Defines basic graphics available from PETSc. 168 */ 169 #include "draw.h" 170 171 extern PLogDouble PetscGetTime(); 172 extern PLogDouble PetscGetCPUTime(); 173 extern int PetscSleep(int); 174 175 extern int PetscInitialize(int*,char***,char*,char*); 176 extern int PetscFinalize(); 177 extern void PetscInitializeFortran(); 178 179 /* 180 Functions that can act on any PETSc object. 181 */ 182 typedef struct _p_PetscObject* PetscObject; 183 extern int PetscObjectDestroy(PetscObject); 184 extern int PetscObjectExists(PetscObject,int*); 185 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 186 extern int PetscObjectGetCookie(PetscObject,int *cookie); 187 extern int PetscObjectGetChild(PetscObject,void **child); 188 extern int PetscObjectGetType(PetscObject,int *type); 189 extern int PetscObjectSetName(PetscObject,char*); 190 extern int PetscObjectGetName(PetscObject,char**); 191 extern int PetscObjectCompose(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 192 extern int PetscObjectReference(PetscObject); 193 extern int PetscObjectDereference(PetscObject); 194 extern int PetscObjectGetNewTag(PetscObject,int *); 195 extern int PetscObjectRestoreNewTag(PetscObject,int *); 196 extern int PetscObjectView(PetscObject,Viewer); 197 198 199 /* 200 Defines PETSc error handling. 201 */ 202 #include "petscerror.h" 203 #include "petschead.h" 204 205 /* 206 Defines PETSc profiling. 207 */ 208 #include "petsclog.h" 209 210 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 211 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 212 213 /*M 214 PetscBarrier - Blocks until this routine is executed by all 215 processors owning the object A. 216 217 Input Parameters: 218 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 219 220 Synopsis: 221 void PetscBarrier(PetscObject obj) 222 223 Notes: 224 This routine calls MPI_Barrier with the communicator 225 of the PETSc Object "A". 226 227 .keywords: barrier, petscobject 228 M*/ 229 230 #define PetscBarrier(A) \ 231 { \ 232 PetscValidHeader(A); \ 233 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 234 MPI_Barrier(((PetscObject)A)->comm); \ 235 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 236 } 237 238 extern int PetscMPIDump(FILE *); 239 240 /* 241 This code allows one to pass a PETSc object in C 242 to a Fortran routine, where (like all PETSc objects in 243 Fortran) it is treated as an integer. 244 */ 245 extern int PetscCObjectToFortranObject(void *,int *); 246 extern int PetscFortranObjectToCObject(int,void *); 247 extern int MPICCommToFortranComm(MPI_Comm,int *); 248 extern int MPIFortranCommToCComm(int,MPI_Comm*); 249 250 /* 251 Simple PETSc parallel IO for ASCII printing 252 */ 253 extern int PetscFixFilename(char*); 254 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 255 extern int PetscFClose(MPI_Comm,FILE*); 256 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 257 extern int PetscPrintf(MPI_Comm,char *,...); 258 extern int (*PetscErrorPrintf)(char *,...); 259 extern int (*PetscHelpPrintf)(MPI_Comm,char *,...); 260 261 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 262 extern int PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...); 263 extern int PetscSynchronizedFlush(MPI_Comm); 264 265 /* 266 Dynamic library lists. Lists of names of routines in dynamic 267 link libraries that will be loaded as needed. 268 */ 269 typedef struct _DLList *DLList; 270 extern int DLRegister_Private(DLList,int,char*,char*,int (*)(void *),int*); 271 extern int DLCreate(int,DLList *); 272 extern int DLDestroy(DLList); 273 extern int DLFindRoutine(DLList,int,char*,int (**)(void*)); 274 extern int DLFindID(DLList,char*,int *); 275 extern int DLFindName(DLList,int,char**); 276 extern int DLDestroyAll(); 277 extern int DLPrintTypes(MPI_Comm,FILE*,char*,char *,DLList); 278 extern int DLGetTypeFromOptions(char *,char *,DLList,int *,char*,int,int *); 279 #if defined(USE_DYNAMIC_LIBRARIES) 280 #define DLRegister(a,b,c,d,e,f) DLRegister_Private(a,b,c,d,0,f) 281 #else 282 #define DLRegister(a,b,c,d,e,f) DLRegister_Private(a,b,c,d,e,f) 283 #endif 284 285 typedef struct _DLLibraryList *DLLibraryList; 286 extern DLLibraryList DLLibrariesLoaded; 287 extern int DLOpen(char *,void **); 288 extern int DLSym(DLLibraryList,char *, void **); 289 extern int DLAppend(DLLibraryList *,char *); 290 extern int DLPrepend(DLLibraryList *,char *); 291 extern int DLClose(DLLibraryList); 292 293 /* 294 C code optimization is often enhanced by telling the compiler 295 that certain pointer arguments to functions are not aliased to 296 to other arguments. This is not yet ANSI C standard so we define 297 the macro "restrict" to indicate that the variable is not aliased 298 to any other argument. 299 */ 300 #if defined(PARCH_solaris) && !defined(__cplusplus) 301 #define restrict _Restrict 302 #else 303 #define restrict 304 #endif 305 306 /* 307 For incremental debugging 308 */ 309 extern int PetscCompare; 310 extern int PetscCompareDouble(double); 311 extern int PetscCompareScalar(Scalar); 312 extern int PetscCompareInt(int); 313 314 /* 315 For use in debuggers 316 */ 317 extern int PetscGlobalRank,PetscGlobalSize; 318 extern int PetscIntView(int,int*,Viewer); 319 extern int PetscDoubleView(int,double *,Viewer); 320 321 #endif 322