This chapter describes the random number generation subroutine that can be called from an HPF program.
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 |
This section contains the random number generation subroutine.
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:
where:
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].
x, seed | Subroutine |
Long-precision real | URNG |
HPF | CALL URNG (seed, x) CALL URNG (seed, x, iopt) |
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.
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.
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.
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.
HPF-specific errors are listed below. Resource and input-argument errors listed in "Error Conditions" also apply to this subroutine.
The vector for x is replicated.
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.
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 )
SEED = 31415926535897.0
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 | * *