CMSC 476: Scatter/Gather Using MPI

Overview

Write an MPI program to generate a random vector and sum its elements (but NOT with MPI_Reduce). Populate the random std::vector<double> on the root process, using a std::minstd_rand with seed of 1 and a std::uniform_real_distribution. Scatter (via MPI_Scatter) this vector and have each process sum its local portion using std::accumulate. Then use MPI_Gather on process 0 to obtain the local sums, and compute a global sum which it’ll print. Verify your result with a serial std::accumulate on the original vector, allowing for an appropriate tolerance.

Input Specification

Input n from the user on process 0, which MUST be a multiple of p.

Use PRECISELY the format below with the EXACT same SPACING and SPELLING.

n ==> 1000

Output Specification

Use PRECISELY the format shown below with the EXACT same spacing and spelling.

Sample Output

(no spaces before the following line)
n ==> 1000

// sum:      xxxxx.xx
Serial sum:  xxxxx.xx

Correct:     yes
(no spaces after the preceding line)

Required Types, Concepts, and Functions

// Up to you...

What to Submit

Submit your source file ScatterGather.cc. You must demo your solution for any credit.


Gary M. Zoppetti, Ph.D.