1 /* $Id: petsc.h,v 1.46 1995/07/27 21:11:43 bsmith Exp curfman $ */ 2 3 #if !defined(__PETSC_PACKAGE) 4 #define __PETSC_PACKAGE 5 6 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.6 Released ?, 1995." 7 8 #include <stdio.h> 9 #if defined(PARCH_sun4) 10 int fprintf(FILE*,char*,...); 11 int printf(char*,...); 12 int fflush(FILE*); 13 int fclose(FILE*); 14 #endif 15 16 /* MPI interface */ 17 #include "mpi.h" 18 #include "mpiu.h" 19 20 #if defined(PETSC_COMPLEX) 21 /* work around for bug in alpha g++ compiler */ 22 #if defined(PARCH_alpha) 23 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b)) 24 /* extern double hypot(double,double); */ 25 #endif 26 #include <complex.h> 27 #define PETSCREAL(a) real(a) 28 #define Scalar complex 29 #else 30 #define PETSCREAL(a) a 31 #define Scalar double 32 #endif 33 34 extern void *(*PetscMalloc)(unsigned int,int,char*); 35 extern int (*PetscFree)(void *,int,char*); 36 #define PETSCMALLOC(a) (*PetscMalloc)(a,__LINE__,__FILE__) 37 #define PETSCFREE(a) (*PetscFree)(a,__LINE__,__FILE__) 38 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*), 39 int (*)(void *,int,char*)); 40 extern int Trdump(FILE *); 41 extern int TrGetMaximumAllocated(double*); 42 43 #define PETSCNEW(A) (A*) PETSCMALLOC(sizeof(A)) 44 #define PETSCMEMCPY(a,b,n) memcpy((char*)(a),(char*)(b),n) 45 #define PETSCMEMSET(a,b,n) memset((char*)(a),(int)(b),n) 46 #include <memory.h> 47 48 #define PETSCMIN(a,b) ( ((a)<(b)) ? (a) : (b) ) 49 #define PETSCMAX(a,b) ( ((a)<(b)) ? (b) : (a) ) 50 #define PETSCABS(a) ( (a)<0.0 ? -(a) : (a) ) 51 52 /* Macros for error checking */ 53 #if !defined(__DIR__) 54 #define __DIR__ 0 55 #endif 56 #if defined(PETSC_DEBUG) 57 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,s,n);} 58 #define SETERRA(n,s) \ 59 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\ 60 MPI_Abort(MPI_COMM_WORLD,_ierr);} 61 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 62 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 63 #define CHKPTRQ(p) if (!p) SETERRQ(1,"PETSC ERROR: No memory"); 64 #define CHKPTRA(p) if (!p) SETERRA(1,"PETSC ERROR: No memory"); 65 #else 66 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,s,n);} 67 #define SETERRA(n,s) \ 68 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\ 69 MPI_Abort(MPI_COMM_WORLD,_ierr);} 70 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 71 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 72 #define CHKPTRQ(p) if (!p) SETERRQ(1,"PETSC ERROR: No memory"); 73 #define CHKPTRA(p) if (!p) SETERRA(1,"PETSC ERROR: No memory"); 74 #endif 75 76 typedef struct _PetscObject* PetscObject; 77 #define PETSC_COOKIE 0x12121212 78 #define PETSC_DECIDE -1 79 #define PETSC_DEFAULT 0 80 81 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 82 83 #include "viewer.h" 84 #include "options.h" 85 86 extern int PetscInitialize(int*,char***,char*,char*); 87 extern int PetscFinalize(); 88 89 extern int PetscObjectDestroy(PetscObject); 90 extern int PetscObjectExists(PetscObject,int*); 91 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 92 extern int PetscObjectSetName(PetscObject,char*); 93 extern int PetscObjectGetName(PetscObject,char**); 94 95 extern int PetscDefaultErrorHandler(int,char*,char*,char*,int,void*); 96 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,void* ); 97 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,void*); 98 extern int PetscError(int,char*,char*,char*,int); 99 extern int PetscPushErrorHandler(int 100 (*handler)(int,char*,char*,char*,int,void*),void* ); 101 extern int PetscPopErrorHandler(); 102 103 extern int PetscSetDebugger(char *,int,char *); 104 extern int PetscAttachDebugger(); 105 106 extern int PetscDefaultSignalHandler(int,void*); 107 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 108 extern int PetscPopSignalHandler(); 109 extern int PetscSetFPTrap(int); 110 #define FP_TRAP_OFF 0 111 #define FP_TRAP_ON 1 112 #define FP_TRAP_ALWAYS 2 113 114 /* 115 Definitions used for the Fortran interface: 116 FORTRANCAPS: Names are uppercase, no trailing underscore 117 FORTRANUNDERSCORE: Names are lowercase, trailing underscore 118 */ 119 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d) 120 #define FORTRANCAPS 121 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux) 122 #define FORTRANUNDERSCORE 123 #endif 124 125 /* Global flop counter */ 126 extern double _TotalFlops; 127 #if defined(PETSC_LOG) 128 #define PLogFlops(n) {_TotalFlops += n;} 129 #else 130 #define PLogFlops(n) 131 #endif 132 133 /*M 134 PLogFlops - Adds floating point operations to the global counter. 135 136 Input Parameter: 137 . f - flop counter 138 139 Synopsis: 140 PLogFlops(int f) 141 142 Notes: 143 A global counter logs all PETSc flop counts. The user can use 144 PLogFlops() to increment this counter to include flops for the 145 application code. 146 147 PETSc automatically logs library events if the code has been 148 compiled with -DPETSC_LOG (which is the default), and -log, 149 -log_summary, or -log_all are specified. PLogFlops() is 150 intended for logging user flops to supplement this PETSc 151 information. 152 153 Example of Usage: 154 $ #define USER_EVENT 75 155 $ PLogEventRegister(USER_EVENT,"User event"); 156 $ PLogEventBegin(USER_EVENT,0,0,0,0); 157 $ [code segment to monitor] 158 $ PLogFlops(user_flops) 159 $ PLogEventEnd(USER_EVENT,0,0,0,0); 160 161 .seealso: PLogEventRegister(), PLogEventBegin(), PLogEventEnd() 162 163 .keywords: Petsc, log, flops, floating point operations 164 M*/ 165 166 extern int PLogPrint(MPI_Comm,FILE *); 167 extern int PLogBegin(); 168 extern int PLogAllBegin(); 169 extern int PLogDump(char*); 170 171 #endif 172