Exemple #1
0
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():
    data = range(10)
    tasks = []
    for d in data:
        tasks.append(torc.submit(work, d))
    torc.wait()
    for t in tasks:
        print(t.result())
Exemple #3
0
def main():
    data = range(10)

    tasks = []
    for d in data:
        t = torc.submit(work, d, callback=cb)
        tasks.append(t)

    torc.wait()
    print("Sum=", sum_v)  # should be 285 = 0^2 + 1^2 + ... + 9^2
Exemple #4
0
def fib(n):
    if n == 0:
        result = 0
    elif n == 1:
        result = 1
    else:
        n_1 = n - 1
        n_2 = n - 2
        if n < 30:
            result1 = fib(n_1)
            result2 = fib(n_2)
            result = result1 + result2
        else:
            task1 = torc.submit(fib, n_1)
            task2 = torc.submit(fib, n_2)
            torc.wait()
            result = task1.result() + task2.result()

    return result
Exemple #5
0
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))
Exemple #6
0
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))
Exemple #7
0
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)
Exemple #8
0
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))