xref: /petsc/include/petsc.h (revision 9ea5d5aec97b6e040a49afd1b9ac5121faa7475f)
1 /* $Id: petsc.h,v 1.95 1996/02/09 01:56:30 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.Beta.12, 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 #include "mpiu.h"
27 
28 #if defined(PETSC_COMPLEX)
29 /* work around for bug in alpha g++ compiler */
30 #if defined(PARCH_alpha)
31 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
32 #endif
33 #include <complex.h>
34 #define PetscReal(a) real(a)
35 #define Scalar       complex
36 #else
37 #define PetscReal(a) a
38 #define Scalar       double
39 #endif
40 
41 extern void *(*PetscMalloc)(unsigned int,int,char*);
42 extern int  (*PetscFree)(void *,int,char*);
43 #define PetscMalloc(a)       (*PetscMalloc)(a,__LINE__,__FILE__)
44 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
45 #define PetscFree(a)         (*PetscFree)(a,__LINE__,__FILE__)
46 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
47 
48 extern int  TrDump(FILE *);
49 extern int  TrSpace( double *, double *,double *);
50 
51 extern void  PetscMemcpy(void *,void *,int);
52 extern void  PetscMemzero(void *,int);
53 extern int   PetscMemcmp(char*, char*, int);
54 extern int   PetscStrlen(char *);
55 extern int   PetscStrcmp(char *,char *);
56 extern int   PetscStrncmp(char *,char *,int );
57 extern void  PetscStrcpy(char *,char *);
58 extern void  PetscStrcat(char *,char *);
59 extern void  PetscStrncat(char *,char *,int);
60 extern void  PetscStrncpy(char *,char *,int);
61 extern char* PetscStrchr(char *,char);
62 extern char* PetscStrrchr(char *,char);
63 extern char* PetscStrstr(char*,char*);
64 extern char* PetscStrtok(char*,char*);
65 extern char* PetscStrrtok(char*,char*);
66 
67 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
68 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
69 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
70 
71 #define PETSC_NULL          0
72 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
73 
74 #if defined(PETSC_COMPLEX)
75 #define PetscAbsScalar(a)     abs(a)
76 #else
77 #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
78 #endif
79 
80 /*  Macros for error checking */
81 #if !defined(__DIR__)
82 #define __DIR__ 0
83 #endif
84 
85 /*
86      Error codes (incomplete)
87 */
88 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
89 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
90 #define PETSC_ERR_ARG 57   /* bad input argument */
91 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
92 #define PETSC_ERR_SIG 59   /* signal received */
93 
94 #if defined(PETSC_DEBUG)
95 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
96 #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
97                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
98 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
99 #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
100 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
101 #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
102 #else
103 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
104 #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
105                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
106 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
107 #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
108 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
109 #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
110 #endif
111 
112 #define PETSC_COOKIE                1211211
113 #define LARGEST_PETSC_COOKIE_STATIC PETSC_COOKIE + 30
114 extern int LARGEST_PETSC_COOKIE;
115 
116 #define PETSC_DECIDE         -1
117 #define PETSC_DEFAULT        -2
118 
119 #include "viewer.h"
120 #include "options.h"
121 
122 extern double PetscGetTime();
123 extern double PetscGetFlops();
124 extern void PetscSleep(int);
125 
126 extern int PetscInitialize(int*,char***,char*,char*,char*);
127 extern int PetscFinalize();
128 
129 typedef struct _PetscObject* PetscObject;
130 extern int PetscObjectDestroy(PetscObject);
131 extern int PetscObjectExists(PetscObject,int*);
132 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
133 extern int PetscObjectGetCookie(PetscObject,int *cookie);
134 extern int PetscObjectGetType(PetscObject,int *type);
135 extern int PetscObjectSetName(PetscObject,char*);
136 extern int PetscObjectGetName(PetscObject,char**);
137 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **));
138 #define PetscObjectChild(a) (((PetscObject) (a))->child)
139 
140 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
141 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
142 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
143 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
144 extern int PetscError(int,char*,char*,int,char*);
145 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
146 extern int PetscPopErrorHandler();
147 
148 extern int PetscSetDebugger(char *,int,char *);
149 extern int PetscAttachDebugger();
150 
151 extern int PetscDefaultSignalHandler(int,void*);
152 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
153 extern int PetscPopSignalHandler();
154 #define FP_TRAP_OFF    0
155 #define FP_TRAP_ON     1
156 #define FP_TRAP_ALWAYS 2
157 extern int PetscSetFPTrap(int);
158 
159 
160 #include "phead.h"
161 #include "plog.h"
162 
163 #endif
164