- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi

I would like to convert code to tbb but i have problem set local variable private(x1,y1,sum) and shared variable on openmp to TBB .

#pragma omp parallel for private (sum,x1,y1) for (int y = 0; y < src.rows; y++) { for (int x = 0; x < src.cols; x++) { sum = 0.0; for (int k = -1;k <= 1; k++) { for (int j = -1;j <= 1; j++) { x1 = circular(src.cols, x - j); y1 = circular(src.rows, y - k); sum = sum + Kernel[j + 1][k + 1] * src.at<uchar>(y1, x1); // cout << "threads=" << omp_get_num_threads() << endl; } } dst.at<uchar>(y, x) = sum; }

Link Copied

1 Reply

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Private variables should just be declared in the scope of a single iteration. Shared variables should be captured by reference into the loop body function.

With C++ lambda functions, the code might look like this:

tbb::parallel_for( 0, src.rows, [&](int y) { // capture shared variables into the lambda by reference for (int x = 0; x < src.cols; x++) { float sum = 0.0; // declared locally for (int k = -1;k <= 1; k++) { for (int j = -1;j <= 1; j++) { int x1 = circular(src.cols, x - j); // declared locally int y1 = circular(src.rows, y - k); // declared locally sum = sum + Kernel[j + 1][k + 1] * src.at<uchar>(y1, x1); } } dst.at<uchar>(y, x) = sum; } });

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page