-
Notifications
You must be signed in to change notification settings - Fork 59
/
timer.html
314 lines (274 loc) · 8.85 KB
/
timer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<html>
<head>
<title>
TIMER - Compute Elapsed Time
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
TIMER <br> Compute Elapsed Time
</h1>
<hr>
<p>
<b>TIMER</b>
is a directory of FORTRAN90 programs which
examine methods for computing
the elapsed CPU time of a part of a calculation.
</p>
<p>
The idea is that you want to
determine the amount of CPU time taken by a piece of your code, so
you write lines like this:
<pre><tt>
call timer ( t1 )
do i = 1, n
...some big calculation...
end do
call timer ( t2 )
write ( *, * ) 'Elapsed CPU time = ', t2 - t1
</pre></tt>
</p>
<p>
Early versions of FORTRAN did not specify a standard way to access
a system timer. Users on UNIX systems
could access a system library routine called ETIME for this purpose,
but ETIME was not part of the FORTRAN language, and was not to be found on
other operating systems.
</p>
<p>
FORTRAN90 added the SYSTEM_CLOCK function which can measure real time:
<pre><tt>
call system_clock ( t1, clock_rate, clock_max )
do i = 1, n
...some big calculation...
end do
call system_clock ( t2, clock_rate, clock_max )
write ( *, * ) 'Elapsed real time = ', real ( t2 - t1 ) / real ( clock_rate )
</pre></tt>
</p>
<p>
FORTRAN95 added the CPU_TIME function which measures CPU time:
<pre><tt>
call cpu_time ( t1 )
do i = 1, n
...some big calculation...
end do
call cpu_time ( t2 )
write ( *, * ) 'Elapsed CPU time = ', t2 - t1
</pre></tt>
</p>
<p>
On various
computers, there are often vendor-supplied routines to do this chore.
You will often find that the timer is inaccurate; some operations will
be reported as taking zero time; other operations will be reported
with times that differ by 5 or 10 percent. Moreover, two timers that
profess to measure the same thing may produce results that are
consistently different by a factor of 40 percent.
</p>
<p>
Another problem is "wrap around". Many timers reach a maximum value,
and then reset themselves to zero. If this happens to you, (it's
happened to me many times!) you may find that a certain procedure
seems to take negative time!
</p>
<p>
Some timers return CPU time, that is, the amount of elapsed computer
time that was used by your program; other routines return "real" time
or "wall clock" time, which will not account for situations in which
your program started, and then was paused for some reason (swapped out,
waiting for I/O, or other system functions), and then finished.
</p>
<p>
For parallel programming, the important thing to measure is the elapsed
wallclock time. This can be found by subtracting an initial reading of
the wallclock time from a final one.
</p>
<p>
The OpenMP system provides a function used as follows:
<pre>
seconds = omp_get_wtime ( )
operations to time;
seconds = omp_get_wtime ( ) - seconds;
</pre>
while the MPI system provides a similar function used as:
<pre>
seconds = MPI_Wtime ( );
operations;
seconds = MPI_Wtime ( ) - seconds;
</pre>
and in MATLAB, wallclock time can be taken with "tic" and "toc":
<pre>
tic;
operation;
seconds = toc;
</pre>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>TIMER</b> is available in
<a href = "../../c_src/timer/timer.html">a C version</a> and
<a href = "../../cpp_src/timer/timer.html">a C++ version</a> and
<a href = "../../f77_src/timer/timer.html">a FORTRAN77 version</a> and
<a href = "../../f_src/timer/timer.html">a FORTRAN90 version</a> and
<a href = "../../m_src/timer/timer.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../f_src/linpack_bench/linpack_bench.html">
LINPACK_BENCH</a>,
a FORTRAN90 program which
measures the time needed to factor and solve a linear system.
</p>
<p>
<a href = "../../f_src/matmul/matmul.html">
MATMUL</a>,
a FORTRAN90 program which
is an interactive matrix multiplication benchmark program.
</p>
<p>
<a href = "../../f77_src/mdbnch/mdbnch.html">
MDBNCH</a>,
a FORTRAN77 program which
is a benchmark code for a molecular dynamics calculation.
</p>
<p>
<a href = "../../f_src/memory_test/memory_test.html">
MEMORY_TEST</a>,
a FORTRAN90 program which
declares and uses a sequence of larger
and larger vectors, to see how big a vector can be used on a given
machine and compiler.
</p>
<p>
<a href = "../../f_src/mpi/mpi.html">
MPI</a>,
FORTRAN90 programs which
illustrate the use of the MPI application program interface
for carrying out parallel computations in a distributed memory environment.
</p>
<p>
<a href = "../../f_src/mxv/mxv.html">
MXV</a>,
a FORTRAN90 program which
compares the performance of (DO I, DO J) loops, (DO J, DO I ) loops,
and MATMUL for computing the product of an MxN matrix A and an N vector X.
</p>
<p>
<a href = "../../f_src/openmp/openmp.html">
OPENMP</a>,
FORTRAN90 programs which
illustrate the use of the OpenMP application program interface
for carrying out parallel computations in a shared memory environment.
</p>
<p>
<a href = "../../f_src/sum_million/sum_million.html">
SUM_MILLION</a>,
a FORTRAN90 program which
sums the integers from 1 to 1,000,000, as a demonstration of how
to rate a computer's speed;
</p>
<p>
<a href = "../../f_src/timestamp/timestamp.html">
TIMESTAMP</a>,
a FORTRAN90 library which
displays the current wall clock time.
</p>
<p>
<a href = "../../f_src/wtime/wtime.html">
WTIME</a>,
a FORTRAN90 library which
returns a reading of the wall clock time in seconds.
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>TIMER_CPU_TIME</b> uses the very convenient FORTRAN95 CPU_TIME routine:
<ul>
<li>
<a href = "timer_cpu_time.f90">timer_cpu_time.f90</a>, the test;
</li>
<li>
<a href = "timer_cpu_time.sh">timer_cpu_time.sh</a>,
commands to compile and run the test;
</li>
<li>
<a href = "timer_cpu_time_output.txt">timer_cpu_time_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>TIMER_ETIME</b> uses the ETIME routine, which is only available
on UNIX systems:
<ul>
<li>
<a href = "timer_etime.f90">timer_etime.f90</a>, the test;
</li>
<li>
<a href = "timer_etime.sh">timer_etime.sh</a>,
commands to compile and run the test;
</li>
<li>
<a href = "timer_etime_output.txt">timer_etime_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>TIMER_OMP_GET_WTIME</b> uses the OpenMP wall clock function <b>omp_get_wtime()</b>:
<ul>
<li>
<a href = "timer_omp_get_wtime.f90">timer_omp_get_wtime.f90</a>, the test;
</li>
<li>
<a href = "timer_omp_get_wtime.sh">timer_omp_get_wtime.sh</a>,
commands to compile and run the test;
</li>
<li>
<a href = "timer_omp_get_wtime_output.txt">timer_omp_get_wtime_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>TIMER_SYSTEM_CLOCK</b> uses the FORTRAN90 SYSTEM_CLOCK routine:
<ul>
<li>
<a href = "timer_system_clock.f90">timer_system_clock.f90</a>,
the test;
</li>
<li>
<a href = "timer_system_clock.sh">timer_system_clock.sh</a>,
commands to compile and run the test;
</li>
<li>
<a href = "timer_system_clock_output.txt">timer_system_clock_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../f_src.html">
the FORTRAN90 source codes</a>.
</p>
<hr>
<i>
Last revised on 13 May 2010.
</i>
<!-- John Burkardt -->
</body>
</html>