mercredi 31 mai 2017

Segmentation fault when generating many random numbers - PGI Fortran

I need to generate a large amount of random numbers (from zero to 1, evenly distributed).

I initially had a Do loop and was generating random numbers on the fly as such:

Real :: RandomN
Integer :: N
DO N = 1, 10000
   Call RANDOM_NUMBER(RandomN)
   ... Some Code ...
ENDDO

However, I was getting a segmentation fault when generating the numbers (if I commented out the "call random_number(RandomN)" line, it worked fine).

Then after reading a post on the PGI forums(http://ift.tt/2roejnf). I decided to generate all the numbers first and put them in an array.

Real :: RndNum(1:10000,1:5)
Integer :: time(8), seed(2)
Call DATE_AND_TIME(values=time)     ! Get the current time 
seed(1) = time(4) * (360000*time(5) + 6000*time(6) + 100*time(7) + time(8))
Call RANDOM_SEED(PUT=seed)
Call RANDOM_NUMBER(RndNum)

However, this gives me a segfault straight away. I have also tried a reduced version without the seed:

Real :: RndNum(1:10000,1:5)
Call RANDOM_NUMBER(RndNum)

This works for a few iterations of my code and then produces a segmentation fault as well. Am I using up some sort of memory? is there a way to clear it? or prevent it from being used up?

Any help with generating the random numbers would be much appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire