Skip to content

Instantly share code, notes, and snippets.

@jtravs
Created April 28, 2014 11:28
Show Gist options
  • Save jtravs/11368929 to your computer and use it in GitHub Desktop.
Save jtravs/11368929 to your computer and use it in GitHub Desktop.
module testsums
export sum5, sum5b, dosums
function sum5(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
for i=1:length(out)
@inbounds out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i]
+ sa4*a4[i] + sa5*a5[i])
end
end
function sum5b(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
for i=1:length(out)
@inbounds out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i])
@inbounds out[i] += scale*(sa4*a4[i] + sa5*a5[i])
end
end
function dosums(T)
scale = rand()
sa1 = rand()
a1 = rand(T,200000)
sa2 = rand()
a2 = rand(T,200000)
sa3 = rand()
a3 = rand(T,200000)
sa4 = rand()
a4 = rand(T,200000)
sa5 = rand()
a5 = rand(T,200000)
out = similar(a1)
sum5(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
@time sum5(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
sum5b(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
@time sum5b(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment