/
TimingAccuracyGLQ.f95
151 lines (123 loc) · 4.82 KB
/
TimingAccuracyGLQ.f95
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Program TimingAccuracyGLQ
!------------------------------------------------------------------------------
!
! This program will test the accuracy of the spherical harmonic GLQ
! tranformation routines by expanding a field in the space domain,
! transforming this to spherical harmonics, and comparing the relative error
! of the coefficients.
!
! Copyright (c) 2005, SHTOOLS
! All rights reserved.
!
!------------------------------------------------------------------------------
use SHTOOLS
use ftypes
implicit none
integer, parameter :: maxdeg = 2800
character(200) :: outfile1, outfile2, outfile3, outfile4, outfile
real(dp), allocatable :: cilm(:,:,:), cilm2(:,:,:), zero(:), &
gridglq(:,:), w(:)
real(dp) :: maxerror, err1, err2, beta, rms, timein(3), timeout(3)
integer :: lmax, l, m, seed, astat(5)
allocate(cilm(2,maxdeg+1,maxdeg+1), stat=astat(1))
allocate(cilm2(2,maxdeg+1,maxdeg+1), stat=astat(2))
allocate(zero(maxdeg+1), stat=astat(3))
allocate(gridglq(maxdeg+1,2*maxdeg+1), stat=astat(4))
allocate(w(maxdeg+1), stat=astat(5))
if (sum(astat(1:5)) /= 0) then
print*, "Error --- TimingAccuracyGLQ"
print*, "Problem allocating arrays CILM, CILM2, ZERO, GRIDGLQ, W"
stop
end if
print*, "Value of beta for power law Sff = l^(-beta) > "
read(*,*) beta
print*, "output file name > "
read(*,*) outfile
outfile1 = trim(outfile) // ".timef"
outfile2 = trim(outfile) // ".timei"
outfile3 = trim(outfile) // ".maxerror"
outfile4 = trim(outfile) // ".rmserror"
seed = -1053253
cilm = 0.0_dp
do l = 1, maxdeg
do m = 0, l
if (m == 0) then
cilm(1,l+1,m+1) = RandomGaussian(seed)
else
cilm(1,l+1,m+1) = RandomGaussian(seed)
cilm(2,l+1,m+1) = RandomGaussian(seed)
end if
end do
cilm(1:2, l+1, 1:l+1) = cilm(1:2, l+1, 1:l+1) * sqrt(dble(l)**beta) &
/ sqrt(2.0_dp * l + 1)
enddo
print*, "Lmax, Maximum rel. error of Cilm, RMS relative error, Precompute time (sec), Time inverse (sec), Time forward (sec)"
lmax = 1
do
lmax = lmax * 2
if (lmax > maxdeg) lmax = maxdeg
if (lmax == 2) then
open(12,file=outfile1, status="replace")
open(13,file=outfile2, status="replace")
open(14,file=outfile3, status="replace")
open(15,file=outfile4, status="replace")
else
open(12,file=outfile1, position="append")
open(13,file=outfile2, position="append")
open(14,file=outfile3, position="append")
open(15,file=outfile4, position="append")
endif
call cpu_time(timein(1))
call SHGLQ(lmax, zero(1:lmax+1), w(1:lmax+1))
call cpu_time(timeout(1))
call cpu_time(timein(2))
call MakeGridGLQ(gridglq(1:lmax+1, 1:2*lmax+1), &
cilm(1:2,1:lmax+1, 1:lmax+1), lmax, &
zero=zero(1:lmax+1), norm=1)
call cpu_time(timeout(2))
call cpu_time(timein(3))
call SHExpandGLQ(cilm2(1:2, 1:lmax+1, 1:lmax+1), lmax, &
gridglq(1:lmax+1, 1:2*lmax+1), w, &
zero=zero(1:lmax+1), norm=1)
call cpu_time(timeout(3))
maxerror = 0.0_dp
rms = 0.0_dp
do l = 1, lmax
do m = 0, l
if (m == 0) then
err1 = abs( (cilm(1,l+1,m+1) - cilm2(1,l+1,m+1)) / cilm(1,l+1,m+1) )
if (err1 >= maxerror) maxerror = err1
rms = rms + err1**2
else
err1 = abs( (cilm(1,l+1,m+1) - cilm2(1,l+1,m+1)) / cilm(1,l+1,m+1) )
err2 = abs( (cilm(2,l+1,m+1) - cilm2(2,l+1,m+1)) / cilm(2,l+1,m+1) )
if (err1 >= maxerror) maxerror = err1
if (err2 >= maxerror) maxerror = err2
rms = rms + err1**2 + err2**2
end if
end do
end do
rms = sqrt(rms / dble(l+1)**2)
! elasped time in seconds!
print*, lmax, maxerror, rms, timeout(1)-timein(1), timeout(2)-timein(2), timeout(3)-timein(3)
write(12,*) lmax, timeout(2)-timein(2)
write(13,*) lmax, timeout(3)-timein(3)
write(14,*) lmax, maxerror
write(15,*) lmax, rms
if (maxerror > 100.0_dp) then
print*, "TESTS FAILED"
print*, "Degree = ", lmax
print*, "Maximum relative error = ", maxerror
close(12)
close(13)
close(14)
close(15)
stop
end if
close(12)
close(13)
close(14)
close(15)
if (lmax == maxdeg) exit
enddo
end program TimingAccuracyGLQ