1 /* $Id: petsc.h,v 1.103 1996/03/19 21:30:28 bsmith Exp bsmith $ */ 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 101 #if defined(PETSC_DEBUG) 102 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 103 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 104 MPI_Abort(MPI_COMM_WORLD,_ierr);} 105 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 106 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 107 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 108 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 109 #else 110 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 111 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 112 MPI_Abort(MPI_COMM_WORLD,_ierr);} 113 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 114 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 115 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 116 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 117 #endif 118 119 #define PETSC_COOKIE 1211211 120 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 121 extern int LARGEST_PETSC_COOKIE; 122 123 #define PETSC_DECIDE -1 124 #define PETSC_DEFAULT -2 125 126 #include "viewer.h" 127 #include "options.h" 128 129 extern double PetscGetTime(); 130 extern double PetscGetFlops(); 131 extern void PetscSleep(int); 132 133 extern int PetscInitialize(int*,char***,char*,char*); 134 extern int PetscFinalize(); 135 136 typedef struct _PetscObject* PetscObject; 137 extern int PetscObjectDestroy(PetscObject); 138 extern int PetscObjectExists(PetscObject,int*); 139 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 140 extern int PetscObjectGetCookie(PetscObject,int *cookie); 141 extern int PetscObjectGetType(PetscObject,int *type); 142 extern int PetscObjectSetName(PetscObject,char*); 143 extern int PetscObjectGetName(PetscObject,char**); 144 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **)); 145 #define PetscObjectChild(a) (((PetscObject) (a))->child) 146 147 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 148 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 149 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 150 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 151 extern int PetscError(int,char*,char*,int,char*); 152 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 153 extern int PetscPopErrorHandler(); 154 155 extern int PetscSetDebugger(char *,int,char *); 156 extern int PetscAttachDebugger(); 157 158 extern int PetscDefaultSignalHandler(int,void*); 159 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 160 extern int PetscPopSignalHandler(); 161 #define FP_TRAP_OFF 0 162 #define FP_TRAP_ON 1 163 #define FP_TRAP_ALWAYS 2 164 extern int PetscSetFPTrap(int); 165 166 167 #include "phead.h" 168 #include "plog.h" 169 170 #define PetscBarrier(A) \ 171 {PetscValidHeader(A); \ 172 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 173 MPI_Barrier(((PetscObject)A)->comm); \ 174 PLogEventEnd(Petsc_Barrier,A,0,0,0);} 175 176 /* 177 This code allows one to pass a PETSc object in C 178 to a Fortran routine, where (like all PETSc objects in 179 Fortran) it is treated as an integer. 180 */ 181 extern int PetscCObjectToFortranObject(void *a,int *b); 182 extern int PetscFortranObjectToCObject(int a,void *b); 183 184 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 185 extern int PetscFClose(MPI_Comm,FILE*); 186 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 187 extern int PetscPrintf(MPI_Comm,char *,...); 188 189 extern int PetscSetDisplay(MPI_Comm,char *,int); 190 191 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 192 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 193 194 #endif 195