We further illustrate the use of Fortran M communication statements with
the program ring2.fm. This program implements a ``ring
pipeline'', in which NP processes are connected via a
unidirectional ring. After NP-1 send-receive-compute cycles,
each process has accumulated the value
in the
variable sum.
==
program ring2
parameter (np=4)
inport (integer) ins(np)
outport (integer) outs(np)
do i = 1, np
channel(in=ins(i), out=outs(mod(i,np)+1))
enddo
processdo i = 1, np
processcall ringnode(i, np, ins(i), outs(i))
endprocessdo
end
process ringnode(me, np, in, out)
intent (in) me, np, in, out
integer me, np
inport (integer) in
outport (integer) out
buff = me
sum = buff
do i = 1, np-1
send(out) buff
receive(in) buff
sum = sum + buff
enddo
endchannel(out)
receive(in) buff
print *, 'node ', me, ' has sum = ', sum
end
=1.03