Statistiques
| Révision :

root / testing / ptimer / HPL_ptimer.c

Historique | Voir | Annoter | Télécharger (11,5 ko)

1
/* 
2
 * -- High Performance Computing Linpack Benchmark (HPL)                
3
 *    HPL - 2.0 - September 10, 2008                          
4
 *    Antoine P. Petitet                                                
5
 *    University of Tennessee, Knoxville                                
6
 *    Innovative Computing Laboratory                                 
7
 *    (C) Copyright 2000-2008 All Rights Reserved                       
8
 *                                                                      
9
 * -- Copyright notice and Licensing terms:                             
10
 *                                                                      
11
 * Redistribution  and  use in  source and binary forms, with or without
12
 * modification, are  permitted provided  that the following  conditions
13
 * are met:                                                             
14
 *                                                                      
15
 * 1. Redistributions  of  source  code  must retain the above copyright
16
 * notice, this list of conditions and the following disclaimer.        
17
 *                                                                      
18
 * 2. Redistributions in binary form must reproduce  the above copyright
19
 * notice, this list of conditions,  and the following disclaimer in the
20
 * documentation and/or other materials provided with the distribution. 
21
 *                                                                      
22
 * 3. All  advertising  materials  mentioning  features  or  use of this
23
 * software must display the following acknowledgement:                 
24
 * This  product  includes  software  developed  at  the  University  of
25
 * Tennessee, Knoxville, Innovative Computing Laboratory.             
26
 *                                                                      
27
 * 4. The name of the  University,  the name of the  Laboratory,  or the
28
 * names  of  its  contributors  may  not  be used to endorse or promote
29
 * products  derived   from   this  software  without  specific  written
30
 * permission.                                                          
31
 *                                                                      
32
 * -- Disclaimer:                                                       
33
 *                                                                      
34
 * THIS  SOFTWARE  IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING,  BUT NOT
36
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
38
 * OR  CONTRIBUTORS  BE  LIABLE FOR ANY  DIRECT,  INDIRECT,  INCIDENTAL,
39
 * SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES  (INCLUDING,  BUT NOT
40
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41
 * DATA OR PROFITS; OR BUSINESS INTERRUPTION)  HOWEVER CAUSED AND ON ANY
42
 * THEORY OF LIABILITY, WHETHER IN CONTRACT,  STRICT LIABILITY,  OR TORT
43
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
45
 * ---------------------------------------------------------------------
46
 */ 
47
/*
48
 * Include files
49
 */
50
#include "hpl.h"
51
/*
52
 * ---------------------------------------------------------------------
53
 * Static variables
54
 * ---------------------------------------------------------------------
55
 */
56
static int         HPL_ptimer_disabled;
57
static double      HPL_ptimer_cpusec   [HPL_NPTIMER],
58
                   HPL_ptimer_cpustart [HPL_NPTIMER],
59
                   HPL_ptimer_wallsec  [HPL_NPTIMER],
60
                   HPL_ptimer_wallstart[HPL_NPTIMER];
61
/*
62
 * ---------------------------------------------------------------------
63
 * User callable functions
64
 * ---------------------------------------------------------------------
65
 */
66
#ifdef STDC_HEADERS
67
void HPL_ptimer_boot( void )
68
#else
69
void HPL_ptimer_boot()
70
#endif
71
{
72
/*
73
 * HPL_ptimer_boot (re)sets all timers to 0, and enables HPL_ptimer.
74
 */
75
/*
76
 * .. Local Variables ..
77
 */
78
   int                        i;
79
/* ..
80
 * .. Executable Statements ..
81
 */
82
   HPL_ptimer_disabled = 0;
83

    
84
   for( i = 0; i < HPL_NPTIMER; i++ )
85
   {
86
      HPL_ptimer_cpusec  [i] = HPL_ptimer_wallsec  [i] = HPL_rzero;
87
      HPL_ptimer_cpustart[i] = HPL_ptimer_wallstart[i] = HPL_PTIMER_STARTFLAG;
88
   }
89
/*
90
 * End of HPL_ptimer_boot
91
 */
92
}
93

    
94
#ifdef STDC_HEADERS
95
void HPL_ptimer( const int I )
96
#else
97
void HPL_ptimer( I )
98
   const int                  I;
99
#endif
100
{
101
/* 
102
 * Purpose
103
 * =======
104
 *
105
 * HPL_ptimer provides a  "stopwatch"  functionality  cpu/wall  timer in
106
 * seconds.  Up to  64  separate timers can be functioning at once.  The
107
 * first call starts the timer,  and the second stops it.  This  routine
108
 * can be disenabled  by calling HPL_ptimer_disable(),  so that calls to
109
 * the timer are ignored.  This feature can be used to make sure certain
110
 * sections of code do not affect timings,  even  if  they call routines
111
 * which have HPL_ptimer calls in them. HPL_ptimer_enable()  will enable
112
 * the  timer  functionality.  One  can retrieve  the current value of a
113
 * timer by calling
114
 *  
115
 * t0 = HPL_ptimer_inquire( HPL_WALL_TIME | HPL_CPU_TIME, I )
116
 *  
117
 * where  I  is the timer index in  [0..64).  To  inititialize the timer
118
 * functionality, one must have called HPL_ptimer_boot() prior to any of
119
 * the functions mentioned above.
120
 *
121
 * Arguments
122
 * =========
123
 *
124
 * I       (global input)                const int
125
 *         On entry, I specifies the timer to stop/start.
126
 *
127
 * ---------------------------------------------------------------------
128
 */ 
129
/* ..
130
 * .. Executable Statements ..
131
 */
132
   if( HPL_ptimer_disabled ) return;
133
/*
134
 * If timer has not been started, start it.  Otherwise,  stop it and add
135
 * interval to count
136
 */
137
   if( HPL_ptimer_wallstart[I] == HPL_PTIMER_STARTFLAG )
138
   {
139
      HPL_ptimer_wallstart[I] = HPL_ptimer_walltime();
140
      HPL_ptimer_cpustart [I] = HPL_ptimer_cputime ();
141
   }
142
   else
143
   {
144
      HPL_ptimer_cpusec   [I] += HPL_ptimer_cputime ()-HPL_ptimer_cpustart [I];
145
      HPL_ptimer_wallsec  [I] += HPL_ptimer_walltime()-HPL_ptimer_wallstart[I];
146
      HPL_ptimer_wallstart[I]  = HPL_PTIMER_STARTFLAG;
147
   }
148
/*
149
 * End of HPL_ptimer
150
 */
151
} 
152

    
153
#ifdef STDC_HEADERS
154
void HPL_ptimer_enable( void )
155
#else
156
void HPL_ptimer_enable()
157
#endif
158
{
159
/*
160
 * HPL_ptimer_enable sets it so calls to HPL_ptimer are not ignored.
161
 */
162
/* ..
163
 * .. Executable Statements ..
164
 */
165
   HPL_ptimer_disabled = 0;
166
   return;
167
/*
168
 * End of HPL_ptimer_enable
169
 */
170
} 
171

    
172
#ifdef STDC_HEADERS
173
void HPL_ptimer_disable( void )
174
#else
175
void HPL_ptimer_disable()
176
#endif
177
{
178
/*
179
 * HPL_ptimer_disable sets it so calls to HPL_ptimer are ignored.
180
 */
181
/* ..
182
 * .. Executable Statements ..
183
 */
184
   HPL_ptimer_disabled = 1;
185
   return;
186
/*
187
 * End of HPL_ptimer_disable
188
 */
189
} 
190

    
191
#ifdef STDC_HEADERS
192
double HPL_ptimer_inquire
193
(
194
   const HPL_T_PTIME          TMTYPE,
195
   const int                  I
196
)
197
#else
198
double HPL_ptimer_inquire( TMTYPE, I )
199
   const int                  I;
200
   const HPL_T_PTIME          TMTYPE;
201
#endif
202
{
203
/*
204
 * Purpose
205
 * =======
206
 *
207
 * HPL_ptimer_inquire returns wall- or cpu- time that has accumulated in
208
 * timer I.
209
 *
210
 * Arguments
211
 * =========
212
 *
213
 * TMTYPE  (global input)              const HPL_T_PTIME
214
 *         On entry, TMTYPE specifies what time will be returned as fol-
215
 *         lows
216
 *            = HPL_WALL_PTIME : wall clock time is returned,
217
 *            = HPL_CPU_PTIME  : CPU time is returned (default).
218
 *
219
 * I       (global input)              const int
220
 *         On entry, I specifies the timer to return.
221
 *
222
 * ---------------------------------------------------------------------
223
 */
224
/*
225
 * .. Local Variables ..
226
 */
227
   double          time;
228
/* ..
229
 * .. Executable Statements ..
230
 */
231
/*
232
 * If wall- or cpu-time are not available on this machine, return
233
 * HPL_PTIMER_ERROR
234
 */
235
   if( TMTYPE == HPL_WALL_PTIME )
236
   {
237
      if( HPL_ptimer_walltime() == HPL_PTIMER_ERROR )
238
         time = HPL_PTIMER_ERROR;
239
      else
240
         time = HPL_ptimer_wallsec[I];
241
   }
242
   else
243
   {
244
      if( HPL_ptimer_cputime()  == HPL_PTIMER_ERROR )
245
         time = HPL_PTIMER_ERROR;
246
      else
247
         time = HPL_ptimer_cpusec [I];
248
   }
249
   return( time );
250
/*
251
 * End of HPL_ptimer_inquire
252
 */
253
}
254

    
255
#ifdef STDC_HEADERS
256
void HPL_ptimer_combine
257
(
258
   MPI_Comm                   COMM,
259
   const HPL_T_PTIME_OP       OPE,
260
   const HPL_T_PTIME          TMTYPE,
261
   const int                  N,
262
   const int                  IBEG,
263
   double                     * TIMES
264
)
265
#else
266
void HPL_ptimer_combine( COMM, OPE, TMTYPE, N, IBEG, TIMES )
267
   const int                  IBEG, N;
268
   const HPL_T_PTIME_OP       OPE;
269
   const HPL_T_PTIME          TMTYPE;
270
   MPI_Comm                   COMM;
271
   double                     * TIMES;
272
#endif
273
{
274
/*
275
 * Purpose
276
 * =======
277
 *
278
 * HPL_ptimer_combine  combines the timing information stored on a scope
279
 * of processes into the user TIMES array.
280
 *
281
 * Arguments
282
 * =========
283
 *
284
 * COMM    (global/local input)        MPI_Comm
285
 *         The MPI communicator  identifying  the process  collection on
286
 *         which the timings are taken.
287
 *
288
 * OPE     (global input)              const HPL_T_PTIME_OP
289
 *         On entry, OP  specifies what combine operation should be done
290
 *         as follows:
291
 *            = HPL_AMAX_PTIME get max. time on any process (default),
292
 *            = HPL_AMIN_PTIME get min. time on any process,
293
 *            = HPL_SUM_PTIME  get sum of times across processes.
294
 *
295
 * TMTYPE  (global input)              const HPL_T_PTIME
296
 *         On entry, TMTYPE specifies what time will be returned as fol-
297
 *         lows
298
 *            = HPL_WALL_PTIME : wall clock time is returned,
299
 *            = HPL_CPU_PTIME  : CPU time is returned (default).
300
 *
301
 * N       (global input)              const int
302
 *         On entry, N specifies the number of timers to combine.
303
 *
304
 * IBEG    (global input)              const int
305
 *         On entry, IBEG specifies the first timer to be combined.
306
 *
307
 * TIMES   (global output)             double *
308
 *         On entry, TIMES is an array of dimension at least N. On exit,
309
 *         this array contains the requested timing information.
310
 *
311
 * ---------------------------------------------------------------------
312
 */
313
/*
314
 * .. Local Variables ..
315
 */
316
   int                        i, tmpdis;
317
/* ..
318
 * .. Executable Statements ..
319
 */
320
   tmpdis = HPL_ptimer_disabled; HPL_ptimer_disabled = 1;
321
/*
322
 * Timer has been disabled for combine operation -  copy timing informa-
323
 * tion into user times array.  If  wall- or  cpu-time are not available
324
 * on this machine, fill in times with HPL_PTIMER_ERROR flag and return.
325
 */
326
   if( TMTYPE == HPL_WALL_PTIME )
327
   {
328
      if( HPL_ptimer_walltime() == HPL_PTIMER_ERROR )
329
      { for( i = 0; i < N; i++ ) TIMES[i] = HPL_PTIMER_ERROR; return;   }
330
      else
331
      { for( i = 0; i < N; i++ ) TIMES[i] = HPL_ptimer_wallsec[IBEG+i]; }
332
   }
333
   else
334
   {
335
      if( HPL_ptimer_cputime() == HPL_PTIMER_ERROR )
336
      { for( i = 0; i < N; i++ ) TIMES[i] = HPL_PTIMER_ERROR; return;  }
337
      else
338
      { for( i = 0; i < N; i++ ) TIMES[i] = HPL_ptimer_cpusec[IBEG+i]; }
339
   }
340
/*
341
 * Combine all nodes information, restore HPL_ptimer_disabled, and return
342
 */
343
   for( i = 0; i < N; i++ ) TIMES[i] = Mmax( HPL_rzero, TIMES[i] );
344

    
345
   if(      OPE == HPL_AMAX_PTIME )
346
      (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_max, COMM );
347
   else if( OPE == HPL_AMIN_PTIME )
348
      (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_min, COMM );
349
   else if( OPE == HPL_SUM_PTIME  )
350
      (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_sum, COMM );
351
   else
352
      (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_max, COMM );
353

    
354
   HPL_ptimer_disabled = tmpdis;
355
/*
356
 * End of HPL_ptimer_combine
357
 */
358
}