From a3f53691afd9502d06172cc91e34803ce87b6359 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 20 Jul 2025 22:00:05 +0200 Subject: [PATCH 01/27] Fix issue: #3532 --- nestkernel/connection_manager.cpp | 4 +- nestkernel/source_table.h | 88 ++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index 0924fb73e2..857dcf838d 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -996,7 +996,7 @@ nest::ConnectionManager::find_connection( const size_t tid, { // lcid will hold the position of the /first/ connection from node // snode_id to any local node, or be invalid - size_t lcid = source_table_.find_first_source( tid, syn_id, snode_id ); + size_t lcid = source_table_.find_first_source( tid, syn_id, snode_id, use_compressed_spikes() ); if ( lcid == invalid_index ) { return invalid_index; @@ -1446,7 +1446,7 @@ nest::ConnectionManager::get_targets( const std::vector< size_t >& sources, { for ( size_t i = 0; i < sources.size(); ++i ) { - const size_t start_lcid = source_table_.find_first_source( tid, syn_id, sources[ i ] ); + const size_t start_lcid = source_table_.find_first_source( tid, syn_id, sources[ i ], use_compressed_spikes() ); if ( start_lcid != invalid_index ) { connections_[ tid ][ syn_id ]->get_target_node_ids( tid, start_lcid, post_synaptic_element, targets[ i ] ); diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index ac5574ca6e..7ab65fdb67 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -29,6 +29,7 @@ #include #include #include +#include #include // Includes from nestkernel: @@ -300,7 +301,10 @@ class SourceTable * Finds the first entry in sources_ at the given thread id and * synapse type that is equal to snode_id. */ - size_t find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id ) const; + size_t find_first_source( const size_t tid, + const synindex syn_id, + const size_t snode_id, + bool isCompressedEnabled = false ) const; /** * Marks entry in sources_ at given position as disabled. @@ -471,27 +475,75 @@ SourceTable::no_targets_to_process( const size_t tid ) } inline size_t -SourceTable::find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id ) const +SourceTable::find_first_source( const size_t tid, + const synindex syn_id, + const size_t snode_id, + bool isCompressedEnabled /* default = false */ ) const { - // binary search in sorted sources - const BlockVector< Source >::const_iterator begin = sources_[ tid ][ syn_id ].begin(); - const BlockVector< Source >::const_iterator end = sources_[ tid ][ syn_id ].end(); - BlockVector< Source >::const_iterator it = std::lower_bound( begin, end, Source( snode_id, true ) ); - - // source found by binary search could be disabled, iterate through - // sources until a valid one is found - while ( it != end ) + using SourceIter = BlockVector< Source >::const_iterator; + + const SourceIter begin = sources_[ tid ][ syn_id ].begin(); + const SourceIter end = sources_[ tid ][ syn_id ].end(); + + if ( isCompressedEnabled ) { - if ( it->get_node_id() == snode_id and not it->is_disabled() ) + // binary search in sorted sources + SourceIter it = std::lower_bound( begin, end, Source( snode_id, true ) ); + + // source found by binary search could be disabled, iterate through + // sources until a valid one is found + while ( it != end ) { - const size_t lcid = it - begin; - return lcid; + if ( it->get_node_id() == snode_id and not it->is_disabled() ) + { + const size_t lcid = it - begin; + return lcid; + } + ++it; } - ++it; + + // no enabled entry with this snode ID found + return invalid_index; } + else + { - // no enabled entry with this snode ID found - return invalid_index; + auto nth_equal = + []( SourceIter first, SourceIter last, const Source& value, size_t n ) -> std::pair< bool, SourceIter > + { + if ( n == 0 ) + { + auto iter = std::find( first, last, value ); + return { iter != last, iter }; + } + auto iter = std::find( first, last, value ); + while ( n > 0 && iter != last ) + { + --n; + iter = std::find( std::next( iter ), last, value ); + } + return { iter != last, iter }; + }; + size_t pos = 0; + auto res = nth_equal( begin, end, Source( snode_id, true ), pos ); + if ( !res.first ) + { + return invalid_index; + } + + while ( res.first ) + { + if ( res.second->get_node_id() == snode_id && not res.second->is_disabled() ) + { + // found a valid source + size_t lcid = res.second - begin; + return lcid; + } + ++pos; + res = nth_equal( std::next( res.second ), end, Source( snode_id, true ), pos ); + } + return invalid_index; + } } inline void @@ -521,8 +573,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 4271659955ef178195af76a47a3c0666caa4b17d Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 20 Jul 2025 22:06:11 +0200 Subject: [PATCH 02/27] Make clang-format happy --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 7ab65fdb67..e8f6238c85 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -573,8 +573,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 25b7240f4d0a49b349a1cc2f5a045cbda97dcb35 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 20 Jul 2025 22:08:30 +0200 Subject: [PATCH 03/27] Make clang-format happy --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index e8f6238c85..d9c0caea82 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -573,8 +573,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 7617de0027ada0dd0477786b32707ffd4ae9b8cc Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 20 Jul 2025 23:29:25 +0200 Subject: [PATCH 04/27] Avoid copies of Source --- nestkernel/source_table.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index d9c0caea82..b14bd7bea2 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -485,10 +485,12 @@ SourceTable::find_first_source( const size_t tid, const SourceIter begin = sources_[ tid ][ syn_id ].begin(); const SourceIter end = sources_[ tid ][ syn_id ].end(); + Source value {snode_id, true}; + if ( isCompressedEnabled ) { // binary search in sorted sources - SourceIter it = std::lower_bound( begin, end, Source( snode_id, true ) ); + SourceIter it = std::lower_bound( begin, end, value ); // source found by binary search could be disabled, iterate through // sources until a valid one is found @@ -525,7 +527,7 @@ SourceTable::find_first_source( const size_t tid, return { iter != last, iter }; }; size_t pos = 0; - auto res = nth_equal( begin, end, Source( snode_id, true ), pos ); + auto res = nth_equal( begin, end, value, pos ); if ( !res.first ) { return invalid_index; @@ -540,7 +542,7 @@ SourceTable::find_first_source( const size_t tid, return lcid; } ++pos; - res = nth_equal( std::next( res.second ), end, Source( snode_id, true ), pos ); + res = nth_equal( std::next( res.second ), end, value, pos ); } return invalid_index; } From 02c2055f31f51f29f187ac44bb271b13a8c0ce24 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 20 Jul 2025 23:33:44 +0200 Subject: [PATCH 05/27] Make clang-format happy #3 --- nestkernel/source_table.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index b14bd7bea2..0236d05a73 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -485,7 +485,7 @@ SourceTable::find_first_source( const size_t tid, const SourceIter begin = sources_[ tid ][ syn_id ].begin(); const SourceIter end = sources_[ tid ][ syn_id ].end(); - Source value {snode_id, true}; + Source value { snode_id, true }; if ( isCompressedEnabled ) { @@ -575,8 +575,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 93a07984036d84f747918d85923e48c39d3d2003 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Mon, 21 Jul 2025 00:11:18 +0200 Subject: [PATCH 06/27] Disable my Nvim clangformat-plugin --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 0236d05a73..92f0ac19d4 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -575,8 +575,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 94cdccb7ece0faea91931fcb6ea1cb63f79c739e Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 12:53:41 +0200 Subject: [PATCH 07/27] Use std::find_if instead of custom function --- nestkernel/source_table.h | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 92f0ac19d4..148c493e31 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -509,40 +509,13 @@ SourceTable::find_first_source( const size_t tid, } else { - - auto nth_equal = - []( SourceIter first, SourceIter last, const Source& value, size_t n ) -> std::pair< bool, SourceIter > - { - if ( n == 0 ) - { - auto iter = std::find( first, last, value ); - return { iter != last, iter }; - } - auto iter = std::find( first, last, value ); - while ( n > 0 && iter != last ) - { - --n; - iter = std::find( std::next( iter ), last, value ); - } - return { iter != last, iter }; - }; - size_t pos = 0; - auto res = nth_equal( begin, end, value, pos ); - if ( !res.first ) + auto sourceIter = std::find_if( begin, end, [&value]( const Source& src ) { + return src.get_node_id() == value.get_node_id() && not src.is_disabled(); + } ); + if ( sourceIter != end ) { - return invalid_index; - } - - while ( res.first ) - { - if ( res.second->get_node_id() == snode_id && not res.second->is_disabled() ) - { - // found a valid source - size_t lcid = res.second - begin; - return lcid; - } - ++pos; - res = nth_equal( std::next( res.second ), end, value, pos ); + const size_t lcid = sourceIter - begin; + return lcid; } return invalid_index; } From 0015a85be16c26a28e08e5e14cdf98134549f188 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 12:54:40 +0200 Subject: [PATCH 08/27] Apply clang format --- nestkernel/source_table.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 148c493e31..99b51ddb6c 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -509,9 +509,9 @@ SourceTable::find_first_source( const size_t tid, } else { - auto sourceIter = std::find_if( begin, end, [&value]( const Source& src ) { - return src.get_node_id() == value.get_node_id() && not src.is_disabled(); - } ); + auto sourceIter = std::find_if( begin, + end, + [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() && not src.is_disabled(); } ); if ( sourceIter != end ) { const size_t lcid = sourceIter - begin; @@ -548,8 +548,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 3454d36d2ff6f70aaafb0e2dbaefaa4054449460 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 13:07:34 +0200 Subject: [PATCH 09/27] Make clang happy again --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 99b51ddb6c..6753d26e9c 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -548,8 +548,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From bbf3bafaca1cb1412a7da323458311125f380a4f Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 13:24:55 +0200 Subject: [PATCH 10/27] Use custom compare method for std::lower_bound --- nestkernel/source_table.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 6753d26e9c..e61c13d459 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -489,21 +489,22 @@ SourceTable::find_first_source( const size_t tid, if ( isCompressedEnabled ) { + auto comp = [](const Source& source, const Source& value) { + if (source.is_disabled()) { + return false; + } + return source.get_node_id() < value.get_node_id(); + }; // binary search in sorted sources - SourceIter it = std::lower_bound( begin, end, value ); + SourceIter it = std::lower_bound( begin, end, value, comp ); // source found by binary search could be disabled, iterate through // sources until a valid one is found - while ( it != end ) + if (it != end ) { - if ( it->get_node_id() == snode_id and not it->is_disabled() ) - { - const size_t lcid = it - begin; - return lcid; - } - ++it; + const size_t lcid = it - begin; + return lcid; } - // no enabled entry with this snode ID found return invalid_index; } From 9c67d5a6b7c87f67aef8a87876b06d82c8d06645 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 13:26:38 +0200 Subject: [PATCH 11/27] Fix clang-format again --- nestkernel/source_table.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index e61c13d459..df0117c511 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -489,18 +489,20 @@ SourceTable::find_first_source( const size_t tid, if ( isCompressedEnabled ) { - auto comp = [](const Source& source, const Source& value) { - if (source.is_disabled()) { - return false; - } - return source.get_node_id() < value.get_node_id(); + auto comp = []( const Source& source, const Source& value ) + { + if ( source.is_disabled() ) + { + return false; + } + return source.get_node_id() < value.get_node_id(); }; // binary search in sorted sources SourceIter it = std::lower_bound( begin, end, value, comp ); // source found by binary search could be disabled, iterate through // sources until a valid one is found - if (it != end ) + if ( it != end ) { const size_t lcid = it - begin; return lcid; @@ -549,8 +551,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 28e50b45f395420abbee73aef3a8413585623018 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 13:34:23 +0200 Subject: [PATCH 12/27] Fix format again --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index df0117c511..54d573780f 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -551,8 +551,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From eead8c30efb780aa7e0094665e6e4d11eaaada2f Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 13:37:57 +0200 Subject: [PATCH 13/27] Fix space --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 54d573780f..1c0bd8a97f 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -551,8 +551,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From d138558f713a6fe2cdaed2f54bc2cbeb859993c2 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sat, 20 Sep 2025 20:32:27 +0200 Subject: [PATCH 14/27] Fix std::lower_bound comp predicate --- nestkernel/source_table.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 1c0bd8a97f..03c10cffa1 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -491,7 +491,7 @@ SourceTable::find_first_source( const size_t tid, { auto comp = []( const Source& source, const Source& value ) { - if ( source.is_disabled() ) + if ( !source.is_disabled() ) { return false; } From e30af4fdc98787e8da60a3902155ffb3aeef4864 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 21 Sep 2025 13:57:10 +0200 Subject: [PATCH 15/27] Fix the logic behind std::lower_bound with deleted connection --- nestkernel/source_table.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 03c10cffa1..5fd11aa7e4 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -489,23 +489,29 @@ SourceTable::find_first_source( const size_t tid, if ( isCompressedEnabled ) { - auto comp = []( const Source& source, const Source& value ) - { - if ( !source.is_disabled() ) - { - return false; - } - return source.get_node_id() < value.get_node_id(); - }; + // auto comp = []( const Source& source, const Source& value ) + // { + // if ( source.is_disabled() || source.get_node_id() < value.get_node_id()) + // { + // return true; + // } + // return false; + // }; // binary search in sorted sources - SourceIter it = std::lower_bound( begin, end, value, comp ); + SourceIter it = std::lower_bound( begin, end, value ); // source found by binary search could be disabled, iterate through // sources until a valid one is found if ( it != end ) { - const size_t lcid = it - begin; - return lcid; + auto sourceIter = std::find_if( it, + end, + [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() && not src.is_disabled(); } ); + if ( sourceIter != end ) + { + const size_t lcid = sourceIter - begin; + return lcid; + } } // no enabled entry with this snode ID found return invalid_index; @@ -551,8 +557,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From 8564c57c29fb3cf41ad0820e668e6821ffb5c313 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Sun, 21 Sep 2025 14:00:34 +0200 Subject: [PATCH 16/27] Fix indentation --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 5fd11aa7e4..d9380240ad 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -557,8 +557,8 @@ SourceTable::num_unique_sources( const size_t tid, const synindex syn_id ) const size_t n = 0; size_t last_source = 0; for ( BlockVector< Source >::const_iterator cit = sources_[ tid ][ syn_id ].begin(); - cit != sources_[ tid ][ syn_id ].end(); - ++cit ) + cit != sources_[ tid ][ syn_id ].end(); + ++cit ) { if ( last_source != ( *cit ).get_node_id() ) { From ed28503f683a0ec06206303684ec8140e605faf7 Mon Sep 17 00:00:00 2001 From: "Ayssar:Debian:WSL" Date: Mon, 22 Sep 2025 11:48:04 +0200 Subject: [PATCH 17/27] Adjust the function to be more compact and simpler --- nestkernel/source_table.h | 60 ++++++++++++++------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index d9380240ad..313d02e1e5 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -304,7 +304,7 @@ class SourceTable size_t find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id, - bool isCompressedEnabled = false ) const; + bool using_compressed_spikes = false ) const; /** * Marks entry in sources_ at given position as disabled. @@ -478,56 +478,38 @@ inline size_t SourceTable::find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id, - bool isCompressedEnabled /* default = false */ ) const + bool using_compressed_spikes /* default = false */ ) const { - using SourceIter = BlockVector< Source >::const_iterator; - const SourceIter begin = sources_[ tid ][ syn_id ].begin(); - const SourceIter end = sources_[ tid ][ syn_id ].end(); + const auto source_begin = sources_[ tid ][ syn_id ].cbegin(); + const auto source_end = sources_[ tid ][ syn_id ].cend(); - Source value { snode_id, true }; + const Source selected_source { snode_id, /* is_primary */ true }; - if ( isCompressedEnabled ) + auto find_source = []( auto begin, auto end, const Source& value ) -> size_t { - // auto comp = []( const Source& source, const Source& value ) - // { - // if ( source.is_disabled() || source.get_node_id() < value.get_node_id()) - // { - // return true; - // } - // return false; - // }; - // binary search in sorted sources - SourceIter it = std::lower_bound( begin, end, value ); - - // source found by binary search could be disabled, iterate through - // sources until a valid one is found - if ( it != end ) - { - auto sourceIter = std::find_if( it, - end, - [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() && not src.is_disabled(); } ); - if ( sourceIter != end ) - { - const size_t lcid = sourceIter - begin; - return lcid; - } - } - // no enabled entry with this snode ID found - return invalid_index; - } - else - { - auto sourceIter = std::find_if( begin, + iter = std::find_if( begin, end, [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() && not src.is_disabled(); } ); - if ( sourceIter != end ) + if ( iter != end ) { - const size_t lcid = sourceIter - begin; + const size_t lcid = iter - begin; return lcid; } + // no enabled entry with this snode ID found return invalid_index; + }; + + auto iter = source_begin; + + if ( using_compressed_spikes ) + { + auto iter = std::lower_bound( iter, source_end, selected_source ); } + + auto ret = find_source( iter, source_end, selected_source ); + + return ret; } inline void From 06e36f5fa173dcb1dc2f4af86cabe838e9a19c8e Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Mon, 22 Sep 2025 17:23:47 +0200 Subject: [PATCH 18/27] Fix compiler errors --- nestkernel/source_table.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 313d02e1e5..a1394c071d 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -481,16 +481,16 @@ SourceTable::find_first_source( const size_t tid, bool using_compressed_spikes /* default = false */ ) const { - const auto source_begin = sources_[ tid ][ syn_id ].cbegin(); - const auto source_end = sources_[ tid ][ syn_id ].cend(); + const auto source_begin = sources_[ tid ][ syn_id ].begin(); + const auto source_end = sources_[ tid ][ syn_id ].end(); const Source selected_source { snode_id, /* is_primary */ true }; - auto find_source = []( auto begin, auto end, const Source& value ) -> size_t + auto find_source_lcid = []( auto begin, auto end, const Source& value ) -> size_t { - iter = std::find_if( begin, + auto iter = std::find_if( begin, end, - [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() && not src.is_disabled(); } ); + [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() and not src.is_disabled(); } ); if ( iter != end ) { const size_t lcid = iter - begin; @@ -504,12 +504,10 @@ SourceTable::find_first_source( const size_t tid, if ( using_compressed_spikes ) { - auto iter = std::lower_bound( iter, source_end, selected_source ); + iter = std::lower_bound( iter, source_end, selected_source ); } - auto ret = find_source( iter, source_end, selected_source ); - - return ret; + return find_source_lcid( iter, source_end, selected_source ); } inline void From 7610668e01d691929cd50fc79eb3928c58cbf424 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Mon, 22 Sep 2025 22:12:16 +0200 Subject: [PATCH 19/27] Compare Iter with origin --- nestkernel/source_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index a1394c071d..0f2e1d8fc0 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -486,14 +486,14 @@ SourceTable::find_first_source( const size_t tid, const Source selected_source { snode_id, /* is_primary */ true }; - auto find_source_lcid = []( auto begin, auto end, const Source& value ) -> size_t + auto find_source_lcid = [ &source_begin ]( auto begin, auto end, const Source& value ) -> size_t { auto iter = std::find_if( begin, end, [ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() and not src.is_disabled(); } ); if ( iter != end ) { - const size_t lcid = iter - begin; + const size_t lcid = iter - source_begin; return lcid; } // no enabled entry with this snode ID found From e99e03c74ab590861be94ba6d03937c2cc2a995f Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Wed, 24 Sep 2025 23:19:32 +0200 Subject: [PATCH 20/27] Fix find_connection implementation for use_compressed_spike=OFF --- nestkernel/connection_manager.cpp | 49 +++++++++++++++++++++---------- nestkernel/connection_manager.h | 3 +- nestkernel/connector_base.h | 12 ++++++-- nestkernel/source_table.h | 23 +++++++++++++++ 4 files changed, 67 insertions(+), 20 deletions(-) diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index 72fe4b165e..ee050bbd2b 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -55,6 +55,7 @@ #include "kernel_manager.h" #include "mpi_manager_impl.h" #include "nest_names.h" +#include "nest_types.h" #include "node.h" #include "sonata_connector.h" #include "stopwatch_impl.h" @@ -978,21 +979,37 @@ nest::ConnectionManager::find_connection( const size_t tid, { // lcid will hold the position of the /first/ connection from node // snode_id to any local node, or be invalid - size_t lcid = source_table_.find_first_source( tid, syn_id, snode_id, use_compressed_spikes() ); - if ( lcid == invalid_index ) - { - return invalid_index; - } - // lcid will hold the position of the /first/ connection from node - // snode_id to node tnode_id, or be invalid - lcid = connections_[ tid ][ syn_id ]->find_first_target( tid, lcid, tnode_id ); - if ( lcid != invalid_index ) + if ( use_compressed_spikes() ) { + size_t source_index = source_table_.find_first_source( tid, syn_id, snode_id, use_compressed_spikes() ); + if ( source_index == invalid_index ) + { + return invalid_index; + } + + // lcid will hold the position of the /first/ connection from node + // snode_id to node tnode_id, or be invalid + size_t lcid = + connections_[ tid ][ syn_id ]->find_first_target( tid, source_index, tnode_id, use_compressed_spikes() ); + return lcid; } + else + { + size_t lcid = connections_[ tid ][ syn_id ]->find_first_target( tid, 0, tnode_id, use_compressed_spikes() ); + if ( lcid == invalid_index ) + { + return invalid_index; + } + + std::vector< size_t > lcids {}; + connections_[ tid ][ syn_id ]->get_source_lcids( tid, tnode_id, lcids ); + size_t source_index = source_table_.select_source_lcid_from_list( tid, snode_id, syn_id, lcids ); - return lcid; + return source_index; + } + return invalid_index; } void @@ -1003,7 +1020,7 @@ nest::ConnectionManager::disconnect( const size_t tid, { assert( syn_id != invalid_synindex ); - const size_t lcid = find_connection( tid, syn_id, snode_id, tnode_id ); + const auto lcid = find_connection( tid, syn_id, snode_id, tnode_id ); if ( lcid == invalid_index ) // this function should only be called // with a valid connection @@ -1025,7 +1042,7 @@ nest::ConnectionManager::trigger_update_weight( const long vt_id, const size_t tid = kernel().vp_manager.get_thread_id(); for ( std::vector< ConnectorBase* >::iterator it = connections_[ tid ].begin(); it != connections_[ tid ].end(); - ++it ) + ++it ) { if ( *it ) { @@ -1312,8 +1329,8 @@ nest::ConnectionManager::get_connections_from_sources_( const size_t tid, else { for ( std::vector< size_t >::const_iterator t_node_id = target_neuron_node_ids.begin(); - t_node_id != target_neuron_node_ids.end(); - ++t_node_id ) + t_node_id != target_neuron_node_ids.end(); + ++t_node_id ) { // target_table_devices_ contains connections both to and from // devices. First we get connections from devices. @@ -1321,8 +1338,8 @@ nest::ConnectionManager::get_connections_from_sources_( const size_t tid, source_node_id, *t_node_id, tid, syn_id, synapse_label, conns_in_thread ); } for ( std::vector< size_t >::const_iterator t_node_id = target_device_node_ids.begin(); - t_node_id != target_device_node_ids.end(); - ++t_node_id ) + t_node_id != target_device_node_ids.end(); + ++t_node_id ) { // Then, we get connections to devices. target_table_devices_.get_connections_to_devices_( diff --git a/nestkernel/connection_manager.h b/nestkernel/connection_manager.h index d29999b520..8b558c698b 100644 --- a/nestkernel/connection_manager.h +++ b/nestkernel/connection_manager.h @@ -201,7 +201,8 @@ class ConnectionManager : public ManagerInterface const DictionaryDatum& third_connectivity, const std::map< Name, std::vector< DictionaryDatum > >& synapse_specs ); - size_t find_connection( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); + size_t + find_connection( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); void disconnect( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); diff --git a/nestkernel/connector_base.h b/nestkernel/connector_base.h index 7cdd91b1e8..3144cbab14 100644 --- a/nestkernel/connector_base.h +++ b/nestkernel/connector_base.h @@ -189,7 +189,10 @@ class ConnectorBase * where the node_id of the target matches target_node_id. If there are no matches, * the function returns invalid_index. */ - virtual size_t find_first_target( const size_t tid, const size_t start_lcid, const size_t target_node_id ) const = 0; + virtual size_t find_first_target( const size_t tid, + const size_t start_lcid, + const size_t target_node_id, + bool use_compressed_spikes = false ) const = 0; /** * Return lcid of first connection where the node ID of the target @@ -464,7 +467,10 @@ class Connector : public ConnectorBase } size_t - find_first_target( const size_t tid, const size_t start_lcid, const size_t target_node_id ) const override + find_first_target( const size_t tid, + const size_t start_lcid, + const size_t target_node_id, + bool use_compressed_spikes = false ) const override { size_t lcid = start_lcid; while ( true ) @@ -474,7 +480,7 @@ class Connector : public ConnectorBase return lcid; } - if ( not C_[ lcid ].source_has_more_targets() ) + if ( not C_[ lcid ].source_has_more_targets() and use_compressed_spikes ) { return invalid_index; } diff --git a/nestkernel/source_table.h b/nestkernel/source_table.h index 0f2e1d8fc0..a4ebef7424 100644 --- a/nestkernel/source_table.h +++ b/nestkernel/source_table.h @@ -26,7 +26,9 @@ // C++ includes: #include #include +#include #include +#include #include #include #include @@ -306,6 +308,11 @@ class SourceTable const size_t snode_id, bool using_compressed_spikes = false ) const; + size_t select_source_lcid_from_list( const size_t tid, + const size_t snode_id, + const size_t syn_id, + const std::vector< size_t >& lcids ) const; + /** * Marks entry in sources_ at given position as disabled. */ @@ -473,6 +480,22 @@ SourceTable::no_targets_to_process( const size_t tid ) current_positions_[ tid ].syn_id = -1; current_positions_[ tid ].lcid = -1; } +inline size_t +SourceTable::select_source_lcid_from_list( const size_t tid, + const size_t snode_id, + const size_t syn_id, + const std::vector< size_t >& lcids ) const +{ + for ( const auto& lcid : lcids ) + { + auto sources = sources_[ tid ][ syn_id ]; + if ( lcid < sources.size() and sources[ lcid ].get_node_id() == snode_id ) + { + return lcid; + } + } + return invalid_lcid; +} inline size_t SourceTable::find_first_source( const size_t tid, From f8170d53b90ececd76cc5300225db0752744fb51 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Wed, 24 Sep 2025 23:30:55 +0200 Subject: [PATCH 21/27] Add pytest --- ...est_connectivity_with_compressed_spikes.py | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 testsuite/pytests/test_connectivity_with_compressed_spikes.py diff --git a/testsuite/pytests/test_connectivity_with_compressed_spikes.py b/testsuite/pytests/test_connectivity_with_compressed_spikes.py new file mode 100644 index 0000000000..4c2662fda6 --- /dev/null +++ b/testsuite/pytests/test_connectivity_with_compressed_spikes.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +# +# test_issue_3442.py +# +# This file is part of NEST. +# +# Copyright (C) 2004 The NEST Initiative +# +# NEST is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# NEST is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NEST. If not, see . + + +import nest +import pytest +import random + +""" +Testing disconnection of connections with compressd spikes, toggled on/off, using a random edge order. +""" + + +@pytest.mark.parametrize("with_compressed_spikes", [False, True]) +@pytest.mark.parametrize("n_nodes", [5, 10, 13, 42]) +def test_disconnect_one_by_one(with_compressed_spikes, n_nodes): + nest.ResetKernel() + + nest.use_compressed_spikes = with_compressed_spikes + + n = nest.Create("parrot_neuron", n_nodes) + nest.Connect(n, n) + + nest.GetConnections() + + pairs = [(i, j) for i in range(1, n_nodes + 1) for j in range(1, n_nodes + 1)] + random.shuffle(pairs) + + for i, j in pairs: + nest.Disconnect(n[i - 1], n[j - 1]) + + +@pytest.mark.parametrize("with_compressed_spikes", [False, True]) +@pytest.mark.parametrize("n_nodes", [5, 10, 13, 42]) +def test_disconnect_all_at_once(with_compressed_spikes, n_nodes): + nest.ResetKernel() + + nest.use_compressed_spikes = with_compressed_spikes + + n = nest.Create("parrot_neuron", n_nodes) + nest.Connect(n, n) + + nest.GetConnections() + + nest.Disconnect(n, n) + + +@pytest.mark.parametrize("with_compressed_spikes", [False, True]) +@pytest.mark.parametrize("n_nodes", [5, 10, 13, 42]) +def test_disconnect_by_edge(with_compressed_spikes, n_nodes): + nest.ResetKernel() + + nest.use_compressed_spikes = with_compressed_spikes + + n = nest.Create("parrot_neuron", n_nodes) + nest.Connect(n, n) + + c = nest.GetConnections() + + edges = [i for i in range(0, n_nodes * n_nodes)] + random.shuffle(edges) + + for i in edges: + c[i].disconnect() From 007501f93ccd86b275decf5cad0d9b2b22a0deca Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Wed, 24 Sep 2025 23:35:10 +0200 Subject: [PATCH 22/27] Format files --- nestkernel/connection_manager.cpp | 10 +++++----- nestkernel/connection_manager.h | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index ee050bbd2b..667e8e7719 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -1042,7 +1042,7 @@ nest::ConnectionManager::trigger_update_weight( const long vt_id, const size_t tid = kernel().vp_manager.get_thread_id(); for ( std::vector< ConnectorBase* >::iterator it = connections_[ tid ].begin(); it != connections_[ tid ].end(); - ++it ) + ++it ) { if ( *it ) { @@ -1329,8 +1329,8 @@ nest::ConnectionManager::get_connections_from_sources_( const size_t tid, else { for ( std::vector< size_t >::const_iterator t_node_id = target_neuron_node_ids.begin(); - t_node_id != target_neuron_node_ids.end(); - ++t_node_id ) + t_node_id != target_neuron_node_ids.end(); + ++t_node_id ) { // target_table_devices_ contains connections both to and from // devices. First we get connections from devices. @@ -1338,8 +1338,8 @@ nest::ConnectionManager::get_connections_from_sources_( const size_t tid, source_node_id, *t_node_id, tid, syn_id, synapse_label, conns_in_thread ); } for ( std::vector< size_t >::const_iterator t_node_id = target_device_node_ids.begin(); - t_node_id != target_device_node_ids.end(); - ++t_node_id ) + t_node_id != target_device_node_ids.end(); + ++t_node_id ) { // Then, we get connections to devices. target_table_devices_.get_connections_to_devices_( diff --git a/nestkernel/connection_manager.h b/nestkernel/connection_manager.h index 8b558c698b..d29999b520 100644 --- a/nestkernel/connection_manager.h +++ b/nestkernel/connection_manager.h @@ -201,8 +201,7 @@ class ConnectionManager : public ManagerInterface const DictionaryDatum& third_connectivity, const std::map< Name, std::vector< DictionaryDatum > >& synapse_specs ); - size_t - find_connection( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); + size_t find_connection( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); void disconnect( const size_t tid, const synindex syn_id, const size_t snode_id, const size_t tnode_id ); From a344c571614ad59b092a1e04507d442b42d971dd Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Wed, 24 Sep 2025 23:37:53 +0200 Subject: [PATCH 23/27] Fix copyright header --- testsuite/pytests/test_connectivity_with_compressed_spikes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/pytests/test_connectivity_with_compressed_spikes.py b/testsuite/pytests/test_connectivity_with_compressed_spikes.py index 4c2662fda6..7c7a02ee65 100644 --- a/testsuite/pytests/test_connectivity_with_compressed_spikes.py +++ b/testsuite/pytests/test_connectivity_with_compressed_spikes.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# test_issue_3442.py +# test_connectivity_with_compressed_spikes.py # # This file is part of NEST. # From 097babd1fd397ebf0b0aa06661fffca9ddec79fe Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Wed, 24 Sep 2025 23:40:08 +0200 Subject: [PATCH 24/27] Sort imports --- testsuite/pytests/test_connectivity_with_compressed_spikes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testsuite/pytests/test_connectivity_with_compressed_spikes.py b/testsuite/pytests/test_connectivity_with_compressed_spikes.py index 7c7a02ee65..18151c06a5 100644 --- a/testsuite/pytests/test_connectivity_with_compressed_spikes.py +++ b/testsuite/pytests/test_connectivity_with_compressed_spikes.py @@ -20,9 +20,10 @@ # along with NEST. If not, see . +import random + import nest import pytest -import random """ Testing disconnection of connections with compressd spikes, toggled on/off, using a random edge order. From 0c4048b1ef8f7759258b7989b1ac55c1626e1fbf Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Thu, 25 Sep 2025 19:52:24 +0200 Subject: [PATCH 25/27] Add bit flag for disabled sources --- libnestutil/nest_types.h | 2 +- nestkernel/source.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libnestutil/nest_types.h b/libnestutil/nest_types.h index 2e37234248..ad55ddfb9b 100644 --- a/libnestutil/nest_types.h +++ b/libnestutil/nest_types.h @@ -92,7 +92,7 @@ constexpr uint8_t NUM_BITS_PROCESSED_FLAG = 1U; constexpr uint8_t NUM_BITS_MARKER_SPIKE_DATA = 2U; constexpr uint8_t NUM_BITS_LAG = 14U; constexpr uint8_t NUM_BITS_DELAY = 21U; -constexpr uint8_t NUM_BITS_NODE_ID = 62U; +constexpr uint8_t NUM_BITS_NODE_ID = 61U; // Maximally allowed values for bitfields diff --git a/nestkernel/source.h b/nestkernel/source.h index c4e93ec11c..0852e274d1 100644 --- a/nestkernel/source.h +++ b/nestkernel/source.h @@ -44,6 +44,7 @@ class Source bool processed_ : 1; //!< whether this target has already been moved //!< to the MPI buffer bool primary_ : 1; + bool disabled_ : 1; public: Source(); @@ -62,6 +63,7 @@ class Source void set_processed( const bool processed ); bool is_processed() const; + /** * Sets whether Source is primary. */ @@ -91,6 +93,7 @@ inline Source::Source() : node_id_( 0 ) , processed_( false ) , primary_( true ) + , disabled_( false ) { } @@ -98,6 +101,7 @@ inline Source::Source( const uint64_t node_id, const bool is_primary ) : node_id_( node_id ) , processed_( false ) , primary_( is_primary ) + , disabled_( false ) { assert( node_id <= MAX_NODE_ID ); } @@ -142,13 +146,13 @@ Source::is_primary() const inline void Source::disable() { - node_id_ = DISABLED_NODE_ID; + disabled_ = true; } inline bool Source::is_disabled() const { - return node_id_ == DISABLED_NODE_ID; + return disabled_; } inline bool From 52460b810af83d765e59839c1316254a9797cde1 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Thu, 25 Sep 2025 19:54:51 +0200 Subject: [PATCH 26/27] Activate Source again on changing node_id --- nestkernel/source.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nestkernel/source.h b/nestkernel/source.h index 0852e274d1..ef203033c1 100644 --- a/nestkernel/source.h +++ b/nestkernel/source.h @@ -111,6 +111,7 @@ Source::set_node_id( const uint64_t node_id ) { assert( node_id <= MAX_NODE_ID ); node_id_ = node_id; + disabled_ = false; } inline uint64_t From b3941febae688c0333e5b42bdaa3d49b5e7ad886 Mon Sep 17 00:00:00 2001 From: med-ayssar Date: Thu, 25 Sep 2025 23:37:45 +0200 Subject: [PATCH 27/27] Avoid double-delete of ptr --- models/eprop_synapse.cpp | 10 ++++++++-- models/eprop_synapse_bsshslm_2020.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/models/eprop_synapse.cpp b/models/eprop_synapse.cpp index f167592024..8d93f0ce0c 100644 --- a/models/eprop_synapse.cpp +++ b/models/eprop_synapse.cpp @@ -126,7 +126,10 @@ Connector< eprop_synapse< TargetIdentifierPtrRport > >::~Connector() { for ( auto& c : C_ ) { - c.delete_optimizer(); + if ( not c.is_disabled() ) + { + c.delete_optimizer(); + } } C_.clear(); } @@ -136,7 +139,10 @@ Connector< eprop_synapse< TargetIdentifierIndex > >::~Connector() { for ( auto& c : C_ ) { - c.delete_optimizer(); + if ( not c.is_disabled() ) + { + c.delete_optimizer(); + } } C_.clear(); } diff --git a/models/eprop_synapse_bsshslm_2020.cpp b/models/eprop_synapse_bsshslm_2020.cpp index ceb1dba4d1..34cad442ff 100644 --- a/models/eprop_synapse_bsshslm_2020.cpp +++ b/models/eprop_synapse_bsshslm_2020.cpp @@ -131,7 +131,10 @@ Connector< eprop_synapse_bsshslm_2020< TargetIdentifierPtrRport > >::~Connector( { for ( auto& c : C_ ) { - c.delete_optimizer(); + if ( not c.is_disabled() ) + { + c.delete_optimizer(); + } } C_.clear(); } @@ -141,7 +144,10 @@ Connector< eprop_synapse_bsshslm_2020< TargetIdentifierIndex > >::~Connector() { for ( auto& c : C_ ) { - c.delete_optimizer(); + if ( not c.is_disabled() ) + { + c.delete_optimizer(); + } } C_.clear(); }