xref: /petsc/include/petsc.h (revision 5f74e6c5e3b3b8c6321c77c77cda6690d4b7fdde)
1 /* $Id: petsc.h,v 1.187 1997/11/13 19:33:14 bsmith 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.21, Released November 13, 1997."
13 
14 #define PETSC_VERSION_MAJOR    2
15 #define PETSC_VERSION_MINOR    0
16 #define PETSC_VERSION_SUBMINOR 21
17 #define PETSC_VERSION_DATE     "November 13, 1997"
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 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
88 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
89 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
90                            int (*)(void *,int,char*,char*,char*));
91 extern int  PetscClearMalloc();
92 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
93 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
94 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNC__,__FILE__,__SDIR__)
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 /*
105     Basic memory and string operations
106 */
107 extern int   PetscMemcpy(void *,void *,int);
108 extern int   PetscMemmove(void *,void *,int);
109 extern int   PetscMemzero(void *,int);
110 extern int   PetscMemcmp(void*, void*, int);
111 extern int   PetscStrlen(char *);
112 extern int   PetscStrcmp(char *,char *);
113 extern int   PetscStrcasecmp(char *,char *);
114 extern int   PetscStrncmp(char *,char *,int );
115 extern int   PetscStrcpy(char *,char *);
116 extern int   PetscStrcat(char *,char *);
117 extern int   PetscStrncat(char *,char *,int);
118 extern int   PetscStrncpy(char *,char *,int);
119 extern char* PetscStrchr(char *,char);
120 extern char* PetscStrrchr(char *,char);
121 extern char* PetscStrstr(char*,char*);
122 extern char* PetscStrtok(char*,char*);
123 extern char* PetscStrrtok(char*,char*);
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 PLogDouble PetscGetTime();
151 extern PLogDouble PetscGetCPUTime();
152 extern void       PetscSleep(int);
153 
154 extern int    PetscInitialize(int*,char***,char*,char*);
155 extern int    PetscFinalize();
156 extern void   PetscInitializeFortran();
157 
158 /*
159     Functions that can act on any PETSc object.
160 */
161 typedef struct _p_PetscObject* PetscObject;
162 extern int PetscObjectDestroy(PetscObject);
163 extern int PetscObjectExists(PetscObject,int*);
164 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
165 extern int PetscObjectGetCookie(PetscObject,int *cookie);
166 extern int PetscObjectGetChild(PetscObject,void **child);
167 extern int PetscObjectGetType(PetscObject,int *type);
168 extern int PetscObjectSetName(PetscObject,char*);
169 extern int PetscObjectGetName(PetscObject,char**);
170 extern int PetscObjectCompose(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
171 extern int PetscObjectReference(PetscObject);
172 extern int PetscObjectDereference(PetscObject);
173 extern int PetscObjectGetNewTag(PetscObject,int *);
174 extern int PetscObjectRestoreNewTag(PetscObject,int *);
175 extern int PetscObjectView(PetscObject,Viewer);
176 
177 typedef enum {PETSC_INT = 0, PETSC_DOUBLE = 1, PETSC_SHORT = 2, PETSC_FLOAT = 3,
178               PETSC_COMPLEX = 4, PETSC_CHAR = 5} PetscDataType;
179 #if defined(USE_PETSC_COMPLEX)
180 #define PETSC_SCALAR PETSC_COMPLEX
181 #else
182 #define PETSC_SCALAR PETSC_DOUBLE
183 #endif
184 
185 typedef enum {PETSC_INT_SIZE = sizeof(int), PETSC_DOUBLE_SIZE = sizeof(double),
186               PETSC_SCALAR_SIZE = sizeof(Scalar), PETSC_COMPLEX_SIZE = sizeof(double),
187               PETSC_CHAR_SIZE = sizeof(char)} PetscDataTypeSize;
188 extern int PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
189 extern int PetscDataTypeGetSize(PetscDataType,int*);
190 extern int PetscDataTypeGetName(PetscDataType,char**);
191 
192 /*
193     Defines PETSc error handling.
194 */
195 #include "petscerror.h"
196 #include "petschead.h"
197 
198 /*
199      Defines PETSc profiling.
200 */
201 #include "petsclog.h"
202 
203 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
204 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
205 
206 /*M
207     PetscBarrier - Blocks until this routine is executed by all
208                    processors owning the object A.
209 
210    Input Parameters:
211 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
212 
213    Synopsis:
214    void PetscBarrier(PetscObject obj)
215 
216   Notes:
217   This routine calls MPI_Barrier with the communicator
218   of the PETSc Object "A".
219 
220 .keywords: barrier, petscobject
221 M*/
222 
223 #define PetscBarrier(A) \
224   { \
225     PetscValidHeader(A); \
226     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
227     MPI_Barrier(((PetscObject)A)->comm); \
228     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
229   }
230 
231 extern int PetscMPIDump(FILE *);
232 
233 /*
234       This code allows one to pass a PETSc object in C
235   to a Fortran routine, where (like all PETSc objects in
236   Fortran) it is treated as an integer.
237 */
238 extern int  PetscCObjectToFortranObject(void *,int *);
239 extern int  PetscFortranObjectToCObject(int,void *);
240 extern int  MPICCommToFortranComm(MPI_Comm,int *);
241 extern int  MPIFortranCommToCComm(int,MPI_Comm*);
242 
243 /*
244       Simple PETSc parallel IO for ASCII printing
245 */
246 extern int  PetscFixFilename(char*);
247 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
248 extern int  PetscFClose(MPI_Comm,FILE*);
249 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
250 extern int  PetscPrintf(MPI_Comm,char *,...);
251 extern int  PetscErrorPrintf(char *,...);
252 
253 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
254 extern int  PetscSynchronizedFPrintf(MPI_Comm,FILE*,char *,...);
255 extern int  PetscSynchronizedFlush(MPI_Comm);
256 
257 /*
258    For incremental debugging
259 */
260 extern int PetscCompare;
261 extern int PetscCompareDouble(double);
262 extern int PetscCompareScalar(Scalar);
263 extern int PetscCompareInt(int);
264 
265 /*
266    For use in debuggers
267 */
268 extern int PetscGlobalRank,PetscGlobalSize;
269 extern int PetscIntView(int,int*,Viewer);
270 extern int PetscDoubleView(int,double *,Viewer);
271 
272 #endif
273