Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 - First, I want to know the validity of this information: If the number of threads increases, the speedup increases. 2 - If this
First, I want to know the validity of this information: If the number of threads increases, the speedup increases.
If this information is correct, my code should work correctly when I increase the number of threads in the terminal. I was trying to increase the number of n but it did not work.
what is the problem and how can I correct it Can you provide me with the code after modification?
#include
#include
#include
#include
#include
using namespace std;
void Parallelsortvector& X double& parallelexecutiontime
unsigned int i j count, N Xsize;
vector tmpN;
double starttime ompgetwtime;
#pragma omp parallel for privatei j count sharedX tmp
for i ; i N; i
count ;
for j ; j N; j
if Xj XiXj Xi && j i
count;
tmpcount Xi;
double endtime ompgetwtime;
parallelexecutiontime endtime starttime;
copytmpbegin tmpend Xbegin;
void Serialsortvector& X double& serialexecutiontime
double starttime ompgetwtime;
sortXbegin Xend;
double endtime ompgetwtime;
serialexecutiontime endtime starttime;
int mainint argc, char argv
if argc
cout "Usage: argv endl;
return ;
int numthreads atoiargv;
ompsetnumthreadsnumthreads;
vector num ;
double parallelexecutiontime ;
Parallelsortnum parallelexecutiontime;
double serialexecutiontime ;
Serialsortnum serialexecutiontime;
cout "Parallel Execution Time: parallelexecutiontime seconds" endl;
cout "Serial Execution Time: serialexecutiontime seconds" endl;
double speedup serialexecutiontime parallelexecutiontime;
cout "Speedup: speedup endl;
double efficiency speedup numthreads;
cout "Efficiency: efficiency endl;
for const auto& n : num
cout n ;
cout endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started