Debian Codegraph @

brian2/devices/cpp_standalone/templates/synapses_classes.cpp

raw
1 {% macro cpp_file() %}
2 {% endmacro %}
3
4 {% macro h_file() %}
5
6 #ifndef _BRIAN_SYNAPSES_H
7 #define _BRIAN_SYNAPSES_H
8
9 #include<vector>
10 #include<algorithm>
11 {{ openmp_pragma('include') }}
12
13 #include "brianlib/spikequeue.h"
14
15 class SynapticPathway
16 {
17 public:
18 int Nsource, Ntarget, _nb_threads;
19 std::vector<int> &sources;
20 std::vector<int> all_peek;
21 std::vector< CSpikeQueue * > queue;
22 SynapticPathway(std::vector<int> &_sources, int _spikes_start, int _spikes_stop)
23 : sources(_sources)
24 {
25 _nb_threads = {{ openmp_pragma('get_num_threads') }};
26
27 for (int _idx=0; _idx < _nb_threads; _idx++)
28 queue.push_back(new CSpikeQueue(_spikes_start, _spikes_stop));
29 };
30
31 ~SynapticPathway()
32 {
33 for (int _idx=0; _idx < _nb_threads; _idx++)
34 delete(queue[_idx]);
35 }
36
37 void push(int *spikes, int nspikes)
38 {
39 queue[{{ openmp_pragma('get_thread_num') }}]->push(spikes, nspikes);
40 }
41
42 void advance()
43 {
44 queue[{{ openmp_pragma('get_thread_num') }}]->advance();
45 }
46
47 vector<int32_t>* peek()
48 {
49 {{ openmp_pragma('static-ordered') }}
50 for(int _thread=0; _thread < {{ openmp_pragma('get_num_threads') }}; _thread++)
51 {
52 {{ openmp_pragma('ordered') }}
53 {
54 if (_thread == 0)
55 all_peek.clear();
56 all_peek.insert(all_peek.end(), queue[_thread]->peek()->begin(), queue[_thread]->peek()->end());
57 }
58 }
59
60 return &all_peek;
61 }
62
63 template <typename scalar> void prepare(int n_source, int n_target, scalar *real_delays, int n_delays,
64 int *sources, int n_synapses, double _dt)
65 {
66 Nsource = n_source;
67 Ntarget = n_target;
68 {{ openmp_pragma('parallel') }}
69 {
70 int length;
71 if ({{ openmp_pragma('get_thread_num') }} == _nb_threads - 1)
72 length = n_synapses - (int){{ openmp_pragma('get_thread_num') }}*(n_synapses/_nb_threads);
73 else
74 length = (int) n_synapses/_nb_threads;
75
76 int padding = {{ openmp_pragma('get_thread_num') }}*(n_synapses/_nb_threads);
77
78 queue[{{ openmp_pragma('get_thread_num') }}]->openmp_padding = padding;
79 if (n_delays > 1)
80 queue[{{ openmp_pragma('get_thread_num') }}]->prepare(&real_delays[padding], length, &sources[padding], length, _dt);
81 else if (n_delays == 1)
82 queue[{{ openmp_pragma('get_thread_num') }}]->prepare(&real_delays[0], 1, &sources[padding], length, _dt);
83 else // no synapses
84 queue[{{ openmp_pragma('get_thread_num') }}]->prepare((scalar *)NULL, 0, &sources[padding], length, _dt);
85 }
86 }
87
88 };
89
90 #endif
91
92 {% endmacro %}