Debian Codegraph @

dev/benchmarks/openmp/example_standalone_bis.py

raw
1 #!/usr/bin/env python
2 # coding: latin-1
3 """
4 CUBA example with delays.
5 """
6
7 import sys, time, os
8 from brian2 import *
9
10 standalone = int(sys.argv[-2])
11 n_threads = int(sys.argv[-1])
12 path = 'data_example_bis_%d' %n_threads
13
14 if standalone == 1:
15 set_device('cpp_standalone')
16 brian_prefs.codegen.cpp_standalone.openmp_threads = n_threads
17
18 start = time.time()
19 n_cells = 1000
20
21 numpy.random.seed(42)
22 connectivity = numpy.random.randn(n_cells, n_cells)
23
24 taum = 20 * ms
25 taus = 5 * ms
26 Vt = -50 * mV
27 Vr = -60 * mV
28 El = -49 * mV
29
30 fac = (60 * 0.27 / 10) # excitatory synaptic weight (voltage)
31
32 gmax = 20*fac
33 dApre = .01
34 taupre = 20 * ms
35 taupost = taupre
36 dApost = -dApre * taupre / taupost * 1.05
37 dApost *= 0.1*gmax
38 dApre *= 0.1*gmax
39
40
41 eqs = Equations('''
42 dv/dt = (g-(v-El))/taum : volt
43 dg/dt = -g/taus : volt
44 ''')
45
46 P = NeuronGroup(n_cells, model=eqs, threshold='v>Vt', reset='v=Vr', refractory=5 * ms)
47 P.v = Vr + numpy.random.rand(len(P)) * (Vt - Vr)
48 P.g = 0 * mV
49
50
51
52 S = Synapses(P, P,
53 model = '''dApre/dt=-Apre/taupre : 1 (event-driven)
54 dApost/dt=-Apost/taupost : 1 (event-driven)
55 w : 1''',
56 pre = '''g += w*mV
57 Apre += dApre
58 w = w + Apost''',
59 post = '''Apost += dApost
60 w = w + Apre''')
61 S.connect()
62 S.w = fac*connectivity.flatten()
63
64
65 spike_mon = SpikeMonitor(P)
66 state_mon = StateMonitor(S, 'w', record=range(10), when=Clock(dt=0.1*second))
67 v_mon = StateMonitor(P, 'v', record=range(10))
68
69 if standalone == 1:
70 device.insert_code('main', 'std::clock_t start = std::clock();')
71
72 run(5 * second, report='text')
73
74 if standalone == 1:
75 device.insert_code('main', '''
76 std::ofstream myfile ("speed.txt");
77 if (myfile.is_open())
78 {
79 double value = (double) (std::clock() - start)/(%d * CLOCKS_PER_SEC);
80 myfile << value << std::endl;
81 myfile.close();
82 }
83 ''' %(max(1, n_threads)))
84
85
86 try:
87 os.removedirs(path)
88 except Exception:
89 pass
90
91 if standalone == 1:
92 device.build(project_dir=path, compile_project=True, run_project=True, debug=False)