home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adaptor.zip / adapt.zip / adaptor / dalib / pvm3 / timing0.c < prev    next >
Text File  |  1993-12-01  |  10KB  |  348 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. #undef 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.           *************************************************/
  78.  
  79. struct tms starttime[TIMERS], stoptime[TIMERS];
  80.  
  81. long ms_start[TIMERS], ms_stop[TIMERS];
  82.  
  83. long start_walltime;                         /* walltime function */
  84.  
  85. #if defined(IPSC)
  86. double first_time;
  87. #endif
  88.  
  89. float usertime[TIMERS], systemtime[TIMERS];
  90. long mean_ms[TIMERS];                        /* measured in milliseconds */
  91.  
  92. #ifdef MULTI
  93. void time_synchronization ()
  94.  
  95. { int x, sender, op;
  96.  
  97.   /* synchronize all processors */
  98.   x = 0;
  99.   if (target_model == 0) /* WITH HOST */
  100.      sender = 0;
  101.    else
  102.      sender = 1;
  103.   process_broadcast (&x, 0, sender);
  104.   op = 7;
  105.   dalib_reduction_ (&x, &op);           /* int_sum */
  106. }
  107. #endif
  108.  
  109.           /*************************************************
  110.           *                                                *
  111.           *  long dalib_timestamp ()                       *
  112.           *                                                *
  113.           *    - get a time stamp of current walltime      *
  114.           *                                                *
  115.           *  counts tick, tick is usually every 10 us      *
  116.           *                                                *
  117.           *  machine dependent implementation              *
  118.           *                                                *
  119.           *************************************************/
  120.  
  121. /* general function to get a time stamp */
  122.  
  123. #if defined(SUN4) || defined(IBM) || defined(SRM) || defined(KSR1) || defined(SGI) || defined(OS2)
  124. long dalib_timestamp ()
  125. { long t;
  126.   struct timeval tp;
  127.   struct timezone tzp;
  128.   (void) gettimeofday(&tp,&tzp);
  129.   t = tp.tv_sec * 100000 + tp.tv_usec / 10;
  130.   return (t);
  131. }
  132. #endif
  133.  
  134. #if defined(ALLIANT)
  135. long dalib_timestamp ()
  136. { long t;
  137.   t = hrcounter.uuu.ddd.d_hv_low;  /* tick every 10 us */
  138.   return (t);
  139. }
  140. #endif
  141.  
  142. #if defined(IPSC)
  143. long dalib_timestamp ()
  144. { long t;
  145.   double d, dclock_ ();
  146.  
  147.   d = dclock_() - first_time;
  148.   t = d * ((double) 100000.0);  /* tick every 10 us */
  149.   return (t);
  150. }
  151. #endif
  152.  
  153. #if defined(HMEIKO)
  154. long dalib_timestamp ()
  155. { long t;
  156.   t = MEIKO_time((void *)NULL)/100000;
  157.   return (t);
  158. }
  159. #endif
  160.  
  161. #if defined(MEIKO)
  162. long dalib_timestamp ()
  163. { long t;
  164.   double dzero, dsecnds_();
  165.   dzero = 0.0;
  166.   d = dsecnds_(&dzero);
  167.   t = d * ((double) 100000.0);  /* tick every 10 us */
  168.   return (t);
  169. }
  170. #endif
  171.  
  172. #if defined(GC)
  173. long dalib_timestamp ()
  174. { long t;
  175.   t = TimeNowLow ();               /* tick every 64 us */
  176.   return (t);
  177. }
  178. #endif
  179.  
  180. #if defined(IPB)
  181. long dalib_timestamp ()
  182. { long t;
  183.   double d;
  184.   CMMD_node_timer_stop (0);
  185.   d = CMMD_node_timer_elapsed (0);
  186.   CMMD_node_timer_start (0);
  187.   t = d * 100000.0;                 /* tick for 10 us */
  188.   return (t);
  189. }
  190. #endif
  191.  
  192.           /*************************************************
  193.           *                                                *
  194.           *  void dalib_init_walltime ()                   *
  195.           *                                                *
  196.           *************************************************/
  197.  
  198. void dalib_init_walltime ()
  199.  
  200. { /* walltime is measured in multiple of 10 microseconds */
  201.  
  202. #if defined(IPSC)
  203.   double dclock_ ();
  204.   first_time = dclock_ ();
  205. #endif
  206. #if defined(IPB)
  207.   CMMD_node_timer_clear (0);
  208. #endif
  209.   start_walltime = dalib_timestamp ();
  210. }
  211.  
  212. void dalib_clear_timer__ (timer)
  213. int *timer;
  214. {
  215.   int tim;
  216.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  217.  
  218.   mean_ms   [tim] = 0;
  219.   usertime  [tim] = 0.0;
  220.   systemtime[tim] = 0.0;
  221. }
  222.  
  223. void dalib_start_timer__ (timer)
  224. int *timer;
  225. {
  226.   int tim;
  227.     
  228.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  229.  
  230. #ifdef MULTI
  231.   time_synchronization ();
  232. #endif
  233.  
  234. #if defined(IPB)
  235.   starttime[tim].tms_utime = 0;
  236.   starttime[tim].tms_stime = 0;
  237. #else
  238.   times (starttime+tim);
  239. #endif
  240.  
  241.   ms_start[tim] = dalib_timestamp ();
  242. }
  243.  
  244. void dalib_stop_timer__ (timer)
  245. int *timer;
  246.  
  247. { float h;
  248.   int tim;
  249.  
  250.   tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  251.  
  252. #ifdef MULTI
  253.   time_synchronization ();
  254. #endif
  255.  
  256.   /* stop timer */
  257. #if defined(IPB)
  258.   stoptime[tim].tms_utime = 0;
  259.   stoptime[tim].tms_stime = 0;
  260. #else
  261.   times (stoptime+tim);
  262. #endif
  263.  
  264.   ms_stop[tim] = dalib_timestamp ();
  265.  
  266.   /* add user time */
  267.   h = stoptime[tim].tms_utime - starttime[tim].tms_utime;
  268.   h = h / HZ;
  269.   usertime[tim] += h;
  270.  
  271.   /* add system time */
  272.   h = stoptime[tim].tms_stime - starttime[tim].tms_stime;
  273.   h = h / HZ;
  274.   systemtime[tim] += h;
  275.  
  276.   /* add whole time */
  277.   mean_ms[tim]    += (ms_stop[tim] - ms_start[tim]);
  278. }
  279.  
  280. void dalib_print_timer__ (timer)
  281. int *timer;
  282. {
  283.  int tim, printer;
  284.  long milli_seconds;
  285.  tim = *timer; if (tim < 0) tim = 0; if (tim>=TIMERS) tim = 0;
  286.  
  287. #if defined(ALLIANT) || defined(SUN4) || defined(IBM) || defined(SRM) || defined(IPSC) || defined (MEIKO) || defined (KSR1) || defined (SGI) || defined(OS2)
  288.   milli_seconds = mean_ms[tim] / 100;
  289. #endif
  290. #if defined(GC)
  291.   milli_seconds = mean_ms[tim] * 1000 / CLK_TCK_LOW;
  292. #endif
  293.  
  294.  
  295. #ifdef MULTI
  296.  if (target_model == 0) /* WITH HOST */
  297.     printer = 0;
  298.   else
  299.     printer = 1;
  300.  
  301.  if (pcb.i == printer)
  302.   printf ("Timer %d: User time: %f, System time: %f, Mean time: %d ms\n",
  303.            tim, usertime[tim], systemtime[tim], milli_seconds);
  304. #else
  305.   printf ("Timer %d: User time: %f, System time: %f, Mean time: %d ms\n",
  306.            tim, usertime[tim], systemtime[tim], milli_seconds);
  307. #endif
  308. }
  309.  
  310. void dalib_walltime_ (t)
  311. float *t;
  312.  
  313. { long us;
  314.  
  315.   int from, length;
  316.  
  317. #ifdef MULTI
  318.   time_synchronization ();
  319. #endif
  320.  
  321.   us = dalib_timestamp ();
  322.   us -= start_walltime;
  323.  
  324.   /* justify to s */
  325.  
  326. #if defined(IPSC) || defined (SRM) || defined (MEIKO) || defined (IPB)
  327.   *t = ((float) us ) / 100000.0;
  328. #endif
  329. #if defined(ALLIANT) || defined(SUN4) || defined(IBM) || defined(SRM) || defined (KSR1) || defined (SGI) || defined(OS2)
  330.   *t = ((float) us ) / 100000.0;
  331. #endif
  332. #if defined(GC)
  333.   *t = ((float) us ) / ((float) CLK_TCK_LOW);
  334. #endif
  335.  
  336.   /* it might be very important that all processors have the same time */
  337.  
  338. #ifdef MULTI
  339.   from = target_model;
  340. #if defined(SRM) || defined(IPSC) || defined(MEIKO) || defined(HMEIKO) || defined(IPB)
  341.   /* node has only accurate timer */
  342.   from = 1;
  343. #endif
  344.   length = 4;
  345.   dalib_broadcast_ (t, &length, &from);
  346. #endif
  347. }
  348.