How to get system time for a RNG seed?

Hello,

Can I use SYSTEM_CLOCK(COUNT, COUNT_RATE, COUNT_MAX)
in the PGI FORTRAN? It’s supposed to be an “intrinsic” subroutine in f90.
I declare

integer COUNT, COUNT_RATE, COUNT_MAX

and put

SYSTEM_CLOCK(COUNT, COUNT_RATE, COUNT_MAX)

in the main body. The compiler complains:

: error S0034 : Syntax error at or near end of line.

How to make it compile? Will

COUNT

be a large random interger that can be used as a seed for a RNG.

Thanks.

Art.

I think the issue is that SYSTEM_CLOCK is an intrinsic subroutine, so it must be CALL’ed:

CALL SYSTEM_CLOCK(…)

That’s usually my issue when I find an intrinsic is erroring out, I’ve used function syntax instead of subroutine.

ETA: I don’t think this will do what you are wanting, now that I’ve tried a test program. It looks like PGI uses SYSTEM_CLOCK to return the number of ticks since execution starting at 0. So if you CALL SYSTEM_CLOCK(t0) and then CALL SYSTEM_CLOCK(t1), you’ll get t0=0 and t1=50 or something. The standard seems to state that the starting count is arbitrary, and PGI chose 0.

The question now is how is RANDOM_SEED seeded by PGI with no arguments? With some compilers, I think CALL RANDOM_SEED() is seeded by the system clock, but it is implementation dependent, I’m fairly sure.

Hi Matt,

You are correct on all counts. Though for early PGI releases (pre 5.2) or if the user sets the environment flag “STATIC_RANDOM_SEED”, a static random seed is used.

  • Mat

Hello,

I am trying to get a random seed for my RNG.

I have tested 3 functions:

CALL SYSTEM_CLOCK(COUNT, COUNT_RATE, COUNT_MAX)

call date_and_time(date)

CALL RANDOM_SEED(seed)

For some reason I always get the same numbers for ‘COUNT, COUNT_RATE, COUNT_MAX’! Even for ‘seed’ I get the same number, which is always 34 on my system. ‘date’ has the day, month, and the year in it. Hopefully, this variable will change on daily basis, but it’s a character, and I still have to convert it to an integer.

I read somewhere on this forum that ‘COUNT_MAX’ is the time from the beginning of the execution rather than the system time.

Please help to get the system time in a long integer format.

Thanks.

Artem.

Hi Artem,

The logic for setting the random seed is as follows:

    1. If RANDOM_NUMBER is called without RANDOM_SEED being called first, then a static (hard coded) seed is used.
  1. A user defined seed is used when RANDOM_SEED is called with an argument.
  2. When RANDOM_SEED is called without arguments, a seed is generated based on the system time and current process ID. (Unless the environment variable “STATIC_RANDOM_SEED” is set to 1, where a static seed is used instead.).

Try calling RANDOM_SEED without arguments since sounds like what you want.

Alternatively, you may want to use the lib3F function “stime” which returns the number of seconds since 00:00:00 GMT January 1, 1970. (See: Chapter 7 of the PGI Fortran Reference Guide.).

Hope this helps,
Mat