Skip to content

Commit 67b4443

Browse files
authored
Fixed gfortran issue
1 parent a9e600f commit 67b4443

File tree

4 files changed

+79
-55
lines changed

4 files changed

+79
-55
lines changed

timers/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SHELL=/bin/sh
33
.SUFFIXES:
44
.SUFFIXES: .o .F90 .f90
55

6-
FC=ifx
6+
FC=gfortran
77
FCFLAGS=-O2 -march=native
88
FXFLAGS=-O2 -march=native
99

timers/README.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@
1818
options. test_timers.F90 also tests the Fortran intrinsic CPU_TIME which
1919
is called directly.
2020

21+
The default compiler is gfortran. To build with different compiler
22+
using make just type (for example ifx)
23+
24+
make FC=ifx
25+
2126
You can change the number of iterations by adding -D__IMAX__=x and
2227
-D__JMAX=y where x and y are integer values to the compile options
23-
for test_timers.F90
28+
for test_timers.F90. ie
2429

25-
These programs were compiled and tested on a Linux Mint 21.3 system running on an AMD Ryzen 5 5600x processor with the following compilers
30+
make FC=gfortran-13 FCFLAGS="-O2 -march=native -D__linux__" FXFLAGS="-O2 -march= native -D__linux__ -D__IMAX__=1000 -D__JMAX=100"
2631

32+
Note the -D__linux__ is only needed for gfortran. The other compilers set
33+
__linux__ by default on Linux systems.
34+
35+
These programs were compiled and tested on a Linux Mint 21.3 system running on an AMD Ryzen 5 5600x processor with the following compilers
2736

2837
Intel
2938
ifx 2024.1.0

timers/test_timers.F90

+53-40
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Program test_timers
22

3-
USE ISO_FORTRAN_ENV, WP=>REAL64
4-
USE timers
5-
63
#ifndef __JMAX__
7-
#define __JMAX__ 10000
4+
#define __JMAX__ 10000
85
#endif
96
#ifndef __IMAX__
10-
#define __IMAX__ 10000
7+
#define __IMAX__ 10000
118
#endif
129

10+
USE ISO_FORTRAN_ENV, WP=>REAL64
11+
USE timers
12+
1313
Implicit NONE
1414

1515
Integer :: niters
@@ -20,6 +20,7 @@ Program test_timers
2020
Integer :: i, j
2121

2222
niters = (__IMAX__)*(__JMAX__)
23+
2324
Print *,''
2425
Print *,' *** Test of Fortran and C timer routines ***'
2526
Print *,''
@@ -28,105 +29,105 @@ Program test_timers
2829
sum = 0.0_WP
2930
time_e = 0.0_WP
3031
time_s = 0.0_WP
31-
Call timer_gtd(time_s)
32-
Do j=1, __JMAX__
32+
Call timer_dt(time_s)
33+
Do j=1, __JMAX__
3334
Do i=1, __IMAX__
34-
sum = sum + REAL(i+j,WP)
35+
sum = sum + Real(i+j,WP)
3536
End Do
3637
End Do
37-
Call timer_gtd(time_e)
38+
Call timer_dt(time_e)
3839
delta = time_e - time_s
39-
Write(*,'( " C gettimeofday = ", 1PE22.15)') delta
40+
Write(*,'( " DATE_AND_TIME = ", 1PE22.15)') delta
4041
Write(buf,'(1PE22.15)') sum
4142

4243
sum = 0.0_WP
4344
time_e = 0.0_WP
4445
time_s = 0.0_WP
45-
Call timer_cgt(time_s, CLOCK_MONOTONIC)
46+
Call CPU_TIME(time_s)
4647
Do j=1, __JMAX__
4748
Do i=1, __IMAX__
48-
sum = sum + REAL(i+j,WP)
49+
sum = sum + Real(i+j,WP)
4950
End Do
5051
End Do
51-
Call timer_cgt(time_e, CLOCK_MONOTONIC)
52+
Call CPU_TIME(time_e)
5253
delta = time_e - time_s
53-
Write(*,'( " C clock_gettime (MONOTONIC) = ", 1PE22.15)') delta
54+
Write(*,'( " CPU_TIME = ", 1PE22.15)') delta
5455
Write(buf,'(1PE22.15)') sum
5556

5657
sum = 0.0_WP
5758
time_e = 0.0_WP
5859
time_s = 0.0_WP
59-
Call timer_cgt(time_s, CLOCK_REALTIME)
60+
Call timer_sc(time_s)
6061
Do j=1, __JMAX__
6162
Do i=1, __IMAX__
62-
sum = sum + REAL(i+j,WP)
63+
sum = sum + Real(i+j,WP)
6364
End Do
6465
End Do
65-
Call timer_cgt(time_e, CLOCK_REALTIME)
66+
Call timer_sc(time_e)
6667
delta = time_e - time_s
67-
Write(*,'( " C clock_gettime (REALTIME) = ", 1PE22.15)') delta
68+
Write(*,'( " SYSTEM_CLOCK = ", 1PE22.15)') delta
6869
Write(buf,'(1PE22.15)') sum
6970

70-
#ifdef __linux__
7171
sum = 0.0_WP
7272
time_e = 0.0_WP
7373
time_s = 0.0_WP
74-
Call timer_cgt(time_s, CLOCK_THREAD_CPUTIME_ID)
75-
Do j=1, __JMAX__
74+
Call timer_gtd(time_s)
75+
Do j=1, __JMAX__
7676
Do i=1, __IMAX__
77-
sum = sum + REAL(i+j,WP)
77+
sum = sum + Real(i+j,WP)
7878
End Do
7979
End Do
80-
Call timer_cgt(time_e, CLOCK_THREAD_CPUTIME_ID)
80+
Call timer_gtd(time_e)
8181
delta = time_e - time_s
82-
Write(*,'( " C clock_gettime (THREAD_CPUTIME) = ", 1PE22.15," Linux only")') delta
82+
Write(*,'( " C gettimeofday = ", 1PE22.15)') delta
8383
Write(buf,'(1PE22.15)') sum
84-
#endif
85-
84+
8685
sum = 0.0_WP
8786
time_e = 0.0_WP
8887
time_s = 0.0_WP
89-
Call timer_dt(time_s)
88+
Call timer_cgt(time_s, CLOCK_MONOTONIC)
9089
Do j=1, __JMAX__
9190
Do i=1, __IMAX__
92-
sum = sum + REAL(i+j,WP)
91+
sum = sum + Real(i+j,WP)
9392
End Do
9493
End Do
95-
Call timer_dt(time_e)
94+
Call timer_cgt(time_e, CLOCK_MONOTONIC)
9695
delta = time_e - time_s
97-
Write(*,'( " DATE_AND_TIME = ", 1PE22.15)') delta
96+
Write(*,'( " C clock_gettime (MONOTONIC) = ", 1PE22.15)') delta
9897
Write(buf,'(1PE22.15)') sum
9998

10099
sum = 0.0_WP
101100
time_e = 0.0_WP
102101
time_s = 0.0_WP
103-
Call CPU_TIME(time_s)
102+
Call timer_cgt(time_s, CLOCK_REALTIME)
104103
Do j=1, __JMAX__
105104
Do i=1, __IMAX__
106-
sum = sum + REAL(i+j,WP)
105+
sum = sum + Real(i+j,WP)
107106
End Do
108107
End Do
109-
Call CPU_TIME(time_e)
108+
Call timer_cgt(time_e, CLOCK_REALTIME)
110109
delta = time_e - time_s
111-
Write(*,'( " CPU_TIME = ", 1PE22.15)') delta
110+
Write(*,'( " C clock_gettime (REALTIME) = ", 1PE22.15)') delta
112111
Write(buf,'(1PE22.15)') sum
113112

113+
#ifdef __linux__
114114
sum = 0.0_WP
115115
time_e = 0.0_WP
116116
time_s = 0.0_WP
117-
Call timer_sc(time_s)
117+
Call timer_cgt(time_s, CLOCK_THREAD_CPUTIME_ID)
118118
Do j=1, __JMAX__
119119
Do i=1, __IMAX__
120-
sum = sum + REAL(i+j,WP)
120+
sum = sum + Real(i+j,WP)
121121
End Do
122122
End Do
123-
Call timer_sc(time_e)
123+
Call timer_cgt(time_e, CLOCK_THREAD_CPUTIME_ID)
124124
delta = time_e - time_s
125-
Write(*,'( " SYSTEM_CLOCK = ", 1PE22.15)') delta
125+
Write(*,'( " C clock_gettime (THREAD_CPUTIME) = ", 1PE22.15," Linux only")') delta
126126
Write(buf,'(1PE22.15)') sum
127-
127+
#endif
128+
128129
Print *,''
129-
Print *,'DATE_AND_TIME and SYSTEM_CLOCK increments'
130+
Print *,'DATE_AND_TIME, CPU_TIME and SYSTEM_CLOCK increments'
130131
Print *,''
131132
time_e = 0.0_WP
132133
time_s = 0.0_WP
@@ -137,6 +138,17 @@ Program test_timers
137138
End Do
138139
delta = time_e - time_s
139140
Write(*,'( " DATE_AND_TIME increment = ", 1PE22.15)') delta
141+
142+
time_e = 0.0_WP
143+
time_s = 0.0_WP
144+
Call CPU_TIME(time_s)
145+
Do
146+
Call CPU_TIME(time_e)
147+
If (time_e > time_s) EXIT
148+
End Do
149+
delta = time_e - time_s
150+
Write(*,'( " CPU_TIME increment = ", 1PE22.15)') delta
151+
140152
time_e = 0.0_WP
141153
time_s = 0.0_WP
142154
Call timer_sc(time_s)
@@ -147,6 +159,7 @@ Program test_timers
147159
delta = time_e - time_s
148160
Write(*,'( " SYSTEM_CLOCK increment = ", 1PE22.15)') delta
149161
Print *,''
162+
150163
Stop
151164

152165
End Program test_timers

timers/timers.F90

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Module timers
44
USE ISO_C_BINDING, ONLY: C_INT, C_LONG, C_PTR, C_NULL_PTR, C_DOUBLE
55

66
Implicit NONE
7-
PRIVATE
7+
Private
8+
89
! Define some clock ids for C clock_gettime function
910

1011
Integer(C_INT), Parameter :: CLOCK_REALTIME = 0_C_INT
@@ -35,10 +36,10 @@ Module timers
3536
Interface
3637
Function gettimeofday_c(timeval, timezone) BIND(C, NAME="gettimeofday")
3738

38-
Import :: timeval_c, C_PTR, C_INT
39-
Type(timeval_c), Intent(INOUT) :: timeval
40-
Type(C_PTR), Intent(IN) :: timezone
41-
Integer(C_INT) :: gettimeofday_c
39+
Import :: timeval_c, C_PTR, C_INT
40+
Type(timeval_c), Intent(OUT) :: timeval
41+
Type(C_PTR), Intent(IN) :: timezone
42+
Integer(C_INT) :: gettimeofday_c
4243
End Function gettimeofday_c
4344
End Interface
4445

@@ -47,16 +48,17 @@ Function clock_gettime_c(clockid, tp) BIND(C,NAME="clock_gettime")
4748

4849
Import :: timespec_c, C_INT
4950

50-
Integer(C_INT), VALUE :: clockid
51-
Type(timespec_c), Intent(INOUT) :: tp
52-
Integer(C_INT) :: clock_gettime_c
51+
Integer(C_INT), VALUE :: clockid
52+
Type(timespec_c), Intent(OUT) :: tp
53+
Integer(C_INT) :: clock_gettime_c
5354

5455
End Function clock_gettime_c
5556
End Interface
5657

5758
Public :: timer_dt, timer_gtd, timer_cgt, timer_sc
5859
Public :: CLOCK_REALTIME
5960
Public :: CLOCK_MONOTONIC
61+
6062
! These are Linux only
6163
#ifdef __linux__
6264
Public :: CLOCK_PROCESS_CPUTIME_ID
@@ -100,14 +102,14 @@ End Subroutine timer_gtd
100102

101103
Subroutine timer_cgt(time, clockid)
102104

103-
! Wrap call to C clock_gettime and return time in secs and nsecs
104-
! depending on clockid. Realative clock CLOCK_MONOTONIC is default
105+
! Wrap call to C clock_gettime and return time in seconds
106+
! depending on clockid. clockid CLOCK_MONOTONIC is the default
105107

106108
Real(WP), Intent(OUT) :: time
107109
Integer(C_INT), Optional, Intent(IN) :: clockid
108-
Type(timespec_c) :: td
109110

110-
Integer(C_INT) :: cid, err
111+
Integer(C_INT) :: cid, err
112+
Type(timespec_c) :: td
111113

112114
cid = CLOCK_MONOTONIC
113115

0 commit comments

Comments
 (0)