import Linda
# replace the above by
# import NetworkLinda
# to run on different hosts
def part0(T):
# T is the Linda tuplespace object
# part0 is the host (or thread) that
# initializes the tuplespace to have
# the values of an array to be summed
# first 1/3 of array for slave 0
for i in range(0,1000):
x = 1.0 / (0.1 + float(i))
T.Out(("A",i,x))
# second 1/3 of array for slave 1
for i in range(1000,2000):
x = 1.0 / (0.1 + float(i))
T.Out(("A",i,x))
# last 1/3 of array for slave 2
for i in range(2000,3000):
x = 1.0 / (0.1 + float(i))
T.Out(("A",i,x))
# wait for all the slaves
# to be finished
S = 0.0
for i in range(0,3):
c = "sum" + str(i)
# get result from one slave
v = T.In((c,None))
S += v[1]
print "Final Sum =", S