C H A P T E R  15

Parallel Random Number Generation Routines

Sun S3L offers two alternative methods for generating pseudo-random numbers for parallel arrays, Lagged-Fibonacci random number generator (LFG) and Linear Congruential random number generator (LCG). The routines associated with these two methods are discussed in the following sections:


Initialize Lagged-Fibonacci State Table

S3L_setup_rand_fib allocates a set of LFG state tables and initializes them with the fixed parameters: l = 17, k = 5, m = 32, where:

An LFG state table operates as a circular buffer, with the table lag and short lag values pointing into different locations in the table. As the two pointers step through the state table, a sequence of pseudo-random numbers is created. At each step in the cycle, the two values pointed at by table lag and short lag are added together, with that sum replacing the value created by the previous step.

The size of each state table is l x m (the product of the table lag and width parameters). Since S3L_setup_rand_fib uses 17 and 32 for these parameters, each state table will occupy 544 bits of memory.

The table lag and short lag values have been selected to provide optimal balance between the length of the random number generation period and the amount of memory used. A random number generator's period is the number of new random values that it generates before returning to the start of the sequence. Maximizing the period ensures that the random numbers generated for each node are from a different period of the LFG.

A Linear Multiplicative Generator (LMG) is used to initialize the noncritical elements of the state table. The LMG itself is initialized by a seed value that is entered as an argument to S3L_setup_rand_fib.

S3L_setup_rand_fib has the following argument syntax:

S3L_setup_rand_fib(setup_id, seed, ier)

setup_id is a scalar integer returned by S3L_setup_rand_fib. It can be used by subsequent calls to S3L_rand_fib to access the state tables.

seed is an integer value that is used to initialize the Linear Multiplicative Generator which, in turn, initializes the LFG state tables.

If the call is made from a Fortran program, error status will be in ier.

For detailed descriptions of the Fortran and C bindings for the LFG setup routine, see the S3L_setup_rand_fib(3) man page or the corresponding description in the Sun S3L Software Reference Manual.

Examples showing S3L_setup_rand_fib in use can be found in:

/opt/SUNWhpc/examples/s3l/rand_fib/rand_fib.c
/opt/SUNWhpc/examples/s3l/rand_fib-f/rand_fib.f


Lagged-Fibonacci Random Number Generator

S3L_rand_fib writes a pseudo-random number into each element of a parallel array, a, using a Lagged-Fibonacci random number generator (LFG). The random numbers are produced by the following iterative equation:

x[n] = (x[n-e] + x[n-k]) % 2m

The result of S3L_rand_fib depends on how the parallel array a is distributed.

The following summarizes the different value ranges that are used for the different supported data types:

  • When the parallel array is of type integer, its elements are filled with nonnegative integers in the range 0 . . . 231 -1.
  • When the parallel array is single- or double-precision real, its elements are filled with random nonnegative numbers in the range 0 . . . 1.
  • For complex arrays, the real and imaginary parts are initialized to random real numbers.

S3L_rand_fib has the following argument syntax:

S3L__rand_fib(a, setup_id, ier)

a is a Sun S3L array handle that describes the parallel array to be initialized by the LFG.

setup_id is an integer value that is used to access the state table associated with the array a.

If the call is made from a Fortran program, error status will be in ier.

For detailed descriptions of the Fortran and C bindings for the LFG routine, see the S3L_rand_fib(3) man page or the corresponding description in the Sun S3L Software Reference Manual.

Examples showing S3L_rand_fib in use can be found in:

/opt/SUNWhpc/examples/s3l/rand_fib/rand_fib.c
/opt/SUNWhpc/examples/s3l/rand_fib-f/rand_fib.f


Linear Congruential Random Number Generator

S3L_rand_lcg initializes a parallel array a, using a Linear Congruential random number generator (LCG). It produces random numbers that are independent of the distribution of the parallel array.

The random numbers are initialized by an internal iterative equation of the type:

x[n] = (a*x[n-1] + c) % 2m

The result of S3L_rand_lcg does not depend on how the parallel array a is distributed.

The following summarizes the different value ranges that are used for the different supported data types:

  • When the parallel array is of type integer, its elements are filled with nonnegative integers in the range 0 . . . 231 -1.
  • When the parallel array is single- or double-precision real, its elements are filled with random nonnegative numbers in the range 0 . . . 1.
  • For complex arrays, the real and imaginary parts are initialized to random real numbers.

S3L_rand_lcg has the following argument syntax:

S3L__rand_lcg(a, iseed, ier)

a is a Sun S3L array handle that describes the parallel array to be initialized by the LCG.

iseed is an integer value. If positive, it is used as the initial seed for the LCG. If zero or negative, the LCG produces a sequence of random numbers that is a continuation of a sequence generated by a prior S3L_rand_lcg call.

If the call is made from a Fortran program, error status will be in ier.

For detailed descriptions of the Fortran and C bindings for the LCG routine, see the S3L_rand_lcg(3) man page or the corresponding description in the Sun S3L Software Reference Manual.

Examples showing S3L_rand_lcg in use can be found in:

/opt/SUNWhpc/examples/s3l/rand_lcg/rand_lcg.c
/opt/SUNWhpc/examples/s3l/rand_lcg-f/rand_lcg.f


Deallocate LFG Setup

S3L_free_rand_fib frees memory allocated to the state table of a particular random number generator.

S3L_free_rand_fib has the following argument syntax:

S3L_free_rand_fib(setup_id, ier)

setup_id is an integer value associated with the state tables that are to be deallocated.

For detailed descriptions of the Fortran and C bindings for the LFG deallocation routine, see the S3L_free_rand_fib(3) man page or the corresponding description in the Sun S3L Software Reference Manual.

Examples showing S3L_free_rand_fib in use can be found in:

/opt/SUNWhpc/examples/s3l/rand_fib/rand_fib.c
/opt/SUNWhpc/examples/s3l/rand_fib-f/rand_fib.f