URNG: A portable optimization technique for software applications requiring pseudo-random numbers

https://doi.org/10.1016/j.simpat.2003.08.007Get rights and content

Abstract

Research software involving stochastic behaviour often requires millions of random numbers. In addition to the quality of the pseudo-random number generator (PRNG), the speed of the algorithm and the ease of its implementation are common practical aspects. In this work we will discuss how to optimize the access speed to random numbers independently from the generation algorithm. We propose an additional implementation technique in order to speed up any kind of PRNG taking into account the capacities of current computers and microcomputers. The speed of our solution stems from the classical unrolling optimization technique, it is named the URNG technique (unrolled random number generator). Random numbers are first generated in source code, then precompiled and stored inside the RAM of inexpensive computers at the executable loading time. With this technique random numbers need to be computed only once. The URNG technique is compliant with parallel computing. Limits and effects on speed and sensitivity are explored over four computer generations with a simple Monte Carlo simulation. Every research field using stochastic computation can be concerned by this software optimization technique which is currently limited to applications requiring not more than a few hundred millions of pseudo-random numbers.

Introduction

In most research fields various problems remain very tedious if not intractable if they are tackled with deterministic algorithms and this is the main reason why scientists often develop stochastic algorithms. For small problem size, this kind of randomized approach has proved to be less efficient than its deterministic counterpart. However, it is now well known that stochastic algorithms can efficiently tackle various large-scale problems and we have gained this certitude also from our experience [2], [6], [15]. Such stochastic algorithms need a source of randomness. Pseudo-random number generators (PRNGs) are frequently preferred to physical devices mainly because they authorize results reproducibility, they are often portable and facilitate program debugging. For computer scientists specialized in stochastic computations and or simulations, it is well known that there are no safe and universal random number generators [14], [19]. Since generators of any kind have their side effects, it is at least strongly recommended to check the results with different kinds of generators. In addition to the study of their theoretical and empirical qualities [1], [4], [18], [21], [23], [26], the efficiency and optimization of random numbers has often been considered by specialists in their sequential [10], [17]] and parallel versions [3], [5], [24], [28]. Despite a fair amount of sound theoretical work on pseudo-random number generation algorithms, the theoretical gain is often eradicated by poor computer implementations. Indeed, the concern for speed often results in shortcuts which most of the time rely on approximations. Such approximations can be disastrous in random number generation and some are very machine-specific [11]. In this paper we will concentrate on the coding considerations for a very portable speedup technique: i.e. applicable to any programming language and to any PRNG.

Section snippets

The unrolling technique applied to pseudo-random numbers generation

In every stochastic software and particularly if we deal with stochastic simulation, the number of calls to the pseudo-random generator is responsible for getting a great account of CPU resources [16]. In this paragraph we will describe the URNG implementation technique (unrolling random number generators) to optimize the access to random numbers of any generator. This method will be described hereafter as the “unrolling” method. It consists in generating automatically a source file containing

The need to apply this technique to different PRNGs

Knowing that there is no universal generator, it is strongly recommended to test a stochastic application with widely different PRNGs. They can be classified in four major classes: linear generators, lagged generators, inversive generators and mixed generators. It is interesting to maintain at least one large sequence file for each major type of generator. For instance, inversive generators are very interesting for verifying simulation results obtained with an linear congruential generator

Benchmark description

We have built a benchmark with several PRNGs on a simple Monte Carlo simulation (PI computation). The main goal of these tests was not to compute an approximated PI value, but rather to measure the average speed of the generators. We decided to compare the unrolling technique to two kinds of generators described in [22]: an ultra fast implementation of the “quick and dirty” generator (coded with a macroinstruction) and the shuffled version of ran2 in Numerical Recipies. After some preliminary

Conclusion

We have presented an implementation technique able to speed up software that makes an intensive use of PRNGs. The essence of speed is based on the unrolling optimization technique, and thus we named it the URNG technique (unrolled random number generator). With this technique, we obtain the same speedup ratio independently from the PRNG. Whatever the generation algorithm, arrays are generated and compiled to be present in memory after the loading of the executable program. Instead of computing

Acknowledgements

I would like to thank my research assistant Alexandre Roche, for his technical report, the implementation and testing on various computers of this speedup technique. In addition, the author would also like to thank the reviewers for their very informative contributions.

References (28)

  • P.D. Coddington, Random number generators for parallel computers, Natl. HPCC Software Exchange Rev. 1.1,...
  • J. Eichenauer et al.

    A non linear congruential pseudo random number generator

    Statistical Papers

    (1986)
  • J. Eichenauer-Hermann

    Explicit inversive congruential pseudorandom numbers: the compound approach

    Computing

    (1993)
  • J. Eichenauer-Hermann

    Statistical independence of a new class of inversive congruential pseudorandom numbers

    Mathematics of Computation

    (1993)
  • Cited by (6)

    View full text