Advertisement
Guest User

Untitled

a guest
May 26th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. static void parallel_for_impl(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
  2. {
  3.     if ((numThreads < 0 || numThreads > 1) && range.end - range.start > 1)
  4.     {
  5.         ParallelLoopBodyWrapperContext ctx(body, range, nstripes);
  6.         ProxyLoopBody pbody(ctx);
  7.         cv::Range stripeRange = pbody.stripeRange();
  8.         if( stripeRange.end - stripeRange.start == 1 )
  9.         {
  10.             body(range);
  11.             return;
  12.         }
  13.  
  14. #if defined HAVE_TBB
  15.  
  16. #if TBB_INTERFACE_VERSION >= 8000
  17.         tbbArena.execute(pbody);
  18. #else
  19.         pbody();
  20. #endif
  21.  
  22. #elif defined HAVE_HPX
  23.         pbody();
  24. #elif defined HAVE_OPENMP
  25.  
  26.         #pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax)
  27.         for (int i = stripeRange.start; i < stripeRange.end; ++i)
  28.             pbody(Range(i, i + 1));
  29.  
  30. #elif defined HAVE_GCD
  31.  
  32.         dispatch_queue_t concurrent_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  33.         dispatch_apply_f(stripeRange.end - stripeRange.start, concurrent_queue, &pbody, block_function);
  34.  
  35. #elif defined WINRT
  36.  
  37.         Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
  38.  
  39. #elif defined HAVE_CONCURRENCY
  40.  
  41.         if(!pplScheduler || pplScheduler->Id() == Concurrency::CurrentScheduler::Id())
  42.         {
  43.             Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
  44.         }
  45.         else
  46.         {
  47.             pplScheduler->Attach();
  48.             Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
  49.             Concurrency::CurrentScheduler::Detach();
  50.         }
  51.  
  52. #elif defined HAVE_PTHREADS_PF
  53.  
  54.         parallel_for_pthreads(pbody.stripeRange(), pbody, pbody.stripeRange().size());
  55.  
  56. #else
  57.  
  58. #error You have hacked and compiling with unsupported parallel framework
  59.  
  60. #endif
  61.  
  62.         ctx.finalize();  // propagate exceptions if exists
  63.     }
  64.     else
  65.     {
  66.         body(range);
  67.     }
  68. }
  69.  
  70.  
  71.     class ProxyLoopBody : public ParallelLoopBodyWrapper
  72.     {
  73.     public:
  74.         ProxyLoopBody(ParallelLoopBodyWrapperContext& ctx_)
  75.         : ParallelLoopBodyWrapper(ctx_)
  76.         {}
  77.  
  78.         void operator ()() const  // run parallel job
  79.         {
  80.             cv::Range range = this->stripeRange();
  81.             hpx::parallel::for_loop_strided(
  82.                     hpx::parallel::execution::par,
  83.                     range.start, range.end, 1,
  84.                     &ctx.body);
  85.         }
  86.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement