# SkipAheadStream

Initializes a stream using the block-splitting method.

## Syntax

Fortran:

status = vslskipaheadstream( stream, nskip )

C:

status = vslSkipAheadStream( stream, nskip);

## Description

This function skips a given number of elements in a random stream. This feature is particularly useful in distributing random numbers from original random stream across different computational nodes. If the largest number of random numbers used by a computational node is nskip, then the original random sequence may be split by SkipAheadStream into non-overlapping blocks of nskip size so that each block corresponds to the respective computational node. The number of computational nodes is unlimited. This method is known as the block-splitting method or as the skip-ahead method. (see Figure“Block-Splitting Method”).

Block-Splitting Method

The skip-ahead method is supported only for those basic generators that allow skipping elements by the skip-ahead method, which is more efficient than simply generating them by generator with subsequent manual skipping. See VSL Notes for details.

Please note that for quasi-random basic generators the skip-ahead method works with components of quasi-random vectors rather than with whole quasi-random vectors. Thus to skip NS quasi-random vectors, set nskip parameter equal to the NS*DIMEN, where DIMEN is the dimension of quasi-random vector.

The following code examples illustrate how to initialize three independent streams using SkipAheadStream function:

## FORTRAN Code for Block-Splitting Method

...

type(VSL_STREAM_STATE) ::stream1

type(VSL_STREAM_STATE) ::stream2

type(VSL_STREAM_STATE) ::stream3

! Creating the 1st stream

status = vslnewstream(stream1, VSL_BRNG_MCG31, 174)

! Skipping ahead by 7 elements the 2nd stream

status = vslcopystream(stream2, stream1);

status = vslskipaheadstream(stream2, 7);

! Skipping ahead by 7 elements the 3rd stream

status = vslcopystream(stream3, stream2);

status = vslskipaheadstream(stream3, 7);

! Generating random numbers

...

! Deleting the streams

status = vsldeletestream(stream1)

status = vsldeletestream(stream2)

status = vsldeletestream(stream3)

...

## C Code for Block-Splitting Method

VSLStreamStatePtr stream1;

VSLStreamStatePtr stream2;

VSLStreamStatePtr stream3;

/* Creating the 1st stream

*/

status = vslNewStream(&stream1, VSL_BRNG_MCG31, 174);

/* Skipping ahead by 7 elements the 2nd stream */

status = vslCopyStream(&stream2, stream1);

status = vslSkipAheadStream(stream2, 7);

/* Skipping ahead by 7 elements the 3rd stream */

status = vslCopyStream(&stream3, stream2);

status = vslSkipAheadStream(stream3, 7);

/* Generating random numbers

*/

...

/* Deleting the streams

*/

status = vslDeleteStream(&stream1);

status = vslDeleteStream(&stream2);

status = vslDeleteStream(&stream3);

...

## Input Parameters

Name | Type | Description
--- | --- | ---
stream | FORTRAN: TYPE(VSL_STREAM_STATE), INTENT(IN) C: VSLStreamStatePtr | FORTRAN: Descriptor of the stream to which block-splitting method is applied C: Pointer to the stream state structure to which block-splitting method is applied
nskip | FORTRAN: INTEGER(KIND=8), INTENT(IN) C: long long | Number of skipped elements

## Return Values

VSL_ERROR_OK, VSL_STATUS_OK
  Indicates no error, execution is successful.
VSL_ERROR_NULL_PTR
  stream is a NULL pointer.
VSL_ERROR_BAD_STREAM

  stream is not a valid random stream.

VSL_ERROR_SKIPAHEAD_UNSUPPORTED

  BRNG does not support Skip-Ahead method.

Parent topic: Service Routines