1 2 #if !defined(__PETSC_PACKAGE) 3 #define __PETSC_PACKAGE 4 5 #include <stdio.h> 6 #if defined(PARCH_sun4) 7 int fprintf(FILE*,char*,...); 8 int printf(char*,...); 9 int fflush(FILE*); 10 int fclose(FILE*); 11 #endif 12 13 /* MPI interface */ 14 #include "mpi.h" 15 #include "mpe.h" 16 #if defined(PETSC_COMPLEX) 17 #define MPI_SCALAR MPIR_dcomplex_dte 18 #else 19 #define MPI_SCALAR MPI_DOUBLE 20 #endif 21 extern FILE *MPE_fopen(MPI_Comm,char *,char *); 22 extern int MPE_fclose(MPI_Comm,FILE*); 23 extern int MPE_fprintf(MPI_Comm,FILE*,char *,...); 24 extern int MPE_printf(MPI_Comm,char *,...); 25 extern int MPE_Set_display(MPI_Comm,char **); 26 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 /* extern double hypot(double,double); */ 33 #endif 34 #include <complex.h> 35 #define PETSCREAL(a) real(a) 36 #define Scalar complex 37 #else 38 #define PETSCREAL(a) a 39 #define Scalar double 40 #endif 41 42 43 /* Macros for getting and freeing memory */ 44 #if defined(PETSC_MALLOC) 45 #define MALLOC(a) Trmalloc(a,__LINE__,__FILE__) 46 #define FREE(a) Trfree(a,__LINE__,__FILE__) 47 #else 48 #define MALLOC(a) malloc(a) 49 #define FREE(a) free(a) 50 #endif 51 #define NEW(a) (a *) MALLOC(sizeof(a)) 52 #define MEMCPY(a,b,n) memcpy((char*)(a),(char*)(b),n) 53 #define MEMSET(a,b,n) memset((char*)(a),(int)(b),n) 54 #include <memory.h> 55 56 /* Macros for error checking */ 57 #if !defined(__DIR__) 58 #define __DIR__ 0 59 #endif 60 #if defined(PETSC_DEBUG) 61 #define SETERR(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,s,n);} 62 #define SETERRA(n,s) \ 63 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\ 64 MPI_Abort(MPI_COMM_WORLD,_ierr);} 65 #define CHKERR(n) {if (n) SETERR(n,(char *)0);} 66 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 67 #define CHKPTR(p) if (!p) SETERR(1,"No memory"); 68 #define CHKPTRA(p) if (!p) SETERRA(1,"No memory"); 69 #else 70 #define SETERR(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,s,n);} 71 #define SETERRA(n,s) \ 72 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\ 73 MPI_Abort(MPI_COMM_WORLD,_ierr);} 74 #define CHKERR(n) {if (n) SETERR(n,(char *)0);} 75 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 76 #define CHKPTR(p) if (!p) SETERR(1,"No memory"); 77 #define CHKPTRA(p) if (!p) SETERRA(1,"No memory"); 78 #endif 79 80 typedef struct _PetscObject* PetscObject; 81 #define PETSC_COOKIE 0x12121212 82 #define PETSC_DECIDE -1 83 84 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 85 86 #include "viewer.h" 87 88 /* useful Petsc routines (used often) */ 89 extern int PetscInitialize(int*,char***,char*,char*); 90 extern int PetscFinalize(); 91 92 extern int PetscDestroy(PetscObject); 93 extern int PetscObjectSetName(PetscObject,char*); 94 extern int PetscObjectGetName(PetscObject,char**); 95 96 extern int PetscDefaultErrorHandler(int,char*,char*,char*,int,void*); 97 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,void* ); 98 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,void*); 99 extern int PetscError(int,char*,char*,char*,int); 100 extern int PetscPushErrorHandler(int 101 (*handler)(int,char*,char*,char*,int,void*),void* ); 102 extern int PetscPopErrorHandler(); 103 104 extern int PetscSetDebugger(char *,int,char *); 105 extern int PetscAttachDebugger(); 106 107 extern int PetscDefaultSignalHandler(int,void*); 108 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 109 extern int PetscPopSignalHandler(); 110 extern int PetscSetFPTrap(int); 111 #define FP_TRAP_OFF 0 112 #define FP_TRAP_ON 1 113 #define FP_TRAP_ALWAYS 2 114 115 #if defined(PETSC_MALLOC) 116 extern void *Trmalloc(unsigned int,int,char*); 117 extern int Trfree(void *,int,char*); 118 extern int Trdump(FILE *); 119 #else 120 #include <malloc.h> 121 #endif 122 123 #if defined(PARCH_cray) || defined(PARCH_NCUBE) 124 #define FORTRANCAPS 125 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_HPUX) 126 #define FORTRANUNDERSCORE 127 #endif 128 129 #include <stdio.h> /* I don't like this, but? */ 130 131 /* Global flop counter */ 132 extern double _TotalFlops; 133 #if defined(PETSC_LOG) 134 #define PLogFlops(n) {_TotalFlops += n;} 135 #else 136 #define PLogFlops(n) 137 #endif 138 139 #endif 140