xref: /petsc/include/petsc.h (revision 639f9d9dbbc54d6ac4e42e98283c540b41bb2cee)
1 /* $Id: petsc.h,v 1.142 1996/10/29 18:26:31 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.16, Released ???. ?, ????."
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*);
60 extern int  (*PetscTrFree)(void *,int,char*);
61 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
62 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FILE__)
63 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
64 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FILE__)
65 
66 extern int   PetscTrDump(FILE *);
67 extern int   PetscTrSpace( double *, double *,double *);
68 extern int   PetscTrValid(int ,char*);
69 extern int   PetscTrDebugLevel(int);
70 
71 extern void  PetscMemcpy(void *,void *,int);
72 extern void  PetscMemzero(void *,int);
73 extern int   PetscMemcmp(void*, void*, int);
74 extern int   PetscStrlen(char *);
75 extern int   PetscStrcmp(char *,char *);
76 extern int   PetscStrncmp(char *,char *,int );
77 extern void  PetscStrcpy(char *,char *);
78 extern void  PetscStrcat(char *,char *);
79 extern void  PetscStrncat(char *,char *,int);
80 extern void  PetscStrncpy(char *,char *,int);
81 extern char* PetscStrchr(char *,char);
82 extern char* PetscStrrchr(char *,char);
83 extern char* PetscStrstr(char*,char*);
84 extern char* PetscStrtok(char*,char*);
85 extern char* PetscStrrtok(char*,char*);
86 
87 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
88 #define PETSC_NULL            0
89 #define PETSC_DECIDE         -1
90 #define PETSC_DEFAULT        -2
91 
92 /*
93    Defines the directory where the compiled source is located; used
94    in print error messages. __DIR__ is usually defined in the makefile.
95 */
96 #if !defined(__DIR__)
97 #define __DIR__ 0
98 #endif
99 
100 /*
101      Error codes (incomplete)
102 */
103 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
104 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
105 #define PETSC_ERR_ARG 57   /* bad input argument */
106 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
107 #define PETSC_ERR_SIG 59   /* signal received */
108 #define PETSC_ERR_SIZ 60   /* nonconforming object sizes */
109 #define PETSC_ERR_IDN 61   /* two arguments not allowed to be the same */
110 
111 #if defined(PETSC_DEBUG)
112 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
113 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
114                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
115 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
116 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
117 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
118 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
119 #else
120 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
121 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
122                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
123 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
124 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
125 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
126 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
127 #endif
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/plog/src/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 #include "viewer.h"
141 #include "options.h"
142 
143 extern double PetscGetTime();
144 extern void   PetscSleep(int);
145 
146 extern int    PetscInitialize(int*,char***,char*,char*);
147 extern int    PetscFinalize();
148 extern void   PetscInitializeFortran();
149 
150 /*
151     Functions that can act on any PETSc object.
152 */
153 typedef struct _PetscObject* PetscObject;
154 extern int PetscObjectDestroy(PetscObject);
155 extern int PetscObjectExists(PetscObject,int*);
156 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
157 extern int PetscObjectGetCookie(PetscObject,int *cookie);
158 extern int PetscObjectGetChild(PetscObject,void **child);
159 extern int PetscObjectGetType(PetscObject,int *type);
160 extern int PetscObjectSetName(PetscObject,char*);
161 extern int PetscObjectGetName(PetscObject,char**);
162 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
163 extern int PetscObjectReference(PetscObject);
164 extern int PetscObjectGetNewTag(PetscObject,int *);
165 extern int PetscObjectRestoreNewTag(PetscObject,int *);
166 
167 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
168 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
169 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
170 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
171 extern int PetscError(int,char*,char*,int,char*);
172 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
173 extern int PetscPopErrorHandler();
174 
175 extern int PetscDefaultSignalHandler(int,void*);
176 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
177 extern int PetscPopSignalHandler();
178 #define PETSC_FP_TRAP_OFF    0
179 #define PETSC_FP_TRAP_ON     1
180 extern int PetscSetFPTrap(int);
181 
182 #include "phead.h"
183 #include "plog.h"
184 
185 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
186 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
187 
188 /*M
189     PetscBarrier - Blocks Until this routine is executed by all
190                    processors owning the object A.
191 
192    Input Parameters:
193 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
194 
195    Synopsis:
196    void PetscBarrier(PetscObject obj)
197 
198   Notes:
199   This routine calls MPI_Barrier with the communicator
200   of the PETSc Object "A".
201 
202 .keywords: barrier, petscobject
203 M*/
204 
205 #define PetscBarrier(A) \
206   { \
207     PetscValidHeader(A); \
208     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
209     MPI_Barrier(((PetscObject)A)->comm); \
210     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
211   }
212 
213 extern int PetscMPIDump(FILE *);
214 
215 /*
216       This code allows one to pass a PETSc object in C
217   to a Fortran routine, where (like all PETSc objects in
218   Fortran) it is treated as an integer.
219 */
220 extern int PetscCObjectToFortranObject(void *a,int *b);
221 extern int PetscFortranObjectToCObject(int a,void *b);
222 
223 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
224 extern int  PetscFClose(MPI_Comm,FILE*);
225 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
226 extern int  PetscPrintf(MPI_Comm,char *,...);
227 
228 /*
229    For incremental debugging
230 */
231 extern int PetscCompare;
232 extern int PetscCompareDouble(double);
233 extern int PetscCompareScalar(Scalar);
234 extern int PetscCompareInt(int);
235 
236 /*
237    For use in debuggers
238 */
239 extern int PetscGlobalRank,PetscGlobalSize;
240 extern int PetscIntView(int,int*,Viewer);
241 extern int PetscDoubleView(int,double *,Viewer);
242 
243 #endif
244