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