Advertisement
Guest User

code for 1 thread

a guest
Mar 27th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. //
  2. // helloflops1
  3. //
  4. // A simple example to try
  5. // to get lots of Flops on
  6. // Intel(r) Xeon Phi(tm) co-processors.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/time.h>
  13. //
  14. // dtime -
  15. //
  16. // utility routine to return
  17. // the current wall clock time
  18. //
  19. double dtime()
  20. {
  21.     double tseconds = 0.0;
  22.     struct timeval mytime;
  23.     gettimeofday(&mytime,(struct timezone*)0);
  24.     tseconds = (double)(mytime.tv_sec + mytime.tv_usec*1.0e-6);
  25.     return( tseconds );
  26. }
  27.  
  28.  
  29. #define FLOPS_ARRAY_SIZE (1024*1024)
  30. #define MAXFLOPS_ITERS 100000000
  31. #define LOOP_COUNT 128
  32. // Floating pt ops per inner loop iteration
  33. #define FLOPSPERCALC 2    
  34. // define some arrays - 64 byte aligned for fastest cache access
  35. float fa[FLOPS_ARRAY_SIZE] __attribute__((align(64)));
  36. float fb[FLOPS_ARRAY_SIZE] __attribute__((align(64)));
  37.  
  38. //
  39. // Main program - pedal to the metal...calculate tons o'flops!
  40. //
  41. int main(int argc, char *argv[] )
  42. {
  43.         int i,j,k;
  44.         double tstart, tstop, ttime;
  45.     double gflops = 0.0;
  46.     float a=1.1;
  47.  
  48.        
  49.         //
  50.         // initialize the compute arrays
  51.         //
  52.  
  53.         printf("Initializing\r\n");
  54.         for(i=0; i<FLOPS_ARRAY_SIZE; i++)
  55.         {
  56.         fa[i] = (float)i + 0.1;
  57.             fb[i] = (float)i + 0.2;
  58.         }  
  59.  
  60.         printf("Starting Compute\r\n");
  61.  
  62.         tstart = dtime();  
  63.         // loop many times to really get lots of calculations
  64.         for(j=0; j<MAXFLOPS_ITERS; j++)  
  65.         {
  66.         //
  67.         // scale 1st array and add in the 2nd array
  68.         // example usage - y = mx + b;
  69.         //
  70.             for(k=0; k<LOOP_COUNT; k++)  
  71.         {
  72.                 fa[k] = a * fa[k] + fb[k];
  73.             }
  74.      }
  75.          tstop = dtime();
  76.  
  77.          // # of gigaflops we just calculated  
  78.          gflops = (double)( 1.0e-9*LOOP_COUNT*MAXFLOPS_ITERS*FLOPSPERCALC);    
  79.  
  80.      // elasped time
  81.          ttime = tstop - tstart;
  82.  
  83.          //
  84.          // Print the results
  85.          //
  86.          if ((ttime) > 0.0)
  87.          {
  88.              printf("GFlops = %10.3lf, Secs = %10.3lf, GFlops per sec = %10.3lf\r\n",
  89.                      gflops, ttime, gflops/ttime);
  90.          }   
  91.          return( 0 );
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement