0

Which would be the best method for uniformly distributing values into buckets. The values are generated using gaussian distribution, hence most values are near the median.

I am implementing bucket sort in CUDA. Since most of the values are generated near median they are inserted into 4-5 buckets. I can make large number of buckets and would like to evenly distribute the values in all/most buckets instead of just 3-4 buckets.

  • It sounds like histogramming. [Thrust](https://github.com/thrust/thrust/blob/master/examples/histogram.cu) and [CUB](http://nvlabs.github.io/cub/structcub_1_1_device_histogram.html) both provide histogramming possibilities. I wouldn't recommend writing your own code to do it. – Robert Crovella Nov 11 '14 at 04:38
  • The above is sound advice. Have a look at CUB's histogramming options here: http://nvlabs.github.io/cub/structcub_1_1_device_histogram.html – ebarr Nov 11 '14 at 05:20
  • Thanks! Histogramming and histogram equalization looked the obvious choice. – Ameya Patil Nov 11 '14 at 14:06

1 Answers1

2

It seems you're looking for an histogram.

If you are looking for performance, go into the CUB or Thrust libraries as the two comments point out, otherwise you'll end up expending a lot of time and still not achieving those performance levels.

If you are decided to implement the histogram I'll recommend you to start with the simplest implementation; a two-step approach. In the first step you calculate the number of elements which falls into each bucket, so you can create the container structure with the right array sizes. The second step simply copy the elements to the corresponding array of the structure.

Since here, you can evolve to more complex versions, using for example a prefix sum to calculate the initial positions of the buckets on a large array.

The application is bounded by memory traffic (you have not arithmetic workload at all), so try to improve the locality and the access patterns as much as you can.

Of course, check out the open source code to get some ideas.

srodrb
  • 1,194
  • 11
  • 23