/
pisum.f90
100 lines (69 loc) · 1.93 KB
/
pisum.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module benchmark_iter
use, intrinsic :: iso_fortran_env, only : dp=>real64,i64=>int64, stderr=>error_unit
use perf, only : init_random_seed, sysclock2ms, assert
Implicit None
integer, parameter :: wp=dp
contains
Real(dp) function pisum(N,Nrun) result(t)
integer, intent(in) :: N,Nrun
integer(i64) :: tic,toc,tmin
! integer(i64) :: tmin[*] = huge(0_i64)
! real(wp) :: psum[*] = 0._wp
integer :: k,j, im, Nimg
real(wp), parameter :: pi = 4.0_wp*atan(1.0_wp)
real(wp), volatile :: psum
tmin = huge(0_i64)
!im = this_image()
!Nimg = num_images()
im=1
Nimg= 1
do j = 1,Nrun
call system_clock(tic)
psum = 0._wp ! must have this line
do k = im,N, Nimg ! 1,N
psum = psum + (-1.0_wp)**(real(k,wp)+1.0_wp) / (2.0_wp*k - 1.0_wp)
enddo
! call co_sum(psum)
call system_clock(toc)
if (toc-tic<tmin) tmin=toc-tic
enddo
! if (im==1) then
psum = 4._wp*psum
if (abs(psum-pi) > 1e-4_wp) then
write(stderr,*) 'final value',psum
write(stderr,*) 'error ', psum - pi
write(stderr,*) 'FORTRAN pisum fail to converge'
stop 1
endif
! endif
! call co_min(tmin)
t = sysclock2ms(tmin) / 1000
End Function pisum
end module benchmark_iter
Program run_iter
use, intrinsic:: iso_fortran_env, only: dp=>real64, i64=>int64, compiler_version, compiler_options
use benchmark_iter,only: pisum
use perf, only: sysclock2ms
Implicit None
integer :: N=1000000, Nrun=10, argc, Ni
character(16) :: argv
real(dp) :: t
! Ni = num_images()
Ni=1
argc = command_argument_count()
if (argc>0) then
call get_command_argument(1,argv)
read(argv,*) N
endif
if (argc>1) then
call get_command_argument(2,argv)
read(argv,*) Nrun
endif
!-----------------------------------------------------
print '(A,I12,A,I3,A)', '--> Fortran. N=',N,' using',Ni,' images'
!print *,compiler_version()
!print *,compiler_options()
!------pisum----------------
t = pisum(N, Nrun)
print '(ES12.4,A)', t,' sec.'
End Program