Skip to content

Commit 8d031cf

Browse files
committed
tests and bugfixes
1 parent 4fa4d32 commit 8d031cf

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Build Status](https://travis-ci.com/jishnub/ParallelUtilities.jl.svg?branch=master)](https://travis-ci.com/jishnub/ParallelUtilities.jl)
44
[![Coverage Status](https://coveralls.io/repos/github/jishnub/ParallelUtilities.jl/badge.svg?branch=master)](https://coveralls.io/github/jishnub/ParallelUtilities.jl?branch=master)
5+
[![codecov](https://codecov.io/gh/jishnub/ParallelUtilities.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jishnub/ParallelUtilities.jl)
56

67
Parallel mapreduce and other helpful functions for HPC, meant primarily for embarassingly parallel operations that often require one to split up a list of tasks into subsections that can be processed on individual cores.
78

src/ParallelUtilities.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,13 @@ function pmapreduce(fmap::Function,freduce::Function,iterable::Tuple,args...;kwa
675675

676676
nprocs_node_dict = nprocs_node(procs_used)
677677
node_channels = Dict(
678-
node=>RemoteChannel(()->Channel{Any}(nprocs_node_dict[node]),procid_node)
678+
node=>RemoteChannel(()->Channel{pval}(nprocs_node_dict[node]),procid_node)
679679
for (node,procid_node) in zip(nodes,procid_rank1_on_node))
680680

681681
# Worker at which the final reduction takes place
682682
p_final = first(procid_rank1_on_node)
683683

684-
finalnode_reducechannel = RemoteChannel(()->Channel{Any}(length(procid_rank1_on_node)),p_final)
684+
finalnode_reducechannel = RemoteChannel(()->Channel{pval}(length(procid_rank1_on_node)),p_final)
685685

686686
result_channel = RemoteChannel(()->Channel{Any}(1))
687687

@@ -761,10 +761,12 @@ end
761761
# pmap in batches without reduction
762762
############################################################################################
763763

764-
function pmapbatch(f::Function,iterable::Tuple,args...;kwargs...)
764+
function pmapbatch(f::Function,iterable::Tuple,args...;
765+
num_workers = nworkersactive(iterable),kwargs...)
766+
765767
procs_used = workersactive(iterable)
766-
num_workers = get(kwargs,:num_workers,length(procs_used))
767-
if num_workers<length(procs_used)
768+
769+
if num_workers < length(procs_used)
768770
procs_used = procs_used[1:num_workers]
769771
end
770772
num_workers = length(procs_used)

test/runtests.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ end
215215
ps = ProductSplit(iters,np,proc_id)
216216
@test whichproc(iters,first(ps),np) === nothing
217217
@test whichproc(iters,nothing,np) === nothing
218+
@test procrange_recast(ps,2) == (0:-1)
218219

219220
iters = (1:1,2:2)
220221
ps = ProductSplit(iters,1,1)
@@ -265,6 +266,20 @@ end
265266
end
266267
end
267268
end
269+
270+
@testset "getindex" begin
271+
for iters in [(1:10,),(1:10,4:6),(1:10,4:6,1:4),(1:2:10,4:1:6)]
272+
for np=1:ntasks(iters),p=1:np
273+
ps = ProductSplit(iters,np,p)
274+
ps_col = collect(ps)
275+
for i in 1:length(ps)
276+
@test ps[i] == ps_col[i]
277+
end
278+
@test_throws ParallelUtilities.BoundsErrorPS ps[0]
279+
@test_throws ParallelUtilities.BoundsErrorPS ps[length(ps)+1]
280+
end
281+
end
282+
end
268283
end
269284

270285
@testset "ReverseLexicographicTuple" begin
@@ -327,6 +342,10 @@ end
327342
itp = Iterators.product(iters...)
328343
@test nworkersactive(itp) == nworkersactive(iters)
329344
@test workersactive(itp) == workersactive(iters)
345+
346+
ps = ProductSplit(iters,2,1)
347+
@test nworkersactive(ps) == nworkersactive(iters)
348+
@test workersactive(ps) == workersactive(iters)
330349
end
331350

332351
@testset "hostnames" begin
@@ -354,6 +373,8 @@ end
354373
@test res == workers()
355374
res = pmapbatch(x->myid(),(iterable,1:1))
356375
@test res == workers()
376+
res = pmapbatch(x->myid(),iterable,num_workers=1)
377+
@test res == workers()[1:1]
357378

358379
iterable = 1:nworkers()-1
359380
res = pmapbatch(x->myid(),iterable)
@@ -373,6 +394,11 @@ end
373394
res = pmapbatch(identity,iterable)
374395
resexp = [ProductSplit((iterable,),nworkersactive(iterable),p) for p=1:nworkersactive(iterable)]
375396
@test res == resexp
397+
398+
iterable = 1:2nworkers()
399+
res = pmapbatch(identity,Iterators.product(iterable))
400+
resexp = [ProductSplit((iterable,),nworkersactive(iterable),p) for p=1:nworkersactive(iterable)]
401+
@test res == resexp
376402
end
377403

378404
@testset "errors" begin

0 commit comments

Comments
 (0)