Skip to content

Commit cea2f2c

Browse files
committed
timed pmapsum
1 parent 55f50d0 commit cea2f2c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ version = "0.1.1"
66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
88
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
9+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

src/ParallelUtilities.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module ParallelUtilities
22

3-
using Reexport
3+
using Reexport,TimerOutputs
44
@reexport using Distributed
55

66
export split_across_processors,split_product_across_processors,
77
get_processor_id_from_split_array,procid_allmodes,mode_index_in_file,
88
get_processor_range_from_split_array,workers_active,nworkers_active,worker_rank,
99
get_index_in_split_array,procid_and_mode_index,extrema_from_split_array,
10-
pmapsum,sum_at_node,pmap_onebatch_per_worker,moderanges_common_lastarray,
10+
pmapsum,pmapsum_timed,sum_at_node,pmap_onebatch_per_worker,moderanges_common_lastarray,
1111
get_nodes,get_hostnames,get_nprocs_node
1212

1313
function worker_rank()
@@ -250,10 +250,32 @@ function pmapsum(f::Function,iterable,args...;kwargs...)
250250
end
251251
return s
252252
end
253-
254253
@fetchfrom first(procs_used) final_sum(futures)
255254
end
256255

256+
function pmapsum_timed(f::Function,iterable,args...;kwargs...)
257+
258+
procs_used = workers_active(iterable)
259+
260+
futures = pmap_onebatch_per_worker(f,iterable,args...;kwargs...)
261+
262+
timer = TimerOutput()
263+
function final_sum(futures,timer)
264+
@timeit timer "fetch" s = fetch(first(futures))
265+
@sync for f in futures[2:end]
266+
@async begin
267+
@timeit timer "fetch" t_i = fetch(f)
268+
s += t_i
269+
end
270+
end
271+
return s,timer
272+
end
273+
274+
s,timer = @fetchfrom first(procs_used) final_sum(futures,timer)
275+
println(timer)
276+
return s
277+
end
278+
257279
function pmap_onebatch_per_worker(f::Function,iterable,args...;kwargs...)
258280

259281
procs_used = workers_active(iterable)

0 commit comments

Comments
 (0)