Skip to main content
QUICK REVIEW

[论文解读] MergeShuffle: A Very Fast, Parallel Random Permutation Algorithm

Axel Bacher, Olivier Bodini|arXiv (Cornell University)|Aug 13, 2015
Algorithms and Data Compression参考文献 26被引用 15
一句话总结

MergeShuffle 是一种高效、并行的随机排列算法,时间复杂度为 $ nackepsilon_2 n + O(1) $,使用 $ nackepsilon_2 n + \Theta(n) $ 个随机位,且为原地算法。它基于合并均匀洗牌的子数组的分治策略,相较于 Fisher-Yates 和 Rao-Sandelius 等现有算法,在大规模并行环境(尤其是多核系统)中表现出更优的性能。

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

研究动机与目标

  • 设计一种适用于现代多核与 GPU 架构的快速、原地且可并行化的随机排列算法。
  • 在保持输出排列均匀随机性的前提下,最小化所用随机位的数量。
  • 为 Fisher-Yates 洗牌提供一种实用的替代方案,使其在并行环境中能够高效扩展。
  • 通过一种称为 BalancedShuffle 的变体,探索随机位效率与空间使用之间的理论权衡。

提出的方法

  • 采用自底向上或自顶向下的分治方法,递归地合并两个均匀洗牌的子数组。
  • 使用平衡的字生成技术,以 $ k $ 个 0 和 $ n-k $ 个 1 的方式采样一个大小为 $ n $ 的随机交错模式。
  • 利用来自 $ C(n,k) $(即长度为 $ n $、含 $ k $ 个 0 的二进制字符串集合)的随机字,将两个已洗牌的子数组交错合并。
  • 使用区间算法或 Knuth-Yao 风格的位流模拟,高效生成均匀随机位。
  • 使用 C 语言实现算法,并通过 OpenMP 实现多核环境下的共享内存并行化。
  • 引入 BalancedShuffle 作为变体,通过使用平衡字减少随机位使用,但需额外的辅助空间。

实验结果

研究问题

  • RQ1并行随机排列算法是否能够同时实现高性能与低随机位使用?
  • RQ2在大规模并行环境中,MergeShuffle 与 Fisher-Yates 和 Rao-Sandelius 算法相比性能如何?
  • RQ3在不牺牲性能或正确性的情况下,随机位使用最多可减少多少?
  • RQ4使用平衡字对洗牌过程的随机性和效率有何影响?
  • RQ5基于分治合并的方法是否能在顺序和并行执行中均优于传统的顺序洗牌?

主要发现

  • MergeShuffle 实现了 $ n\backepsilon_2 n + \Theta(n) $ 的随机位使用,与理论下限仅相差一个常数因子。
  • 在 40 核集群上,对于大小为 $ 10^5 $ 到 $ 10^8 $ 的排列,MergeShuffle 的运行时间始终优于 Fisher-Yates 和 Rao-Sandelius 算法,并在并行执行中表现出可测量的加速效果。
  • 当 $ n = 10^8 $ 时,MergeShuffle 的运行时间约为 26.5 亿个周期,略快于 Rao-Sandelius(26.3 亿个周期),并显著快于 Fisher-Yates(26.3 亿个周期)。
  • BalancedShuffle 变体通过使用平衡字减少了随机位使用,但因额外的空间分配和实现较慢(初始测试使用 Python)而带来性能损失。
  • 理论分析证实,由于输入状态与输出排列之间存在双射映射,该算法能产生均匀随机的排列。
  • 该算法的依赖结构支持高效并行化,其依赖图具有对数深度,理论上可扩展至 $ n/\backepsilon n $ 个处理器。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。