def server_proc(): async def server(w): with w.comm.ctx.socket(zmq.REP) as new_task_socket: new_task_socket.bind(bind_addr) while not w.stop: if new_task_socket.poll(timeout=0) == 0: await asyncio.sleep(0) task_bytes = new_task_socket.recv() task = cloudpickle.loads(task_bytes) out = await w.wait_for_work(task) out_bytes = cloudpickle.dumps(out) new_task_socket.send(out_bytes) tsk.cluster(2, server)
def run_tsk_parallel(): n_cores = 2 async def submit(w): # A = np.random.rand(job_size, job_size) # r = w.memory.put(A) # def fnc(w): # A_inside = tsk.remote_get(r) # return invert(w, A_inside) fnc_dref = w.memory.put( serialized=taskloaf.serialize.dumps(lambda w: long_fnc(0))) async with tsk.profile.Profiler(w, range(n_cores)): start = time.time() out = await wait_all( [tsk.task(w, fnc_dref, to=i % n_cores) for i in range(n_jobs)]) print('inside: ', time.time() - start) return tsk.cluster(n_cores, submit)
import taskloaf as tsk from taskloaf.promise import task, when_all async def submit(w): X = 3.1 n = 10 pr = task(w, lambda w: task(w, lambda w: X)) for i in range(n): pr = pr.then(lambda w, x: x + 1) pr = when_all([pr, task(w, lambda w: X, to=1)]).then(lambda w, x: sum(x)) print('answer is', await pr) if __name__ == "__main__": tsk.cluster(2, submit)
import taskloaf as tsk async def submit(w): n = await tsk.task(w, lambda w: 10, to = 1) pr = tsk.when_all( [tsk.task(w, lambda w, i = i: i, to = i % 2) for i in range(n)] ).then(lambda w, x: sum(x)) return (await pr) if __name__ == "__main__": result = tsk.cluster(2, submit) print(result) assert(result == 45)
inner_chunk_size = int(1e9) t.report(str(w.addr) + ' setup') for i in range(0, indptr.shape[0], inner_chunk_size): _sparse.csrmv(indptr[i:(i + inner_chunk_size + 1)], indices, data, v, out[i:(i + inner_chunk_size)], False) await asyncio.sleep(0) t.report(str(w.addr) + ' dot') # return out_dref dot_dref = put_fnc(w, dot) # await run_dot() async with tsk.Profiler(w, range(0)): t.report('put/startprof') for i in range(4): print('') print('') print('') await map(w, dot_dref, len(matrix_chunks), time.time(), n_super_chunks=n_super_chunks) t.report('dot') # tsk.cluster(n_cores, submit) tsk.cluster(n_cores, submit2)
import taskloaf as tsk async def submit(w): await tsk.task(w, lambda w: print('hI')) if __name__ == "__main__": tsk.run(submit) tsk.cluster(1, submit) tsk.cluster(1, submit, runner=tsk.mpirun)
async def submit(w): async def submit2(w): print("HI!") tsk.cluster(2, submit2)
for pr in setup_prs: await pr import time start = time.time() n_tasks = 8 * 2 for j in range(10): prs = [] for i in range(n_tasks): prs.append(tsk.task(gpu_run, to=i % n_workers)) for i in range(n_tasks): await prs[i] print(time.time() - start) n_workers = 8 tsk.cluster(n_workers, submit) # # async def work_builder(): # print("YO!") # addr = tsk.get_service('comm').addr # def add_task(): # print("PEACE" + str(addr)) # return addr # rem_addr = await tsk.task(add_task, to = gpu_addr) # return (2.0, rem_addr) # # def f2(x): # return x * 2 # pr1 = tsk.task(work_builder, to = 0).then(f2)