Skip to content
Snippets Groups Projects
Verified Commit 490029a9 authored by Dorian Stoll's avatar Dorian Stoll
Browse files

rodinia-srad: julia: Convert to threads

parent a8994fc5
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env julia
using Printf
using Random
const OUTPUT = haskey(ENV, "OUTPUT")
function usage()
......@@ -47,22 +50,20 @@ function main(args)
jW[1] = 1
jE[cols] = cols
dN::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols))
dS::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols))
dW::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols))
dE::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols))
dN::Matrix{Float32} = zeros(rows,cols)
dS::Matrix{Float32} = zeros(rows,cols)
dW::Matrix{Float32} = zeros(rows,cols)
dE::Matrix{Float32} = zeros(rows,cols)
println("Randomizing the input matrix")
srand(7)
Random.seed!(7)
I = rand(Float32,rows,cols)
J::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols),init = J -> J[Base.localindexes(J)] = exp.(I[Base.localindexes(J)]))
c::SharedArray{Float32,2} = SharedArray(Float32,(rows,cols))
J = exp.(I)
c::Matrix{Float32} = zeros(rows,cols)
println("Start the SRAD main loop")
tic()
sum::Float32 = 0
sum2::Float32 = 0
for iter in 1:niter
......@@ -80,7 +81,7 @@ function main(args)
varROI::Float32 = (sum / size_R) - meanROI * meanROI
q0sqr::Float32 = varROI / (meanROI * meanROI)
@sync @parallel for i in 1:size(J,1)
Threads.@threads for i in 1:size(J,1)
for j in size(J,2)
Jc = J[i,j]
......@@ -113,7 +114,7 @@ function main(args)
end
end
@sync @parallel for i in 1:size(J,1)
Threads.@threads for i in 1:size(J,1)
for j in 1:size(J,2)
# diffusion coefficient
cN = c[i,j]
......@@ -130,8 +131,6 @@ function main(args)
end
end
toc()
println("Computation done")
if OUTPUT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment