OpenMP归约失败,出现错误消息’用户自定义归约未找到’avgs’?’。

huangapple go评论52阅读模式
英文:

Why is OpenMP reduction failing with error message 'user defined reduction not found for 'avgs'?'

问题

在这段代码中,为什么对reduction(减少)的操作会引发错误:

用户定义的reduction(减少)未找到 'avgs'

我预期这段代码会使avgs的值在每个并行线程中私有化,然后在for循环执行结束时将它们全部相加。

英文:

Why is the reduction in this code throwing an error:

user defined reduction not found for 'avgs'

void parallel_avg_pixel(long img[DIM_ROW][DIM_COL][DIM_RGB], long *avgs) {
    int row, col, pixel;
    long count = 0;

#pragma omp parallel for reduction(+:avgs)
    for (row = 0; row < DIM_ROW; row++) {
        for (col = 0; col < DIM_COL; col++) {
            for (pixel = 0; pixel < DIM_RGB; pixel++){
                avgs[pixel] += img[row][col][pixel];
                count++;
            }
        }
    }

    count /= 3;

    for (pixel = 0; pixel < DIM_RGB; pixel++) {
        avgs[pixel] /= count;
    }
}

I expected this code to make the value of avgs private for each thread in parallel and then sum them all together at the end of execution of the for loops.

答案1

得分: 3

你的变量 avgs 是一个指针。你不能对指针进行缩减操作。OpenMP 告诉你,如果你想对指针进行缩减操作,你需要为它们定义一个缩减规则。

好的,你把它当作数组来使用,但问题是 OpenMP 不知道它的长度是多少。

请使用以下语法:

#pragma omp reduction(+:avgs[0:DIM_RGB])
英文:

Your variable avgs is a pointer. You can not reduce on pointers. OpenMP is telling you that if you want to reduce pointers, you need to define a reduction for them.

Ok, you're using it as an array but then the problem is OpenMP doesn't know how long it is.

Use the following syntax:

#pragma omp reduction(+:avgs[0:DIM_RGB])

huangapple
  • 本文由 发表于 2023年6月5日 06:01:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76402569.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定