NEST main@caf0ae8
 
Loading...
Searching...
No Matches
event_delivery_manager_impl.h
Go to the documentation of this file.
1/*
2 * event_delivery_manager_impl.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef EVENT_DELIVERY_MANAGER_IMPL_H
24#define EVENT_DELIVERY_MANAGER_IMPL_H
25
27
28// Includes from nestkernel:
30#include "kernel_manager.h"
31
32namespace nest
33{
34
35template < class EventT >
36inline void
37EventDeliveryManager::send_local_( Node& source, EventT& e, const long lag )
38{
39 assert( not source.has_proxies() );
40 e.set_stamp( kernel().simulation_manager.get_slice_origin() + Time::step( lag + 1 ) );
41 e.set_sender( source );
42 const size_t t = source.get_thread();
43 const size_t ldid = source.get_local_device_id();
45}
46
47inline void
49{
50 assert( not source.has_proxies() );
51 e.set_stamp( kernel().simulation_manager.get_slice_origin() + Time::step( 1 ) );
52 e.set_sender( source );
53 const size_t t = source.get_thread();
54 const size_t ldid = source.get_local_device_id();
56}
57
58template < class EventT >
59inline void
60EventDeliveryManager::send( Node& source, EventT& e, const long lag )
61{
62 send_local_( source, e, lag );
63}
64
65template <>
66inline void
67EventDeliveryManager::send< SpikeEvent >( Node& source, SpikeEvent& e, const long lag )
68{
69 const size_t tid = source.get_thread();
70 const size_t source_node_id = source.get_node_id();
71 e.set_sender_node_id( source_node_id );
72 if ( source.has_proxies() )
73 {
74 local_spike_counter_[ tid ] += e.get_multiplicity();
75
76 e.set_stamp( kernel().simulation_manager.get_slice_origin() + Time::step( lag + 1 ) );
77 e.set_sender( source );
78
79 if ( source.is_off_grid() )
80 {
81 send_off_grid_remote( tid, e, lag );
82 }
83 else
84 {
85 send_remote( tid, e, lag );
86 }
87 kernel().connection_manager.send_to_devices( tid, source_node_id, e );
88 }
89 else
90 {
91 send_local_( source, e, lag );
92 }
93}
94
95template <>
96inline void
97EventDeliveryManager::send< DSSpikeEvent >( Node& source, DSSpikeEvent& e, const long lag )
98{
99 e.set_sender_node_id( source.get_node_id() );
100 send_local_( source, e, lag );
101}
102
103inline void
104EventDeliveryManager::send_remote( size_t tid, SpikeEvent& e, const long lag )
105{
106 // Put the spike in a buffer for the remote machines
107 const size_t lid = kernel().vp_manager.node_id_to_lid( e.get_sender().get_node_id() );
108 const auto& targets = kernel().connection_manager.get_remote_targets_of_local_node( tid, lid );
109
110 for ( const auto& target : targets )
111 {
112 // Unroll spike multiplicity as plastic synapses only handle individual spikes.
113 for ( size_t i = 0; i < e.get_multiplicity(); ++i )
114 {
115 ( *emitted_spikes_register_[ tid ] ).emplace_back( target, lag, e.is_flush_event() );
116 }
117 }
118}
119
120inline void
122{
123 // Put the spike in a buffer for the remote machines
124 const size_t lid = kernel().vp_manager.node_id_to_lid( e.get_sender().get_node_id() );
125 const auto& targets = kernel().connection_manager.get_remote_targets_of_local_node( tid, lid );
126
127 for ( const auto& target : targets )
128 {
129 // Unroll spike multiplicity as plastic synapses only handle individual spikes.
130 for ( size_t i = 0; i < e.get_multiplicity(); ++i )
131 {
132 ( *off_grid_emitted_spikes_register_[ tid ] ).emplace_back( target, lag, e.get_offset() );
133 }
134 }
135}
136
137inline void
139{
140 const size_t tid = kernel().vp_manager.get_thread_id();
141 const size_t source_node_id = source.get_node_id();
142 const size_t lid = kernel().vp_manager.node_id_to_lid( source_node_id );
143
144 if ( source.has_proxies() )
145 {
146
147 // We need to consider every synapse type this event supports to
148 // make sure also labeled and connection created by CopyModel are
149 // considered.
150 const std::set< synindex >& supported_syn_ids = e.get_supported_syn_ids();
151 for ( const auto& syn_id : supported_syn_ids )
152 {
153 const std::vector< size_t >& positions =
155
156 for ( size_t i = 0; i < positions.size(); ++i )
157 {
158 std::vector< unsigned int >::iterator it = send_buffer_secondary_events_.begin() + positions[ i ];
159 e >> it;
160 }
161 }
162 kernel().connection_manager.send_to_devices( tid, source_node_id, e );
163 }
164 else
165 {
166 send_local_( source, e, 0 ); // need to pass lag (last argument), but not
167 // used in template specialization, so pass
168 // zero as dummy value
169 }
170}
171
172inline size_t
177
178
179} // of namespace nest
180
181#endif
void send_from_device(const size_t tid, const size_t ldid, Event &e)
Send event e to all targets of source device ldid (local device id)
Definition connection_manager_impl.h:79
void send_to_devices(const size_t tid, const size_t source_node_id, Event &e)
Send event e to all device targets of source source_node_id.
Definition connection_manager_impl.h:67
const std::vector< Target > & get_remote_targets_of_local_node(const size_t tid, const size_t lid) const
Definition connection_manager.h:818
const std::vector< size_t > & get_secondary_send_buffer_positions(const size_t tid, const size_t lid, const synindex syn_id) const
Definition connection_manager.h:846
"Callback request event" for use in Device.
Definition event.h:521
void send_remote(size_t tid, SpikeEvent &, const long lag=0)
Add node ID of event sender to the spike_register.
Definition event_delivery_manager_impl.h:104
std::vector< std::vector< SpikeDataWithRank > * > emitted_spikes_register_
Register of emitted spikes.
Definition event_delivery_manager.h:423
std::vector< unsigned int > send_buffer_secondary_events_
Buffer to collect the secondary events after serialization.
Definition event_delivery_manager.h:441
std::vector< unsigned long > local_spike_counter_
Number of generated spike events (both off- and on-grid) during the last call to simulate.
Definition event_delivery_manager.h:447
std::vector< std::vector< OffGridSpikeDataWithRank > * > off_grid_emitted_spikes_register_
Register of emitted off-grid spikes.
Definition event_delivery_manager.h:436
void send_secondary(Node &source, SecondaryEvent &e)
Send a secondary event remote.
Definition event_delivery_manager_impl.h:138
size_t write_toggle() const
Return 0 for even, 1 for odd time slices.
Definition event_delivery_manager_impl.h:173
void send(Node &source, EventT &e, const long lag=0)
Standard routine for sending events.
Definition event_delivery_manager_impl.h:60
void send_off_grid_remote(size_t tid, SpikeEvent &e, const long lag=0)
Add node ID of event sender to the spike_register.
Definition event_delivery_manager_impl.h:121
void send_local_(Node &source, EventT &e, const long lag)
Sends event e to all targets of node source.
Definition event_delivery_manager_impl.h:37
Base class for all NEST network objects.
Definition node.h:99
Base class of secondary events.
Definition secondary_event.h:50
size_t get_slice() const
Get slice number.
Definition simulation_manager.h:275
Event for spike information.
Definition event.h:418
size_t get_thread_id() const
Gets ID of local thread.
Definition vp_manager.h:176
size_t node_id_to_lid(const size_t node_id) const
Returns thread local index of a given global node.
Definition vp_manager_impl.h:79
ConnectionManager connection_manager
Definition kernel_manager.h:239
SimulationManager simulation_manager
Definition kernel_manager.h:237
VPManager vp_manager
Definition kernel_manager.h:234
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
Definition nest_time.h:246