Question: I need help. I ' m trying to run my project in terminal by using mpicc so give me the exact code to do this.

I need help. I'm trying to run my project in terminal by using mpicc so give me the exact code to do this.
the source code is the following
// Benchmarking Performance of the Sieve of Eratosthenes Prgram.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include
#include
#include
#include
#include
#include
#include // Include MPI header file
static void mpiSieveOfEratosthenes(int n, int rank, int size){
int root = sqrt(n);
std::vector prime(root +1, true);
prime[0]= prime[1]= false;
for (int i =2; i = root; i++){
if (prime[i]){
for (int j = i * i; j = root; j += i){
prime[j]= false;
}
}
}
int start = rank *(n /2)+((rank >0)?1 : 2);
int end =(rank ==1)? n : ((rank +1)*(n /2));
std::vector segment(end - start +1, true);
for (int p =2; p = root; p++){
if (prime[p]){
int startIndex = std::max(p * p,(start + p -1)/ p * p);
for (int j = startIndex; j = end; j += p)
segment[static_cast>::size_type>(j)- start]= false;
}
}
if (rank ==0){
for (int p =2; p = root; p++)
if (prime[p])
std::cout p "";
}
MPI_Barrier(MPI_COMM_WORLD);
for (int index = start; index = end; ++index)
if (segment[static_cast>::size_type>(index)- start])
std::cout index "";
}
int main(int argc, char* argv[]){
int pnum;
std::cout "Enter the upper limit for finding prime numbers: ";
std::cin >> pnum;
int rank, size;
// Initialize MPI environment
MPI_Init(&argc, &argv);
// Get the rank of the process
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Get the total number of processes
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank ==0){// If this is the master process
auto start = std::chrono::high_resolution_clock::now();
mpiSieveOfEratosthenes(pnum, rank, size); // Call mpiSieve function
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration duration = end - start;
std::cout "
Max Prime: " pnum ", Processes: " size
", Time: " duration.count()" seconds using MPI
";
}
else {
mpiSieveOfEratosthenes(pnum, rank, size); // Call mpiSieve function for worker processes
}
// Wait for Esc key press before exiting
std::cout "
Press Esc to exit...";
while (true){
if (_kbhit()){
char ch =_getch();
if (ch ==27){//27 is the ASCII code for Esc
break;
}
}
}
// Finalize MPI environment
MPI_Finalize();
return 0;
}
I need help. I ' m trying to run my project in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!