-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pool_spawn_RF.py
More file actions
38 lines (32 loc) · 1.06 KB
/
Copy pathtest_pool_spawn_RF.py
File metadata and controls
38 lines (32 loc) · 1.06 KB
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
# -*- mode: python -*-
# test_pool_spawn_RF.py
# sage -ipython # un iPython qui sait trouver les librairies
# # de SageMath-10-6.app sur macOS
# Puis par exemple:
# from test_pool_spawn_RF import bar as spawn_bar
from sage.rings.real_mpfr import RealField
import time
import multiprocessing as mp
def worker(args):
a, data, precision = args
R = RealField(precision)
x = R(data)
result = x.sin()
return result
def bar(numcalls=100,
ncpus=8,
data_list=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
precision=100,
check=False):
mp.set_start_method('spawn', force=True)
print("Setting multiprocessing start method to 'spawn'")
with mp.Pool(processes=ncpus) as pool:
for i in range(numcalls):
inputs = [(a, data_list[a], precision) for a in range(ncpus)]
results = pool.map(worker, inputs)
if check:
print(results)
return None
if __name__ == "__main__":
mp.set_start_method('spawn', force=True)
print("Setting multiprocessing start method to 'spawn'")