@@ -40,9 +40,15 @@ template<typename GraphAndGainTypes>
4040typename ParallelConstruction<GraphAndGainTypes>::TmpHyperedge
4141ParallelConstruction<GraphAndGainTypes>::DynamicIdenticalNetDetection::get(const size_t he_hash,
4242 const vec<whfc::Node>& pins) {
43+ if constexpr (PartitionedHypergraph::is_graph) {
44+ // there can't be identical nets for graphs
45+ return TmpHyperedge { 0 , std::numeric_limits<size_t >::max (), whfc::invalidHyperedge };
46+ }
47+
4348 const size_t bucket_idx = he_hash % _hash_buckets.size ();
4449 if ( __atomic_load_n (&_hash_buckets[bucket_idx].threshold , __ATOMIC_RELAXED) == _threshold ) {
4550 // There exists already some hyperedges with the same hash
51+ _hash_buckets[bucket_idx].lock .lock ();
4652 for ( const ThresholdHyperedge& tmp : _hash_buckets[bucket_idx].identical_nets ) {
4753 // Check if there is some hyperedge equal to he
4854 const TmpHyperedge& tmp_e = tmp.e ;
@@ -57,28 +63,33 @@ ParallelConstruction<GraphAndGainTypes>::DynamicIdenticalNetDetection::get(const
5763 }
5864 }
5965 if ( is_identical ) {
66+ _hash_buckets[bucket_idx].lock .unlock ();
6067 return tmp_e;
6168 }
6269 }
6370 }
71+ _hash_buckets[bucket_idx].lock .unlock ();
6472 }
6573 return TmpHyperedge { 0 , std::numeric_limits<size_t >::max (), whfc::invalidHyperedge };
6674}
6775
6876template <typename GraphAndGainTypes>
6977void ParallelConstruction<GraphAndGainTypes>::DynamicIdenticalNetDetection::add(const TmpHyperedge& tmp_he) {
78+ if constexpr (PartitionedHypergraph::is_graph) {
79+ // there can't be identical nets for graphs
80+ return ;
81+ }
82+
7083 const size_t bucket_idx = tmp_he.hash % _hash_buckets.size ();
71- uint32_t expected = __atomic_load_n (&_hash_buckets[bucket_idx].threshold , __ATOMIC_RELAXED);
72- uint32_t desired = _threshold - 1 ;
73- while ( __atomic_load_n (&_hash_buckets[bucket_idx].threshold , __ATOMIC_RELAXED) < _threshold ) {
74- if ( expected < desired &&
75- __atomic_compare_exchange (&_hash_buckets[bucket_idx].threshold ,
76- &expected, &desired, false , __ATOMIC_ACQ_REL, __ATOMIC_RELAXED) ) {
77- _hash_buckets[bucket_idx].identical_nets .clear ();
78- __atomic_store_n (&_hash_buckets[bucket_idx].threshold , _threshold, __ATOMIC_RELAXED);
79- }
84+ HashBucket& bucket = _hash_buckets[bucket_idx];
85+ bucket.lock .lock ();
86+ const uint32_t current = __atomic_load_n (&bucket.threshold , __ATOMIC_RELAXED);
87+ if (current < _threshold) {
88+ bucket.identical_nets .clear ();
89+ __atomic_store_n (&bucket.threshold , _threshold, __ATOMIC_RELAXED);
8090 }
81- _hash_buckets[bucket_idx].identical_nets .push_back (ThresholdHyperedge { tmp_he, _threshold });
91+ bucket.identical_nets .push_back (ThresholdHyperedge { tmp_he, _threshold });
92+ bucket.lock .unlock ();
8293}
8394
8495template <typename GraphAndGainTypes>
0 commit comments