Convert the following MPI program to a sequent program

Job ID: 36318330

Budget: $10 – $30 USD

Write the program to behave like:

How many processes?

5

Then make a shared memory location of type int of the size of: 5

The function (like f) that would be the one parameter of m_fork() should do the following:

Generates a random integer.

Check to see:

if it is a prime number, saves the number in the array that its index is the rank of the process.

If it is not a prime number, saves its negate in in the array that its index is the rank of the process.

Now the process of rank zero prints the array such that:

if the content of a location of the array is positive (like n), outputs n is a prime number.

if the content of a location of the array is negative (like -n) outputs n is not a prime number.

Note when process with rank zero is going to print the array, all the processes (including rank zero) have saved their number to array.

Use the file sequent.h given and then convert the given mpi code to sequent

//File name: prime.c
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int isPrime(int n){
int i;
for(i = 2; i < n; i++)
if(n % i == 0)
return 0;
return 1;
}

int main(){
int comm_sz, my_rank, q, n;

MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
srandom((unsigned)time(NULL) + my_rank);
n = 1 + random()%10000; //The program should work for any positive number.
if(isPrime(n))
MPI_Send(&n, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
else{
n = -n;
MPI_Send(&n, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}
//To make sure all the processes obtained a number, and sent either n or -n to process 0
MPI_Barrier(MPI_COMM_WORLD);
if(my_rank == 0)
for (q = 0; q < comm_sz; q++)
{
MPI_Recv(&n, 1, MPI_INT, q, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
if(n < 0)
printf("Receiving from process: %d, %d is NOT a prime number\n", q, -n);
else
printf("Receiving from process: %d, %d is a prime number\n", q, n);
}
MPI_Finalize();
return 0;
}