Hello all,

We are using this method to find all the prime numbers.

Our work didn't use the MPI_Isend() or MPI_Irecv() commands. The following is the MPI parallel part code.The highlighted is the explanation.

We use two dimensional vector to represent the array. The first column (p[i][0]) is the value, the second column (p[i][1]) is the status. If the status is 0, then it means that the corresponding value p[i][0] has been checked and deleted. If the status is 1, then that means the number p[i][0] is still in the list waiting for check.

Could you please take some time to give us some working direction?

Thank you for your time.

MPI Code:

Code:MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); int temp; while (minnum <=floor(sqrt(upperlimit))) // loop for every different "minnum" { if (rank==0) { pset.push_back(minnum); // store the value of "minnum" into prime set "pset" } for (int i=rank;i<upperlimit-1;i+=size) // divide array into "size" groups { if (p[i][0]%minnum==0 & p[i][1]==1) { //p[i][1]==1 means number i has never been deleted. p[i][1]=0; // p[i][1]==0 means number i has been deleted. } } for (int i=rank;i<upperlimit-1;i+=size) // find the min value in every rank. { if (p[i][1]==1) { temp=i+2; break; } } // MPI_Waitall (count,&array_of_requests,&array_of_statuses) // we want to use this command, but we do not use MPI_Isend(), so there is no array status and request. MPI_Allreduce(&temp,&minnum,size,MPI_INT,MPI_MIN,MPI_COMM_WORLD); // find the global min value using collective command // MPI_Bcast(&minnum,1,MPI_INT,0,MPI_COMM_WORLD); // we think there is no need to broadcast. } for (int i=rank;i<upperlimit-1;i+=size) // when add the remaining prime number to the prime set pset. { if (p[i][1]==1) { pset.push_back(p[i][0]); } }