IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Timer_dh.c
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
49 Timer_dhCreate (Timer_dh * t)
50 {
51  START_FUNC_DH
52  struct _timer_dh *tmp =
53  (struct _timer_dh *) MALLOC_DH (sizeof (struct _timer_dh));
54  CHECK_V_ERROR;
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);
69  SET_INFO (msgBuf_dh);
70 #elif defined(MPI_TIMING)
71  SET_INFO ("using MPI timing")
72 #else
73  SET_INFO ("using JUNK timing")
74 #endif
75 END_FUNC_DH}
76 
77 #undef __FUNC__
78 #define __FUNC__ "Timer_dhDestroy"
79 void
80 Timer_dhDestroy (Timer_dh t)
81 {
82  START_FUNC_DH FREE_DH (t);
83 END_FUNC_DH}
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
95 Timer_dhStart (Timer_dh t)
96 {
97  START_FUNC_DH t->begin_wall = times (&(t->begin_cpu));
98  t->isRunning = true;
99 END_FUNC_DH}
100 
101 #undef __FUNC__
102 #define __FUNC__ "Timer_dhStop"
103 void
104 Timer_dhStop (Timer_dh t)
105 {
106  START_FUNC_DH t->end_wall = times (&(t->end_cpu));
107  t->isRunning = false;
108 END_FUNC_DH}
109 
110 #undef __FUNC__
111 #define __FUNC__ "Timer_dhReadWall"
112 double
113 Timer_dhReadWall (Timer_dh t)
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
125 Timer_dhReadCPU (Timer_dh t)
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
141 Timer_dhReadUsage (Timer_dh t)
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
159 Timer_dhStart (Timer_dh t)
160 {
161  START_FUNC_DH t->begin_wall = MPI_Wtime ();
162  t->isRunning = true;
163 END_FUNC_DH}
164 
165 #undef __FUNC__
166 #define __FUNC__ "Timer_dhStop"
167 void
168 Timer_dhStop (Timer_dh t)
169 {
170  START_FUNC_DH t->end_wall = MPI_Wtime ();
171  t->isRunning = false;
172 END_FUNC_DH}
173 
174 #undef __FUNC__
175 #define __FUNC__ "Timer_dhReadWall"
176 double
177 Timer_dhReadWall (Timer_dh t)
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
188 Timer_dhReadCPU (Timer_dh t)
189 {
190 START_FUNC_DH END_FUNC_VAL (-1.0)}
191 
192 #undef __FUNC__
193 #define __FUNC__ "Timer_dhReadUsage"
194 double
195 Timer_dhReadUsage (Timer_dh t)
196 {
197  START_FUNC_DH END_FUNC_VAL (-1.0);
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
210 Timer_dhStart (Timer_dh t)
211 {
212 START_FUNC_DH END_FUNC_DH}
213 
214 #undef __FUNC__
215 #define __FUNC__ "Timer_dhStop"
216 void
217 Timer_dhStop (Timer_dh t)
218 {
219 START_FUNC_DH END_FUNC_DH}
220 
221 #undef __FUNC__
222 #define __FUNC__ "Timer_dhReadWall"
223 double
224 Timer_dhReadWall (Timer_dh t)
225 {
226 START_FUNC_DH END_FUNC_VAL (-1.0)}
227 
228 #undef __FUNC__
229 #define __FUNC__ "Timer_dhReadCPU"
230 double
231 Timer_dhReadCPU (Timer_dh t)
232 {
233 START_FUNC_DH END_FUNC_VAL (-1.0)}
234 
235 #undef __FUNC__
236 #define __FUNC__ "Timer_dhReadUsage"
237 double
238 Timer_dhReadUsage (Timer_dh t)
239 {
240  START_FUNC_DH END_FUNC_VAL (-1.0);
241 }
242 
243 #endif