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