diff --git a/metagraph/src/common/vectors/wavelet_tree.cpp b/metagraph/src/common/vectors/wavelet_tree.cpp index ef920658b2..339e2c4ee0 100644 --- a/metagraph/src/common/vectors/wavelet_tree.cpp +++ b/metagraph/src/common/vectors/wavelet_tree.cpp @@ -4,6 +4,7 @@ #include "common/serialization.hpp" #include "common/utils/template_utils.hpp" +#include "common/threads/threading.hpp" typedef wavelet_tree::TAlphabet TAlphabet; @@ -301,7 +302,9 @@ void wavelet_tree_dyn::clear() { sdsl::int_vector<> wavelet_tree_dyn::to_vector() const { sdsl::int_vector<> vector(dwt_.size(), 0, logsigma()); - for(size_t i = 0; i < vector.size(); ++i) { + // set the block size to a multiple of 64 to avoid race conditions for any width + #pragma omp parallel for num_threads(get_num_threads()) schedule(static, 1024) + for (size_t i = 0; i < vector.size(); ++i) { vector[i] = dwt_.at(i); } return vector; @@ -392,7 +395,11 @@ bool wavelet_tree_sdsl::load(std::istream &in) { template sdsl::int_vector<> wavelet_tree_sdsl::to_vector() const { sdsl::int_vector<> vector(wwt_.size(), 0, logsigma_); - std::copy(wwt_.begin(), wwt_.end(), vector.begin()); + // set the block size to a multiple of 64 to avoid race conditions for any width + #pragma omp parallel for num_threads(get_num_threads()) schedule(static, 1024) + for (uint64_t i = 0; i < wwt_.size(); ++i) { + vector[i] = wwt_[i]; + } return vector; }