xref: /petsc/include/petsc.h (revision b9fa9cd00acd5827c9866f4329ced14637d43fca)
1 /* $Id: petsc.h,v 1.50 1995/08/01 14:04:20 bsmith Exp bsmith $ */
2 
3 #if !defined(__PETSC_PACKAGE)
4 #define __PETSC_PACKAGE
5 
6 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.7 Released ?, 1995."
7 
8 #include <stdio.h>
9 #if defined(PARCH_sun4)
10 int fprintf(FILE*,char*,...);
11 int printf(char*,...);
12 int fflush(FILE*);
13 int fclose(FILE*);
14 #endif
15 
16 /* MPI interface */
17 #include "mpi.h"
18 #include "mpiu.h"
19 
20 #if defined(PETSC_COMPLEX)
21 /* work around for bug in alpha g++ compiler */
22 #if defined(PARCH_alpha)
23 #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
24 /* extern double hypot(double,double); */
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*),
39                            int (*)(void *,int,char*));
40 extern int  Trdump(FILE *);
41 extern int  TrGetMaximumAllocated(double*);
42 
43 #define PETSCNEW(A)         (A*) PETSCMALLOC(sizeof(A))
44 #define PETSCMEMCPY(a,b,n)   memcpy((char*)(a),(char*)(b),n)
45 #define PETSCMEMSET(a,b,n)   memset((char*)(a),(int)(b),n)
46 #include <memory.h>
47 
48 #define PETSCMIN(a,b)      ( ((a)<(b)) ? (a) : (b) )
49 #define PETSCMAX(a,b)      ( ((a)<(b)) ? (b) : (a) )
50 #define PETSCABS(a)        ( ((a)<0)   ? -(a) : (a) )
51 
52 /*  Macros for error checking */
53 #if !defined(__DIR__)
54 #define __DIR__ 0
55 #endif
56 #define PETSC_ERROR_NO_MEM 55
57 #if defined(PETSC_DEBUG)
58 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,s,n);}
59 #define SETERRA(n,s)    \
60                 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\
61                  MPI_Abort(MPI_COMM_WORLD,_ierr);}
62 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
63 #define CHKERRA(n)      {if (n) SETERRA(n,(char *)0);}
64 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERROR_NO_MEM,(char*)0);
65 #define CHKPTRA(p)      if (!p) SETERRA(PETSC_ERROR_NO_MEM,(char*)0);
66 #else
67 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,s,n);}
68 #define SETERRA(n,s)    \
69                 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\
70                  MPI_Abort(MPI_COMM_WORLD,_ierr);}
71 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
72 #define CHKERRA(n)      {if (n) SETERRA(n,(char *)0);}
73 #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERROR_NO_MEM,(char*)0);
74 #define CHKPTRA(p)      if (!p) SETERRA(PETSC_ERROR_NO_MEM,(char*)0);
75 #endif
76 
77 typedef struct _PetscObject* PetscObject;
78 #define PETSC_COOKIE         0x12121212
79 #define PETSC_DECIDE         -1
80 #define PETSC_DEFAULT        0
81 
82 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
83 
84 #include "viewer.h"
85 #include "options.h"
86 
87 extern int PetscInitialize(int*,char***,char*,char*);
88 extern int PetscFinalize();
89 
90 extern int PetscObjectDestroy(PetscObject);
91 extern int PetscObjectExists(PetscObject,int*);
92 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
93 extern int PetscObjectSetName(PetscObject,char*);
94 extern int PetscObjectGetName(PetscObject,char**);
95 
96 extern int PetscDefaultErrorHandler(int,char*,char*,char*,int,void*);
97 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,void* );
98 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,void*);
99 extern int PetscError(int,char*,char*,char*,int);
100 extern int PetscPushErrorHandler(int
101                          (*handler)(int,char*,char*,char*,int,void*),void* );
102 extern int PetscPopErrorHandler();
103 
104 extern int PetscSetDebugger(char *,int,char *);
105 extern int PetscAttachDebugger();
106 
107 extern int PetscDefaultSignalHandler(int,void*);
108 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
109 extern int PetscPopSignalHandler();
110 extern int PetscSetFPTrap(int);
111 #define FP_TRAP_OFF    0
112 #define FP_TRAP_ON     1
113 #define FP_TRAP_ALWAYS 2
114 
115 /*
116    Definitions used for the Fortran interface:
117    FORTRANCAPS:       Names are uppercase, no trailing underscore
118    FORTRANUNDERSCORE: Names are lowercase, trailing underscore
119  */
120 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
121 #define FORTRANCAPS
122 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
123 #define FORTRANUNDERSCORE
124 #endif
125 
126 /* Global flop counter */
127 extern double _TotalFlops;
128 #if defined(PETSC_LOG)
129 #define PLogFlops(n) {_TotalFlops += n;}
130 #else
131 #define PLogFlops(n)
132 #endif
133 
134 /*M
135    PLogFlops - Adds floating point operations to the global counter.
136 
137    Input Parameter:
138 .  f - flop counter
139 
140    Synopsis:
141    PLogFlops(int f)
142 
143    Notes:
144    A global counter logs all PETSc flop counts.  The user can use
145    PLogFlops() to increment this counter to include flops for the
146    application code.
147 
148    PETSc automatically logs library events if the code has been
149    compiled with -DPETSC_LOG (which is the default), and -log,
150    -log_summary, or -log_all are specified.  PLogFlops() is
151    intended for logging user flops to supplement this PETSc
152    information.
153 
154     Example of Usage:
155 $     #define USER_EVENT 75
156 $     PLogEventRegister(USER_EVENT,"User event");
157 $     PLogEventBegin(USER_EVENT,0,0,0,0);
158 $     [code segment to monitor]
159 $     PLogFlops(user_flops)
160 $     PLogEventEnd(USER_EVENT,0,0,0,0);
161 
162 .seealso:  PLogEventRegister(), PLogEventBegin(), PLogEventEnd()
163 
164 .keywords:  Petsc, log, flops, floating point operations
165 M*/
166 
167 extern int PLogPrint(MPI_Comm,FILE *);
168 extern int PLogBegin();
169 extern int PLogAllBegin();
170 extern int PLogDump(char*);
171 
172 #endif
173