print( "work inp={:.3f}, kwargs={}, out={:.3f} ...on node {:d} worker {} thread {}" .format(x, kwargs, y, torc.node_id(), torc.worker_id(), threading.get_ident()), flush=True) return y 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)) if __name__ == '__main__': torc.start(main)
def test_masterworker(nworkers): os.environ["TORCPY_WORKERS"] = str(nworkers) torcpy.start(main)