1 /* $Id: petsc.h,v 1.162 1997/05/22 20:44:44 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 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.18, Released ??? ?, 1997." 10 11 #include <stdio.h> 12 #include "mpi.h" 13 14 #if defined(PETSC_COMPLEX) 15 #if defined(HAVE_NONSTANDARD_COMPLEX_H) 16 #include HAVE_NONSTANDARD_COMPLEX_H 17 #else 18 #include <complex.h> 19 #endif 20 extern MPI_Datatype MPIU_COMPLEX; 21 #define MPIU_SCALAR MPIU_COMPLEX 22 #define PetscReal(a) real(a) 23 #define PetscImaginary(a) imag(a) 24 #define PetscAbsScalar(a) abs(a) 25 #define PetscConj(a) conj(a) 26 /* 27 The new complex class for GNU C++ is based on templates and is not backward 28 compatible with all previous complex class libraries. 29 */ 30 #if defined(USES_TEMPLATED_COMPLEX) 31 #define Scalar complex<double> 32 #else 33 #define Scalar complex 34 #endif 35 36 /* Compiling for real numbers only */ 37 #else 38 #define MPIU_SCALAR MPI_DOUBLE 39 #define PetscReal(a) (a) 40 #define PetscImaginary(a) (a) 41 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 42 #define Scalar double 43 #define PetscConj(a) (a) 44 #endif 45 46 /* 47 Certain objects may be created using either single 48 or double precision. 49 */ 50 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision; 51 52 extern MPI_Comm PETSC_COMM_WORLD; 53 extern MPI_Comm PETSC_COMM_SELF; 54 extern int PetscInitializedCalled; 55 extern int PetscSetCommWorld(MPI_Comm); 56 57 /* PETSC_i is the imaginary number, i */ 58 extern Scalar PETSC_i; 59 60 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 61 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 62 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 63 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 64 65 /* 66 PLogDouble variables are used to contain double precision numbers 67 that are not used in the numerical computations, but rather in logging, 68 timing etc. 69 */ 70 typedef double PLogDouble; 71 /* 72 Once PETSc is compiling with a ADIC enhanced version of MPI 73 we will create a new MPI_Datatype for the inactive double variables. 74 */ 75 #if defined(AD_DERIV_H) 76 /* extern MPI_Datatype MPIU_PLOGDOUBLE; */ 77 #else 78 #if !defined(PETSC_USING_MPIUNI) 79 #define MPIU_PLOGDOUBLE MPI_DOUBLE 80 #endif 81 #endif 82 83 /* 84 Defines the malloc employed by PETSc. Users may employ these routines as well. 85 */ 86 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*); 87 extern int (*PetscTrFree)(void *,int,char*,char*,char*); 88 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*), 89 int (*)(void *,int,char*,char*,char*)); 90 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 91 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 92 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__) 93 94 extern int PetscTrDump(FILE *); 95 extern int PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *); 96 extern int PetscTrValid(int,char *,char *,char *); 97 extern int PetscTrDebugLevel(int); 98 extern int PetscTrLog(); 99 extern int PetscTrLogDump(FILE *); 100 extern int PetscGetResidentSetSize(PLogDouble *); 101 102 extern void PetscMemcpy(void *,void *,int); 103 extern void PetscMemzero(void *,int); 104 extern int PetscMemcmp(void*, void*, int); 105 extern int PetscStrlen(char *); 106 extern int PetscStrcmp(char *,char *); 107 extern int PetscStrcasecmp(char *,char *); 108 extern int PetscStrncmp(char *,char *,int ); 109 extern void PetscStrcpy(char *,char *); 110 extern void PetscStrcat(char *,char *); 111 extern void PetscStrncat(char *,char *,int); 112 extern void PetscStrncpy(char *,char *,int); 113 extern char* PetscStrchr(char *,char); 114 extern char* PetscStrrchr(char *,char); 115 extern char* PetscStrstr(char*,char*); 116 extern char* PetscStrtok(char*,char*); 117 extern char* PetscStrrtok(char*,char*); 118 119 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 120 #define PETSC_NULL 0 121 #define PETSC_DECIDE -1 122 #define PETSC_DEFAULT -2 123 124 /* 125 Each PETSc object class has it's own cookie (internal integer in the 126 data structure used for error checking). These are all defined by an offset 127 from the lowest one, PETSC_COOKIE. If you increase these you must 128 increase the field sizes in petsc/src/plog/src/plog.c 129 */ 130 #define PETSC_COOKIE 1211211 131 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 132 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 133 extern int LARGEST_PETSC_COOKIE; 134 135 #include "viewer.h" 136 #include "options.h" 137 #include "draw.h" 138 139 extern PLogDouble PetscGetTime(); 140 extern PLogDouble PetscGetCPUTime(); 141 extern void PetscSleep(int); 142 143 extern int PetscInitialize(int*,char***,char*,char*); 144 extern int PetscFinalize(); 145 extern void PetscInitializeFortran(); 146 147 /* 148 Functions that can act on any PETSc object. 149 */ 150 typedef struct _p_PetscObject* PetscObject; 151 extern int PetscObjectDestroy(PetscObject); 152 extern int PetscObjectExists(PetscObject,int*); 153 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 154 extern int PetscObjectGetCookie(PetscObject,int *cookie); 155 extern int PetscObjectGetChild(PetscObject,void **child); 156 extern int PetscObjectGetType(PetscObject,int *type); 157 extern int PetscObjectSetName(PetscObject,char*); 158 extern int PetscObjectGetName(PetscObject,char**); 159 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 160 extern int PetscObjectReference(PetscObject); 161 extern int PetscObjectGetNewTag(PetscObject,int *); 162 extern int PetscObjectRestoreNewTag(PetscObject,int *); 163 164 #include "petscerror.h" 165 #include "petschead.h" 166 #include "petsclog.h" 167 168 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 169 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 170 171 /*M 172 PetscBarrier - Blocks until this routine is executed by all 173 processors owning the object A. 174 175 Input Parameters: 176 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 177 178 Synopsis: 179 void PetscBarrier(PetscObject obj) 180 181 Notes: 182 This routine calls MPI_Barrier with the communicator 183 of the PETSc Object "A". 184 185 .keywords: barrier, petscobject 186 M*/ 187 188 #define PetscBarrier(A) \ 189 { \ 190 PetscValidHeader(A); \ 191 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 192 MPI_Barrier(((PetscObject)A)->comm); \ 193 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 194 } 195 196 extern int PetscMPIDump(FILE *); 197 198 /* 199 This code allows one to pass a PETSc object in C 200 to a Fortran routine, where (like all PETSc objects in 201 Fortran) it is treated as an integer. 202 */ 203 extern int PetscCObjectToFortranObject(void *a,int *b); 204 extern int PetscFortranObjectToCObject(int a,void *b); 205 206 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 207 extern int PetscFClose(MPI_Comm,FILE*); 208 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 209 extern int PetscPrintf(MPI_Comm,char *,...); 210 211 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 212 extern int PetscSynchronizedFlush(MPI_Comm); 213 214 /* 215 For incremental debugging 216 */ 217 extern int PetscCompare; 218 extern int PetscCompareDouble(double); 219 extern int PetscCompareScalar(Scalar); 220 extern int PetscCompareInt(int); 221 222 /* 223 For use in debuggers 224 */ 225 extern int PetscGlobalRank,PetscGlobalSize; 226 extern int PetscIntView(int,int*,Viewer); 227 extern int PetscDoubleView(int,double *,Viewer); 228 229 #endif 230