1 /* $Id: petsc.h,v 1.104 1996/03/23 18:35:47 bsmith Exp curfman $ */ 2 /* 3 PETSc header file, included in all PETSc programs. 4 */ 5 #if !defined(__PETSC_PACKAGE) 6 #define __PETSC_PACKAGE 7 8 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.13, Released ???, 1996." 9 10 #include <stdio.h> 11 12 /* 13 This is to deal with missing entries in the Gnu gcc include files 14 the Sun4 machines. It's ugly but then so is the Gnu compiler! 15 */ 16 #if defined(PARCH_sun4) && !defined(__cplusplus) && defined(_Gnu_) 17 extern int fprintf(FILE*,const char*,...); 18 extern int printf(const char*,...); 19 extern int fflush(FILE *); 20 extern int fclose(FILE *); 21 extern void fscanf(FILE *,char *,...); 22 #endif 23 24 /* MPI interface */ 25 #include "mpi.h" 26 #if defined(PETSC_COMPLEX) 27 extern MPI_Datatype MPIU_COMPLEX; 28 #define MPIU_SCALAR MPIU_COMPLEX 29 #else 30 #define MPIU_SCALAR MPI_DOUBLE 31 #endif 32 33 #if defined(PETSC_COMPLEX) 34 /* work around for bug in alpha g++ compiler */ 35 #if defined(PARCH_alpha) 36 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b)) 37 #endif 38 #include <complex.h> 39 #define PetscReal(a) real(a) 40 #define Scalar complex 41 #else 42 #define PetscReal(a) a 43 #define Scalar double 44 #endif 45 46 extern void *(*PetscMalloc)(unsigned int,int,char*); 47 extern int (*PetscFree)(void *,int,char*); 48 #define PetscMalloc(a) (*PetscMalloc)(a,__LINE__,__FILE__) 49 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 50 #define PetscFree(a) (*PetscFree)(a,__LINE__,__FILE__) 51 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 52 53 extern int PetscTrDump(FILE *); 54 extern int PetscTrSpace( double *, double *,double *); 55 extern int PetscTrValid(); 56 extern int PetscTrDebugLevel(int); 57 58 extern void PetscMemcpy(void *,void *,int); 59 extern void PetscMemzero(void *,int); 60 extern int PetscMemcmp(void*, void*, int); 61 extern int PetscStrlen(char *); 62 extern int PetscStrcmp(char *,char *); 63 extern int PetscStrncmp(char *,char *,int ); 64 extern void PetscStrcpy(char *,char *); 65 extern void PetscStrcat(char *,char *); 66 extern void PetscStrncat(char *,char *,int); 67 extern void PetscStrncpy(char *,char *,int); 68 extern char* PetscStrchr(char *,char); 69 extern char* PetscStrrchr(char *,char); 70 extern char* PetscStrstr(char*,char*); 71 extern char* PetscStrtok(char*,char*); 72 extern char* PetscStrrtok(char*,char*); 73 74 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 75 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 76 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 77 78 #define PETSC_NULL 0 79 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 80 81 #if defined(PETSC_COMPLEX) 82 #define PetscAbsScalar(a) abs(a) 83 #else 84 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 85 #endif 86 87 /* Macros for error checking */ 88 #if !defined(__DIR__) 89 #define __DIR__ 0 90 #endif 91 92 /* 93 Error codes (incomplete) 94 */ 95 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 96 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 97 #define PETSC_ERR_ARG 57 /* bad input argument */ 98 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 99 #define PETSC_ERR_SIG 59 /* signal received */ 100 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 101 102 #if defined(PETSC_DEBUG) 103 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 104 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 105 MPI_Abort(MPI_COMM_WORLD,_ierr);} 106 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 107 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 108 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 109 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 110 #else 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(MPI_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 #endif 119 120 #define PETSC_COOKIE 1211211 121 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 122 extern int LARGEST_PETSC_COOKIE; 123 124 #define PETSC_DECIDE -1 125 #define PETSC_DEFAULT -2 126 127 #include "viewer.h" 128 #include "options.h" 129 130 extern double PetscGetTime(); 131 extern double PetscGetFlops(); 132 extern void PetscSleep(int); 133 134 extern int PetscInitialize(int*,char***,char*,char*); 135 extern int PetscFinalize(); 136 137 typedef struct _PetscObject* PetscObject; 138 extern int PetscObjectDestroy(PetscObject); 139 extern int PetscObjectExists(PetscObject,int*); 140 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 141 extern int PetscObjectGetCookie(PetscObject,int *cookie); 142 extern int PetscObjectGetType(PetscObject,int *type); 143 extern int PetscObjectSetName(PetscObject,char*); 144 extern int PetscObjectGetName(PetscObject,char**); 145 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **)); 146 #define PetscObjectChild(a) (((PetscObject) (a))->child) 147 148 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 149 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 150 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 151 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 152 extern int PetscError(int,char*,char*,int,char*); 153 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 154 extern int PetscPopErrorHandler(); 155 156 extern int PetscSetDebugger(char *,int,char *); 157 extern int PetscAttachDebugger(); 158 159 extern int PetscDefaultSignalHandler(int,void*); 160 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 161 extern int PetscPopSignalHandler(); 162 #define FP_TRAP_OFF 0 163 #define FP_TRAP_ON 1 164 #define FP_TRAP_ALWAYS 2 165 extern int PetscSetFPTrap(int); 166 167 168 #include "phead.h" 169 #include "plog.h" 170 171 #define PetscBarrier(A) \ 172 {PetscValidHeader(A); \ 173 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 174 MPI_Barrier(((PetscObject)A)->comm); \ 175 PLogEventEnd(Petsc_Barrier,A,0,0,0);} 176 177 /* 178 This code allows one to pass a PETSc object in C 179 to a Fortran routine, where (like all PETSc objects in 180 Fortran) it is treated as an integer. 181 */ 182 extern int PetscCObjectToFortranObject(void *a,int *b); 183 extern int PetscFortranObjectToCObject(int a,void *b); 184 185 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 186 extern int PetscFClose(MPI_Comm,FILE*); 187 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 188 extern int PetscPrintf(MPI_Comm,char *,...); 189 190 extern int PetscSetDisplay(MPI_Comm,char *,int); 191 192 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 193 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 194 195 #endif 196