smbinterp/bin/slave.py

78 lines
1.8 KiB
Python
Raw Normal View History

2011-03-02 22:51:43 -08:00
#!/usr/bin/env python
import sys
2011-03-31 20:19:20 -07:00
import os
2011-03-30 22:09:10 -07:00
import time
2011-03-02 22:51:43 -08:00
from multiprocessing.managers import BaseManager
2011-03-30 09:36:20 -07:00
from optparse import OptionParser
import datetime
2011-03-30 09:36:20 -07:00
2011-03-02 23:20:03 -08:00
import numpy as np
2011-03-02 22:51:43 -08:00
import interp.bootstrap
2011-03-30 09:36:20 -07:00
from interp.grid.gmsh import ggrid
from interp.tools import baker_exact_3D as exact
2011-03-02 22:51:43 -08:00
2011-04-01 23:10:29 -07:00
from interp.cluster import QueueManager, get_qs
2011-03-02 22:51:43 -08:00
2011-04-01 23:10:29 -07:00
def keep_working(controls):
pass
2011-04-01 23:10:29 -07:00
def work(inq, outq, g, myname):
pass
2011-03-02 22:51:43 -08:00
if __name__ == '__main__':
2011-03-30 09:36:20 -07:00
parser = OptionParser(usage = "usage: %s [options] <server> <gmsh file>")
2011-04-01 23:10:29 -07:00
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="verbose flag (display progress bar: %default)")
2011-03-30 09:36:20 -07:00
parser.add_option('-p', '--port',
type="int", dest="port", default=6666,
2011-03-30 09:36:20 -07:00
help="specify the port to use on the server (default: %default)")
(options, args) = parser.parse_args()
2011-03-30 09:36:20 -07:00
if len(args) != 2:
parser.print_usage()
2011-03-02 22:51:43 -08:00
sys.exit(1)
2011-03-30 09:36:20 -07:00
server, input_file = args
m = QueueManager(address=(server, options.port), authkey='asdf')
2011-03-02 22:51:43 -08:00
m.connect()
2011-04-01 23:10:29 -07:00
tasksq, resultsq, masterq, slavesq = get_qs(m)
2011-03-02 22:51:43 -08:00
2011-03-30 09:36:20 -07:00
g = ggrid(input_file)
2011-03-02 23:20:03 -08:00
g.q = np.array([exact(x) for x in g.verts])
2011-03-31 20:19:20 -07:00
myname = "%s-%d" % (os.uname()[1], os.getpid())
2011-04-01 23:10:29 -07:00
if options.verbose:
print myname
2011-03-30 22:09:10 -07:00
2011-04-01 23:10:29 -07:00
while True:
# indicate that I am loaded up, and ready for workload
masterq.put(myname)
# wait for master's start signal
action = slavesq.get()
if action == "teardown":
break
while not tasksq.empty():
i, o, e, X = tasksq.get()
try:
a = g.run_baker(X, order = o, extra_points = e)
resultsq.put((i, myname, a['qlin'], a['error'], a['final'], exact(X)))
except Exception as e:
print X, e
resultsq.put((i, myname, 0.0, 0.0, 0.0, 0.0))
if options.verbose:
print "exiting"