1 /* $Id: petsc.h,v 1.144 1996/12/08 20:53:01 bsmith Exp curfman $ */ 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 Dec. 10, 1996." 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 PetscImaginary(a) imag(a) 24 #define PetscAbsScalar(a) abs(a) 25 /* 26 The new complex class for GNU C++ is based on templates and is not backward 27 compatible with all previous complex class libraries. 28 */ 29 #if defined(USES_TEMPLATED_COMPLEX) 30 #define Scalar complex<double> 31 #else 32 #define Scalar complex 33 #endif 34 35 /* Compiling for real numbers only */ 36 #else 37 #define MPIU_SCALAR MPI_DOUBLE 38 #define PetscReal(a) a 39 #define PetscImaginary(a) a 40 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 41 #define Scalar double 42 #endif 43 44 extern MPI_Comm PETSC_COMM_WORLD; 45 extern int PetscInitializedCalled; 46 extern int PetscSetCommWorld(MPI_Comm); 47 48 /* PETSC_i is the imaginary number, i */ 49 extern Scalar PETSC_i; 50 51 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 52 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 53 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 54 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 55 56 /* 57 Defines the malloc employed by PETSc. Users may employ these routines as well. 58 */ 59 extern void *(*PetscTrMalloc)(unsigned int,int,char*); 60 extern int (*PetscTrFree)(void *,int,char*); 61 extern int PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*)); 62 #define PetscMalloc(a) (*PetscTrMalloc)(a,__LINE__,__FILE__) 63 #define PetscNew(A) (A*) PetscMalloc(sizeof(A)) 64 #define PetscFree(a) (*PetscTrFree)(a,__LINE__,__FILE__) 65 66 extern int PetscTrDump(FILE *); 67 extern int PetscTrSpace( double *, double *,double *); 68 extern int PetscTrValid(int ,char*); 69 extern int PetscTrDebugLevel(int); 70 71 extern void PetscMemcpy(void *,void *,int); 72 extern void PetscMemzero(void *,int); 73 extern int PetscMemcmp(void*, void*, int); 74 extern int PetscStrlen(char *); 75 extern int PetscStrcmp(char *,char *); 76 extern int PetscStrncmp(char *,char *,int ); 77 extern void PetscStrcpy(char *,char *); 78 extern void PetscStrcat(char *,char *); 79 extern void PetscStrncat(char *,char *,int); 80 extern void PetscStrncpy(char *,char *,int); 81 extern char* PetscStrchr(char *,char); 82 extern char* PetscStrrchr(char *,char); 83 extern char* PetscStrstr(char*,char*); 84 extern char* PetscStrtok(char*,char*); 85 extern char* PetscStrrtok(char*,char*); 86 87 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth; 88 #define PETSC_NULL 0 89 #define PETSC_DECIDE -1 90 #define PETSC_DEFAULT -2 91 92 /* 93 Each PETSc object class has it's own cookie (internal integer in the 94 data structure used for error checking). These are all defined by an offset 95 from the lowest one, PETSC_COOKIE. If you increase these you must 96 increase the field sizes in petsc/src/plog/src/plog.c 97 */ 98 #define PETSC_COOKIE 1211211 99 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30 100 #define LARGEST_PETSC_COOKIE_ALLOWED PETSC_COOKIE + 50 101 extern int LARGEST_PETSC_COOKIE; 102 103 #include "viewer.h" 104 #include "options.h" 105 106 extern double PetscGetTime(); 107 extern void PetscSleep(int); 108 109 extern int PetscInitialize(int*,char***,char*,char*); 110 extern int PetscFinalize(); 111 extern void PetscInitializeFortran(); 112 113 /* 114 Functions that can act on any PETSc object. 115 */ 116 typedef struct _PetscObject* PetscObject; 117 extern int PetscObjectDestroy(PetscObject); 118 extern int PetscObjectExists(PetscObject,int*); 119 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm); 120 extern int PetscObjectGetCookie(PetscObject,int *cookie); 121 extern int PetscObjectGetChild(PetscObject,void **child); 122 extern int PetscObjectGetType(PetscObject,int *type); 123 extern int PetscObjectSetName(PetscObject,char*); 124 extern int PetscObjectGetName(PetscObject,char**); 125 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*)); 126 extern int PetscObjectReference(PetscObject); 127 extern int PetscObjectGetNewTag(PetscObject,int *); 128 extern int PetscObjectRestoreNewTag(PetscObject,int *); 129 130 #include "petscerror.h" 131 #include "petschead.h" 132 #include "petsclog.h" 133 134 extern int PetscSequentialPhaseBegin(MPI_Comm,int); 135 extern int PetscSequentialPhaseEnd(MPI_Comm,int); 136 137 /*M 138 PetscBarrier - Blocks Until this routine is executed by all 139 processors owning the object A. 140 141 Input Parameters: 142 . A - PETSc object ( Mat, Vec, IS, SNES etc...) 143 144 Synopsis: 145 void PetscBarrier(PetscObject obj) 146 147 Notes: 148 This routine calls MPI_Barrier with the communicator 149 of the PETSc Object "A". 150 151 .keywords: barrier, petscobject 152 M*/ 153 154 #define PetscBarrier(A) \ 155 { \ 156 PetscValidHeader(A); \ 157 PLogEventBegin(Petsc_Barrier,A,0,0,0); \ 158 MPI_Barrier(((PetscObject)A)->comm); \ 159 PLogEventEnd(Petsc_Barrier,A,0,0,0); \ 160 } 161 162 extern int PetscMPIDump(FILE *); 163 164 /* 165 This code allows one to pass a PETSc object in C 166 to a Fortran routine, where (like all PETSc objects in 167 Fortran) it is treated as an integer. 168 */ 169 extern int PetscCObjectToFortranObject(void *a,int *b); 170 extern int PetscFortranObjectToCObject(int a,void *b); 171 172 extern FILE *PetscFOpen(MPI_Comm,char *,char *); 173 extern int PetscFClose(MPI_Comm,FILE*); 174 extern int PetscFPrintf(MPI_Comm,FILE*,char *,...); 175 extern int PetscPrintf(MPI_Comm,char *,...); 176 177 extern int PetscSynchronizedPrintf(MPI_Comm,char *,...); 178 extern int PetscSynchronizedFlush(MPI_Comm); 179 180 /* 181 For incremental debugging 182 */ 183 extern int PetscCompare; 184 extern int PetscCompareDouble(double); 185 extern int PetscCompareScalar(Scalar); 186 extern int PetscCompareInt(int); 187 188 /* 189 For use in debuggers 190 */ 191 extern int PetscGlobalRank,PetscGlobalSize; 192 extern int PetscIntView(int,int*,Viewer); 193 extern int PetscDoubleView(int,double *,Viewer); 194 195 #endif 196