mirror of
https://github.com/opencv/opencv.git
synced 2024-12-11 14:39:11 +08:00
avoid calling of setNumThreads() to respect user settings
This commit is contained in:
parent
265f335dae
commit
3b15f3e3b9
@ -67,7 +67,6 @@ PERF_TEST_P( TestStereoCorresp, DISABLED_TooLongInDebug_SGBM, Combine(Values(Siz
|
|||||||
|
|
||||||
MakeArtificialExample(rng,src_left,src_right);
|
MakeArtificialExample(rng,src_left,src_right);
|
||||||
|
|
||||||
cv::setNumThreads(cv::getNumberOfCPUs());
|
|
||||||
int wsize = 3;
|
int wsize = 3;
|
||||||
int P1 = 8*src_left.channels()*wsize*wsize;
|
int P1 = 8*src_left.channels()*wsize*wsize;
|
||||||
TEST_CYCLE()
|
TEST_CYCLE()
|
||||||
|
@ -382,6 +382,7 @@ TEST(Calib3d_SolvePnPRansac, concurrency)
|
|||||||
Mat rvec1, rvec2;
|
Mat rvec1, rvec2;
|
||||||
Mat tvec1, tvec2;
|
Mat tvec1, tvec2;
|
||||||
|
|
||||||
|
int threads = getNumThreads();
|
||||||
{
|
{
|
||||||
// limit concurrency to get deterministic result
|
// limit concurrency to get deterministic result
|
||||||
theRNG().state = 20121010;
|
theRNG().state = 20121010;
|
||||||
@ -390,6 +391,7 @@ TEST(Calib3d_SolvePnPRansac, concurrency)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
setNumThreads(threads);
|
||||||
Mat rvec;
|
Mat rvec;
|
||||||
Mat tvec;
|
Mat tvec;
|
||||||
// parallel executions
|
// parallel executions
|
||||||
|
@ -579,9 +579,6 @@ namespace cv{
|
|||||||
CV_Assert(img.cols == imgLabels.cols);
|
CV_Assert(img.cols == imgLabels.cols);
|
||||||
CV_Assert(connectivity == 8 || connectivity == 4);
|
CV_Assert(connectivity == 8 || connectivity == 4);
|
||||||
|
|
||||||
const int nThreads = cv::getNumberOfCPUs();
|
|
||||||
cv::setNumThreads(nThreads);
|
|
||||||
|
|
||||||
const int h = img.rows;
|
const int h = img.rows;
|
||||||
const int w = img.cols;
|
const int w = img.cols;
|
||||||
|
|
||||||
@ -606,12 +603,13 @@ namespace cv{
|
|||||||
P[0] = 0;
|
P[0] = 0;
|
||||||
|
|
||||||
cv::Range range(0, h);
|
cv::Range range(0, h);
|
||||||
|
const double nParallelStripes = std::max(1, std::min(h / 2, getNumThreads()*4));
|
||||||
|
|
||||||
LabelT nLabels = 1;
|
LabelT nLabels = 1;
|
||||||
|
|
||||||
if (connectivity == 8){
|
if (connectivity == 8){
|
||||||
//First scan, each thread works with chunk of img.rows/nThreads rows
|
//First scan
|
||||||
//e.g. 300 rows, 4 threads -> each chunks is composed of 75 rows
|
cv::parallel_for_(range, FirstScan8Connectivity(img, imgLabels, P, chunksSizeAndLabels), nParallelStripes);
|
||||||
cv::parallel_for_(range, FirstScan8Connectivity(img, imgLabels, P, chunksSizeAndLabels), nThreads);
|
|
||||||
|
|
||||||
//merge labels of different chunks
|
//merge labels of different chunks
|
||||||
mergeLabels8Connectivity(imgLabels, P, chunksSizeAndLabels);
|
mergeLabels8Connectivity(imgLabels, P, chunksSizeAndLabels);
|
||||||
@ -621,9 +619,8 @@ namespace cv{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//First scan, each thread works with chunk of img.rows/nThreads rows
|
//First scan
|
||||||
//e.g. 300 rows, 4 threads -> each chunks is composed of 75 rows
|
cv::parallel_for_(range, FirstScan4Connectivity(img, imgLabels, P, chunksSizeAndLabels), nParallelStripes);
|
||||||
cv::parallel_for_(range, FirstScan4Connectivity(img, imgLabels, P, chunksSizeAndLabels), nThreads);
|
|
||||||
|
|
||||||
//merge labels of different chunks
|
//merge labels of different chunks
|
||||||
mergeLabels4Connectivity(imgLabels, P, chunksSizeAndLabels);
|
mergeLabels4Connectivity(imgLabels, P, chunksSizeAndLabels);
|
||||||
@ -638,7 +635,7 @@ namespace cv{
|
|||||||
|
|
||||||
sop.init(nLabels);
|
sop.init(nLabels);
|
||||||
//Second scan
|
//Second scan
|
||||||
cv::parallel_for_(range, SecondScan(imgLabels, P, sop, sopArray, nLabels), nThreads);
|
cv::parallel_for_(range, SecondScan(imgLabels, P, sop, sopArray, nLabels), nParallelStripes);
|
||||||
StatsOp::mergeStats(imgLabels, sopArray, sop, nLabels);
|
StatsOp::mergeStats(imgLabels, sopArray, sop, nLabels);
|
||||||
sop.finish();
|
sop.finish();
|
||||||
|
|
||||||
@ -2530,9 +2527,6 @@ namespace cv{
|
|||||||
CV_Assert(img.cols == imgLabels.cols);
|
CV_Assert(img.cols == imgLabels.cols);
|
||||||
CV_Assert(connectivity == 8);
|
CV_Assert(connectivity == 8);
|
||||||
|
|
||||||
const int nThreads = cv::getNumberOfCPUs();
|
|
||||||
cv::setNumThreads(nThreads);
|
|
||||||
|
|
||||||
const int h = img.rows;
|
const int h = img.rows;
|
||||||
const int w = img.cols;
|
const int w = img.cols;
|
||||||
|
|
||||||
@ -2556,10 +2550,11 @@ namespace cv{
|
|||||||
P[0] = 0;
|
P[0] = 0;
|
||||||
|
|
||||||
cv::Range range(0, h);
|
cv::Range range(0, h);
|
||||||
|
const double nParallelStripes = std::max(1, std::min(h / 2, getNumThreads()*4));
|
||||||
|
|
||||||
//First scan, each thread works with chunk of img.rows/nThreads rows
|
//First scan, each thread works with chunk of img.rows/nThreads rows
|
||||||
//e.g. 300 rows, 4 threads -> each chunks is composed of 75 rows
|
//e.g. 300 rows, 4 threads -> each chunks is composed of 75 rows
|
||||||
cv::parallel_for_(range, FirstScan(img, imgLabels, P, chunksSizeAndLabels), nThreads);
|
cv::parallel_for_(range, FirstScan(img, imgLabels, P, chunksSizeAndLabels), nParallelStripes);
|
||||||
|
|
||||||
//merge labels of different chunks
|
//merge labels of different chunks
|
||||||
mergeLabels(img, imgLabels, P, chunksSizeAndLabels);
|
mergeLabels(img, imgLabels, P, chunksSizeAndLabels);
|
||||||
@ -2574,7 +2569,7 @@ namespace cv{
|
|||||||
sop.init(nLabels);
|
sop.init(nLabels);
|
||||||
|
|
||||||
//Second scan
|
//Second scan
|
||||||
cv::parallel_for_(range, SecondScan(img, imgLabels, P, sop, sopArray, nLabels), nThreads);
|
cv::parallel_for_(range, SecondScan(img, imgLabels, P, sop, sopArray, nLabels), nParallelStripes);
|
||||||
|
|
||||||
StatsOp::mergeStats(imgLabels, sopArray, sop, nLabels);
|
StatsOp::mergeStats(imgLabels, sopArray, sop, nLabels);
|
||||||
sop.finish();
|
sop.finish();
|
||||||
@ -3936,12 +3931,12 @@ namespace cv{
|
|||||||
int lDepth = L.depth();
|
int lDepth = L.depth();
|
||||||
int iDepth = I.depth();
|
int iDepth = I.depth();
|
||||||
const char *currentParallelFramework = cv::currentParallelFramework();
|
const char *currentParallelFramework = cv::currentParallelFramework();
|
||||||
const int numberOfCPUs = cv::getNumberOfCPUs();
|
const int nThreads = cv::getNumThreads();
|
||||||
|
|
||||||
CV_Assert(iDepth == CV_8U || iDepth == CV_8S);
|
CV_Assert(iDepth == CV_8U || iDepth == CV_8S);
|
||||||
|
|
||||||
//Run parallel labeling only if the rows of the image are at least twice the number returned by getNumberOfCPUs
|
//Run parallel labeling only if the rows of the image are at least twice the number of available threads
|
||||||
const bool is_parallel = currentParallelFramework != NULL && numberOfCPUs > 1 && L.rows / numberOfCPUs >= 2;
|
const bool is_parallel = currentParallelFramework != NULL && nThreads > 1 && L.rows / nThreads >= 2;
|
||||||
|
|
||||||
if (ccltype == CCL_WU || connectivity == 4){
|
if (ccltype == CCL_WU || connectivity == 4){
|
||||||
// Wu algorithm is used
|
// Wu algorithm is used
|
||||||
|
Loading…
Reference in New Issue
Block a user