IBM Books

Parallel Engineering and Scientific Subroutine Library for AIX Version 2 Release 3: Guide and Reference

PDURNG--Uniform Random Number Generator

This subroutine generates a global vector x of n 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 is the number of random numbers to be generated.

If n is 0, no computation is performed, and the initial seed is unchanged.

The global output vector x is distributed across the np processes, using block-cyclic distribution with a block size nb. (The processor grid can be one- or two-dimensions. For two dimensions, processes are selected in row-major order.) The length n of vector x must be a multiple of (np)(nb).

Table 116. Data Types

x, seed Subroutine
Long-precision real PDURNG

Syntax

Fortran CALL PDURNG (seed, n, nb, x, iopt, icontxt)
C and C++ pdurng (seed, n, nb, x, iopt, icontxt);

On Entry

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

Scope: global

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

n
is the global number of random numbers to be generated.

Scope: global

Specified as: a fullword integer; n >= 0 and n must be divisible by (nb)(np).

nb
is the block size for vector x, used in the block-cyclic distribution.

Scope: global

Specified as: a fullword integer; nb > 0.

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).

Scope: global

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

icontxt
is the BLACS context parameter.

Scope: global

Specified as: the fullword integer that was returned by a prior call to BLACS_GRIDINIT or BLACS_GRIDMAP.

On Return

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

Scope: global

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

x
is the local vector x of size n/np, 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).

Scope: local

Returned as: a one-dimensional array of (at least) length n/np, with a block size of nb, containing numbers of the data type indicated in Table 116.

Notes and Coding Rules
  1. In your C program, argument seed must be passed by reference.
  2. The suggested block size is (data cache size)/2, where, the data cache size can be obtained by utilizing the following C language code fragment:
    #include <sys/systemcfg.h>
    int ics;
         .
         .
         .
    ics=_system_configuration.dcache_size/8;
    
  3. There is no performance impact for nb = 1.
  4. If you want n/np random numbers generated on each process, just set the block size to nb = n/np.
  5. To generate more than (231-1) random numbers, you should make multiple calls to PDURNG.
  6. The local vector x of length n/np can have sequential correlations. For details, see references [42], [47], [48], [49], and [50].

Error Conditions

Computational Errors

None

Input-Argument and Miscellaneous Errors

Stage 1 

  1. icontxt is invalid

Stage 2 

  1. PDURNG was called from outside the process grid.

Stage 3 

  1. seed < 1.0 or seed >= 2.048
  2. n < 0
  3. n is not divisible by (nb)(np)
  4. nb <= 0
  5. iopt <> 0 or 1

Example

This example generates 30 random numbers in global vector x with a block size of 3, using block-cyclic distribution over a 5 × 1 process grid.

Call Statements and Input
ORDER = 'R'
NPROW = 5
NPCOL = 1
CALL BLACS_GET(0, 0, ICONTXT)
CALL BLACS_GRIDINIT(ICONTXT, ORDER, NPROW, NPCOL)
CALL BLACS_GRIDINFO(ICONTXT, NPROW, NPCOL, MYROW, MYCOL)
 
             SEED   N     NB  X   IOPT  ICONTXT
              |     |     |   |    |        |
CALL PDURNG( SEED , 30 ,  3 , X ,  0 ,  ICONTXT)
 
SEED    = 31415926535897.0
Note:
icontxt is the output of the BLACS_GRIDINIT call.

Output

SEED = (a30s0) mod (m) = 6316434292705.0

Global vector x with block size 3:

B,D             0
     *                      *
     | 0.683821516135299845 |
 0   | 0.058874407800946215 |
     | 0.391855250856924187 |
     | -------------------- |
     | 0.755994653022330709 |
 1   | 0.557764301423606668 |
     | 0.001333801764989317 |
     | -------------------- |
     | 0.056855932753212101 |
 2   | 0.331063036202269956 |
     | 0.347339794409027292 |
     | -------------------- |
     | 0.649429020370863697 |
 3   | 0.386144876217390021 |
     | 0.457224855098420591 |
     | -------------------- |
     | 0.892518134165118937 |
 4   | 0.074548748224632532 |
     | 0.912379366805073033 |
     | -------------------- |
     | 0.112809499110515077 |
 5   | 0.857547605095465570 |
     | 0.756480901897081282 |
     | -------------------- |
     | 0.046993364463578046 |
 6   | 0.889457684002341153 |
     | 0.167775766106718294 |
     | -------------------- |
     | 0.504952722600595649 |
 7   | 0.999725924546471134 |
     | 0.696269487398215148 |
     | -------------------- |
     | 0.671896598019703362 |
 8   | 0.271472156040264423 |
     | 0.566418406688985243 |
     | -------------------- |
     | 0.464684865759100063 |
 9   | 0.982442539763031419 |
     | 0.022440482512937620 |
     *                      *

The following is the 5 × 1 process grid:

B,D  |    0    
-----| -------  
0    |   P00
5    |   
-----| -------  
1    |   P10
6    |   
-----| -------  
2    |   P20
7    |   
-----| -------  
3    |   P30
8    |   
-----| -------  
4    |   P40
9    |   

Local arrays for x:

p,q  |          0
-----|----------------------
     | 0.683821516135299845
     | 0.058874407800946215
     | 0.391855250856924187
 0   | 0.112809499110515077
     | 0.857547605095465570
     | 0.756480901897081282
-----|----------------------
     | 0.755994653022330709
     | 0.557764301423606668
     | 0.001333801764989317
 1   | 0.046993364463578046
     | 0.889457684002341153
     | 0.167775766106718294
-----|----------------------
     | 0.056855932753212101
     | 0.331063036202269956
     | 0.347339794409027292
 2   | 0.504952722600595649
     | 0.999725924546471134
     | 0.696269487398215148
-----|----------------------
     | 0.649429020370863697
     | 0.386144876217390021
     | 0.457224855098420591
 3   | 0.671896598019703362
     | 0.271472156040264423
     | 0.566418406688985243
-----|----------------------
     | 0.892518134165118937
     | 0.074548748224632532
     | 0.912379366805073033
 4   | 0.464684865759100063
     | 0.982442539763031419
     | 0.022440482512937620


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