Last active
August 29, 2015 14:25
-
-
Save ArchRobison/00e666bea128f1862f37 to your computer and use it in GitHub Desktop.
Julia program that demonstrates performance improvement from treating subnormals as zeros.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Apply smoothing operator to a, putting result in b. | |
function relax{T}( b::Vector{T}, a::Vector{T} ) | |
assert(length(a)==length(b)) | |
c = T(0.25) | |
d = T(0.5) | |
n = length(b) | |
b[1] = 1 # Boundary condition | |
@inbounds for i=2:n-1 | |
b[i] = c*a[i-1]+d*a[i]+c*a[i+1] | |
end | |
b[n] = 0 # Boundary condition | |
end | |
# Apply smoothing operator 1000 times | |
function flog{T}( b::Vector{T}, a::Vector{T} ) | |
for t=1:500 | |
relax(b,a) | |
relax(a,b) | |
end | |
end | |
# Warmup | |
flog(rand(Float32,100), rand(Float32,100)) | |
# Do some timing trials. | |
for i=1:12 | |
b = zeros(Float32,1000) | |
if i%3==0 | |
# Use tiny noise instead of zeros | |
a = rand(Float32,1000) .* 1E-9 | |
input = "nano-noise" | |
else | |
a = zeros(Float32,1000) | |
input = "zeros" | |
end | |
if i%3==2 | |
set_zero_subnormals(true) | |
rounding = "subnormals are zero" | |
else | |
set_zero_subnormals(false) | |
rounding = "IEEE" | |
end | |
a[1] = 1 | |
print(rpad(string(input," with ",rounding),30)) | |
@time flog(b,a) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment