Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Timer_dh.c
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #include "Timer_dh.h"
44 #include "Mem_dh.h"
45 
46 #undef __FUNC__
47 #define __FUNC__ "Timer_dhCreate"
48 void
50 {
52  struct _timer_dh *tmp =
53  (struct _timer_dh *) MALLOC_DH (sizeof (struct _timer_dh));
55  *t = tmp;
56 
57  tmp->isRunning = false;
58  tmp->begin_wall = 0.0;
59  tmp->end_wall = 0.0;
60 #ifdef WIN32
61  tmp->sc_clk_tck = CLOCKS_PER_SEC;
62 #else
63  tmp->sc_clk_tck = sysconf (128);
64 #endif
65 
66 #if defined(EUCLID_TIMING)
67  sprintf (msgBuf_dh, "using EUCLID_TIMING; _SC_CLK_TCK = %i",
68  (int) tmp->sc_clk_tck);
70 #elif defined(MPI_TIMING)
71  SET_INFO ("using MPI timing")
72 #else
73  SET_INFO ("using JUNK timing")
74 #endif
76 
77 #undef __FUNC__
78 #define __FUNC__ "Timer_dhDestroy"
79 void
81 {
84 
85 /*-------------------------------------------------------------------------------
86  * EUCLID_TIMING timing methods; these use times() to record
87  * both wall and cpu time.
88  *-------------------------------------------------------------------------------*/
89 
90 #ifdef EUCLID_TIMING
91 
92 #undef __FUNC__
93 #define __FUNC__ "Timer_dhStart"
94 void
96 {
97  START_FUNC_DH t->begin_wall = times (&(t->begin_cpu));
98  t->isRunning = true;
100 
101 #undef __FUNC__
102 #define __FUNC__ "Timer_dhStop"
103 void
105 {
106  START_FUNC_DH t->end_wall = times (&(t->end_cpu));
107  t->isRunning = false;
109 
110 #undef __FUNC__
111 #define __FUNC__ "Timer_dhReadWall"
112 double
114 {
115  START_FUNC_DH double retval = 0.0;
116  long int sc_clk_tck = t->sc_clk_tck;
117  if (t->isRunning)
118  t->end_wall = times (&(t->end_cpu));
119  retval = (double) (t->end_wall - t->begin_wall) / (double) sc_clk_tck;
120 END_FUNC_VAL (retval)}
121 
122 #undef __FUNC__
123 #define __FUNC__ "Timer_dhReadCPU"
124 double
126 {
127  START_FUNC_DH double retval;
128  long int sc_clk_tck = t->sc_clk_tck;
129  if (t->isRunning)
130  t->end_wall = times (&(t->end_cpu));
131  retval = (double) (t->end_cpu.tms_utime - t->begin_cpu.tms_utime
132  + t->end_cpu.tms_stime - t->begin_cpu.tms_stime
133  + t->end_cpu.tms_cutime - t->begin_cpu.tms_cutime
134  + t->end_cpu.tms_cstime - t->begin_cpu.tms_cstime)
135  / (double) sc_clk_tck;
136 END_FUNC_VAL (retval)}
137 
138 #undef __FUNC__
139 #define __FUNC__ "Timer_dhReadUsage"
140 double
142 {
143  START_FUNC_DH double cpu = Timer_dhReadCPU (t);
144  double wall = Timer_dhReadWall (t);
145  double retval = 100.0 * cpu / wall;
146  END_FUNC_VAL (retval);
147 }
148 
149 /*-------------------------------------------------------------------------------
150  * Parallel timing functions; these use MPI_Wtime() to record
151  * wall-clock time only.
152  *-------------------------------------------------------------------------------*/
153 
154 #elif defined(MPI_TIMING)
155 
156 #undef __FUNC__
157 #define __FUNC__ "Timer_dhStart"
158 void
160 {
161  START_FUNC_DH t->begin_wall = MPI_Wtime ();
162  t->isRunning = true;
164 
165 #undef __FUNC__
166 #define __FUNC__ "Timer_dhStop"
167 void
169 {
170  START_FUNC_DH t->end_wall = MPI_Wtime ();
171  t->isRunning = false;
173 
174 #undef __FUNC__
175 #define __FUNC__ "Timer_dhReadWall"
176 double
178 {
179  START_FUNC_DH double retval;
180  if (t->isRunning)
181  t->end_wall = MPI_Wtime ();
182  retval = t->end_wall - t->begin_wall;
183 END_FUNC_VAL (retval)}
184 
185 #undef __FUNC__
186 #define __FUNC__ "Timer_dhReadCPU"
187 double
189 {
191 
192 #undef __FUNC__
193 #define __FUNC__ "Timer_dhReadUsage"
194 double
196 {
198 }
199 
200 
201 /*-------------------------------------------------------------------------------
202  * junk timing methods -- these do nothing!
203  *-------------------------------------------------------------------------------*/
204 
205 #else
206 
207 #undef __FUNC__
208 #define __FUNC__ "Timer_dhStart"
209 void
211 {
213 
214 #undef __FUNC__
215 #define __FUNC__ "Timer_dhStop"
216 void
218 {
220 
221 #undef __FUNC__
222 #define __FUNC__ "Timer_dhReadWall"
223 double
225 {
227 
228 #undef __FUNC__
229 #define __FUNC__ "Timer_dhReadCPU"
230 double
232 {
234 
235 #undef __FUNC__
236 #define __FUNC__ "Timer_dhReadUsage"
237 double
239 {
241 }
242 
243 #endif
bool isRunning
Definition: Timer_dh.h:100
double Timer_dhReadWall(Timer_dh t)
Definition: Timer_dh.c:224
#define CHECK_V_ERROR
Definition: macros_dh.h:138
double begin_wall
Definition: Timer_dh.h:102
#define END_FUNC_DH
Definition: macros_dh.h:187
#define END_FUNC_VAL(retval)
Definition: macros_dh.h:208
#define MALLOC_DH(s)
void Timer_dhDestroy(Timer_dh t)
Definition: Timer_dh.c:80
void Timer_dhStop(Timer_dh t)
Definition: Timer_dh.c:217
#define SET_INFO(msg)
Definition: macros_dh.h:156
void Timer_dhCreate(Timer_dh *t)
Definition: Timer_dh.c:49
double end_wall
Definition: Timer_dh.h:103
#define START_FUNC_DH
Definition: macros_dh.h:181
double Timer_dhReadUsage(Timer_dh t)
Definition: Timer_dh.c:238
void Timer_dhStart(Timer_dh t)
Definition: Timer_dh.c:210
long int sc_clk_tck
Definition: Timer_dh.h:101
double Timer_dhReadCPU(Timer_dh t)
Definition: Timer_dh.c:231
char msgBuf_dh[MSG_BUF_SIZE_DH]
Definition: globalObjects.c:61
#define FREE_DH(p)