next up previous

3 Writing PVM Applications     continued...

During execution, before any other PVM function can be called, a task must first enroll into PVM. This assigns a unique task id number to the task. These task ids are used when sending and receiving messages. Once a task has completed its work under PVM, it must inform the PVM daemon that it is exiting from the virtual machine. This does not terminate the process executing the task which can continue running, however, it may not interact with any other PVM tasks.

The following subsections give an example program in both C and Fortran 77. For these examples, we shall assume that the user has built his own set of PVM executables on makina1 and the program sources reside in the user's $HOME directory.

The examples given here illustrate a master/worker code that sums up the values of an integer array. The master task spawns off five worker tasks, sends each of the workers a portion of the array to be summed up, receives the partial totals from each of the workers, and adds those up for the final total. The worker tasks receive an array of integers, add up all the values in the array, and send the total back to the master process.

The PVM source comes with example applications. These can be found in the pvm3/examples directory.