-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parallel_for_ flagNestedParallelFor cause multi task in difference thread may not parallel #25556
Comments
@opencv-alalek could you take a look? |
It is not a bug. Parallel for is designed to work in this way. Nested parallel for does not lead to better performance. See #25260 (comment). |
This design is flawed, resulting in external non-nested calls that probabilistically cannot be concurrent. And for multi-threaded calls to a function that uses parral_for, this scheme may be invalidated
|
Just replace |
duplicate of #9336 |
@opencv-alalek This is not a duplicate of #9336 . That (low quality, no repro code) issue talks about nested (i.e. vertical) parallelization, this issue is about horizontal. |
Here is minimal reproducing example (MRE). #include <opencv2/imgproc.hpp>
#include <thread>
#include <chrono>
#include <iostream>
using namespace std;
using namespace std::chrono;
int main()
{
int rows = 20000;
int cols = 20000;
cv::Size size(cols, rows);
cv::Mat src(size, CV_8UC1);
cv::Mat out1, out2;
auto time0 = high_resolution_clock::now();
decltype(time0) time1, time2;
auto thread1 = thread([&]() {
cv::resize(src, out1, {}, 2, 2, cv::INTER_LANCZOS4);
time1 = high_resolution_clock::now();
});
auto thread2 = thread([&]() {
cv::resize(src, out2, {}, 2, 2, cv::INTER_LANCZOS4);
time2 = high_resolution_clock::now();
});
thread1.join();
thread2.join();
cout << "Time resize (thread 1) : " << duration_cast<nanoseconds>(time1 - time0).count() * 1e-9 << endl;
cout << "Time resize (thread 2) : " << duration_cast<nanoseconds>(time2 - time0).count() * 1e-9 << endl;
return 0;
} Running it twice gives Run 1: Time resize (thread 1) : 9.20218
Time resize (thread 2) : 2.04223 Run 2: Time resize (thread 1) : 2.11035
Time resize (thread 2) : 7.64846 I run |
Ah sry, ofc you cant replace |
System Information
opencv 4.9
Detailed description
When multiple threads are using cv::resize, the cv::resize of some threads cannot be fall into parallel for
Steps to reproduce
Issue submission checklist
The text was updated successfully, but these errors were encountered: