Question
Hi. I need to write a program dealing with prime number factorization and parallel computing through mpi. I am stuck at this point and have
Hi. I need to write a program dealing with prime number factorization and parallel computing through mpi. I am stuck at this point and have pasted the problem below.
"Is the number (N) 2,000,000,111 prime? Let each process test a disjoint set of integers, and rpint out any factor they find. You do not have to test all integers < N: any factor is at most sqrt(N) ~ 45,200.:
I don't think I can use i%0 as it would probably give a runtime error. Is there more than one solution?
#include
#include
#include
int main(int argc,char **argv) {
MPI_Init(&argc,&argv);
MPI_Comm comm = MPI_COMM_WORLD;
int nprocs, procno;
MPI_Comm_size(comm,&nprocs);
MPI_Comm_rank(comm,&procno);
int bignum = 2000000111, maxfactor = 45200;
// Exercise:
// -- Parallelize the do loop so that each processor
// tries different candidate numbers.
// -- If a processors finds a factor, print it to the screen.
// 1. Set loop bounds /***code below***/
do {
statement(s);
}
// 2. Fill in loop header
for ( int myfactor = 2; myfactor <= ____; myfactor++
/**** code here ****/
) {
if (bignum%myfactor==0) {
printf("Processor %d found factor %d ",procno,myfactor);
}
}
MPI_Finalize();
return 0;
}
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