Please anone help me with this screen shots of test runs please Write a parallel
ID: 3766117 • Letter: P
Question
Please anone help me with this screen shots of test runs please
Write a parallel program with MPI that supports the following computation.
1). It generates five processes P0, P1, P2, P3, and P4.
2). Main process gets a number n from key board, then initiates MPI.
3) Process Pi (i=0,1,2,3) uses n to call the following two functions.
a) function prime(int n) finds the smallest prime number q that q=8m+(2i+1) >n for some integer m. Note a prime number p is an integer that is not product of two integers less than p.
b) function twin(int n) finds the least twin number (q, q+2) that q=8m+(2i+1)> n for some integer m. A pair (q,q+2) is a twin if both q and q+2 are prime numbers.
4) P4 gets all four results from the other four processes and returns the least prime number and twin.
For example, if n=10, P0 returns 11 and (11,13), P1 returns 13 and (17, 19), P2 returns 17 and (17, 19), and P3 returns 19 and (29,31). Finally, P4 returns 11 and (11,13).
All the five processes share the same program.
Your complete C++ code for this project with summary in a word document, please have readable code
Screenshots of test runs
please anyone help me with this program its urgent
Explanation / Answer
MPI is a directory of C++ programs which illustrate the use of the Message Passing Interface for parallel programming which allows a user to write a program in a familiar language, such as C, C++, FORTRAN, or Python, and carry out a computation in parallel on an arbitrary number of cooperating computers.
number of processors(n) number of iterations(p) where q is quotient and r is remainder.
n = p X q + r
here the function has to generate or fix which is prime and return that numbers to main from the range of n.
so no of processors would be n.
#include <iostream>
#include <mpi.h>
using namespace std;
int main(int argc, char** argv){
int i,p;
int n,m=1;
int sum, ssum,ssum2;
MPI_Init(&argc,&argv);
p=MPI::COMM_WORLD.Get_size( );
MPI_Comm_rank(comm,&n);
sum=MPI_Prime(n);
ssum=MPI_Twin(n);
ssum1=ssum+2;
m++;
printf("Process %d of %d ", myrank, n);
printf("%d(%d %d)",sum,ssum,ssum2);
MPI_Finalize();
return 0;
}
MPI_Prime(int n)
{
for(int i=n;8*m+(2*i+1)>n;i++)
{
for ( int c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d ",i);
count++;
}
i++;
}
}
MPI_Twin(int n1)
{
n2=n1+2;
if(n1%i==0)
c1++;
if(n2%i==0)
c2++;
}
d=abs(n1-n2);
if(d==2 && c1==2 && c2==2)
return n1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.