Reduction with OpenMP

前端 未结 2 382
醉话见心
醉话见心 2020-12-10 02:40

I am trying to compute mean of a 2d matrix using openmp. This 2d matrix is actually an image.

I am doing the thread-wise division of data. For example, if I have

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 03:30

    In your case, the sum = sum + val could interpreted as val[i] = val[i-1] + val[i] in 1-d array (or val[rows][cols] = val[rows][cols-1] + val[rows][cols] in 2-d array) which is a prefix sum calculation.

    Reduction is one of solution for prefix sum, you can use reduction to any commutative-associative operators like '+', '-', '*', '/'.

提交回复
热议问题