def get_targets(ipyclient):
<EOL>hosts = []<EOL>for eid in ipyclient.ids:<EOL><INDENT>engine = ipyclient[eid]<EOL>if not engine.outstanding:<EOL><INDENT>hosts.append(engine.apply(socket.gethostname))<EOL><DEDENT><DEDENT>hosts = [i.get() for i in hosts]<EOL>hostset = set(hosts)<EOL>hostzip = zip(hosts, ipyclient.ids)<EOL>hostdict = {host: [i[<NUM_LIT:1>] for i in hostzip if i[<NUM_LIT:0>] == host] for host in hostset}<EOL>targets = list(itertools.chain(*[hostdict[i][:<NUM_LIT:2>] for i in hostdict]))<EOL>return targets<EOL>
A function to find 2 engines per hostname on the ipyclient.
We'll assume that the CPUs are hyperthreaded, which is why
we grab two. If they are not then no foul. Two multi-threaded
jobs will be run on each of the 2 engines per host.