2011-03-02 23:01:46 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-09-27 21:08:10 -07:00
|
|
|
from collections import defaultdict
|
|
|
|
from optparse import OptionParser
|
2011-03-30 17:36:28 -07:00
|
|
|
import os
|
2011-09-27 21:08:10 -07:00
|
|
|
from progressbar import ProgressBar, Percentage, Bar, ETA
|
2011-03-30 20:12:16 -07:00
|
|
|
import shelve
|
2011-09-27 21:08:10 -07:00
|
|
|
import sys
|
|
|
|
import time
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-06-07 21:37:12 -07:00
|
|
|
import numpy as np
|
|
|
|
|
2011-09-27 20:54:04 -07:00
|
|
|
from interp.cluster import QueueManager, get_qs
|
2011-06-07 21:37:12 -07:00
|
|
|
|
2011-03-02 23:01:46 -08:00
|
|
|
if __name__ == '__main__':
|
2011-09-27 20:54:04 -07:00
|
|
|
parser = OptionParser(usage="usage: %s [options] <server> <interp count>")
|
|
|
|
|
|
|
|
parser.add_option("-l", "--last-time",
|
|
|
|
action="store_true", dest="last", default=False,
|
|
|
|
help="when finished, send shutdown signal to connected nodes"
|
|
|
|
"(default: %default)")
|
|
|
|
|
|
|
|
parser.add_option('-n', '--node-count',
|
|
|
|
type="int", dest="participants", default=None,
|
|
|
|
help="specify how many participants we should wait for"
|
|
|
|
"(default: %default)")
|
|
|
|
|
|
|
|
parser.add_option('-p', '--port',
|
|
|
|
type="int", dest="port", default=6666,
|
|
|
|
help="specify the port to use on the server (default: %default)")
|
|
|
|
|
|
|
|
parser.add_option("-o", "--order",
|
|
|
|
type="int", dest="order", default=2,
|
|
|
|
help="order of interpolation (default: %default)")
|
|
|
|
|
|
|
|
parser.add_option("-e", "--extra-points",
|
|
|
|
type="int", dest="extra", default=3,
|
|
|
|
help="number of extra points (default: %default)")
|
|
|
|
|
|
|
|
parser.add_option('-s', '--shelve',
|
|
|
|
type="str", dest="shelvename",
|
|
|
|
default=os.path.expanduser('~/interp.shelve'),
|
|
|
|
help="shelve output file (default: %default)")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if len(args) != 2:
|
|
|
|
parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
server = args[0]
|
|
|
|
count = int(float(args[1]))
|
|
|
|
|
|
|
|
m = QueueManager(address=(server, options.port), authkey='asdf')
|
|
|
|
m.connect()
|
|
|
|
|
|
|
|
tasksq, resultsq, masterq, minionsq = get_qs(m)
|
|
|
|
|
|
|
|
workers = []
|
|
|
|
|
|
|
|
if not options.participants:
|
|
|
|
print "wait on all announced participants"
|
|
|
|
participants = 0
|
|
|
|
while not masterq.empty():
|
|
|
|
participants += 1
|
|
|
|
worker = masterq.get()
|
|
|
|
workers.append(worker)
|
|
|
|
print "%d: %s is ready" % (participants, worker)
|
|
|
|
if participants == 0:
|
|
|
|
print "nobody found"
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
participants = options.participants
|
|
|
|
print "wait on %d participants" % participants
|
|
|
|
for i in xrange(participants):
|
|
|
|
worker = masterq.get()
|
|
|
|
workers.append(worker)
|
|
|
|
print "%d of %d: %s is ready" % (i + 1, participants, worker)
|
|
|
|
|
|
|
|
if len(set(workers)) != len(workers):
|
|
|
|
for i in workers:
|
|
|
|
minionsq.put("slay")
|
|
|
|
raise Exception("duplicate workers reported")
|
|
|
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
widgets = ['submit jobs: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
|
|
|
pbar = ProgressBar(widgets=widgets, maxval=count)
|
|
|
|
pbar.start()
|
|
|
|
submit_start = time.time()
|
|
|
|
for i in xrange(count):
|
|
|
|
X = np.random.random((1, 3))[0]
|
|
|
|
tasksq.put((i, options.order, options.extra, X))
|
|
|
|
pbar.update(i + 1)
|
|
|
|
submit_end = time.time()
|
|
|
|
pbar.finish()
|
|
|
|
|
|
|
|
for i in xrange(participants):
|
|
|
|
print "sending worker %d start message" % (i + 1,)
|
|
|
|
minionsq.put("start")
|
|
|
|
|
|
|
|
receive_start = time.time()
|
|
|
|
widgets = ['interpolate: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
|
|
|
pbar = ProgressBar(widgets=widgets, maxval=count)
|
|
|
|
pbar.start()
|
|
|
|
for i in xrange(count):
|
|
|
|
cur_result = resultsq.get()
|
|
|
|
results.append(cur_result)
|
|
|
|
pbar.update(i + 1)
|
|
|
|
receive_end = time.time()
|
|
|
|
pbar.finish()
|
|
|
|
|
|
|
|
submit = submit_end - submit_start
|
|
|
|
receive = receive_end - receive_start
|
|
|
|
|
|
|
|
# shut down all participants
|
2011-04-02 00:32:23 -07:00
|
|
|
for i in xrange(participants):
|
2011-09-27 20:54:04 -07:00
|
|
|
if options.last:
|
|
|
|
minionsq.put("teardown")
|
|
|
|
|
|
|
|
# post processing
|
|
|
|
stats = {}
|
|
|
|
stats['submit'] = float(submit)
|
|
|
|
stats['receive'] = float(receive)
|
|
|
|
stats['count'] = count
|
|
|
|
stats['participants'] = participants
|
|
|
|
stats['extra'] = options.extra
|
|
|
|
stats['order'] = options.order
|
|
|
|
|
|
|
|
print "%s" % stats
|
|
|
|
|
|
|
|
tasks_accomplished_by = defaultdict(int)
|
|
|
|
for i in results:
|
|
|
|
tasks_accomplished_by[i[1]] += 1
|
|
|
|
stats['tasks'] = tasks_accomplished_by
|
|
|
|
|
|
|
|
npresults = np.array([(i[0], i[2], i[3], i[4], i[5]) for i in results])
|
|
|
|
|
|
|
|
n = str(time.time())
|
|
|
|
s = shelve.open(options.shelvename)
|
|
|
|
s[n] = {
|
|
|
|
'stats': stats,
|
|
|
|
'results': npresults,
|
|
|
|
}
|
|
|
|
s.close()
|