xref: /petsc/include/petsc.h (revision 2d3f70b590038937f900a8656dd709b442ef6fcb)
1 /* $Id: petsc.h,v 1.131 1996/09/12 16:28:47 bsmith Exp curfman $ */
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 world communicator */
41 extern MPI_Comm PETSC_COMM_WORLD;
42 extern int      PetscInitializedCalled;
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 extern int PetscSetCommWorld(MPI_Comm);
160 
161 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
162 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
163 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
164 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
165 extern int PetscError(int,char*,char*,int,char*);
166 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
167 extern int PetscPopErrorHandler();
168 
169 extern int PetscDefaultSignalHandler(int,void*);
170 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
171 extern int PetscPopSignalHandler();
172 #define PETSC_FP_TRAP_OFF    0
173 #define PETSC_FP_TRAP_ON     1
174 extern int PetscSetFPTrap(int);
175 
176 #include "phead.h"
177 #include "plog.h"
178 
179 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
180 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
181 /*M PetscBarrier - Blocks Until this routine is executed by all
182     processors owning the object A
183 
184   Input Parameters:
185 . A - PETSc object  ( Mat, Vec, IS, SNES etc...)
186 
187   Notes:
188   This routine calls MPI_Barrier with the communicator
189   of the PETSc Object "A".
190 
191 .keywords: barrier, petscobject
192 M*/
193 #define PetscBarrier(A) \
194   { \
195     PetscValidHeader(A); \
196     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
197     MPI_Barrier(((PetscObject)A)->comm); \
198     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
199   }
200 
201 extern int PetscMPIDump(FILE *);
202 
203 /*
204       This code allows one to pass a PETSc object in C
205   to a Fortran routine, where (like all PETSc objects in
206   Fortran) it is treated as an integer.
207 */
208 extern int PetscCObjectToFortranObject(void *a,int *b);
209 extern int PetscFortranObjectToCObject(int a,void *b);
210 
211 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
212 extern int  PetscFClose(MPI_Comm,FILE*);
213 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
214 extern int  PetscPrintf(MPI_Comm,char *,...);
215 
216 extern int PetscIntView(int,int*,Viewer);
217 extern int PetscDoubleView(int,double *,Viewer);
218 
219 /*
220    For use in debuggers
221 */
222 extern int PetscGlobalRank,PetscGlobalSize;
223 
224 #endif
225