xref: /petsc/include/petsc.h (revision c005e166144a6ac88a244813670ca9f5d5dfe78d)
1 /* $Id: petsc.h,v 1.124 1996/07/25 14:01:12 bsmith 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.14, Released July 25, 1996."
9 
10 #include <stdio.h>
11 
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 #if defined(USES_TEMPLATED_COMPLEX)
25 #define Scalar            complex<double>
26 #else
27 #define Scalar            complex
28 #endif
29 #else
30 #define MPIU_SCALAR       MPI_DOUBLE
31 #define PetscReal(a)      a
32 #define PetscAbsScalar(a) ( ((a)<0.0)   ? -(a) : (a) )
33 #define Scalar            double
34 #endif
35 
36 extern void *(*PetscTrMalloc)(unsigned int,int,char*);
37 extern int  (*PetscTrFree)(void *,int,char*);
38 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
39 #define PetscMalloc(a)       (*PetscTrMalloc)(a,__LINE__,__FILE__)
40 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
41 #define PetscFree(a)         (*PetscTrFree)(a,__LINE__,__FILE__)
42 
43 extern int  PetscTrDump(FILE *);
44 extern int  PetscTrSpace( double *, double *,double *);
45 extern int  PetscTrValid(int ,char*);
46 extern int  PetscTrDebugLevel(int);
47 
48 extern void  PetscMemcpy(void *,void *,int);
49 extern void  PetscMemzero(void *,int);
50 extern int   PetscMemcmp(void*, void*, int);
51 extern int   PetscStrlen(char *);
52 extern int   PetscStrcmp(char *,char *);
53 extern int   PetscStrncmp(char *,char *,int );
54 extern void  PetscStrcpy(char *,char *);
55 extern void  PetscStrcat(char *,char *);
56 extern void  PetscStrncat(char *,char *,int);
57 extern void  PetscStrncpy(char *,char *,int);
58 extern char* PetscStrchr(char *,char);
59 extern char* PetscStrrchr(char *,char);
60 extern char* PetscStrstr(char*,char*);
61 extern char* PetscStrtok(char*,char*);
62 extern char* PetscStrrtok(char*,char*);
63 
64 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
65 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
66 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
67 #define PetscAbsDouble(a)  ( ((a)<0)   ? -(a) : (a) )
68 
69 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
70 #define PETSC_NULL            0
71 #define PETSC_DECIDE         -1
72 #define PETSC_DEFAULT        -2
73 
74 /*  Macros for error checking */
75 #if !defined(__DIR__)
76 #define __DIR__ 0
77 #endif
78 
79 /*
80      Error codes (incomplete)
81 */
82 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
83 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
84 #define PETSC_ERR_ARG 57   /* bad input argument */
85 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
86 #define PETSC_ERR_SIG 59   /* signal received */
87 #define PETSC_ERR_SIZ 60   /* nonconforming object sizes */
88 
89 #if defined(PETSC_DEBUG)
90 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
91 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
92                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
93 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
94 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
95 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
96 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
97 #else
98 #define SETERRQ(n,s)   {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
99 #define SETERRA(n,s)   {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
100                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
101 #define CHKERRQ(n)     {if (n) SETERRQ(n,(char *)0);}
102 #define CHKERRA(n)     {if (n) SETERRA(n,(char *)0);}
103 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
104 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
105 #endif
106 
107 #define PETSC_COOKIE                1211211
108 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30
109 extern int LARGEST_PETSC_COOKIE;
110 
111 #include "viewer.h"
112 #include "options.h"
113 
114 extern double PetscGetTime();
115 extern void   PetscSleep(int);
116 
117 extern int PetscInitialize(int*,char***,char*,char*);
118 extern int PetscFinalize();
119 extern void PetscInitializeFortran();
120 
121 typedef struct _PetscObject* PetscObject;
122 extern int PetscObjectDestroy(PetscObject);
123 extern int PetscObjectExists(PetscObject,int*);
124 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
125 extern int PetscObjectGetCookie(PetscObject,int *cookie);
126 extern int PetscObjectGetChild(PetscObject,void **child);
127 extern int PetscObjectGetType(PetscObject,int *type);
128 extern int PetscObjectSetName(PetscObject,char*);
129 extern int PetscObjectGetName(PetscObject,char**);
130 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **),
131                               int (*)(void*));
132 extern int PetscObjectReference(PetscObject);
133 extern int PetscObjectGetNewTag(PetscObject,int *);
134 extern int PetscObjectRestoreNewTag(PetscObject,int *);
135 
136 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
137 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
138 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
139 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
140 extern int PetscError(int,char*,char*,int,char*);
141 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
142 extern int PetscPopErrorHandler();
143 
144 extern int PetscDefaultSignalHandler(int,void*);
145 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
146 extern int PetscPopSignalHandler();
147 #define PETSC_FP_TRAP_OFF    0
148 #define PETSC_FP_TRAP_ON     1
149 #define PETSC_FP_TRAP_ALWAYS 2
150 extern int PetscSetFPTrap(int);
151 
152 #include "phead.h"
153 #include "plog.h"
154 
155 extern int  PetscSequentialPhaseBegin(MPI_Comm,int);
156 extern int  PetscSequentialPhaseEnd(MPI_Comm,int);
157 #define PetscBarrier(A) \
158   { \
159     PetscValidHeader(A); \
160     PLogEventBegin(Petsc_Barrier,A,0,0,0); \
161     MPI_Barrier(((PetscObject)A)->comm); \
162     PLogEventEnd(Petsc_Barrier,A,0,0,0); \
163   }
164 
165 extern int PetscMPIDump(FILE *);
166 
167 /*
168       This code allows one to pass a PETSc object in C
169   to a Fortran routine, where (like all PETSc objects in
170   Fortran) it is treated as an integer.
171 */
172 extern int PetscCObjectToFortranObject(void *a,int *b);
173 extern int PetscFortranObjectToCObject(int a,void *b);
174 
175 extern FILE *PetscFOpen(MPI_Comm,char *,char *);
176 extern int  PetscFClose(MPI_Comm,FILE*);
177 extern int  PetscFPrintf(MPI_Comm,FILE*,char *,...);
178 extern int  PetscPrintf(MPI_Comm,char *,...);
179 
180 extern int PetscIntView(int,int*,Viewer);
181 extern int PetscDoubleView(int,double *,Viewer);
182 
183 #endif
184