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