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