Question: MPI Program You are supposed to use the given template for implementing each of the problems. Additionally, your program will be given two arguments, path

MPI Program

You are supposed to use the given template for implementing each of the problems. Additionally, your program will be given two arguments, path to an input file and an output file from which your program will obtain the input and output the result into respectively, like the following (for C++): mpirun -np 11 ./a.out .

Write a program to check if a number is prime. Input: First line will contain the integer N. Output: Print Y ES if the integer is prime, else print NO. Constraints: 1 <= N <= 109 1 Example: Sample Input: 11 Sample Output: YES

Code should be written in the middle of the template given below, where it is written as "Enter your code here"

# include # include using namespace std ; int main ( int argc , char ** argv ) { int rank , numprocs ; // initiate MPI MPI_Init ( &argc , & argv ); // get size of the current communicator MPI_Comm_size ( MPI_COMM_WORLD , & numprocs ); // get current process rank MPI_Comm_rank ( MPI_COMM_WORLD , & rank ); /* synchronize all processes */ MPI_Barrier ( MPI_COMM_WORLD ); double start_time = MPI_Wtime (); // enter your code here MPI_Barrier ( MPI_COMM_WORLD ); double end_time = MPI_Wtime () - start_time ; double maxTime ; // get max program run time for all processes MPI_Reduce ( & end_time , & maxTime , 1, MPI_DOUBLE , MPI_MAX , 0, MPI_COMM_WORLD ); if ( rank == 0 ) { cout <<" Total time (s): " <

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!