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