Parmeet
Parmeet

Reputation: 41

Speed up issues with 4 threads on quadcore system using OpenMP

I have a speed up problem using 4 threads on quadcore system using OpenMP. With 2 threads the efficiency is close to 1 but with 4 threads it reduces to half that is the running time is more or less same as when running the code using 2 threads. I searched on OpenMP forum and i find similar issue before which is because of Inter turbo boost technology. Please refer to this post http://openmp.org/forum/viewtopic.php?f=3&t=1289&start=0&hilit=intel+turbo+boost

So i have tried to disable turbo boost on all the 4 processors of my machine but couldn't get rid of the problem.

I took the benchmark code from above link only.

I have a DELL laptop and my harware/OS information summary is as follows:

OS : Linux3.0.0.12-generic , Ubuntu
KDE SC Version : 4.7.1

Processor: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz

Please let me know what could be other possible problems that is not allowing me to speed up using 4 threads/cores. As an additional info. i have checked that all the 4 threads are running on different cores.

Looking forward to your answers.

Code:

#include <stdio.h>
#include <omp.h>
#include <math.h>


double estimate_pi(double radius, int nsteps){

   int i;
   double h=2*radius/nsteps;
   double sum=0;
   for (i=1;i<nsteps;i++){
      sum+=sqrt(pow(radius,2)-pow(-radius+i*h,2));
      //sum+=.5*sum;
   }
   sum*=h;
   sum=2*sum/(radius*radius);
   //printf("radius:%f --> %f\n",radius,sum);
   return sum;


}

int main(int argc, char* argv[]){


   double ser_est,par_est;
   long int radii_range;
   if (argc>1) radii_range=atoi(argv[1]);
   else radii_range=500;   

   int nthreads;
   if (argc>2) nthreads=atoi(argv[2]);
   else nthreads=omp_get_num_procs();

   printf("Estimating Pi by averaging %ld estimates.\n",radii_range);
   printf("OpenMP says there are %d processors available.\n",omp_get_num_procs());

   int r;
   double start, stop, serial_time, par_time;



   par_est=0;
   double tmp=0;
   ser_est=0;
   start=omp_get_wtime();
   for (r=1;r<=radii_range;r++){
      tmp=estimate_pi(r,1e6);
      ser_est+=tmp;
   }
   stop=omp_get_wtime();
   serial_time=stop-start;
   ser_est=ser_est/radii_range;

   omp_set_num_threads(nthreads);
   start=omp_get_wtime();
   #pragma omp parallel for private(r,tmp) reduction(+:par_est)
   for (r=1;r<=radii_range;r++){
      tmp=estimate_pi(r,1e6);
      par_est+=tmp;
   }
   stop=omp_get_wtime();
   par_time=stop-start;
   par_est=par_est/radii_range;

   printf("Serial Estimate: %f\nParallel Estimate:%f\n\n",ser_est,par_est);
   printf("Serial Time: %f\nParallel Time:%f\nNumber of Threads: %d\nSpeedup: %f\nEfficiency: %f\n",serial_time,par_time,nthreads,serial_time/par_time, serial_time/par_time/nthreads);


}

Upvotes: 2

Views: 912

Answers (1)

Tudor
Tudor

Reputation: 62459

The Core i7-2620M is a dual-core with HT (thus 4 logical cores). HT will not always improve program performance and the improvement depends a lot on the program itself (for some memory-intensive apps it may even degrade). You should definitely not expect a 4x speedup, since it does not have 4 physical cores.

If you have time it's worth to read a bit from here: http://software.intel.com/en-us/articles/performance-insights-to-intel-hyper-threading-technology/

Upvotes: 5

Related Questions