1 /* $Id: petsc.h,v 1.139 1996/10/16 03:49:02 bsmith Exp bsmith $ */ 2 /* 3 This is the main PETSc include file (for C and C++). It is included by 4 all other PETSc include files so almost never has to be specifically included. 5 */ 6 #if !defined(__PETSC_PACKAGE) 7 #define __PETSC_PACKAGE 8 9 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.16, Released ???. ?, ????." 10 11 #include <stdio.h> 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 /* 25 The new complex class for GNU C++ is based on templates and is not backward 26 compatible with all previous complex class libraries. 27 */ 28 #if defined(USES_TEMPLATED_COMPLEX) 29 #define Scalar complex<double> 30 #else 31 #define Scalar complex 32 #endif 33 #else 34 #define MPIU_SCALAR MPI_DOUBLE 35 #define PetscReal(a) a 36 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 37 #define Scalar double 38 #endif 39 40 extern MPI_Comm PETSC_COMM_WORLD; 41 extern int PetscInitializedCalled; 42 extern int PetscSetCommWorld(MPI_Comm); 43 44 /* PETSC_i is the imaginary number, i */ 45 extern Scalar PETSC_i; 46 47 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 48 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 49 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 50 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 51 52 /* 53 Defines the malloc employed by PETSc. Users may employ these routines as well. 54 */ 55 extern void *(*PetscTrMalloc)(unsigned int,int,char*); 56 extern int (*PetscTrFree)(void *,int,char*); 57 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 58 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FILE__) 59 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 60 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FILE__) 61 62 extern int PetscTrDump(FILE *); 63 extern int PetscTrSpace( double *, double *,double *); 64 extern int PetscTrValid(int ,char*); 65 extern int PetscTrDebugLevel(int); 66 67 extern void PetscMemcpy(void *,void *,int); 68 extern void PetscMemzero(void *,int); 69 extern int PetscMemcmp(void*, void*, int); 70 extern int PetscStrlen(char *); 71 extern int PetscStrcmp(char *,char *); 72 extern int PetscStrncmp(char *,char *,int ); 73 extern void PetscStrcpy(char *,char *); 74 extern void PetscStrcat(char *,char *); 75 extern void PetscStrncat(char *,char *,int); 76 extern void PetscStrncpy(char *,char *,int); 77 extern char* PetscStrchr(char *,char); 78 extern char* PetscStrrchr(char *,char); 79 extern char* PetscStrstr(char*,char*); 80 extern char* PetscStrtok(char*,char*); 81 extern char* PetscStrrtok(char*,char*); 82 83 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 84 #define PETSC_NULL 0 85 #define PETSC_DECIDE -1 86 #define PETSC_DEFAULT -2 87 88 /* 89 Defines the directory where the compiled source is located; used 90 in print error messages. __DIR__ is usually defined in the makefile. 91 */ 92 #if !defined(__DIR__) 93 #define __DIR__ 0 94 #endif 95 96 /* 97 Error codes (incomplete) 98 */ 99 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 100 #define PETSC_ERR_SUP 56 /* no support yet for this operation */ 101 #define PETSC_ERR_ARG 57 /* bad input argument */ 102 #define PETSC_ERR_OBJ 58 /* null or corrupt PETSc object */ 103 #define PETSC_ERR_SIG 59 /* signal received */ 104 #define PETSC_ERR_SIZ 60 /* nonconforming object sizes */ 105 106 #if defined(PETSC_DEBUG) 107 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 108 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 109 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 110 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 111 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 112 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 113 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 114 #else 115 #define SETERRQ(n,s) {return PetscError(__LINE__,__DIR__,__FILE__,n,s);} 116 #define SETERRA(n,s) {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\ 117 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 118 #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} 119 #define CHKERRA(n) {if (n) SETERRA(n,(char *)0);} 120 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0); 121 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,(char*)0); 122 #endif 123 124 /* 125 Each PETSc object class has it's own cookie (internal integer in the 126 data structure used for error checking). These are all defined by an offset 127 from the lowest one, PETSC_COOKIE. If you increase these you must 128 increase the field sizes in petsc/src/plog/src/plog.c 129 */ 130 #define PETSC_COOKIE 1211211 131 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 132 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 133 extern int LARGEST_PETSC_COOKIE; 134 135 #include "viewer.h" 136 #include "options.h" 137 138 extern double PetscGetTime(); 139 extern void PetscSleep(int); 140 141 extern int PetscInitialize(int*,char***,char*,char*); 142 extern int PetscFinalize(); 143 extern void PetscInitializeFortran(); 144 145 /* 146 Functions that can act on any PETSc object. 147 */ 148 typedef struct _PetscObject* PetscObject; 149 extern int PetscObjectDestroy(PetscObject); 150 extern int PetscObjectExists(PetscObject,int*); 151 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 152 extern int PetscObjectGetCookie(PetscObject,int *cookie); 153 extern int PetscObjectGetChild(PetscObject,void **child); 154 extern int PetscObjectGetType(PetscObject,int *type); 155 extern int PetscObjectSetName(PetscObject,char*); 156 extern int PetscObjectGetName(PetscObject,char**); 157 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 158 extern int PetscObjectReference(PetscObject); 159 extern int PetscObjectGetNewTag(PetscObject,int *); 160 extern int PetscObjectRestoreNewTag(PetscObject,int *); 161 162 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*); 163 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*); 164 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* ); 165 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*); 166 extern int PetscError(int,char*,char*,int,char*); 167 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*); 168 extern int PetscPopErrorHandler(); 169 170 extern int PetscDefaultSignalHandler(int,void*); 171 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 172 extern int PetscPopSignalHandler(); 173 #define PETSC_FP_TRAP_OFF 0 174 #define PETSC_FP_TRAP_ON 1 175 extern int PetscSetFPTrap(int); 176 177 #include "phead.h" 178 #include "plog.h" 179 180 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 181 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 182 183 /*M 184 PetscBarrier - Blocks Until this routine is executed by all 185 processors owning the object A. 186 187 Input Parameters: 188 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 189 190 Synopsis: 191 void PetscBarrier(PetscObject obj) 192 193 Notes: 194 This routine calls MPI_Barrier with the communicator 195 of the PETSc Object "A". 196 197 .keywords: barrier, petscobject 198 M*/ 199 200 #define PetscBarrier(A) \ 201 { \ 202 PetscValidHeader(A); \ 203 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 204 MPI_Barrier(((PetscObject)A)->comm); \ 205 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 206 } 207 208 extern int PetscMPIDump(FILE *); 209 210 /* 211 This code allows one to pass a PETSc object in C 212 to a Fortran routine, where (like all PETSc objects in 213 Fortran) it is treated as an integer. 214 */ 215 extern int PetscCObjectToFortranObject(void *a,int *b); 216 extern int PetscFortranObjectToCObject(int a,void *b); 217 218 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 219 extern int PetscFClose(MPI_Comm,FILE*); 220 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 221 extern int PetscPrintf(MPI_Comm,char *,...); 222 223 /* 224 For incremental debugging 225 */ 226 extern int PetscCompare; 227 extern int PetscCompareDouble(double); 228 extern int PetscCompareScalar(Scalar); 229 extern int PetscCompareInt(int); 230 231 /* 232 For use in debuggers 233 */ 234 extern int PetscGlobalRank,PetscGlobalSize; 235 extern int PetscIntView(int,int*,Viewer); 236 extern int PetscDoubleView(int,double *,Viewer); 237 238 #endif 239