一种结合分段与位打包的缓存感知混合筛法用于快速生成素数
A Cache-Aware Hybrid Sieve Combining Segmentation and Bit-Packing for Fast Prime Generation
AI总结:
本文提出一种结合分段与位打包的缓存感知混合筛法,通过优化内存带宽和缓存局部性,显著减少内存使用和提升素数生成效率。
摘要:
素数生成是密码学、数论和随机算法中的基础任务。虽然经典的埃拉托色尼筛法在理论上简单高效,但其在现代中央处理器上的实际性能常受到内存访问效率的限制。本文介绍了一种缓存感知的混合筛法,整合了分段、位打包和缓存行对齐的块处理,以优化内存带宽和一级和二级缓存的局部性。所提出的方法通过只存储奇数并使用每个值一个位来减少内存使用。筛范围被划分为缓存大小的块以最小化缓存缺失,同时将上限平方根以内的素数在块间重用。实验结果表明,与经典筛法相比,内存使用减少了最多8倍,运行时间提高了最多2.4倍;与分段筛法相比,运行时间提高了1.7倍。基准测试至十的九次方表明,面向架构的算法设计可以带来显著的实际性能提升。
英文摘要:
Prime generation is a fundamental task in cryptography, number theory, and randomized algorithms. While the classical Sieve of Eratosthenes is simple and efficient in theory, its practical performance on modern central processing units is often limited by memory access inefficiencies. This paper introduces a cache-aware hybrid sieve that integrates segmentation, bit-packing, and cache-line-aligned block processing to optimize memory bandwidth and level one and level two cache locality. The proposed approach reduces memory usage by storing only odd numbers and using one bit per value. The sieve range is divided into cache-sized blocks to minimize cache misses, while primes up to the square root of the limit are reused across blocks. Experimental results demonstrate up to an eight times reduction in memory usage and runtime improvements of up to two point four times compared to the classical sieve and one point seven times compared to the segmented sieve. Benchmarks up to ten to the power of nine illustrate that architecture-aware algorithm design can yield substantial practical performance gains.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。