From gilles.guillot at inapg.inra.fr  Wed Nov 30 16:06:33 2005
From: gilles.guillot at inapg.inra.fr (Gilles GUILLOT)
Date: Wed, 30 Nov 2005 16:06:33 +0100
Subject: [Rd] RNG stuck via Fortran call
Message-ID: <200511301606.34120.gilles.guillot@inapg.inra.fr>

Having not much success with my previous question I try to reformulate it:

I'm simulating a Markow chain in Fortran interfaced with R.
Each loop of my Fortran calls various functions of the R RNG through 
the wrapper given below.

In a run of 100 iterations of the Markov kernel, 
 after 20 iterations, the RNG seems like frozen.

For example, the first call to the RNG in my loop is:

 rpostlamb = ggrgam(dble(m),1.d0)
 write(*,*) 'rpostlamb=',rpostlamb


after the 20th iteration,  it will return the same value 
rpostlamb=  1.24634557

for all the following interations.

Is there any suggestion of explanation for this strange fact ?


Thanks in advance

Gilles 

R Version 2.2.0 compiled under Mandrake 10.1


#include <R.h>
#include <Rmath.h>

/******************/
/* random numbers */
/******************/

void F77_SUB(rndstart)(void) 
{ GetRNGstate(); }

void F77_SUB(rndend)(void) 
{ PutRNGstate(); }

double F77_SUB(ggrnorm)(double *mu, double *sigma) 
{ return rnorm(*mu, *sigma); }

double F77_SUB(ggrexp)(double *scale)
{return rexp(*scale);}

double F77_SUB(ggrgam)(double *a, double *scale)
{return rgamma(*a, *scale);}

double F77_SUB(ggrunif)(double *a, double *b)
{return runif(*a, *b);}

double F77_SUB(ggrbinom)(double *n, double *p)
{return rbinom(*n, *p);}

double F77_SUB(ggrpois)(double *lambda)
{return rpois(*lambda);}



[Rd] RNG stuck via Fortran call
Gilles GUILLOT