Counting Primes
Problem Statement:
Students should write a parallel c program for “Counting Primes” using the following two methods: MPI_Send and MPI_Receive ONLY
Given
- – Â Lower bound number x
- – Â Upper bound number yOutput
- – Â Count of prime numbers occurring between x and y
- – Â Count of prime numbers occurring in each process.Example:
“Total number of prime numbers is: 20” “Total number of prime numbers in P1 is: 10” “Total number of prime numbers in P2 is: 6” “Total number of prime numbers in P3 is: 4”
1
Faculty of Computers and Information Cairo University
Spring-2021
Parallelization Scenario Master Process:
- – Â Calculate the sub range size r=(y-x)/p
- – Â Note that p is the number of processes.
- – Â Broadcast x and r to each slave process using MPI_Send.
- – Â Receive sub count from each slave process using MPI_Receive.
- – Â Print total count of primes between x and y.Slave Process:
- – Â Receive x and r through the MPI_Receive.
- – Â Calculate the lower bound a and upper bound b according to its rank.
- – Â Count primes in its sub range (between a and b).
- – Â Print the partial count
- – Â Send this partial count to the master process using the MPI_Send.




