Following is the code:
template<int N>
void para_sort(std::vector<bfs_node<N>>& res) {
#pragma omp parallel
{
boost::sort::block_indirect_sort(res.begin(), res.end(), compare_node<N>);
}
}
The code runs without any exception when running with only one OMP thread. However, the code throws in an exception on running with multiple threads.
The code works fine with multiple threads when Boost::Parallel_stable_sort
used.
I suspected it would be the strict weak ordering requirement that caused it raise exception. But in that case it should be raised with parallel_stable_sort
and std::sort
(sequential version).
Is boost::block_indirect_sort
demands more stricter or weaker ordering constraint.
template<int N>
bool compare_node(const bfs_node<N>& lhs, const bfs_node<N>& rhs) {
if (lhs.id == rhs.id) return false;
for (int i = 0; i < N * 64; ++i) {
bool lflag = in_set(lhs.id, i);
bool rflag = in_set(rhs.id, i);
if (lflag == rflag ) { continue; }
if (lflag) return true;
return false;
}
return false;
} //
where id
field here represents a unordered_set
type data structure. For ex: id
represents the set {1,2,3}
and in_set(id, 1)
will return true
and otherwise false
Exception raised: Invalid read of size 16 ==2125== at 0x46C59F: void boost::sort::pdqsort_detail::pdqsort_loop<__gnu_cxx::__normal_iterator<bfs_node<1>*, std::vector<bfs_node<1>, std::allocator<bfs_node<1> > > >, std::less<bfs_node<1> >, false>(__gnu_cxx::__normal_iterator<bfs_node<1>*, std::vector<bfs_node<1>, std::allocator<bfs_node<1> > > >, __gnu_cxx::__normal_iterator<bfs_node<1>*, std::vector<bfs_node<1>, std::allocator<bfs_node<1> > > >, std::less<bfs_node<1> >, int, bool)
Aucun commentaire:
Enregistrer un commentaire