PVM Master/Slave Programs Exercises

Exercise 1

Study the programs fhostA.f and fnodeA.f. By using the techniques shown in that master/slave program write your own PVM program to do the following.

The master program should read in two integer numbers and then spawn a task to calculate the ratio of these numbers. The ratio is then returned to the master and written to standard output. Your program should have these features:

Exercise 2

This exercise is to show the passing of arrays to a number of spawned nodes. Calculations performed by the nodes are very simple, but additional features of PVM will be demonstrated. These will include message passing of arrays (previous example was on scalars); spawning of more than one process; the multi-cast routine, pvmfmcast; and use of the debugger when a number of processes are spawned.

Your host program should initialize an array - I suggest b(1), b(2), ..., b(9)=0 - and spawn a number of processes. Let the user choose 1-3 processes to spawn. The task of the node programs is to increment each element of b by an integer. This integer should be equal to the position of that node's tid in the tids array returned by the call to pvmfspawn by the host.

Each node should then return the incremented array to the host program, which then prints the array to standard output. So if two processes were spawned two arrays will be printed, one with all elements equal 1 and the other with all elements equal 2. As with exercise 1 your program should have the following features:

PVM SPMD Program Exercise

This exercise illustrates the SPMD (Single Program Multiple Data) model, a common approach in applications development. In this approach data is partitioned and distributed amongst machines in the PVM configuration, and the same executable is placed on each node. The example given below does not illustrate a single executable performing calculations on different data, instead it shows how to get a program to spawn copies of itself; that is, a hostless program. Once copies of the program have been distributed, a tid is passed around all processes and returned to the first program copy.

To help get you started there is a program called spmd.f directory. Follow how this program works and then write a routine called dowork.f to pass tids(0) around all processes. tids(0) should finally be returned to the first copy of the program. Show that tids(0) was successfully passed around with an appropriate message printed to the screen.

Here is a summary of how the program spmd.f works.


Submitted by Mark Johnston,
last updated on 18 January 1995.