I have the following question in my assignment. I know that I need to use Amdahl's law but I don't know which part is going to be which part in the formula.
Here is the question:
How much will the following code speed up if we run it simultaneously on 8 threads?
#include <stdio.h>
#include <omp.h> //OpenMP library
int main()
{
int i=0,j=0;
for (i=0;i<1000;i ){
i*i;
}
#pragma omp parallel for
for (j=0;j<2000;j ){
j*j;
}
return 0;
}
Any help is appreciated!
CodePudding user response:
Amdahl's Law is like so:
s is the speedup of the part of the task that benefits from improved system resources and p is the proportion of execution time that the part benefiting from improved resources originally occupied.
Your program runs in time proportional to 3000, the total number of loop iterations if the program is run in serial.
The part of the program you wish to parallelize accounts for 2/3 of the run time. Since you plan to run it on 8 threads your theoretical speed-up for that part of the program is 8x.
We plug numbers in to the equation:
1/((1-2/3) (2/3)/8)
This indicates a 2.4x bound on the speed-up.