1 /* $Id: petsc.h,v 1.140 1996/10/22 18:53:02 bsmith Exp curfman $ */ 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.16, Released ???. ?, ????." 10 11 #include <stdio.h> 12 #include "mpi.h" 13 14 #if defined(PETSC_COMPLEX) 15 #if defined(PARCH_t3d) 16 #include "/usr/include/mpp/CC/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 /* 26 The new complex class for GNU C++ is based on templates and is not backward 27 compatible with all previous complex class libraries. 28 */ 29 #if defined(USES_TEMPLATED_COMPLEX) 30 #define Scalar complex<double> 31 #else 32 #define Scalar complex 33 #endif 34 35 /* Compiling for real numbers only */ 36 #else 37 #define MPIU_SCALAR MPI_DOUBLE 38 #define PetscReal(a) a 39 #define PetscImaginary(a) a 40 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 41 #define Scalar double 42 #endif 43 44 extern MPI_Comm PETSC_COMM_WORLD; 45 extern int PetscInitializedCalled; 46 extern int PetscSetCommWorld(MPI_Comm); 47 48 /* PETSC_i is the imaginary number, i */ 49 extern Scalar PETSC_i; 50 51 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 52 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 53 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 54 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 55 56 /* 57 Defines the malloc employed by PETSc. Users may employ these routines as well. 58 */ 59 extern void *(*PetscTrMalloc)(unsigned int,int,char*); 60 extern int (*PetscTrFree)(void *,int,char*); 61 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 62 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FILE__) 63 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 64 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FILE__) 65 66 extern int PetscTrDump(FILE *); 67 extern int PetscTrSpace( double *, double *,double *); 68 extern int PetscTrValid(int ,char*); 69 extern int PetscTrDebugLevel(int); 70 71 extern void PetscMemcpy(void *,void *,int); 72 extern void PetscMemzero(void *,int); 73 extern int PetscMemcmp(void*, void*, int); 74 extern int PetscStrlen(char *); 75 extern int PetscStrcmp(char *,char *); 76 extern int PetscStrncmp(char *,char *,int ); 77 extern void PetscStrcpy(char *,char *); 78 extern void PetscStrcat(char *,char *); 79 extern void PetscStrncat(char *,char *,int); 80 extern void PetscStrncpy(char *,char *,int); 81 extern char* PetscStrchr(char *,char); 82 extern char* PetscStrrchr(char *,char); 83 extern char* PetscStrstr(char*,char*); 84 extern char* PetscStrtok(char*,char*); 85 extern char* PetscStrrtok(char*,char*); 86 87 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 88 #define PETSC_NULL 0 89 #define PETSC_DECIDE -1 90 #define PETSC_DEFAULT -2 91 92 /* 93 Defines the directory where the compiled source is located; used 94 in print error messages. __DIR__ is usually defined in the makefile. 95 */ 96 #if !defined(__DIR__) 97 #define __DIR__ 0 98 #endif 99 100 /* 101 Error codes (incomplete) 102 */ 103 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 104 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 105 #define PETSC_ERR_ARG 57 /* bad input argument */ 106 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 107 #define PETSC_ERR_SIG 59 /* signal received */ 108 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 109 110 #if defined(PETSC_DEBUG) 111 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 112 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 113 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 114 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 115 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 116 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 117 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 118 #else 119 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 120 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 121 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 122 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 123 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 124 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 125 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 126 #endif 127 128 /* 129 Each PETSc object class has it's own cookie (internal integer in the 130 data structure used for error checking). These are all defined by an offset 131 from the lowest one, PETSC_COOKIE. If you increase these you must 132 increase the field sizes in petsc/src/plog/src/plog.c 133 */ 134 #define PETSC_COOKIE 1211211 135 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 136 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 137 extern int LARGEST_PETSC_COOKIE; 138 139 #include "viewer.h" 140 #include "options.h" 141 142 extern double PetscGetTime(); 143 extern void PetscSleep(int); 144 145 extern int PetscInitialize(int*,char***,char*,char*); 146 extern int PetscFinalize(); 147 extern void PetscInitializeFortran(); 148 149 /* 150 Functions that can act on any PETSc object. 151 */ 152 typedef struct _PetscObject* PetscObject; 153 extern int PetscObjectDestroy(PetscObject); 154 extern int PetscObjectExists(PetscObject,int*); 155 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 156 extern int PetscObjectGetCookie(PetscObject,int *cookie); 157 extern int PetscObjectGetChild(PetscObject,void **child); 158 extern int PetscObjectGetType(PetscObject,int *type); 159 extern int PetscObjectSetName(PetscObject,char*); 160 extern int PetscObjectGetName(PetscObject,char**); 161 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 162 extern int PetscObjectReference(PetscObject); 163 extern int PetscObjectGetNewTag(PetscObject,int *); 164 extern int PetscObjectRestoreNewTag(PetscObject,int *); 165 166 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 167 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 168 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 169 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 170 extern int PetscError(int,char*,char*,int,char*); 171 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 172 extern int PetscPopErrorHandler(); 173 174 extern int PetscDefaultSignalHandler(int,void*); 175 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 176 extern int PetscPopSignalHandler(); 177 #define PETSC_FP_TRAP_OFF 0 178 #define PETSC_FP_TRAP_ON 1 179 extern int PetscSetFPTrap(int); 180 181 #include "phead.h" 182 #include "plog.h" 183 184 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 185 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 186 187 /*M 188 PetscBarrier - Blocks Until this routine is executed by all 189 processors owning the object A. 190 191 Input Parameters: 192 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 193 194 Synopsis: 195 void PetscBarrier(PetscObject obj) 196 197 Notes: 198 This routine calls MPI_Barrier with the communicator 199 of the PETSc Object "A". 200 201 .keywords: barrier, petscobject 202 M*/ 203 204 #define PetscBarrier(A) \ 205 { \ 206 PetscValidHeader(A); \ 207 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 208 MPI_Barrier(((PetscObject)A)->comm); \ 209 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 210 } 211 212 extern int PetscMPIDump(FILE *); 213 214 /* 215 This code allows one to pass a PETSc object in C 216 to a Fortran routine, where (like all PETSc objects in 217 Fortran) it is treated as an integer. 218 */ 219 extern int PetscCObjectToFortranObject(void *a,int *b); 220 extern int PetscFortranObjectToCObject(int a,void *b); 221 222 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 223 extern int PetscFClose(MPI_Comm,FILE*); 224 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 225 extern int PetscPrintf(MPI_Comm,char *,...); 226 227 /* 228 For incremental debugging 229 */ 230 extern int PetscCompare; 231 extern int PetscCompareDouble(double); 232 extern int PetscCompareScalar(Scalar); 233 extern int PetscCompareInt(int); 234 235 /* 236 For use in debuggers 237 */ 238 extern int PetscGlobalRank,PetscGlobalSize; 239 extern int PetscIntView(int,int*,Viewer); 240 extern int PetscDoubleView(int,double *,Viewer); 241 242 #endif 243