Skip to content
Prev 4892 / 12125 Next

[R-pkg-devel] For reproducibility issue

Hi all,

I think what I?ve done is something different. Inside the Fortran subroutine, I have a subroutine for setting the seed value of the RNG of GNU Fortran which I think it is not related to the R RNG like the one below:

    subroutine initrandomseedsinr(temp)
    implicit none
    integer :: n
    integer, intent(in):: temp
    integer, dimension(:), allocatable :: seed

    call random_seed(size = n)
    allocate(seed(n))
    seed = temp
    call random_seed(PUT = seed)
    deallocate(seed)

    end subroutine initrandomseedsinr
, where temp is an argument of the Fortran subroutine as well as in the wrapper R function. This will be related to the RNG method used in the GNU Fortran that build on GCC not to the R. I am not sure if I am right on this, but tried with using RNGkind(sample.kind = "Rounding") and it doesn?t help. The difference in the results were not major. The output at the end of running the functions kept having very similar results, but still have the issue of reproducing exact results which I need it for relating work that is based on the package.

Many thanks,

Waleed




Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Avraham Adler<mailto:avraham.adler at gmail.com>
Sent: ?Friday,? ?January ?17,? ?2020 ?06:30 ??
To: Ivan Krylov<mailto:krylov.r00t at gmail.com>
Cc: ???? ??? ???? ???????<mailto:wkmtierie at qu.edu.sa>; R Package Development<mailto:r-package-devel at r-project.org>
Subject: Re: [R-pkg-devel] For reproducibility issue

Hi.

If it helps, I call the R RNG from Fortran in my Delaporte package
[1], also using iso_c_bindings. Specifically, I have the following C
code [2]:

void F77_SUB(unifrnd) (int *n, double *x){
GetRNGstate();
for (int i = 0; i < *n; ++i){
*(x + i) = unif_rand();
}
PutRNGstate();
}
and call it in Fortran like so [3]:

subroutine rdelap_f(n, a, na, b, nb, l, nl, vars) bind(C, name="rdelap_f_")

external unifrnd

integer(kind = c_int), intent(in), value :: n, na, nb, nl
real(kind = c_double), intent(out), dimension(n) :: vars
real(kind = c_double), intent(in) :: a(na), b(nb), l(nl)
real(kind = c_double), dimension(n) :: p
integer(kind = c_int) :: lg, lt

call unifrnd(n, p)
lt = 1_c_int
lg = 0_c_int
call qdelap_f(p, n, a, na, b, nb, l, nl, lt, lg, vars)

end subroutine rdelap_f

The package passes CRAN tests (at least as of now) on anything between
GCC 4 and GCC9 [4].

Hope that helps,

Avi

[1] https://bitbucket.org/aadler/delaporte/src/master/
[2] https://bitbucket.org/aadler/delaporte/src/master/src/utils_and_wrappers.c
[3] https://bitbucket.org/aadler/delaporte/src/master/src/delaporte.f95
[4] https://cran.r-project.org/web/checks/check_results_Delaporte.html
On Fri, Jan 17, 2020 at 2:39 PM Ivan Krylov <krylov.r00t at gmail.com> wrote:

  
  
Message-ID: <AM0PR07MB633928457834EE5E4AB3FC42EF310@AM0PR07MB6339.eurprd07.prod.outlook.com>
In-Reply-To: <CAL6gwnJdK9k6U22u6OvO+uwfLzrqLKN5jaW_9suDc=zW-smXEA@mail.gmail.com>