program spmd
c
c program taken from PVM 3.1 Release Notes
c and User's guide
c
c Author: Nilesh Raj
c Date: 31 August 1994
c Version: 1.0
c Language; FORTRAN-77
c
implicit none
#include "fpvm3.h"
integer NPROC,MXPROC
parameter ( MXPROC=11)
integer mytid, me, numt, i, info
integer tids(0:MXPROC)
c
c enroll in PVM
c
call pvmfmytid(mytid)
c
c am I parent or child?
c
call pvmfparent(tids(0))
if (tids(0) .lt. 0) then
tids(0) = mytid
me = 0
write(6,'('' Enter total number of nodes (2-10): '',$)')
read(5,'(i4)')NPROC
c
c start copies of myself
c
call pvmfspawn('fspmd',PVMDEFAULT,'*',NPROC-1,tids(1),numt)
write(6,'('' Number of nodes spawned: '',i4)')numt
write(6,'('' Tid to be passed around nodes: '',i8)')mytid
c
c send number of processes to children
c
call pvmfinitsend(0,info)
call pvmfpack(INTEGER4,NPROC,1,1,info)
call pvmfmcast(NPROC-1,tids(1),5,info)
c
c send tids array to children
c
call pvmfinitsend(0,info)
call pvmfpack(INTEGER4,tids,NPROC,1,info)
call pvmfmcast(NPROC-1,tids(1),0,info)
else
c
c receive NPROC
c
call pvmfrecv(tids(0),5,info)
call pvmfunpack(INTEGER4,NPROC,1,1,info)
c
c receive the tids arrays and set me
c
call pvmfrecv(tids(0),0,info)
call pvmfunpack(INTEGER4,tids,NPROC,1,info)
do 10 i=1,NPROC-1
if (mytid .eq. tids(i)) me=i
10 continue
endif
c
c all NPROC tasks are equal now
c and can address each other by tids(0) through tids(NPROC-1)
c for each process me => process number [0-(NPROC-1)]
c
call dowork(me, tids, NPROC)
if (me .eq. 0) then
write(6,'('' Tid successfully passed around all nodes '')')
write(6,'('' Host: Terminating '')')
endif
c
c program finished exit PVM
c
call pvmfexit(info)
stop
end