xref: /petsc/include/petsc.h (revision ac21db08aa40af791c2efdc4ec91ffd8ae7ad00f)
1 /* $Id: petsc.h,v 1.93 1996/01/26 04:35:46 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 PETSC_DECIDE         -1
114 #define PETSC_DEFAULT        -2
115 
116 #include "viewer.h"
117 #include "options.h"
118 
119 extern double PetscGetTime();
120 extern double PetscGetFlops();
121 extern void PetscSleep(int);
122 
123 extern int PetscInitialize(int*,char***,char*,char*,char*);
124 extern int PetscFinalize();
125 
126 typedef struct _PetscObject* PetscObject;
127 extern int PetscObjectDestroy(PetscObject);
128 extern int PetscObjectExists(PetscObject,int*);
129 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
130 extern int PetscObjectGetCookie(PetscObject,int *cookie);
131 extern int PetscObjectGetType(PetscObject,int *type);
132 extern int PetscObjectSetName(PetscObject,char*);
133 extern int PetscObjectGetName(PetscObject,char**);
134 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **));
135 #define PetscObjectChild(a) (((PetscObject) (a))->child)
136 
137 extern int PetscTraceBackErrorHandler(int,char*,char*,int,char*,void*);
138 extern int PetscStopErrorHandler(int,char*,char*,int,char*,void*);
139 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
140 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
141 extern int PetscError(int,char*,char*,int,char*);
142 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
143 extern int PetscPopErrorHandler();
144 
145 extern int PetscSetDebugger(char *,int,char *);
146 extern int PetscAttachDebugger();
147 
148 extern int PetscDefaultSignalHandler(int,void*);
149 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
150 extern int PetscPopSignalHandler();
151 #define FP_TRAP_OFF    0
152 #define FP_TRAP_ON     1
153 #define FP_TRAP_ALWAYS 2
154 extern int PetscSetFPTrap(int);
155 
156 
157 #include "phead.h"
158 #include "plog.h"
159 
160 #endif
161