ZIGGURAT_OPEN_MP
Using the ZIGGURAT Library with OpenMP


ZIGGURAT_OPEN_MP is a FORTRAN90 library which explores how the ZIGGURAT library may be used, in conjunction with OpenMP, to compute random numbers efficiently and correctly.

The primary worry, when computing random numbers in OpenMP, occurs when the user calls a random number generator which may have some internal memory. In that case, the internal memory may become corrupted if multiple threads are invoking the code at the same time.

A safe way to compute random numbers is to ensure that the seed value, and any other data or tables needed by the computation, are stored externally, in the user program. That way, each thread can have a separate copy of the data, and multiple threads of random number calculations can be going along simultaneously without fear of overwriting or memory contention.

The program presented here is somewhat awkward, because it wishes to verify that OpenMP can compute exactly the same data as a sequential program. To do so, we need to create separate seeds for each threads, and ensure that the threads execute the loop iterations in some predictable sequence. When the sequential program goes through the same calculations, we again have to do some acrobatics to ensure that it is doing the same things that the parallel program did.

So some of the complications in this program are there to ensure that we can exhibit the same results sequentially and in parallel. Once you are convinced of that, and see how to go about this, your own program can be set up without some of the overhead and special instructions used in this demonstration.

On an Apple PowerPC G5 with two processors, the following results were observed:
ThreadsTest01Test02Test03Test04
10.592 s1.240 s1.579 s1.478 s
20.315 s0.638 s0.791 s0.796 s
40.303 s0.635 s0.826 s0.773 s

Usage:

In the BASH shell, the program could be run with 2 threads using the commands:

        export OMP_NUM_THREADS=2
        ./ziggurat_open_mp
      

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Related Data and Programs:

CVT is a FORTRAN90 library which computes elements of a Centroidal Voronoi Tessellation.

FAURE is a FORTRAN90 library which computes elements of a Faure quasirandom sequence.

FFT_OPEN_MP is a FORTRAN90 program which demonstrates the computation of a Fast Fourier Transform in parallel, using OpenMP.

GRID is a FORTRAN90 library which computes elements of a grid dataset.

HALTON is a FORTRAN90 library which computes elements of a Halton quasirandom sequence.

HAMMERSLEY is a FORTRAN90 library which computes elements of a Hammersley quasirandom sequence.

HEX_GRID is a FORTRAN90 library which computes elements of a hexagonal grid dataset.

HEX_GRID_ANGLE is a FORTRAN90 library which computes elements of an angled hexagonal grid dataset.

IHS is a FORTRAN90 library which computes elements of an improved distributed Latin hypercube dataset.

LATIN_CENTER is a FORTRAN90 library which computes elements of a Latin Hypercube dataset, choosing center points.

LATIN_EDGE is a FORTRAN90 library which computes elements of a Latin Hypercube dataset, choosing edge points.

LATIN_RANDOM is a FORTRAN90 library which computes elements of a Latin Hypercube dataset, choosing points at random.

LCVT is a FORTRAN90 library which computes a latinized Centroidal Voronoi Tessellation.

MD_OPEN_MP is a FORTRAN90 program which carries out a molecular dynamics simulation using OpenMP.

MXV_OPEN_MP is a FORTRAN90 program which compares the performance of plain vanilla Fortran and the FORTRAN90 intrinsic routine MATMUL, for the matrix multiplication problem y=A*x, with and without parallelization by OpenMP.

NIEDERREITER2 is a FORTRAN90 library which computes elements of a Niederreiter quasirandom sequence with base 2.

NORMAL is a FORTRAN90 library which computes elements of a sequence of pseudorandom normally distributed values.

OPEN_MP FORTRAN90 programs which illustrate the use of the OpenMP application program interface for carrying out parallel computations in a shared memory environment.

OPEN_MP_ITHACA FORTRAN90 programs which illustrate the use of OpenMP on the Virginia Tech ITHACA cluster.

QUAD_OPEN_MP is a FORTRAN90 program which approximates an integral using a quadrature rule, and carries out the computation in parallel using OpenMP.

RANDOM_MPI, a FORTRAN90 program which demonstrates one way to generate the same sequence of random numbers for both sequential execution and parallel execution under MPI.

RANDOM_OPEN_MP, FORTRAN90 programs which illustrate and explore issues involving the generation of random numbers in a parallel program using OpenMP.

RBOX is a C program which generates a set of points in a region, selected at random according to a given distribution.

SATISFIABILITY_OPEN_MP is a FORTRAN90 program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, using OpenMP for parallel execution.

SGEFA_OPEN_MP is a FORTRAN90 program which reimplements the SGEFA/SGESL linear algebra routines from LINPACK for use with OpenMP.

SOBOL is a FORTRAN90 library which computes elements of a Sobol quasirandom sequence.

UNIFORM is a FORTRAN90 library which computes elements of uniform pseudorandom sequence.

VAN_DER_CORPUT is a FORTRAN90 library which computes elements of a van der Corput quasirandom sequence.

ZIGGURAT is a FORTRAN90 program which generates points from a uniform, normal or exponential distribution, using the ziggurat method.

ZIGGURAT_OPEN_MP is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version.

Reference:

  1. George Marsaglia, Wai Wan Tsang,
    The Ziggurat Method for Generating Random Variables,
    Journal of Statistical Software,
    Volume 5, Number 8, October 2000, seven pages.

Source Code:

Examples and Tests:

ZIGGURAT_OPEN_MP_RUN runs ZIGGURAT_OPEN_MP interactively.

ZIGGURAT_OPEN_MP_BATCH runs ZIGGURAT_OPEN_MP through the batch system.

List of Routines:

You can go up one level to the FORTRAN90 source codes.


Last revised on 06 September 2009.