HPL_timer.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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_timer_disabled;
  57. static double HPL_timer_cpusec [HPL_NTIMER],
  58. HPL_timer_cpustart [HPL_NTIMER],
  59. HPL_timer_wallsec [HPL_NTIMER],
  60. HPL_timer_wallstart[HPL_NTIMER];
  61. /*
  62. * ---------------------------------------------------------------------
  63. * User callable functions
  64. * ---------------------------------------------------------------------
  65. */
  66. #ifdef STDC_HEADERS
  67. void HPL_timer_boot( void )
  68. #else
  69. void HPL_timer_boot()
  70. #endif
  71. {
  72. /*
  73. * HPL_timer_boot (re)sets all timers to 0, and enables HPL_timer.
  74. */
  75. /*
  76. * .. Local Variables ..
  77. */
  78. int i;
  79. /* ..
  80. * .. Executable Statements ..
  81. */
  82. HPL_timer_disabled = 0;
  83. for( i = 0; i < HPL_NTIMER; i++ )
  84. {
  85. HPL_timer_cpusec [i] = HPL_timer_wallsec [i] = HPL_rzero;
  86. HPL_timer_cpustart[i] = HPL_timer_wallstart[i] = HPL_TIMER_STARTFLAG;
  87. }
  88. /*
  89. * End of HPL_timer_boot
  90. */
  91. }
  92. #ifdef STDC_HEADERS
  93. void HPL_timer( const int I )
  94. #else
  95. void HPL_timer( I )
  96. const int I;
  97. #endif
  98. {
  99. /*
  100. * Purpose
  101. * =======
  102. *
  103. * HPL_timer provides a "stopwatch" functionality cpu/wall timer in
  104. * seconds. Up to 64 separate timers can be functioning at once. The
  105. * first call starts the timer, and the second stops it. This routine
  106. * can be disenabled by calling HPL_timer_disable(), so that calls to
  107. * the timer are ignored. This feature can be used to make sure certain
  108. * sections of code do not affect timings, even if they call routines
  109. * which have HPL_timer calls in them. HPL_timer_enable() will re-enable
  110. * the timer functionality. One can retrieve the current value of a
  111. * timer by calling
  112. *
  113. * t0 = HPL_timer_inquire( HPL_WALL_TIME | HPL_CPU_TIME, I )
  114. *
  115. * where I is the timer index in [0..64). To initialize the timer
  116. * functionality, one must have called HPL_timer_boot() prior to any of
  117. * the functions mentioned above.
  118. *
  119. * Arguments
  120. * =========
  121. *
  122. * I (global input) const int
  123. * On entry, I specifies the timer to stop/start.
  124. *
  125. * ---------------------------------------------------------------------
  126. */
  127. /* ..
  128. * .. Executable Statements ..
  129. */
  130. if( HPL_timer_disabled ) return;
  131. /*
  132. * If timer has not been started, start it. Otherwise, stop it and add
  133. * interval to count
  134. */
  135. if( HPL_timer_wallstart[I] == HPL_TIMER_STARTFLAG )
  136. {
  137. HPL_timer_wallstart[I] = HPL_timer_walltime();
  138. HPL_timer_cpustart [I] = HPL_timer_cputime ();
  139. }
  140. else
  141. {
  142. HPL_timer_cpusec [I] += HPL_timer_cputime () - HPL_timer_cpustart [I];
  143. HPL_timer_wallsec [I] += HPL_timer_walltime() - HPL_timer_wallstart[I];
  144. HPL_timer_wallstart[I] = HPL_TIMER_STARTFLAG;
  145. }
  146. /*
  147. * End of HPL_timer
  148. */
  149. }
  150. #ifdef STDC_HEADERS
  151. void HPL_timer_enable( void )
  152. #else
  153. void HPL_timer_enable()
  154. #endif
  155. {
  156. /*
  157. * HPL_timer_enable sets it so calls to HPL_timer are not ignored.
  158. */
  159. /* ..
  160. * .. Executable Statements ..
  161. */
  162. HPL_timer_disabled = 0;
  163. return;
  164. /*
  165. * End of HPL_timer_enable
  166. */
  167. }
  168. #ifdef STDC_HEADERS
  169. void HPL_timer_disable( void )
  170. #else
  171. void HPL_timer_disable()
  172. #endif
  173. {
  174. /*
  175. * HPL_timer_disable sets it so calls to HPL_timer are ignored.
  176. */
  177. /* ..
  178. * .. Executable Statements ..
  179. */
  180. HPL_timer_disabled = 1;
  181. return;
  182. /*
  183. * End of HPL_timer_disable
  184. */
  185. }
  186. #ifdef STDC_HEADERS
  187. double HPL_timer_inquire
  188. (
  189. const HPL_T_TIME TMTYPE,
  190. const int I
  191. )
  192. #else
  193. double HPL_timer_inquire( TMTYPE, I )
  194. const int I;
  195. const HPL_T_TIME TMTYPE;
  196. #endif
  197. {
  198. /*
  199. * Purpose
  200. * =======
  201. *
  202. * HPL_timer_inquire returns wall- or cpu- time that has accumulated in
  203. * timer I.
  204. *
  205. * Arguments
  206. * =========
  207. *
  208. * TMTYPE (global input) const HPL_T_TIME
  209. * On entry, TMTYPE specifies what time will be returned as fol-
  210. * lows
  211. * = HPL_WALL_TIME : wall clock time is returned,
  212. * = HPL_CPU_TIME : CPU time is returned (default).
  213. *
  214. * I (global input) const int
  215. * On entry, I specifies the timer to return.
  216. *
  217. * ---------------------------------------------------------------------
  218. */
  219. /*
  220. * .. Local Variables ..
  221. */
  222. double time;
  223. /* ..
  224. * .. Executable Statements ..
  225. */
  226. /*
  227. * If wall- or cpu-time are not available on this machine, return
  228. * HPL_TIMER_ERROR
  229. */
  230. if( TMTYPE == HPL_WALL_TIME )
  231. {
  232. if( HPL_timer_walltime() == HPL_TIMER_ERROR )
  233. time = HPL_TIMER_ERROR;
  234. else
  235. time = HPL_timer_wallsec[I];
  236. }
  237. else
  238. {
  239. if( HPL_timer_cputime() == HPL_TIMER_ERROR )
  240. time = HPL_TIMER_ERROR;
  241. else
  242. time = HPL_timer_cpusec [I];
  243. }
  244. return( time );
  245. /*
  246. * End of HPL_timer_inquire
  247. */
  248. }