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