1 /* $Id: petsc.h,v 1.190 1997/12/04 05:25:16 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.21, Released November 13, 1997." 13 14 #define PETSC_VERSION_MAJOR 2 15 #define PETSC_VERSION_MINOR 0 16 #define PETSC_VERSION_SUBMINOR 21 17 #define PETSC_VERSION_DATE "November 13, 1997" 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 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*); 88 extern int (*PetscTrFree)(void *,int,char*,char*,char*); 89 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*), 90 int (*)(void *,int,char*,char*,char*)); 91 extern int PetscClearMalloc(); 92 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 93 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 94 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 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 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 144 #define PETSC_NULL 0 145 #define PETSC_DECIDE -1 146 #define PETSC_DETERMINE PETSC_DECIDE 147 #define PETSC_DEFAULT -2 148 149 /* 150 Each PETSc object class has it's own cookie (internal integer in the 151 data structure used for error checking). These are all defined by an offset 152 from the lowest one, PETSC_COOKIE. If you increase these you must 153 increase the field sizes in petsc/src/plog/src/plog.c 154 */ 155 #define PETSC_COOKIE 1211211 156 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 157 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 158 extern int LARGEST_PETSC_COOKIE; 159 160 #include "viewer.h" 161 #include "options.h" 162 163 /* 164 Defines basic graphics available from PETSc. 165 */ 166 #include "draw.h" 167 168 extern PLogDouble PetscGetTime(); 169 extern PLogDouble PetscGetCPUTime(); 170 extern int PetscSleep(int); 171 172 extern int PetscInitialize(int*,char***,char*,char*); 173 extern int PetscFinalize(); 174 extern void PetscInitializeFortran(); 175 176 /* 177 Functions that can act on any PETSc object. 178 */ 179 typedef struct _p_PetscObject* PetscObject; 180 extern int PetscObjectDestroy(PetscObject); 181 extern int PetscObjectExists(PetscObject,int*); 182 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 183 extern int PetscObjectGetCookie(PetscObject,int *cookie); 184 extern int PetscObjectGetChild(PetscObject,void **child); 185 extern int PetscObjectGetType(PetscObject,int *type); 186 extern int PetscObjectSetName(PetscObject,char*); 187 extern int PetscObjectGetName(PetscObject,char**); 188 extern int PetscObjectCompose(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 189 extern int PetscObjectReference(PetscObject); 190 extern int PetscObjectDereference(PetscObject); 191 extern int PetscObjectGetNewTag(PetscObject,int *); 192 extern int PetscObjectRestoreNewTag(PetscObject,int *); 193 extern int PetscObjectView(PetscObject,Viewer); 194 195 196 /* 197 Defines PETSc error handling. 198 */ 199 #include "petscerror.h" 200 #include "petschead.h" 201 202 /* 203 Defines PETSc profiling. 204 */ 205 #include "petsclog.h" 206 207 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 208 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 209 210 /*M 211 PetscBarrier - Blocks until this routine is executed by all 212 processors owning the object A. 213 214 Input Parameters: 215 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 216 217 Synopsis: 218 void PetscBarrier(PetscObject obj) 219 220 Notes: 221 This routine calls MPI_Barrier with the communicator 222 of the PETSc Object "A". 223 224 .keywords: barrier, petscobject 225 M*/ 226 227 #define PetscBarrier(A) \ 228 { \ 229 PetscValidHeader(A); \ 230 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 231 MPI_Barrier(((PetscObject)A)->comm); \ 232 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 233 } 234 235 extern int PetscMPIDump(FILE *); 236 237 /* 238 This code allows one to pass a PETSc object in C 239 to a Fortran routine, where (like all PETSc objects in 240 Fortran) it is treated as an integer. 241 */ 242 extern int PetscCObjectToFortranObject(void *,int *); 243 extern int PetscFortranObjectToCObject(int,void *); 244 extern int MPICCommToFortranComm(MPI_Comm,int *); 245 extern int MPIFortranCommToCComm(int,MPI_Comm*); 246 247 /* 248 Simple PETSc parallel IO for ASCII printing 249 */ 250 extern int PetscFixFilename(char*); 251 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 252 extern int PetscFClose(MPI_Comm,FILE*); 253 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 254 extern int PetscPrintf(MPI_Comm,char *,...); 255 extern int PetscErrorPrintf(char *,...); 256 257 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 258 extern int PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...); 259 extern int PetscSynchronizedFlush(MPI_Comm); 260 261 /* 262 C code optimization is often enhanced by telling the compiler 263 that certain pointer arguments to functions are not aliased to 264 to other arguments. This is not yet ANSI C standard so we define 265 the macro "restrict" to indicate that the variable is not aliased 266 to any other argument. 267 */ 268 #if defined(PARCH_solaris) && !defined(__cplusplus) 269 #define restrict _Restrict 270 #else 271 #define restrict 272 #endif 273 274 /* 275 For incremental debugging 276 */ 277 extern int PetscCompare; 278 extern int PetscCompareDouble(double); 279 extern int PetscCompareScalar(Scalar); 280 extern int PetscCompareInt(int); 281 282 /* 283 For use in debuggers 284 */ 285 extern int PetscGlobalRank,PetscGlobalSize; 286 extern int PetscIntView(int,int*,Viewer); 287 extern int PetscDoubleView(int,double *,Viewer); 288 289 #endif 290