xref: /petsc/include/petsc.h (revision ecf371e4f11dc92d760a8a34d4f20e65e993c904)
1 /* $Id: petsc.h,v 1.199 1998/03/16 21:51:32 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.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 extern MPI_Comm PETSC_COMM_WORLD;
80 extern MPI_Comm PETSC_COMM_SELF;
81 extern int      PetscInitializedCalled;
82 extern int      PetscSetCommWorld(MPI_Comm);
83 
84 /*
85     Defines the malloc employed by PETSc. Users may use these routines as well.
86 */
87 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
88 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
89 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
90 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
91 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
92 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
93                            int (*)(void *,int,char*,char*,char*));
94 extern int  PetscClearMalloc();
95 
96 extern int   PetscTrDump(FILE *);
97 extern int   PetscTrSpace( PLogDouble *, PLogDouble *,PLogDouble *);
98 extern int   PetscTrValid(int,char *,char *,char *);
99 extern int   PetscTrDebugLevel(int);
100 extern int   PetscTrLog();
101 extern int   PetscTrLogDump(FILE *);
102 extern int   PetscGetResidentSetSize(PLogDouble *);
103 
104 #include "src/inline/bitarray.h"
105 
106 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
107               PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType;
108 #if defined(USE_PETSC_COMPLEX)
109 #define PETSC_SCALAR PETSC_COMPLEX
110 #else
111 #define PETSC_SCALAR PETSC_DOUBLE
112 #endif
113 
114 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
115               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double),
116               PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize;
117 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
118 extern int PetscDataTypeGetSize(PetscDataType,int*);
119 extern int PetscDataTypeGetName(PetscDataType,char**);
120 
121 /*
122     Basic memory and string operations
123 */
124 extern int   PetscMemcpy(void *,void *,int);
125 extern int   PetscBitMemcpy(void*,int,void*,int,int,PetscDataType);
126 extern int   PetscMemmove(void *,void *,int);
127 extern int   PetscMemzero(void *,int);
128 extern int   PetscMemcmp(void*, void*, int);
129 extern int   PetscStrlen(char *);
130 extern int   PetscStrcmp(char *,char *);
131 extern int   PetscStrcasecmp(char *,char *);
132 extern int   PetscStrncmp(char *,char *,int );
133 extern int   PetscStrcpy(char *,char *);
134 extern int   PetscStrcat(char *,char *);
135 extern int   PetscStrncat(char *,char *,int);
136 extern int   PetscStrncpy(char *,char *,int);
137 extern char* PetscStrchr(char *,char);
138 extern char* PetscStrrchr(char *,char);
139 extern char* PetscStrstr(char*,char*);
140 extern char* PetscStrtok(char*,char*);
141 extern char* PetscStrrtok(char*,char*);
142 
143 /*
144        Basic PETSc constants
145 */
146 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
147 #define PETSC_NULL            0
148 #define PETSC_DECIDE         -1
149 #define PETSC_DETERMINE      PETSC_DECIDE
150 #define PETSC_DEFAULT        -2
151 
152 /*
153     Each PETSc object class has it's own cookie (internal integer in the
154   data structure used for error checking). These are all defined by an offset
155   from the lowest one, PETSC_COOKIE. If you increase these you must
156   increase the field sizes in petsc/src/plog/src/plog.c
157 */
158 #define PETSC_COOKIE                    1211211
159 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
160 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
161 extern int LARGEST_PETSC_COOKIE;
162 
163 #include "viewer.h"
164 #include "options.h"
165 
166 /*
167     Defines basic graphics available from PETSc.
168 */
169 #include "draw.h"
170 
171 extern PLogDouble PetscGetTime();
172 extern PLogDouble PetscGetCPUTime();
173 extern int        PetscSleep(int);
174 
175 extern int    PetscInitialize(int*,char***,char*,char*);
176 extern int    PetscInitializeNoArguments();
177 extern int    PetscFinalize();
178 extern void   PetscInitializeFortran();
179 
180 /*
181     Functions that can act on any PETSc object.
182 */
183 typedef struct _p_PetscObject* PetscObject;
184 extern int PetscObjectDestroy(PetscObject);
185 extern int PetscObjectExists(PetscObject,int*);
186 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
187 extern int PetscObjectGetCookie(PetscObject,int *cookie);
188 extern int PetscObjectGetChild(PetscObject,void **child);
189 extern int PetscObjectGetType(PetscObject,int *type);
190 extern int PetscObjectSetName(PetscObject,char*);
191 extern int PetscObjectGetName(PetscObject,char**);
192 extern int PetscObjectCompose(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
193 extern int PetscObjectReference(PetscObject);
194 extern int PetscObjectGetReference(PetscObject,int*);
195 extern int PetscObjectDereference(PetscObject);
196 extern int PetscObjectGetNewTag(PetscObject,int *);
197 extern int PetscObjectRestoreNewTag(PetscObject,int *);
198 extern int PetscObjectView(PetscObject,Viewer);
199 
200 
201 /*
202     Defines PETSc error handling.
203 */
204 #include "petscerror.h"
205 
206 /*
207     Dynamic library lists. Lists of names of routines in dynamic
208   link libraries that will be loaded as needed.
209 */
210 typedef struct _DLList *DLList;
211 extern int    DLRegister_Private(DLList*,char*,char*,int (*)(void *));
212 extern int    DLRegisterCreate(DLList *);
213 extern int    DLRegisterDestroy(DLList);
214 extern int    DLRegisterFind(MPI_Comm,DLList,char*,int (**)(void*));
215 extern int    DLRegisterPrintTypes(MPI_Comm,FILE*,char*,char *,DLList);
216 #if defined(USE_DYNAMIC_LIBRARIES)
217 #define       DLRegister(a,b,p,c) DLRegister_Private(a,b,p,0)
218 #else
219 #define       DLRegister(a,b,p,c) DLRegister_Private(a,b,p,(int (*)(void *))c)
220 #endif
221 
222 typedef struct _DLLibraryList *DLLibraryList;
223 extern DLLibraryList DLLibrariesLoaded;
224 extern int DLLibraryOpen(MPI_Comm,char *,void **);
225 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,char*,char *, void **);
226 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,char *);
227 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,char *);
228 extern int DLLibraryClose(DLLibraryList);
229 
230 
231 #include "petschead.h"
232 
233 /*
234      Defines PETSc profiling.
235 */
236 #include "petsclog.h"
237 
238 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
239 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
240 
241 /*M
242     PetscBarrier - Blocks until this routine is executed by all
243                    processors owning the object A.
244 
245    Input Parameters:
246 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
247 
248    Synopsis:
249    void PetscBarrier(PetscObject obj)
250 
251   Notes:
252   This routine calls MPI_Barrier with the communicator
253   of the PETSc Object "A".
254 
255 .keywords: barrier, petscobject
256 M*/
257 
258 #define PetscBarrier(A) \
259   { \
260     PetscValidHeader(A); \
261     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
262     MPI_Barrier(((PetscObject)A)->comm); \
263     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
264   }
265 
266 extern int PetscMPIDump(FILE *);
267 
268 /*
269       This code allows one to pass a PETSc object in C
270   to a Fortran routine, where (like all PETSc objects in
271   Fortran) it is treated as an integer.
272 */
273 extern int  PetscCObjectToFortranObject(void *,int *);
274 extern int  PetscFortranObjectToCObject(int,void *);
275 extern int  MPICCommToFortranComm(MPI_Comm,int *);
276 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
277 
278 /*
279       Simple PETSc parallel IO for ASCII printing
280 */
281 extern int  PetscFixFilename(char*);
282 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
283 extern int  PetscFClose(MPI_Comm,FILE*);
284 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
285 extern int  PetscPrintf(MPI_Comm,char *,...);
286 extern int  (*PetscErrorPrintf)(char *,...);
287 extern int  (*PetscHelpPrintf)(MPI_Comm,char *,...);
288 
289 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
290 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...);
291 extern int  PetscSynchronizedFlush(MPI_Comm);
292 
293 
294 /*
295     C code optimization is often enhanced by telling the compiler
296   that certain pointer arguments to functions are not aliased to
297   to other arguments. This is not yet ANSI C standard so we define
298   the macro "restrict" to indicate that the variable is not aliased
299   to any other argument.
300 */
301 #if defined(HAVE_RESTRICT) && !defined(__cplusplus)
302 #define restrict _Restrict
303 #else
304 #define restrict
305 #endif
306 
307 /*
308    For incremental debugging
309 */
310 extern int PetscCompare;
311 extern int PetscCompareDouble(double);
312 extern int PetscCompareScalar(Scalar);
313 extern int PetscCompareInt(int);
314 
315 /*
316    For use in debuggers
317 */
318 extern int PetscGlobalRank,PetscGlobalSize;
319 extern int PetscIntView(int,int*,Viewer);
320 extern int PetscDoubleView(int,double *,Viewer);
321 
322 #endif
323