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