# NAG CL Interfaceg05ymc (quasi_​uniform)

Settings help

CL Name Style:

## 1Purpose

g05ymc generates a uniformly distributed low-discrepancy sequence as proposed by Sobol, Faure or Niederreiter. It must be preceded by a call to one of the initialization functions g05ylc or g05ync.

## 2Specification

 #include
 void g05ymc (Nag_OrderType order, Integer n, double quas[], Integer pdquas, Integer iref[], NagError *fail)
The function may be called by the names: g05ymc, nag_rand_quasi_uniform or nag_quasi_rand_uniform.

## 3Description

Low discrepancy (quasi-random) sequences are used in numerical integration, simulation and optimization. Like pseudorandom numbers they are uniformly distributed but they are not statistically independent, rather they are designed to give more even distribution in multidimensional space (uniformity). Therefore, they are often more efficient than pseudorandom numbers in multidimensional Monte Carlo methods.
g05ymc generates a set of points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ with high uniformity in the $S$-dimensional unit cube ${I}^{S}={\left[0,1\right]}^{S}$.
Let $G$ be a subset of ${I}^{S}$ and define the counting function ${S}_{N}\left(G\right)$ as the number of points ${x}^{i}\in G$. For each $x=\left({x}_{1},{x}_{2},\dots ,{x}_{S}\right)\in {I}^{S}$, let ${G}_{x}$ be the rectangular $S$-dimensional region
 $G x = [0, x 1 ) × [0, x 2 ) ×⋯× [0, x S )$
with volume ${x}_{1},{x}_{2},\dots ,{x}_{S}$. Then one measure of the uniformity of the points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ is the discrepancy:
 $DN* (x1,x2,…,xN) = sup x∈IS |SN(Gx)-Nx1,x2,…,xS| .$
which has the form
 $DN*(x1,x2,…,xN)≤CS(log⁡N)S+O((log⁡N)S-1) for all N≥2.$
The principal aim in the construction of low-discrepancy sequences is to find sequences of points in ${I}^{S}$ with a bound of this form where the constant ${C}_{S}$ is as small as possible.
The type of low-discrepancy sequence generated by g05ymc depends on the initialization function called and can include those proposed by Sobol, Faure or Niederreiter. If the initialization function g05ync was used then the sequence will be scrambled (see Section 3 in g05ync for details).

## 4References

Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software 14(1) 88–100
Fox B L (1986) Algorithm 647: implementation and relative efficiency of quasirandom sequence generators ACM Trans. Math. Software 12(4) 362–376

## 5Arguments

Note: the following variables are used in the parameter descriptions:
• $\mathit{idim}={\mathbf{idim}}$, the number of dimensions required, see g05ylc or g05ync
• $\mathit{liref}={\mathbf{liref}}$, the length of iref as supplied to the initialization function g05ylc or g05ync
1: $\mathbf{order}$Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{n}$Integer Input
On entry: the number of quasi-random numbers required.
Constraint: ${\mathbf{n}}\ge 0$ and ${\mathbf{n}}+\text{previous number of generated values}\le {2}^{31}-1$.
3: $\mathbf{quas}\left[\mathit{dim}\right]$double Output
Note: where ${\mathbf{QUAS}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{quas}}\left[\left(j-1\right)×{\mathbf{pdquas}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{quas}}\left[\left(i-1\right)×{\mathbf{pdquas}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: ${\mathbf{QUAS}}\left(i,j\right)$ holds the $i$th value for the $j$th dimension.
4: $\mathbf{pdquas}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array quas.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdquas}}\ge \mathit{idim}$;
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdquas}}\ge {\mathbf{n}}$.
5: $\mathbf{iref}\left[\mathit{dim}\right]$Integer Communication Array
Note: the dimension, dim, of the array iref must be at least $\mathit{liref}$.
On entry: contains information on the current state of the sequence.
On exit: contains updated information on the state of the sequence.
6: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INITIALIZATION
On entry, iref has either not been initialized or has been corrupted.
On entry, the specified dimensions are out of sync.
A different number of values have been generated from at least one of the specified dimensions.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{pdquas}}=⟨\mathit{\text{value}}⟩$, $\mathit{idim}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdquas}}\ge \mathit{idim}$.
On entry, ${\mathbf{pdquas}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdquas}}\ge {\mathbf{n}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_TOO_MANY_CALLS
On entry, value of n would result in too many calls to the generator: ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$, generator has previously been called $⟨\mathit{\text{value}}⟩$ times.

Not applicable.

## 8Parallelism and Performance

g05ymc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The Sobol, Sobol (A659) and Niederreiter quasi-random number generators in g05ymc have been parallelized, but require quite large problem sizes to see any significant performance gain. Parallelism is only enabled when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$. The Faure generator is serial.

None.

## 10Example

This example calls g05ylc and g05ymc to estimate the value of the integral
 $∫01 ⋯ ∫01 ∏ i=1 s |4xi-2| dx1, dx2, …, dxs = 1 .$
In this example the number of dimensions $S$ is set to $8$.

### 10.1Program Text

Program Text (g05ymce.c)

None.

### 10.3Program Results

Program Results (g05ymce.r)