1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #10691 from alalek:parallel_for_2018

This commit is contained in:
Alexander Alekhin
2018-01-30 14:13:29 +00:00
6 changed files with 816 additions and 590 deletions
+30 -8
View File
@@ -42,6 +42,7 @@
#include "precomp.hpp"
#include <opencv2/core/utils/configuration.private.hpp>
#include <opencv2/core/utils/trace.private.hpp>
#if defined _WIN32 || defined WINCE
@@ -125,19 +126,15 @@
# define CV_PARALLEL_FRAMEWORK "pthreads"
#endif
#include "parallel_impl.hpp"
using namespace cv;
namespace cv
{
ParallelLoopBody::~ParallelLoopBody() {}
#ifdef HAVE_PTHREADS_PF
void parallel_for_pthreads(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes);
size_t parallel_pthreads_get_threads_num();
void parallel_pthreads_set_threads_num(int num);
#endif
}
namespace
{
#ifdef CV_PARALLEL_FRAMEWORK
@@ -558,10 +555,35 @@ int cv::getNumThreads(void)
#endif
}
void cv::setNumThreads( int threads )
namespace cv {
unsigned defaultNumberOfThreads()
{
(void)threads;
#ifdef __ANDROID__
// many modern phones/tables have 4-core CPUs. Let's use no more
// than 2 threads by default not to overheat the devices
const unsigned int default_number_of_threads = 2;
#else
const unsigned int default_number_of_threads = (unsigned int)std::max(1, cv::getNumberOfCPUs());
#endif
unsigned result = default_number_of_threads;
static int config_num_threads = (int)utils::getConfigurationParameterSizeT("OPENCV_FOR_THREADS_NUM", 0);
if (config_num_threads)
{
result = (unsigned)std::max(1, config_num_threads);
//do we need upper limit of threads number?
}
return result;
}
}
void cv::setNumThreads( int threads_ )
{
(void)threads_;
#ifdef CV_PARALLEL_FRAMEWORK
int threads = (threads_ < 0) ? defaultNumberOfThreads() : (unsigned)threads_;
numThreads = threads;
#endif