A Parallel Statistical Random Number Generator for OpenMP

Version: 1.0
Download

Release Date: 6/7/2013

Version 1.0 of OMPRNG has been significantly rewritten to make use of C++ classes and objects. Although the syntax is now slightly different, this change has made using OMPRNG even easier than version 0.2. In addition, maintenance and updates will be easier with the new architecture. Enjoy!

OMPRNG is a parallel random number generator for C++. It uses

- OpenMP; this is a program for parallelization
- RngStreams; RngStreams creates several "independent" RNG streams

While there are other parallel RNG's such as SPRNG and PURG, these are much more difficult to implement then OMPRNG. In addition, I have found that Hyperthreading (found on Intel's newest chips) can cause problems with parallel RNG's (I have noted problems w/ both PURG and RNGStreams) if not carefully implemented. OMPRNG properly handles Hyperthreading.

Random numbers can be generated from the following statistical distributions

- uniform distribution
- normal distribution
- exponential distribution
- gamma distribution
- chi-square distribution
- beta distribution
- multivariate normal distribution (ALPHA software)

See the omprng.h file for details.

Three files are provided to demonstrate the usage of OMPRNG:

- The file pi.cpp computes a Monte Carlo estimate of pi using parallel processing. Note how simple calls to OMPRNG are: "myRng.runif()". The parallel RNG details are handled in the background (see omprng.h).
- The file test.cpp shows how calls are made to the various statistical RNG's in OMPRNG.
- The file test-mvn.cpp shows how calls are made to the multivariate normal distribution RNG in OMPRNG (a bivariate normal distribution is demonstrated; OMPRNG does allow for dimensions higher than 2).

To compile the program on Linux, you need

- OpenMP (RngStreams is included in the attached file)
- g++ (the gcc C++ compiler)
- make

The matrix software package "Eigen" (http://eigen.tuxfamily.org) is also included in the OMPRNG package; it is used for the multivariate normal distribution.

Users have reported that OMPRNG can be compilied and run on OS-X as well.

Download omprng.zip to a local directory. To compile, do the following:

- $ unzip omprng.zip
- $ cd omprng
- $ make

Three executable programs are provided: "pi", "test", and "test-mvn". To run, type

- $ ./pi
- $ ./test
- $ ./test-mvn

The OMPRNG code is contained in the "omprng.h" file. The .cpp files demonstrate how to use OMPRNG. In the pi.cpp file, for example, the parallel RNG is initialized by a simple command

- omprng myRng;

After the myRng object is created, you simply call it via the command

- myRng.runif();

for a uniform random number in the interval (0,1).

The test.cpp file demonstrates how to generate random numbers from other distributions. For example, random numbers from a N(100,sd=16) distribution can be generated by

- myRng.rnorm(100,16);

Calling "myRng" inside an OpenMP parallel region causes OMPRNG to generate random numbers on each thread (i.e. OMPRNG operates in a parallel manner; specifically, OMPRNG instructs RNGStreams to initialize an RNG stream for each thread). Calling "myRng" inside a serial region causes OMPRNG to generate a random number on one processor (i.e. it behaves in a serial manner). Simple.

MC estimates of pi with 100,000,000 updates:

SERIAL: Intel i5 CPU; 1 thread (no hyperthreading) $ time ./pi Monte Carlo estimate of pi based on 100000000 iterations is 3.14145 real 0m15.257s user 0m15.217s sys 0m0.008s PARALLEL: Intel i5 CPU; 2 cores, 4 threads (hyperthreading) $ time ./pi Monte Carlo estimate of pi based on 100000000 iterations is 3.14148 real 0m7.038s user 0m24.470s sys 0m0.008s

There are no restrictions on the use of OMPRNG except that I take no liability for any problems that may arise from its use.

OMPRNG is free software. However, if you use it in a project or publication, please provide proper credit.

Matthew Bognar

Department of Statistics and Actuarial Science

University of Iowa

http://www.stat.uiowa.edu/~mbognar/omprng

matthew-bognar@uiowa.edu