home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / adaptor / dalib / pvm3 / timing.c < prev    next >
Text File  |  1993-12-01  |  12KB  |  390 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Jul 92                                                   *
  6. *  Last Update : Sep 92                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB                                       *
  9. *                                                                         *
  10. *  Module      : timing.c                                                 *
  11. *                                                                         *
  12. *  Function    : Time Measurement for Benchmarking and so on              *
  13. *                                                                         *
  14. *  Export :  FORTRAN Interface                                            *
  15. *                                                                         *
  16. *     void dalib_clear_timer_ (n)                                         *
  17. *     void dalib_start_timer_ (n)                                         *
  18. *     void dalib_stop_timer_ (n)                                          *
  19. *     void dalib_print_timer_ (n)                                         *
  20. *                                                                         *
  21. *     void dalib_walltime (t)                                             *
  22. *     float *t;                                                           *
  23. *                                                                         *
  24. **************************************************************************/
  25.  
  26. #if defined(OS2)
  27. #include <time.h>
  28. #endif
  29. #include <sys/types.h>
  30. #include <sys/times.h>
  31. #include <sys/time.h>
  32. #if defined(OS2)
  33. #include <sys/param.h>
  34. #endif
  35.  
  36. /* undef   MULTI for timing1.c,  single node,
  37.    define  MULTI for timing.c,   many nodes    */
  38.  
  39. #define MULTI
  40.  
  41. #ifdef MULTI
  42. #include "system.h"
  43. #endif
  44.  
  45. #ifndef OS2
  46. #define HZ 60
  47. #endif
  48. #define TIMERS 10
  49.  
  50. #if defined(ALLIANT)
  51. extern struct hrcval hrcounter;
  52. #endif
  53.  
  54. #if defined(IPB)
  55. #include <cm/cmmd.h>
  56. #endif
  57.  
  58. /**************************************************************************
  59. *                                                                         *
  60. *  struct tms {                                                           *
  61. *          clock_t tms_utime;              / user time /                  *
  62. *          clock_t tms_stime;              / system time /                *
  63. *          clock_t tms_cutime;             / user time, children /        *
  64. *          clock_t tms_cstime;             / system time, children /      *
  65. *  }                                                                      *
  66. **************************************************************************/
  67.  
  68.           /*************************************************
  69.           *                                                *
  70.           *  values for each TIMER                         *
  71.           *                                                *
  72.           *   starttime [timer]                            *
  73.           *   stoptime  [timer]                            *
  74.           *   ms_start  [timer]                            *
  75.           *   ms_stop   [timer]                            *
  76.           *                                                *
  77.           *   usertime  [timer]   user time of timer       *
  78.           *   systemtime[timer]   system time of timer     *
  79.           *   mean_ms   [timer]   mean time of timer       *
  80.           *                                                *
  81.           *************************************************/
  82.  
  83. struct tms starttime[TIMERS], stoptime[TIMERS];
  84. long   ms_start[TIMERS], ms_stop[TIMERS];
  85.  
  86. long start_walltime;                         /* walltime function */
  87.  
  88. #if defined(IPSC)
  89. double first_time;
  90. #endif
  91.  
  92. float usertime[TIMERS], systemtime[TIMERS];
  93. long mean_ms[TIMERS];                        /* measured in milliseconds */
  94.  
  95. #ifdef MULTI
  96. void time_synchronization ()
  97.  
  98. { int x, sender, op;
  99.  
  100.   /* synchronize all processors */
  101.   x = 0;
  102.   if (target_model == 0) /* WITH HOST */
  103.      sender = 0;
  104.    else
  105.      sender = 1;
  106. #if defined(GC)
  107.   process_broadcast (&x, 1, sender);  /* cannot send 0 bytes */
  108. #else
  109.   process_broadcast (&x, 0, sender);
  110. #endif
  111.   op = 7;
  112.   dalib_reduction__ (&x, &op);           /* int_sum */
  113. }
  114. #endif
  115.  
  116.           /*************************************************
  117.           *                                                *
  118.           *  long dalib_timestamp ()                       *
  119.           *                                                *
  120.           *    - get a time stamp of current walltime      *
  121.           *                                                *
  122.           *  counts tick, tick is usually every 10 us      *
  123.           *                                                *
  124.           *  machine dependent implementation              *
  125.           *                                                *
  126.           *************************************************/
  127.  
  128. /* general function to get a time stamp */
  129.  
  130. #if defined(SUN4) || defined(IBM) || defined(SRM) || defined(KSR1) || defined(SGI) || defined(OS2)
  131. long dalib_timestamp ()
  132. { long t;
  133.   struct timeval tp;
  134.   struct timezone tzp;
  135.   (void) gettimeofday(&tp,&tzp);
  136.   t = tp.tv_sec * 100000 + tp.tv_usec / 10;
  137.   return (t);
  138. }
  139. #endif
  140.  
  141. #if defined(ALLIANT)
  142. long dalib_timestamp ()
  143. { long t;
  144.   t = hrcounter.uuu.ddd.d_hv_low;  /* tick every 10 us */
  145.   return (t);
  146. }
  147. #endif
  148.  
  149. #if defined(IPSC)
  150. long dalib_timestamp ()
  151. { long t;
  152.   double d, dclock_ ();
  153.  
  154.   d = dclock_() - first_time;
  155.   t = d * ((double) 100000.0);  /* tick every 10 us */
  156.   return (t);
  157. }
  158. #endif
  159.  
  160. #if defined(HMEIKO)
  161. long dalib_timestamp ()
  162. { long t;
  163.   t = MEIKO_time((void *)NULL)/100000;
  164.   return (t);
  165. }
  166. #endif
  167.  
  168. #if defined(MEIKO)
  169. long dalib_timestamp ()
  170. { long t;
  171.   double dzero, dsecnds_();
  172.   dzero = 0.0;
  173.   d = dsecnds_(&dzero);
  174.   t = d * ((double) 100000.0);  /* tick every 10 us */
  175.   return (t);
  176. }
  177. #endif
  178.  
  179. #if defined(GC)
  180. long dalib_timestamp ()
  181. { long t;
  182.   t = TimeNowLow ();               /* tick every 64 us */
  183.   return (t);
  184. }
  185. #endif
  186.  
  187. #if defined(IPB)
  188. long dalib_timestamp ()
  189. { long t;
  190.   double d;
  191.   CMMD_node_timer_stop (0);
  192.   d = CMMD_node_timer_elapsed (0);
  193.   CMMD_node_timer_start (0);
  194.   t = d * 100000.0;                 /* tick for 10 us */
  195.   return (t);
  196. }
  197. #endif
  198.  
  199.           /*************************************************
  200.           *                                                *
  201.           *  void dalib_init_walltime ()                   *
  202.           *                                                *
  203.           *************************************************/
  204.  
  205. void dalib_init_walltime ()
  206.  
  207. { /* walltime is measured in multiple of 10 microseconds */
  208.  
  209. #if defined(IPSC)
  210.   double dclock_ ();
  211.   first_time = dclock_ ();
  212. #endif
  213. #if defined(IPB)
  214.   CMMD_node_timer_clear (0);
  215. #endif
  216.   start_walltime = dalib_timestamp ();
  217. }
  218.  
  219.           /*************************************************
  220.           *                                                *
  221.           *  void dalib_clear_timer   ()                   *
  222.           *                                                *
  223.           *************************************************/
  224.  
  225. void dalib_clear_timer__ (timer)
  226. int *timer;
  227. {
  228.   int tim;
  229.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  230.  
  231.   mean_ms   [tim] = 0;
  232.   usertime  [tim] = 0.0;
  233.   systemtime[tim] = 0.0;
  234. }
  235.  
  236.           /*************************************************
  237.           *                                                *
  238.           *  void dalib_start_timer   ()                   *
  239.           *                                                *
  240.           *************************************************/
  241.  
  242. void dalib_start_timer__ (timer)
  243. int *timer;
  244. {
  245.   int tim;
  246.     
  247.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  248.  
  249. #ifdef MULTI
  250.   time_synchronization ();
  251. #endif
  252.  
  253. #if defined(IPB)
  254.   starttime[tim].tms_utime = 0;
  255.   starttime[tim].tms_stime = 0;
  256. #else
  257.   times (starttime+tim);
  258. #endif
  259.  
  260.   ms_start[tim] = dalib_timestamp ();
  261. }
  262.  
  263.           /*************************************************
  264.           *                                                *
  265.           *  void dalib_stop_timer   ()                    *
  266.           *                                                *
  267.           *  - adds the new values                         *
  268.           *                                                *
  269.           *************************************************/
  270.  
  271. void dalib_stop_timer__ (timer)
  272. int *timer;
  273.  
  274. { float h;
  275.   int tim;
  276.  
  277.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  278.  
  279. #ifdef MULTI
  280.   time_synchronization ();
  281. #endif
  282.  
  283.   /* stop timer */
  284. #if defined(IPB)
  285.   stoptime[tim].tms_utime = 0;
  286.   stoptime[tim].tms_stime = 0;
  287. #else
  288.   times (stoptime+tim);
  289. #endif
  290.  
  291.   ms_stop[tim] = dalib_timestamp ();
  292.  
  293.   /* add user time */
  294.   h = stoptime[tim].tms_utime - starttime[tim].tms_utime;
  295.   h = h / HZ;
  296.   usertime[tim] += h;
  297.  
  298.   /* add system time */
  299.   h = stoptime[tim].tms_stime - starttime[tim].tms_stime;
  300.   h = h / HZ;
  301.   systemtime[tim] += h;
  302.  
  303.   /* add whole time */
  304.   mean_ms[tim]    += (ms_stop[tim] - ms_start[tim]);
  305. }
  306.  
  307.           /*************************************************
  308.           *                                                *
  309.           *  void dalib_print_timer   ()                   *
  310.           *                                                *
  311.           *************************************************/
  312.  
  313. void dalib_print_timer__ (timer)
  314. int *timer;
  315. {
  316.  int tim, printer;
  317.  long milli_seconds;
  318.  tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  319.  
  320. #if defined(ALLIANT) || defined(SUN4) || defined(IBM) || defined(SRM) || defined(IPSC) || defined (MEIKO) || defined (KSR1) || defined (SGI) || defined (IPB) || defined(OS2)
  321.   milli_seconds = mean_ms[tim] / 100;
  322. #endif
  323. #if defined(GC)
  324.   milli_seconds = mean_ms[tim] * 1000 / CLK_TCK_LOW;
  325. #endif
  326.  
  327.  
  328. #ifdef MULTI
  329.  if (target_model == 0) /* WITH HOST */
  330.     printer = 0;
  331.   else
  332.     printer = 1;
  333.  
  334.  if (pcb.i == printer)
  335.   printf ("Timer %d: User time: %f, System time: %f, Mean time: %d ms\n",
  336.            tim, usertime[tim], systemtime[tim], milli_seconds);
  337. #else
  338.   printf ("Timer %d: User time: %f, System time: %f, Mean time: %d ms\n",
  339.            tim, usertime[tim], systemtime[tim], milli_seconds);
  340. #endif
  341. }
  342.  
  343.           /*************************************************
  344.           *                                                *
  345.           *  void dalib_walltime   ()                      *
  346.           *                                                *
  347.           *************************************************/
  348.  
  349. void dalib_walltime_ (t)
  350. float *t;
  351.  
  352. { long us;
  353.  
  354.   int from, length;
  355.  
  356. #ifdef MULTI
  357.   time_synchronization ();
  358. #endif
  359.  
  360.   us = dalib_timestamp ();
  361.   us -= start_walltime;
  362.  
  363.   /* justify to seconds */
  364.  
  365. #if defined(IPSC) || defined (SRM) || defined (MEIKO) || defined (IPB)
  366.   *t = ((float) us ) / 100000.0;
  367. #endif
  368. #if defined(ALLIANT) || defined(SUN4) || defined(IBM) || defined(SRM) || defined (KSR1) || defined (SGI) || defined(OS2)
  369.   *t = ((float) us ) / 100000.0;
  370. #endif
  371. #if defined(GC)
  372.   *t = ((float) us ) / ((float) CLK_TCK_LOW);
  373. #endif
  374.  
  375.   /* it might be very important that all processors have the same time */
  376.  
  377. #ifdef MULTI
  378.   from = target_model;
  379. #if defined(SRM) || defined(IPSC) || defined(MEIKO) || defined(HMEIKO) || defined(IPB)
  380.   /* node has only accurate timer */
  381.   from = 1;
  382. #endif
  383.   length = 4;
  384. #if defined(KSR1)
  385.   length = 8;   /* float has length 8 on KSR machines */
  386. #endif
  387.   dalib_broadcast__ (t, &length, &from);
  388. #endif
  389. }
  390.