I do not understand the communication patterns

Hi all,

First message on this forum, I hope this is the correct sub-forum.
I am learning cuda on video using “introduction to parallel programming”.
I do not understand the lesson on the communication patterns… For example, what is a Scatter? According to the picture found in the video, I thought that a scatter was a “one to many”. But the quiz explain that sorting the basketball players is a scatter because “Each thread is computing where to write its result”. Which definition is the correct one?


Scatter means writing to arbitrary locations in memory. The opposite is Gather that is reading from arbitrary locations in memory.

In both gather and scatter, you are using lookup of another values as an index. In gather the indirection lookup is on the right hand side whereas for scatter it is on the left hand side. So for gather, the code boils down to something like this.

for (i=0; i<N; ++i)
  x[i] = y[idx[i]];

whereas for scatter, it is like this

for (i=0; i<N; ++i)
  y[idx[i]] = x[i];

Reference: https://en.wikipedia.org/wiki/Gather-scatter_(vector_addressing)

Another way of stating what is described by Mobeen’s illustrative code snippets:

Gather: transform from non-contiguous to contiguous storage
Scatter: transform from contiguous to non-contiguous storage