COSC 6360: Parallel Computing
Programming Project #2_2
Basic MPI Programming
Objective: The purpose of this programming project is to become familiar with the MPI API and write basic communication programs. This can be accomplished by developing simple computer programs that use the MPI parallel communications library.
Part A: Checking Prime Numbers
(25 points)
- Initialize MPI
- Get the size of MPI_COMM_WORLD communicator and rank of the current process(es).
- Declare and fill an array of 100,000 elements with random positive integers
- Have process 0 to send and distribute the elements of the array as evenly as possible among all other processes. Each process will receive its subarray.
- Each process will check every element in its subarray and determine whether the element is a prime number or not and accordingly, increment a counter if the number is a prime. At the end, each process will send process 0 the total number of prime numbers identified in its own subarray. Process 0 will receive the counts of prime numbers from all processes and will print messages indicating which process has found how many prime numbers. At the end, process 0 will also print the total number of prime numbers found in all 100,000 elements.
Part B. Generating Prime Numbers
(25 points)
- Initialize MPI
- Get the size of MPI_COMM_WORLD communicator and rank of the current process(es).
- Have process 0 to receive an input from the keyboard how many prime numbers are to be generated.
- Process 0 will divide the total number of prime numbers to be generated by the number of processes and accordingly, will send a message to each process to produce that many prime numbers.
- Each process will receive the message of how many prime numbers needs to be generated. To produce a prime number, each process can use the random number generation function and check whether a random number is a prime or not and accordingly, can fill an array. At the end each process will send an array of prime numbers to process 0.
- Process 0 will receive an array of prime numbers from each process and put them together in a large array.
- Process 0 will write all the prime numbers generated in a file named as “prime.dat” with each number on a separate line.
Note: To work on this assignment, you need to know how to use the random number generator function. Remember, in the first project we used the random number generator function in the computation of PI. You also need to know how to test whether a positive integer is a prime number or not. A prime number is a number which is only divisible by 1 or by the number itself. If any number other than 1 or the number itself divides the number evenly (i.e, with a remainder of 0), then the number is not a prime number. For any given number n, you may try to divide the number by 2, 3, . . ., n – 1 and see whether it is divisible. A more efficient solution is to try to diviAde n by 2, 3, 4, . . ., . You may find many code examples online. Be sure to include the source in your “readme” file or mention the source as a comment in your program if you copy code from any online sources.
How to submit:
- A makefile is required for this project capable of compiling and building all
- Create a zip file with all files for the assignment and upload it on blackboard. The name of the file should be proj2_2_YourUserId.zip (for example, it will be proj2_2_dkar.zip with my user id: dkar).
- Your solutions must be written in C/C++ using You may do some or all development work on your personal computer, however your programs will be tested on riddler.tamucc.edu.
- Grading elements include correctness, program documentation, good use of functions, good use and selection of any data structures used, and clean, efficient, easy to follow