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