class AmuseProcessor(object): def __init__(self, hosts=[], preamble="pass", channel_type="mpi", verbose=False): from amuse.ext.job_server import JobServer self.preamble = preamble self.amuse_servers = hosts self.job_server = JobServer(self.amuse_servers, channel_type=channel_type, preamble=self.preamble, verbose=verbose, no_wait=True) @property def nproc(Self): return self.job_server.number_available_codes def exec_(self, arg): self.job_server.exec_(arg) def submit_job(self, f, args=(), kwargs={}): return self.job_server.submit_job(f, args, kwargs) def wait(self): return self.job_server.wait() @property def last_finished_job(self): return self.job_server.last_finished_job
def example_parallel_jobs_1(N): from socket import gethostname jobserver=JobServer(["localhost"]*2,channel_type="mpi") print for i in range(N): jobserver.submit_job(somework, (i,)) i=0 while jobserver.wait(): job=jobserver.last_finished_job print job.args[0],job.result
def example_parallel_jobs_1(N): from socket import gethostname jobserver = JobServer(["localhost"] * 2, channel_type="mpi") print for i in range(N): jobserver.submit_job(somework, (i, )) i = 0 while jobserver.wait(): job = jobserver.last_finished_job print job.args[0], job.result
def example_parallel_jobs(N,Nhosts=1): jobserver=JobServer(hosts=[gethostname()]*Nhosts) for i in range(N): jobserver.submit_job(new_plummer_model, (i,)) result=dict() while jobserver.wait(): job=jobserver.last_finished_job result[job.args[0]]=job.result return result
def example_parallel_jobs(N, Nhosts=1): jobserver = JobServer(hosts=[gethostname()] * Nhosts) for i in range(1, N + 1): jobserver.submit_job(new_plummer_model, (i, )) result = dict() while jobserver.wait(): job = jobserver.last_finished_job result[job.args[0]] = job.result return result