home *** CD-ROM | disk | FTP | other *** search
/ Inside Multimedia 1995 July / IMM0795.ISO / share / os2 / sysbench / src / pmb_flop.ckr < prev    next >
Text File  |  1994-11-05  |  31KB  |  1,002 lines

  1. /*--------------------- Start flops.c source code ----------------------*/
  2.  
  3. /*****************************/
  4. /*          FLOPS.c          */
  5. /* Version 2.0,  18 Dec 1992 */
  6. /*         Al Aburto         */
  7. /*  aburto@marlin.nosc.mil   */
  8. /*       'ala' on BIX        */
  9. /*****************************/
  10.  
  11. /*
  12.    Flops.c is a 'c' program which attempts to estimate your systems
  13.    floating-point 'MFLOPS' rating for the FADD, FSUB, FMUL, and FDIV
  14.    operations based on specific 'instruction mixes' (discussed below).
  15.    The program provides an estimate of PEAK MFLOPS performance by making
  16.    maximal use of register variables with minimal interaction with main
  17.    memory. The execution loops are all small so that they will fit in
  18.    any cache. Flops.c can be used along with Linpack and the Livermore
  19.    kernels (which exersize memory much more extensively) to gain further
  20.    insight into the limits of system performance. The flops.c execution
  21.    modules also include various percent weightings of FDIV's (from 0% to
  22.    25% FDIV's) so that the range of performance can be obtained when
  23.    using FDIV's. FDIV's, being computationally more intensive than
  24.    FADD's or FMUL's, can impact performance considerably on some systems.
  25.    
  26.    Flops.c consists of 8 independent modules (routines) which, except for
  27.    module 2, conduct numerical integration of various functions. Module
  28.    2, estimates the value of pi based upon the Maclaurin series expansion
  29.    of atan(1). MFLOPS ratings are provided for each module, but the
  30.    programs overall results are summerized by the MFLOPS(1), MFLOPS(2),
  31.    MFLOPS(3), and MFLOPS(4) outputs.
  32.  
  33.    The MFLOPS(1) result is identical to the result provided by all
  34.    previous versions of flops.c. It is based only upon the results from
  35.    modules 2 and 3. Two problems surfaced in using MFLOPS(1). First, it
  36.    was difficult to completely 'vectorize' the result due to the 
  37.    recurrence of the 's' variable in module 2. This problem is addressed
  38.    in the MFLOPS(2) result which does not use module 2, but maintains
  39.    nearly the same weighting of FDIV's (9.2%) as in MFLOPS(1) (9.6%).
  40.    The second problem with MFLOPS(1) centers around the percentage of
  41.    FDIV's (9.6%) which was viewed as too high for an important class of
  42.    problems. This concern is addressed in the MFLOPS(3) result where NO
  43.    FDIV's are conducted at all. 
  44.    
  45.    The number of floating-point instructions per iteration (loop) is
  46.    given below for each module executed:
  47.  
  48.    MODULE   FADD   FSUB   FMUL   FDIV   TOTAL  Comment
  49.      1        7      0      6      1      14   7.1%  FDIV's
  50.      2        3      2      1      1       7   difficult to vectorize.
  51.      3        6      2      9      0      17   0.0%  FDIV's
  52.      4        7      0      8      0      15   0.0%  FDIV's
  53.      5       13      0     15      1      29   3.4%  FDIV's
  54.      6       13      0     16      0      29   0.0%  FDIV's
  55.      7        3      3      3      3      12   25.0% FDIV's
  56.      8       13      0     17      0      30   0.0%  FDIV's
  57.    
  58.    A*2+3     21     12     14      5      52   A=5, MFLOPS(1), Same as
  59.         40.4%  23.1%  26.9%  9.6%          previous versions of the
  60.                            flops.c program. Includes
  61.                            only Modules 2 and 3, does
  62.                            9.6% FDIV's, and is not
  63.                            easily vectorizable.
  64.    
  65.    1+3+4     58     14     66     14     152   A=4, MFLOPS(2), New output
  66.    +5+6+    38.2%  9.2%   43.4%  9.2%          does not include Module 2,
  67.    A*7                                         but does 9.2% FDIV's.
  68.    
  69.    1+3+4     62      5     74      5     146   A=0, MFLOPS(3), New output
  70.    +5+6+    42.9%  3.4%   50.7%  3.4%          does not include Module 2,
  71.    7+8                                         but does 3.4% FDIV's.
  72.  
  73.    3+4+6     39      2     50      0      91   A=0, MFLOPS(4), New output
  74.    +8       42.9%  2.2%   54.9%  0.0%          does not include Module 2,
  75.                            and does NO FDIV's.
  76.  
  77.    NOTE: Various timer routines are included as indicated below. The
  78.      timer routines, with some comments, are attached at the end 
  79.      of the main program.
  80.  
  81.    NOTE: Please do not remove any of the printouts.
  82.  
  83.    EXAMPLE COMPILATION:
  84.    UNIX based systems
  85.       cc -DUNIX -O flops20.c -o flops
  86.       cc -DUNIX -DROPT flops20.c -o flops 
  87.       cc -DUNIX -fast -O4 flops20.c -o flops 
  88.       .
  89.       .
  90.       .
  91.      etc.
  92.  
  93.    Al Aburto
  94.    aburto@marlin.nosc.mil
  95. */
  96.  
  97. //#include <stdio.h>
  98. #include <math.h>
  99.                  /* 'Uncomment' the line below to run   */
  100.                  /* with 'register double' variables    */
  101.                  /* defined, or compile with the        */
  102.                  /* '-DROPT' option. Don't need this if */
  103.                  /* registers used automatically, but   */
  104.                  /* you might want to try it anyway.    */
  105. /* #define ROPT */
  106.  
  107. /***************************************************************/
  108. /* Timer options. You MUST uncomment one of the options below  */
  109. /* or compile, for example, with the '-DUNIX' option.          */
  110. /***************************************************************/
  111. /* #define Amiga       */
  112. /* #define UNIX        */
  113. /* #define UNIX_Old    */
  114. /* #define VMS         */
  115. /* #define BORLAND_C   */
  116. /* #define MSC         */
  117. /* #define MAC         */
  118. /* #define IPSC        */
  119. /* #define FORTRAN_SEC */
  120. /* #define GTODay      */
  121. /* #define CTimer      */
  122. /* #define UXPM        */
  123.  
  124. static double nulltime, TimeArray[3];   /* Variables needed for 'flops_time()'.     */
  125. static double TLimit;                   /* Threshold to determine Number of    */
  126.                  /* Loops to run. Fixed at 15.0 seconds.*/
  127.  
  128. static double T[36];                    /* Global Array used to hold timing    */
  129.                  /* results and other information.      */
  130.  
  131. static double sa,sb,sc,sd,one,two,three;
  132. static double four,five,piref,piprg;
  133. static double scale,pierr;
  134.  
  135. static double A0 = 1.0;
  136. static double A1 = -0.1666666666671334;
  137. static double A2 = 0.833333333809067E-2;
  138. static double A3 = 0.198412715551283E-3;
  139. static double A4 = 0.27557589750762E-5;
  140. static double A5 = 0.2507059876207E-7;
  141. static double A6 = 0.164105986683E-9;
  142.  
  143. static double B0 = 1.0;
  144. static double B1 = -0.4999999999982;
  145. static double B2 = 0.4166666664651E-1;
  146. static double B3 = -0.1388888805755E-2;
  147. static double B4 = 0.24801428034E-4;
  148. static double B5 = -0.2754213324E-6;
  149. static double B6 = 0.20189405E-8;
  150.  
  151. static double C0 = 1.0;
  152. static double C1 = 0.99999999668;
  153. static double C2 = 0.49999995173;
  154. static double C3 = 0.16666704243;
  155. static double C4 = 0.4166685027E-1;
  156. static double C5 = 0.832672635E-2;
  157. static double C6 = 0.140836136E-2;
  158. static double C7 = 0.17358267E-3;
  159. static double C8 = 0.3931683E-4;
  160.  
  161. static double D1 = 0.3999999946405E-1;
  162. static double D2 = 0.96E-3;
  163. static double D3 = 0.1233153E-5;
  164.  
  165. static double E2 = 0.48E-3;
  166. static double E3 = 0.411051E-6;
  167.  
  168. double pmb_flops()
  169. {
  170.  
  171. #ifdef ROPT
  172.    register double s,u,v,w,x;
  173. #else
  174.    double s,u,v,w,x;
  175. #endif
  176.  
  177.    long loops, NLimit;
  178.    register long i, m, n;
  179.  
  180. //   printf("\n");
  181. //   printf("   FLOPS C Program (Double Precision), V2.0 18 Dec 1992\n\n");
  182.  
  183.                /****************************/
  184.    loops = 15625;      /* Initial number of loops. */
  185.                /*     DO NOT CHANGE!       */
  186.                /****************************/
  187.  
  188. /****************************************************/
  189. /* Set Variable Values.                             */
  190. /* T[1] references all timing results relative to   */
  191. /* one million loops.                               */
  192. /*                                                  */
  193. /* The program will execute from 31250 to 512000000 */
  194. /* loops based on a runtime of Module 1 of at least */
  195. /* TLimit = 15.0 seconds. That is, a runtime of 15  */
  196. /* seconds for Module 1 is used to determine the    */
  197. /* number of loops to execute.                      */
  198. /*                                                  */
  199. /* No more than NLimit = 512000000 loops are allowed*/
  200. /****************************************************/
  201.  
  202.    T[1] = 1.0E+06/(double)loops;
  203.  
  204.    TLimit = 15.0;
  205.    NLimit = 512000000;
  206.  
  207.    piref = 3.14159265358979324;
  208.    one   = 1.0;
  209.    two   = 2.0;
  210.    three = 3.0;
  211.    four  = 4.0;
  212.    five  = 5.0;
  213.    scale = one;
  214.  
  215. //   printf("   Module     Error        RunTime      MFLOPS\n");
  216. //   printf("                            (usec)\n");
  217. /*************************/
  218. /* Initialize the timer. */
  219. /*************************/
  220.    
  221.    flops_time(TimeArray);
  222.    flops_time(TimeArray);
  223.    
  224. /*******************************************************/
  225. /* Module 1.  Calculate integral of df(x)/f(x) defined */
  226. /*            below.  Result is ln(f(1)). There are 14 */
  227. /*            double precision operations per loop     */
  228. /*            ( 7 +, 0 -, 6 *, 1 / ) that are included */
  229. /*            in the timing.                           */
  230. /*            50.0% +, 00.0% -, 42.9% *, and 07.1% /   */
  231. /*******************************************************/
  232.    n = loops;
  233.    sa = 0.0;
  234.  
  235.    while ( sa < TLimit )
  236.    {
  237.    n = 2 * n;
  238.    x = one / (double)n;                            /*********************/
  239.    s = 0.0;                                        /*  Loop 1.          */
  240.    v = 0.0;                                        /*********************/
  241.    w = one;
  242.  
  243.       flops_time(TimeArray);
  244.       for( i = 1 ; i <= n-1 ; i++ )
  245.       {
  246.       v = v + w;
  247.       u = v * x;
  248.       s = s + (D1+u*(D2+u*D3))/(w+u*(D1+u*(E2+u*E3)));
  249.       }
  250.       flops_time(TimeArray);
  251.       sa = TimeArray[1];
  252.  
  253.    if ( n == NLimit ) break;
  254.    /* printf(" %10ld  %12.5lf\n",n,sa); */
  255.    }
  256.  
  257.    scale = 1.0E+06 / (double)n;
  258.    T[1]  = scale;
  259.  
  260. /****************************************/
  261. /* Estimate nulltime ('for' loop time). */
  262. /****************************************/
  263.    flops_time(TimeArray);
  264.    for( i = 1 ; i <= n-1 ; i++ )
  265.    {
  266.    }
  267.    flops_time(TimeArray);
  268.    nulltime = T[1] * TimeArray[1];
  269.    if ( nulltime < 0.0 ) nulltime = 0.0;
  270.  
  271.    T[2] = T[1] * sa - nulltime;
  272.  
  273.    sa = (D1+D2+D3)/(one+D1+E2+E3);
  274.    sb = D1;
  275.  
  276.    T[3] = T[2] / 14.0;                             /*********************/
  277.    sa = x * ( sa + sb + two * s ) / two;           /* Module 1 Results. */
  278.    sb = one / sa;                                  /*********************/
  279.    n  = (long)( (double)( 40000 * (long)sb ) / scale );
  280.    sc = sb - 25.2;
  281.    T[4] = one / T[3];
  282.                             /********************/
  283.                             /*  DO NOT REMOVE   */
  284.                             /*  THIS PRINTOUT!  */
  285.                             /********************/
  286. //   printf("     1   %13.4le  %10.4lf  %10.4lf\n",sc,T[2],T[4]);
  287.  
  288.    m = n;
  289.  
  290. /*******************************************************/
  291. /* Module 2.  Calculate value of PI from Taylor Series */
  292. /*            expansion of atan(1.0).  There are 7     */
  293. /*            double precision operations per loop     */
  294. /*            ( 3 +, 2 -, 1 *, 1 / ) that are included */
  295. /*            in the timing.                           */
  296. /*            42.9% +, 28.6% -, 14.3% *, and 14.3% /   */
  297. /*******************************************************/
  298.  
  299.    s  = -five;                                      /********************/
  300.    sa = -one;                                       /* Loop 2.          */
  301.                             /********************/
  302.    flops_time(TimeArray);
  303.    for ( i = 1 ; i <= m ; i++ )
  304.    {
  305.    s  = -s;
  306.    sa = sa + s;
  307.    }
  308.    flops_time(TimeArray);
  309.    T[5] = T[1] * TimeArray[1];
  310.    if ( T[5] < 0.0 ) T[5] = 0.0;
  311.  
  312.    sc   = (double)m;
  313.  
  314.    u = sa;                                         /*********************/
  315.    v = 0.0;                                        /* Loop 3.           */
  316.    w = 0.0;                                        /*********************/
  317.    x = 0.0;
  318.  
  319.    flops_time(TimeArray);
  320.    for ( i = 1 ; i <= m ; i++)
  321.    {
  322.    s  = -s;
  323.    sa = sa + s;
  324.    u  = u + two;
  325.    x  = x +(s - u);
  326.    v  = v - s * u;
  327.    w  = w + s / u;
  328.    }
  329.    flops_time(TimeArray);
  330.    T[6] = T[1] * TimeArray[1];
  331.  
  332.    T[7] = ( T[6] - T[5] ) / 7.0;                   /*********************/
  333.    m  = (long)( sa * x  / sc );                    /*  PI Results       */
  334.    sa = four * w / five;                           /*********************/
  335.    sb = sa + five / v;
  336.    sc = 31.25;
  337.    piprg = sb - sc / (v * v * v);
  338.    pierr = piprg - piref;
  339.    T[8]  = one  / T[7];
  340.                            /*********************/
  341.                            /*   DO NOT REMOVE   */
  342.                            /*   THIS PRINTOUT!  */
  343.                            /*********************/
  344. //   printf("     2   %13.4le  %10.4lf  %10.4lf\n",pierr,T[6]-T[5],T[8]);
  345.  
  346. /*******************************************************/
  347. /* Module 3.  Calculate integral of sin(x) from 0.0 to */
  348. /*            PI/3.0 using Trapazoidal Method. Result  */
  349. /*            is 0.5. There are 17 double precision    */
  350. /*            operations per loop (6 +, 2 -, 9 *, 0 /) */
  351. /*            included in the timing.                  */
  352. /*            35.3% +, 11.8% -, 52.9% *, and 00.0% /   */
  353. /*******************************************************/
  354.  
  355.    x = piref / ( three * (double)m );              /*********************/
  356.    s = 0.0;                                        /*  Loop 4.          */
  357.    v = 0.0;                                        /*********************/
  358.  
  359.    flops_time(TimeArray);
  360.    for( i = 1 ; i <= m-1 ; i++ )
  361.    {
  362.    v = v + one;
  363.    u = v * x;
  364.    w = u * u;
  365.    s = s + u * ((((((A6*w-A5)*w+A4)*w-A3)*w+A2)*w+A1)*w+one);
  366.    }
  367.    flops_time(TimeArray);
  368.    T[9]  = T[1] * TimeArray[1] - nulltime;
  369.  
  370.    u  = piref / three;
  371.    w  = u * u;
  372.    sa = u * ((((((A6*w-A5)*w+A4)*w-A3)*w+A2)*w+A1)*w+one);
  373.  
  374.    T[10] = T[9] / 17.0;                            /*********************/
  375.    sa = x * ( sa + two * s ) / two;                /* sin(x) Results.   */
  376.    sb = 0.5;                                       /*********************/
  377.    sc = sa - sb;
  378.    T[11] = one / T[10];
  379.                            /*********************/
  380.                            /*   DO NOT REMOVE   */
  381.                            /*   THIS PRINTOUT!  */
  382.                            /*********************/
  383. //   printf("     3   %13.4le  %10.4lf  %10.4lf\n",sc,T[9],T[11]);
  384.  
  385. /************************************************************/
  386. /* Module 4.  Calculate Integral of cos(x) from 0.0 to PI/3 */
  387. /*            using the Trapazoidal Method. Result is       */
  388. /*            sin(PI/3). There are 15 double precision      */
  389. /*            operations per loop (7 +, 0 -, 8 *, and 0 / ) */
  390. /*            included in the timing.                       */
  391. /*            50.0% +, 00.0% -, 50.0% *, 00.0% /            */
  392. /************************************************************/
  393.    A3 = -A3;
  394.    A5 = -A5;
  395.    x = piref / ( three * (double)m );              /*********************/
  396.    s = 0.0;                                        /*  Loop 5.          */
  397.    v = 0.0;                                        /*********************/
  398.  
  399.    flops_time(TimeArray);
  400.    for( i = 1 ; i <= m-1 ; i++ )
  401.    {
  402.    u = (double)i * x;
  403.    w = u * u;
  404.    s = s + w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  405.    }
  406.    flops_time(TimeArray);
  407.    T[12]  = T[1] * TimeArray[1] - nulltime;
  408.  
  409.    u  = piref / three;
  410.    w  = u * u;
  411.    sa = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  412.  
  413.    T[13] = T[12] / 15.0;                             /*******************/
  414.    sa = x * ( sa + one + two * s ) / two;            /* Module 4 Result */
  415.    u  = piref / three;                               /*******************/
  416.    w  = u * u;
  417.    sb = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+A0);
  418.    sc = sa - sb;
  419.    T[14] = one / T[13];
  420.                            /*********************/
  421.                            /*   DO NOT REMOVE   */
  422.                            /*   THIS PRINTOUT!  */
  423.                            /*********************/
  424. //   printf("     4   %13.4le  %10.4lf  %10.4lf\n",sc,T[12],T[14]);
  425.  
  426. /************************************************************/
  427. /* Module 5.  Calculate Integral of tan(x) from 0.0 to PI/3 */
  428. /*            using the Trapazoidal Method. Result is       */
  429. /*            ln(cos(PI/3)). There are 29 double precision  */
  430. /*            operations per loop (13 +, 0 -, 15 *, and 1 /)*/
  431. /*            included in the timing.                       */
  432. /*            46.7% +, 00.0% -, 50.0% *, and 03.3% /        */
  433. /************************************************************/
  434.  
  435.    x = piref / ( three * (double)m );              /*********************/
  436.    s = 0.0;                                        /*  Loop 6.          */
  437.    v = 0.0;                                        /*********************/
  438.  
  439.    flops_time(TimeArray);
  440.    for( i = 1 ; i <= m-1 ; i++ )
  441.    {
  442.    u = (double)i * x;
  443.    w = u * u;
  444.    v = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  445.    s = s + v / (w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one);
  446.    }
  447.    flops_time(TimeArray);
  448.    T[15]  = T[1] * TimeArray[1] - nulltime;
  449.  
  450.    u  = piref / three;
  451.    w  = u * u;
  452.    sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  453.    sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  454.    sa = sa / sb;
  455.  
  456.    T[16] = T[15] / 29.0;                             /*******************/
  457.    sa = x * ( sa + two * s ) / two;                  /* Module 5 Result */
  458.    sb = 0.6931471805599453;                          /*******************/
  459.    sc = sa - sb;
  460.    T[17] = one / T[16];
  461.                            /*********************/
  462.                            /*   DO NOT REMOVE   */
  463.                            /*   THIS PRINTOUT!  */
  464.                            /*********************/
  465. //   printf("     5   %13.4le  %10.4lf  %10.4lf\n",sc,T[15],T[17]);
  466.  
  467. /************************************************************/
  468. /* Module 6.  Calculate Integral of sin(x)*cos(x) from 0.0  */
  469. /*            to PI/4 using the Trapazoidal Method. Result  */
  470. /*            is sin(PI/4)^2. There are 29 double precision */
  471. /*            operations per loop (13 +, 0 -, 16 *, and 0 /)*/
  472. /*            included in the timing.                       */
  473. /*            46.7% +, 00.0% -, 53.3% *, and 00.0% /        */
  474. /************************************************************/
  475.  
  476.    x = piref / ( four * (double)m );               /*********************/
  477.    s = 0.0;                                        /*  Loop 7.          */
  478.    v = 0.0;                                        /*********************/
  479.  
  480.    flops_time(TimeArray);
  481.    for( i = 1 ; i <= m-1 ; i++ )
  482.    {
  483.    u = (double)i * x;
  484.    w = u * u;
  485.    v = u * ((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  486.    s = s + v*(w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one);
  487.    }
  488.    flops_time(TimeArray);
  489.    T[18]  = T[1] * TimeArray[1] - nulltime;
  490.  
  491.    u  = piref / four;
  492.    w  = u * u;
  493.    sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  494.    sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  495.    sa = sa * sb;
  496.  
  497.    T[19] = T[18] / 29.0;                             /*******************/
  498.    sa = x * ( sa + two * s ) / two;                  /* Module 6 Result */
  499.    sb = 0.25;                                        /*******************/
  500.    sc = sa - sb;
  501.    T[20] = one / T[19];
  502.                            /*********************/
  503.                            /*   DO NOT REMOVE   */
  504.                            /*   THIS PRINTOUT!  */
  505.                            /*********************/
  506. //   printf("     6   %13.4le  %10.4lf  %10.4lf\n",sc,T[18],T[20]);
  507.  
  508.  
  509. /*******************************************************/
  510. /* Module 7.  Calculate value of the definite integral */
  511. /*            from 0 to sa of 1/(x+1), x/(x*x+1), and  */
  512. /*            x*x/(x*x*x+1) using the Trapizoidal Rule.*/
  513. /*            There are 12 double precision operations */
  514. /*            per loop ( 3 +, 3 -, 3 *, and 3 / ) that */
  515. /*            are included in the timing.              */
  516. /*            25.0% +, 25.0% -, 25.0% *, and 25.0% /   */
  517. /*******************************************************/
  518.  
  519.                            /*********************/
  520.    s = 0.0;                                        /* Loop 8.           */
  521.    w = one;                                        /*********************/
  522.    sa = 102.3321513995275;
  523.    v = sa / (double)m;
  524.  
  525.    flops_time(TimeArray);
  526.    for ( i = 1 ; i <= m-1 ; i++)
  527.    {
  528.    x = (double)i * v;
  529.    u = x * x;
  530.    s = s - w / ( x + w ) - x / ( u + w ) - u / ( x * u + w );
  531.    }
  532.    flops_time(TimeArray);
  533.    T[21] = T[1] * TimeArray[1] - nulltime;
  534.                            /*********************/
  535.                            /* Module 7 Results  */
  536.                            /*********************/
  537.    T[22] = T[21] / 12.0;                                  
  538.    x  = sa;                                      
  539.    u  = x * x;
  540.    sa = -w - w / ( x + w ) - x / ( u + w ) - u / ( x * u + w );
  541.    sa = 18.0 * v * (sa + two * s );
  542.  
  543.    m  = -2000 * (long)sa;
  544.    m = (long)( (double)m / scale );
  545.  
  546.    sc = sa + 500.2;
  547.    T[23] = one / T[22];
  548.                            /********************/
  549.                            /*  DO NOT REMOVE   */
  550.                            /*  THIS PRINTOUT!  */
  551.                            /********************/
  552. //   printf("     7   %13.4le  %10.4lf  %10.4lf\n",sc,T[21],T[23]);
  553.  
  554. /************************************************************/
  555. /* Module 8.  Calculate Integral of sin(x)*cos(x)*cos(x)    */
  556. /*            from 0 to PI/3 using the Trapazoidal Method.  */
  557. /*            Result is (1-cos(PI/3)^3)/3. There are 30     */
  558. /*            double precision operations per loop included */
  559. /*            in the timing:                                */
  560. /*               13 +,     0 -,    17 *          0 /        */
  561. /*            46.7% +, 00.0% -, 53.3% *, and 00.0% /        */
  562. /************************************************************/
  563.  
  564.    x = piref / ( three * (double)m );              /*********************/
  565.    s = 0.0;                                        /*  Loop 9.          */
  566.    v = 0.0;                                        /*********************/
  567.  
  568.    flops_time(TimeArray);
  569.    for( i = 1 ; i <= m-1 ; i++ )
  570.    {
  571.    u = (double)i * x;
  572.    w = u * u;
  573.    v = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  574.    s = s + v*v*u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  575.    }
  576.    flops_time(TimeArray);
  577.    T[24]  = T[1] * TimeArray[1] - nulltime;
  578.  
  579.    u  = piref / three;
  580.    w  = u * u;
  581.    sa = u*((((((A6*w+A5)*w+A4)*w+A3)*w+A2)*w+A1)*w+one);
  582.    sb = w*(w*(w*(w*(w*(B6*w+B5)+B4)+B3)+B2)+B1)+one;
  583.    sa = sa * sb * sb;
  584.  
  585.    T[25] = T[24] / 30.0;                             /*******************/
  586.    sa = x * ( sa + two * s ) / two;                  /* Module 8 Result */
  587.    sb = 0.29166666666666667;                         /*******************/
  588.    sc = sa - sb;
  589.    T[26] = one / T[25];
  590.                            /*********************/
  591.                            /*   DO NOT REMOVE   */
  592.                            /*   THIS PRINTOUT!  */
  593.                            /*********************/
  594. //   printf("     8   %13.4le  %10.4lf  %10.4lf\n",sc,T[24],T[26]);
  595.  
  596. /**************************************************/   
  597. /* MFLOPS(1) output. This is the same weighting   */
  598. /* used for all previous versions of the flops.c  */
  599. /* program. Includes Modules 2 and 3 only.        */
  600. /**************************************************/ 
  601.    T[27] = ( five * (T[6] - T[5]) + T[9] ) / 52.0;
  602.    T[28] = one  / T[27];
  603.  
  604. /**************************************************/   
  605. /* MFLOPS(2) output. This output does not include */
  606. /* Module 2, but it still does 9.2% FDIV's.       */
  607. /**************************************************/ 
  608.    T[29] = T[2] + T[9] + T[12] + T[15] + T[18];
  609.    T[29] = (T[29] + four * T[21]) / 152.0;
  610.    T[30] = one / T[29];
  611.  
  612. /**************************************************/   
  613. /* MFLOPS(3) output. This output does not include */
  614. /* Module 2, but it still does 3.4% FDIV's.       */
  615. /**************************************************/ 
  616.    T[31] = T[2] + T[9] + T[12] + T[15] + T[18];
  617.    T[31] = (T[31] + T[21] + T[24]) / 146.0;
  618.    T[32] = one / T[31];
  619.  
  620. /**************************************************/   
  621. /* MFLOPS(4) output. This output does not include */
  622. /* Module 2, and it does NO FDIV's.               */
  623. /**************************************************/ 
  624.    T[33] = (T[9] + T[12] + T[18] + T[24]) / 91.0;
  625.    T[34] = one / T[33];
  626.  
  627. /*
  628.    printf("\n");
  629.    printf("   Iterations      = %10ld\n",m);
  630.    printf("   NullTime (usec) = %10.4lf\n",nulltime);
  631.    printf("   MFLOPS(1)       = %10.4lf\n",T[28]);
  632.    printf("   MFLOPS(2)       = %10.4lf\n",T[30]);
  633.    printf("   MFLOPS(3)       = %10.4lf\n",T[32]);
  634.    printf("   MFLOPS(4)       = %10.4lf\n\n",T[34]);
  635. */
  636.  
  637.   return (T[28] + T[30] + T[32] + T[34])/4.0*1.0e6;
  638. }
  639.  
  640. /*****************************************************/
  641. /* Various timer routines.                           */
  642. /* Al Aburto, aburto@marlin.nosc.mil, 20 Dec 1992    */
  643. /*                                                   */
  644. /* flops_time(p) outputs the elapsed time seconds in p[1] */
  645. /* from a call of flops_time(p) to the next call of       */
  646. /* flops_time(p).  Use CAUTION as some of these routines  */
  647. /* will mess up when timing across the hour mark!!!  */
  648. /*                                                   */
  649. /* For timing I use the 'user' time whenever         */
  650. /* possible. Using 'user+sys' time is a separate     */
  651. /* issue.                                            */
  652. /*                                                   */
  653. /*****************************************************/
  654.  
  655. /*********************************/
  656. /* Timer code.                   */
  657. /*********************************/
  658. /*******************/
  659. /*  Amiga flops_time()  */
  660. /*******************/
  661. #ifdef Amiga
  662. #include <ctype.h>
  663. #define HZ 50
  664.  
  665. flops_time(p)
  666. double p[];
  667. {
  668.    double q;
  669.  
  670.    struct   tt {
  671.       long  days;
  672.       long  minutes;
  673.       long  ticks;
  674.    } tt;
  675.  
  676.    q = p[2];
  677.  
  678.    DateStamp(&tt);
  679.  
  680.    p[2] = ( (double)(tt.ticks + (tt.minutes * 60L * 50L)) ) / (double)HZ;
  681.    p[1] = p[2] - q;
  682.    
  683.    return 0;
  684. }
  685. #endif
  686.  
  687. /*****************************************************/
  688. /*  UNIX flops_time(). This is the preferred UNIX timer.  */
  689. /*  Provided by: Markku Kolkka, mk59200@cc.tut.fi    */
  690. /*  HP-UX Addition by: Bo Thide', bt@irfu.se         */
  691. /*****************************************************/
  692. #ifdef UNIX
  693. #include <sys/time.h>
  694. #include <sys/resource.h>
  695.  
  696. #ifdef __hpux
  697. #include <sys/syscall.h>
  698. #define getrusage(a,b) syscall(SYS_getrusage,a,b)
  699. #endif
  700.  
  701. struct rusage rusage;
  702.  
  703. flops_time(p)
  704. double p[];
  705. {
  706.    double q;
  707.  
  708.    q = p[2];
  709.  
  710.    getrusage(RUSAGE_SELF,&rusage);
  711.  
  712.    p[2] = (double)(rusage.ru_utime.tv_sec);
  713.    p[2] = p[2] + (double)(rusage.ru_utime.tv_usec) * 1.0e-06;
  714.    p[1] = p[2] - q;
  715.    
  716.    return 0;
  717. }
  718. #endif
  719.  
  720. /***************************************************/
  721. /*  UNIX_Old flops_time(). This is the old UNIX timer.  */
  722. /*  Use only if absolutely necessary as HZ may be  */
  723. /*  ill defined on your system.                    */
  724. /***************************************************/
  725. #ifdef UNIX_Old
  726. #include <sys/types.h>
  727. #include <sys/times.h>
  728. #include <sys/param.h>
  729.  
  730. #ifndef HZ
  731. #define HZ 60
  732. #endif
  733.  
  734. struct tms tms;
  735.  
  736. flops_time(p)
  737. double p[];
  738. {
  739.    double q;
  740.  
  741.    q = p[2];
  742.  
  743.    times(&tms);
  744.  
  745.    p[2] = (double)(tms.tms_utime) / (double)HZ;
  746.    p[1] = p[2] - q;
  747.    
  748.    return 0;
  749. }
  750. #endif
  751.  
  752. /*********************************************************/
  753. /*  VMS flops_time() for VMS systems.                         */
  754. /*  Provided by: RAMO@uvphys.phys.UVic.CA                */
  755. /*  Some people have run into problems with this timer.  */
  756. /*********************************************************/
  757. #ifdef VMS
  758. #include time
  759.  
  760. #ifndef HZ
  761. #define HZ 100
  762. #endif
  763.  
  764. struct tbuffer_t
  765.        {
  766.     int proc_user_time;
  767.     int proc_system_time;
  768.     int child_user_time;
  769.     int child_system_time;
  770.        };
  771. struct tbuffer_t tms;
  772.  
  773. flops_time(p)
  774. double p[];
  775. {
  776.    double q;
  777.  
  778.    q = p[2];
  779.  
  780.    times(&tms);
  781.  
  782.    p[2] = (double)(tms.proc_user_time) / (double)HZ;
  783.    p[1] = p[2] - q;
  784.    
  785.    return 0;
  786. }
  787. #endif
  788.  
  789. /******************************/
  790. /*  BORLAND C flops_time() for DOS */
  791. /******************************/
  792. #ifdef BORLAND_C
  793. #include <ctype.h>
  794. #include <dos.h>
  795. #include <time.h>
  796.  
  797. #define HZ 100
  798. struct time tnow;
  799.  
  800. flops_time(p)
  801. double p[];
  802. {
  803.    double q;
  804.  
  805.    q = p[2];
  806.  
  807.    gettime(&tnow);
  808.  
  809.    p[2] = 60.0 * (double)(tnow.ti_min);
  810.    p[2] = p[2] + (double)(tnow.ti_sec);
  811.    p[2] = p[2] + (double)(tnow.ti_hund)/(double)HZ;
  812.    p[1] = p[2] - q;
  813.    
  814.    return 0;
  815. }
  816. #endif
  817.  
  818. /**************************************/
  819. /*  Microsoft C (MSC) flops_time() for DOS */
  820. /**************************************/
  821. #ifdef MSC
  822. #include <time.h>
  823. #include <ctype.h>
  824.  
  825. #define HZ CLK_TCK
  826. clock_t tnow;
  827.  
  828. flops_time(p)
  829. double p[];
  830. {
  831.    double q;
  832.  
  833.    q = p[2];
  834.  
  835.    tnow = clock();
  836.  
  837.    p[2] = (double)tnow / (double)HZ;
  838.    p[1] = p[2] - q;
  839.    
  840.    return 0;
  841. }
  842. #endif
  843.  
  844. /*************************************/
  845. /*  Macintosh (MAC) Think C flops_time()  */
  846. /*************************************/
  847. #ifdef MAC
  848. #include <time.h>
  849.  
  850. #define HZ 60
  851.  
  852. flops_time(p)
  853. double p[];
  854. {
  855.    double q;
  856.  
  857.    q = p[2];
  858.  
  859.    p[2] = (double)clock() / (double)HZ;
  860.    p[1] = p[2] - q;
  861.    
  862.    return 0;
  863. }
  864. #endif
  865.  
  866. /************************************************************/
  867. /*  iPSC/860 (IPSC) flops_time() for i860.                       */
  868. /*  Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU  */
  869. /************************************************************/
  870. #ifdef IPSC
  871. extern double dclock();
  872.  
  873. flops_time(p)
  874. double p[];
  875. {
  876.    double q;
  877.  
  878.    q = p[2];
  879.  
  880.    p[2] = dclock();
  881.    p[1] = p[2] - q;
  882.    
  883.    return 0;
  884. }
  885. #endif
  886.  
  887. /**************************************************/
  888. /*  FORTRAN flops_time() for Cray type systems.        */
  889. /*  This is the preferred timer for Cray systems. */
  890. /**************************************************/
  891. #ifdef FORTRAN_SEC
  892.  
  893. fortran double second();
  894.  
  895. flops_time(p)
  896. double p[];
  897. {
  898.    double q,v;
  899.  
  900.    q = p[2];
  901.  
  902.    second(&v);
  903.    p[2] = v;
  904.    p[1] = p[2] - q;
  905.    
  906.    return 0;
  907. }
  908. #endif
  909.  
  910. /***********************************************************/
  911. /*  UNICOS C flops_time() for Cray UNICOS systems.  Don't use   */
  912. /*  unless absolutely necessary as returned time includes  */
  913. /*  'user+system' time.  Provided by: R. Mike Dority,      */
  914. /*  dority@craysea.cray.com                                */
  915. /***********************************************************/
  916. #ifdef CTimer
  917. #include <time.h>
  918.  
  919. flops_time(p)
  920. double p[];
  921. {
  922.    double    q;
  923.    clock_t   t;
  924.  
  925.        q = p[2];
  926.  
  927.        t = clock();
  928.  
  929.        p[2] = (double)t / (double)CLOCKS_PER_SEC;
  930.        p[1] = p[2] - q;
  931.  
  932.        return 0;
  933. }
  934. #endif
  935.  
  936. /********************************************/
  937. /* Another UNIX timer using gettimeofday(). */
  938. /* However, getrusage() is preferred.       */
  939. /********************************************/
  940. #ifdef GTODay
  941. #include <sys/time.h>
  942.  
  943. struct timeval tnow;
  944.  
  945. flops_time(p)
  946. double p[];
  947. {
  948.    double q;
  949.  
  950.    q = p[2];
  951.  
  952.    gettimeofday(&tnow,NULL);
  953.    p[2] = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6;
  954.    p[1] = p[2] - q;
  955.  
  956.    return 0;
  957. }
  958. #endif
  959.  
  960. /*****************************************************/
  961. /*  Fujitsu UXP/M timer.                             */
  962. /*  Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
  963. /*****************************************************/
  964. #ifdef UXPM
  965. #include <sys/types.h>
  966. #include <sys/timesu.h>
  967. struct tmsu rusage;
  968.  
  969. flops_time(p)
  970. double p[];
  971. {
  972.    double q;
  973.  
  974.    q = p[2];
  975.  
  976.    timesu(&rusage);
  977.  
  978.    p[2] = (double)(rusage.tms_utime) * 1.0e-06;
  979.    p[1] = p[2] - q;
  980.    
  981.    return 0;
  982. }
  983. #endif
  984.  
  985. /*------------- End flops.c code, say good night Carol! --------------*/
  986.  
  987. #include <time.h>
  988.  
  989. flops_time(p)
  990. double p[];
  991. {
  992.    double q;
  993.  
  994.    q = p[2];
  995.  
  996.    p[2] = ((double)clock())/CLOCKS_PER_SEC;
  997.    p[1] = p[2] - q;
  998.    
  999.    return 0;
  1000. }
  1001.  
  1002.