1 /* $Id: petsc.h,v 1.121 1996/07/08 22:24:30 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.14, Released April ?, 1996." 9 10 #include <stdio.h> 11 12 #include "mpi.h" 13 14 #if defined(PETSC_COMPLEX) 15 #if defined(PARCH_t3d) 16 #include "/usr/include/mpp/CC/complex.h" 17 #else 18 #include <complex.h> 19 #endif 20 extern MPI_Datatype MPIU_COMPLEX; 21 #define MPIU_SCALAR MPIU_COMPLEX 22 #define PetscReal(a) real(a) 23 #define PetscAbsScalar(a) abs(a) 24 #if defined(USES_TEMPLATED_COMPLEX) 25 #define Scalar complex<double> 26 #else 27 #define Scalar complex 28 #endif 29 #else 30 #define MPIU_SCALAR MPI_DOUBLE 31 #define PetscReal(a) a 32 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 33 #define Scalar double 34 #endif 35 36 extern void *(*PetscTrMalloc)(unsigned int,int,char*); 37 extern int (*PetscTrFree)(void *,int,char*); 38 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 39 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FILE__) 40 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 41 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FILE__) 42 43 extern int PetscTrDump(FILE *); 44 extern int PetscTrSpace( double *, double *,double *); 45 extern int PetscTrValid(int ,char*); 46 extern int PetscTrDebugLevel(int); 47 48 extern void PetscMemcpy(void *,void *,int); 49 extern void PetscMemzero(void *,int); 50 extern int PetscMemcmp(void*, void*, int); 51 extern int PetscStrlen(char *); 52 extern int PetscStrcmp(char *,char *); 53 extern int PetscStrncmp(char *,char *,int ); 54 extern void PetscStrcpy(char *,char *); 55 extern void PetscStrcat(char *,char *); 56 extern void PetscStrncat(char *,char *,int); 57 extern void PetscStrncpy(char *,char *,int); 58 extern char* PetscStrchr(char *,char); 59 extern char* PetscStrrchr(char *,char); 60 extern char* PetscStrstr(char*,char*); 61 extern char* PetscStrtok(char*,char*); 62 extern char* PetscStrrtok(char*,char*); 63 64 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 65 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 66 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 67 68 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 69 #define PETSC_NULL 0 70 #define PETSC_DECIDE -1 71 #define PETSC_DEFAULT -2 72 73 /* Macros for error checking */ 74 #if !defined(__DIR__) 75 #define __DIR__ 0 76 #endif 77 78 /* 79 Error codes (incomplete) 80 */ 81 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 82 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 83 #define PETSC_ERR_ARG 57 /* bad input argument */ 84 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 85 #define PETSC_ERR_SIG 59 /* signal received */ 86 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 87 88 #if defined(PETSC_DEBUG) 89 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 90 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 91 MPI_Abort(MPI_COMM_WORLD,_ierr);} 92 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 93 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 94 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 95 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 96 #else 97 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 98 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 99 MPI_Abort(MPI_COMM_WORLD,_ierr);} 100 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 101 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 102 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 103 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 104 #endif 105 106 #define PETSC_COOKIE 1211211 107 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 108 extern int LARGEST_PETSC_COOKIE; 109 110 #include "viewer.h" 111 #include "options.h" 112 113 extern double PetscGetTime(); 114 extern double PetscGetFlops(); 115 extern void PetscSleep(int); 116 117 extern int PetscInitialize(int*,char***,char*,char*); 118 extern int PetscFinalize(); 119 extern void PetscInitializeFortran(); 120 121 typedef struct _PetscObject* PetscObject; 122 extern int PetscObjectDestroy(PetscObject); 123 extern int PetscObjectExists(PetscObject,int*); 124 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 125 extern int PetscObjectGetCookie(PetscObject,int *cookie); 126 extern int PetscObjectGetChild(PetscObject,void **child); 127 extern int PetscObjectGetType(PetscObject,int *type); 128 extern int PetscObjectSetName(PetscObject,char*); 129 extern int PetscObjectGetName(PetscObject,char**); 130 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **), 131 int (*)(void*)); 132 extern int PetscObjectReference(PetscObject); 133 134 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 135 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 136 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 137 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 138 extern int PetscError(int,char*,char*,int,char*); 139 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 140 extern int PetscPopErrorHandler(); 141 142 extern int PetscDefaultSignalHandler(int,void*); 143 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 144 extern int PetscPopSignalHandler(); 145 #define PETSC_FP_TRAP_OFF 0 146 #define PETSC_FP_TRAP_ON 1 147 #define PETSC_FP_TRAP_ALWAYS 2 148 extern int PetscSetFPTrap(int); 149 150 #include "phead.h" 151 #include "plog.h" 152 153 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 154 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 155 #define PetscBarrier(A) \ 156 { \ 157 PetscValidHeader(A); \ 158 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 159 MPI_Barrier(((PetscObject)A)->comm); \ 160 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 161 } 162 163 /* 164 This code allows one to pass a PETSc object in C 165 to a Fortran routine, where (like all PETSc objects in 166 Fortran) it is treated as an integer. 167 */ 168 extern int PetscCObjectToFortranObject(void *a,int *b); 169 extern int PetscFortranObjectToCObject(int a,void *b); 170 171 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 172 extern int PetscFClose(MPI_Comm,FILE*); 173 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 174 extern int PetscPrintf(MPI_Comm,char *,...); 175 176 #endif 177