xref: /petsc/include/petsc.h (revision 48c77eb08ca7f772a493f9ff704e8ac0c69a5c02)
1 /* $Id: petsc.h,v 1.138 1996/10/09 15:20:26 balay 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 PetscAbsScalar(a) abs(a)
24 /*
25   The new complex class for GNU C++ is based on templates and is not backward
26   compatible with all previous complex class libraries.
27 */
28 #if defined(USES_TEMPLATED_COMPLEX)
29 #define Scalar            complex<double>
30 #else
31 #define Scalar            complex
32 #endif
33 #else
34 #define MPIU_SCALAR       MPI_DOUBLE
35 #define PetscReal(a)      a
36 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
37 #define Scalar            double
38 #endif
39 
40 extern MPI_Comm PETSC_COMM_WORLD;
41 extern int      PetscInitializedCalled;
42 extern int      PetscSetCommWorld(MPI_Comm);
43 
44 /* PETSC_i is the imaginary number, i */
45 extern  Scalar            PETSC_i;
46 
47 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
48 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
49 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
50 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
51 
52 /*
53     Defines the malloc employed by PETSc. Users may employ these routines as well.
54 */
55 extern void *(*PetscTrMalloc)(unsigned int,int,char*);
56 extern int  (*PetscTrFree)(void *,int,char*);
57 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
58 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FILE__)
59 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
60 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FILE__)
61 
62 extern int   PetscTrDump(FILE *);
63 extern int   PetscTrSpace( double *, double *,double *);
64 extern int   PetscTrValid(int ,char*);
65 extern int   PetscTrDebugLevel(int);
66 
67 extern void  PetscMemcpy(void *,void *,int);
68 extern void  PetscMemzero(void *,int);
69 extern int   PetscMemcmp(void*, void*, int);
70 extern int   PetscStrlen(char *);
71 extern int   PetscStrcmp(char *,char *);
72 extern int   PetscStrncmp(char *,char *,int );
73 extern void  PetscStrcpy(char *,char *);
74 extern void  PetscStrcat(char *,char *);
75 extern void  PetscStrncat(char *,char *,int);
76 extern void  PetscStrncpy(char *,char *,int);
77 extern char* PetscStrchr(char *,char);
78 extern char* PetscStrrchr(char *,char);
79 extern char* PetscStrstr(char*,char*);
80 extern char* PetscStrtok(char*,char*);
81 extern char* PetscStrrtok(char*,char*);
82 
83 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
84 #define PETSC_NULL            0
85 #define PETSC_DECIDE         -1
86 #define PETSC_DEFAULT        -2
87 
88 /*
89    Defines the directory where the compiled source is located; used
90    in print error messages. __DIR__ is usually defined in the makefile.
91 */
92 #if !defined(__DIR__)
93 #define __DIR__ 0
94 #endif
95 
96 /*
97      Error codes (incomplete)
98 */
99 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
100 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
101 #define PETSC_ERR_ARG 57   /* bad input argument */
102 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
103 #define PETSC_ERR_SIG 59   /* signal received */
104 #define PETSC_ERR_SIZ 60   /* nonconforming object sizes */
105 
106 #if defined(PETSC_DEBUG)
107 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
108 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
109                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
110 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
111 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
112 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
113 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
114 #else
115 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
116 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
117                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
118 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
119 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
120 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
121 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
122 #endif
123 
124 /*
125     Each PETSc object class has it's own cookie (internal integer in the
126   data structure used for error checking). These are all defined by an offset
127   from the lowest one, PETSC_COOKIE.
128 */
129 #define PETSC_COOKIE                1211211
130 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30
131 extern int LARGEST_PETSC_COOKIE;
132 
133 #include "viewer.h"
134 #include "options.h"
135 
136 extern double PetscGetTime();
137 extern void   PetscSleep(int);
138 
139 extern int    PetscInitialize(int*,char***,char*,char*);
140 extern int    PetscFinalize();
141 extern void   PetscInitializeFortran();
142 
143 /*
144     Functions that can act on any PETSc object.
145 */
146 typedef struct _PetscObject* PetscObject;
147 extern int PetscObjectDestroy(PetscObject);
148 extern int PetscObjectExists(PetscObject,int*);
149 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
150 extern int PetscObjectGetCookie(PetscObject,int *cookie);
151 extern int PetscObjectGetChild(PetscObject,void **child);
152 extern int PetscObjectGetType(PetscObject,int *type);
153 extern int PetscObjectSetName(PetscObject,char*);
154 extern int PetscObjectGetName(PetscObject,char**);
155 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),int (*)(void*));
156 extern int PetscObjectReference(PetscObject);
157 extern int PetscObjectGetNewTag(PetscObject,int *);
158 extern int PetscObjectRestoreNewTag(PetscObject,int *);
159 
160 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
161 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
162 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
163 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
164 extern int PetscError(int,char*,char*,int,char*);
165 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
166 extern int PetscPopErrorHandler();
167 
168 extern int PetscDefaultSignalHandler(int,void*);
169 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
170 extern int PetscPopSignalHandler();
171 #define PETSC_FP_TRAP_OFF    0
172 #define PETSC_FP_TRAP_ON     1
173 extern int PetscSetFPTrap(int);
174 
175 #include "phead.h"
176 #include "plog.h"
177 
178 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
179 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
180 
181 /*M
182     PetscBarrier - Blocks Until this routine is executed by all
183                    processors owning the object A.
184 
185    Input Parameters:
186 .  A - PETSc object  ( Mat, Vec, IS, SNES etc...)
187 
188    Synopsis:
189    void PetscBarrier(PetscObject obj)
190 
191   Notes:
192   This routine calls MPI_Barrier with the communicator
193   of the PETSc Object "A".
194 
195 .keywords: barrier, petscobject
196 M*/
197 
198 #define PetscBarrier(A) \
199   { \
200     PetscValidHeader(A); \
201     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
202     MPI_Barrier(((PetscObject)A)->comm); \
203     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
204   }
205 
206 extern int PetscMPIDump(FILE *);
207 
208 /*
209       This code allows one to pass a PETSc object in C
210   to a Fortran routine, where (like all PETSc objects in
211   Fortran) it is treated as an integer.
212 */
213 extern int PetscCObjectToFortranObject(void *a,int *b);
214 extern int PetscFortranObjectToCObject(int a,void *b);
215 
216 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
217 extern int  PetscFClose(MPI_Comm,FILE*);
218 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
219 extern int  PetscPrintf(MPI_Comm,char *,...);
220 
221 /*
222    For incremental debugging
223 */
224 extern int PetscCompare;
225 extern int PetscCompareDouble(double);
226 extern int PetscCompareScalar(Scalar);
227 extern int PetscCompareInt(int);
228 
229 /*
230    For use in debuggers
231 */
232 extern int PetscGlobalRank,PetscGlobalSize;
233 extern int PetscIntView(int,int*,Viewer);
234 extern int PetscDoubleView(int,double *,Viewer);
235 
236 #endif
237