1 /* $Id: petsc.h,v 1.107 1996/04/10 04:31: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.13, Released ???, 1996." 9 10 #include <stdio.h> 11 12 /* MPI interface */ 13 #include "mpi.h" 14 #if defined(PETSC_COMPLEX) 15 extern MPI_Datatype MPIU_COMPLEX; 16 #define MPIU_SCALAR MPIU_COMPLEX 17 #else 18 #define MPIU_SCALAR MPI_DOUBLE 19 #endif 20 21 #if defined(PETSC_COMPLEX) 22 /* work around for bug in alpha g++ compiler */ 23 #if defined(PARCH_alpha) 24 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b)) 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 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 37 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 42 extern int PetscTrDump(FILE *); 43 extern int PetscTrSpace( double *, double *,double *); 44 extern int PetscTrValid(); 45 extern int PetscTrDebugLevel(int); 46 47 extern void PetscMemcpy(void *,void *,int); 48 extern void PetscMemzero(void *,int); 49 extern int PetscMemcmp(void*, void*, 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 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 90 91 #if defined(PETSC_DEBUG) 92 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 93 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 94 MPI_Abort(MPI_COMM_WORLD,_ierr);} 95 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 96 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 97 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 98 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 99 #else 100 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 101 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 102 MPI_Abort(MPI_COMM_WORLD,_ierr);} 103 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 104 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 105 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 106 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 107 #endif 108 109 #define PETSC_COOKIE 1211211 110 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 111 extern int LARGEST_PETSC_COOKIE; 112 113 #define PETSC_DECIDE -1 114 #define PETSC_DEFAULT -2 115 116 #include "viewer.h" 117 #include "options.h" 118 119 extern int PetscGetHostName(char *,int); 120 extern double PetscGetTime(); 121 extern double PetscGetFlops(); 122 extern void PetscSleep(int); 123 124 extern int PetscInitialize(int*,char***,char*,char*); 125 extern int PetscFinalize(); 126 127 typedef struct _PetscObject* PetscObject; 128 extern int PetscObjectDestroy(PetscObject); 129 extern int PetscObjectExists(PetscObject,int*); 130 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 131 extern int PetscObjectGetCookie(PetscObject,int *cookie); 132 extern int PetscObjectGetType(PetscObject,int *type); 133 extern int PetscObjectSetName(PetscObject,char*); 134 extern int PetscObjectGetName(PetscObject,char**); 135 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **)); 136 #define PetscObjectChild(a) (((PetscObject) (a))->child) 137 138 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 139 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 140 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 141 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 142 extern int PetscError(int,char*,char*,int,char*); 143 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 144 extern int PetscPopErrorHandler(); 145 146 extern int PetscSetDebugger(char *,int,char *); 147 extern int PetscAttachDebugger(); 148 149 extern int PetscDefaultSignalHandler(int,void*); 150 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 151 extern int PetscPopSignalHandler(); 152 #define FP_TRAP_OFF 0 153 #define FP_TRAP_ON 1 154 #define FP_TRAP_ALWAYS 2 155 extern int PetscSetFPTrap(int); 156 157 158 #include "phead.h" 159 #include "plog.h" 160 161 #define PetscBarrier(A) \ 162 {PetscValidHeader(A); \ 163 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 164 MPI_Barrier(((PetscObject)A)->comm); \ 165 PLogEventEnd(Petsc_Barrier,A,0,0,0);} 166 167 /* 168 This code allows one to pass a PETSc object in C 169 to a Fortran routine, where (like all PETSc objects in 170 Fortran) it is treated as an integer. 171 */ 172 extern int PetscCObjectToFortranObject(void *a,int *b); 173 extern int PetscFortranObjectToCObject(int a,void *b); 174 175 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 176 extern int PetscFClose(MPI_Comm,FILE*); 177 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 178 extern int PetscPrintf(MPI_Comm,char *,...); 179 180 extern int PetscSetDisplay(MPI_Comm,char *,int); 181 182 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 183 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 184 185 #endif 186