def fib(n):
    if n <= 1:
        return n
    else:
        child1 = rt.spawn(fib, (n-1,))
        child2 = rt.spawn(fib, (n-2,))
        return child1.wait() + child2.wait()
def handler(event, context):
    qsize = event["qsize"]
    q1 = rt.create_queue(qsize)
    q2 = rt.create_queue(qsize)
    rt.spawn(child, (q1, q2))
    q1.enqueue("ping")
    return q2.dequeue()
def fib(n):
    if n <= 1:
        return n
    else:
        return rt.spawn(fib,
                        (n - 1, ), blocking=True) + rt.spawn(fib, (n - 2, ),
                                                             blocking=True)
Beispiel #4
0
def fib(n):
    rt.pause()
    if n <= 1:
        return n
    else:
        child = rt.spawn(fib, (n-2,))
        return fib(n-1) + child.wait()
Beispiel #5
0
def handler(event, context):
    num_tasks = event["num_tasks"]
    num_workers = event["num_workers"]

    work_queue = rt.create_queue(max_size=num_tasks + num_workers)
    futures = rt.spawn_many(work, (work_queue, ), copies=num_workers)
    work_queue.enqueue(*range(num_tasks))
    work_queue.enqueue(*([None] * num_workers))  # Sentinels.

    return rt.spawn(aggregate, futures, blocking=True)
def parallel_sum(l, r):
    """Computes (l + (l+1) + ... + r)."""
    # TODO(zhangwen): this function can either return an int or a future; this seems confusing...
    if l == r:
        return l

    m = (l + r) // 2
    sl = parallel_sum(l, m)
    sr = parallel_sum(m + 1, r)
    return rt.spawn(operator.add, (sl, sr))
def handler(event, _context):
    num_spawns = int(event["num_spawns"])
    chkpt_size = int(event["chkpt_size"] * 2**20)
    data = b"x" * chkpt_size

    for i in range(num_spawns):
        # TODO(zhangwen): should enable a process to find out its own pid.
        predicted_pid = i + 2
        fut = spawn(child, (predicted_pid, data))
        assert predicted_pid == fut.pid
        fut.wait()
Beispiel #8
0
def handler(event, _):
    num_workers = event["num_workers"]
    num_chunks = event["num_chunks"]

    work_queue = create_queue(max_size=num_workers * 10)
    agg_queue = create_queue(max_size=num_workers * 10)
    workers = map_spawn(worker,
                        range(num_workers),
                        extra_args=(work_queue, agg_queue))
    agg = spawn(aggregate, (
        num_workers,
        agg_queue,
    ))

    work_queue.enqueue(*range(num_chunks))
    work_queue.enqueue(*([None] * num_workers))
    spawn(waiter, workers, blocking=True)  # Wait for all workers to complete.

    agg_queue.enqueue((None, None, None))
    agg.wait()
Beispiel #9
0
def handler(event: Dict[str, Any], _):
    num_chunks = event["num_chunks"]
    num_mappers = event["num_mappers"]
    num_reducers = event["num_reducers"]

    mapper_ranges = make_mapper_ranges(num_chunks, num_mappers)
    mappers = map_spawn(mapper,
                        zip(range(num_mappers), mapper_ranges),
                        extra_args=(num_reducers, ))
    reducers = map_spawn(reducer,
                         range(num_reducers),
                         extra_args=[num_mappers] + mappers)

    # I would just spawn `max` (Python built-in), but `max` throws an exception if it's only passed one value...
    return spawn(my_max, reducers, blocking=True)
def handler(event, _):
    message_size = int(event["message_size"] * 2**20)
    num_messages = event["num_messages"]

    print("Message size = {}".format(message_size))

    ping = rt.create_queue(max_size=1)
    pong = rt.create_queue(max_size=1)

    fut = rt.spawn(child, (ping, pong))

    for i in range(num_messages):
        print("send: {}, {}".format(i, time.time()))
        ping.enqueue([i, "x" * message_size])
        pong.dequeue()
        time.sleep(1)

    ping.enqueue((None, None))
    fut.wait()
def handler(event, _context):
    n = event["n"]
    magic_fut = rt.spawn(make_magic, ())
    futs = rt.map_spawn(odd, range(n), extra_args=(magic_fut, ))
    return rt.spawn(my_sum, futs, blocking=True)
Beispiel #12
0
def handler(_event, _context):
    assert_on_coordinator()

    f1 = rt.spawn(on_coordinator_child, ())
    f2 = rt.spawn(on_lambda_child, ())
    return f1.wait() + f2.wait()