xref: /petsc/include/petscmath.h (revision e489efc1a86f8403e4d3526be892902891a8c83e)
1 /* $Id: petsc.h,v 1.167 1997/08/22 15:20:23 bsmith Exp gropp $ */
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 /* Version text */
10 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.19, Released August 13, 1997."
11 /* Individual version numbers and date */
12 #define PETSC_VERSION_MAJOR 2
13 #define PETSC_VERSION_MINOR 0
14 #define PETSC_VERSION_SUBMINOT 19
15 #define PETSC_VERSION_DATE  "August 13, 1997"
16 
17 /* Before anything else, include the PETSc configuration file.  This
18    contains various definitions that handle portability issues and the
19    presence of important features.  For backward compatibility while
20    developing, this configuration is itself conditionally included.
21  */
22 #ifdef HAVE_PETSCCONF_H
23 #include "petscconf.h"
24 #endif
25 
26 #include <stdio.h>
27 #include "mpi.h"
28 
29 #if defined(PETSC_COMPLEX)
30 #if defined(HAVE_NONSTANDARD_COMPLEX_H)
31 #include HAVE_NONSTANDARD_COMPLEX_H
32 #else
33 #include <complex.h>
34 #endif
35 extern  MPI_Datatype      MPIU_COMPLEX;
36 #define MPIU_SCALAR       MPIU_COMPLEX
37 #define PetscReal(a)      real(a)
38 #define PetscImaginary(a) imag(a)
39 #define PetscAbsScalar(a) abs(a)
40 #define PetscConj(a)      conj(a)
41 /*
42   The new complex class for GNU C++ is based on templates and is not backward
43   compatible with all previous complex class libraries.
44 */
45 #if defined(USES_TEMPLATED_COMPLEX)
46 #define Scalar            complex<double>
47 #else
48 #define Scalar            complex
49 #endif
50 
51 /* Compiling for real numbers only */
52 #else
53 #define MPIU_SCALAR       MPI_DOUBLE
54 #define PetscReal(a)      (a)
55 #define PetscImaginary(a) (a)
56 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
57 #define Scalar            double
58 #define PetscConj(a)      (a)
59 #endif
60 
61 /*
62    Certain objects may be created using either single
63   or double precision.
64 */
65 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision;
66 
67 extern MPI_Comm PETSC_COMM_WORLD;
68 extern MPI_Comm PETSC_COMM_SELF;
69 extern int      PetscInitializedCalled;
70 extern int      PetscSetCommWorld(MPI_Comm);
71 
72 /* PETSC_i is the imaginary number, i */
73 extern  Scalar            PETSC_i;
74 
75 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
76 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
77 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
78 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
79 
80 #define PETSC_MAX 1.e300
81 #define PETSC_MIN -1.e300
82 
83 /*
84     PLogDouble variables are used to contain double precision numbers
85   that are not used in the numerical computations, but rather in logging,
86   timing etc.
87 */
88 typedef double PLogDouble;
89 /*
90       Once PETSc is compiling with a ADIC enhanced version of MPI
91    we will create a new MPI_Datatype for the inactive double variables.
92 */
93 #if defined(AD_DERIV_H)
94 /* extern  MPI_Datatype  MPIU_PLOGDOUBLE; */
95 #else
96 #if !defined(PETSC_USING_MPIUNI)
97 #define MPIU_PLOGDOUBLE MPI_DOUBLE
98 #endif
99 #endif
100 
101 /*
102     Defines the malloc employed by PETSc. Users may employ these routines as well.
103 */
104 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
105 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
106 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
107                            int (*)(void *,int,char*,char*,char*));
108 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
109 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
110 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
111 
112 extern int   PetscTrDump(FILE *);
113 extern int   PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *);
114 extern int   PetscTrValid(int,char *,char *,char *);
115 extern int   PetscTrDebugLevel(int);
116 extern int   PetscTrLog();
117 extern int   PetscTrLogDump(FILE *);
118 extern int   PetscGetResidentSetSize(PLogDouble *);
119 
120 extern void  PetscMemcpy(void *,void *,int);
121 extern void  PetscMemmove(void *,void *,int);
122 extern void  PetscMemzero(void *,int);
123 extern int   PetscMemcmp(void*, void*, int);
124 extern int   PetscStrlen(char *);
125 extern int   PetscStrcmp(char *,char *);
126 extern int   PetscStrcasecmp(char *,char *);
127 extern int   PetscStrncmp(char *,char *,int );
128 extern void  PetscStrcpy(char *,char *);
129 extern void  PetscStrcat(char *,char *);
130 extern void  PetscStrncat(char *,char *,int);
131 extern void  PetscStrncpy(char *,char *,int);
132 extern char* PetscStrchr(char *,char);
133 extern char* PetscStrrchr(char *,char);
134 extern char* PetscStrstr(char*,char*);
135 extern char* PetscStrtok(char*,char*);
136 extern char* PetscStrrtok(char*,char*);
137 
138 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
139 #define PETSC_NULL            0
140 #define PETSC_DECIDE         -1
141 #define PETSC_DEFAULT        -2
142 
143 /*
144     Each PETSc object class has it's own cookie (internal integer in the
145   data structure used for error checking). These are all defined by an offset
146   from the lowest one, PETSC_COOKIE. If you increase these you must
147   increase the field sizes in petsc/src/plog/src/plog.c
148 */
149 #define PETSC_COOKIE                    1211211
150 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
151 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
152 extern int LARGEST_PETSC_COOKIE;
153 
154 #include "viewer.h"
155 #include "options.h"
156 #include "draw.h"
157 
158 extern PLogDouble PetscGetTime();
159 extern PLogDouble PetscGetCPUTime();
160 extern void       PetscSleep(int);
161 
162 extern int    PetscInitialize(int*,char***,char*,char*);
163 extern int    PetscFinalize();
164 extern void   PetscInitializeFortran();
165 
166 /*
167     Functions that can act on any PETSc object.
168 */
169 typedef struct _p_PetscObject* PetscObject;
170 extern int PetscObjectDestroy(PetscObject);
171 extern int PetscObjectExists(PetscObject,int*);
172 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
173 extern int PetscObjectGetCookie(PetscObject,int *cookie);
174 extern int PetscObjectGetChild(PetscObject,void **child);
175 extern int PetscObjectGetType(PetscObject,int *type);
176 extern int PetscObjectSetName(PetscObject,char*);
177 extern int PetscObjectGetName(PetscObject,char**);
178 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
179 extern int PetscObjectReference(PetscObject);
180 extern int PetscObjectGetNewTag(PetscObject,int *);
181 extern int PetscObjectRestoreNewTag(PetscObject,int *);
182 extern int PetscObjectView(PetscObject,Viewer);
183 
184 #include "petscerror.h"
185 #include "petschead.h"
186 #include "petsclog.h"
187 
188 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
189 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
190 
191 /*M
192     PetscBarrier - Blocks until this routine is executed by all
193                    processors owning the object A.
194 
195    Input Parameters:
196 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
197 
198    Synopsis:
199    void PetscBarrier(PetscObject obj)
200 
201   Notes:
202   This routine calls MPI_Barrier with the communicator
203   of the PETSc Object "A".
204 
205 .keywords: barrier, petscobject
206 M*/
207 
208 #define PetscBarrier(A) \
209   { \
210     PetscValidHeader(A); \
211     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
212     MPI_Barrier(((PetscObject)A)->comm); \
213     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
214   }
215 
216 extern int PetscMPIDump(FILE *);
217 
218 /*
219       This code allows one to pass a PETSc object in C
220   to a Fortran routine, where (like all PETSc objects in
221   Fortran) it is treated as an integer.
222 */
223 extern int  PetscCObjectToFortranObject(void *,int *);
224 extern int  PetscFortranObjectToCObject(int,void *);
225 extern int  MPICCommToFortranComm(MPI_Comm,int *);
226 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
227 
228 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
229 extern int  PetscFClose(MPI_Comm,FILE*);
230 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
231 extern int  PetscPrintf(MPI_Comm,char *,...);
232 
233 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
234 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...);
235 extern int  PetscSynchronizedFlush(MPI_Comm);
236 
237 /*
238    For incremental debugging
239 */
240 extern int PetscCompare;
241 extern int PetscCompareDouble(double);
242 extern int PetscCompareScalar(Scalar);
243 extern int PetscCompareInt(int);
244 
245 /*
246    For use in debuggers
247 */
248 extern int PetscGlobalRank,PetscGlobalSize;
249 extern int PetscIntView(int,int*,Viewer);
250 extern int PetscDoubleView(int,double *,Viewer);
251 
252 #endif
253