1 /* $Id: petsc.h,v 1.119 1996/05/28 21:27:58 balay 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 #define Scalar complex 25 #else 26 #define MPIU_SCALAR MPI_DOUBLE 27 #define PetscReal(a) a 28 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 29 #define Scalar double 30 #endif 31 32 extern void *(*PetscTrMalloc)(unsigned int,int,char*); 33 extern int (*PetscTrFree)(void *,int,char*); 34 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 35 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FILE__) 36 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 37 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FILE__) 38 39 extern int PetscTrDump(FILE *); 40 extern int PetscTrSpace( double *, double *,double *); 41 extern int PetscTrValid(int ,char*); 42 extern int PetscTrDebugLevel(int); 43 44 extern void PetscMemcpy(void *,void *,int); 45 extern void PetscMemzero(void *,int); 46 extern int PetscMemcmp(void*, 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 60 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 61 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 62 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 63 64 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 65 #define PETSC_NULL 0 66 #define PETSC_DECIDE -1 67 #define PETSC_DEFAULT -2 68 69 /* Macros for error checking */ 70 #if !defined(__DIR__) 71 #define __DIR__ 0 72 #endif 73 74 /* 75 Error codes (incomplete) 76 */ 77 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 78 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 79 #define PETSC_ERR_ARG 57 /* bad input argument */ 80 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 81 #define PETSC_ERR_SIG 59 /* signal received */ 82 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 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 #define PETSC_COOKIE 1211211 103 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30 104 extern int LARGEST_PETSC_COOKIE; 105 106 #include "viewer.h" 107 #include "options.h" 108 109 extern double PetscGetTime(); 110 extern double PetscGetFlops(); 111 extern void PetscSleep(int); 112 113 extern int PetscInitialize(int*,char***,char*,char*); 114 extern int PetscFinalize(); 115 extern void PetscInitializeFortran(); 116 117 typedef struct _PetscObject* PetscObject; 118 extern int PetscObjectDestroy(PetscObject); 119 extern int PetscObjectExists(PetscObject,int*); 120 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 121 extern int PetscObjectGetCookie(PetscObject,int *cookie); 122 extern int PetscObjectGetChild(PetscObject,void **child); 123 extern int PetscObjectGetType(PetscObject,int *type); 124 extern int PetscObjectSetName(PetscObject,char*); 125 extern int PetscObjectGetName(PetscObject,char**); 126 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **), 127 int (*)(void*)); 128 #define PetscObjectChild(a) (((PetscObject) (a))->child) 129 130 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 131 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 132 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 133 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 134 extern int PetscError(int,char*,char*,int,char*); 135 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 136 extern int PetscPopErrorHandler(); 137 138 extern int PetscDefaultSignalHandler(int,void*); 139 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 140 extern int PetscPopSignalHandler(); 141 #define FP_TRAP_OFF 0 142 #define FP_TRAP_ON 1 143 #define FP_TRAP_ALWAYS 2 144 extern int PetscSetFPTrap(int); 145 146 #include "phead.h" 147 #include "plog.h" 148 149 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 150 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 151 #define PetscBarrier(A) \ 152 { \ 153 PetscValidHeader(A); \ 154 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 155 MPI_Barrier(((PetscObject)A)->comm); \ 156 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 157 } 158 159 /* 160 This code allows one to pass a PETSc object in C 161 to a Fortran routine, where (like all PETSc objects in 162 Fortran) it is treated as an integer. 163 */ 164 extern int PetscCObjectToFortranObject(void *a,int *b); 165 extern int PetscFortranObjectToCObject(int a,void *b); 166 167 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 168 extern int PetscFClose(MPI_Comm,FILE*); 169 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 170 extern int PetscPrintf(MPI_Comm,char *,...); 171 172 #endif 173