Skip to content

Commit eab8304

Browse files
authored
Merge pull request #1442 from suku248/issue_1394
Use vector of integer for per-thread bool indicators
2 parents 22d27af + 4b15e1a commit eab8304

10 files changed

+215
-236
lines changed

nestkernel/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ set( nestkernel_sources
2323
archiving_node.h archiving_node.cpp
2424
clopath_archiving_node.h clopath_archiving_node.cpp
2525
common_synapse_properties.h common_synapse_properties.cpp
26-
completed_checker.h completed_checker.cpp
2726
connection.h
2827
connection_label.h
2928
common_properties_hom_w.h
@@ -53,6 +52,7 @@ set( nestkernel_sources
5352
modelrange_manager.h modelrange_manager.cpp
5453
node.h node.cpp
5554
parameter.h parameter.cpp
55+
per_thread_bool_indicator.h per_thread_bool_indicator.cpp
5656
proxynode.h proxynode.cpp
5757
recording_device.h recording_device.cpp
5858
pseudo_recording_device.h

nestkernel/completed_checker.h

-140
This file was deleted.

nestkernel/connection_manager.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ nest::ConnectionManager::initialize()
9494
secondary_recv_buffer_pos_.resize( num_threads );
9595
sort_connections_by_source_ = true;
9696

97-
have_connections_changed_.resize( num_threads, true );
98-
check_primary_connections_.resize( num_threads, false );
99-
check_secondary_connections_.resize( num_threads, false );
97+
have_connections_changed_.initialize( num_threads, true );
98+
check_primary_connections_.initialize( num_threads, false );
99+
check_secondary_connections_.initialize( num_threads, false );
100100

101101
#pragma omp parallel
102102
{
@@ -555,17 +555,17 @@ nest::ConnectionManager::connect_( Node& s,
555555

556556
// We do not check has_primary_connections_ and secondary_connections_exist_
557557
// directly as this led to worse performance on the supercomputer Piz Daint.
558-
if ( not check_primary_connections_[ tid ] and is_primary )
558+
if ( check_primary_connections_[ tid ].is_false() and is_primary )
559559
{
560560
#pragma omp atomic write
561561
has_primary_connections_ = true;
562-
check_primary_connections_.set( tid, true );
562+
check_primary_connections_[ tid ].set_true();
563563
}
564-
else if ( not check_secondary_connections_[ tid ] and not is_primary )
564+
else if ( check_secondary_connections_[ tid ].is_false() and not is_primary )
565565
{
566566
#pragma omp atomic write
567567
secondary_connections_exist_ = true;
568-
check_secondary_connections_.set( tid, true );
568+
check_secondary_connections_[ tid ].set_true();
569569
}
570570
}
571571

@@ -1409,12 +1409,12 @@ nest::ConnectionManager::set_have_connections_changed( const thread tid )
14091409
// Need to check if have_connections_changed_ has already been set, because if
14101410
// we have a lot of threads and they all try to set the variable at once we get
14111411
// performance issues on supercomputers.
1412-
if ( not have_connections_changed_[ tid ] )
1412+
if ( have_connections_changed_[ tid ].is_false() )
14131413
{
14141414
std::string msg =
14151415
"New connections created, connection descriptors previously obtained using 'GetConnections' are now invalid.";
14161416
LOG( M_WARNING, "ConnectionManager", msg );
1417-
have_connections_changed_.set( tid, true );
1417+
have_connections_changed_[ tid ].set_true();
14181418
}
14191419
}
14201420

@@ -1424,8 +1424,8 @@ nest::ConnectionManager::unset_have_connections_changed( const thread tid )
14241424
// Need to check if have_connections_changed_ has already been set, because if
14251425
// we have a lot of threads and they all try to set the variable at once we get
14261426
// performance issues on supercomputers.
1427-
if ( have_connections_changed_[ tid ] )
1427+
if ( have_connections_changed_[ tid ].is_true() )
14281428
{
1429-
have_connections_changed_.set( tid, false );
1429+
have_connections_changed_[ tid ].set_false();
14301430
}
14311431
}

nestkernel/connection_manager.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
#include "manager_interface.h"
3131

3232
// Includes from nestkernel:
33-
#include "completed_checker.h"
3433
#include "conn_builder.h"
3534
#include "connection_id.h"
3635
#include "connector_base.h"
3736
#include "node_collection.h"
3837
#include "nest_time.h"
3938
#include "nest_timeconverter.h"
4039
#include "nest_types.h"
40+
#include "per_thread_bool_indicator.h"
4141
#include "source_table.h"
4242
#include "target_table.h"
4343
#include "target_table_devices.h"
@@ -580,7 +580,7 @@ class ConnectionManager : public ManagerInterface
580580

581581
//! True if new connections have been created since startup or last call to
582582
//! simulate.
583-
CompletedChecker have_connections_changed_;
583+
PerThreadBoolIndicator have_connections_changed_;
584584

585585
//! Whether to sort connections by source node ID.
586586
bool sort_connections_by_source_;
@@ -589,13 +589,13 @@ class ConnectionManager : public ManagerInterface
589589
bool has_primary_connections_;
590590

591591
//! Check for primary connections (spikes) on each thread.
592-
CompletedChecker check_primary_connections_;
592+
PerThreadBoolIndicator check_primary_connections_;
593593

594594
//! Whether secondary connections (e.g., gap junctions) exist.
595595
bool secondary_connections_exist_;
596596

597597
//! Check for secondary connections (e.g., gap junctions) on each thread.
598-
CompletedChecker check_secondary_connections_;
598+
PerThreadBoolIndicator check_secondary_connections_;
599599

600600
//! Maximum distance between (double) spike times in STDP that is
601601
//! still considered 0. See issue #894

nestkernel/event_delivery_manager.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ EventDeliveryManager::initialize()
8383
reset_timers_counters();
8484
spike_register_.resize( num_threads );
8585
off_grid_spike_register_.resize( num_threads );
86-
gather_completed_checker_.resize( num_threads, false );
86+
gather_completed_checker_.initialize( num_threads, false );
8787
// Ensures that ResetKernel resets off_grid_spiking_
8888
off_grid_spiking_ = false;
8989
buffer_size_target_data_has_changed_ = false;
@@ -107,7 +107,6 @@ EventDeliveryManager::finalize()
107107
// clear the spike buffers
108108
std::vector< std::vector< std::vector< std::vector< Target > > > >().swap( spike_register_ );
109109
std::vector< std::vector< std::vector< std::vector< OffGridTarget > > > >().swap( off_grid_spike_register_ );
110-
gather_completed_checker_.clear();
111110

112111
send_buffer_secondary_events_.clear();
113112
recv_buffer_secondary_events_.clear();
@@ -308,16 +307,16 @@ EventDeliveryManager::gather_spike_data_( const thread tid,
308307
std::vector< SpikeDataT >& recv_buffer )
309308
{
310309
// Assume all threads have some work to do
311-
gather_completed_checker_.set( tid, false );
310+
gather_completed_checker_[ tid ].set_false();
312311
assert( gather_completed_checker_.all_false() );
313312

314313
const AssignedRanks assigned_ranks = kernel().vp_manager.get_assigned_ranks( tid );
315314

316-
while ( not gather_completed_checker_.all_true() )
315+
while ( gather_completed_checker_.any_false() )
317316
{
318317
// Assume this is the last gather round and change to false
319318
// otherwise
320-
gather_completed_checker_.set( tid, true );
319+
gather_completed_checker_[ tid ].set_true();
321320

322321
#pragma omp single
323322
{
@@ -335,13 +334,13 @@ EventDeliveryManager::gather_spike_data_( const thread tid,
335334
// Collocate spikes to send buffer
336335
const bool collocate_completed =
337336
collocate_spike_data_buffers_( tid, assigned_ranks, send_buffer_position, spike_register_, send_buffer );
338-
gather_completed_checker_.logical_and( tid, collocate_completed );
337+
gather_completed_checker_[ tid ].logical_and( collocate_completed );
339338

340339
if ( off_grid_spiking_ )
341340
{
342341
const bool collocate_completed_off_grid = collocate_spike_data_buffers_(
343342
tid, assigned_ranks, send_buffer_position, off_grid_spike_register_, send_buffer );
344-
gather_completed_checker_.logical_and( tid, collocate_completed_off_grid );
343+
gather_completed_checker_[ tid ].logical_and( collocate_completed_off_grid );
345344
}
346345

347346
#pragma omp barrier
@@ -374,13 +373,13 @@ EventDeliveryManager::gather_spike_data_( const thread tid,
374373

375374
// Deliver spikes from receive buffer to ring buffers.
376375
const bool deliver_completed = deliver_events_( tid, recv_buffer );
377-
gather_completed_checker_.logical_and( tid, deliver_completed );
376+
gather_completed_checker_[ tid ].logical_and( deliver_completed );
378377

379378
// Exit gather loop if all local threads and remote processes are
380379
// done.
381380
#pragma omp barrier
382381
// Resize mpi buffers, if necessary and allowed.
383-
if ( not gather_completed_checker_.all_true() and kernel().mpi_manager.adaptive_spike_buffers() )
382+
if ( gather_completed_checker_.any_false() and kernel().mpi_manager.adaptive_spike_buffers() )
384383
{
385384
#pragma omp single
386385
{
@@ -583,19 +582,19 @@ EventDeliveryManager::gather_target_data( const thread tid )
583582
assert( not kernel().connection_manager.is_source_table_cleared() );
584583

585584
// assume all threads have some work to do
586-
gather_completed_checker_.set( tid, false );
585+
gather_completed_checker_[ tid ].set_false();
587586
assert( gather_completed_checker_.all_false() );
588587

589588
const AssignedRanks assigned_ranks = kernel().vp_manager.get_assigned_ranks( tid );
590589

591590
kernel().connection_manager.prepare_target_table( tid );
592591
kernel().connection_manager.reset_source_table_entry_point( tid );
593592

594-
while ( not gather_completed_checker_.all_true() )
593+
while ( gather_completed_checker_.any_false() )
595594
{
596595
// assume this is the last gather round and change to false
597596
// otherwise
598-
gather_completed_checker_.set( tid, true );
597+
gather_completed_checker_[ tid ].set_true();
599598

600599
#pragma omp single
601600
{
@@ -611,7 +610,7 @@ EventDeliveryManager::gather_target_data( const thread tid )
611610
assigned_ranks, kernel().mpi_manager.get_send_recv_count_target_data_per_rank() );
612611

613612
const bool gather_completed = collocate_target_data_buffers_( tid, assigned_ranks, send_buffer_position );
614-
gather_completed_checker_.logical_and( tid, gather_completed );
613+
gather_completed_checker_[ tid ].logical_and( gather_completed );
615614

616615
if ( gather_completed_checker_.all_true() )
617616
{
@@ -627,11 +626,11 @@ EventDeliveryManager::gather_target_data( const thread tid )
627626
} // of omp single
628627

629628
const bool distribute_completed = distribute_target_data_buffers_( tid );
630-
gather_completed_checker_.logical_and( tid, distribute_completed );
629+
gather_completed_checker_[ tid ].logical_and( distribute_completed );
631630
#pragma omp barrier
632631

633632
// resize mpi buffers, if necessary and allowed
634-
if ( not gather_completed_checker_.all_true() and kernel().mpi_manager.adaptive_target_buffers() )
633+
if ( gather_completed_checker_.any_false() and kernel().mpi_manager.adaptive_target_buffers() )
635634
{
636635
#pragma omp single
637636
{

nestkernel/event_delivery_manager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
#include "stopwatch.h"
3434

3535
// Includes from nestkernel:
36-
#include "completed_checker.h"
3736
#include "event.h"
3837
#include "mpi_manager.h" // OffGridSpike
3938
#include "nest_time.h"
4039
#include "nest_types.h"
4140
#include "node.h"
41+
#include "per_thread_bool_indicator.h"
4242
#include "target_table.h"
4343
#include "spike_data.h"
4444
#include "vp_manager.h"
@@ -433,7 +433,7 @@ class EventDeliveryManager : public ManagerInterface
433433
//!< whether size of MPI buffer for communication of spikes was changed
434434
bool buffer_size_spike_data_has_changed_;
435435

436-
CompletedChecker gather_completed_checker_;
436+
PerThreadBoolIndicator gather_completed_checker_;
437437
};
438438

439439
inline void

0 commit comments

Comments
 (0)