NEST main@caf0ae8
 
Loading...
Searching...
No Matches
target.h
Go to the documentation of this file.
1/*
2 * target.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 TARGET_H
24#define TARGET_H
25
26// C++ includes:
27#include <cassert>
28
29// Includes from nestkernel:
30#include "exceptions.h"
31#include "nest_types.h"
32#include "static_assert.h"
33
34namespace nest
35{
36
76
77class Target
78{
79private:
81
82 static constexpr uint8_t BITPOS_LCID = 0U;
83 static constexpr uint8_t BITPOS_RANK = NUM_BITS_LCID;
84 static constexpr uint8_t BITPOS_TID = BITPOS_RANK + NUM_BITS_RANK;
85 static constexpr uint8_t BITPOS_SYN_ID = BITPOS_TID + NUM_BITS_TID;
87
90
91 // generate bit-masks used in bit-operations
92 static constexpr uint64_t MASK_LCID = generate_bit_mask( NUM_BITS_LCID, BITPOS_LCID );
93 static constexpr uint64_t MASK_RANK = generate_bit_mask( NUM_BITS_RANK, BITPOS_RANK );
94 static constexpr uint64_t MASK_TID = generate_bit_mask( NUM_BITS_TID, BITPOS_TID );
97
98public:
99 Target();
100 Target( const Target& target );
101 Target( const size_t tid, const size_t rank, const synindex syn_id, const size_t lcid );
102
103 Target& operator=( const Target& );
104
108 void set_lcid( const size_t lcid );
109
113 size_t get_lcid() const;
114
118 void set_rank( const size_t rank );
119
123 size_t get_rank() const;
124
128 void set_tid( const size_t tid );
129
133 size_t get_tid() const;
134
138 void set_syn_id( const synindex syn_id );
139
143 synindex get_syn_id() const;
144
148 void set_status( enum_status_target_id status );
149
154
158 bool is_processed() const;
159
163 double get_offset() const;
164
168 void mark_for_removal();
169};
170
172using success_target_size = StaticAssert< sizeof( Target ) == 8 >::success;
173
175 : remote_target_id_( 0 )
176{
177}
178
179inline Target::Target( const Target& target )
180 : remote_target_id_( target.remote_target_id_ )
181{
182 set_status( TARGET_ID_UNPROCESSED ); // initialize
183}
184
185inline Target&
187{
188 remote_target_id_ = other.remote_target_id_;
190 return *this;
191}
192
193inline Target::Target( const size_t tid, const size_t rank, const synindex syn_id, const size_t lcid )
194 : remote_target_id_( 0 )
195{
196 // We need to call set_*() methods to properly encode values in bitfield.
197 // Validity of arguments is asserted in set_*() methods.
198 set_lcid( lcid );
199 set_rank( rank );
200 set_tid( tid );
201 set_syn_id( syn_id );
202 set_status( TARGET_ID_UNPROCESSED ); // initialize
203}
204
205inline void
206Target::set_lcid( const size_t lcid )
207{
208 assert( lcid < MAX_LCID );
209 remote_target_id_ = ( remote_target_id_ & ( ~MASK_LCID ) ) | ( static_cast< uint64_t >( lcid ) << BITPOS_LCID );
210}
211
212inline size_t
214{
215 return ( ( remote_target_id_ & MASK_LCID ) >> BITPOS_LCID );
216}
217
218inline void
219Target::set_rank( const size_t rank )
220{
221 assert( rank <= MAX_RANK ); // MAX_RANK is allowed since it is not used as invalid value
222 remote_target_id_ = ( remote_target_id_ & ( ~MASK_RANK ) ) | ( static_cast< uint64_t >( rank ) << BITPOS_RANK );
223}
224
225inline size_t
227{
228 return ( ( remote_target_id_ & MASK_RANK ) >> BITPOS_RANK );
229}
230
231inline void
232Target::set_tid( const size_t tid )
233{
234 assert( tid <= MAX_TID ); // MAX_TID is allowed since it is not used as invalid value
235 remote_target_id_ = ( remote_target_id_ & ( ~MASK_TID ) ) | ( static_cast< uint64_t >( tid ) << BITPOS_TID );
236}
237
238inline size_t
240{
241 return ( ( remote_target_id_ & MASK_TID ) >> BITPOS_TID );
242}
243
244inline void
246{
247 assert( syn_id < MAX_SYN_ID );
248 remote_target_id_ = ( remote_target_id_ & ( ~MASK_SYN_ID ) ) | ( static_cast< uint64_t >( syn_id ) << BITPOS_SYN_ID );
249}
250
251inline synindex
253{
254 return ( ( remote_target_id_ & MASK_SYN_ID ) >> BITPOS_SYN_ID );
255}
256
257inline void
259{
260 switch ( set_status_to )
261 {
264 break;
266 remote_target_id_ = remote_target_id_ & ~MASK_PROCESSED_FLAG; // clear single bit
267 break;
268 default:
269 throw InternalError( "Invalid remote target id status." );
270 }
271}
272
275{
276 if ( ( remote_target_id_ & MASK_PROCESSED_FLAG ) >> BITPOS_PROCESSED_FLAG ) // test single bit
277 {
278 return ( TARGET_ID_PROCESSED );
279 }
280 return ( TARGET_ID_UNPROCESSED );
281}
282
283inline bool
285{
286 return ( get_status() == TARGET_ID_PROCESSED );
287}
288
289inline double
291{
292 return 0;
293}
294
295inline void
300
301
302class OffGridTarget : public Target
303{
304private:
305 double offset_;
306
307public:
309 OffGridTarget( const Target& target, const double offset );
310 double get_offset() const;
311};
312
314 : Target()
315 , offset_( 0 )
316{
317}
318
319inline OffGridTarget::OffGridTarget( const Target& target, const double offset )
320 : Target( target )
321 , offset_( offset )
322{
323}
324
325inline double
327{
328 return offset_;
329}
330
331} // namespace nest
332
333#endif /* #ifndef TARGET_H */
Exception to be thrown if an internal error occurs.
Definition exceptions.h:1220
Definition target.h:303
double offset_
Definition target.h:305
OffGridTarget()
Definition target.h:313
double get_offset() const
Definition target.h:326
check legal size
Definition target.h:78
double get_offset() const
Return offset.
Definition target.h:290
static constexpr uint64_t MASK_LCID
Definition target.h:92
static constexpr uint64_t MASK_TID
Definition target.h:94
static constexpr uint64_t MASK_SYN_ID
Definition target.h:95
static constexpr uint8_t BITPOS_TID
Definition target.h:84
static constexpr uint8_t BITPOS_PROCESSED_FLAG
Definition target.h:86
Target & operator=(const Target &)
Definition target.h:186
static constexpr uint8_t BITPOS_LCID
Definition target.h:82
static constexpr uint8_t BITPOS_SYN_ID
Definition target.h:85
void set_syn_id(const synindex syn_id)
Set the synapse-type id.
Definition target.h:245
Target()
Definition target.h:174
bool is_processed() const
Return the status od the target identifier: processed or unprocessed.
Definition target.h:284
size_t get_rank() const
Return rank.
Definition target.h:226
void set_rank(const size_t rank)
Set rank.
Definition target.h:219
size_t get_lcid() const
Return local connection id.
Definition target.h:213
uint64_t remote_target_id_
Definition target.h:80
enum_status_target_id get_status() const
Get the status of the target identifier: processed or unprocessed.
Definition target.h:274
synindex get_syn_id() const
Return synapse-type id.
Definition target.h:252
size_t get_tid() const
Return thread id.
Definition target.h:239
StaticAssert< NUM_BITS_PROCESSED_FLAG==1U >::success bits_for_processed_flag
Definition target.h:88
static constexpr uint64_t MASK_RANK
Definition target.h:93
void mark_for_removal()
Set the status of the target identifier to processed.
Definition target.h:296
static constexpr uint64_t MASK_PROCESSED_FLAG
Definition target.h:96
void set_status(enum_status_target_id status)
Set the status of the target identifier: processed or unprocessed.
Definition target.h:258
StaticAssert< BITPOS_PROCESSED_FLAG==63U >::success position_of_processed_flag
Definition target.h:89
static constexpr uint8_t BITPOS_RANK
Definition target.h:83
void set_tid(const size_t tid)
Set thread id.
Definition target.h:232
void set_lcid(const size_t lcid)
Set local connection id.
Definition target.h:206
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
constexpr uint64_t generate_bit_mask(const uint8_t num_bits, const uint8_t bit_position)
Default types used by the NEST kernel.
Definition nest_types.h:60
constexpr uint8_t NUM_BITS_PROCESSED_FLAG
Definition nest_types.h:84
constexpr uint8_t NUM_BITS_SYN_ID
Definition nest_types.h:77
constexpr uint8_t NUM_BITS_LCID
Definition nest_types.h:83
constexpr int64_t MAX_TID
Definition nest_types.h:95
constexpr uint64_t MAX_SYN_ID
Definition nest_types.h:96
constexpr uint8_t NUM_BITS_RANK
Definition nest_types.h:75
enum_status_target_id
This class implements a 64-bit target neuron identifier type.
Definition target.h:72
@ TARGET_ID_UNPROCESSED
Definition target.h:74
@ TARGET_ID_PROCESSED
Definition target.h:73
StaticAssert< sizeof(Target)==8 >::success success_target_size
Definition target.h:172
constexpr uint8_t NUM_BITS_TID
Definition nest_types.h:76
constexpr int64_t MAX_RANK
Definition nest_types.h:94
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
constexpr uint64_t MAX_LCID
Definition nest_types.h:93
Compile time assertions.
Definition static_assert.h:47