xref: /petsc/include/petsc.h (revision 0752156a28ac8f8e9dfaef7ce98457a01bf27fb6)
1 /* $Id: petsc.h,v 1.178 1997/09/18 18:04:09 balay 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 /*
10    Current PETSc Version
11 */
12 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.19, Released August 13, 1997."
13 
14 #define PETSC_VERSION_MAJOR    2
15 #define PETSC_VERSION_MINOR    0
16 #define PETSC_VERSION_SUBMINOR 19
17 #define PETSC_VERSION_DATE     "August 13, 1997"
18 
19 /* Before anything else, include the PETSc configuration file.  This
20    contains various definitions that handle portability issues and the
21    presence of important features.  For backward compatibility while
22    developing, this configuration is itself conditionally included.
23  */
24 #ifdef HAVE_PETSCCONF_H
25 #include "petscconf.h"
26 #else
27 
28 /* These are temporary; they contain PARCH_xxxx -> feature-specific
29    definitions */
30 /* Common definitions (sometimes undef'ed below) */
31 #define HAVE_READLINK
32 #define HAVE_MEMMOVE
33 
34 #if defined(PARCH_sun4)
35 /* Fortran BLAS have slow dnrm2 */
36 #define HAVE_SLOW_NRM2
37 /* Functions that we count on Sun4's having */
38 #define HAVE_GETWD
39 #define HAVE_REALPATH
40 /* Functions that Sun4's don't have */
41 #undef HAVE_MEMMOVE
42 #endif
43 
44 #if defined(PARCH_rs6000)
45 /* Use bzero instead of memset( ,0, ) */
46 #define PREFER_BZERO
47 /* Some versions of AIX require u_type definitions */
48 /* #define NEED_UTYPE_TYPEDEFS */
49 #endif
50 
51 #if defined(PARCH_IRIX) || defined(PARCH_IRIX64) || defined(PARCH_IRIX5)
52 /* For some reason, we don't use readlink in grpath.c for IRIX */
53 #undef HAVE_READLINK
54 /* gettimeofday required sys/resource.h and C++ prototype for gettimeof
55    day */
56 #define NEEDS_GETTIMEOFDAY_PROTO
57 #endif
58 
59 #if defined(PARCH_paragon) ||  defined(PARCH_alpha)
60 /* Some versions of these systems require u_type definitions */
61 #define NEED_UTYPE_TYPEDEFS
62 #endif
63 #endif
64 
65 
66 #include <stdio.h>
67 /*
68     Defines the interface to MPI allowing the use of all MPI functions.
69 */
70 #include "mpi.h"
71 
72 /*
73     Defines some elementary mathematics functions and constants.
74 */
75 #include "petscmath.h"
76 
77 extern MPI_Comm PETSC_COMM_WORLD;
78 extern MPI_Comm PETSC_COMM_SELF;
79 extern int      PetscInitializedCalled;
80 extern int      PetscSetCommWorld(MPI_Comm);
81 
82 /*
83     Defines the malloc employed by PETSc. Users may employ these routines as well.
84 */
85 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
86 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
87 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
88                            int (*)(void *,int,char*,char*,char*));
89 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
90 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
91 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
92 
93 extern int   PetscTrDump(FILE *);
94 extern int   PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *);
95 extern int   PetscTrValid(int,char *,char *,char *);
96 extern int   PetscTrDebugLevel(int);
97 extern int   PetscTrLog();
98 extern int   PetscTrLogDump(FILE *);
99 extern int   PetscGetResidentSetSize(PLogDouble *);
100 
101 /*
102     Basic memory and string operations
103 */
104 extern int   PetscMemcpy(void *,void *,int);
105 extern int   PetscMemmove(void *,void *,int);
106 extern int   PetscMemzero(void *,int);
107 extern int   PetscMemcmp(void*, void*, int);
108 extern int   PetscStrlen(char *);
109 extern int   PetscStrcmp(char *,char *);
110 extern int   PetscStrcasecmp(char *,char *);
111 extern int   PetscStrncmp(char *,char *,int );
112 extern int   PetscStrcpy(char *,char *);
113 extern int   PetscStrcat(char *,char *);
114 extern int   PetscStrncat(char *,char *,int);
115 extern int   PetscStrncpy(char *,char *,int);
116 extern char* PetscStrchr(char *,char);
117 extern char* PetscStrrchr(char *,char);
118 extern char* PetscStrstr(char*,char*);
119 extern char* PetscStrtok(char*,char*);
120 extern char* PetscStrrtok(char*,char*);
121 
122 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
123 #define PETSC_NULL            0
124 #define PETSC_DECIDE         -1
125 #define PETSC_DEFAULT        -2
126 
127 /*
128     Each PETSc object class has it's own cookie (internal integer in the
129   data structure used for error checking). These are all defined by an offset
130   from the lowest one, PETSC_COOKIE. If you increase these you must
131   increase the field sizes in petsc/src/plog/src/plog.c
132 */
133 #define PETSC_COOKIE                    1211211
134 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
135 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
136 extern int LARGEST_PETSC_COOKIE;
137 
138 #include "viewer.h"
139 #include "options.h"
140 
141 /*
142     Defines basic graphics available from PETSc.
143 */
144 #include "draw.h"
145 
146 extern PLogDouble PetscGetTime();
147 extern PLogDouble PetscGetCPUTime();
148 extern void       PetscSleep(int);
149 
150 extern int    PetscInitialize(int*,char***,char*,char*);
151 extern int    PetscFinalize();
152 extern void   PetscInitializeFortran();
153 
154 /*
155     Functions that can act on any PETSc object.
156 */
157 typedef struct _p_PetscObject* PetscObject;
158 extern int PetscObjectDestroy(PetscObject);
159 extern int PetscObjectExists(PetscObject,int*);
160 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
161 extern int PetscObjectGetCookie(PetscObject,int *cookie);
162 extern int PetscObjectGetChild(PetscObject,void **child);
163 extern int PetscObjectGetType(PetscObject,int *type);
164 extern int PetscObjectSetName(PetscObject,char*);
165 extern int PetscObjectGetName(PetscObject,char**);
166 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
167 extern int PetscObjectReference(PetscObject);
168 extern int PetscObjectDereference(PetscObject);
169 extern int PetscObjectGetNewTag(PetscObject,int *);
170 extern int PetscObjectRestoreNewTag(PetscObject,int *);
171 extern int PetscObjectView(PetscObject,Viewer);
172 
173 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
174               PETSC_DCOMPLEX = 4} PetscDataType;
175 #if defined(PETSC_COMPLEX)
176 #define PETSC_SCALAR PETSC_DCOMPLEX
177 #else
178 #define PETSC_SCALAR PETSC_DOUBLE
179 #endif
180 
181 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
182               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_DCOMPLEX_SIZE = sizeof(double)}
183               PetscDataTypeSize;
184 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
185 extern int PetscDataTypeGetSize(PetscDataType,int*);
186 extern int PetscDataTypeGetName(PetscDataType,char**);
187 
188 /*
189     Defines PETSc error handling.
190 */
191 #include "petscerror.h"
192 #include "petschead.h"
193 
194 /*
195      Defines PETSc profiling.
196 */
197 #include "petsclog.h"
198 
199 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
200 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
201 
202 /*M
203     PetscBarrier - Blocks until this routine is executed by all
204                    processors owning the object A.
205 
206    Input Parameters:
207 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
208 
209    Synopsis:
210    void PetscBarrier(PetscObject obj)
211 
212   Notes:
213   This routine calls MPI_Barrier with the communicator
214   of the PETSc Object "A".
215 
216 .keywords: barrier, petscobject
217 M*/
218 
219 #define PetscBarrier(A) \
220   { \
221     PetscValidHeader(A); \
222     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
223     MPI_Barrier(((PetscObject)A)->comm); \
224     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
225   }
226 
227 extern int PetscMPIDump(FILE *);
228 
229 /*
230       This code allows one to pass a PETSc object in C
231   to a Fortran routine, where (like all PETSc objects in
232   Fortran) it is treated as an integer.
233 */
234 extern int  PetscCObjectToFortranObject(void *,int *);
235 extern int  PetscFortranObjectToCObject(int,void *);
236 extern int  MPICCommToFortranComm(MPI_Comm,int *);
237 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
238 
239 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
240 extern int  PetscFClose(MPI_Comm,FILE*);
241 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
242 extern int  PetscPrintf(MPI_Comm,char *,...);
243 
244 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
245 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...);
246 extern int  PetscSynchronizedFlush(MPI_Comm);
247 
248 /*
249    For incremental debugging
250 */
251 extern int PetscCompare;
252 extern int PetscCompareDouble(double);
253 extern int PetscCompareScalar(Scalar);
254 extern int PetscCompareInt(int);
255 
256 /*
257    For use in debuggers
258 */
259 extern int PetscGlobalRank,PetscGlobalSize;
260 extern int PetscIntView(int,int*,Viewer);
261 extern int PetscDoubleView(int,double *,Viewer);
262 
263 #endif
264