-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df491c4
commit 158148b
Showing
4 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "FinEtoolsHeatDiff" | ||
uuid = "972d1c22-8bdd-11e9-11cf-cdcb7577b041" | ||
authors = ["Petr Krysl <[email protected]>"] | ||
version = "3.0.5" | ||
version = "3.0.6" | ||
|
||
[deps] | ||
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
module mgather1 | ||
using Test | ||
using Random | ||
|
||
function test() | ||
N = 10000 # Number of nodes in the mesh | ||
nen = 20 # Number of nodes per element | ||
nloops = 2 * N | ||
all_indexes = [randperm(N)[1:nen] for _ in 1:nloops] | ||
buffnen3 = rand(nen, 3) | ||
buff3nen = rand(3, nen) | ||
dataN3 = rand(N, 3) | ||
data3N = Matrix(transpose(dataN3)) | ||
|
||
t1 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for i in 1:nen | ||
ii = indexes[i] | ||
for j in 1:3 | ||
buffnen3[i, j] = dataN3[ii, j] | ||
end | ||
end | ||
end | ||
|
||
t2 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for j in 1:3 | ||
# alternative to the loop below | ||
# buffnen3[:, j] .= dataN3[indexes, j] # SLOW | ||
@inbounds for i in 1:nen | ||
ii = indexes[i] | ||
buffnen3[i, j] = dataN3[ii, j] | ||
end | ||
end | ||
end | ||
|
||
t3 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for i in 1:nen | ||
ii = indexes[i] | ||
for j in 1:3 | ||
buff3nen[j, i] = dataN3[ii, j] | ||
end | ||
end | ||
end | ||
|
||
t4 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for j in 1:3 | ||
for i in 1:nen | ||
ii = indexes[i] | ||
buff3nen[j, i] = dataN3[ii, j] | ||
end | ||
end | ||
end | ||
|
||
|
||
t5 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for i in 1:nen | ||
ii = indexes[i] | ||
for j in 1:3 | ||
buffnen3[i, j] = data3N[j, ii] | ||
end | ||
end | ||
end | ||
|
||
t6 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for j in 1:3 | ||
for i in 1:nen | ||
ii = indexes[i] | ||
buffnen3[i, j] = data3N[j, ii] | ||
end | ||
end | ||
end | ||
|
||
t7 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for i in 1:nen | ||
ii = indexes[i] | ||
for j in 1:3 | ||
buff3nen[j, i] = data3N[j, ii] | ||
end | ||
end | ||
end | ||
|
||
t8 = @elapsed for l = 1:nloops | ||
indexes = view(all_indexes, l)[1] | ||
@inbounds for j in 1:3 | ||
for i in 1:nen | ||
ii = indexes[i] | ||
buff3nen[j, i] = data3N[j, ii] | ||
end | ||
end | ||
end | ||
|
||
[t1, t2, t3, t4, t5, t6, t7, t8] ./ nloops .* 1e6 # In microseconds | ||
end | ||
end | ||
using Main.mgather1 | ||
ts = [0.0 for i in 1:8] | ||
ntries = 10 | ||
for i in 1:ntries | ||
@info "Try $i" | ||
ts .+= mgather1.test() | ||
end | ||
ts ./= ntries | ||
ts = Float32.(ts) | ||
|
||
println("Mesh data N x 3, Element buffer nen x 3, Loop i, j: Time $(ts[1]) [mus]") | ||
println("Mesh data N x 3, Element buffer nen x 3, Loop j, i: Time $(ts[2]) [mus]") | ||
println("Mesh data N x 3, Element buffer 3 x nen, Loop i, j: Time $(ts[3]) [mus]") | ||
println("Mesh data N x 3, Element buffer 3 x nen, Loop j, i: Time $(ts[4]) [mus]") | ||
println("Mesh data 3 x N, Element buffer nen x 3, Loop i, j: Time $(ts[5]) [mus]") | ||
println("Mesh data 3 x N, Element buffer nen x 3, Loop j, i: Time $(ts[6]) [mus]") | ||
println("Mesh data 3 x N, Element buffer 3 x nen, Loop i, j: Time $(ts[7]) [mus]") | ||
println("Mesh data 3 x N, Element buffer 3 x nen, Loop j, i: Time $(ts[8]) [mus]") |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module mwe_tasks_2 | ||
using Base.Threads | ||
function work(r) | ||
s = 0.0 | ||
for j in r | ||
s = s + exp(-(j - minimum(r))^2 / (maximum(r) - minimum(r))^2) | ||
end | ||
s | ||
end | ||
function test(nchunks = 2) | ||
# @info "nchunks = $(nchunks)" | ||
# @info "nthreads.((:default, :interactive)) = $(Threads.nthreads.((:default, :interactive)))" | ||
# @info "maxthreadid = $(Threads.maxthreadid())" | ||
# @info "threadpool.(1:Threads.maxthreadid()) = $(threadpool.(1:Threads.maxthreadid()))" | ||
# @info "Threads.threadpoolsize.((:default, :interactive)) = $(Threads.threadpoolsize.((:default, :interactive)))" | ||
N = 200000000 | ||
chincr = N / nchunks | ||
@assert nchunks * chincr == N | ||
chunks = [(((i-1)*chincr+1:i*chincr), i) for i = 1:nchunks] | ||
|
||
s = Float64[] | ||
start = time() | ||
Threads.@sync begin | ||
for ch in chunks | ||
Threads.@spawn let r = $ch[1], i = $ch[2] | ||
# @info "Chunk $(i), thread $(threadid()), $(Threads.threadpool(threadid())): Spawned $(time() - start)" | ||
push!(s, work(r)) | ||
# @info "$(i): Finished $(time() - start)" | ||
end | ||
end | ||
end | ||
# @info "Finished $(time() - start)" | ||
# @show s | ||
end | ||
end | ||
using Main.mwe_tasks_2; | ||
mwe_tasks_2.test() | ||
ts = [] | ||
for n = 1:10 | ||
push!(ts, @elapsed mwe_tasks_2.test()) | ||
end | ||
@show extrema(ts) |