xref: /petsc/include/petsc.h (revision d7e8b82609919f5be22f34483b29990a2bb120b8)
1 /* $Id: petsc.h,v 1.66 1995/11/06 17:15:04 balay Exp balay $ */
2 
3 #if !defined(__PETSC_PACKAGE)
4 #define __PETSC_PACKAGE
5 
6 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.9 Released ?."
7 
8 #include <stdio.h>
9 #if defined(PARCH_sun4) && !defined(__cplusplus)
10 extern int fprintf(FILE*,const char*,...);
11 extern int printf(const char*,...);
12 extern int fflush(FILE *);
13 extern int fclose(FILE *);
14 extern void fscanf(FILE *,char *,...);
15 #endif
16 
17 /* MPI interface */
18 #include "mpi.h"
19 #include "mpiu.h"
20 
21 #if defined(PETSC_COMPLEX)
22 /* work around for bug in alpha g++ compiler */
23 #if defined(PARCH_alpha)
24 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
25 #endif
26 #include <complex.h>
27 #define PETSCREAL(a) real(a)
28 #define Scalar       complex
29 #else
30 #define PETSCREAL(a) a
31 #define Scalar       double
32 #endif
33 
34 extern void *(*PetscMalloc)(unsigned int,int,char*);
35 extern int  (*PetscFree)(void *,int,char*);
36 #define PetscMalloc(a)       (*PetscMalloc)(a,__LINE__,__FILE__)
37 #define PetscFree(a)         (*PetscFree)(a,__LINE__,__FILE__)
38 extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
39 extern int  TrDump(FILE *);
40 extern int  TrGetMaximumAllocated(double*);
41 
42 #define PetscNew(A)         (A*) PetscMalloc(sizeof(A))
43 
44 extern void  PetscMemcpy(void *,void *,int);
45 extern void  PetscMemzero(void *,int);
46 extern int   PetscStrlen(char *);
47 extern int   PetscStrcmp(char *,char *);
48 extern int   PetscStrncmp(char *,char *,int );
49 extern void  PetscStrcpy(char *,char *);
50 extern void  PetscStrcat(char *,char *);
51 extern void  PetscStrncat(char *,char *,int);
52 extern void  PetscStrncpy(char *,char *,int);
53 extern char* PetscStrchr(char *,char);
54 extern char* PetscStrrchr(char *,char);
55 extern char* PetscStrstr(char*,char*);
56 extern char* PetscStrtok(char*,char*);
57 extern char* PetscStrrtok(char*,char*);
58 extern int   PetscMemcmp(char*, char*, int);
59 
60 #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
61 #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
62 #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
63 
64 #if defined(PETSC_COMPLEX)
65 #define PetscAbsScalar(a)     abs(a)
66 #else
67 #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
68 #endif
69 
70 /*  Macros for error checking */
71 #if !defined(__DIR__)
72 #define __DIR__ 0
73 #endif
74 
75 /*
76        Unable to malloc error and no supported function
77 */
78 #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
79 #define PETSC_ERR_SUP 56   /* no support yet for this operation */
80 #define PETSC_ERR_ARG 57   /* bad input argument */
81 #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
82 
83 #if defined(PETSC_DEBUG)
84 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
85 #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
86                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
87 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
88 #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
89 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
90 #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
91 #else
92 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
93 #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
94                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
95 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
96 #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
97 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
98 #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
99 #endif
100 
101 typedef struct _PetscObject* PetscObject;
102 #define PETSC_COOKIE         1211211
103 #define PETSC_DECIDE         -1
104 #define PETSC_DEFAULT        -2
105 
106 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
107 
108 #include "viewer.h"
109 #include "options.h"
110 
111 extern int PetscInitialize(int*,char***,char*,char*,char*);
112 extern int PetscFinalize();
113 
114 extern int PetscObjectDestroy(PetscObject);
115 extern int PetscObjectExists(PetscObject,int*);
116 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
117 extern int PetscObjectGetCookie(PetscObject,int *cookie);
118 extern int PetscObjectGetType(PetscObject,int *type);
119 extern int PetscObjectSetName(PetscObject,char*);
120 extern int PetscObjectGetName(PetscObject,char**);
121 
122 extern int PetscDefaultErrorHandler(int,char*,char*,int,char*,void*);
123 extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
124 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
125 extern int PetscError(int,char*,char*,int,char*);
126 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
127 extern int PetscPopErrorHandler();
128 
129 extern int PetscSetDebugger(char *,int,char *);
130 extern int PetscAttachDebugger();
131 
132 extern int PetscDefaultSignalHandler(int,void*);
133 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
134 extern int PetscPopSignalHandler();
135 extern int PetscSetFPTrap(int);
136 #define FP_TRAP_OFF    0
137 #define FP_TRAP_ON     1
138 #define FP_TRAP_ALWAYS 2
139 
140 /*
141    Definitions used for the Fortran interface:
142    FORTRANCAPS:       Names are uppercase, no trailing underscore
143    FORTRANUNDERSCORE: Names are lowercase, trailing underscore
144  */
145 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
146 #define FORTRANCAPS
147 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
148 #define FORTRANUNDERSCORE
149 #endif
150 
151 #include "phead.h"
152 #include "plog.h"
153 
154 extern void PetscSleep(int);
155 
156 #endif
157