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