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