Bucket sort parallel algorithm using C++ OpenMPI

Bucket Sort is quite an easy to implement algorithm when talking about parallel algorithms. Its main logic is to spare different parts of array into different buckets, then sort them at the same time with another algorithm and put it back together in one big result array.

I took some images from Wikipedia for better understanding:

We put those numbers into buckets based on interval which is get looping from the min value until the end of all numbers which is the max number in the array. In this case you might see that all the negative numbers will be in the first bucket which might be in some case a disadvantage of this particular implementation of this algorithm.

The numbers are at first calculated by the same logic and the main process sends information of how many numbers each bucket will need to parse and get. By doing the same routine again, the main process sends out all the numbers to a particular bucket and buckets are receiving information until it gets all the numbers that should be sent to it.

After putting the numbers into the specific buckets, you just sort them out using any sorting algorithm you want. The native sort() function of C++ is used in this example.

I’ve even create a simple “random” numbers generator which you can use to create some test info. The code is below:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.