diff --git a/bin/master.py b/bin/master.py index 690df03..d37e61b 100644 --- a/bin/master.py +++ b/bin/master.py @@ -47,6 +47,15 @@ def run_queries(count, order = 3, extra_points = 8, verbose = False): return (r, submit_end - submit_start, receive_end - receive_start) +def clean_up(inq, expected_participants, shutdown = False): + """ + I replace the normal first argument to the inq with None, and then do some + code branching based on the second paramter, which is shutdown + """ + for i in xrange(expected_participants): + inq.put([None, shutdown, None, None]) + + if __name__ == '__main__': parser = OptionParser(usage = "usage: %s [options] ") @@ -54,6 +63,10 @@ if __name__ == '__main__': action="store_true", dest="verbose", default=False, help="verbose flag (display progress bar: %default)") + parser.add_option("-l", "--last-time", + action="store_true", dest="last", default=False, + help="when finished, send shutdown signal to nodes (default: %default)") + parser.add_option('-p', '--port', type="int", dest="port", default=6666, help="specify the port to use on the server (default: %default)") @@ -94,8 +107,7 @@ if __name__ == '__main__': results, submit, receive = run_queries(count, order = options.order, extra_points = options.extra, verbose = options.verbose) # shut down all participants - for i in xrange(expected_participants): - inq.put([None] * 4) + clean_up(inq, expected_participants) # post processing stats = {} @@ -122,3 +134,6 @@ if __name__ == '__main__': 'results' : npresults, } s.close() + + if options.last: + clean_up(inq, expected_participants, shutdown = True) diff --git a/bin/slave.py b/bin/slave.py index e6709af..ea9e317 100644 --- a/bin/slave.py +++ b/bin/slave.py @@ -22,7 +22,7 @@ def work(inq, outq, g, myname): while True: i, o, e, X = inq.get() if i == None: - break + return o a = g.run_baker(X, order = o, extra_points = e) outq.put((i, myname, a['qlin'], a['error'], a['final'], exact(X))) @@ -56,4 +56,6 @@ if __name__ == '__main__': g.q = np.array([exact(x) for x in g.verts]) myname = options.label - work(inq, outq, g, myname) + shutdown = False + while not shutdown: + shutdown = work(inq, outq, g, myname)