
上QQ阅读APP看书,第一时间看更新
Gather
In this pattern, each thread or task has multiple inputs, and it produces a single output to be written at a single location in memory. Suppose you want to write a program that finds a moving average of three numbers; this is an example of a gather operation. It takes three inputs from memory and writes single output to memory. So, there is data reuse on the input side. It is basically a many-to-one operation. The code for gather pattern will look as follows:
out[i] = (in [i-1] + in[i] + in[i+1])/3