Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Random numbers with coarrays

Arjen_Markus
Honored Contributor I
439 Views

Hello, I have asked this on the forum for Windows as well (see https://software.intel.com/en-us/node/add/forum/36933 for the discussion there), but I ran into the following problem with the random number generator and coarrays (text copied forr the Windows forum):

---

I have run into a small riddle. I was trying to use the random_number subroutine in a small program using coarrays and discovered that on Linux, with the Intel compiler version I have access to, 18.0.3, the random numbers on each image are the same (well, sometimes I see two sets but not clearly independent sequences). When I try this on Windows (version 18.0.5) , I do get independent random numbers. In both cases I use random_seed to initialise the random number generator. Here is a small demo program:

program chkrandom
    implicit none

   real :: r

   call random_seed
   call random_number( r )

   write(*,*) this_image(), r

end program chkrandom

Typical output on Windows:

3  0.2110407
6  0.4997412
1  0.1226530
7  0.5719163
8  0.2361415
5  0.1315411
2  0.5468156
4  0.5232784

Typical output on Linux:

1  0.8679414
2  0.8679414
3  0.8679414
4  0.8679414
5  0.8679414
6  0.8679414
7  0.8679414
8  0.8679414

and every once in a while something like this:

1  0.5012199
2  0.5980424
3  0.5012199
4  0.5012199
5  0.5012199
6  0.5012199
7  0.4597191
8  0.5012199

Clearly not the most independent random numbers.

Does anyone know how I can get better results?

----

The various suggestions I got led to slightly more variation, but not quite as much as I expected. Here is a typical output from a slightly modified demo program (requiring two random numbers instead of one for each call to random_number):

           1  0.6096058      0.3789599
           2  0.6165187      0.9890364
           3  0.6234315      0.5991130
           4  0.6303443      0.2091895
           5  0.6372572      0.8192660
           6  0.6441700      0.4293426
           7  0.6510828      3.9419141E-02
           8  0.6579956      0.6494957

It would seem that you need to spend a few more random numbers to get a satisfactory result.

Does anybody have a better suggestion?

0 Kudos
2 Replies
AThar2
Beginner
439 Views

I think you got a typo. Is that not the topic you were referring to

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/808640

0 Kudos
Arjen_Markus
Honored Contributor I
439 Views

Oops, my apologies - that is indeed the correct reference.

0 Kudos
Reply