Hi, I'm having trouble using the system_clock intrinsic with g95: it
is only returning count=0. I get the same behavior on Linux x86 and
on Windows x86 under MinGW. Here is my test program:
--------------------------------------------------------------
[sys_clock]$ g95 --version | head -n1
G95 (GCC 4.0.3 (g95 0.92!) May 5 2009)
[sys_clock]$ cat prog.f90
PROGRAM prog
INTEGER :: clock, rate, cmax
CALL SYSTEM_CLOCK(clock,count_rate=rate,count_max=cmax)
PRINT*, 'size of int:', sizeof(clock)
PRINT*, 'count:', clock
PRINT*, 'rate:', rate
PRINT*, 'max:', cmax
END PROGRAM prog
[sys_clock]$ g95 prog.f90
[sys_clock]$ a.out
size of int: 4
count: 0
rate: 10000
max: 2147483647
----------------------------------------------------------------------
PROGRAM prog
INTEGER :: clock, rate, cmax, i, j
REAL(8) :: D
DO i = 1, 5
CALL SYSTEM_CLOCK(clock,count_rate=rate,count_max=cmax)
PRINT*, 'size of int:', sizeof(clock)
PRINT*, 'count:', clock
PRINT*, 'rate:', rate
PRINT*, 'max:', cmax
!!!!!!!!!!!!!!!!!!!
!! WORK A LITTLE !!
!!!!!!!!!!!!!!!!!!!
DO j = 1, 999
D = SIN(D) +0.25
END DO
END DO
END PROGRAM prog
Thanks, I tied that, and my output looks like:
[sys_clock]$ ./a.out
count: 0
count: 1
count: 2
count: 2
count: 3
So it looks like it is counting. However, I am trying to use this to
randomize the random number seed as described at
http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, in which
case this will not work. I am aware that with g95, calling random_seed
() without arguments will randomize the seed, but this does not work
on certain other compilers (e.g. gfortran, which just sets the seed to
a "default" value).
I guess my real question is whether or not there is a compiler-
independent mechanism for randomizing the seed?
Also from reading here:
http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/...,
it states that "The initial value of COUNT depends on the current
value of the processor clock in a range from 0 to COUNT_MAX." It
seems like that by always starting the count at 0 when you make the
first call to system_clock, g95 is not producing the correct behavior.
You can search among system files to get a "number" that changes from
run to run. Use INQUIRE, if the file is found, open it, read a
number, then return with this number. For example, you can search for
the file
/proc/uptime
If it's there then it will contain different numbers at different
times. With enough research you can write a subroutine that can look
for standard files on many types of OS's without ever having to call a
nonstandard subroutine such as system().
Thanks, this is also what Andy Vaught suggested, and we are now using
it. See here: http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gfortran/DATE_005fAND_005fTIM....
This function returns milliseconds, seconds, minutes, etc., and can
easily be used to generate a seed. Works with both g95 and gfortran.
On Jun 15, 6:27 am, Evangelos Bertakis <eberta...@gmail.com> wrote: