Skip to content

Commit 168a3f9

Browse files
committed
Resolve concurrency bug in nonblocking backend that was laid bare by new unit test
1 parent 6cae20f commit 168a3f9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

include/graphblas/nonblocking/pipeline.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ namespace grb {
173173
* The set is built explicitly before the execution of the pipeline in the
174174
* execution method.
175175
*/
176-
std::set< const Coordinates< nonblocking > * > already_dense_coordinates;
176+
std::map< const Coordinates< nonblocking > *, bool >
177+
already_dense_coordinates;
177178
#endif
178179
/**
179180
* This set of vectors is used for the verification for correct usage of the

src/graphblas/nonblocking/pipeline.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Pipeline::Pipeline() {
7373
input_matrices.insert( dummy );
7474
out_of_place_output_coordinates.insert( dumCoor );
7575
#ifdef GRB_ALREADY_DENSE_OPTIMIZATION
76-
already_dense_coordinates.insert( dumCCoor );
76+
already_dense_coordinates.insert( std::make_pair( dumCCoor, true ) );
7777
#endif
7878
dense_descr_coordinates.insert( dumCoor );
7979
}
@@ -540,22 +540,21 @@ bool Pipeline::emptyAlreadyDenseVectors() const {
540540
bool Pipeline::containsAlreadyDenseVector(
541541
const Coordinates< nonblocking > * const vector_ptr
542542
) const {
543-
return already_dense_coordinates.find( vector_ptr ) !=
544-
already_dense_coordinates.end();
543+
const auto it = already_dense_coordinates.find( vector_ptr );
544+
return it != already_dense_coordinates.cend() && it->second;
545545
}
546546

547547
void Pipeline::markMaybeSparseVector(
548548
const Coordinates< nonblocking > * const vector_ptr
549549
) {
550550
// the vector should be marked sparse only if it has not already been marked
551-
if( already_dense_coordinates.find( vector_ptr ) !=
552-
already_dense_coordinates.end()
553-
) {
551+
auto it = already_dense_coordinates.find( vector_ptr );
552+
if( it != already_dense_coordinates.end() ) {
554553
// when this method is invoked by an out-of-place primitive
555554
// disable a potentially enabled dense descriptor
556555
all_already_dense_vectors = false;
557-
// and remove the coordinates from the set
558-
already_dense_coordinates.erase( vector_ptr );
556+
// and disable the coordinates
557+
it->second = false;
559558
}
560559
}
561560
#endif
@@ -699,7 +698,7 @@ void Pipeline::buildAlreadyDenseVectors() {
699698
it != dense_descr_coordinates.end(); ++it
700699
) {
701700
if( ( *it )->isDense() ) {
702-
already_dense_coordinates.insert( *it );
701+
already_dense_coordinates.insert( std::make_pair( *it, true ) );
703702
} else {
704703
all_already_dense_vectors = false;
705704
}
@@ -711,7 +710,7 @@ void Pipeline::buildAlreadyDenseVectors() {
711710
it != accessed_coordinates.end(); ++it
712711
) {
713712
if( ( *it )->isDense() ) {
714-
already_dense_coordinates.insert( *it );
713+
already_dense_coordinates.insert( std::make_pair( *it, true ) );
715714
} else {
716715
all_already_dense_vectors = false;
717716
}

0 commit comments

Comments
 (0)