xref: /petsc/include/petsc.h (revision b4874afa33ef89d436bd5cc157aada57df95d045)
1 /* $Id: petsc.h,v 1.89 1996/01/23 18:40:41 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.11, Released Jan. 23, 1996."
9 
10 #include <stdio.h>
11 
12 /*
13     This is 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  TrGetMaximumAllocated(double*);
50 extern int  TrSpace( int *, int *);
51 
52 extern void  PetscMemcpy(void *,void *,int);
53 extern void  PetscMemzero(void *,int);
54 extern int   PetscMemcmp(char*, char*, int);
55 extern int   PetscStrlen(char *);
56 extern int   PetscStrcmp(char *,char *);
57 extern int   PetscStrncmp(char *,char *,int );
58 extern void  PetscStrcpy(char *,char *);
59 extern void  PetscStrcat(char *,char *);
60 extern void  PetscStrncat(char *,char *,int);
61 extern void  PetscStrncpy(char *,char *,int);
62 extern char* PetscStrchr(char *,char);
63 extern char* PetscStrrchr(char *,char);
64 extern char* PetscStrstr(char*,char*);
65 extern char* PetscStrtok(char*,char*);
66 extern char* PetscStrrtok(char*,char*);
67 
68 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
69 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
70 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
71 
72 #define PETSC_NULL          0
73 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
74 
75 #if defined(PETSC_COMPLEX)
76 #define PetscAbsScalar(a)     abs(a)
77 #else
78 #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
79 #endif
80 
81 /*  Macros for error checking */
82 #if !defined(__DIR__)
83 #define __DIR__ 0
84 #endif
85 
86 /*
87      Error codes (incomplete)
88 */
89 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
90 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
91 #define PETSC_ERR_ARG 57   /* bad input argument */
92 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
93 #define PETSC_ERR_SIG 59   /* signal received */
94 
95 #if defined(PETSC_DEBUG)
96 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
97 #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
98                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
99 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
100 #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
101 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
102 #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
103 #else
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 #endif
112 
113 #define PETSC_COOKIE         1211211
114 #define PETSC_DECIDE         -1
115 #define PETSC_DEFAULT        -2
116 
117 #include "viewer.h"
118 #include "options.h"
119 
120 extern double PetscGetTime();
121 extern double PetscGetFlops();
122 extern void PetscSleep(int);
123 
124 extern int PetscInitialize(int*,char***,char*,char*,char*);
125 extern int PetscFinalize();
126 
127 typedef struct _PetscObject* PetscObject;
128 extern int PetscObjectDestroy(PetscObject);
129 extern int PetscObjectExists(PetscObject,int*);
130 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
131 extern int PetscObjectGetCookie(PetscObject,int *cookie);
132 extern int PetscObjectGetType(PetscObject,int *type);
133 extern int PetscObjectSetName(PetscObject,char*);
134 extern int PetscObjectGetName(PetscObject,char**);
135 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **));
136 #define PetscObjectChild(a) (((PetscObject) (a))->child)
137 
138 extern int PetscDefaultErrorHandler(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    Definitions used for the Fortran interface:
158    FORTRANCAPS:       Names are uppercase, no trailing underscore
159    FORTRANUNDERSCORE: Names are lowercase, trailing underscore
160  */
161 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
162 #define FORTRANCAPS
163 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
164 #define FORTRANUNDERSCORE
165 #endif
166 
167 #include "phead.h"
168 #include "plog.h"
169 
170 #endif
171