Example of PVM Master/Slave program

There are two source programs: fhostA.f and fnodeA.f

First an explanation of the working of fhostA.f and fnodeA.f.

These combined are an example of a master/slave PVM model. A master program "spawns" and directs slave programs which in turn may perform calculations.

The routine pvmfserror sets automatic error message printing for all subsequent PVM calls by the calling process.

The master program - fhostA.f - calls pvmfmytid to enroll this process into PVM on its first call and generates a unique tid (task identifier) if the process was not started with pvmfspawn. The call to pvmfspawn is made to execute a given number of slave programs on other machines.

The call pvmfinitsend clears the SEND buffer and prepares it for packing a new message. pvmfpack packs a given data type into the active SEND buffer. pvmfsend labels the message with an integer identifier or message tag and sends it immediately to process task tid.

pvmfrecv is a blocking receive routine which will wait until a message with the correct label arrives from tid.

A single Fortran subroutine handles all the unpacking functions. Unpacking must be performed in the same order as the corresponding pack.

Finally, pvmfexit tells the local PVM daemon that this process is leaving PVM.

Now consider the slave program fnodeA.f

pvmfparent returns the tid of the process that spawned the calling process. The routines pvmfrecv and pvmfunpack have already been explained - this time the slave is waiting to receive from the master.

A very simple computation by the slave then follows. Initiating the SEND buffer, PACKing the message, and SENDing to the master follows the same procedure as in fhostA.f

UP


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