HPL_ptimer.c.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. #include "RCCE_lib.h"
  52. /*
  53. * ---------------------------------------------------------------------
  54. * Static variables
  55. * ---------------------------------------------------------------------
  56. */
  57. static int HPL_ptimer_disabled;
  58. static double HPL_ptimer_cpusec [HPL_NPTIMER],
  59. HPL_ptimer_cpustart [HPL_NPTIMER],
  60. HPL_ptimer_wallsec [HPL_NPTIMER],
  61. HPL_ptimer_wallstart[HPL_NPTIMER];
  62. #ifdef _OPENMP
  63. #pragma omp threadprivate(HPL_ptimer_disabled)
  64. #pragma omp threadprivate(HPL_ptimer_cpusec)
  65. #pragma omp threadprivate(HPL_ptimer_cpustart)
  66. #pragma omp threadprivate(HPL_ptimer_wallsec)
  67. #pragma omp threadprivate(HPL_ptimer_wallstart)
  68. #endif
  69. /*
  70. * ---------------------------------------------------------------------
  71. * User callable functions
  72. * ---------------------------------------------------------------------
  73. */
  74. #ifdef STDC_HEADERS
  75. void HPL_ptimer_boot( void )
  76. #else
  77. void HPL_ptimer_boot()
  78. #endif
  79. {
  80. /*
  81. * HPL_ptimer_boot (re)sets all timers to 0, and enables HPL_ptimer.
  82. */
  83. /*
  84. * .. Local Variables ..
  85. */
  86. int i;
  87. /* ..
  88. * .. Executable Statements ..
  89. */
  90. HPL_ptimer_disabled = 0;
  91. for( i = 0; i < HPL_NPTIMER; i++ )
  92. {
  93. HPL_ptimer_cpusec [i] = HPL_ptimer_wallsec [i] = HPL_rzero;
  94. HPL_ptimer_cpustart[i] = HPL_ptimer_wallstart[i] = HPL_PTIMER_STARTFLAG;
  95. }
  96. /*
  97. * End of HPL_ptimer_boot
  98. */
  99. }
  100. #ifdef STDC_HEADERS
  101. void HPL_ptimer( const int I )
  102. #else
  103. void HPL_ptimer( I )
  104. const int I;
  105. #endif
  106. {
  107. /*
  108. * Purpose
  109. * =======
  110. *
  111. * HPL_ptimer provides a "stopwatch" functionality cpu/wall timer in
  112. * seconds. Up to 64 separate timers can be functioning at once. The
  113. * first call starts the timer, and the second stops it. This routine
  114. * can be disenabled by calling HPL_ptimer_disable(), so that calls to
  115. * the timer are ignored. This feature can be used to make sure certain
  116. * sections of code do not affect timings, even if they call routines
  117. * which have HPL_ptimer calls in them. HPL_ptimer_enable() will enable
  118. * the timer functionality. One can retrieve the current value of a
  119. * timer by calling
  120. *
  121. * t0 = HPL_ptimer_inquire( HPL_WALL_TIME | HPL_CPU_TIME, I )
  122. *
  123. * where I is the timer index in [0..64). To inititialize the timer
  124. * functionality, one must have called HPL_ptimer_boot() prior to any of
  125. * the functions mentioned above.
  126. *
  127. * Arguments
  128. * =========
  129. *
  130. * I (global input) const int
  131. * On entry, I specifies the timer to stop/start.
  132. *
  133. * ---------------------------------------------------------------------
  134. */
  135. /* ..
  136. * .. Executable Statements ..
  137. */
  138. if( HPL_ptimer_disabled ) return;
  139. /*
  140. * If timer has not been started, start it. Otherwise, stop it and add
  141. * interval to count
  142. */
  143. if( HPL_ptimer_wallstart[I] == HPL_PTIMER_STARTFLAG )
  144. {
  145. HPL_ptimer_wallstart[I] = HPL_ptimer_walltime();
  146. HPL_ptimer_cpustart [I] = HPL_ptimer_cputime ();
  147. }
  148. else
  149. {
  150. HPL_ptimer_cpusec [I] += HPL_ptimer_cputime ()-HPL_ptimer_cpustart [I];
  151. HPL_ptimer_wallsec [I] += HPL_ptimer_walltime()-HPL_ptimer_wallstart[I];
  152. HPL_ptimer_wallstart[I] = HPL_PTIMER_STARTFLAG;
  153. }
  154. /*
  155. * End of HPL_ptimer
  156. */
  157. }
  158. #ifdef STDC_HEADERS
  159. void HPL_ptimer_enable( void )
  160. #else
  161. void HPL_ptimer_enable()
  162. #endif
  163. {
  164. /*
  165. * HPL_ptimer_enable sets it so calls to HPL_ptimer are not ignored.
  166. */
  167. /* ..
  168. * .. Executable Statements ..
  169. */
  170. HPL_ptimer_disabled = 0;
  171. return;
  172. /*
  173. * End of HPL_ptimer_enable
  174. */
  175. }
  176. #ifdef STDC_HEADERS
  177. void HPL_ptimer_disable( void )
  178. #else
  179. void HPL_ptimer_disable()
  180. #endif
  181. {
  182. /*
  183. * HPL_ptimer_disable sets it so calls to HPL_ptimer are ignored.
  184. */
  185. /* ..
  186. * .. Executable Statements ..
  187. */
  188. HPL_ptimer_disabled = 1;
  189. return;
  190. /*
  191. * End of HPL_ptimer_disable
  192. */
  193. }
  194. #ifdef STDC_HEADERS
  195. double HPL_ptimer_inquire
  196. (
  197. const HPL_T_PTIME TMTYPE,
  198. const int I
  199. )
  200. #else
  201. double HPL_ptimer_inquire( TMTYPE, I )
  202. const int I;
  203. const HPL_T_PTIME TMTYPE;
  204. #endif
  205. {
  206. /*
  207. * Purpose
  208. * =======
  209. *
  210. * HPL_ptimer_inquire returns wall- or cpu- time that has accumulated in
  211. * timer I.
  212. *
  213. * Arguments
  214. * =========
  215. *
  216. * TMTYPE (global input) const HPL_T_PTIME
  217. * On entry, TMTYPE specifies what time will be returned as fol-
  218. * lows
  219. * = HPL_WALL_PTIME : wall clock time is returned,
  220. * = HPL_CPU_PTIME : CPU time is returned (default).
  221. *
  222. * I (global input) const int
  223. * On entry, I specifies the timer to return.
  224. *
  225. * ---------------------------------------------------------------------
  226. */
  227. /*
  228. * .. Local Variables ..
  229. */
  230. double time;
  231. /* ..
  232. * .. Executable Statements ..
  233. */
  234. /*
  235. * If wall- or cpu-time are not available on this machine, return
  236. * HPL_PTIMER_ERROR
  237. */
  238. if( TMTYPE == HPL_WALL_PTIME )
  239. {
  240. if( HPL_ptimer_walltime() == HPL_PTIMER_ERROR )
  241. time = HPL_PTIMER_ERROR;
  242. else
  243. time = HPL_ptimer_wallsec[I];
  244. }
  245. else
  246. {
  247. if( HPL_ptimer_cputime() == HPL_PTIMER_ERROR )
  248. time = HPL_PTIMER_ERROR;
  249. else
  250. time = HPL_ptimer_cpusec [I];
  251. }
  252. return( time );
  253. /*
  254. * End of HPL_ptimer_inquire
  255. */
  256. }
  257. #ifdef STDC_HEADERS
  258. void HPL_ptimer_combine
  259. (
  260. MPI_Comm COMM,
  261. const HPL_T_PTIME_OP OPE,
  262. const HPL_T_PTIME TMTYPE,
  263. const int N,
  264. const int IBEG,
  265. double * TIMES
  266. )
  267. #else
  268. void HPL_ptimer_combine( COMM, OPE, TMTYPE, N, IBEG, TIMES )
  269. const int IBEG, N;
  270. const HPL_T_PTIME_OP OPE;
  271. const HPL_T_PTIME TMTYPE;
  272. MPI_Comm COMM;
  273. double * TIMES;
  274. #endif
  275. {
  276. /*
  277. * Purpose
  278. * =======
  279. *
  280. * HPL_ptimer_combine combines the timing information stored on a scope
  281. * of processes into the user TIMES array.
  282. *
  283. * Arguments
  284. * =========
  285. *
  286. * COMM (global/local input) MPI_Comm
  287. * The MPI communicator identifying the process collection on
  288. * which the timings are taken.
  289. *
  290. * OPE (global input) const HPL_T_PTIME_OP
  291. * On entry, OP specifies what combine operation should be done
  292. * as follows:
  293. * = HPL_AMAX_PTIME get max. time on any process (default),
  294. * = HPL_AMIN_PTIME get min. time on any process,
  295. * = HPL_SUM_PTIME get sum of times across processes.
  296. *
  297. * TMTYPE (global input) const HPL_T_PTIME
  298. * On entry, TMTYPE specifies what time will be returned as fol-
  299. * lows
  300. * = HPL_WALL_PTIME : wall clock time is returned,
  301. * = HPL_CPU_PTIME : CPU time is returned (default).
  302. *
  303. * N (global input) const int
  304. * On entry, N specifies the number of timers to combine.
  305. *
  306. * IBEG (global input) const int
  307. * On entry, IBEG specifies the first timer to be combined.
  308. *
  309. * TIMES (global output) double *
  310. * On entry, TIMES is an array of dimension at least N. On exit,
  311. * this array contains the requested timing information.
  312. *
  313. * ---------------------------------------------------------------------
  314. */
  315. /*
  316. * .. Local Variables ..
  317. */
  318. int i, tmpdis;
  319. /* ..
  320. * .. Executable Statements ..
  321. */
  322. tmpdis = HPL_ptimer_disabled; HPL_ptimer_disabled = 1;
  323. /*
  324. * Timer has been disabled for combine operation - copy timing informa-
  325. * tion into user times array. If wall- or cpu-time are not available
  326. * on this machine, fill in times with HPL_PTIMER_ERROR flag and return.
  327. */
  328. if( TMTYPE == HPL_WALL_PTIME )
  329. {
  330. if( HPL_ptimer_walltime() == HPL_PTIMER_ERROR )
  331. { for( i = 0; i < N; i++ ) TIMES[i] = HPL_PTIMER_ERROR; return; }
  332. else
  333. { for( i = 0; i < N; i++ ) TIMES[i] = HPL_ptimer_wallsec[IBEG+i]; }
  334. }
  335. else
  336. {
  337. if( HPL_ptimer_cputime() == HPL_PTIMER_ERROR )
  338. { for( i = 0; i < N; i++ ) TIMES[i] = HPL_PTIMER_ERROR; return; }
  339. else
  340. { for( i = 0; i < N; i++ ) TIMES[i] = HPL_ptimer_cpusec[IBEG+i]; }
  341. }
  342. /*
  343. * Combine all nodes information, restore HPL_ptimer_disabled, and return
  344. */
  345. for( i = 0; i < N; i++ ) {
  346. TIMES[i] = Mmax( HPL_rzero, TIMES[i] );
  347. }
  348. if( OPE == HPL_AMAX_PTIME )
  349. (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_max, COMM );
  350. else if( OPE == HPL_AMIN_PTIME )
  351. (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_min, COMM );
  352. else if( OPE == HPL_SUM_PTIME )
  353. (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_sum, COMM );
  354. else
  355. (void) HPL_all_reduce( (void *)(TIMES), N, HPL_DOUBLE, HPL_max, COMM );
  356. HPL_ptimer_disabled = tmpdis;
  357. /*
  358. * End of HPL_ptimer_combine
  359. */
  360. }