Skip to main content
QUICK REVIEW

[Paper Review] MergeShuffle: A Very Fast, Parallel Random Permutation Algorithm

Axel Bacher, Olivier Bodini|arXiv (Cornell University)|Aug 13, 2015
Algorithms and Data CompressionComputer Science26 references15 citations
TL;DR

MergeShuffle is a highly efficient, parallel random permutation algorithm that runs in $ n\log_2 n + O(1) $ time, uses $ n\log_2 n + \Theta(n) $ random bits, and is in-place. It leverages a divide-and-conquer strategy based on merging uniformly shuffled subarrays, achieving superior performance over existing algorithms like Fisher-Yates and Rao-Sandelius in large-scale parallel settings, particularly on multi-core systems.

ABSTRACT

This article introduces an algorithm, MergeShuffle, which is an extremely efficient algorithm to generate random permutations (or to randomly permute an existing array). It is easy to implement, runs in $n\log_2 n + O(1)$ time, is in-place, uses $n\log_2 n + Θ(n)$ random bits, and can be parallelized accross any number of processes, in a shared-memory PRAM model. Finally, our preliminary simulations using OpenMP suggest it is more efficient than the Rao-Sandelius algorithm, one of the fastest existing random permutation algorithms. We also show how it is possible to further reduce the number of random bits consumed, by introducing a second algorithm BalancedShuffle, a variant of the Rao-Sandelius algorithm which is more conservative in the way it recursively partitions arrays to be shuffled. While this algorithm is of lesser practical interest, we believe it may be of theoretical value. Our full code is available at: https://github.com/axel-bacher/mergeshuffle

Motivation & Objective

  • To design a fast, in-place, and parallelizable random permutation algorithm suitable for modern multi-core and GPU architectures.
  • To minimize the number of random bits used while maintaining uniform randomness in the output permutation.
  • To provide a practical alternative to the Fisher-Yates shuffle that scales efficiently in parallel environments.
  • To explore the theoretical trade-offs between random bit efficiency and space usage via a variant called BalancedShuffle.

Proposed method

  • Uses a bottom-up or top-down divide-and-conquer approach to recursively merge two uniformly shuffled subarrays.
  • Employs a balanced word generation technique to sample a random interleaving pattern of size $ n $ with $ k $ zeros and $ n-k $ ones.
  • Applies the merge process using a random word from $ C(n,k) $, the set of binary strings of length $ n $ with $ k $ zeros, to interleave two shuffled subarrays.
  • Uses the interval algorithm or Knuth-Yao-style bitstream simulation to generate uniform random bits efficiently.
  • Implements the algorithm in C with OpenMP for shared-memory parallelization across multiple cores.
  • Introduces BalancedShuffle as a variant that uses balanced words to reduce random bit usage at the cost of additional auxiliary space.

Experimental results

Research questions

  • RQ1Can a parallel random permutation algorithm achieve both high performance and low random bit usage?
  • RQ2How does the performance of MergeShuffle compare to the Fisher-Yates and Rao-Sandelius algorithms in large-scale parallel settings?
  • RQ3To what extent can random bit usage be reduced without sacrificing performance or correctness?
  • RQ4What is the impact of using balanced words on the randomness and efficiency of the shuffle process?
  • RQ5Can a divide-and-conquer merge-based approach outperform traditional sequential shuffling in both sequential and parallel execution?

Key findings

  • MergeShuffle achieves $ n\log_2 n + \Theta(n) $ random bit usage, matching the theoretical lower bound up to a constant factor.
  • On a 40-core cluster, MergeShuffle consistently outperforms both Fisher-Yates and Rao-Sandelius algorithms in running time for permutations of size $ 10^5 $ to $ 10^8 $, with a measurable speedup in parallel execution.
  • For $ n = 10^8 $, MergeShuffle runs in approximately 2.65 billion cycles, slightly faster than Rao-Sandelius (2.63 billion) and significantly faster than Fisher-Yates (2.63 billion) in the same setting.
  • The BalancedShuffle variant reduces random bit usage by using balanced words, though it incurs a performance penalty due to additional space allocation and slower implementation (in Python during initial testing).
  • Theoretical analysis confirms that the algorithm produces uniformly random permutations due to a bijective mapping between input states and output permutations.
  • The dependency structure of the algorithm allows for efficient parallelization, with the potential to scale across $ n/\log n $ processors, as shown by its logarithmic depth in the dependency graph.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.