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

  1. /* processor benchmark using multiple threads */
  2.  
  3.  
  4.  
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <io.h>
  9. #include <time.h>
  10. #include <process.h>
  11. #include <string.h>
  12. #include <direct.h>
  13. #include <errno.h>
  14.  
  15. #include <fcntl.h>
  16. #include <stdarg.h>
  17. #include <malloc.h>
  18.  
  19. #define maxthreads 8
  20.  
  21. DWORD threadid[maxthreads];
  22. HANDLE threadhandle[maxthreads];
  23. DWORD ProcAff;
  24. DWORD SysAff;
  25. DWORD ThdAff;
  26.  
  27. double float_counters[maxthreads];
  28. double int_counters[maxthreads];
  29. DWORD float_thread_start_time[maxthreads];
  30. DWORD int_thread_start_time[maxthreads];
  31. DWORD float_thread_stop_time[maxthreads];
  32. DWORD int_thread_stop_time[maxthreads];
  33. BOOLEAN setprocessoraffinity = FALSE;
  34. BOOLEAN assignedpaffin[maxthreads] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE };
  35. DWORD paffinarray[maxthreads] = { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  36.  
  37. DWORD intstarttime, intstoptime, floatstarttime, floatstoptime;
  38. int totaltime;
  39.  
  40.  
  41. int noprocessors = 0;
  42. int availprocessors = 0;
  43.  
  44. int number_of_processors(affin)
  45. DWORD affin;
  46.  
  47. {
  48.    
  49.   int numprocessors = 0;
  50.  
  51.   // return the number of processors based on the system affinity dword
  52.   // each bit represents a processor
  53.   // ie 00000011 = 3 = 2 processors 
  54.   if (affin == 0x0001)
  55.     numprocessors = 1;
  56.   else if (affin == 0x0003)
  57.      numprocessors = 2;
  58.   else if (affin == 0x0007)
  59.      numprocessors = 3;
  60.   else if (affin == 0x000F)
  61.      numprocessors = 4;
  62.   else if (affin == 0x001F)
  63.      numprocessors = 5;
  64.   else if (affin == 0x003F)
  65.      numprocessors = 6;
  66.   else if (affin == 0x007F)
  67.      numprocessors = 7;
  68.   else if (affin == 0x00FF)
  69.      numprocessors = 8;
  70.   else if (affin == 0x01FF)
  71.      numprocessors = 9;
  72.   else if (affin = 0x03FF)
  73.      numprocessors == 10;
  74.   else if (affin = 0x07FF)
  75.      numprocessors = 11;
  76.   else if (affin == 0x0FFF)
  77.      numprocessors = 12;
  78.   else if (affin == 0x1FFF)
  79.      numprocessors = 13;
  80.   else if (affin == 0x3FFF)
  81.      numprocessors = 14;
  82.   else if (affin == 0x7FFF)
  83.      numprocessors = 15;
  84.    else if (affin == 0xFFFF)
  85.      numprocessors = 16;
  86.  
  87. else 
  88.  
  89.   {
  90.     printf("ERROR: Illegal processor affinity mask = %x defaulting to 1 processor. \n",affin);
  91.      fflush(stdout);
  92.     numprocessors = 1;
  93.   }
  94.  
  95.   
  96. return numprocessors;
  97.  
  98. }
  99.  
  100. void set_thread_to_processor(thnd,processorno,threadno)
  101. HANDLE thnd;
  102. int processorno;
  103. int threadno;
  104.  
  105. {
  106.  
  107.   DWORD affinmask = 0;
  108.  DWORD ThdAff = 0;
  109.  
  110.  
  111.   // override if set thread individually
  112.   if (assignedpaffin[threadno])
  113.     {
  114.      printf("Setting thread number %d with Affinity mask %ld \n",threadno,paffinarray[threadno]);
  115.      fflush(stdout);
  116.      
  117.      ThdAff = SetThreadAffinityMask( thnd,paffinarray[threadno]);
  118.      if ( !ThdAff )
  119.       printf( "SetThreadAffinityMask(%ld) failed\n\n",paffinarray[threadno] );
  120.      else printf( "Previous thread affinity %x\n\n", ThdAff );
  121.      fflush(stdout);
  122.     }
  123.  
  124.    else
  125.  
  126.     {
  127.  
  128.   printf("Setting thread number %d to only run on processor %d \n",threadno,processorno);
  129.   fflush(stdout);
  130.  
  131.   switch (processorno)
  132.           {
  133.          case 1:
  134.           affinmask = (DWORD)1;
  135.           break;
  136.          
  137.          case 2:
  138.           affinmask = (DWORD)1 << 1;
  139.           break;
  140.          
  141.          case 3:
  142.           affinmask = (DWORD)1 << 2;
  143.           break;
  144.  
  145.          case 4:
  146.           affinmask = (DWORD)1 << 3;
  147.           break;
  148.  
  149.          case 5:
  150.           affinmask = (DWORD)1 << 4;
  151.           break;
  152.  
  153.          case 6:
  154.           affinmask = (DWORD)1 << 5;
  155.           break;
  156.          
  157.          case 7:
  158.           affinmask = (DWORD)1 << 6;
  159.           break;
  160.          
  161.          case 8:
  162.           affinmask = (DWORD)1 << 7;
  163.           break;
  164.  
  165.   
  166.  
  167.          default: printf("Illegal processor number %d in set thread to processor\n",processorno);
  168.                   printf("Defaulting to processor 1 \n");
  169.                   fflush(stdout);
  170.                   affinmask = 1 << 1;
  171.  
  172.  
  173.         }
  174.  
  175.      // now set the thing
  176.  
  177.    ThdAff = SetThreadAffinityMask( thnd,affinmask);
  178. if ( !ThdAff )
  179.       printf( "SetThreadAffinityMask(%ld) failed\n\n",affinmask );
  180.    else printf( "Previous thread affinity %x\n\n", ThdAff );
  181.    fflush(stdout);
  182.   }
  183.  }    
  184.  
  185.  
  186. float flops(threadid)
  187.   float threadid;
  188.  
  189.   {
  190.  
  191.     return ((float)threadid * (float)2.234556);
  192.  
  193.    }
  194.  
  195. int iops(threadid)
  196.   int threadid;
  197.  
  198.   {
  199.  
  200.     return (threadid * 25);
  201.  
  202.    }
  203.  
  204.  
  205. DWORD thread1_float()
  206.  
  207. {
  208.   float a;
  209.   float_counters[1] = 0;
  210.   float_thread_start_time[1] = GetTickCount();
  211.   while (1)
  212.     {
  213.       a = flops(1.1);
  214.       ++float_counters[1];
  215.     }
  216.  return 0;
  217.  
  218. }
  219.  
  220. DWORD thread1_int()
  221.  
  222. {
  223.   int a;
  224.   int_counters[1] = 0;
  225.   int_thread_start_time[1] = GetTickCount();
  226.   while (1)
  227.     {
  228.       a = iops(1);
  229.       ++int_counters[1];
  230.     }
  231.  return 0;
  232.  
  233. }
  234.  
  235.  
  236. DWORD thread2_float()
  237.  
  238. {
  239.   float a;
  240.   float_counters[2] = 0;
  241.   float_thread_start_time[2] = GetTickCount();
  242.   while (1)
  243.     {
  244.       a = flops(1.2);
  245.       ++float_counters[2];
  246.     }
  247.  return 0;
  248.  
  249. }
  250.  
  251. DWORD thread2_int()
  252.  
  253. {
  254.   int a;
  255.   int_counters[2] = 0;
  256.   int_thread_start_time[2] = GetTickCount();
  257.   while (1)
  258.     {
  259.       a = iops(2);
  260.       ++int_counters[2];
  261.     }
  262.  return 0;
  263.  
  264. }
  265.  
  266. DWORD thread3_float()
  267.  
  268. {
  269.   float a;
  270.   float_counters[3] = 0;
  271.   float_thread_start_time[3] = GetTickCount();
  272.   while (1)
  273.     {
  274.       a = flops(1,3);
  275.       ++float_counters[3];
  276.     }
  277.  return 0;
  278.  
  279. }
  280.  
  281. DWORD thread3_int()
  282.  
  283. {
  284.   int a;
  285.   int_counters[3] = 0;
  286.   int_thread_start_time[3] = GetTickCount();
  287.   while (1)
  288.     {
  289.       a = iops(1);
  290.       ++int_counters[3];
  291.     }
  292.  return 0;
  293.  
  294. }
  295.  
  296. DWORD thread4_float()
  297.  
  298. {
  299.   float a;
  300.   float_counters[4] = 0;
  301.   float_thread_start_time[4] = GetTickCount();
  302.   while (1)
  303.     {
  304.       a = flops(1.4);
  305.       ++float_counters[4];
  306.     }
  307.  return 0;
  308.  
  309. }
  310.  
  311. DWORD thread4_int()
  312.  
  313. {
  314.   int a;
  315.   int_counters[4] = 0;
  316.   int_thread_start_time[4] = GetTickCount();
  317.   while (1)
  318.     {
  319.       a = iops(4);
  320.       ++int_counters[4];
  321.     }
  322.  return 0;
  323.  
  324. }
  325.  
  326. DWORD thread5_float()
  327.  
  328. {
  329.   float a;
  330.   float_counters[5] = 0;
  331.   float_thread_start_time[5] = GetTickCount();
  332.   while (1)
  333.     {
  334.       a = flops(1.5);
  335.       ++float_counters[5];
  336.     }
  337.  return 0;
  338.  
  339. }
  340.  
  341. DWORD thread5_int()
  342.  
  343. {
  344.   int a;
  345.   int_counters[5] = 0;
  346.   int_thread_start_time[5] = GetTickCount();
  347.   while (1)
  348.     {
  349.       a = iops(5);
  350.       ++int_counters[5];
  351.     }
  352.  return 0;
  353.  
  354. }
  355.  
  356. DWORD thread6_float()
  357.  
  358. {
  359.   float a;
  360.   float_counters[6] = 0;
  361.   float_thread_start_time[6] = GetTickCount();
  362.   while (1)
  363.     {
  364.       a = flops(1.6);
  365.       ++float_counters[6];
  366.     }
  367.  return 0;
  368.  
  369. }
  370.  
  371. DWORD thread6_int()
  372.  
  373. {
  374.   int a;
  375.   int_counters[6] = 0;
  376.   int_thread_start_time[6] = GetTickCount();
  377.   while (1)
  378.     {
  379.       a = iops(6);
  380.       ++int_counters[6];
  381.     }
  382.  return 0;
  383.  
  384. }
  385.  
  386. DWORD thread7_float()
  387.  
  388. {
  389.   float a;
  390.   float_counters[7] = 0;
  391.   float_thread_start_time[7] = GetTickCount();
  392.   while (1)
  393.     {
  394.       a = flops(1.7);
  395.       ++float_counters[7];
  396.     }
  397.  return 0;
  398. }
  399.  
  400. DWORD thread7_int()
  401.  
  402. {
  403.   int a;
  404.   int_counters[7] = 0;
  405.   int_thread_start_time[7] = GetTickCount();
  406.   while (1)
  407.     {
  408.       a = iops(7);
  409.       ++int_counters[7];
  410.     }
  411.  return 0;
  412.  
  413. }
  414.  
  415. DWORD thread0_float()
  416.  
  417. {
  418.   float a;
  419.   float_counters[0] = 0;
  420.   float_thread_start_time[0] = GetTickCount();
  421.   while (1)
  422.     {
  423.       a = flops(1.0);
  424.       ++float_counters[0];
  425.     }
  426.  return 0;
  427.  
  428. }
  429.  
  430. DWORD thread0_int()
  431.  
  432. {
  433.   int a;
  434.   int_counters[0] = 0;
  435.   int_thread_start_time[0] = GetTickCount();
  436.   while (1)
  437.     {
  438.       a = iops(1);
  439.       ++int_counters[0];
  440.     }
  441.  return 0;
  442.  
  443. }
  444.  
  445. /* ----------------------------------------------------------- */
  446.  
  447. void report_results(timespan,threadcount)
  448.   int timespan;
  449.   int threadcount;
  450.   {
  451.  
  452.   DWORD totaltime = 0;
  453.   DWORD localtime = 0;
  454.   double totalcount = 0;
  455.   double localcount = 0;
  456.   int i;
  457.  
  458.    
  459.      printf("Floating point results for %d milliseconds with %d thread(s).\n",timespan,threadcount);
  460.      printf("______________________________________________________________\n\n");
  461.  
  462.      for (i=0; i<threadcount; i++)
  463.        {
  464.         printf("Thread %d ---->\n",i);
  465.         printf("                Start time = %u End time = %u \n",float_thread_start_time[i],
  466.                 float_thread_stop_time[i]);
  467.         
  468.         localtime = float_thread_stop_time[i] - float_thread_start_time[i];
  469.         localcount = float_counters[i];
  470.  
  471.         printf("                Total time = %u Milliseconds, Operations = %.0lf \n",localtime,localcount);
  472.         printf("                Float Ops/Second = %10.4lf \n",(double)(localcount / (double)localtime) * (double)1000);
  473.         fflush(stdout);
  474.  
  475.         totaltime = floatstoptime - floatstarttime;
  476.         totalcount = totalcount + localcount;
  477.  
  478.         }
  479.  
  480.       // now do overall totals
  481.  
  482.  
  483.       printf("Overall Total time = %u Operations = %.0lf \n",totaltime,totalcount);
  484.       printf("Overall Float Ops Second = %10.4lf \n",(double)(totalcount / (double)totaltime) * (double)1000);
  485.          
  486.  
  487.        // reset totals and do integer ops
  488.        totaltime = 0;
  489.        totalcount = 0;
  490.  
  491.      printf("\n\nInteger results for %d milliseconds with %d thread(s).\n",timespan,threadcount);
  492.      printf("______________________________________________________________\n\n");
  493.  
  494.      for (i=0; i<threadcount; i++)
  495.        {
  496.         printf("Thread %d ---->\n",i);
  497.         printf("                Start time = %u End time = %u \n",int_thread_start_time[i],
  498.                 int_thread_stop_time[i]);
  499.         
  500.         localtime = int_thread_stop_time[i] - int_thread_start_time[i];
  501.         localcount = int_counters[i];
  502.  
  503.         printf("                Total time = %u Operations = %.0lf \n",localtime,localcount);
  504.         printf("                Integer Ops/Second = %10.4lf \n",(double)(localcount / (double)localtime) * (double)1000);
  505.         fflush(stdout);
  506.  
  507.         totaltime = intstoptime - intstarttime;
  508.         totalcount = totalcount + localcount;
  509.  
  510.         }
  511.  
  512.       // now do overall totals
  513.  
  514.        printf("Overall total time = %u Operations = %.0lf \n",totaltime,totalcount);
  515.       printf("Overall Integer Ops Second = %10.4lf \n",(double)(totalcount / (double)totaltime) * (double)1000);
  516.  
  517.       fflush(stdout);        
  518.   }
  519.  
  520. /* --------------------------------------------------------------------- */
  521.  
  522.  
  523. void main(argc,argv)
  524. int argc;
  525. char **argv;
  526.  
  527. {
  528.    int current_arg = 1;
  529.    BOOLEAN more_args = TRUE;
  530.    BOOLEAN done = FALSE;
  531.    int i;
  532.    int threadcount = 1;
  533.  
  534.    // default time is ten seconds
  535.    totaltime = 5000;
  536.    if (argc > 1)
  537.      {
  538.    /* process arguments */
  539.    if (argv[current_arg][0] != '-')
  540.      {
  541.       printf("Illegal parms \n");
  542.       fflush(stdout);
  543.       exit(1);
  544.      }
  545.    else
  546.         
  547.     do 
  548.      {
  549.       /* get the first one and if it doesn't start with a - we have a problem */
  550.         
  551.        switch (argv[current_arg][1])
  552.            {
  553.  
  554.                  // assign paffin value 
  555.                   case 'v':
  556.                   if (argc < (current_arg + 3))
  557.                     {
  558.                       printf("ERROR: Two Parameters needed for Affinity assignment Thread followed by value \n");
  559.                       fflush(stdout);
  560.                       exit(1);
  561.                     }
  562.                    else
  563.                      {
  564.                     
  565.                         int tid = atoi(argv[current_arg + 1]);
  566.                         DWORD affin = (DWORD)atol(argv[current_arg + 2]);
  567.                         int i = 0;
  568.  
  569.                         if ((affin < 0x0001) || (affin > 0x01FF))
  570.                           {
  571.                            printf("ERROR: Affinity value must be between 0x0001 and 0x01FF. \n");
  572.                            fflush(stdout);
  573.                            exit(1);
  574.                           }
  575.  
  576.                         
  577.                         if (strncmp(argv[current_arg + 1],"*",1) == 0)
  578.                            {
  579.                                 for (i=0; i<maxthreads; i++)
  580.                                   {
  581.                                    paffinarray[i] = affin;
  582.                                  assignedpaffin[i] = TRUE;
  583.                                 }
  584.                            }
  585.  
  586.                         else if ((tid <1) || (tid > 8))
  587.                          {
  588.                            printf("ERROR: Thread value must be between 1 and 8. \n");
  589.                            fflush(stdout);
  590.                            exit(1);
  591.                           }
  592.                         else // only affin 1 thread 
  593.                           {
  594.                            paffinarray[tid] = affin;
  595.                            assignedpaffin[tid] = TRUE;
  596.                           }
  597.                                 
  598.                        current_arg = current_arg + 2;
  599.                     }
  600.                    break;
  601.  
  602.                  case 's':
  603.                   if (argc < (current_arg + 2))
  604.                     {
  605.                       printf("ERROR: Parameter needed for time value. \n");
  606.                       fflush(stdout);
  607.                       exit(1);
  608.                     }
  609.                    else
  610.                      {
  611.                         totaltime = atoi(argv[current_arg + 1]);
  612.                         ++current_arg;
  613.                     }
  614.                    break;
  615.  
  616.                   case 't':
  617.                     if (argc < (current_arg + 2))
  618.                       {
  619.                         printf("ERROR: Parameter needed for thread count value. \n");
  620.                         fflush(stdout);
  621.                         exit(1);
  622.                       }
  623.                     else
  624.                       {
  625.                        threadcount = atoi(argv[current_arg + 1]);
  626.                        if ((threadcount <1) || (threadcount > 8))
  627.                          {
  628.                            printf("ERROR: Thread count must be between 1 and 8 \n");
  629.                            fflush(stdout);
  630.                            exit(1);
  631.                           }
  632.                         else ++current_arg;
  633.                        }
  634.                       break;
  635.  
  636.                     case 'a':
  637.                       /* set threads to only run on 1 processor this will help determine
  638.                       if all processors are working if not certain threads will be starved */
  639.  
  640.                       setprocessoraffinity = TRUE;
  641.                       break;
  642.                       
  643.                     default: break;
  644.  
  645.     } /* end of switch */
  646.                          
  647.                
  648.     ++current_arg;
  649.     if (current_arg >= argc)
  650.       more_args = FALSE;
  651.  
  652.     } while ((!done) && (more_args));
  653.    
  654.    } 
  655.    /* initialize */
  656.  
  657.    
  658.      printf("NT Multiprocessor Benchmark by L. Kahn (C) 1994 \n");
  659.      printf("_________________________________________________\n\n");
  660.      printf("Default time to run threads is %d milliseconds with %d Simultaneous Thread(s).\n",
  661.        (int)totaltime,threadcount);
  662.      
  663.    if (!GetProcessAffinityMask( GetCurrentProcess(), &ProcAff, &SysAff) )
  664.      {
  665.        printf( "ERROR: GetProcessAffinityMask failed, defaulting to 1 processor\n\n" );
  666.        noprocessors = 1;
  667.        availprocessors = 1;
  668.      }
  669.  
  670.    else
  671.       {
  672.         printf( "System Affinity = %x\nProcess affinity = %x\n", SysAff, ProcAff );
  673.         noprocessors = number_of_processors(SysAff);
  674.         availprocessors = number_of_processors(ProcAff);
  675.       
  676.         printf("Number of processors reported = %d \n",noprocessors);
  677.         printf("Number of available processors reported = %d \n\n",availprocessors);
  678.         fflush(stdout);
  679.       }
  680.  
  681.      if (setprocessoraffinity)
  682.        {
  683.         int i = 0;
  684.         printf("Each thread will be assigned to run ONLY on each sequential processor, or\n");
  685.         printf("on a particular set of processors if the default values have been overridden\n");
  686.         printf("with the -v option.  If you run more threads than you have processors the \n");
  687.         printf("additional threads will run on all the processors.\n");
  688.         printf("By assiging threads to particular processors (that exist in your machine) you \n");
  689.         printf("can determine if they are working properly.\n");
  690.         printf("The following threads have the affinity mask overridden with the following values: \n");
  691.  
  692.         for (i=0; i<threadcount; i++)
  693.           {
  694.            if (assignedpaffin[i])
  695.              {
  696.               printf(" -->  Thread %d will be assigned affinity of %ld\n",i,paffinarray[i]);
  697.               fflush(stdout);
  698.              }
  699.            }
  700.       }  
  701.  
  702.    /* now create the threads to calculate the flops */
  703.     printf("Starting Floating Point pass.\n");
  704.     fflush(stdout);
  705.  
  706.     for (i=0; i<threadcount; i++)
  707.        {
  708.          float_thread_start_time[i] = 0;
  709.          float_thread_stop_time[i] = 0;
  710.          float_counters[i] = 0;
  711.         
  712.  
  713.       switch (i)
  714.         {
  715.         
  716.         case 0:
  717.        threadhandle[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread0_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  718.         break;
  719.  
  720.         case 1:
  721.        threadhandle[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread1_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  722.         break;
  723.  
  724.         case 2:
  725.        threadhandle[2] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread2_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  726.         break;
  727.  
  728.         case 3:
  729.        threadhandle[3] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread3_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  730.         break;
  731.  
  732.         case 4:
  733.        threadhandle[4] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread4_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  734.         break;
  735.  
  736.         case 5:
  737.        threadhandle[5] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread5_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  738.         break;
  739.  
  740.         case 6:
  741.        threadhandle[6] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread6_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  742.         break;
  743.  
  744.         case 7:
  745.        threadhandle[7] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread7_float,NULL,CREATE_SUSPENDED,&threadid[0]);
  746.         break;
  747.     
  748.       default: break;
  749.  
  750.     }            // end of switch
  751.  
  752.  } // end of loop
  753.  
  754.       /* now that the threads are created start them up */
  755.       floatstarttime = GetTickCount();
  756.       for (i=0; i<threadcount; i++)
  757.         
  758.         {
  759.  
  760.           if (setprocessoraffinity)
  761.             set_thread_to_processor(threadhandle[i],i+1,i);
  762.  
  763.         ResumeThread(threadhandle[i]);
  764.         
  765.         }
  766.  
  767.        /* now sleep for the required time */
  768.      Sleep(totaltime);
  769.  
  770.      /* now kill the threads setting stop time for each */
  771.      for (i=0; i<threadcount; i++)
  772.        {
  773.          TerminateThread(threadhandle[i],1);
  774.          float_thread_stop_time[i] = GetTickCount();
  775.        }
  776.      floatstoptime = GetTickCount();
  777.  
  778.  /* now do the calcs for integer operations */
  779.     printf("Starting Integer pass.\n");
  780.     fflush(stdout);
  781.  
  782.      for (i=0; i<threadcount; i++)
  783.        {
  784.          int_thread_start_time[i] = 0;
  785.          int_thread_stop_time[i] = 0;
  786.          int_counters[i] = 0;
  787.         
  788.  
  789.       switch (i)
  790.         {
  791.         
  792.         case 0:
  793.        threadhandle[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread0_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  794.         break;
  795.  
  796.         case 1:
  797.        threadhandle[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread1_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  798.         break;
  799.  
  800.         case 2:
  801.        threadhandle[2] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread2_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  802.         break;
  803.  
  804.         case 3:
  805.        threadhandle[3] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread3_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  806.         break;
  807.  
  808.         case 4:
  809.        threadhandle[4] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread4_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  810.         break;
  811.  
  812.         case 5:
  813.        threadhandle[5] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread5_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  814.         break;
  815.  
  816.         case 6:
  817.        threadhandle[6] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread6_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  818.         break;
  819.  
  820.         case 7:
  821.        threadhandle[7] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread7_int,NULL,CREATE_SUSPENDED,&threadid[0]);
  822.         break;
  823.     
  824.       default: break;
  825.  
  826.     }            // end of switch
  827.  
  828.  } // end of loop
  829.  
  830.       /* now that the threads are created start them up */
  831.       /* now that the threads are created start them up */
  832.       intstarttime = GetTickCount();
  833.       for (i=0; i<threadcount; i++)
  834.         
  835.         {
  836.  
  837.           if (setprocessoraffinity)
  838.             set_thread_to_processor(threadhandle[i],i+1,i);
  839.  
  840.         ResumeThread(threadhandle[i]);
  841.         
  842.         }
  843.   
  844.        /* now sleep for the required time */
  845.      Sleep(totaltime);
  846.  
  847.      /* now kill the threads setting stop time for each */
  848.      for (i=0; i<threadcount; i++)
  849.        {
  850.          TerminateThread(threadhandle[i],1);
  851.          int_thread_stop_time[i] = GetTickCount();
  852.        }
  853.    
  854.        intstoptime = GetTickCount();
  855.  
  856.  // now report results
  857.  
  858.  report_results(totaltime,threadcount);
  859.  
  860. }
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.