xref: /petsc/include/petsc.h (revision 4e627d3a034d8dbe6c0b444d105a274c665112f3)
1 /* $Id: petsc.h,v 1.105 1996/04/07 16:53:59 curfman Exp bsmith $ */
2 /*
3    PETSc header file, included in all PETSc programs.
4 */
5 #if !defined(__PETSC_PACKAGE)
6 #define __PETSC_PACKAGE
7 
8 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.13, Released ???, 1996."
9 
10 #include <stdio.h>
11 
12 /*
13     This is to deal with missing entries in the Gnu gcc include files
14   the Sun4 machines. It's ugly but then so is the Gnu compiler!
15 */
16 #if defined(PARCH_sun4) && !defined(__cplusplus) && defined(_Gnu_)
17 extern int fprintf(FILE*,const char*,...);
18 extern int printf(const char*,...);
19 extern int fflush(FILE *);
20 extern int fclose(FILE *);
21 extern void fscanf(FILE *,char *,...);
22 #endif
23 
24 /* MPI interface */
25 #include "mpi.h"
26 #if defined(PETSC_COMPLEX)
27 extern MPI_Datatype MPIU_COMPLEX;
28 #define MPIU_SCALAR MPIU_COMPLEX
29 #else
30 #define MPIU_SCALAR MPI_DOUBLE
31 #endif
32 
33 #if defined(PETSC_COMPLEX)
34 /* work around for bug in alpha g++ compiler */
35 #if defined(PARCH_alpha)
36 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
37 #endif
38 #include <complex.h>
39 #define PetscReal(a) real(a)
40 #define Scalar       complex
41 #else
42 #define PetscReal(a) a
43 #define Scalar       double
44 #endif
45 
46 extern void *(*PetscMalloc)(unsigned int,int,char*);
47 extern int  (*PetscFree)(void *,int,char*);
48 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
49 
50 #define PetscMalloc(a)       (*PetscMalloc)(a,__LINE__,__FILE__)
51 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
52 #define PetscFree(a)         (*PetscFree)(a,__LINE__,__FILE__)
53 
54 extern int  PetscTrDump(FILE *);
55 extern int  PetscTrSpace( double *, double *,double *);
56 extern int  PetscTrValid();
57 extern int  PetscTrDebugLevel(int);
58 
59 extern void  PetscMemcpy(void *,void *,int);
60 extern void  PetscMemzero(void *,int);
61 extern int   PetscMemcmp(void*, void*, int);
62 extern int   PetscStrlen(char *);
63 extern int   PetscStrcmp(char *,char *);
64 extern int   PetscStrncmp(char *,char *,int );
65 extern void  PetscStrcpy(char *,char *);
66 extern void  PetscStrcat(char *,char *);
67 extern void  PetscStrncat(char *,char *,int);
68 extern void  PetscStrncpy(char *,char *,int);
69 extern char* PetscStrchr(char *,char);
70 extern char* PetscStrrchr(char *,char);
71 extern char* PetscStrstr(char*,char*);
72 extern char* PetscStrtok(char*,char*);
73 extern char* PetscStrrtok(char*,char*);
74 
75 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
76 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
77 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
78 
79 #define PETSC_NULL          0
80 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
81 
82 #if defined(PETSC_COMPLEX)
83 #define PetscAbsScalar(a)     abs(a)
84 #else
85 #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
86 #endif
87 
88 /*  Macros for error checking */
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 #define PETSC_COOKIE                1211211
122 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30
123 extern int LARGEST_PETSC_COOKIE;
124 
125 #define PETSC_DECIDE         -1
126 #define PETSC_DEFAULT        -2
127 
128 #include "viewer.h"
129 #include "options.h"
130 
131 extern double PetscGetTime();
132 extern double PetscGetFlops();
133 extern void   PetscSleep(int);
134 
135 extern int PetscInitialize(int*,char***,char*,char*);
136 extern int PetscFinalize();
137 
138 typedef struct _PetscObject* PetscObject;
139 extern int PetscObjectDestroy(PetscObject);
140 extern int PetscObjectExists(PetscObject,int*);
141 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
142 extern int PetscObjectGetCookie(PetscObject,int *cookie);
143 extern int PetscObjectGetType(PetscObject,int *type);
144 extern int PetscObjectSetName(PetscObject,char*);
145 extern int PetscObjectGetName(PetscObject,char**);
146 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **));
147 #define PetscObjectChild(a) (((PetscObject) (a))->child)
148 
149 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
150 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
151 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
152 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
153 extern int PetscError(int,char*,char*,int,char*);
154 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
155 extern int PetscPopErrorHandler();
156 
157 extern int PetscSetDebugger(char *,int,char *);
158 extern int PetscAttachDebugger();
159 
160 extern int PetscDefaultSignalHandler(int,void*);
161 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
162 extern int PetscPopSignalHandler();
163 #define FP_TRAP_OFF    0
164 #define FP_TRAP_ON     1
165 #define FP_TRAP_ALWAYS 2
166 extern int PetscSetFPTrap(int);
167 
168 
169 #include "phead.h"
170 #include "plog.h"
171 
172 #define PetscBarrier(A) \
173   {PetscValidHeader(A); \
174    PLogEventBegin(Petsc_Barrier,A,0,0,0); \
175    MPI_Barrier(((PetscObject)A)->comm); \
176    PLogEventEnd(Petsc_Barrier,A,0,0,0);}
177 
178 /*
179       This code allows one to pass a PETSc object in C
180   to a Fortran routine, where (like all PETSc objects in
181   Fortran) it is treated as an integer.
182 */
183 extern int PetscCObjectToFortranObject(void *a,int *b);
184 extern int PetscFortranObjectToCObject(int a,void *b);
185 
186 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
187 extern int  PetscFClose(MPI_Comm,FILE*);
188 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
189 extern int  PetscPrintf(MPI_Comm,char *,...);
190 
191 extern int  PetscSetDisplay(MPI_Comm,char *,int);
192 
193 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
194 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
195 
196 #endif
197