Skip to content

Commit c976db7

Browse files
committed
hardlink instead of softlink in doc examples
1 parent 41e052f commit c976db7

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

docs/src/examples/pmapreduce.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/src/examples/pmapreduce.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module PMapReduceTiming
2+
3+
using ParallelUtilities
4+
using Distributed
5+
6+
function initialize(sleeptime)
7+
A = Array{Int}(undef, 20, 20)
8+
for ind in eachindex(A)
9+
sleep(sleeptime)
10+
A[ind] = ind
11+
end
12+
return A
13+
end
14+
15+
function main_mapreduce(sleeptime)
16+
mapreduce(x -> initialize(sleeptime), hcat, 1:20)
17+
end
18+
19+
function main_pmapreduce(sleeptime)
20+
pmapreduce(x -> initialize(sleeptime), hcat, 1:20)
21+
end
22+
23+
function compare_with_serial()
24+
# precompile
25+
main_mapreduce(0)
26+
main_pmapreduce(0)
27+
28+
# time
29+
println("Tesing serial")
30+
A = @time main_mapreduce(5e-6)
31+
println("Tesing parallel")
32+
B = @time main_pmapreduce(5e-6)
33+
34+
# check results
35+
println("Results match : ", A == B)
36+
end
37+
38+
end

docs/src/examples/sharedarrays.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/src/examples/sharedarrays.jl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module SharedArraysTiming
2+
3+
using ParallelUtilities
4+
using SharedArrays
5+
using Distributed
6+
7+
function initialize_localpart(s, sleeptime)
8+
for ind in localindices(s)
9+
sleep(sleeptime)
10+
s[ind] = ind
11+
end
12+
end
13+
14+
function initializenode_sharedarray(sleeptime)
15+
pids = ParallelUtilities.workers_myhost()
16+
s = SharedArray{Int}((2_000,), pids = pids)
17+
@sync for p in pids
18+
@spawnat p initialize_localpart(s, sleeptime)
19+
end
20+
return sdata(s)
21+
end
22+
23+
function initialize_serial(sleeptime)
24+
pids = ParallelUtilities.workers_myhost()
25+
s = Array{Int}(undef, 2_000)
26+
for ind in eachindex(s)
27+
sleep(sleeptime)
28+
s[ind] = ind
29+
end
30+
return sdata(s)
31+
end
32+
33+
function main_sharedarray(sleeptime)
34+
workers_node_pool = ParallelUtilities.workerpool_nodes()
35+
nw_node = nworkers(workers_node_pool)
36+
pmapreduce(x -> initializenode_sharedarray(sleeptime), hcat, workers_node_pool, 1:nw_node)
37+
end
38+
39+
function main_serial(sleeptime)
40+
workers_node_pool = ParallelUtilities.workerpool_nodes()
41+
nw_node = nworkers(workers_node_pool)
42+
mapreduce(x -> initialize_serial(sleeptime), hcat, 1:nw_node)
43+
end
44+
45+
function compare_with_serial()
46+
# precompile
47+
main_serial(0)
48+
main_sharedarray(0)
49+
# time
50+
println("Testing serial")
51+
A = @time main_serial(5e-3)
52+
println("Testing sharedarray")
53+
B = @time main_sharedarray(5e-3)
54+
55+
println("Results match : ", A == B)
56+
end
57+
58+
end

docs/src/examples/threads.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/src/examples/threads.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module ThreadsTiming
2+
3+
using ParallelUtilities
4+
using Distributed
5+
6+
function initialize_serial(sleeptime)
7+
s = zeros(Int, 2_000)
8+
for ind in eachindex(s)
9+
sleep(sleeptime)
10+
s[ind] = ind
11+
end
12+
return s
13+
end
14+
15+
function initializenode_threads(sleeptime)
16+
s = zeros(Int, 2_000)
17+
Threads.@threads for ind in eachindex(s)
18+
sleep(sleeptime)
19+
s[ind] = ind
20+
end
21+
return s
22+
end
23+
24+
function main_threads(sleeptime)
25+
workers_node_pool = ParallelUtilities.workerpool_nodes()
26+
nw_nodes = nworkers(workers_node_pool)
27+
pmapreduce(x -> initializenode_threads(sleeptime), hcat, workers_node_pool, 1:nw_nodes)
28+
end
29+
30+
function main_serial(sleeptime)
31+
workers_node_pool = ParallelUtilities.workerpool_nodes()
32+
nw_nodes = nworkers(workers_node_pool)
33+
mapreduce(x -> initialize_serial(sleeptime), hcat, 1:nw_nodes)
34+
end
35+
36+
function compare_with_serial()
37+
# precompile
38+
main_serial(0)
39+
main_threads(0)
40+
# time
41+
println("Testing serial")
42+
A = @time main_serial(5e-3);
43+
println("Testing threads")
44+
B = @time main_threads(5e-3);
45+
46+
println("Results match : ", A == B)
47+
end
48+
49+
end

0 commit comments

Comments
 (0)