smbinterp/bin/slave.py

58 lines
1.4 KiB
Python

#!/usr/bin/env python
import sys
from multiprocessing.managers import BaseManager
from optparse import OptionParser
import numpy as np
import interp.bootstrap
from interp.grid.gmsh import ggrid
from interp.tools import baker_exact_3D as exact
class QueueManager(BaseManager): pass
QueueManager.register('get_inqueue' )
QueueManager.register('get_outqueue')
if __name__ == '__main__':
parser = OptionParser(usage = "usage: %s [options] <server> <gmsh file>")
parser.add_option('-l', '--label',
type="str", dest="label", default='jane',
help="specify this slave's response label (default: %default)")
parser.add_option('-p', '--port',
type="int", dest="port", default='6666',
help="specify the port to use on the server (default: %default)")
(options, args) = parser.parse_args()
if len(args) != 2:
parser.print_usage()
sys.exit(1)
server, input_file = args
myname = options.label
m = QueueManager(address=(server, 50000), authkey='asdf')
m.connect()
inq = m.get_inqueue()
outq = m.get_outqueue()
g = ggrid(input_file)
g.q = np.array([exact(x) for x in g.verts])
outq.put((myname, "ready"))
while True:
i, o, e, X = inq.get()
if i == None:
break
a = g.run_baker(X, order = o, extra_points = e)
outq.put((i, myname, a['qlin'], a['error'], a['final'], exact(X)))
print "%s finished" % myname