help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] RNG and threads


From: Warren Weckesser
Subject: Re: [Help-gsl] RNG and threads
Date: Thu, 4 Sep 2008 19:36:22 -0400

This has nothing to do with threads.  Check this out:

----------
#include <stdio.h>
#include <gsl/gsl_rng.h>

int main (void)
    {
    const gsl_rng_type * T;
    gsl_rng *r1, *r2, *r3;
    int i, n = 10;

    gsl_rng_env_setup();

    T = gsl_rng_ranlxs0;

    r1 = gsl_rng_alloc(T);
    r2 = gsl_rng_alloc(T);
    r3 = gsl_rng_alloc(T);
    gsl_rng_set(r1,0);
    gsl_rng_set(r2,1);
    gsl_rng_set(r3,2);

    for (i = 0; i < n; i++)
        {
        double u1 = gsl_rng_uniform (r1);
        double u2 = gsl_rng_uniform (r2);
        double u3 = gsl_rng_uniform (r3);
        printf ("%.11f %.11f %.11f\n", u1,u2, u3);
        }

    gsl_rng_free (r1);
    gsl_rng_free (r2);
    gsl_rng_free (r3);
    return 0;
    }
----------
Compile and run:
----------
$ gcc gslrngtest.c -lgsl -o gslrngtest
$ ./gslrngtest
0.32085895538 0.32085895538 0.16047435999
0.49408543110 0.49408543110 0.24704271555
0.70446860790 0.70446860790 0.35229921341
0.81177759171 0.81177759171 0.40588879585
0.65004783869 0.65004783869 0.32499593496
0.75581908226 0.75581908226 0.87790954113
0.16959655285 0.16959655285 0.08471691608
0.24530410767 0.24530410767 0.12265205383
0.18674021959 0.18674021959 0.59334981441
0.62624281645 0.62624281645 0.31312137842
$
----------
My guess as to why the first two columns are the same is based on this quote
from the docs:

"If the seed s is zero then the standard seed from the original
implementation is used instead."

Perhaps the "standard seed from the original implementation" of ranlxs0
algorithm is 1.

Warren



On Thu, Sep 4, 2008 at 6:15 PM, Torquil Macdonald Sørensen <
address@hidden> wrote:

> Hello, are all the RNGs supposed to generate independent streams of numbers
> when they are declared in separate threads? I'm seeing some strange results
> with the ranlxs0, but mt19937 seems to behave as expected. In the manual it
> says
>
> "Each instance of a generator keeps track of its own state, allowing the
> generators to be used in multi-threaded programs."
>
> But when I run my OpenMP-parallelized program with ranlxs0, both threads
> produce the exact same results! With mt19937 I get different results for
> each thread (which is expected since I always seed with the thread
> identification number 0, 1, 2, ...).
>
> Best regards,
> Torquil Sørensen
>
>
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]