File: vine_python_future_hof.py

package info (click to toggle)
cctools 1%3A7.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 36,956 kB
  • sloc: ansic: 114,614; python: 29,532; cpp: 20,313; sh: 13,675; perl: 4,056; xml: 3,688; makefile: 1,436
file content (60 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env python

import sys
import ndcctools.taskvine as vine

port_file = None
try:
    port_file = sys.argv[1]
except IndexError:
    sys.stderr.write("Usage: {} PORTFILE\n".format(sys.argv[0]))
    raise

def main():
    executor = vine.FuturesExecutor(
        port=[9123, 9129], manager_name="vine_hof_test", factory=False
    )

    print("listening on port {}".format(executor.manager.port))
    with open(port_file, "w") as f:
        f.write(str(executor.manager.port))

    nums = list(range(101))

    rows = 3
    mult_table = executor.allpairs(lambda x, y: x*y, range(rows), nums, chunk_size=11).result()
    assert sum(mult_table[1]) == sum(nums)
    assert sum(sum(r) for r in mult_table) == sum(sum(nums) * n for n in range(rows))

    doubles = executor.map(lambda x: 2*x, nums, chunk_size=10).result()
    assert sum(doubles) == sum(nums)*2

    doubles = executor.map(lambda x: 2*x, nums, chunk_size=13).result()
    assert sum(doubles) == sum(nums)*2

    maximum = executor.reduce(max, nums, fn_arity=2).result()
    assert maximum == 100

    maximum = executor.reduce(max, nums, fn_arity=25).result()
    assert maximum == 100

    maximum = executor.reduce(max, nums, fn_arity=1000).result()
    assert maximum == 100

    maximum = executor.reduce(max, nums, fn_arity=2, chunk_size=50).result()
    assert maximum == 100

    minimum = executor.reduce(min, nums, fn_arity=2, chunk_size=50).result()
    assert minimum == 0

    total = executor.reduce(sum, nums, fn_arity=11, chunk_size=13).result()
    assert total == sum(nums)




if __name__ == "__main__":
    main()


# vim: set sts=4 sw=4 ts=4 expandtab ft=python: