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