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:
- Prompt the user for input numbers.
- The user should be kept informed of the status of the PVM program. Do this by including "write" statements of the form in fhostA.f and fnodeA.f.
- The result should be sent to standard output on the host.
- Examine the
/tmp/pvml.<uid>
file to look at output from node process.
- Try running your program so that it divides by 0. You will need at this point to add PVMDEBUG to the arguments in the spawn routine.
- Examine how your PVM program works under the debugger. Try this using both valid input and division by 0.
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:
- Prompt the user for input numbers.
- The user should be kept informed of the status of the PVM program - see exercise 1.
- The result should be sent to standard output on the host.
- Examine the
/tmp/pvml.<uid>
file to look at output from node processes.
- Examine how your PVM program works under the debugger. For each process spawned there will be a separate xterm window running dbx.
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.
- The call to
pvmfparent
determines whether this copy of the program was started by the user or was spawned.
- If the copy was started by the user, the program then spawns copies of itself.
- The
tids
array is multi-cast to the spawned processes.
- The spawned processors receive
tids
array.
Submitted by Mark Johnston,
last updated on 18 January 1995.