1 /* $Id: petsc.h,v 1.79 1995/12/21 18:34:37 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.11, Released ?." 9 10 #include <stdio.h> 11 #if defined(PARCH_sun4) && !defined(__cplusplus) 12 extern int fprintf(FILE*,const char*,...); 13 extern int printf(const char*,...); 14 extern int fflush(FILE *); 15 extern int fclose(FILE *); 16 extern void fscanf(FILE *,char *,...); 17 #endif 18 19 /* MPI interface */ 20 #include "mpi.h" 21 #include "mpiu.h" 22 23 #if defined(PETSC_COMPLEX) 24 /* work around for bug in alpha g++ compiler */ 25 #if defined(PARCH_alpha) 26 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b)) 27 #endif 28 #include <complex.h> 29 #define PETSCREAL(a) real(a) 30 #define Scalar complex 31 #else 32 #define PETSCREAL(a) a 33 #define Scalar double 34 #endif 35 36 extern void *(*PetscMalloc)(unsigned int,int,char*); 37 extern int (*PetscFree)(void *,int,char*); 38 #define PetscMalloc(a) (*PetscMalloc)(a,__LINE__,__FILE__) 39 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 40 #define PetscFree(a) (*PetscFree)(a,__LINE__,__FILE__) 41 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 42 43 extern int TrDump(FILE *); 44 extern int TrGetMaximumAllocated(double*); 45 46 extern void PetscMemcpy(void *,void *,int); 47 extern void PetscMemzero(void *,int); 48 extern int PetscMemcmp(char*, char*, int); 49 extern int PetscStrlen(char *); 50 extern int PetscStrcmp(char *,char *); 51 extern int PetscStrncmp(char *,char *,int ); 52 extern void PetscStrcpy(char *,char *); 53 extern void PetscStrcat(char *,char *); 54 extern void PetscStrncat(char *,char *,int); 55 extern void PetscStrncpy(char *,char *,int); 56 extern char* PetscStrchr(char *,char); 57 extern char* PetscStrrchr(char *,char); 58 extern char* PetscStrstr(char*,char*); 59 extern char* PetscStrtok(char*,char*); 60 extern char* PetscStrrtok(char*,char*); 61 62 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 63 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 64 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 65 66 #define PETSC_NULL 0 67 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 68 69 #if defined(PETSC_COMPLEX) 70 #define PetscAbsScalar(a) abs(a) 71 #else 72 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 73 #endif 74 75 /* Macros for error checking */ 76 #if !defined(__DIR__) 77 #define __DIR__ 0 78 #endif 79 80 /* 81 Error codes (incomplete) 82 */ 83 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 84 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 85 #define PETSC_ERR_ARG 57 /* bad input argument */ 86 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 87 88 #if defined(PETSC_DEBUG) 89 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 90 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 91 MPI_Abort(MPI_COMM_WORLD,_ierr);} 92 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 93 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 94 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 95 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 96 #else 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 #endif 105 106 typedef struct _PetscObject* PetscObject; 107 #define PETSC_COOKIE 1211211 108 #define PETSC_DECIDE -1 109 #define PETSC_DEFAULT -2 110 111 #include "viewer.h" 112 #include "options.h" 113 114 extern double PetscGetTime(); 115 extern void PetscSleep(int); 116 117 extern int PetscInitialize(int*,char***,char*,char*,char*); 118 extern int PetscFinalize(); 119 120 extern int PetscObjectDestroy(PetscObject); 121 extern int PetscObjectExists(PetscObject,int*); 122 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 123 extern int PetscObjectGetCookie(PetscObject,int *cookie); 124 extern int PetscObjectGetType(PetscObject,int *type); 125 extern int PetscObjectSetName(PetscObject,char*); 126 extern int PetscObjectGetName(PetscObject,char**); 127 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **)); 128 #define PetscObjectChild(a) (((PetscObject) (a))->child) 129 130 extern int PetscDefaultErrorHandler(int,char*,char*,int,char*,void*); 131 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 132 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 133 extern int PetscError(int,char*,char*,int,char*); 134 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 135 extern int PetscPopErrorHandler(); 136 137 extern int PetscSetDebugger(char *,int,char *); 138 extern int PetscAttachDebugger(); 139 140 extern int PetscDefaultSignalHandler(int,void*); 141 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 142 extern int PetscPopSignalHandler(); 143 #define FP_TRAP_OFF 0 144 #define FP_TRAP_ON 1 145 #define FP_TRAP_ALWAYS 2 146 extern int PetscSetFPTrap(int); 147 148 /* 149 Definitions used for the Fortran interface: 150 FORTRANCAPS: Names are uppercase, no trailing underscore 151 FORTRANUNDERSCORE: Names are lowercase, trailing underscore 152 */ 153 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d) 154 #define FORTRANCAPS 155 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux) 156 #define FORTRANUNDERSCORE 157 #endif 158 159 #include "phead.h" 160 #include "plog.h" 161 162 #endif 163