xref: /petsc/include/petsc.h (revision 2b36279985d181bf1ae28d424577ae2c2fbebdf4)
1 /* $Id: petsc.h,v 1.153 1997/03/26 01:38:58 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.17, Released ???. ??, 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 int      PetscInitializedCalled;
54 extern int      PetscSetCommWorld(MPI_Comm);
55 
56 /* PETSC_i is the imaginary number, i */
57 extern  Scalar            PETSC_i;
58 
59 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
60 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
61 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
62 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
63 
64 /*
65     PLogDouble variables are used to contain double precision numbers
66   that are not used in the numerical computations, but rather in logging,
67   timing etc.
68 */
69 typedef double PLogDouble;
70 
71 /*
72     Defines the malloc employed by PETSc. Users may employ these routines as well.
73 */
74 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
75 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
76 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
77                            int (*)(void *,int,char*,char*,char*));
78 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
79 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
80 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
81 
82 extern int   PetscTrDump(FILE *);
83 extern int   PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *);
84 extern int   PetscTrValid(int,char *,char *,char *);
85 extern int   PetscTrDebugLevel(int);
86 extern int   PetscTrLog();
87 extern int   PetscTrLogDump(FILE *);
88 extern int   PetscGetResidentSetSize(PLogDouble *);
89 
90 extern void  PetscMemcpy(void *,void *,int);
91 extern void  PetscMemzero(void *,int);
92 extern int   PetscMemcmp(void*, void*, int);
93 extern int   PetscStrlen(char *);
94 extern int   PetscStrcmp(char *,char *);
95 extern int   PetscStrncmp(char *,char *,int );
96 extern void  PetscStrcpy(char *,char *);
97 extern void  PetscStrcat(char *,char *);
98 extern void  PetscStrncat(char *,char *,int);
99 extern void  PetscStrncpy(char *,char *,int);
100 extern char* PetscStrchr(char *,char);
101 extern char* PetscStrrchr(char *,char);
102 extern char* PetscStrstr(char*,char*);
103 extern char* PetscStrtok(char*,char*);
104 extern char* PetscStrrtok(char*,char*);
105 
106 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
107 #define PETSC_NULL            0
108 #define PETSC_DECIDE         -1
109 #define PETSC_DEFAULT        -2
110 
111 /*
112     Each PETSc object class has it's own cookie (internal integer in the
113   data structure used for error checking). These are all defined by an offset
114   from the lowest one, PETSC_COOKIE. If you increase these you must
115   increase the field sizes in petsc/src/plog/src/plog.c
116 */
117 #define PETSC_COOKIE                    1211211
118 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
119 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
120 extern int LARGEST_PETSC_COOKIE;
121 
122 #include "viewer.h"
123 #include "options.h"
124 #include "draw.h"
125 
126 extern PLogDouble PetscGetTime();
127 extern void       PetscSleep(int);
128 
129 extern int    PetscInitialize(int*,char***,char*,char*);
130 extern int    PetscFinalize();
131 extern void   PetscInitializeFortran();
132 
133 /*
134     Functions that can act on any PETSc object.
135 */
136 typedef struct _PetscObject* PetscObject;
137 extern int PetscObjectDestroy(PetscObject);
138 extern int PetscObjectExists(PetscObject,int*);
139 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
140 extern int PetscObjectGetCookie(PetscObject,int *cookie);
141 extern int PetscObjectGetChild(PetscObject,void **child);
142 extern int PetscObjectGetType(PetscObject,int *type);
143 extern int PetscObjectSetName(PetscObject,char*);
144 extern int PetscObjectGetName(PetscObject,char**);
145 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
146 extern int PetscObjectReference(PetscObject);
147 extern int PetscObjectGetNewTag(PetscObject,int *);
148 extern int PetscObjectRestoreNewTag(PetscObject,int *);
149 
150 #include "petscerror.h"
151 #include "petschead.h"
152 #include "petsclog.h"
153 
154 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
155 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
156 
157 /*M
158     PetscBarrier - Blocks until this routine is executed by all
159                    processors owning the object A.
160 
161    Input Parameters:
162 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
163 
164    Synopsis:
165    void PetscBarrier(PetscObject obj)
166 
167   Notes:
168   This routine calls MPI_Barrier with the communicator
169   of the PETSc Object "A".
170 
171 .keywords: barrier, petscobject
172 M*/
173 
174 #define PetscBarrier(A) \
175   { \
176     PetscValidHeader(A); \
177     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
178     MPI_Barrier(((PetscObject)A)->comm); \
179     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
180   }
181 
182 extern int PetscMPIDump(FILE *);
183 
184 /*
185       This code allows one to pass a PETSc object in C
186   to a Fortran routine, where (like all PETSc objects in
187   Fortran) it is treated as an integer.
188 */
189 extern int  PetscCObjectToFortranObject(void *a,int *b);
190 extern int  PetscFortranObjectToCObject(int a,void *b);
191 
192 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
193 extern int  PetscFClose(MPI_Comm,FILE*);
194 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
195 extern int  PetscPrintf(MPI_Comm,char *,...);
196 
197 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
198 extern int  PetscSynchronizedFlush(MPI_Comm);
199 
200 /*
201    For incremental debugging
202 */
203 extern int PetscCompare;
204 extern int PetscCompareDouble(double);
205 extern int PetscCompareScalar(Scalar);
206 extern int PetscCompareInt(int);
207 
208 /*
209    For use in debuggers
210 */
211 extern int PetscGlobalRank,PetscGlobalSize;
212 extern int PetscIntView(int,int*,Viewer);
213 extern int PetscDoubleView(int,double *,Viewer);
214 
215 #endif
216