Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void parallel_for_impl(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
- {
- if ((numThreads < 0 || numThreads > 1) && range.end - range.start > 1)
- {
- ParallelLoopBodyWrapperContext ctx(body, range, nstripes);
- ProxyLoopBody pbody(ctx);
- cv::Range stripeRange = pbody.stripeRange();
- if( stripeRange.end - stripeRange.start == 1 )
- {
- body(range);
- return;
- }
- #if defined HAVE_TBB
- #if TBB_INTERFACE_VERSION >= 8000
- tbbArena.execute(pbody);
- #else
- pbody();
- #endif
- #elif defined HAVE_HPX
- pbody();
- #elif defined HAVE_OPENMP
- #pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax)
- for (int i = stripeRange.start; i < stripeRange.end; ++i)
- pbody(Range(i, i + 1));
- #elif defined HAVE_GCD
- dispatch_queue_t concurrent_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_apply_f(stripeRange.end - stripeRange.start, concurrent_queue, &pbody, block_function);
- #elif defined WINRT
- Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
- #elif defined HAVE_CONCURRENCY
- if(!pplScheduler || pplScheduler->Id() == Concurrency::CurrentScheduler::Id())
- {
- Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
- }
- else
- {
- pplScheduler->Attach();
- Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
- Concurrency::CurrentScheduler::Detach();
- }
- #elif defined HAVE_PTHREADS_PF
- parallel_for_pthreads(pbody.stripeRange(), pbody, pbody.stripeRange().size());
- #else
- #error You have hacked and compiling with unsupported parallel framework
- #endif
- ctx.finalize(); // propagate exceptions if exists
- }
- else
- {
- body(range);
- }
- }
- class ProxyLoopBody : public ParallelLoopBodyWrapper
- {
- public:
- ProxyLoopBody(ParallelLoopBodyWrapperContext& ctx_)
- : ParallelLoopBodyWrapper(ctx_)
- {}
- void operator ()() const // run parallel job
- {
- cv::Range range = this->stripeRange();
- hpx::parallel::for_loop_strided(
- hpx::parallel::execution::par,
- range.start, range.end, 1,
- &ctx.body);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement