2011-03-02 23:01:46 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-03-02 23:38:47 -08:00
|
|
|
import sys
|
2011-03-30 17:36:28 -07:00
|
|
|
import os
|
2011-03-02 23:38:47 -08:00
|
|
|
|
2011-03-30 15:04:49 -07:00
|
|
|
import time
|
|
|
|
|
2011-03-30 20:12:16 -07:00
|
|
|
import shelve
|
|
|
|
from progressbar import *
|
|
|
|
from collections import defaultdict
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
2011-03-02 23:01:46 -08:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import interp.bootstrap
|
|
|
|
|
2011-03-30 15:04:49 -07:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger("interp")
|
|
|
|
|
2011-04-01 23:10:29 -07:00
|
|
|
from interp.cluster import QueueManager, get_qs
|
2011-03-30 21:00:13 -07:00
|
|
|
|
2011-03-02 23:01:46 -08:00
|
|
|
if __name__ == '__main__':
|
2011-04-01 23:34:54 -07:00
|
|
|
parser = OptionParser(usage = "usage: %s [options] <server> <interp count>")
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-03-30 21:00:13 -07:00
|
|
|
parser.add_option("-l", "--last-time",
|
|
|
|
action="store_true", dest="last", default=False,
|
2011-04-01 23:34:54 -07:00
|
|
|
help="when finished, send shutdown signal to connected nodes (default: %default)")
|
2011-03-30 21:00:13 -07:00
|
|
|
|
2011-04-02 00:32:23 -07:00
|
|
|
parser.add_option('-n', '--node-count',
|
|
|
|
type="int", dest="participants", default=None,
|
|
|
|
help="specify how many participants we should wait for (default: %default)")
|
|
|
|
|
2011-03-30 20:12:16 -07:00
|
|
|
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)")
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-03-30 20:12:16 -07:00
|
|
|
(options, args) = parser.parse_args()
|
2011-04-02 00:21:43 -07:00
|
|
|
if len(args) != 2:
|
2011-03-30 20:12:16 -07:00
|
|
|
parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
server = args[0]
|
2011-04-02 00:43:55 -07:00
|
|
|
count = int(float(args[1]))
|
2011-03-30 20:12:16 -07:00
|
|
|
|
|
|
|
m = QueueManager(address=(server, options.port), authkey='asdf')
|
|
|
|
m.connect()
|
2011-03-02 23:38:47 -08:00
|
|
|
|
2011-04-01 23:10:29 -07:00
|
|
|
tasksq, resultsq, masterq, slavesq = get_qs(m)
|
2011-03-02 23:01:46 -08:00
|
|
|
|
2011-04-02 00:32:23 -07:00
|
|
|
if not options.participants:
|
|
|
|
print "wait on all announced participants"
|
|
|
|
participants = 0
|
|
|
|
while not masterq.empty():
|
|
|
|
participants += 1
|
|
|
|
worker = masterq.get()
|
|
|
|
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()
|
|
|
|
print "%d of %d: %s is ready" % (i+1, participants, worker)
|
2011-04-01 23:10:29 -07:00
|
|
|
|
|
|
|
results = []
|
|
|
|
|
2011-04-02 01:01:22 -07:00
|
|
|
widgets = ['submit jobs: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
|
|
|
pbar = ProgressBar(widgets = widgets, maxval = count)
|
|
|
|
pbar.start()
|
2011-04-01 23:10:29 -07:00
|
|
|
submit_start = time.time()
|
|
|
|
for i in xrange(count):
|
|
|
|
X = np.random.random((1,3))[0]
|
|
|
|
tasksq.put((i, options.order, options.extra, X))
|
2011-04-02 01:01:22 -07:00
|
|
|
pbar.update(i+1)
|
2011-04-01 23:10:29 -07:00
|
|
|
submit_end = time.time()
|
2011-04-02 01:01:22 -07:00
|
|
|
pbar.finish()
|
2011-04-01 23:10:29 -07:00
|
|
|
|
2011-04-01 23:34:54 -07:00
|
|
|
for i in xrange(participants):
|
2011-04-02 00:21:43 -07:00
|
|
|
print "sending worker %d start message" % (i+1,)
|
2011-04-01 23:10:29 -07:00
|
|
|
slavesq.put("start")
|
|
|
|
|
|
|
|
receive_start = time.time()
|
2011-04-02 01:01:22 -07:00
|
|
|
widgets = ['interpolate: ', Percentage(), ' ', Bar(), ' ', ETA()]
|
2011-04-01 23:10:29 -07:00
|
|
|
pbar = ProgressBar(widgets = widgets, maxval = count)
|
|
|
|
pbar.start()
|
|
|
|
for i in xrange(count):
|
|
|
|
results.append(resultsq.get())
|
|
|
|
pbar.update(i+1)
|
|
|
|
receive_end = time.time()
|
|
|
|
pbar.finish()
|
|
|
|
|
|
|
|
submit = submit_end - submit_start
|
|
|
|
receive = receive_end - receive_start
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-03-30 17:36:28 -07:00
|
|
|
# shut down all participants
|
2011-04-01 23:34:54 -07:00
|
|
|
for i in xrange(participants):
|
2011-04-01 23:10:29 -07:00
|
|
|
if options.last:
|
|
|
|
slavesq.put("teardown")
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-03-30 20:12:16 -07:00
|
|
|
# post processing
|
2011-03-30 17:36:28 -07:00
|
|
|
stats = {}
|
2011-04-01 23:34:54 -07:00
|
|
|
stats['submit' ] = float(submit)
|
|
|
|
stats['receive' ] = float(receive)
|
|
|
|
stats['count' ] = count
|
|
|
|
stats['participants'] = participants
|
2011-03-30 15:04:49 -07:00
|
|
|
|
2011-04-01 23:10:29 -07:00
|
|
|
print "%s" % stats
|
2011-03-30 17:36:28 -07:00
|
|
|
log.error("stats: %s", stats)
|
2011-03-30 20:12:16 -07:00
|
|
|
|
|
|
|
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])
|
|
|
|
|
|
|
|
s = shelve.open(options.shelvename)
|
|
|
|
n = str(time.time())
|
|
|
|
s[n] = {
|
|
|
|
'stats' : stats,
|
|
|
|
'results' : npresults,
|
|
|
|
}
|
|
|
|
s.close()
|