xref: /petsc/include/petsc.h (revision 7c2000337a446092e4e06a20f2ff73813d334fd7) !
1 /* $Id: petsc.h,v 1.250 1999/10/01 21:23:20 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
12 */
13 #include "petscversion.h"
14 
15 /* ========================================================================== */
16 /*
17    The PETSc configuration file.  Contains various definitions that
18    handle portability issues and the presence of machine features.
19 
20    petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is
21    found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH}
22    in the bmake/common definition of PETSC_INCLUDE
23 */
24 #include "petscconf.h"
25 
26 /* ========================================================================== */
27 
28 #include <stdio.h>
29 /*
30     Defines the interface to MPI allowing the use of all MPI functions.
31 */
32 #include "mpi.h"
33 
34 /*
35     Defines some elementary mathematics functions and constants.
36 */
37 #include "petscmath.h"
38 
39 /*
40     Variable type where we stash PETSc object pointers in Fortran.
41     Assumes that sizeof(long) == sizeof(void *) which is true on
42     all machines that we know.
43 */
44 #define PetscFortranAddr   long
45 
46 extern MPI_Comm PETSC_COMM_WORLD;
47 extern MPI_Comm PETSC_COMM_SELF;
48 extern int      PetscInitializedCalled;
49 extern int      PetscSetCommWorld(MPI_Comm);
50 
51 /*
52     Defines the malloc employed by PETSc. Users may use these routines as well.
53 */
54 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
55 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
56 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
57 extern void *(*PetscTrMalloc)(int,int,char*,char*,char*);
58 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
59 extern int  PetscSetMalloc(void *(*)(int,int,char*,char*,char*),
60                            int (*)(void *,int,char*,char*,char*));
61 extern int  PetscClearMalloc(void);
62 
63 /*
64    Routines for tracing memory corruption/bleeding with default PETSc
65    memory allocation
66 */
67 extern int   PetscTrDump(FILE *);
68 extern int   PetscTrSpace(PLogDouble *, PLogDouble *,PLogDouble *);
69 extern int   PetscTrValid(int,const char[],const char[],const char[]);
70 extern int   PetscTrDebugLevel(int);
71 extern int   PetscTrLog(void);
72 extern int   PetscTrLogDump(FILE *);
73 extern int   PetscGetResidentSetSize(PLogDouble *);
74 
75 /*
76      Constants and functions used for handling different basic data types.
77      These are used, for example, in binary IO routines
78 */
79 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
80               PETSC_COMPLEX = 4, PETSC_CHAR = 5, PETSC_LOGICAL = 6} PetscDataType;
81 #if defined(PETSC_USE_COMPLEX)
82 #define PETSC_SCALAR PETSC_COMPLEX
83 #else
84 #define PETSC_SCALAR PETSC_DOUBLE
85 #endif
86 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
87               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double),
88               PETSC_CHAR_SIZE = sizeof(char), PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize;
89 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
90 extern int PetscDataTypeGetSize(PetscDataType,int*);
91 extern int PetscDataTypeGetName(PetscDataType,char*[]);
92 
93 /*
94        Basic PETSc constants
95 */
96 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
97 #define PETSC_NULL            0
98 #define PETSC_DECIDE         -1
99 #define PETSC_DETERMINE      PETSC_DECIDE
100 #define PETSC_DEFAULT        -2
101 
102 /*
103     Basic memory and string operations. These are usually simple wrappers
104    around the basic Unix system calls, but a few of them have additional
105    functionality and/or error checking.
106 */
107 extern int   PetscMemcpy(void *,const void *,int);
108 extern int   PetscBitMemcpy(void*,int,const void*,int,int,PetscDataType);
109 extern int   PetscMemmove(void *,void *,int);
110 extern int   PetscMemzero(void *,int);
111 extern int   PetscMemcmp(const void*,const void*, int);
112 extern int   PetscStrlen(const char[],int*);
113 extern int   PetscStrcmp(const char[],const char[]);
114 extern int   PetscStrcasecmp(const char[],const char[],PetscTruth*);
115 extern int   PetscStrncmp(const char[],const char[],int,PetscTruth*);
116 extern int   PetscStrcpy(char[],const char[]);
117 extern int   PetscStrcat(char[],const char[]);
118 extern int   PetscStrncat(char[],const char[],int);
119 extern int   PetscStrncpy(char[],const char[],int);
120 extern int   PetscStrchr(const char[],char,char **);
121 extern int   PetscStrrchr(const char[],char,char **);
122 extern int   PetscStrstr(const char[],const char[],char **);
123 extern int   PetscStrtok(const char[],const char[],char **);
124 extern int   PetscStrallocpy(const char[],char **);
125 
126 #define PetscTypeCompare(a,b) (!PetscStrcmp((char*)(((PetscObject)(a))->type_name),(char *)(b)))
127 
128 
129 /*
130     Each PETSc object class has it's own cookie (internal integer in the
131   data structure used for error checking). These are all defined by an offset
132   from the lowest one, PETSC_COOKIE. If you increase these you must
133   increase the field sizes in petsc/src/sys/src/plog/plog.c
134 */
135 #define PETSC_COOKIE                    1211211
136 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
137 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
138 extern int LARGEST_PETSC_COOKIE;
139 
140 typedef struct _FList *FList;
141 
142 #include "viewer.h"
143 #include "options.h"
144 
145 extern int PetscGetTime(PLogDouble*);
146 extern int PetscGetCPUTime(PLogDouble*);
147 extern int PetscSleep(int);
148 
149 /*
150     Initialization of PETSc or its micro-kernel ALICE
151 */
152 extern int  AliceInitialize(int*,char***,const char[],const char[]);
153 extern int  AliceInitializeNoArguments(void);
154 extern int  AliceFinalize(void);
155 extern void AliceInitializeFortran(void);
156 
157 extern int  PetscInitialize(int*,char***,char[],const char[]);
158 extern int  PetscInitializeNoArguments(void);
159 extern int  PetscFinalize(void);
160 extern void PetscInitializeFortran(void);
161 
162 /*
163     Functions that can act on any PETSc object.
164 */
165 typedef struct _p_PetscObject* PetscObject;
166 extern int PetscObjectDestroy(PetscObject);
167 extern int PetscObjectExists(PetscObject,PetscTruth*);
168 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
169 extern int PetscObjectGetCookie(PetscObject,int *cookie);
170 extern int PetscObjectGetType(PetscObject,int *type);
171 extern int PetscObjectSetName(PetscObject,const char[]);
172 extern int PetscObjectGetName(PetscObject,char*[]);
173 extern int PetscObjectReference(PetscObject);
174 extern int PetscObjectGetReference(PetscObject,int*);
175 extern int PetscObjectDereference(PetscObject);
176 extern int PetscObjectGetNewTag(PetscObject,int *);
177 extern int PetscObjectRestoreNewTag(PetscObject,int *);
178 extern int PetscCommGetNewTag(MPI_Comm,int *);
179 extern int PetscCommRestoreNewTag(MPI_Comm,int *);
180 extern int PetscObjectView(PetscObject,Viewer);
181 extern int PetscObjectCompose(PetscObject,const char[],PetscObject);
182 extern int PetscObjectQuery(PetscObject,const char[],PetscObject *);
183 extern int PetscObjectComposeFunction_Private(PetscObject,const char[],const char[],void *);
184 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
185 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,0)
186 #else
187 #define PetscObjectComposeFunction(a,b,c,d) PetscObjectComposeFunction_Private(a,b,c,d)
188 #endif
189 extern int PetscObjectQueryFunction(PetscObject,const char[],void **);
190 extern int PetscObjectSetOptionsPrefix(PetscObject,const char[]);
191 extern int PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
192 extern int PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
193 extern int PetscObjectGetOptionsPrefix(PetscObject,char*[]);
194 extern int PetscObjectPublish(PetscObject);
195 extern int PetscObjectChangeTypeName(PetscObject,char *);
196 
197 /*
198     Defines PETSc error handling.
199 */
200 #include "petscerror.h"
201 
202 /*
203     Mechanism for managing lists of objects attached (composed) with
204    a PETSc object.
205 */
206 typedef struct _OList *OList;
207 extern int OListDestroy(OList *);
208 extern int OListFind(OList,const char[],PetscObject*);
209 extern int OListReverseFind(OList,PetscObject,char**);
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 extern int FListAdd_Private(FList*,const char[],const char[],int (*)(void *));
218 extern int FListDestroy(FList);
219 extern int FListFind(MPI_Comm,FList,const char[],int (**)(void*));
220 extern int FListPrintTypes(MPI_Comm,FILE*,const char[],const char[],FList);
221 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
222 #define    FListAdd(a,b,p,c) FListAdd_Private(a,b,p,0)
223 #else
224 #define    FListAdd(a,b,p,c) FListAdd_Private(a,b,p,(int (*)(void *))c)
225 #endif
226 extern int FListDuplicate(FList,FList *);
227 extern int FListView(FList,Viewer);
228 
229 /*
230    Routines for handling dynamic libraries. PETSc uses dynamic libraries
231   by default on most machines (except IBM). This is controlled by the
232   flag PETSC_USE_DYNAMIC_LIBRARIES in petscconf.h
233 */
234 typedef struct _DLLibraryList *DLLibraryList;
235 extern DLLibraryList DLLibrariesLoaded;
236 extern int DLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
237 extern int DLLibraryOpen(MPI_Comm,const char[],void **);
238 extern int DLLibrarySym(MPI_Comm,DLLibraryList *,const char[],const char[],void **);
239 extern int DLLibraryAppend(MPI_Comm,DLLibraryList *,const char[]);
240 extern int DLLibraryPrepend(MPI_Comm,DLLibraryList *,const char[]);
241 extern int DLLibraryClose(DLLibraryList);
242 extern int DLLibraryPrintPath(void);
243 extern int DLLibraryGetInfo(void *,char *,char **);
244 
245 /*
246     Mechanism for translating PETSc object representations between languages
247     Not currently used.
248 */
249 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CPP} PetscLanguage;
250 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
251 extern int PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
252 extern int PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
253 
254 /*
255      Useful utility routines
256 */
257 extern int PetscSplitOwnership(MPI_Comm,int*,int*);
258 extern int PetscSequentialPhaseBegin(MPI_Comm,int);
259 extern int PetscSequentialPhaseEnd(MPI_Comm,int);
260 extern int PetscBarrier(PetscObject);
261 extern int PetscMPIDump(FILE*);
262 
263 /*
264     Defines basic graphics available from PETSc.
265 */
266 #include "draw.h"
267 
268 /*
269     Defines the base data structures for all PETSc objects
270 */
271 #include "petschead.h"
272 
273 /*
274      Defines PETSc profiling.
275 */
276 #include "petsclog.h"
277 
278 #if defined(PETSC_HAVE_AMS)
279 extern PetscTruth PetscAMSPublishAll;
280 #define PetscPublishAll(v)\
281   { if (PetscAMSPublishAll) { \
282     int __ierr;\
283     __ierr = PetscObjectPublish((PetscObject)v);CHKERRQ(__ierr);\
284   }}
285 #else
286 #define PetscPublishAll(v)
287 #endif
288 
289 /*
290       This code allows one to pass a MPI communicator between
291     C and Fortran. MPI 2.0 defines a standard API for doing this.
292     The code here is provided to allow PETSc to work with MPI 1.1
293     standard MPI libraries.
294 */
295 extern int  MPICCommToFortranComm(MPI_Comm,int *);
296 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
297 
298 /*
299       Simple PETSc parallel IO for ASCII printing
300 */
301 extern int  PetscFixFilename(const char[],char[]);
302 extern FILE *PetscFOpen(MPI_Comm,const char[],const char[]);
303 extern int  PetscFClose(MPI_Comm,FILE*);
304 extern int  PetscFPrintf(MPI_Comm,FILE*,const char[],...);
305 extern int  PetscPrintf(MPI_Comm,const char[],...);
306 extern int  (*PetscErrorPrintf)(const char[],...);
307 extern int  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
308 
309 extern int  PetscSynchronizedPrintf(MPI_Comm,const char[],...);
310 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...);
311 extern int  PetscSynchronizedFlush(MPI_Comm);
312 
313 /*
314     Simple PETSc object that contains a pointer to any required data
315 */
316 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
317 extern int PetscObjectContainerGetPointer(PetscObjectContainer,void **);
318 extern int PetscObjectContainerSetPointer(PetscObjectContainer,void *);
319 extern int PetscObjectContainerDestroy(PetscObjectContainer);
320 extern int PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
321 
322 /*
323    For incremental debugging
324 */
325 extern int PetscCompare;
326 extern int PetscCompareDouble(double);
327 extern int PetscCompareScalar(Scalar);
328 extern int PetscCompareInt(int);
329 
330 /*
331    For use in debuggers
332 */
333 extern int PetscGlobalRank,PetscGlobalSize;
334 extern int PetscIntView(int,int[],Viewer);
335 extern int PetscDoubleView(int,double[],Viewer);
336 extern int PetscScalarView(int,Scalar[],Viewer);
337 
338 /*
339     C code optimization is often enhanced by telling the compiler
340   that certain pointer arguments to functions are not aliased to
341   to other arguments. This is not yet ANSI C standard so we define
342   the macro "restrict" to indicate that the variable is not aliased
343   to any other argument.
344 */
345 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
346 #define restrict _Restrict
347 #else
348 #define restrict
349 #endif
350 
351 /*
352       Determine if some of the kernel computation routines use
353    Fortran (rather than C) for the numerical calculations. On some machines
354    and compilers (like complex numbers) the Fortran version of the routines
355    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
356    would be set in the petscconf.h file
357 */
358 #if defined(PETSC_USE_FORTRAN_KERNELS)
359 
360 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
361 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
362 #endif
363 
364 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORMSQR)
365 #define PETSC_USE_FORTRAN_KERNEL_NORMSQR
366 #endif
367 
368 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
369 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
370 #endif
371 
372 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
373 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
374 #endif
375 
376 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
377 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
378 #endif
379 
380 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
381 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
382 #endif
383 
384 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
385 #define PETSC_USE_FORTRAN_KERNEL_MDOT
386 #endif
387 
388 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
389 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
390 #endif
391 
392 #endif
393 
394 /*
395     Macros for indicating code that should be compiled with a C interface,
396    rather than a C++ interface. Any routines that are dynamically loaded
397    (such as the PCCreate_XXX() routines) must be wrapped so that the name
398    mangler does not change the functions symbol name. This just hides the
399    ugly extern "C" {} wrappers.
400 */
401 #if defined(__cplusplus)
402 #define EXTERN_C_BEGIN extern "C" {
403 #define EXTERN_C_END }
404 #else
405 #define EXTERN_C_BEGIN
406 #define EXTERN_C_END
407 #endif
408 
409 #endif
410