Coordinated Binding Behavior
Looking again at x = y, what if y has not yet been defined? With conventional sequential programs, we could get junk data. A more helpful language might signal an error or raise an exception; after all, nobody else is going to come along and define y for us.
But in an ensemble setting, somebody might well do just that. In other words, in the context of coordination, an unbound name has a perfectly valid (and useful) interpretation: "Please hold."
x = 123 x = 456
In the setting of conventional sequential programs, it would be unusual to see such code (and a compiler might warn about or eliminate the dead code), but it's reasonable to let the second assignment simply overwrite 123 with 456. We're the only process in town, so who else is going to care about the old value?
But in ensemble settings, other processes may be interested in the sequence of values bound to x. If so, how do we know a particular value of x has been put to good use?
Enter generative communication. Some coordination events generate data that exist independent of any process, others consume such data. We interpret variable binding as adding a value to a list of values, rather than overwriting a single value. We do so by maintaining a FIFO queue of values. But how do we shed values? To complete the picture, retrieval of a value bound to a name removes one value from the queue. In short, an assignment records a value of interest, a retrieval consumes one value, and an empty list of values triggers "Please hold" for a retrieval.
To see how well these play together in a Python session, run this "worker" code:
from nws.client import NetWorkSpace def f(x): return x*x*x ws = NetWorkSpace('table') while True: ws.store('r', f(ws.fetch('x')))
Then, in another Python session, run the "master":
ws = NetWorkSpace('table') for x in range(100): ws.store('x', x) for x in range(100): print 'f(%d) = %d'%(x, ws.fetch('r'))
You will see printed a list of numbers and their cubes, computed by the worker:
- The master and worker can be started in either order.
- The number of workers is not specified in the master code and is completely flexible, but a modest code change would be needed to print out the results in correct order if more than one worker is used.