smbinterp/bin/slave.py

78 lines
1.8 KiB
Python

#!/usr/bin/env python
import sys
import os
import time
from multiprocessing.managers import BaseManager
from optparse import OptionParser
import datetime
import numpy as np
import interp.bootstrap
from interp.grid.gmsh import ggrid
from interp.tools import baker_exact_3D as exact
from interp.cluster import QueueManager, get_qs
def keep_working(controls):
pass
def work(inq, outq, g, myname):
pass
if __name__ == '__main__':
parser = OptionParser(usage = "usage: %s [options] <server> <gmsh file>")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="verbose flag (display progress bar: %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
m = QueueManager(address=(server, options.port), authkey='asdf')
m.connect()
tasksq, resultsq, masterq, slavesq = get_qs(m)
g = ggrid(input_file)
g.q = np.array([exact(x) for x in g.verts])
myname = "%s-%d" % (os.uname()[1], os.getpid())
if options.verbose:
print myname
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"