parallel_for randomly hangs
Hi,
.
I have a simple parallel_for loop that seems to hang on the majority of the runs of the code. Sometimes it works great, and other times it hangs.
.
When using gdb and breakpointing when it hangs, I find the following:
.
(gdb) bt
tbb::internal::custom_scheduler::receive_or_steal_task ()
tbb::internal::custom_scheduler::local_wait_for_all ()
tbb::internal::generic_scheduler::local_spawn_root_and_wait ()
.
.
A slightly simplified version of the code is below, where "num_neighbors" is typically between 20-400.
.
tbb::parallel_for(tbb::blocked_range(0, num_neighbors),
ParallelRegionDistanceEvaluator(
&neighbor_infos,
num_descriptors,
®ion_distances));
.
.
class ParallelRegionDistanceEvaluator {
public:
ParallelRegionDistanceEvaluator(const vector* neighbor_infos,
const int num_descriptors,
vector* results) :
neighbor_infos_(neighbor_infos),
num_descriptors_(num_descriptors),
results_(results)
{}
ParallelRegionDistanceEvaluator(const ParallelRegionDistanceEvaluator& rhs,
tbb::split) :
neighbor_infos_(rhs.neighbor_infos_),
num_descriptors_(rhs.num_descriptors_),
results_(rhs.results_)
{}
void operator()(const tbb::blocked_range& r) const {
vector descriptor_distances(num_descriptors_);
for (int i = r.begin(); i != r.end(); ++i) {
const float region_dist = Evaluate(*(*neighbor_infos_)[i], descriptor_distances);
(*results_)[i] = region_dist;
}
}
private:
const int num_descriptors_;
const vector* neighbor_infos_;
vector* results_;
};
.
.
Playing around a bit, forcing the "num_neighbors" value to parallel_for() to be greater than 100 or so *seems* to remedy/reduce the problem, but the code does reliably run every now and then with any "num_neighbors" size allowed, and I've seen it fail once when it's greater than 100 too.
It almost seems random when/if the code hangs during this call to parallel_for().
.
Any suggestions would be great.
.
Thanks,
~Chris
.
.




