def main(): nodes = torc.num_nodes() if nodes < 2: print("This examples needs at least two MPI processes. Exiting...") return local_workers = torc.num_local_workers() if local_workers > 1: print("This examples should use one worker thread per MPI process. Exiting...") return ntasks = 16 sequence = range(1, ntasks + 1) t0 = torc.gettime() t_all = [] for i in sequence: try: task = torc.submit(work, i, qid=1) t_all.append(task) except ValueError: print("torc.submit: invalid argument") torc.enable_stealing() torc.wait() t1 = torc.gettime() torc.disable_stealing() for task in t_all: print("Received: {}^2={}".format(task.input(), task.result())) print("Elapsed time={:.2f} s".format(t1 - t0))
def main(): ntasks = 4 sequence = range(1, ntasks + 1) t0 = torc.gettime() t_all = [] for i in sequence: task = torc.submit(work, i, callback=cb) t_all.append(task) torc.wait() t1 = torc.gettime() for task in t_all: print("Received: {}^2={}".format(task.input(), task.result())) print("Elapsed time={:.2f} s".format(t1 - t0))
def main(): ntasks = 4 sequence = range(1, ntasks + 1) t0 = torc.gettime() tasks = [] for i in sequence: task = torc.submit(work, i, xx=i + 1) tasks.append(task) torc.wait() t1 = torc.gettime() for t in tasks: print("Received: {}^2={:.3f}".format(t.input(), t.result())) print("1-Elapsed time={:.2f} s".format(t1 - t0))
def main(): ntasks = 4 sequence = range(1, ntasks + 1) t0 = torcpy.gettime() tasks = [] for i in sequence: task = torcpy.submit(work, i) tasks.append(task) torcpy.wait() t1 = torcpy.gettime() print("elapsed time={:.3f} s".format(t1-t0)) for t in tasks: inp = t.input() res = t.result() ref = work(inp) assert(res == ref)
def main(): with torc.TorcPoolExecutor(): print('with statement block') ntasks = 4 sequence = range(1, ntasks + 1) t0 = torc.gettime() tasks = [] for i in sequence: task = torc.submit(work, i) tasks.append(task) for t in torc.as_completed(tasks): print("1-Received: {}^2={:.3f}".format(t.input(), t.result())) t1 = torc.gettime() print("1-Elapsed time={:.2f} s".format(t1 - t0)) print("After first session") with torc.TorcPoolExecutor() as executor: ntasks = 4 sequence = range(1, ntasks + 1) t0 = torc.gettime() tasks = [] for i in sequence: task = executor.submit(work, i) tasks.append(task) executor.wait() t1 = torc.gettime() for t in tasks: print("2-Received: {}^2={:.3f}".format(t.input(), t.result())) print("2-Elapsed time={:.2f} s".format(t1 - t0)) print("After second session")
def main(): # tr.print_diff() ntasks = 4 # 100000 sequence = range(1, ntasks + 1) t0 = torc.gettime() tasks = [] for i in sequence: task = torc.submit(work, i) tasks.append(task) torc.wait() t1 = torc.gettime() for t in tasks: print("Received: sqrt({})={:.3f}".format(t.input(), t.result())) del tasks # tr.print_diff() print("Elapsed time={:.2f} s".format(t1 - t0))