PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

Need help on using RANDOM_SEED

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
tom.rb.edwards



Joined: 02 Dec 2010
Posts: 35

PostPosted: Tue May 31, 2011 8:14 am    Post subject: Need help on using RANDOM_SEED Reply with quote

I would like to generate the same set of random numbers each time I execute a program. The problem is that each time I run it, the random numbers are different because they are seeded by a different value. Here is my program:

Code:
program test
  implicit none
  real :: rand_num
  integer :: index

  call random_seed()
  do index = 1,10
    call random_number(rand_num)
    print*,rand_num
  end do

end program test


So in order to seed with the same value at each execution, one must put an argument in random_seed() that will seed with the same value each time.

The problem is that when I try 'random_seed(1)' or 'random_seed(put=1)', neither work as the compiler comes up with an error saying
Quote:
PGF90-S-0074-Illegal number or type of arguments to random_seed - keyword argument size (rand_test.f90: 6)


How do I then use random_seed to force the same seed at each execution of the program?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6660
Location: The Portland Group Inc.

PostPosted: Tue May 31, 2011 9:29 am    Post subject: Reply with quote

Hi Tom,

Your on the right track. The only correction is that the put argument to random_seed needs to be an array.

Code:
% cat rand.f90
program test
  implicit none
  real :: rand_num
  integer :: index, seeds(2)
  seeds(1)=1
  call random_seed(put=seeds)
  do index = 1,10
    call random_number(rand_num)
    print*,rand_num
  end do
end program test


Alternatively, you can set the environment variable "STATIC_RANDOM_SEED" to "YES" to have the PGI runtime use a static instead of variable initial seed.

Hope this helps,
Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group