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