home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / benchmar / 1924 < prev    next >
Encoding:
Text File  |  1993-01-11  |  29.7 KB  |  997 lines

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