xref: /petsc/include/petsc.h (revision 369a4401ebeca8baccc22dd3d5896cf35eb2576f)
1 /* $Id: petsc.h,v 1.42 1995/07/15 17:39:49 bsmith Exp curfman $ */
2 
3 #if !defined(__PETSC_PACKAGE)
4 #define __PETSC_PACKAGE
5 
6 #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.6 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 /*  Macros for error checking */
49 #if !defined(__DIR__)
50 #define __DIR__ 0
51 #endif
52 #if defined(PETSC_DEBUG)
53 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,s,n);}
54 #define SETERRA(n,s)    \
55                 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\
56                  MPI_Abort(MPI_COMM_WORLD,_ierr);}
57 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
58 #define CHKERRA(n)      {if (n) SETERRA(n,(char *)0);}
59 #define CHKPTRQ(p)       if (!p) SETERRQ(1,"No memory");
60 #define CHKPTRA(p)      if (!p) SETERRA(1,"No memory");
61 #else
62 #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,s,n);}
63 #define SETERRA(n,s)    \
64                 {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,s,n);\
65                  MPI_Abort(MPI_COMM_WORLD,_ierr);}
66 #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
67 #define CHKERRA(n)      {if (n) SETERRA(n,(char *)0);}
68 #define CHKPTRQ(p)       if (!p) SETERRQ(1,"No memory");
69 #define CHKPTRA(p)      if (!p) SETERRA(1,"No memory");
70 #endif
71 
72 typedef struct _PetscObject* PetscObject;
73 #define PETSC_COOKIE         0x12121212
74 #define PETSC_DECIDE         -1
75 #define PETSC_DEFAULT        0
76 
77 typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
78 
79 #include "viewer.h"
80 #include "options.h"
81 
82 extern int PetscInitialize(int*,char***,char*,char*);
83 extern int PetscFinalize();
84 
85 extern int PetscObjectDestroy(PetscObject);
86 extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
87 extern int PetscObjectSetName(PetscObject,char*);
88 extern int PetscObjectGetName(PetscObject,char**);
89 
90 extern int PetscDefaultErrorHandler(int,char*,char*,char*,int,void*);
91 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,void* );
92 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,void*);
93 extern int PetscError(int,char*,char*,char*,int);
94 extern int PetscPushErrorHandler(int
95                          (*handler)(int,char*,char*,char*,int,void*),void* );
96 extern int PetscPopErrorHandler();
97 
98 extern int PetscSetDebugger(char *,int,char *);
99 extern int PetscAttachDebugger();
100 
101 extern int PetscDefaultSignalHandler(int,void*);
102 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
103 extern int PetscPopSignalHandler();
104 extern int PetscSetFPTrap(int);
105 #define FP_TRAP_OFF    0
106 #define FP_TRAP_ON     1
107 #define FP_TRAP_ALWAYS 2
108 
109 #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
110 #define FORTRANCAPS
111 #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
112 #define FORTRANUNDERSCORE
113 #endif
114 
115 /* Global flop counter */
116 extern double _TotalFlops;
117 #if defined(PETSC_LOG)
118 #define PLogFlops(n) {_TotalFlops += n;}
119 #else
120 #define PLogFlops(n)
121 #endif
122 
123 /*M
124    PLogFlops - Adds floating point operations to the global counter.
125 
126    Input Parameter:
127 .  f - flop counter
128 
129    Synopsis:
130    PLogFlops(int f)
131 
132    Notes:
133    A global counter logs all PETSc flop counts.  The user can use
134    PLogFlops() to increment this counter to include flops for the
135    application code.
136 
137    PETSc automatically logs library events if the code has been
138    compiled with -DPETSC_LOG (which is the default), and -log,
139    -log_summary, or -log_all are specified.  PLogFlops() is
140    intended for logging user flops to supplement this PETSc
141    information.
142 
143     Example of Usage:
144 $     #define USER_EVENT 75
145 $     PLogEventRegister(USER_EVENT,"User event");
146 $     PLogEventBegin(USER_EVENT,0,0,0,0);
147 $     [code segment to monitor]
148 $     PLogFlops(user_flops)
149 $     PLogEventEnd(USER_EVENT,0,0,0,0);
150 
151 .seealso:  PLogEventRegister(), PLogEventBegin(), PLogEventEnd()
152 
153 .keywords:  Petsc, log, flops, floating point operations
154 M*/
155 
156 extern int PLogPrint(MPI_Comm,FILE *);
157 extern int PLogBegin();
158 extern int PLogAllBegin();
159 extern int PLogDump(char*);
160 
161 #endif
162