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

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 Databases Questions!