xref: /petsc/include/petsc.h (revision e1311b9049e89cb3452dcd306fde571f4b440ff2)
1 /* $Id: petsc.h,v 1.204 1998/03/31 22:39:15 bsmith Exp balay $ */
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.22, Released ??? ??, 1998."
13 
14 #define PETSC_VERSION_MAJOR    2
15 #define PETSC_VERSION_MINOR    0
16 #define PETSC_VERSION_SUBMINOR 22
17 #define PETSC_VERSION_DATE     "??? ??, 1998"
18 
19 /* ========================================================================== */
20 /* Before anything else, include the PETSc configuration file.  This
21    contains various definitions that handle portability issues and the
22    presence of important features.  For backward compatibility while
23    developing, this configuration is itself conditionally included.
24  */
25 #ifdef HAVE_PETSCCONF_H
26 #include "petscconf.h"
27 #else
28 
29 /* These are temporary; they contain PARCH_xxxx -> feature-specific
30    definitions */
31 /* Common definitions (sometimes undef'ed below) */
32 #define HAVE_READLINK
33 #define HAVE_MEMMOVE
34 
35 #if defined(PARCH_sun4)
36 /* Fortran BLAS have slow dnrm2 */
37 #define HAVE_SLOW_NRM2
38 /* Functions that we count on Sun4's having */
39 #define HAVE_GETWD
40 #define HAVE_REALPATH
41 /* Functions that Sun4's don't have */
42 #undef HAVE_MEMMOVE
43 #endif
44 
45 #if defined(PARCH_rs6000)
46 /* Use bzero instead of memset( ,0, ) */
47 #define PREFER_BZERO
48 /* Some versions of AIX require u_type definitions */
49 /* #define NEED_UTYPE_TYPEDEFS */
50 #endif
51 
52 #if defined(PARCH_IRIX) || defined(PARCH_IRIX64) || defined(PARCH_IRIX5)
53 /* For some reason, we don't use readlink in grpath.c for IRIX */
54 #undef HAVE_READLINK
55 /* gettimeofday required sys/resource.h and C++ prototype for gettimeof
56    day */
57 #define NEEDS_GETTIMEOFDAY_PROTO
58 #endif
59 
60 #if defined(PARCH_paragon) ||  defined(PARCH_alpha)
61 /* Some versions of these systems require u_type definitions */
62 #define NEED_UTYPE_TYPEDEFS
63 #endif
64 #endif
65 
66 /* ========================================================================== */
67 
68 #include <stdio.h>
69 /*
70     Defines the interface to MPI allowing the use of all MPI functions.
71 */
72 #include "mpi.h"
73 
74 /*
75     Defines some elementary mathematics functions and constants.
76 */
77 #include "petscmath.h"
78 /*
79     This shouuld be in petscmath.h?
80 */
81 #if defined(HAVE_64BITS) && !defined(USE_POINTER_CONVERSION)
82 #define PetscFortranAddr   long
83 #else
84 #define PetscFortranAddr   int
85 #endif
86 
87 extern MPI_Comm PETSC_COMM_WORLD;
88 extern MPI_Comm PETSC_COMM_SELF;
89 extern int      PetscInitializedCalled;
90 extern int      PetscSetCommWorld(MPI_Comm);
91 
92 /*
93     Defines the malloc employed by PETSc. Users may use these routines as well.
94 */
95 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
96 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
97 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
98 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
99 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
100 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
101                            int (*)(void *,int,char*,char*,char*));
102 extern int  PetscClearMalloc(void);
103 
104 extern int   PetscTrDump(FILE *);
105 extern int   PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *);
106 extern int   PetscTrValid(int,char *,char *,char *);
107 extern int   PetscTrDebugLevel(int);
108 extern int   PetscTrLog(void);
109 extern int   PetscTrLogDump(FILE *);
110 extern int   PetscGetResidentSetSize(PLogDouble *);
111 
112 #include "src/inline/bitarray.h"
113 
114 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
115               PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType;
116 #if defined(USE_PETSC_COMPLEX)
117 #define PETSC_SCALAR PETSC_COMPLEX
118 #else
119 #define PETSC_SCALAR PETSC_DOUBLE
120 #endif
121 
122 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
123               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double),
124               PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize;
125 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
126 extern int PetscDataTypeGetSize(PetscDataType,int*);
127 extern int PetscDataTypeGetName(PetscDataType,char**);
128 
129 /*
130     Basic memory and string operations
131 */
132 extern int   PetscMemcpy(void *,void *,int);
133 extern int   PetscBitMemcpy(void*,int,void*,int,int,PetscDataType);
134 extern int   PetscMemmove(void *,void *,int);
135 extern int   PetscMemzero(void *,int);
136 extern int   PetscMemcmp(void*, void*, int);
137 extern int   PetscStrlen(char *);
138 extern int   PetscStrcmp(char *,char *);
139 extern int   PetscStrcasecmp(char *,char *);
140 extern int   PetscStrncmp(char *,char *,int );
141 extern int   PetscStrcpy(char *,char *);
142 extern int   PetscStrcat(char *,char *);
143 extern int   PetscStrncat(char *,char *,int);
144 extern int   PetscStrncpy(char *,char *,int);
145 extern char* PetscStrchr(char *,char);
146 extern char* PetscStrrchr(char *,char);
147 extern char* PetscStrstr(char*,char*);
148 extern char* PetscStrtok(char*,char*);
149 extern char* PetscStrrtok(char*,char*);
150 
151 /*
152        Basic PETSc constants
153 */
154 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
155 #define PETSC_NULL            0
156 #define PETSC_DECIDE         -1
157 #define PETSC_DETERMINE      PETSC_DECIDE
158 #define PETSC_DEFAULT        -2
159 
160 /*
161     Each PETSc object class has it's own cookie (internal integer in the
162   data structure used for error checking). These are all defined by an offset
163   from the lowest one, PETSC_COOKIE. If you increase these you must
164   increase the field sizes in petsc/src/plog/src/plog.c
165 */
166 #define PETSC_COOKIE                    1211211
167 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
168 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
169 extern int LARGEST_PETSC_COOKIE;
170 
171 #include "viewer.h"
172 #include "options.h"
173 
174 /*
175     Defines basic graphics available from PETSc.
176 */
177 #include "draw.h"
178 
179 extern int PetscGetTime(PLogDouble*);
180 extern int PetscGetCPUTime(PLogDouble*);
181 extern int PetscSleep(int);
182 
183 extern int  PetscInitialize(int*,char***,char*,char*);
184 extern int  PetscInitializeNoArguments(void);
185 extern int  PetscFinalize(void);
186 extern void PetscInitializeFortran(void);
187 
188 /*
189     Functions that can act on any PETSc object.
190 */
191 typedef struct _p_PetscObject* PetscObject;
192 extern int PetscObjectDestroy(PetscObject);
193 extern int PetscObjectExists(PetscObject,int*);
194 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
195 extern int PetscObjectGetCookie(PetscObject,int *cookie);
196 extern int PetscObjectGetType(PetscObject,int *type);
197 extern int PetscObjectSetName(PetscObject,char*);
198 extern int PetscObjectGetName(PetscObject,char**);
199 extern int PetscObjectReference(PetscObject);
200 extern int PetscObjectGetReference(PetscObject,int*);
201 extern int PetscObjectDereference(PetscObject);
202 extern int PetscObjectGetNewTag(PetscObject,int *);
203 extern int PetscObjectRestoreNewTag(PetscObject,int *);
204 extern int PetscObjectView(PetscObject,Viewer);
205 
206 extern int PetscObjectCompose(PetscObject,char *,PetscObject);
207 extern int PetscObjectQuery(PetscObject,char *,PetscObject *);
208 #if defined(USE_DYNAMIC_LIBRARIES)
209 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,0)
210 #else
211 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,d)
212 #endif
213 extern int PetscObjectComposeFunction_Private(PetscObject,char *,char *,void *);
214 extern int PetscObjectQueryFunction(PetscObject,char *,void **);
215 
216 
217 /*
218     Defines PETSc error handling.
219 */
220 #include "petscerror.h"
221 
222 /*
223     Mechanism for managing lists of objects attached (composed) with
224    a PETSc object.
225 */
226 typedef struct _OList *OList;
227 extern int OListDestroy(OList *);
228 extern int OListFind(OList,char *,PetscObject*);
229 extern int OListAdd(OList *,char *,PetscObject);
230 extern int OListRemove(OList *,char *);
231 extern int OListDuplicate(OList,OList *);
232 
233 /*
234     Dynamic library lists. Lists of names of routines in dynamic
235   link libraries that will be loaded as needed.
236 */
237 typedef struct _DLList *DLList;
238 extern int    DLRegister_Private(DLList*,char*,char*,int (*)(void *));
239 extern int    DLRegisterCreate(DLList *);
240 extern int    DLRegisterDestroy(DLList);
241 extern int    DLRegisterFind(MPI_Comm,DLList,char*,int (**)(void*));
242 extern int    DLRegisterPrintTypes(MPI_Comm,FILE*,char*,char *,DLList);
243 #if defined(USE_DYNAMIC_LIBRARIES)
244 #define       DLRegister(a,b,p,c) DLRegister_Private(a,b,p,0)
245 #else
246 #define       DLRegister(a,b,p,c) DLRegister_Private(a,b,p,(int (*)(void *))c)
247 #endif
248 
249 typedef struct _DLLibraryList *DLLibraryList;
250 extern DLLibraryList DLLibrariesLoaded;
251 extern int DLLibraryOpen(MPI_Comm,char *,void **);
252 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,char*,char *, void **);
253 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,char *);
254 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,char *);
255 extern int DLLibraryClose(DLLibraryList);
256 
257 
258 #include "petschead.h"
259 
260 /*
261      Defines PETSc profiling.
262 */
263 #include "petsclog.h"
264 
265 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
266 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
267 
268 /*M
269     PetscBarrier - Blocks until this routine is executed by all
270                    processors owning the object A.
271 
272    Input Parameters:
273 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
274 
275    Synopsis:
276    void PetscBarrier(PetscObject obj)
277 
278   Notes:
279   This routine calls MPI_Barrier with the communicator
280   of the PETSc Object "A".
281 
282 .keywords: barrier, petscobject
283 M*/
284 
285 #define PetscBarrier(A) \
286   { \
287     PetscValidHeader(A); \
288     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
289     MPI_Barrier(((PetscObject)A)->comm); \
290     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
291   }
292 
293 extern int PetscMPIDump(FILE *);
294 
295 /*
296       This code allows one to pass a PETSc object in C
297   to a Fortran routine, where (like all PETSc objects in
298   Fortran) it is treated as an integer.
299 */
300 extern int  PetscCObjectToFortranObject(void *,PetscFortranAddr *);
301 extern int  PetscFortranObjectToCObject(PetscFortranAddr,void *);
302 extern int  MPICCommToFortranComm(MPI_Comm,int *);
303 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
304 
305 /*
306       Simple PETSc parallel IO for ASCII printing
307 */
308 extern int  PetscFixFilename(char*);
309 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
310 extern int  PetscFClose(MPI_Comm,FILE*);
311 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
312 extern int  PetscPrintf(MPI_Comm,char *,...);
313 extern int  (*PetscErrorPrintf)(char *,...);
314 extern int  (*PetscHelpPrintf)(MPI_Comm,char *,...);
315 
316 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
317 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...);
318 extern int  PetscSynchronizedFlush(MPI_Comm);
319 
320 
321 /*
322     C code optimization is often enhanced by telling the compiler
323   that certain pointer arguments to functions are not aliased to
324   to other arguments. This is not yet ANSI C standard so we define
325   the macro "restrict" to indicate that the variable is not aliased
326   to any other argument.
327 */
328 #if defined(HAVE_RESTRICT) && !defined(__cplusplus)
329 #define restrict _Restrict
330 #else
331 #define restrict
332 #endif
333 
334 /*
335    For incremental debugging
336 */
337 extern int PetscCompare;
338 extern int PetscCompareDouble(double);
339 extern int PetscCompareScalar(Scalar);
340 extern int PetscCompareInt(int);
341 
342 /*
343    For use in debuggers
344 */
345 extern int PetscGlobalRank,PetscGlobalSize;
346 extern int PetscIntView(int,int*,Viewer);
347 extern int PetscDoubleView(int,double *,Viewer);
348 
349 #endif
350