我有一个由英特尔 IPP 定义的函数来对图像/图像区域进行操作。
图像的输入是指向图像的指针、定义要处理的尺寸的参数和过滤器的参数。
IPP 函数是单线程的。
现在,我有一个大小为 M x N 的图像。
我想在其上并行应用过滤器。
主要思想很简单,将图像分解为 4 个相互独立的子图像。
将过滤器应用于每个子图像并将结果写入空图像的子块,其中每个线程写入一组不同的像素。
这真的就像在自己的核心上处理 4 个图像。
这是我正在使用的程序:
void OpenMpTest()
{
const int width = 1920;
const int height = 1080;
Ipp32f input_image[width * height];
Ipp32f output_image[width * height];
IppiSize size = { width, height };
int step = width * sizeof(Ipp32f);
/* Splitting the image */
IppiSize section_size = { width / 2, height / 2};
Ipp32f* input_upper_left = input_image;
Ipp32f* input_upper_right = input_image + width / 2;
Ipp32f* input_lower_left = input_image + (height / 2) * width;
Ipp32f* input_lower_right = input_image + (height / 2) * width + width / 2;
Ipp32f* output_upper_left = input_image;
Ipp32f* output_upper_right = input_image + width / 2;
Ipp32f* output_lower_left = input_image + (height / 2) * width;
Ipp32f* output_lower_right = input_image + (height / 2) * width + width / 2;
Ipp32f* input_sections[4] = { input_upper_left, input_upper_right, input_lower_left, input_lower_right };
Ipp32f* output_sections[4] = { output_upper_left, output_upper_right, output_lower_left, output_lower_right };
/* Filter Params */
Ipp32f pKernel[7] = { 1, 2, 3, 4, 3, 2, 1 };
omp_set_num_threads(4);
#pragma omp parallel for
for (int i = 0; i < 4; i++)
ippiFilterRow_32f_C1R(
input_sections[i], step,
output_sections[i], step,
section_size, pKernel, 7, 3);
}
现在,问题是我没有看到与在所有图像上工作的单线程模式相比没有任何收获。
我试图改变图像大小或过滤器大小,但什么都不会改变图片。
我能获得的最多没什么意义(10-20%)。
我认为这可能与我不能“承诺”每个线程它收到的区域是“只读”的有关。
而且要让它知道它写入的内存位置也只属于他自己。
我阅读了有关将变量定义为私有和共享的信息,但我找不到处理数组和指针的指南。
在 OpenMP 中处理指针和子数组的正确方法是什么?