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