xref: /petsc/include/petsc.h (revision ee0de897fec99be7c10c7637bbd068d61b2ce625)
1 /* $Id: petsc.h,v 1.86 1996/01/16 22:13:39 balay Exp balay $ */
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 ?."
9 
10 #include <stdio.h>
11 #if defined(PARCH_sun4) && !defined(__cplusplus) && defined(_Gnu_)
12 extern int fprintf(FILE*,const char*,...);
13 extern int printf(const char*,...);
14 extern int fflush(FILE *);
15 extern int fclose(FILE *);
16 extern void fscanf(FILE *,char *,...);
17 #endif
18 
19 /* MPI interface */
20 #include "mpi.h"
21 #include "mpiu.h"
22 
23 #if defined(PETSC_COMPLEX)
24 /* work around for bug in alpha g++ compiler */
25 #if defined(PARCH_alpha)
26 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
27 #endif
28 #include <complex.h>
29 #define PETSCREAL(a) real(a)
30 #define Scalar       complex
31 #else
32 #define PETSCREAL(a) a
33 #define Scalar       double
34 #endif
35 
36 extern void *(*PetscMalloc)(unsigned int,int,char*);
37 extern int  (*PetscFree)(void *,int,char*);
38 #define PetscMalloc(a)       (*PetscMalloc)(a,__LINE__,__FILE__)
39 #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
40 #define PetscFree(a)         (*PetscFree)(a,__LINE__,__FILE__)
41 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
42 
43 extern int  TrDump(FILE *);
44 extern int  TrGetMaximumAllocated(double*);
45 extern int  TrSpace( int *, int *);
46 
47 extern void  PetscMemcpy(void *,void *,int);
48 extern void  PetscMemzero(void *,int);
49 extern int   PetscMemcmp(char*, char*, int);
50 extern int   PetscStrlen(char *);
51 extern int   PetscStrcmp(char *,char *);
52 extern int   PetscStrncmp(char *,char *,int );
53 extern void  PetscStrcpy(char *,char *);
54 extern void  PetscStrcat(char *,char *);
55 extern void  PetscStrncat(char *,char *,int);
56 extern void  PetscStrncpy(char *,char *,int);
57 extern char* PetscStrchr(char *,char);
58 extern char* PetscStrrchr(char *,char);
59 extern char* PetscStrstr(char*,char*);
60 extern char* PetscStrtok(char*,char*);
61 extern char* PetscStrrtok(char*,char*);
62 
63 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
64 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
65 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
66 
67 #define PETSC_NULL          0
68 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
69 
70 #if defined(PETSC_COMPLEX)
71 #define PetscAbsScalar(a)     abs(a)
72 #else
73 #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
74 #endif
75 
76 /*  Macros for error checking */
77 #if !defined(__DIR__)
78 #define __DIR__ 0
79 #endif
80 
81 /*
82      Error codes (incomplete)
83 */
84 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
85 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
86 #define PETSC_ERR_ARG 57   /* bad input argument */
87 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
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 PETSC_DECIDE         -1
109 #define PETSC_DEFAULT        -2
110 
111 #include "viewer.h"
112 #include "options.h"
113 
114 extern double PetscGetTime();
115 extern double PetscGetFlops();
116 extern void PetscSleep(int);
117 
118 extern int PetscInitialize(int*,char***,char*,char*,char*);
119 extern int PetscFinalize();
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 PetscObjectGetType(PetscObject,int *type);
127 extern int PetscObjectSetName(PetscObject,char*);
128 extern int PetscObjectGetName(PetscObject,char**);
129 extern int PetscObjectInherit(PetscObject,void *, int (*)(void *,void **));
130 #define PetscObjectChild(a) (((PetscObject) (a))->child)
131 
132 extern int PetscDefaultErrorHandler(int,char*,char*,int,char*,void*);
133 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
134 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
135 extern int PetscError(int,char*,char*,int,char*);
136 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
137 extern int PetscPopErrorHandler();
138 
139 extern int PetscSetDebugger(char *,int,char *);
140 extern int PetscAttachDebugger();
141 
142 extern int PetscDefaultSignalHandler(int,void*);
143 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
144 extern int PetscPopSignalHandler();
145 #define FP_TRAP_OFF    0
146 #define FP_TRAP_ON     1
147 #define FP_TRAP_ALWAYS 2
148 extern int PetscSetFPTrap(int);
149 
150 /*
151    Definitions used for the Fortran interface:
152    FORTRANCAPS:       Names are uppercase, no trailing underscore
153    FORTRANUNDERSCORE: Names are lowercase, trailing underscore
154  */
155 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
156 #define FORTRANCAPS
157 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
158 #define FORTRANUNDERSCORE
159 #endif
160 
161 #include "phead.h"
162 #include "plog.h"
163 
164 #endif
165