-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_charm4py_pool_executor.py
63 lines (46 loc) · 1.4 KB
/
test_charm4py_pool_executor.py
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
from charm4py import entry_method, chare, Chare, Array, Reducer, Future, charm
from charm4py.pool import PoolScheduler, Pool, PoolExecutor
from charm4py.charm import Charm, CharmRemote
import numpy as np
from time import sleep
def multiply(a,b):
sleep(10*np.random.rand())
return a*b
def main(arg):
data = np.arange(1,100)
pool_proxy = Chare(PoolScheduler, onPE=0)
executor = PoolExecutor(pool_proxy)
#result = executor.map(multiply, data, data)
#print(result)
#print(list(zip(data, data, result)))
futures = [executor.submit(multiply, entry, entry) for entry in data]
from concurrent.futures import wait
from time import time, sleep
futures[0].set_running_or_notify_cancel()
for future in futures:
print(future._state)
#future.set_running_or_notify_cancel()
#future.deposit(5)
#future.send(result=5)
#futures[0].get()
for future in futures:
#print("Called GET at time", time())
print(future.values)
#print(future.gotvalues)
#print(future)
#future.cancel()
#future()
#print(future)
"""
for future in futures:
#print(future._state)
future.set_running_or_notify_cancel()
sleep(3)
for future in futures:
print(future._state)
"""
#wait(futures)
exit()
charm.start(main)
exit() # charm.exit freezes the program
charm.exit()