1 /* $Id: petsc.h,v 1.197 1998/02/23 21:04:57 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 204 /* 205 Dynamic library lists. Lists of names of routines in dynamic 206 link libraries that will be loaded as needed. 207 */ 208 typedef struct _DLList *DLList; 209 extern int DLRegister_Private(DLList*,char*,char*,int (*)(void *)); 210 extern int DLRegisterCreate(DLList *); 211 extern int DLRegisterDestroy(DLList); 212 extern int DLRegisterFind(DLList,char*,int (**)(void*)); 213 extern int DLRegisterPrintTypes(MPI_Comm,FILE*,char*,char *,DLList); 214 #if defined(USE_DYNAMIC_LIBRARIES) 215 #define DLRegister(a,b,p,c) DLRegister_Private(a,b,p,0) 216 #else 217 #define DLRegister(a,b,p,c) DLRegister_Private(a,b,p,(int (*)(void *))c) 218 #endif 219 220 typedef struct _DLLibraryList *DLLibraryList; 221 extern DLLibraryList DLLibrariesLoaded; 222 extern int DLLibraryOpen(char *,void **); 223 extern int DLLibrarySym(DLLibraryList *,char*,char *, void **); 224 extern int DLLibraryAppend(DLLibraryList *,char *); 225 extern int DLLibraryPrepend(DLLibraryList *,char *); 226 extern int DLLibraryClose(DLLibraryList); 227 228 229 #include "petschead.h" 230 231 /* 232 Defines PETSc profiling. 233 */ 234 #include "petsclog.h" 235 236 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 237 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 238 239 /*M 240 PetscBarrier - Blocks until this routine is executed by all 241 processors owning the object A. 242 243 Input Parameters: 244 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 245 246 Synopsis: 247 void PetscBarrier(PetscObject obj) 248 249 Notes: 250 This routine calls MPI_Barrier with the communicator 251 of the PETSc Object "A". 252 253 .keywords: barrier, petscobject 254 M*/ 255 256 #define PetscBarrier(A) \ 257 { \ 258 PetscValidHeader(A); \ 259 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 260 MPI_Barrier(((PetscObject)A)->comm); \ 261 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 262 } 263 264 extern int PetscMPIDump(FILE *); 265 266 /* 267 This code allows one to pass a PETSc object in C 268 to a Fortran routine, where (like all PETSc objects in 269 Fortran) it is treated as an integer. 270 */ 271 extern int PetscCObjectToFortranObject(void *,int *); 272 extern int PetscFortranObjectToCObject(int,void *); 273 extern int MPICCommToFortranComm(MPI_Comm,int *); 274 extern int MPIFortranCommToCComm(int,MPI_Comm*); 275 276 /* 277 Simple PETSc parallel IO for ASCII printing 278 */ 279 extern int PetscFixFilename(char*); 280 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 281 extern int PetscFClose(MPI_Comm,FILE*); 282 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 283 extern int PetscPrintf(MPI_Comm,char *,...); 284 extern int (*PetscErrorPrintf)(char *,...); 285 extern int (*PetscHelpPrintf)(MPI_Comm,char *,...); 286 287 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 288 extern int PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...); 289 extern int PetscSynchronizedFlush(MPI_Comm); 290 291 292 /* 293 C code optimization is often enhanced by telling the compiler 294 that certain pointer arguments to functions are not aliased to 295 to other arguments. This is not yet ANSI C standard so we define 296 the macro "restrict" to indicate that the variable is not aliased 297 to any other argument. 298 */ 299 #if defined(PARCH_solaris) && !defined(__cplusplus) 300 #define restrict _Restrict 301 #else 302 #define restrict 303 #endif 304 305 /* 306 For incremental debugging 307 */ 308 extern int PetscCompare; 309 extern int PetscCompareDouble(double); 310 extern int PetscCompareScalar(Scalar); 311 extern int PetscCompareInt(int); 312 313 /* 314 For use in debuggers 315 */ 316 extern int PetscGlobalRank,PetscGlobalSize; 317 extern int PetscIntView(int,int*,Viewer); 318 extern int PetscDoubleView(int,double *,Viewer); 319 320 #endif 321