Debian Codegraph @

dev/benchmarks/openmp/test_openmp_2.py

raw
1 import sys, os, numpy, time, pylab
2
3 filename = 'STDP_standalone.py'
4 datapath = 'data_stdp'
5 threads = [0, 1, 2, 4, 6]
6 results = {}
7 results['duration'] = []
8
9 for t in threads:
10 start = time.time()
11 os.system('python %s 1 %d' %(filename, t))
12 with open('%s_%d/speed.txt' %(datapath, t), 'r') as f:
13 results['duration'] += [float(f.read())]
14 results[t] = {}
15
16 for t in threads:
17 results[t] = {}
18 path = datapath + '_%d/' %t
19 ids = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_i', dtype=numpy.int32)
20 times = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_t', dtype=numpy.float64)
21 w = numpy.fromfile(path+'results/_dynamic_array_synapses_w', dtype=numpy.float64)
22 times_2 = numpy.fromfile(path+'results/_dynamic_array_statemonitor_t', dtype=numpy.float64)
23 w_over_time = numpy.fromfile(path+'results/_dynamic_array_statemonitor__recorded_w', dtype=numpy.float64)
24 results[t]['spikes'] = (times, ids)
25 results[t]['w'] = w
26 results[t]['trace_w'] = (times_2, w_over_time)
27
28 pylab.figure()
29 pylab.subplot(221)
30 pylab.title('Raster plots')
31 pylab.xlabel('Time [s]')
32 pylab.ylabel('# cell')
33 for t in threads:
34 pylab.plot(results[t]['spikes'][0], results[t]['spikes'][1], '.')
35 pylab.legend([str(t) for t in threads])
36 pylab.xlim(0.5, 0.55)
37
38 pylab.subplot(222)
39 pylab.title('Weight Evolution')
40 pylab.xlabel('Time [s]')
41 pylab.ylabel('Weight [ns]')
42 for t in threads:
43 pylab.plot(results[t]['trace_w'][0], results[t]['trace_w'][1])
44 pylab.legend([str(t) for t in threads])
45
46 pylab.subplot(223)
47 pylab.title('Final Distribution')
48 pylab.xlabel('Weight [ns]')
49 pylab.ylabel('Number of synapses')
50 for t in threads:
51 x, y = numpy.histogram(results[t]['w'], 100)
52 pylab.plot(y[1:], x)
53 pylab.legend([str(t) for t in threads])
54
55 pylab.subplot(224)
56 pylab.title('Speed')
57 pylab.plot(threads, results['duration'])
58 pylab.xlabel('# threads')
59 pylab.ylabel('Time [s]')
60
61 pylab.tight_layout()
62
63 pylab.savefig('STDP_openmp.png')
64
65 pylab.show()