xref: /petsc/include/petsc.h (revision 2e8a6d31cfff42dc61c2443ddfa186a411c27ca7)
1 /* $Id: petsc.h,v 1.228 1998/09/28 00:25:11 bsmith Exp bsmith $ */
2 /*
3    This is the main PETSc include file (for C and C++).  It is included by all
4    other PETSc include files, so it almost never has to be specifically included.
5 */
6 #if !defined(__PETSC_H)
7 #define __PETSC_H
8 
9 /* ========================================================================== */
10 /*
11    Current PETSc version number and release date, also listed in
12     docs/changes.html
13     docs/tex/manual/manual.tex and
14     docs/tex/manual/manual_tex.tex.
15 */
16 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.23, Released September 28, 1998."
17 
18 #define PETSC_VERSION_MAJOR    2
19 #define PETSC_VERSION_MINOR    0
20 #define PETSC_VERSION_SUBMINOR 23
21 #define PETSC_VERSION_DATE     "September 29, 1998"
22 #define PETSC_AUTHOR_INFO      "The PETSc Team:\
23  Satish Balay, Bill Gropp, Lois Curfman McInnes, Barry Smith\n\
24  Bug reports, questions: petsc-maint@mcs.anl.gov\n\
25  Web page: http://www.mcs.anl.gov/petsc/\n"
26 
27 /* ========================================================================== */
28 /*
29    The PETSc configuration file.  Contains various definitions that
30    handle portability issues and the presence of machine features.
31 
32    petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h
33 */
34 #include "petscconf.h"
35 
36 /* ========================================================================== */
37 
38 #include <stdio.h>
39 /*
40     Defines the interface to MPI allowing the use of all MPI functions.
41 */
42 #include "mpi.h"
43 
44 /*
45     Defines some elementary mathematics functions and constants.
46 */
47 #include "petscmath.h"
48 
49 /*
50     Variable type where we stash PETSc object pointers in Fortran.
51     Assumes that sizeof(long) == sizeof(void *) which is true on
52     all machines that we know.
53 */
54 #define PetscFortranAddr   long
55 
56 extern MPI_Comm PETSC_COMM_WORLD;
57 extern MPI_Comm PETSC_COMM_SELF;
58 extern int      PetscInitializedCalled;
59 extern int      PetscSetCommWorld(MPI_Comm);
60 
61 /*
62     Defines the malloc employed by PETSc. Users may use these routines as well.
63 */
64 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
65 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
66 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
67 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
68 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
69 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
70                            int (*)(void *,int,char*,char*,char*));
71 extern int  PetscClearMalloc(void);
72 
73 /*
74    Routines for tracing memory corruption/bleeding with default PETSc
75    memory allocation
76 */
77 extern int   PetscTrDump(FILE *);
78 extern int   PetscTrSpace(PLogDouble *, PLogDouble *,PLogDouble *);
79 extern int   PetscTrValid(int,const char[],const char[],const char[]);
80 extern int   PetscTrDebugLevel(int);
81 extern int   PetscTrLog(void);
82 extern int   PetscTrLogDump(FILE *);
83 extern int   PetscGetResidentSetSize(PLogDouble *);
84 
85 
86 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
87               PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType;
88 #if defined(USE_PETSC_COMPLEX)
89 #define PETSC_SCALAR PETSC_COMPLEX
90 #else
91 #define PETSC_SCALAR PETSC_DOUBLE
92 #endif
93 
94 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
95               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double),
96               PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize;
97 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
98 extern int PetscDataTypeGetSize(PetscDataType,int*);
99 extern int PetscDataTypeGetName(PetscDataType,char*[]);
100 
101 /*
102     Basic memory and string operations
103 */
104 extern int   PetscMemcpy(void *,const void *,int);
105 extern int   PetscBitMemcpy(void*,int,const void*,int,int,PetscDataType);
106 extern int   PetscMemmove(void *,void *,int);
107 extern int   PetscMemzero(void *,int);
108 extern int   PetscMemcmp(const void*,const void*, int);
109 extern int   PetscStrlen(const char[]);
110 extern int   PetscStrcmp(const char[],const char[]);
111 extern int   PetscStrcasecmp(const char[],const char[]);
112 extern int   PetscStrncmp(const char[],const char[],int );
113 extern int   PetscStrcpy(char[],const char[]);
114 extern int   PetscStrcat(char[],const char[]);
115 extern int   PetscStrncat(char[],const char[],int);
116 extern int   PetscStrncpy(char[],const char[],int);
117 extern char* PetscStrchr(const char[],char);
118 extern char* PetscStrrchr(const char[],char);
119 extern char* PetscStrstr(const char[],const char[]);
120 extern char* PetscStrtok(const char[],const char[]);
121 
122 /*
123        Basic PETSc constants
124 */
125 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
126 #define PETSC_NULL            0
127 #define PETSC_DECIDE         -1
128 #define PETSC_DETERMINE      PETSC_DECIDE
129 #define PETSC_DEFAULT        -2
130 
131 /*
132     Each PETSc object class has it's own cookie (internal integer in the
133   data structure used for error checking). These are all defined by an offset
134   from the lowest one, PETSC_COOKIE. If you increase these you must
135   increase the field sizes in petsc/src/plog/src/plog.c
136 */
137 #define PETSC_COOKIE                    1211211
138 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
139 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
140 extern int LARGEST_PETSC_COOKIE;
141 
142 #include "viewer.h"
143 #include "options.h"
144 
145 /*
146     Defines basic graphics available from PETSc.
147 */
148 #include "draw.h"
149 
150 extern int PetscGetTime(PLogDouble*);
151 extern int PetscGetCPUTime(PLogDouble*);
152 extern int PetscSleep(int);
153 
154 /*
155     Initialization of PETSc or its micro-kernel ALICE
156 */
157 extern int  AliceInitialize(int*,char***,const char[],const char[]);
158 extern int  AliceInitializeNoArguments(void);
159 extern int  AliceFinalize(void);
160 extern void AliceInitializeFortran(void);
161 
162 extern int  PetscInitialize(int*,char***,char[],const char[]);
163 extern int  PetscInitializeNoArguments(void);
164 extern int  PetscFinalize(void);
165 extern void PetscInitializeFortran(void);
166 
167 /*
168     Functions that can act on any PETSc object.
169 */
170 typedef struct _p_PetscObject* PetscObject;
171 extern int PetscObjectDestroy(PetscObject);
172 extern int PetscObjectExists(PetscObject,int*);
173 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
174 extern int PetscObjectGetCookie(PetscObject,int *cookie);
175 extern int PetscObjectGetType(PetscObject,int *type);
176 extern int PetscObjectSetName(PetscObject,const char[]);
177 extern int PetscObjectGetName(PetscObject,char*[]);
178 extern int PetscObjectReference(PetscObject);
179 extern int PetscObjectGetReference(PetscObject,int*);
180 extern int PetscObjectDereference(PetscObject);
181 extern int PetscObjectGetNewTag(PetscObject,int *);
182 extern int PetscObjectRestoreNewTag(PetscObject,int *);
183 extern int PetscObjectView(PetscObject,Viewer);
184 extern int PetscObjectCompose(PetscObject,const char[],PetscObject);
185 extern int PetscObjectQuery(PetscObject,const char[],PetscObject *);
186 extern int PetscObjectComposeFunction_Private(PetscObject,const char[],const char[],void *);
187 #if defined(USE_DYNAMIC_LIBRARIES)
188 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,0)
189 #else
190 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,d)
191 #endif
192 extern int PetscObjectQueryFunction(PetscObject,const char[],void **);
193 extern int PetscObjectSetOptionsPrefix(PetscObject,const char[]);
194 extern int PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
195 extern int PetscObjectGetOptionsPrefix(PetscObject,char*[]);
196 extern int PetscObjectPublish(PetscObject);
197 
198 /*
199     Defines PETSc error handling.
200 */
201 #include "petscerror.h"
202 
203 /*
204     Mechanism for managing lists of objects attached (composed) with
205    a PETSc object.
206 */
207 typedef struct _OList *OList;
208 extern int OListDestroy(OList *);
209 extern int OListFind(OList,const char[],PetscObject*);
210 extern int OListAdd(OList *,const char[],PetscObject);
211 extern int OListDuplicate(OList,OList *);
212 
213 /*
214     Dynamic library lists. Lists of names of routines in dynamic
215   link libraries that will be loaded as needed.
216 */
217 typedef struct _FList *FList;
218 extern int FListAdd_Private(FList*,const char[],const char[],int (*)(void *));
219 extern int FListDestroy(FList);
220 extern int FListFind(MPI_Comm,FList,const char[],int (**)(void*));
221 extern int FListPrintTypes(MPI_Comm,FILE*,const char[],const char[],FList);
222 #if defined(USE_DYNAMIC_LIBRARIES)
223 #define    FListAdd(a,b,p,c) FListAdd_Private(a,b,p,0)
224 #else
225 #define    FListAdd(a,b,p,c) FListAdd_Private(a,b,p,(int (*)(void *))c)
226 #endif
227 extern int FListDuplicate(FList,FList *);
228 
229 typedef struct _DLLibraryList *DLLibraryList;
230 extern DLLibraryList DLLibrariesLoaded;
231 extern int DLLibraryOpen(MPI_Comm,const char[],void **);
232 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,const char[],const char[],void **);
233 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,const char[]);
234 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,const char[]);
235 extern int DLLibraryClose(DLLibraryList);
236 extern int DLLibraryPrintPath();
237 
238 /*
239     Mechanism for translating PETSc object representations between languages
240     Note currently used.
241 */
242 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CPP} PetscLanguage;
243 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
244 extern int PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
245 extern int PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
246 
247 #include "petschead.h"
248 
249 /*
250      Defines PETSc profiling.
251 */
252 #include "petsclog.h"
253 
254 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
255 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
256 extern int  PetscBarrier(PetscObject);
257 extern int  PetscMPIDump(FILE*);
258 
259 /*
260       This code allows one to pass a MPI communicator between
261     C and Fortran. MPI 2.0 defines a standard API for doing this.
262     The code here is provided to allow PETSc to work with MPI 1.1
263     standard MPI libraries.
264 */
265 extern int  MPICCommToFortranComm(MPI_Comm,int *);
266 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
267 
268 /*
269       Simple PETSc parallel IO for ASCII printing
270 */
271 extern int  PetscFixFilename(const char[],char[]);
272 extern FILE *PetscFOpen(MPI_Comm,const char[],const char[]);
273 extern int  PetscFClose(MPI_Comm,FILE*);
274 extern int  PetscFPrintf(MPI_Comm,FILE*,const char[],...);
275 extern int  PetscPrintf(MPI_Comm,const char[],...);
276 extern int  (*PetscErrorPrintf)(const char[],...);
277 extern int  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
278 
279 extern int  PetscSynchronizedPrintf(MPI_Comm,const char[],...);
280 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...);
281 extern int  PetscSynchronizedFlush(MPI_Comm);
282 
283 
284 /*
285     Simple PETSc object that contains a pointer to any required data
286 */
287 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
288 extern int PetscObjectContainerGetPointer(PetscObjectContainer,void **);
289 extern int PetscObjectContainerSetPointer(PetscObjectContainer,void *);
290 extern int PetscObjectContainerDestroy(PetscObjectContainer);
291 extern int PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
292 
293 
294 /*
295    For incremental debugging
296 */
297 extern int PetscCompare;
298 extern int PetscCompareDouble(double);
299 extern int PetscCompareScalar(Scalar);
300 extern int PetscCompareInt(int);
301 
302 /*
303    For use in debuggers
304 */
305 extern int PetscGlobalRank,PetscGlobalSize;
306 extern int PetscIntView(int,int[],Viewer);
307 extern int PetscDoubleView(int,double[],Viewer);
308 
309 /*
310     C code optimization is often enhanced by telling the compiler
311   that certain pointer arguments to functions are not aliased to
312   to other arguments. This is not yet ANSI C standard so we define
313   the macro "restrict" to indicate that the variable is not aliased
314   to any other argument.
315 */
316 #if defined(HAVE_RESTRICT) && !defined(__cplusplus)
317 #define restrict _Restrict
318 #else
319 #define restrict
320 #endif
321 
322 /*
323       Determine if some of the kernel computation routines use
324    Fortran (rather than C) for the numerical calculations. On some machines
325    and compilers (like complex numbers) the Fortran version of the routines
326    is faster than the C/C++ versions.
327 */
328 #if defined(USE_FORTRAN_KERNELS)
329 
330 #if !defined(USE_FORTRAN_KERNEL_MULTAIJ)
331 #define USE_FORTRAN_KERNEL_MULTAIJ
332 #endif
333 
334 #if !defined(USE_FORTRAN_KERNEL_NORMSQR)
335 #define USE_FORTRAN_KERNEL_NORMSQR
336 #endif
337 
338 #if !defined(USE_FORTRAN_KERNEL_MAXPY)
339 #define USE_FORTRAN_KERNEL_MAXPY
340 #endif
341 
342 #if !defined(USE_FORTRAN_KERNEL_SOLVEAIJ)
343 #define USE_FORTRAN_KERNEL_SOLVEAIJ
344 #endif
345 
346 #if !defined(USE_FORTRAN_KERNEL_SOLVEBAIJ)
347 #define USE_FORTRAN_KERNEL_SOLVEBAIJ
348 #endif
349 
350 #if !defined(USE_FORTRAN_KERNEL_MULTADDAIJ)
351 #define USE_FORTRAN_KERNEL_MULTADDAIJ
352 #endif
353 
354 #if !defined(USE_FORTRAN_KERNEL_MDOT)
355 #define USE_FORTRAN_KERNEL_MDOT
356 #endif
357 
358 #endif
359 
360 #endif
361