Point to Point Communication

Example: Average of a set of numbers

Computing the average and standard deviation of a set of numbers is a simple task. Yet doing it in parallel provides a good introduction to message passing programming using MPI.

The data set data is some noisy data set. The file contains "x" and a "y" coordinates of points that you can display with plot_data. We seek the average and standard deviation of the "y" column.

The code average.c solves this problem using a serial algorithm. Note the use of "MALLOC" and "FREE" to reserve memory space and free it up. This allows writing a flexible and general code.

A parallel implementation of the solution could use an algorithm in which the data is divided among all the processes. This illustrates one of the advantage of using a prallel architecture in that the memory requirement per node is much less than in a serial implementation of the code. Or that the agregate memory of the parallel computer is tipically much larger than the memory of a single computer, allowing larger problems to be solved.

The algorithm of a parallel implementation is illustrated in a simplified flowchart. Note the following:

A parallel code should be written by the student. It requires a careful buildup and testing of the statements.


   Back to top of page

   Back to course contents