def __init__(self, site): self.tc = client.TaskClient(('127.0.0.1', 10113)) self.rc = client.MultiEngineClient(('127.0.0.1', 10105)) self.rc.execute(fetchParse) self.allLinks = [] self.linksWorking = {} self.linksDone = {} self.site = site
def main(): parser = OptionParser() parser.set_defaults(n=100) parser.set_defaults(tmin=1) parser.set_defaults(tmax=60) parser.set_defaults(controller='localhost') parser.set_defaults(meport=10105) parser.set_defaults(tport=10113) parser.add_option("-n", type='int', dest='n', help='the number of tasks to run') parser.add_option("-t", type='float', dest='tmin', help='the minimum task length in seconds') parser.add_option("-T", type='float', dest='tmax', help='the maximum task length in seconds') parser.add_option("-c", type='string', dest='controller', help='the address of the controller') parser.add_option("-p", type='int', dest='meport', help="the port on which the controller listens for the MultiEngine/RemoteController client") parser.add_option("-P", type='int', dest='tport', help="the port on which the controller listens for the TaskClient client") (opts, args) = parser.parse_args() assert opts.tmax >= opts.tmin, "tmax must not be smaller than tmin" rc = client.MultiEngineClient((opts.controller, opts.meport)) tc = client.TaskClient((opts.controller, opts.tport)) rc.block=True nengines = len(rc.get_ids()) rc.execute('from IPython.genutils import time') # the jobs should take a random time within a range times = [random.random()*(opts.tmax-opts.tmin)+opts.tmin for i in range(opts.n)] tasks = [client.Task("time.sleep(%f)"%t) for t in times] stime = sum(times) print "executing %i tasks, totalling %.1f secs on %i engines"%(opts.n, stime, nengines) time.sleep(1) start = time.time() taskids = [tc.run(t) for t in tasks] tc.barrier(taskids) stop = time.time() ptime = stop-start scale = stime/ptime print "executed %.1f secs in %.1f secs"%(stime, ptime) print "%.3fx parallel performance on %i engines"%(scale, nengines) print "%.1f%% of theoretical max"%(100*scale/nengines)
#!/usr/bin/env python # encoding: utf-8 """Run a Monte-Carlo options pricer in parallel.""" from ipython1.kernel import client import numpy as N from mcpricer import MCOptionPricer tc = client.TaskClient(('127.0.0.1', 10113)) rc = client.MultiEngineClient(('127.0.0.1', 10105)) # Initialize the common code on the engines rc.run('mcpricer.py') # Push the variables that won't change (stock print, interest rate, days and MC paths) rc.push(dict(S=100.0, r=0.05, days=260, paths=10000)) task_string = """\ op = MCOptionPricer(S,K,sigma,r,days,paths) op.run() vp, ap, vc, ac = op.vanilla_put, op.asian_put, op.vanilla_call, op.asian_call """ # Create arrays of strike prices and volatilities K_vals = N.arange(90.0, 110.0, 2.0) sigma_vals = N.arange(0.02, 0.3, 0.02) # Submit tasks taskids = [] for K in K_vals: for sigma in sigma_vals: