-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parallel.py
81 lines (72 loc) · 2.16 KB
/
test_parallel.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# TODO: this test file is not up to date,
# but no longer needed as parallelisation works
from functions import *
import matplotlib.pyplot as plt
from time import time
from datetime import datetime
from dask import delayed, compute
import dask.multiprocessing
dask.config.set(scheduler='processes')
import argparse
parser = argparse.ArgumentParser(
description='testing parameters')
parser.add_argument(
'-n', '--max_threads',
type=int, default=60
)
parser.add_argument(
'-s', '--savefig',
action='store_true'
)
parser.add_argument(
'-c', '--coherence',
type=float, default=0.5
)
parser.add_argument(
'-l', '--lambda_',
type=float, default=0.8
)
parser.add_argument(
'-p', '--plasticity',
action='store_true'
)
parser.add_argument(
'-f', '--usefitted',
action='store_true'
)
args = parser.parse_args()
# proper `if __name__...` idiom needed for parallel processing
if __name__ == '__main__':
title_suffix = ''
if args.savefig:
for key,value in vars(args).items():
if key not in ['savefig', 'max_threads']:
title_suffix += f'{key}:{value} '
title_suffix += f'\np:{p} w+:{w_plus} fitted:{args.usefitted}'
sim_delayed = delayed(simulate_original)
max_threads = args.max_threads
times = np.empty(max_threads, dtype=float)
for i in range(1, max_threads+1):
print(f"itr {i}/{max_threads}:", end='\t')
start = time()
computations = [
sim_delayed(
coherence=args.coherence,
lambda_=args.lambda_,
plasticity=args.plasticity,
use_phi_fitted=args.usefitted
) for k in range(i)
]
result = compute(computations)
end = time()
times[i-1] = end-start
print(f"time taken: {times[i-1]:.2f} seconds")
if args.savefig:
plt.plot(np.arange(1, max_threads+1), times)
plt.xlabel('number of processes')
plt.ylabel('time taken (seconds)')
plt.title(
f'Parallelisation Speeds\n' + title_suffix)
plt.savefig(
f'parallelisation_speeds_{datetime.now()}.png'
)