C****************************************************************************** C PVM TEMPLATE CODES C FILE: pvm.ex1.master.f C OTHER FILES: pvm.ex1.worker.f make.pvm.ex1.f C DESCRIPTION: Fortran Language version of PVM example 1 master component. C In this simple example, the master component initiates a specified number of C instances of the worker component. It then distributes an equal portion of C an array to each instance of the worker component. Each instance of the C worker component receives its portion of the array, and performs a simple C value assignment to each of its elements. The value assigned to each C element is simply that element's index in the array+1. Each worker component C then sends its portion of the array back to the master component. As the C master receives back each portion of the array, selected elements are C displayed. Note that the order in which the worker components finish is C non-deterministic so that different portions of the array may display C "out of order". C PVM VERSION: 2.4.2 C AUTHOR: Blaise Barney C LAST REVISED: 6/27/93 bbarney for 2.4.2 C****************************************************************************** program example1_master integer NUM_INSTANCES, ARRAYSIZE, FROMMASTER_MSG, FROMWORKER_MSG parameter (NUM_INSTANCES = 6) parameter (ARRAYSIZE = 60000) parameter (FROMMASTER_MSG = 1) parameter (FROMWORKER_MSG = 2) integer i, index, bytes, workernum, msgtype, rc, & inst(NUM_INSTANCES), chunksize character*16 worker real*4 data(ARRAYSIZE), result(ARRAYSIZE) C******************* enroll this program in pvm **************************** print *, '*********** Starting PVM Example 1 ************' call fenroll("ex1.m", rc) if (rc .lt. 0) then print *, 'MASTER: Unable to enroll this component.' print *, ' Return code= ', rc print *, ' Quitting.' stop else print *, 'MASTER: Component enrolled as instance = ', rc endif C******************* initiate worker processes ******************************* print *, 'MASTER: Initiating worker components...' do 10 i=1, NUM_INSTANCES call finitiate("ex1.w", "RIOS", inst(i)) print *, ' instance= ', inst(i) 10 continue C******************* initializations ************************************** chunksize = (ARRAYSIZE / NUM_INSTANCES) do 20 i=1, ARRAYSIZE data(i) = 0.0 20 continue C****************** send array chunks to each instance ********************* print *, 'MASTER: Sending data to worker instances...' index = 1 msgtype = FROMMASTER_MSG do 30 i=1, NUM_INSTANCES call finitsend() call fputnint(index, 1, rc) call fputnint(chunksize, 1, rc) call fputnfloat(data(index), chunksize, rc) call fsnd("ex1.w", inst(i), msgtype, rc) index = index + chunksize 30 continue C***************** wait for results from all worker instances *************** print *, 'MASTER: Waiting for results from worker instances...' msgtype = FROMWORKER_MSG do 40 i=1, NUM_INSTANCES call frcv(msgtype, rc) call fgetnint(index, 1, rc) call fgetnfloat(result(index), chunksize, rc) call frcvinfo(bytes, msgtype, worker, workernum, rc) print *, '---------------------------------------------------' print *, 'MASTER: Sample results from worker instance = ', & workernum print *, ' result[', index, ']=', result(index) print *, ' result[', index+100, ']=', result(index+100) print *, ' result[', index+1000, ']=', result(index+1000) print *, ' ' 40 continue print *, 'MASTER: All Done!' C*** leave PVM *** call fleave() end