xref: /petsc/include/petsc.h (revision e3372554f290963355654d01f2ff0b8ae7c17006)
1 /* $Id: petsc.h,v 1.145 1996/12/09 16:55:37 curfman 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 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.16, Released Dec. 10, 1996."
10 
11 #include <stdio.h>
12 #include "mpi.h"
13 
14 #if defined(PETSC_COMPLEX)
15 #if defined(PARCH_t3d)
16 #include "/usr/include/mpp/CC/complex.h"
17 #else
18 #include <complex.h>
19 #endif
20 extern  MPI_Datatype      MPIU_COMPLEX;
21 #define MPIU_SCALAR       MPIU_COMPLEX
22 #define PetscReal(a)      real(a)
23 #define PetscImaginary(a) imag(a)
24 #define PetscAbsScalar(a) abs(a)
25 /*
26   The new complex class for GNU C++ is based on templates and is not backward
27   compatible with all previous complex class libraries.
28 */
29 #if defined(USES_TEMPLATED_COMPLEX)
30 #define Scalar            complex<double>
31 #else
32 #define Scalar            complex
33 #endif
34 
35 /* Compiling for real numbers only */
36 #else
37 #define MPIU_SCALAR       MPI_DOUBLE
38 #define PetscReal(a)      a
39 #define PetscImaginary(a) a
40 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
41 #define Scalar            double
42 #endif
43 
44 extern MPI_Comm PETSC_COMM_WORLD;
45 extern int      PetscInitializedCalled;
46 extern int      PetscSetCommWorld(MPI_Comm);
47 
48 /* PETSC_i is the imaginary number, i */
49 extern  Scalar            PETSC_i;
50 
51 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
52 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
53 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
54 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
55 
56 /*
57     Defines the malloc employed by PETSc. Users may employ these routines as well.
58 */
59 extern void *(*PetscTrMalloc)(unsigned int,int,char*,char*,char*);
60 extern int  (*PetscTrFree)(void *,int,char*,char*,char*);
61 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*,char*,char*),
62                            int (*)(void *,int,char*,char*,char*));
63 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FUNCTION__,__FILE__,__DIR__)
64 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
65 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FUNCTION__,__FILE__,__DIR__)
66 
67 extern int   PetscTrDump(FILE *);
68 extern int   PetscTrSpace( double *, double *,double *);
69 extern int   PetscTrValid(int,char *,char *,char *);
70 extern int   PetscTrDebugLevel(int);
71 
72 extern void  PetscMemcpy(void *,void *,int);
73 extern void  PetscMemzero(void *,int);
74 extern int   PetscMemcmp(void*, void*, int);
75 extern int   PetscStrlen(char *);
76 extern int   PetscStrcmp(char *,char *);
77 extern int   PetscStrncmp(char *,char *,int );
78 extern void  PetscStrcpy(char *,char *);
79 extern void  PetscStrcat(char *,char *);
80 extern void  PetscStrncat(char *,char *,int);
81 extern void  PetscStrncpy(char *,char *,int);
82 extern char* PetscStrchr(char *,char);
83 extern char* PetscStrrchr(char *,char);
84 extern char* PetscStrstr(char*,char*);
85 extern char* PetscStrtok(char*,char*);
86 extern char* PetscStrrtok(char*,char*);
87 
88 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
89 #define PETSC_NULL            0
90 #define PETSC_DECIDE         -1
91 #define PETSC_DEFAULT        -2
92 
93 /*
94     Each PETSc object class has it's own cookie (internal integer in the
95   data structure used for error checking). These are all defined by an offset
96   from the lowest one, PETSC_COOKIE. If you increase these you must
97   increase the field sizes in petsc/src/plog/src/plog.c
98 */
99 #define PETSC_COOKIE                1211211
100 #define LARGEST_PETSC_COOKIE_PREDEFINED PETSC_COOKIE + 30
101 #define LARGEST_PETSC_COOKIE_ALLOWED    PETSC_COOKIE + 50
102 extern int LARGEST_PETSC_COOKIE;
103 
104 #include "viewer.h"
105 #include "options.h"
106 
107 extern double PetscGetTime();
108 extern void   PetscSleep(int);
109 
110 extern int    PetscInitialize(int*,char***,char*,char*);
111 extern int    PetscFinalize();
112 extern void   PetscInitializeFortran();
113 
114 /*
115     Functions that can act on any PETSc object.
116 */
117 typedef struct _PetscObject* PetscObject;
118 extern int PetscObjectDestroy(PetscObject);
119 extern int PetscObjectExists(PetscObject,int*);
120 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
121 extern int PetscObjectGetCookie(PetscObject,int *cookie);
122 extern int PetscObjectGetChild(PetscObject,void **child);
123 extern int PetscObjectGetType(PetscObject,int *type);
124 extern int PetscObjectSetName(PetscObject,char*);
125 extern int PetscObjectGetName(PetscObject,char**);
126 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
127 extern int PetscObjectReference(PetscObject);
128 extern int PetscObjectGetNewTag(PetscObject,int *);
129 extern int PetscObjectRestoreNewTag(PetscObject,int *);
130 
131 #include "petscerror.h"
132 #include "petschead.h"
133 #include "petsclog.h"
134 
135 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
136 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
137 
138 /*M
139     PetscBarrier - Blocks Until this routine is executed by all
140                    processors owning the object A.
141 
142    Input Parameters:
143 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
144 
145    Synopsis:
146    void PetscBarrier(PetscObject obj)
147 
148   Notes:
149   This routine calls MPI_Barrier with the communicator
150   of the PETSc Object "A".
151 
152 .keywords: barrier, petscobject
153 M*/
154 
155 #define PetscBarrier(A) \
156   { \
157     PetscValidHeader(A); \
158     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
159     MPI_Barrier(((PetscObject)A)->comm); \
160     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
161   }
162 
163 extern int PetscMPIDump(FILE *);
164 
165 /*
166       This code allows one to pass a PETSc object in C
167   to a Fortran routine, where (like all PETSc objects in
168   Fortran) it is treated as an integer.
169 */
170 extern int PetscCObjectToFortranObject(void *a,int *b);
171 extern int PetscFortranObjectToCObject(int a,void *b);
172 
173 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
174 extern int  PetscFClose(MPI_Comm,FILE*);
175 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
176 extern int  PetscPrintf(MPI_Comm,char *,...);
177 
178 extern int  PetscSynchronizedPrintf(MPI_Comm,char *,...);
179 extern int  PetscSynchronizedFlush(MPI_Comm);
180 
181 /*
182    For incremental debugging
183 */
184 extern int PetscCompare;
185 extern int PetscCompareDouble(double);
186 extern int PetscCompareScalar(Scalar);
187 extern int PetscCompareInt(int);
188 
189 /*
190    For use in debuggers
191 */
192 extern int PetscGlobalRank,PetscGlobalSize;
193 extern int PetscIntView(int,int*,Viewer);
194 extern int PetscDoubleView(int,double *,Viewer);
195 
196 #endif
197