Guide and Reference


Random Number Generation (HPF)

This chapter describes the random number generation subroutine that can be called from an HPF program.


Overview of the Random Number Generation Subroutine

The random number generation subroutine generates uniformly distributed random numbers.

Table 142. List of Random Number Generation Subroutine (HPF)
Descriptive Name Long-Precision Subroutine Page
Uniform Random Number Generator URNG URNG--Uniform Random Number Generator

Random Number Generation Subroutine

This section contains the random number generation subroutine.

URNG--Uniform Random Number Generator

This subroutine generates a vector x of uniform pseudo-random numbers in the ranges (0,1) or (-1,1), depending on the iopt argument. The random numbers are generated using the multiplicative congruential method with a user-specified seed, as follows:

si = (a(si-1)) mod (m) = (ais0) mod (m)
xi = si/m    if iopt = 0
xi = (2si/m)-1    if iopt = 1
   for i = 1, 2, ..., n

where:

s0 is the initial seed provided by the caller.
si for i = 1, n is a random sequence.
xi for i = 1, n are the random numbers.
a = 44485709377909.0
m = 2.048
n = size(x) = number of random numbers to be generated.

If the assumed-shape array has a size of zero, no computation is performed, the subroutine returns, and the initial seed is unchanged.

The process rank must be one for the array data in this subroutine; that is, given np processes, you must use a 1 × np or np × 1 process grid. In addition, the array data must be evenly distributed across all processes, using block distribution.
Note: This differs from the message-passing version of this subroutine, PDURNG, which supports block-cyclic data distribution.

See references [8], [41], [42], [47], [48], [49], and [50].

Table 143. Data Types
x, seed Subroutine
Long-precision real URNG

Syntax

HPF CALL URNG (seed, x) CALL URNG (seed, x, iopt)

On Entry

seed

is the initial value s0 used to generate the random numbers.

Type: required

Specified as: a number of the data type indicated in Table 143. You should specify seed to be an odd, whole number; otherwise, this subroutine sets it to an odd, whole number and continues with the computation. The value of seed must be 1.0 <= seed < 2.048.

x

See 'On Return'.

iopt

indicates the range of uniform random numbers to generate, where:

If iopt = 0, the range is (0,1).

If iopt = 1, the range is (-1,1).

Type: optional

Default: iopt = 0

Specified as: a fullword integer; iopt = 0 or 1.

On Return

seed

is the new seed that is to be used to generate additional random numbers in subsequent invocations of this subroutine, having a value of seed =  (ans0) mod (m).

Type: required

Returned as: a number of the data type indicated in Table 143. It is an odd, whole number, where 1.0 <= seed < 2.048.

x

is the vector x, containing the uniform pseudo-random numbers, where:

If iopt = 0, they are in the range (0,1).

If iopt = 1, they are in the range (-1,1).

Type: required

Returned as: an assumed-shape array with shape (:), containing numbers of the data type indicated in Table 143, where size(x)mod(np) = 0.

Notes and Coding Rules

  1. To generate more than (231-1) random numbers, you should make multiple calls to this subroutine.

  2. For details on how to set up and code your HPF program using Parallel ESSL, see "Coding Your HPF Program"

  3. Block data distribution is required for your array data, where the array data is evenly distributed across all processes. Because data directives are included in the interface module PESSL_HPF, you can specify any data distribution for your vector, and the XL HPF compiler will, if necessary, redistribute the data prior to calling this subroutine. For how to code your HPF directives, see "Distributing Data in an HPF Program".

Error Conditions

HPF-specific errors are listed below. Resource and input-argument errors listed in "Error Conditions" also apply to this subroutine.

Input-Argument Errors

Stage 1
  1. The rank of the ultimate align target is greater than 1 for x.
  2. The process rank is not 1 for x.

Stage 2

The vector for x is replicated.

Stage 3

The size of the assumed-shape array for x is invalid--that is, it is not a multiple of the product of the blocksize and the number of processes.

Example

This example generates 30 random numbers in vector x. The array data is block distributed, evenly, over 5 processes, unlike the array data in "Example" which is block-cyclically distributed.

!HPF$ PROCESSORS PROC(5)
!HPF$ DISTRIBUTE (BLOCK) ONTO PROC :: X
 
CALL URNG( SEED , X )
-or-
CALL URNG( SEED , X , IOPT=0 )

Input

SEED = 31415926535897.0

Output

SEED =  (a30s0) mod (m)  = 6316434292705.0

Vector x:

 *                      *
 | 0.683821516135299845 |
 | 0.058874407800946215 |
 | 0.391855250856924187 |
 | 0.755994653022330709 |
 | 0.557764301423606668 |
 | 0.001333801764989317 |
 | 0.056855932753212101 |
 | 0.331063036202269956 |
 | 0.347339794409027292 |
 | 0.649429020370863697 |
 | 0.386144876217390021 |
 | 0.457224855098420591 |
 | 0.892518134165118937 |
 | 0.074548748224632532 |
 | 0.912379366805073033 |
 | 0.112809499110515077 |
 | 0.857547605095465570 |
 | 0.756480901897081282 |
 | 0.046993364463578046 |
 | 0.889457684002341153 |
 | 0.167775766106718294 |
 | 0.504952722600595649 |
 | 0.999725924546471134 |
 | 0.696269487398215148 |
 | 0.671896598019703362 |
 | 0.271472156040264423 |
 | 0.566418406688985243 |
 | 0.464684865759100063 |
 | 0.982442539763031419 |
 | 0.022440482512937620 |
 *                      *


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]