Debian Codegraph @

dev/benchmarks/openmp/test_openmp_1.py

raw
1 import sys, os, numpy, time, pylab
2
3 filename = 'CUBA_standalone.py'
4 datapath = 'data_cuba'
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
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 vms = numpy.fromfile(path+'results/_array_neurongroup_v', dtype=numpy.float64)
22 w = numpy.fromfile(path+'results/_dynamic_array_synapses_1_w', dtype=numpy.float64)
23 results[t]['spikes'] = (times, ids)
24 results[t]['vms'] = vms
25 results[t]['w'] = w
26
27 pylab.figure()
28 pylab.subplot(221)
29 pylab.title('Raster plots')
30 pylab.xlabel('Time [s]')
31 pylab.ylabel('# cell')
32 for t in threads:
33 pylab.plot(results[t]['spikes'][0], results[t]['spikes'][1], '.')
34 pylab.legend([str(t) for t in threads])
35 pylab.xlim(0.5, 0.55)
36
37 pylab.subplot(222)
38 pylab.title('Mean Rates')
39 pylab.xlabel('Time [s]')
40 pylab.ylabel('Rate [Hz]')
41 for t in threads:
42 x, y = numpy.histogram(results[t]['spikes'][0], 100)
43 pylab.plot(y[1:], x)
44 pylab.legend([str(t) for t in threads])
45
46
47 pylab.subplot(223)
48 pylab.title('Network')
49 pylab.xlabel('# threads')
50 pylab.ylabel('Number of synapses')
51 r = []
52 for t in threads:
53 r += [len(results[t]['w'])]
54 pylab.bar(threads, r)
55 pylab.ylim(min(r)-1000, max(r)+1000)
56
57 pylab.subplot(224)
58 pylab.title('Speed')
59 pylab.plot(threads, results['duration'])
60 pylab.xlabel('# threads')
61 pylab.ylabel('Time [s]')
62
63 pylab.tight_layout()
64 pylab.savefig('cuba_openmp.png')
65
66
67 pylab.show()