1 /* $Id: petsc.h,v 1.101 1996/03/01 01:53:04 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 #include "mpiu.h" 27 28 #if defined(PETSC_COMPLEX) 29 /* work around for bug in alpha g++ compiler */ 30 #if defined(PARCH_alpha) 31 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b)) 32 #endif 33 #include <complex.h> 34 #define PetscReal(a) real(a) 35 #define Scalar complex 36 #else 37 #define PetscReal(a) a 38 #define Scalar double 39 #endif 40 41 extern void *(*PetscMalloc)(unsigned int,int,char*); 42 extern int (*PetscFree)(void *,int,char*); 43 #define PetscMalloc(a) (*PetscMalloc)(a,__LINE__,__FILE__) 44 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 45 #define PetscFree(a) (*PetscFree)(a,__LINE__,__FILE__) 46 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 47 48 extern int TrDump(FILE *); 49 extern int TrSpace( double *, double *,double *); 50 extern int TrValid(); 51 52 extern void PetscMemcpy(void *,void *,int); 53 extern void PetscMemzero(void *,int); 54 extern int PetscMemcmp(void*, void*, int); 55 extern int PetscStrlen(char *); 56 extern int PetscStrcmp(char *,char *); 57 extern int PetscStrncmp(char *,char *,int ); 58 extern void PetscStrcpy(char *,char *); 59 extern void PetscStrcat(char *,char *); 60 extern void PetscStrncat(char *,char *,int); 61 extern void PetscStrncpy(char *,char *,int); 62 extern char* PetscStrchr(char *,char); 63 extern char* PetscStrrchr(char *,char); 64 extern char* PetscStrstr(char*,char*); 65 extern char* PetscStrtok(char*,char*); 66 extern char* PetscStrrtok(char*,char*); 67 68 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 69 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 70 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 71 72 #define PETSC_NULL 0 73 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 74 75 #if defined(PETSC_COMPLEX) 76 #define PetscAbsScalar(a) abs(a) 77 #else 78 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 79 #endif 80 81 /* Macros for error checking */ 82 #if !defined(__DIR__) 83 #define __DIR__ 0 84 #endif 85 86 /* 87 Error codes (incomplete) 88 */ 89 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 90 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 91 #define PETSC_ERR_ARG 57 /* bad input argument */ 92 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 93 #define PETSC_ERR_SIG 59 /* signal received */ 94 95 #if defined(PETSC_DEBUG) 96 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 97 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 98 MPI_Abort(MPI_COMM_WORLD,_ierr);} 99 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 100 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 101 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 102 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 103 #else 104 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 105 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 106 MPI_Abort(MPI_COMM_WORLD,_ierr);} 107 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 108 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 109 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 110 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 111 #endif 112 113 #define PETSC_COOKIE 1211211 114 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 115 extern int LARGEST_PETSC_COOKIE; 116 117 #define PETSC_DECIDE -1 118 #define PETSC_DEFAULT -2 119 120 #include "viewer.h" 121 #include "options.h" 122 123 extern double PetscGetTime(); 124 extern double PetscGetFlops(); 125 extern void PetscSleep(int); 126 127 extern int PetscInitialize(int*,char***,char*,char*,char*); 128 extern int PetscFinalize(); 129 130 typedef struct _PetscObject* PetscObject; 131 extern int PetscObjectDestroy(PetscObject); 132 extern int PetscObjectExists(PetscObject,int*); 133 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 134 extern int PetscObjectGetCookie(PetscObject,int *cookie); 135 extern int PetscObjectGetType(PetscObject,int *type); 136 extern int PetscObjectSetName(PetscObject,char*); 137 extern int PetscObjectGetName(PetscObject,char**); 138 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **)); 139 #define PetscObjectChild(a) (((PetscObject) (a))->child) 140 141 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 142 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 143 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 144 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 145 extern int PetscError(int,char*,char*,int,char*); 146 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 147 extern int PetscPopErrorHandler(); 148 149 extern int PetscSetDebugger(char *,int,char *); 150 extern int PetscAttachDebugger(); 151 152 extern int PetscDefaultSignalHandler(int,void*); 153 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 154 extern int PetscPopSignalHandler(); 155 #define FP_TRAP_OFF 0 156 #define FP_TRAP_ON 1 157 #define FP_TRAP_ALWAYS 2 158 extern int PetscSetFPTrap(int); 159 160 161 #include "phead.h" 162 #include "plog.h" 163 164 #define PetscBarrier(A) \ 165 {PETSCVALIDHEADER(A); \ 166 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 167 MPI_Barrier(((PetscObject)A)->comm); \ 168 PLogEventEnd(Petsc_Barrier,A,0,0,0);} 169 170 #endif 171