Ejemplo n.º 1
0
async def submit():
    gang = await tsk.ctx().wait_for_workers(2)
    X = 3.1
    n = 10
    pr = tsk.task(lambda: tsk.task(lambda: X))
    for i in range(n):
        pr = pr.then(lambda x: x + 1)

    async def asum(x):
        return sum(x)

    pr = tsk.when_all([pr, tsk.task(lambda: X, to=gang[1])]).then(asum)
    print("answer is", await pr)
Ejemplo n.º 2
0
async def submit():
    setup_prs = [
        tsk.task(lambda i=i: setup_gpu_server(i), to=i)
        for i in range(n_workers)
    ]
    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)
Ejemplo n.º 3
0
 async def f():
     gang = await tsk.ctx().wait_for_workers(2)
     fnc_dref = tsk.put(long_fnc)
     async with tsk.Profiler(gang):
         start = time.time()
         await wait_all([
             tsk.task(fnc_dref, to=gang[i % len(gang)])
             for i in range(n_jobs)
         ])
         print("inside: ", time.time() - start)
Ejemplo n.º 4
0
    async def dot(self, v_ref):
        out = TskArray(size=self.shape[0])
        jobs = []
        for i in range(len(self.chunks)):
            jobs.append(
                tsk.task(self.dot_fnc_refs[i], v_ref, out, to=self.gang[i])
            )

        for i in range(len(jobs)):
            await jobs[i]
        return await out.array()
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
async def map_helper(w, f, N_low, N_high, core_range, *args):
    t = tsk.Timer(None)
    n_chunks = len(core_range)
    chunk_bounds = np.linspace(N_low, N_high, n_chunks + 1).astype(np.int32)
    out_chunks = [
        tsk.task(w,
                 f, [chunk_bounds[i], chunk_bounds[i + 1]] + list(args),
                 to=core_range[i]) for i in range(n_chunks)
    ]
    t.report('submit map')
    results = []
    for c in out_chunks:
        results.append(await c)
    t.report('wait map')
    return results
Ejemplo n.º 7
0
def test_tree():
    ctx = taskloaf.launch_local(1)

    def empty_tree():
        return (None, None, 0)

    def insert(tree, val):
        def insert_helper(node):
            if val < node[2]:
                if node[0] is not None:
                    return (node[0].then(insert_helper), node[1], node[2])
                else:
                    return (taskloaf.ready((None,None,val)), node[1], node[2])
            else:
                if node[1] is not None:
                    return (node[0], node[1].then(insert_helper), node[2])
                else:
                    return (node[0], taskloaf.ready((None,None,val)), node[2])
        return tree.then(insert_helper)

    def concat(first_str, second_str):
        return (first_str
            .then(lambda s1: second_str.then(lambda s2: s1 + s2))
            .unwrap())

    def print_tree(tree):
        def print_helper(t, indent):
            out = taskloaf.ready('    ' * indent + str(t[2]) + '\n')
            if t[0] != None:
                out = concat(out, t[0].then(lambda t: print_helper(t, indent + 1)).unwrap())
            if t[1] != None:
                out = concat(out, t[1].then(lambda t: print_helper(t, indent + 1)).unwrap())
            return out
        return tree.then(lambda t: print_helper(t, 0)).unwrap()

    t = taskloaf.task(empty_tree)
    values = [random.randint(-10000, 10000) for i in range(10)]
    for v in values:
        t = insert(t, v)
    # print("")
    # print("")
    # print("")
    print(print_tree(t).get())
Ejemplo n.º 8
0
def test_task():
    ctx = taskloaf.launch_local(1)
    def return1():
        return 1
    fut = taskloaf.task(return1)
    assert(fut.get() == 1)
Ejemplo n.º 9
0
 def func():
     return taskloaf.task(lambda: 10)
Ejemplo n.º 10
0
def test_unwrap():
    ctx = taskloaf.launch_local(1)
    def func():
        return taskloaf.task(lambda: 10)
    assert(taskloaf.task(func).unwrap().get() == 10)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
def test_send_task():
    ctx = taskloaf.launch_mpi()
    assert(taskloaf.task(1, fnc).get() == 10)
Ejemplo n.º 13
0
 async def start(self):
     self.prof_tasks = [
         tsk.task(self.w, start_profiler, to=addr) for addr in self.addrs
     ]
     for pt in self.prof_tasks:
         await pt
Ejemplo n.º 14
0
 async def start(self):
     self.prof_tasks = [tsk.task(start_profiler, to=n) for n in self.names]
     for pt in self.prof_tasks:
         await pt