From 36ba080d14ce9e321e7c9ad97a6b973ea0b76088 Mon Sep 17 00:00:00 2001 From: Stephen Mardson McQuay Date: Sat, 2 Apr 2011 00:34:54 -0600 Subject: [PATCH] auto calculate participants --- bin/master.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/bin/master.py b/bin/master.py index 9b4ae49..fd45bc3 100644 --- a/bin/master.py +++ b/bin/master.py @@ -20,11 +20,11 @@ log = logging.getLogger("interp") from interp.cluster import QueueManager, get_qs if __name__ == '__main__': - parser = OptionParser(usage = "usage: %s [options] ") + parser = OptionParser(usage = "usage: %s [options] ") parser.add_option("-l", "--last-time", action="store_true", dest="last", default=False, - help="when finished, send shutdown signal to nodes (default: %default)") + help="when finished, send shutdown signal to connected nodes (default: %default)") parser.add_option('-p', '--port', type="int", dest="port", default=6666, @@ -48,7 +48,7 @@ if __name__ == '__main__': sys.exit(1) server = args[0] - expected_participants, count = (int(i) for i in args[1:]) + count = int(args[1]) m = QueueManager(address=(server, options.port), authkey='asdf') m.connect() @@ -56,9 +56,12 @@ if __name__ == '__main__': tasksq, resultsq, masterq, slavesq = get_qs(m) print "wait on all participants" - for i in xrange(expected_participants): + for i in xrange(participants): + participants = 0 + while not masterq.empty(): + participants += 1: worker = masterq.get() - print "%d of %d : %s is ready" % (i, expected_participants - 1, worker) + print "%d: %s is ready" % (participants - 1, worker) print "everyone ready!" @@ -70,7 +73,7 @@ if __name__ == '__main__': tasksq.put((i, options.order, options.extra, X)) submit_end = time.time() - for i in xrange(expected_participants): + for i in xrange(participants): print "sending %d th start message" % i slavesq.put("start") @@ -88,7 +91,7 @@ if __name__ == '__main__': receive = receive_end - receive_start # shut down all participants - for i in xrange(expected_participants): + for i in xrange(participants): if options.last: slavesq.put("teardown") else: @@ -96,10 +99,10 @@ if __name__ == '__main__': # post processing stats = {} - stats['submit' ] = float(submit) - stats['receive' ] = float(receive) - stats['count' ] = count - stats['expected_participants'] = expected_participants + stats['submit' ] = float(submit) + stats['receive' ] = float(receive) + stats['count' ] = count + stats['participants'] = participants print "%s" % stats log.error("stats: %s", stats)