home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / ntcode / ptnt / whet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  41.6 KB  |  2,229 lines

  1. /* whetstone/
  2.  *      Whetstone benchmark in C.  This program is a translation of the
  3.  *    original Algol version in "A Synthetic Benchmark" by H.J. Curnow
  4.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.
  5.  *
  6.  *    Used to test compiler optimization and floating point performance.
  7.  *
  8.  *    Compile by:        cc -O -s -o whet whet.c
  9.  *    or:            cc -O -DPOUT -s -o whet whet.c
  10.  *    if output is desired.
  11.  */
  12.  
  13. // modified by l.g. kahn for windows NT to do parallel version. 
  14.  
  15. // #define ITERATIONS    10 /* 1 Million Whetstone instructions */
  16. //#define ITERATIONS    100 /* 10 Million Whetstone instructions */
  17.  
  18. #include "math.h"
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21.  
  22. /* processor benchmark using multiple threads */
  23.  
  24.  
  25.  
  26. #include <windows.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <io.h>
  30. #include <time.h>
  31. #include <process.h>
  32. #include <string.h>
  33. #include <direct.h>
  34. #include <errno.h>
  35.  
  36. #include <fcntl.h>
  37. #include <stdarg.h>
  38. #include <malloc.h>
  39.  
  40. #define maxthreads 8
  41.  
  42. DWORD threadid[maxthreads];
  43. HANDLE threadhandle[maxthreads];
  44. DWORD ProcAff;
  45. DWORD SysAff;
  46. DWORD ThdAff;
  47.  
  48. DWORD thread_start_time[maxthreads];
  49. DWORD thread_stop_time[maxthreads];
  50. DWORD starttime, stoptime;
  51. BOOLEAN setprocessoraffinity = FALSE;
  52. BOOLEAN assignedpaffin[maxthreads] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE };
  53. DWORD paffinarray[maxthreads] = { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  54.  
  55.  
  56. /*BOOL
  57. WINAPI
  58. GetProcessAffinityMask(
  59.     HANDLE hProcess,
  60.     LPDWORD lpProcessAffinityMask,
  61.     LPDWORD lpSystemAffinityMask
  62.     );
  63.  
  64. DWORD
  65. WINAPI
  66. SetThreadAffinityMask(
  67.     HANDLE hThread,
  68.     DWORD dwThreadAffinityMask
  69.     );
  70. */
  71. int noprocessors = 0;
  72. int availprocessors = 0;
  73.  
  74. double         e1[4], t, t1, t2;
  75. int        i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
  76.  
  77. int ITERATIONS = 100; // = 10 million whetstones
  78.  
  79. int number_of_processors(affin)
  80. DWORD affin;
  81.  
  82. {
  83.    
  84.   int numprocessors = 0;
  85.  
  86.   // return the number of processors based on the system affinity dword
  87.   // each bit represents a processor
  88.   // ie 00000011 = 3 = 2 processors 
  89.   if (affin == 0x0001)
  90.     numprocessors = 1;
  91.   else if (affin == 0x0003)
  92.      numprocessors = 2;
  93.   else if (affin == 0x0007)
  94.      numprocessors = 3;
  95.   else if (affin == 0x000F)
  96.      numprocessors = 4;
  97.   else if (affin == 0x001F)
  98.      numprocessors = 5;
  99.   else if (affin == 0x003F)
  100.      numprocessors = 6;
  101.   else if (affin == 0x007F)
  102.      numprocessors = 7;
  103.   else if (affin == 0x00FF)
  104.      numprocessors = 8;
  105.   else if (affin == 0x01FF)
  106.      numprocessors = 9;
  107.   else if (affin = 0x03FF)
  108.      numprocessors == 10;
  109.   else if (affin = 0x07FF)
  110.      numprocessors = 11;
  111.   else if (affin == 0x0FFF)
  112.      numprocessors = 12;
  113.   else if (affin == 0x1FFF)
  114.      numprocessors = 13;
  115.   else if (affin == 0x3FFF)
  116.      numprocessors = 14;
  117.   else if (affin == 0x7FFF)
  118.      numprocessors = 15;
  119.    else if (affin == 0xFFFF)
  120.      numprocessors = 16;
  121.  
  122. else 
  123.  
  124.   {
  125.     printf("ERROR: Illegal processor affinity mask = %x defaulting to 1 processor. \n",affin);
  126.      fflush(stdout);
  127.     numprocessors = 1;
  128.   }
  129.  
  130.   
  131. return numprocessors;
  132.  
  133. }
  134.  
  135. void set_thread_to_processor(thnd,processorno,threadno)
  136. HANDLE thnd;
  137. int processorno;
  138. int threadno;
  139.  
  140. {
  141.  
  142.  DWORD affinmask = 0;
  143.  DWORD ThdAff = 0;
  144.  
  145.  
  146.   // override if set thread individually
  147.   if (assignedpaffin[threadno])
  148.     {
  149.      printf("Setting thread number %d with Affinity mask %ld \n",threadno,paffinarray[threadno]);
  150.      fflush(stdout);
  151.      
  152.      ThdAff = SetThreadAffinityMask( thnd,paffinarray[threadno]);
  153.      if ( !ThdAff )
  154.       printf( "SetThreadAffinityMask(%ld) failed\n\n",paffinarray[threadno] );
  155.      else printf( "Previous thread affinity %x\n\n", ThdAff );
  156.      fflush(stdout);
  157.     }
  158.  
  159.    else
  160.  
  161.     {
  162.  
  163.   printf("Setting thread number %d to only run on processor %d \n",threadno,processorno);
  164.   fflush(stdout);
  165.  
  166.   switch (processorno)
  167.           {
  168.          case 1:
  169.           affinmask = (DWORD)1;
  170.           break;
  171.          
  172.          case 2:
  173.           affinmask = (DWORD)1 << 1;
  174.           break;
  175.          
  176.          case 3:
  177.           affinmask = (DWORD)1 << 2;
  178.           break;
  179.  
  180.          case 4:
  181.           affinmask = (DWORD)1 << 3;
  182.           break;
  183.  
  184.          case 5:
  185.           affinmask = (DWORD)1 << 4;
  186.           break;
  187.  
  188.          case 6:
  189.           affinmask = (DWORD)1 << 5;
  190.           break;
  191.          
  192.          case 7:
  193.           affinmask = (DWORD)1 << 6;
  194.           break;
  195.          
  196.          case 8:
  197.           affinmask = (DWORD)1 << 7;
  198.           break;
  199.  
  200.   
  201.  
  202.          default: printf("Illegal processor number %d in set thread to processor\n",processorno);
  203.                   printf("Defaulting to processor 1 \n");
  204.                   fflush(stdout);
  205.                   affinmask = 1 << 1;
  206.  
  207.  
  208.         }
  209.  
  210.      // now set the thing
  211.  
  212.    ThdAff = SetThreadAffinityMask( thnd,affinmask);
  213. if ( !ThdAff )
  214.       printf( "SetThreadAffinityMask(%ld) failed\n\n",affinmask );
  215.    else printf( "Previous thread affinity %x\n\n", ThdAff );
  216.    fflush(stdout);
  217.   }
  218.  }    
  219.  
  220.  
  221. #ifdef POUT
  222. void pout(n, j, k, x1, x2, x3, x4)
  223. int n, j, k;
  224. double x1, x2, x3, x4;
  225. {
  226.     printf("%6d%6d%6d  %5e  %5e  %5e  %5e\n",
  227.         n, j, k, x1, x2, x3, x4);
  228. }
  229. #endif
  230.  
  231.  
  232.  
  233. void pa_1(e)
  234. double e[4];
  235. {
  236.     register int j;
  237.  
  238.     j = 0;
  239.      lab:
  240.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  241.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  242.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  243.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  244.     j += 1;
  245.     if (j < 6)
  246.         goto lab;
  247. }
  248.  
  249.  
  250. void pa_2(e)
  251. double e[4];
  252. {
  253.     register int j;
  254.  
  255.     j = 0;
  256.      lab:
  257.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  258.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  259.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  260.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  261.     j += 1;
  262.     if (j < 6)
  263.         goto lab;
  264. }
  265.  
  266. void pa_3(e)
  267. double e[4];
  268. {
  269.     register int j;
  270.  
  271.     j = 0;
  272.      lab:
  273.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  274.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  275.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  276.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  277.     j += 1;
  278.     if (j < 6)
  279.         goto lab;
  280. }
  281.  
  282. void pa_4(e)
  283. double e[4];
  284. {
  285.     register int j;
  286.  
  287.     j = 0;
  288.      lab:
  289.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  290.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  291.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  292.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  293.     j += 1;
  294.     if (j < 6)
  295.         goto lab;
  296. }
  297.  
  298. void pa_5(e)
  299. double e[4];
  300. {
  301.     register int j;
  302.  
  303.     j = 0;
  304.      lab:
  305.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  306.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  307.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  308.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  309.     j += 1;
  310.     if (j < 6)
  311.         goto lab;
  312. }
  313.  
  314. void pa_6(e)
  315. double e[4];
  316. {
  317.     register int j;
  318.  
  319.     j = 0;
  320.      lab:
  321.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  322.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  323.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  324.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  325.     j += 1;
  326.     if (j < 6)
  327.         goto lab;
  328. }
  329.  
  330. void pa_7(e)
  331. double e[4];
  332. {
  333.     register int j;
  334.  
  335.     j = 0;
  336.      lab:
  337.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  338.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  339.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  340.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  341.     j += 1;
  342.     if (j < 6)
  343.         goto lab;
  344. }
  345.  
  346. void pa_8(e)
  347. double e[4];
  348. {
  349.     register int j;
  350.  
  351.     j = 0;
  352.      lab:
  353.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  354.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  355.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  356.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  357.     j += 1;
  358.     if (j < 6)
  359.         goto lab;
  360. }
  361.  
  362.  
  363. void p3_1(x, y, z)
  364. double x, y, *z;
  365. {
  366.     x  = t * (x + y);
  367.     y  = t * (x + y);
  368.     *z = (x + y) /t2;
  369. }
  370.  
  371. void p3_2(x, y, z)
  372. double x, y, *z;
  373. {
  374.     x  = t * (x + y);
  375.     y  = t * (x + y);
  376.     *z = (x + y) /t2;
  377. }
  378.  
  379. void p3_3(x, y, z)
  380. double x, y, *z;
  381. {
  382.     x  = t * (x + y);
  383.     y  = t * (x + y);
  384.     *z = (x + y) /t2;
  385. }
  386.  
  387. void p3_4(x, y, z)
  388. double x, y, *z;
  389. {
  390.     x  = t * (x + y);
  391.     y  = t * (x + y);
  392.     *z = (x + y) /t2;
  393. }
  394.  
  395. void p3_5(x, y, z)
  396. double x, y, *z;
  397. {
  398.     x  = t * (x + y);
  399.     y  = t * (x + y);
  400.     *z = (x + y) /t2;
  401. }
  402.  
  403. void p3_6(x, y, z)
  404. double x, y, *z;
  405. {
  406.     x  = t * (x + y);
  407.     y  = t * (x + y);
  408.     *z = (x + y) /t2;
  409. }
  410.  
  411. void p3_7(x, y, z)
  412. double x, y, *z;
  413. {
  414.     x  = t * (x + y);
  415.     y  = t * (x + y);
  416.     *z = (x + y) /t2;
  417. }
  418.  
  419. void p3_8(x, y, z)
  420. double x, y, *z;
  421. {
  422.     x  = t * (x + y);
  423.     y  = t * (x + y);
  424.     *z = (x + y) /t2;
  425. }
  426.  
  427.  
  428. void p0_1()
  429. {
  430.     e1[j] = e1[k];
  431.     e1[k] = e1[l];
  432.     e1[l] = e1[j];
  433. }
  434.  
  435. void p0_2()
  436. {
  437.     e1[j] = e1[k];
  438.     e1[k] = e1[l];
  439.     e1[l] = e1[j];
  440. }
  441.  
  442. void p0_3()
  443. {
  444.     e1[j] = e1[k];
  445.     e1[k] = e1[l];
  446.     e1[l] = e1[j];
  447. }
  448.  
  449. void p0_4()
  450. {
  451.     e1[j] = e1[k];
  452.     e1[k] = e1[l];
  453.     e1[l] = e1[j];
  454. }
  455.  
  456. void p0_5()
  457. {
  458.     e1[j] = e1[k];
  459.     e1[k] = e1[l];
  460.     e1[l] = e1[j];
  461. }
  462.  
  463. void p0_6()
  464. {
  465.     e1[j] = e1[k];
  466.     e1[k] = e1[l];
  467.     e1[l] = e1[j];
  468. }
  469.  
  470. void p0_7()
  471. {
  472.     e1[j] = e1[k];
  473.     e1[k] = e1[l];
  474.     e1[l] = e1[j];
  475. }
  476.  
  477. void p0_8()
  478. {
  479.     e1[j] = e1[k];
  480.     e1[k] = e1[l];
  481.     e1[l] = e1[j];
  482. }
  483.  
  484. DWORD thread0()
  485. {
  486.  
  487. double        x1, x2, x3, x4, x, y, z;
  488.  
  489. thread_start_time[0] = GetTickCount();
  490.  
  491.     /* initialize constants */
  492.  
  493.     t   =   0.499975;
  494.     t1  =   0.50025;
  495.     t2  =   2.0;
  496.  
  497.     /* set values of module weights */
  498.  
  499.     n1  =   0 * ITERATIONS;
  500.     n2  =  12 * ITERATIONS;
  501.     n3  =  14 * ITERATIONS;
  502.     n4  = 345 * ITERATIONS;
  503.     n6  = 210 * ITERATIONS;
  504.     n7  =  32 * ITERATIONS;
  505.     n8  = 899 * ITERATIONS;
  506.     n9  = 616 * ITERATIONS;
  507.     n10 =   0 * ITERATIONS;
  508.     n11 =  93 * ITERATIONS;
  509.  
  510. /* MODULE 1:  simple identifiers */
  511.  
  512.     x1 =  1.0;
  513.     x2 = x3 = x4 = -1.0;
  514.  
  515.     for(i = 1; i <= n1; i += 1) {
  516.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  517.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  518.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  519.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  520.     }
  521. #ifdef POUT
  522.     pout(n1, n1, n1, x1, x2, x3, x4);
  523. #endif
  524.  
  525.  
  526. /* MODULE 2:  array elements */
  527.  
  528.     e1[0] =  1.0;
  529.     e1[1] = e1[2] = e1[3] = -1.0;
  530.  
  531.     for (i = 1; i <= n2; i +=1) {
  532.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  533.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  534.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  535.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  536.     }
  537. #ifdef POUT
  538.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  539. #endif
  540.  
  541. /* MODULE 3:  array as parameter */
  542.  
  543.     for (i = 1; i <= n3; i += 1)
  544.         pa_1(e1);
  545. #ifdef POUT
  546.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  547. #endif
  548.  
  549. /* MODULE 4:  conditional jumps */
  550.  
  551.     j = 1;
  552.     for (i = 1; i <= n4; i += 1) {
  553.         if (j == 1)
  554.             j = 2;
  555.         else
  556.             j = 3;
  557.  
  558.         if (j > 2)
  559.             j = 0;
  560.         else
  561.             j = 1;
  562.  
  563.         if (j < 1 )
  564.             j = 1;
  565.         else
  566.             j = 0;
  567.     }
  568. #ifdef POUT
  569.     pout(n4, j, j, x1, x2, x3, x4);
  570. #endif
  571.  
  572. /* MODULE 5:  omitted */
  573.  
  574. /* MODULE 6:  integer arithmetic */
  575.  
  576.     j = 1;
  577.     k = 2;
  578.     l = 3;
  579.  
  580.     for (i = 1; i <= n6; i += 1) {
  581.         j = j * (k - j) * (l -k);
  582.         k = l * k - (l - j) * k;
  583.         l = (l - k) * (k + j);
  584.  
  585.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  586.         e1[k - 2] = j * k * l;
  587.     }
  588. #ifdef POUT
  589.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  590. #endif
  591.  
  592. /* MODULE 7:  trig. functions */
  593.  
  594.     x = y = 0.5;
  595.  
  596.     for(i = 1; i <= n7; i +=1) {
  597.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  598.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  599.     }
  600. #ifdef POUT
  601.     pout(n7, j, k, x, x, y, y);
  602. #endif
  603.  
  604. /* MODULE 8:  procedure calls */
  605.  
  606.     x = y = z = 1.0;
  607.  
  608.     for (i = 1; i <= n8; i +=1)
  609.         p3_1(x, y, &z);
  610. #ifdef POUT
  611.     pout(n8, j, k, x, y, z, z);
  612. #endif
  613.  
  614. /* MODULE9:  array references */
  615.  
  616.     j = 1;
  617.     k = 2;
  618.     l = 3;
  619.  
  620.     e1[0] = 1.0;
  621.     e1[1] = 2.0;
  622.     e1[2] = 3.0;
  623.  
  624.     for(i = 1; i <= n9; i += 1)
  625.         p0_1();
  626. #ifdef POUT
  627.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  628. #endif
  629.  
  630. /* MODULE10:  integer arithmetic */
  631.  
  632.     j = 2;
  633.     k = 3;
  634.  
  635.     for(i = 1; i <= n10; i +=1) {
  636.         j = j + k;
  637.         k = j + k;
  638.         j = k - j;
  639.         k = k - j - j;
  640.     }
  641. #ifdef POUT
  642.     pout(n10, j, k, x1, x2, x3, x4);
  643. #endif
  644.  
  645. /* MODULE11:  standard functions */
  646.  
  647.     x = 0.75;
  648.     for(i = 1; i <= n11; i +=1)
  649.         x = sqrt( exp( log(x) / t1));
  650.  
  651. #ifdef POUT
  652.     pout(n11, j, k, x, x, x, x);
  653. #endif
  654.  
  655. // lgk modifications to record kips and start and times
  656.  
  657. thread_stop_time[0] = GetTickCount();
  658.  
  659. return 0;
  660.  
  661. }
  662.  
  663.  
  664.  
  665.  
  666. DWORD thread1()
  667. {
  668.  
  669. double        x1, x2, x3, x4, x, y, z;
  670.  
  671.     /* initialize constants */
  672. thread_start_time[1] = GetTickCount();
  673.  
  674.     t   =   0.499975;
  675.     t1  =   0.50025;
  676.     t2  =   2.0;
  677.  
  678.     /* set values of module weights */
  679.  
  680.     n1  =   0 * ITERATIONS;
  681.     n2  =  12 * ITERATIONS;
  682.     n3  =  14 * ITERATIONS;
  683.     n4  = 345 * ITERATIONS;
  684.     n6  = 210 * ITERATIONS;
  685.     n7  =  32 * ITERATIONS;
  686.     n8  = 899 * ITERATIONS;
  687.     n9  = 616 * ITERATIONS;
  688.     n10 =   0 * ITERATIONS;
  689.     n11 =  93 * ITERATIONS;
  690.  
  691. /* MODULE 1:  simple identifiers */
  692.  
  693.     x1 =  1.0;
  694.     x2 = x3 = x4 = -1.0;
  695.  
  696.     for(i = 1; i <= n1; i += 1) {
  697.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  698.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  699.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  700.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  701.     }
  702. #ifdef POUT
  703.     pout(n1, n1, n1, x1, x2, x3, x4);
  704. #endif
  705.  
  706.  
  707. /* MODULE 2:  array elements */
  708.  
  709.     e1[0] =  1.0;
  710.     e1[1] = e1[2] = e1[3] = -1.0;
  711.  
  712.     for (i = 1; i <= n2; i +=1) {
  713.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  714.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  715.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  716.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  717.     }
  718. #ifdef POUT
  719.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  720. #endif
  721.  
  722. /* MODULE 3:  array as parameter */
  723.  
  724.     for (i = 1; i <= n3; i += 1)
  725.         pa_2(e1);
  726. #ifdef POUT
  727.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  728. #endif
  729.  
  730. /* MODULE 4:  conditional jumps */
  731.  
  732.     j = 1;
  733.     for (i = 1; i <= n4; i += 1) {
  734.         if (j == 1)
  735.             j = 2;
  736.         else
  737.             j = 3;
  738.  
  739.         if (j > 2)
  740.             j = 0;
  741.         else
  742.             j = 1;
  743.  
  744.         if (j < 1 )
  745.             j = 1;
  746.         else
  747.             j = 0;
  748.     }
  749. #ifdef POUT
  750.     pout(n4, j, j, x1, x2, x3, x4);
  751. #endif
  752.  
  753. /* MODULE 5:  omitted */
  754.  
  755. /* MODULE 6:  integer arithmetic */
  756.  
  757.     j = 1;
  758.     k = 2;
  759.     l = 3;
  760.  
  761.     for (i = 1; i <= n6; i += 1) {
  762.         j = j * (k - j) * (l -k);
  763.         k = l * k - (l - j) * k;
  764.         l = (l - k) * (k + j);
  765.  
  766.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  767.         e1[k - 2] = j * k * l;
  768.     }
  769. #ifdef POUT
  770.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  771. #endif
  772.  
  773. /* MODULE 7:  trig. functions */
  774.  
  775.     x = y = 0.5;
  776.  
  777.     for(i = 1; i <= n7; i +=1) {
  778.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  779.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  780.     }
  781. #ifdef POUT
  782.     pout(n7, j, k, x, x, y, y);
  783. #endif
  784.  
  785. /* MODULE 8:  procedure calls */
  786.  
  787.     x = y = z = 1.0;
  788.  
  789.     for (i = 1; i <= n8; i +=1)
  790.         p3_2(x, y, &z);
  791. #ifdef POUT
  792.     pout(n8, j, k, x, y, z, z);
  793. #endif
  794.  
  795. /* MODULE9:  array references */
  796.  
  797.     j = 1;
  798.     k = 2;
  799.     l = 3;
  800.  
  801.     e1[0] = 1.0;
  802.     e1[1] = 2.0;
  803.     e1[2] = 3.0;
  804.  
  805.     for(i = 1; i <= n9; i += 1)
  806.         p0_2();
  807. #ifdef POUT
  808.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  809. #endif
  810.  
  811. /* MODULE10:  integer arithmetic */
  812.  
  813.     j = 2;
  814.     k = 3;
  815.  
  816.     for(i = 1; i <= n10; i +=1) {
  817.         j = j + k;
  818.         k = j + k;
  819.         j = k - j;
  820.         k = k - j - j;
  821.     }
  822. #ifdef POUT
  823.     pout(n10, j, k, x1, x2, x3, x4);
  824. #endif
  825.  
  826. /* MODULE11:  standard functions */
  827.  
  828.     x = 0.75;
  829.     for(i = 1; i <= n11; i +=1)
  830.         x = sqrt( exp( log(x) / t1));
  831.  
  832. #ifdef POUT
  833.     pout(n11, j, k, x, x, x, x);
  834. #endif
  835.  
  836. // lgk modifications to record kips and start and times
  837.  
  838. thread_stop_time[1] = GetTickCount();
  839.  
  840. return 0;
  841.  
  842. }
  843.  
  844.  
  845. DWORD thread2()
  846. {
  847.  
  848. double        x1, x2, x3, x4, x, y, z;
  849.  
  850.     /* initialize constants */
  851. thread_start_time[2] = GetTickCount();
  852.  
  853.     t   =   0.499975;
  854.     t1  =   0.50025;
  855.     t2  =   2.0;
  856.  
  857.     /* set values of module weights */
  858.  
  859.     n1  =   0 * ITERATIONS;
  860.     n2  =  12 * ITERATIONS;
  861.     n3  =  14 * ITERATIONS;
  862.     n4  = 345 * ITERATIONS;
  863.     n6  = 210 * ITERATIONS;
  864.     n7  =  32 * ITERATIONS;
  865.     n8  = 899 * ITERATIONS;
  866.     n9  = 616 * ITERATIONS;
  867.     n10 =   0 * ITERATIONS;
  868.     n11 =  93 * ITERATIONS;
  869.  
  870. /* MODULE 1:  simple identifiers */
  871.  
  872.     x1 =  1.0;
  873.     x2 = x3 = x4 = -1.0;
  874.  
  875.     for(i = 1; i <= n1; i += 1) {
  876.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  877.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  878.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  879.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  880.     }
  881. #ifdef POUT
  882.     pout(n1, n1, n1, x1, x2, x3, x4);
  883. #endif
  884.  
  885.  
  886. /* MODULE 2:  array elements */
  887.  
  888.     e1[0] =  1.0;
  889.     e1[1] = e1[2] = e1[3] = -1.0;
  890.  
  891.     for (i = 1; i <= n2; i +=1) {
  892.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  893.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  894.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  895.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  896.     }
  897. #ifdef POUT
  898.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  899. #endif
  900.  
  901. /* MODULE 3:  array as parameter */
  902.  
  903.     for (i = 1; i <= n3; i += 1)
  904.         pa_3(e1);
  905. #ifdef POUT
  906.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  907. #endif
  908.  
  909. /* MODULE 4:  conditional jumps */
  910.  
  911.     j = 1;
  912.     for (i = 1; i <= n4; i += 1) {
  913.         if (j == 1)
  914.             j = 2;
  915.         else
  916.             j = 3;
  917.  
  918.         if (j > 2)
  919.             j = 0;
  920.         else
  921.             j = 1;
  922.  
  923.         if (j < 1 )
  924.             j = 1;
  925.         else
  926.             j = 0;
  927.     }
  928. #ifdef POUT
  929.     pout(n4, j, j, x1, x2, x3, x4);
  930. #endif
  931.  
  932. /* MODULE 5:  omitted */
  933.  
  934. /* MODULE 6:  integer arithmetic */
  935.  
  936.     j = 1;
  937.     k = 2;
  938.     l = 3;
  939.  
  940.     for (i = 1; i <= n6; i += 1) {
  941.         j = j * (k - j) * (l -k);
  942.         k = l * k - (l - j) * k;
  943.         l = (l - k) * (k + j);
  944.  
  945.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  946.         e1[k - 2] = j * k * l;
  947.     }
  948. #ifdef POUT
  949.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  950. #endif
  951.  
  952. /* MODULE 7:  trig. functions */
  953.  
  954.     x = y = 0.5;
  955.  
  956.     for(i = 1; i <= n7; i +=1) {
  957.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  958.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  959.     }
  960. #ifdef POUT
  961.     pout(n7, j, k, x, x, y, y);
  962. #endif
  963.  
  964. /* MODULE 8:  procedure calls */
  965.  
  966.     x = y = z = 1.0;
  967.  
  968.     for (i = 1; i <= n8; i +=1)
  969.         p3_3(x, y, &z);
  970. #ifdef POUT
  971.     pout(n8, j, k, x, y, z, z);
  972. #endif
  973.  
  974. /* MODULE9:  array references */
  975.  
  976.     j = 1;
  977.     k = 2;
  978.     l = 3;
  979.  
  980.     e1[0] = 1.0;
  981.     e1[1] = 2.0;
  982.     e1[2] = 3.0;
  983.  
  984.     for(i = 1; i <= n9; i += 1)
  985.         p0_3();
  986. #ifdef POUT
  987.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  988. #endif
  989.  
  990. /* MODULE10:  integer arithmetic */
  991.  
  992.     j = 2;
  993.     k = 3;
  994.  
  995.     for(i = 1; i <= n10; i +=1) {
  996.         j = j + k;
  997.         k = j + k;
  998.         j = k - j;
  999.         k = k - j - j;
  1000.     }
  1001. #ifdef POUT
  1002.     pout(n10, j, k, x1, x2, x3, x4);
  1003. #endif
  1004.  
  1005. /* MODULE11:  standard functions */
  1006.  
  1007.     x = 0.75;
  1008.     for(i = 1; i <= n11; i +=1)
  1009.         x = sqrt( exp( log(x) / t1));
  1010.  
  1011. #ifdef POUT
  1012.     pout(n11, j, k, x, x, x, x);
  1013. #endif
  1014.  
  1015. // lgk modifications to record kips and start and times
  1016.  
  1017. thread_stop_time[2] = GetTickCount();
  1018.  
  1019. return 0;
  1020.  
  1021. }
  1022.  
  1023.  
  1024. DWORD thread3()
  1025. {
  1026.  
  1027. double        x1, x2, x3, x4, x, y, z;
  1028.  
  1029.     /* initialize constants */
  1030. thread_start_time[3] = GetTickCount();
  1031.  
  1032.     t   =   0.499975;
  1033.     t1  =   0.50025;
  1034.     t2  =   2.0;
  1035.  
  1036.     /* set values of module weights */
  1037.  
  1038.     n1  =   0 * ITERATIONS;
  1039.     n2  =  12 * ITERATIONS;
  1040.     n3  =  14 * ITERATIONS;
  1041.     n4  = 345 * ITERATIONS;
  1042.     n6  = 210 * ITERATIONS;
  1043.     n7  =  32 * ITERATIONS;
  1044.     n8  = 899 * ITERATIONS;
  1045.     n9  = 616 * ITERATIONS;
  1046.     n10 =   0 * ITERATIONS;
  1047.     n11 =  93 * ITERATIONS;
  1048.  
  1049. /* MODULE 1:  simple identifiers */
  1050.  
  1051.     x1 =  1.0;
  1052.     x2 = x3 = x4 = -1.0;
  1053.  
  1054.     for(i = 1; i <= n1; i += 1) {
  1055.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  1056.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  1057.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  1058.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  1059.     }
  1060. #ifdef POUT
  1061.     pout(n1, n1, n1, x1, x2, x3, x4);
  1062. #endif
  1063.  
  1064.  
  1065. /* MODULE 2:  array elements */
  1066.  
  1067.     e1[0] =  1.0;
  1068.     e1[1] = e1[2] = e1[3] = -1.0;
  1069.  
  1070.     for (i = 1; i <= n2; i +=1) {
  1071.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  1072.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  1073.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  1074.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  1075.     }
  1076. #ifdef POUT
  1077.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  1078. #endif
  1079.  
  1080. /* MODULE 3:  array as parameter */
  1081.  
  1082.     for (i = 1; i <= n3; i += 1)
  1083.         pa_4(e1);
  1084. #ifdef POUT
  1085.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  1086. #endif
  1087.  
  1088. /* MODULE 4:  conditional jumps */
  1089.  
  1090.     j = 1;
  1091.     for (i = 1; i <= n4; i += 1) {
  1092.         if (j == 1)
  1093.             j = 2;
  1094.         else
  1095.             j = 3;
  1096.  
  1097.         if (j > 2)
  1098.             j = 0;
  1099.         else
  1100.             j = 1;
  1101.  
  1102.         if (j < 1 )
  1103.             j = 1;
  1104.         else
  1105.             j = 0;
  1106.     }
  1107. #ifdef POUT
  1108.     pout(n4, j, j, x1, x2, x3, x4);
  1109. #endif
  1110.  
  1111. /* MODULE 5:  omitted */
  1112.  
  1113. /* MODULE 6:  integer arithmetic */
  1114.  
  1115.     j = 1;
  1116.     k = 2;
  1117.     l = 3;
  1118.  
  1119.     for (i = 1; i <= n6; i += 1) {
  1120.         j = j * (k - j) * (l -k);
  1121.         k = l * k - (l - j) * k;
  1122.         l = (l - k) * (k + j);
  1123.  
  1124.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  1125.         e1[k - 2] = j * k * l;
  1126.     }
  1127. #ifdef POUT
  1128.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  1129. #endif
  1130.  
  1131. /* MODULE 7:  trig. functions */
  1132.  
  1133.     x = y = 0.5;
  1134.  
  1135.     for(i = 1; i <= n7; i +=1) {
  1136.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  1137.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  1138.     }
  1139. #ifdef POUT
  1140.     pout(n7, j, k, x, x, y, y);
  1141. #endif
  1142.  
  1143. /* MODULE 8:  procedure calls */
  1144.  
  1145.     x = y = z = 1.0;
  1146.  
  1147.     for (i = 1; i <= n8; i +=1)
  1148.         p3_4(x, y, &z);
  1149. #ifdef POUT
  1150.     pout(n8, j, k, x, y, z, z);
  1151. #endif
  1152.  
  1153. /* MODULE9:  array references */
  1154.  
  1155.     j = 1;
  1156.     k = 2;
  1157.     l = 3;
  1158.  
  1159.     e1[0] = 1.0;
  1160.     e1[1] = 2.0;
  1161.     e1[2] = 3.0;
  1162.  
  1163.     for(i = 1; i <= n9; i += 1)
  1164.         p0_4();
  1165. #ifdef POUT
  1166.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  1167. #endif
  1168.  
  1169. /* MODULE10:  integer arithmetic */
  1170.  
  1171.     j = 2;
  1172.     k = 3;
  1173.  
  1174.     for(i = 1; i <= n10; i +=1) {
  1175.         j = j + k;
  1176.         k = j + k;
  1177.         j = k - j;
  1178.         k = k - j - j;
  1179.     }
  1180. #ifdef POUT
  1181.     pout(n10, j, k, x1, x2, x3, x4);
  1182. #endif
  1183.  
  1184. /* MODULE11:  standard functions */
  1185.  
  1186.     x = 0.75;
  1187.     for(i = 1; i <= n11; i +=1)
  1188.         x = sqrt( exp( log(x) / t1));
  1189.  
  1190. #ifdef POUT
  1191.     pout(n11, j, k, x, x, x, x);
  1192. #endif
  1193.  
  1194. // lgk modifications to record kips and start and times
  1195.  
  1196. thread_stop_time[3] = GetTickCount();
  1197.  
  1198. return 0;
  1199.  
  1200. }
  1201.  
  1202.  
  1203. DWORD thread4()
  1204. {
  1205.  
  1206. double        x1, x2, x3, x4, x, y, z;
  1207.  
  1208.     /* initialize constants */
  1209. thread_start_time[4] = GetTickCount();
  1210.  
  1211.     t   =   0.499975;
  1212.     t1  =   0.50025;
  1213.     t2  =   2.0;
  1214.  
  1215.     /* set values of module weights */
  1216.  
  1217.     n1  =   0 * ITERATIONS;
  1218.     n2  =  12 * ITERATIONS;
  1219.     n3  =  14 * ITERATIONS;
  1220.     n4  = 345 * ITERATIONS;
  1221.     n6  = 210 * ITERATIONS;
  1222.     n7  =  32 * ITERATIONS;
  1223.     n8  = 899 * ITERATIONS;
  1224.     n9  = 616 * ITERATIONS;
  1225.     n10 =   0 * ITERATIONS;
  1226.     n11 =  93 * ITERATIONS;
  1227.  
  1228. /* MODULE 1:  simple identifiers */
  1229.  
  1230.     x1 =  1.0;
  1231.     x2 = x3 = x4 = -1.0;
  1232.  
  1233.     for(i = 1; i <= n1; i += 1) {
  1234.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  1235.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  1236.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  1237.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  1238.     }
  1239. #ifdef POUT
  1240.     pout(n1, n1, n1, x1, x2, x3, x4);
  1241. #endif
  1242.  
  1243.  
  1244. /* MODULE 2:  array elements */
  1245.  
  1246.     e1[0] =  1.0;
  1247.     e1[1] = e1[2] = e1[3] = -1.0;
  1248.  
  1249.     for (i = 1; i <= n2; i +=1) {
  1250.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  1251.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  1252.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  1253.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  1254.     }
  1255. #ifdef POUT
  1256.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  1257. #endif
  1258.  
  1259. /* MODULE 3:  array as parameter */
  1260.  
  1261.     for (i = 1; i <= n3; i += 1)
  1262.         pa_5(e1);
  1263. #ifdef POUT
  1264.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  1265. #endif
  1266.  
  1267. /* MODULE 4:  conditional jumps */
  1268.  
  1269.     j = 1;
  1270.     for (i = 1; i <= n4; i += 1) {
  1271.         if (j == 1)
  1272.             j = 2;
  1273.         else
  1274.             j = 3;
  1275.  
  1276.         if (j > 2)
  1277.             j = 0;
  1278.         else
  1279.             j = 1;
  1280.  
  1281.         if (j < 1 )
  1282.             j = 1;
  1283.         else
  1284.             j = 0;
  1285.     }
  1286. #ifdef POUT
  1287.     pout(n4, j, j, x1, x2, x3, x4);
  1288. #endif
  1289.  
  1290. /* MODULE 5:  omitted */
  1291.  
  1292. /* MODULE 6:  integer arithmetic */
  1293.  
  1294.     j = 1;
  1295.     k = 2;
  1296.     l = 3;
  1297.  
  1298.     for (i = 1; i <= n6; i += 1) {
  1299.         j = j * (k - j) * (l -k);
  1300.         k = l * k - (l - j) * k;
  1301.         l = (l - k) * (k + j);
  1302.  
  1303.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  1304.         e1[k - 2] = j * k * l;
  1305.     }
  1306. #ifdef POUT
  1307.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  1308. #endif
  1309.  
  1310. /* MODULE 7:  trig. functions */
  1311.  
  1312.     x = y = 0.5;
  1313.  
  1314.     for(i = 1; i <= n7; i +=1) {
  1315.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  1316.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  1317.     }
  1318. #ifdef POUT
  1319.     pout(n7, j, k, x, x, y, y);
  1320. #endif
  1321.  
  1322. /* MODULE 8:  procedure calls */
  1323.  
  1324.     x = y = z = 1.0;
  1325.  
  1326.     for (i = 1; i <= n8; i +=1)
  1327.         p3_5(x, y, &z);
  1328. #ifdef POUT
  1329.     pout(n8, j, k, x, y, z, z);
  1330. #endif
  1331.  
  1332. /* MODULE9:  array references */
  1333.  
  1334.     j = 1;
  1335.     k = 2;
  1336.     l = 3;
  1337.  
  1338.     e1[0] = 1.0;
  1339.     e1[1] = 2.0;
  1340.     e1[2] = 3.0;
  1341.  
  1342.     for(i = 1; i <= n9; i += 1)
  1343.         p0_5();
  1344. #ifdef POUT
  1345.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  1346. #endif
  1347.  
  1348. /* MODULE10:  integer arithmetic */
  1349.  
  1350.     j = 2;
  1351.     k = 3;
  1352.  
  1353.     for(i = 1; i <= n10; i +=1) {
  1354.         j = j + k;
  1355.         k = j + k;
  1356.         j = k - j;
  1357.         k = k - j - j;
  1358.     }
  1359. #ifdef POUT
  1360.     pout(n10, j, k, x1, x2, x3, x4);
  1361. #endif
  1362.  
  1363. /* MODULE11:  standard functions */
  1364.  
  1365.     x = 0.75;
  1366.     for(i = 1; i <= n11; i +=1)
  1367.         x = sqrt( exp( log(x) / t1));
  1368.  
  1369. #ifdef POUT
  1370.     pout(n11, j, k, x, x, x, x);
  1371. #endif
  1372.  
  1373. // lgk modifications to record kips and start and times
  1374.  
  1375. thread_stop_time[4] = GetTickCount();
  1376.  
  1377. return 0;
  1378.  
  1379. }
  1380.  
  1381.  
  1382. DWORD thread5()
  1383. {
  1384.  
  1385. double        x1, x2, x3, x4, x, y, z;
  1386.  
  1387.     /* initialize constants */
  1388. thread_start_time[5] = GetTickCount();
  1389.  
  1390.     t   =   0.499975;
  1391.     t1  =   0.50025;
  1392.     t2  =   2.0;
  1393.  
  1394.     /* set values of module weights */
  1395.  
  1396.     n1  =   0 * ITERATIONS;
  1397.     n2  =  12 * ITERATIONS;
  1398.     n3  =  14 * ITERATIONS;
  1399.     n4  = 345 * ITERATIONS;
  1400.     n6  = 210 * ITERATIONS;
  1401.     n7  =  32 * ITERATIONS;
  1402.     n8  = 899 * ITERATIONS;
  1403.     n9  = 616 * ITERATIONS;
  1404.     n10 =   0 * ITERATIONS;
  1405.     n11 =  93 * ITERATIONS;
  1406.  
  1407. /* MODULE 1:  simple identifiers */
  1408.  
  1409.     x1 =  1.0;
  1410.     x2 = x3 = x4 = -1.0;
  1411.  
  1412.     for(i = 1; i <= n1; i += 1) {
  1413.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  1414.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  1415.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  1416.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  1417.     }
  1418. #ifdef POUT
  1419.     pout(n1, n1, n1, x1, x2, x3, x4);
  1420. #endif
  1421.  
  1422.  
  1423. /* MODULE 2:  array elements */
  1424.  
  1425.     e1[0] =  1.0;
  1426.     e1[1] = e1[2] = e1[3] = -1.0;
  1427.  
  1428.     for (i = 1; i <= n2; i +=1) {
  1429.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  1430.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  1431.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  1432.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  1433.     }
  1434. #ifdef POUT
  1435.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  1436. #endif
  1437.  
  1438. /* MODULE 3:  array as parameter */
  1439.  
  1440.     for (i = 1; i <= n3; i += 1)
  1441.         pa_6(e1);
  1442. #ifdef POUT
  1443.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  1444. #endif
  1445.  
  1446. /* MODULE 4:  conditional jumps */
  1447.  
  1448.     j = 1;
  1449.     for (i = 1; i <= n4; i += 1) {
  1450.         if (j == 1)
  1451.             j = 2;
  1452.         else
  1453.             j = 3;
  1454.  
  1455.         if (j > 2)
  1456.             j = 0;
  1457.         else
  1458.             j = 1;
  1459.  
  1460.         if (j < 1 )
  1461.             j = 1;
  1462.         else
  1463.             j = 0;
  1464.     }
  1465. #ifdef POUT
  1466.     pout(n4, j, j, x1, x2, x3, x4);
  1467. #endif
  1468.  
  1469. /* MODULE 5:  omitted */
  1470.  
  1471. /* MODULE 6:  integer arithmetic */
  1472.  
  1473.     j = 1;
  1474.     k = 2;
  1475.     l = 3;
  1476.  
  1477.     for (i = 1; i <= n6; i += 1) {
  1478.         j = j * (k - j) * (l -k);
  1479.         k = l * k - (l - j) * k;
  1480.         l = (l - k) * (k + j);
  1481.  
  1482.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  1483.         e1[k - 2] = j * k * l;
  1484.     }
  1485. #ifdef POUT
  1486.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  1487. #endif
  1488.  
  1489. /* MODULE 7:  trig. functions */
  1490.  
  1491.     x = y = 0.5;
  1492.  
  1493.     for(i = 1; i <= n7; i +=1) {
  1494.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  1495.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  1496.     }
  1497. #ifdef POUT
  1498.     pout(n7, j, k, x, x, y, y);
  1499. #endif
  1500.  
  1501. /* MODULE 8:  procedure calls */
  1502.  
  1503.     x = y = z = 1.0;
  1504.  
  1505.     for (i = 1; i <= n8; i +=1)
  1506.         p3_6(x, y, &z);
  1507. #ifdef POUT
  1508.     pout(n8, j, k, x, y, z, z);
  1509. #endif
  1510.  
  1511. /* MODULE9:  array references */
  1512.  
  1513.     j = 1;
  1514.     k = 2;
  1515.     l = 3;
  1516.  
  1517.     e1[0] = 1.0;
  1518.     e1[1] = 2.0;
  1519.     e1[2] = 3.0;
  1520.  
  1521.     for(i = 1; i <= n9; i += 1)
  1522.         p0_6();
  1523. #ifdef POUT
  1524.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  1525. #endif
  1526.  
  1527. /* MODULE10:  integer arithmetic */
  1528.  
  1529.     j = 2;
  1530.     k = 3;
  1531.  
  1532.     for(i = 1; i <= n10; i +=1) {
  1533.         j = j + k;
  1534.         k = j + k;
  1535.         j = k - j;
  1536.         k = k - j - j;
  1537.     }
  1538. #ifdef POUT
  1539.     pout(n10, j, k, x1, x2, x3, x4);
  1540. #endif
  1541.  
  1542. /* MODULE11:  standard functions */
  1543.  
  1544.     x = 0.75;
  1545.     for(i = 1; i <= n11; i +=1)
  1546.         x = sqrt( exp( log(x) / t1));
  1547.  
  1548. #ifdef POUT
  1549.     pout(n11, j, k, x, x, x, x);
  1550. #endif
  1551.  
  1552. // lgk modifications to record kips and start and times
  1553.  
  1554. thread_stop_time[5] = GetTickCount();
  1555.  
  1556. return 0;
  1557.  
  1558. }
  1559.  
  1560.  
  1561. DWORD thread6()
  1562. {
  1563.  
  1564. double        x1, x2, x3, x4, x, y, z;
  1565.  
  1566.     /* initialize constants */
  1567. thread_start_time[6] = GetTickCount();
  1568.  
  1569.     t   =   0.499975;
  1570.     t1  =   0.50025;
  1571.     t2  =   2.0;
  1572.  
  1573.     /* set values of module weights */
  1574.  
  1575.     n1  =   0 * ITERATIONS;
  1576.     n2  =  12 * ITERATIONS;
  1577.     n3  =  14 * ITERATIONS;
  1578.     n4  = 345 * ITERATIONS;
  1579.     n6  = 210 * ITERATIONS;
  1580.     n7  =  32 * ITERATIONS;
  1581.     n8  = 899 * ITERATIONS;
  1582.     n9  = 616 * ITERATIONS;
  1583.     n10 =   0 * ITERATIONS;
  1584.     n11 =  93 * ITERATIONS;
  1585.  
  1586. /* MODULE 1:  simple identifiers */
  1587.  
  1588.     x1 =  1.0;
  1589.     x2 = x3 = x4 = -1.0;
  1590.  
  1591.     for(i = 1; i <= n1; i += 1) {
  1592.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  1593.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  1594.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  1595.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  1596.     }
  1597. #ifdef POUT
  1598.     pout(n1, n1, n1, x1, x2, x3, x4);
  1599. #endif
  1600.  
  1601.  
  1602. /* MODULE 2:  array elements */
  1603.  
  1604.     e1[0] =  1.0;
  1605.     e1[1] = e1[2] = e1[3] = -1.0;
  1606.  
  1607.     for (i = 1; i <= n2; i +=1) {
  1608.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  1609.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  1610.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  1611.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  1612.     }
  1613. #ifdef POUT
  1614.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  1615. #endif
  1616.  
  1617. /* MODULE 3:  array as parameter */
  1618.  
  1619.     for (i = 1; i <= n3; i += 1)
  1620.         pa_7(e1);
  1621. #ifdef POUT
  1622.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  1623. #endif
  1624.  
  1625. /* MODULE 4:  conditional jumps */
  1626.  
  1627.     j = 1;
  1628.     for (i = 1; i <= n4; i += 1) {
  1629.         if (j == 1)
  1630.             j = 2;
  1631.         else
  1632.             j = 3;
  1633.  
  1634.         if (j > 2)
  1635.             j = 0;
  1636.         else
  1637.             j = 1;
  1638.  
  1639.         if (j < 1 )
  1640.             j = 1;
  1641.         else
  1642.             j = 0;
  1643.     }
  1644. #ifdef POUT
  1645.     pout(n4, j, j, x1, x2, x3, x4);
  1646. #endif
  1647.  
  1648. /* MODULE 5:  omitted */
  1649.  
  1650. /* MODULE 6:  integer arithmetic */
  1651.  
  1652.     j = 1;
  1653.     k = 2;
  1654.     l = 3;
  1655.  
  1656.     for (i = 1; i <= n6; i += 1) {
  1657.         j = j * (k - j) * (l -k);
  1658.         k = l * k - (l - j) * k;
  1659.         l = (l - k) * (k + j);
  1660.  
  1661.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  1662.         e1[k - 2] = j * k * l;
  1663.     }
  1664. #ifdef POUT
  1665.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  1666. #endif
  1667.  
  1668. /* MODULE 7:  trig. functions */
  1669.  
  1670.     x = y = 0.5;
  1671.  
  1672.     for(i = 1; i <= n7; i +=1) {
  1673.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  1674.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  1675.     }
  1676. #ifdef POUT
  1677.     pout(n7, j, k, x, x, y, y);
  1678. #endif
  1679.  
  1680. /* MODULE 8:  procedure calls */
  1681.  
  1682.     x = y = z = 1.0;
  1683.  
  1684.     for (i = 1; i <= n8; i +=1)
  1685.         p3_7(x, y, &z);
  1686. #ifdef POUT
  1687.     pout(n8, j, k, x, y, z, z);
  1688. #endif
  1689.  
  1690. /* MODULE9:  array references */
  1691.  
  1692.     j = 1;
  1693.     k = 2;
  1694.     l = 3;
  1695.  
  1696.     e1[0] = 1.0;
  1697.     e1[1] = 2.0;
  1698.     e1[2] = 3.0;
  1699.  
  1700.     for(i = 1; i <= n9; i += 1)
  1701.         p0_7();
  1702. #ifdef POUT
  1703.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  1704. #endif
  1705.  
  1706. /* MODULE10:  integer arithmetic */
  1707.  
  1708.     j = 2;
  1709.     k = 3;
  1710.  
  1711.     for(i = 1; i <= n10; i +=1) {
  1712.         j = j + k;
  1713.         k = j + k;
  1714.         j = k - j;
  1715.         k = k - j - j;
  1716.     }
  1717. #ifdef POUT
  1718.     pout(n10, j, k, x1, x2, x3, x4);
  1719. #endif
  1720.  
  1721. /* MODULE11:  standard functions */
  1722.  
  1723.     x = 0.75;
  1724.     for(i = 1; i <= n11; i +=1)
  1725.         x = sqrt( exp( log(x) / t1));
  1726.  
  1727. #ifdef POUT
  1728.     pout(n11, j, k, x, x, x, x);
  1729. #endif
  1730.  
  1731. // lgk modifications to record kips and start and times
  1732.  
  1733. thread_stop_time[6] = GetTickCount();
  1734.  
  1735. return 0;
  1736.  
  1737. }
  1738.  
  1739.  
  1740. DWORD thread7()
  1741. {
  1742.  
  1743. double        x1, x2, x3, x4, x, y, z;
  1744.  
  1745.     /* initialize constants */
  1746. thread_start_time[7] = GetTickCount();
  1747.  
  1748.     t   =   0.499975;
  1749.     t1  =   0.50025;
  1750.     t2  =   2.0;
  1751.  
  1752.     /* set values of module weights */
  1753.  
  1754.     n1  =   0 * ITERATIONS;
  1755.     n2  =  12 * ITERATIONS;
  1756.     n3  =  14 * ITERATIONS;
  1757.     n4  = 345 * ITERATIONS;
  1758.     n6  = 210 * ITERATIONS;
  1759.     n7  =  32 * ITERATIONS;
  1760.     n8  = 899 * ITERATIONS;
  1761.     n9  = 616 * ITERATIONS;
  1762.     n10 =   0 * ITERATIONS;
  1763.     n11 =  93 * ITERATIONS;
  1764.  
  1765. /* MODULE 1:  simple identifiers */
  1766.  
  1767.     x1 =  1.0;
  1768.     x2 = x3 = x4 = -1.0;
  1769.  
  1770.     for(i = 1; i <= n1; i += 1) {
  1771.         x1 = ( x1 + x2 + x3 - x4 ) * t;
  1772.         x2 = ( x1 + x2 - x3 - x4 ) * t;
  1773.         x3 = ( x1 - x2 + x3 + x4 ) * t;
  1774.         x4 = (-x1 + x2 + x3 + x4 ) * t;
  1775.     }
  1776. #ifdef POUT
  1777.     pout(n1, n1, n1, x1, x2, x3, x4);
  1778. #endif
  1779.  
  1780.  
  1781. /* MODULE 2:  array elements */
  1782.  
  1783.     e1[0] =  1.0;
  1784.     e1[1] = e1[2] = e1[3] = -1.0;
  1785.  
  1786.     for (i = 1; i <= n2; i +=1) {
  1787.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  1788.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  1789.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  1790.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  1791.     }
  1792. #ifdef POUT
  1793.     pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  1794. #endif
  1795.  
  1796. /* MODULE 3:  array as parameter */
  1797.  
  1798.     for (i = 1; i <= n3; i += 1)
  1799.         pa_8(e1);
  1800. #ifdef POUT
  1801.     pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  1802. #endif
  1803.  
  1804. /* MODULE 4:  conditional jumps */
  1805.  
  1806.     j = 1;
  1807.     for (i = 1; i <= n4; i += 1) {
  1808.         if (j == 1)
  1809.             j = 2;
  1810.         else
  1811.             j = 3;
  1812.  
  1813.         if (j > 2)
  1814.             j = 0;
  1815.         else
  1816.             j = 1;
  1817.  
  1818.         if (j < 1 )
  1819.             j = 1;
  1820.         else
  1821.             j = 0;
  1822.     }
  1823. #ifdef POUT
  1824.     pout(n4, j, j, x1, x2, x3, x4);
  1825. #endif
  1826.  
  1827. /* MODULE 5:  omitted */
  1828.  
  1829. /* MODULE 6:  integer arithmetic */
  1830.  
  1831.     j = 1;
  1832.     k = 2;
  1833.     l = 3;
  1834.  
  1835.     for (i = 1; i <= n6; i += 1) {
  1836.         j = j * (k - j) * (l -k);
  1837.         k = l * k - (l - j) * k;
  1838.         l = (l - k) * (k + j);
  1839.  
  1840.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  1841.         e1[k - 2] = j * k * l;
  1842.     }
  1843. #ifdef POUT
  1844.     pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  1845. #endif
  1846.  
  1847. /* MODULE 7:  trig. functions */
  1848.  
  1849.     x = y = 0.5;
  1850.  
  1851.     for(i = 1; i <= n7; i +=1) {
  1852.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  1853.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  1854.     }
  1855. #ifdef POUT
  1856.     pout(n7, j, k, x, x, y, y);
  1857. #endif
  1858.  
  1859. /* MODULE 8:  procedure calls */
  1860.  
  1861.     x = y = z = 1.0;
  1862.  
  1863.     for (i = 1; i <= n8; i +=1)
  1864.         p3_8(x, y, &z);
  1865. #ifdef POUT
  1866.     pout(n8, j, k, x, y, z, z);
  1867. #endif
  1868.  
  1869. /* MODULE9:  array references */
  1870.  
  1871.     j = 1;
  1872.     k = 2;
  1873.     l = 3;
  1874.  
  1875.     e1[0] = 1.0;
  1876.     e1[1] = 2.0;
  1877.     e1[2] = 3.0;
  1878.  
  1879.     for(i = 1; i <= n9; i += 1)
  1880.         p0_8();
  1881. #ifdef POUT
  1882.     pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  1883. #endif
  1884.  
  1885. /* MODULE10:  integer arithmetic */
  1886.  
  1887.     j = 2;
  1888.     k = 3;
  1889.  
  1890.     for(i = 1; i <= n10; i +=1) {
  1891.         j = j + k;
  1892.         k = j + k;
  1893.         j = k - j;
  1894.         k = k - j - j;
  1895.     }
  1896. #ifdef POUT
  1897.     pout(n10, j, k, x1, x2, x3, x4);
  1898. #endif
  1899.  
  1900. /* MODULE11:  standard functions */
  1901.  
  1902.     x = 0.75;
  1903.     for(i = 1; i <= n11; i +=1)
  1904.         x = sqrt( exp( log(x) / t1));
  1905.  
  1906. #ifdef POUT
  1907.     pout(n11, j, k, x, x, x, x);
  1908. #endif
  1909.  
  1910. // lgk modifications to record kips and start and times
  1911.  
  1912. thread_stop_time[7] = GetTickCount();
  1913. return 0;
  1914.  
  1915. }
  1916.  
  1917.  
  1918. /* ----------------------------------------------------------- */
  1919.  
  1920. void report_results(threadcount)
  1921.   int threadcount;
  1922.   {
  1923.  
  1924.   DWORD totaltime = 0;
  1925.   DWORD localtime = 0;
  1926.   double totalcount = 0;
  1927.   double localcount = 0;
  1928.   int i;
  1929.  
  1930.    
  1931.      printf("Parallel Whetstone results with %d thread(s).\n",threadcount);
  1932.      printf("______________________________________________________________\n\n");
  1933.  
  1934.      for (i=0; i<threadcount; i++)
  1935.        {
  1936.         printf("Thread %d ---->\n",i);
  1937.         printf("                Start time = %u End time = %u \n",thread_start_time[i],
  1938.                 thread_stop_time[i]);
  1939.         
  1940.         localtime = thread_stop_time[i] - thread_start_time[i];
  1941.         localcount = ITERATIONS*100000; // 10 million if iter = 100
  1942.  
  1943.         printf("                Total time = %u Milliseconds, Operations = %.0lf \n",localtime,localcount);
  1944.         printf("                Whetstone Ops/Second = %10.4lf \n",(double)(localcount / (double)localtime) * (double)1000);
  1945.         fflush(stdout);
  1946.  
  1947.         totaltime = stoptime - starttime;
  1948.         totalcount = totalcount + localcount;
  1949.  
  1950.         }
  1951.  
  1952.       // now do overall totals
  1953.  
  1954.  
  1955.       printf("Overall Total time = %u Operations = %.0lf \n",totaltime,totalcount);
  1956.       printf("Overall Whetstone Ops/Second = %10.4lf \n",(double)(totalcount / (double)totaltime) * (double)1000);
  1957.           fflush(stdout);        
  1958.   }
  1959.  
  1960. /* --------------------------------------------------------------------- */
  1961.  
  1962.  
  1963. /* --------------------------------------------------------------------- */
  1964.  
  1965.  
  1966. void main(argc,argv)
  1967. int argc;
  1968. char **argv;
  1969.  
  1970. {
  1971.    int current_arg = 1;
  1972.    BOOLEAN more_args = TRUE;
  1973.    BOOLEAN done = FALSE;
  1974.    int i;
  1975.    int threadcount = 1;
  1976.    DWORD dwWaitStatus = 0;
  1977.  
  1978.     if (argc > 1)
  1979.      {
  1980.    /* process arguments */
  1981.    if (argv[current_arg][0] != '-')
  1982.      {
  1983.       printf("Illegal parms \n");
  1984.       fflush(stdout);
  1985.       exit(1);
  1986.      }
  1987.    else
  1988.         
  1989.     do 
  1990.      {
  1991.       /* get the first one and if it doesn't start with a - we have a problem */
  1992.         
  1993.        switch (argv[current_arg][1])
  1994.            {
  1995.                  
  1996.                   // assign paffin value 
  1997.                   case 'v':
  1998.                   if (argc < (current_arg + 3))
  1999.                     {
  2000.                       printf("ERROR: Two Parameters needed for Affinity assignment Thread followed by value \n");
  2001.                       fflush(stdout);
  2002.                       exit(1);
  2003.                     }
  2004.                    else
  2005.                      {
  2006.                     
  2007.                         int tid = atoi(argv[current_arg + 1]);
  2008.                         DWORD affin = (DWORD)atol(argv[current_arg + 2]);
  2009.                         int i = 0;
  2010.  
  2011.                         if ((affin < 0x0001) || (affin > 0x01FF))
  2012.                           {
  2013.                            printf("ERROR: Affinity value must be between 0x0001 and 0x01FF. \n");
  2014.                            fflush(stdout);
  2015.                            exit(1);
  2016.                           }
  2017.  
  2018.                         
  2019.                         if (strncmp(argv[current_arg + 1],"*",1) == 0)
  2020.                            {
  2021.                                 for (i=0; i<maxthreads; i++)
  2022.                                   {
  2023.                                    paffinarray[i] = affin;
  2024.                                  assignedpaffin[i] = TRUE;
  2025.                                 }
  2026.                            }
  2027.  
  2028.                         else if ((tid <1) || (tid > 8))
  2029.                          {
  2030.                            printf("ERROR: Thread value must be between 1 and 8. \n");
  2031.                            fflush(stdout);
  2032.                            exit(1);
  2033.                           }
  2034.                         else // only affin 1 thread 
  2035.                           {
  2036.                            paffinarray[tid] = affin;
  2037.                            assignedpaffin[tid] = TRUE;
  2038.                           }
  2039.                                 
  2040.                        current_arg = current_arg + 2;
  2041.                     }
  2042.                    break;
  2043.  
  2044.                  case 'i':
  2045.                   if (argc < (current_arg + 2))
  2046.                     {
  2047.                       printf("ERROR: Parameter needed for iterations value. \n");
  2048.                       fflush(stdout);
  2049.                       exit(1);
  2050.                     }
  2051.                    else
  2052.                      {
  2053.                         ITERATIONS = atoi(argv[current_arg + 1]);
  2054.                         if ((ITERATIONS <10) || (ITERATIONS > 10000))
  2055.                          {
  2056.                            printf("ERROR: Iteration value must be between 10 and 10000 \n");
  2057.                            fflush(stdout);
  2058.                            exit(1);
  2059.                           }
  2060.                         else ++current_arg;
  2061.                     }
  2062.                    break;
  2063.  
  2064.                   case 't':
  2065.                     if (argc < (current_arg + 2))
  2066.                       {
  2067.                         printf("ERROR: Parameter needed for thread count value. \n");
  2068.                         fflush(stdout);
  2069.                         exit(1);
  2070.                       }
  2071.                     else
  2072.                       {
  2073.                        threadcount = atoi(argv[current_arg + 1]);
  2074.                        if ((threadcount <1) || (threadcount > 8))
  2075.                          {
  2076.                            printf("ERROR: Thread count must be between 1 and 8 \n");
  2077.                            fflush(stdout);
  2078.                            exit(1);
  2079.                           }
  2080.                         else ++current_arg;
  2081.                        }
  2082.                       break;
  2083.  
  2084.                     case 'a':
  2085.                       /* set threads to only run on 1 processor this will help determine
  2086.                       if all processors are working if not certain threads will be starved */
  2087.  
  2088.                       setprocessoraffinity = TRUE;
  2089.                       break;
  2090.                       
  2091.                     default: break;
  2092.  
  2093.     } /* end of switch */
  2094.                          
  2095.                
  2096.     ++current_arg;
  2097.     if (current_arg >= argc)
  2098.       more_args = FALSE;
  2099.  
  2100.     } while ((!done) && (more_args));
  2101.    
  2102.    } 
  2103.    /* initialize */
  2104.  
  2105.    
  2106.      printf("NT Whetstone Multiprocessor Benchmark by L. Kahn (C) 1994 \n");
  2107.      printf("__________________________________________________________\n\n");
  2108.      printf("Number of Iterations = %d, Simultaneous Thread(s) = %d.\n",ITERATIONS,threadcount);
  2109.      
  2110.    if (!GetProcessAffinityMask( GetCurrentProcess(), &ProcAff, &SysAff) )
  2111.      {
  2112.        printf( "ERROR: GetProcessAffinityMask failed, defaulting to 1 processor\n\n" );
  2113.        noprocessors = 1;
  2114.        availprocessors = 1;
  2115.      }
  2116.  
  2117.    else
  2118.       {
  2119.         printf( "System Affinity = %x\nProcess affinity = %x\n", SysAff, ProcAff );
  2120.         noprocessors = number_of_processors(SysAff);
  2121.         availprocessors = number_of_processors(ProcAff);
  2122.       
  2123.         printf("Number of processors reported = %d \n",noprocessors);
  2124.         printf("Number of available processors reported = %d \n\n",availprocessors);
  2125.         fflush(stdout);
  2126.       }
  2127.  
  2128.      if (setprocessoraffinity)
  2129.        {
  2130.         int i = 0;
  2131.         printf("Each thread will be assigned to run ONLY on each sequential processor, or\n");
  2132.         printf("on a particular set of processors if the default values have been overridden\n");
  2133.         printf("with the -v option.  If you run more threads than you have processors the \n");
  2134.         printf("additional threads will run on all the processors.\n");
  2135.         printf("By assiging threads to particular processors (that exist in your machine) you \n");
  2136.         printf("can determine if they are working properly.\n");
  2137.         printf("The following threads have the affinity mask overridden with the following values: \n");
  2138.  
  2139.         for (i=0; i<threadcount; i++)
  2140.           {
  2141.            if (assignedpaffin[i])
  2142.              {
  2143.               printf(" -->  Thread %d will be assigned affinity of %ld\n",i,paffinarray[i]);
  2144.               fflush(stdout);
  2145.              }
  2146.            }
  2147.       }  
  2148.  
  2149.     for (i=0; i<threadcount; i++)
  2150.        {
  2151.           thread_start_time[i] = 0;
  2152.           thread_stop_time[i] = 0;
  2153.  
  2154.       switch (i)
  2155.         {
  2156.         
  2157.         case 0:
  2158.        threadhandle[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread0,NULL,CREATE_SUSPENDED,&threadid[0]);
  2159.         break;
  2160.  
  2161.         case 1:
  2162.        threadhandle[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread1,NULL,CREATE_SUSPENDED,&threadid[0]);
  2163.         break;
  2164.  
  2165.         case 2:
  2166.        threadhandle[2] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread2,NULL,CREATE_SUSPENDED,&threadid[0]);
  2167.         break;
  2168.  
  2169.         case 3:
  2170.        threadhandle[3] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread3,NULL,CREATE_SUSPENDED,&threadid[0]);
  2171.         break;
  2172.  
  2173.         case 4:
  2174.        threadhandle[4] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread4,NULL,CREATE_SUSPENDED,&threadid[0]);
  2175.         break;
  2176.  
  2177.         case 5:
  2178.        threadhandle[5] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread5,NULL,CREATE_SUSPENDED,&threadid[0]);
  2179.         break;
  2180.  
  2181.         case 6:
  2182.        threadhandle[6] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread6,NULL,CREATE_SUSPENDED,&threadid[0]);
  2183.         break;
  2184.  
  2185.         case 7:
  2186.        threadhandle[7] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread7,NULL,CREATE_SUSPENDED,&threadid[0]);
  2187.         break;
  2188.     
  2189.       default: break;
  2190.  
  2191.     }            // end of switch
  2192.  
  2193.  } // end of loop
  2194.  
  2195.       /* now that the threads are created start them up */
  2196.       starttime = GetTickCount();
  2197.       for (i=0; i<threadcount; i++)
  2198.         
  2199.         {
  2200.  
  2201.           if (setprocessoraffinity)
  2202.             set_thread_to_processor(threadhandle[i],i+1,i);
  2203.  
  2204.         ResumeThread(threadhandle[i]);
  2205.         
  2206.         }
  2207.  
  2208.      dwWaitStatus = WaitForMultipleObjects(threadcount, threadhandle,TRUE,INFINITE);
  2209.      stoptime = GetTickCount();
  2210.  
  2211.   if (dwWaitStatus == WAIT_FAILED) 
  2212.     {
  2213.      printf("ERROR: Wait for multiple objects failed \n");
  2214.      fflush(stdout);
  2215.      exit(1);
  2216.     }
  2217.   else 
  2218.     {
  2219.      printf("All threads have terminated \n");
  2220.      fflush(stdout);
  2221.     }
  2222.  // now report results
  2223.  
  2224.  report_results(threadcount);
  2225.  
  2226. }
  2227.  
  2228.  
  2229.