Skip to content

Commit

Permalink
Add SegmentedOrderedBinaryTrees (#1)
Browse files Browse the repository at this point in the history
* Implement SegmentedOrderedBinaryTree

Asynchronous createbranchchannel for OrderedBinaryTree
Remove type specialization in createbranchchannels

* add tests

* Asynchronous remote tests
  • Loading branch information
jishnub committed May 30, 2020
1 parent 0c9626c commit c398221
Show file tree
Hide file tree
Showing 7 changed files with 2,752 additions and 1,957 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ParallelUtilities"
uuid = "fad6cfc8-4f83-11e9-06cc-151124046ad0"
authors = ["Jishnu Bhattacharya <jishnuonline@gmail.com>"]
version = "0.7.1"
version = "0.7.2"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
2 changes: 1 addition & 1 deletion src/errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct ProcessorNumberError <: Exception
np :: Int
end
function Base.showerror(io::IO,err::ProcessorNumberError)
print(io,"processor id $(err.p) does not line in the range $(1:err.np)")
print(io,"processor id $(err.p) does not lie in the range $(1:err.np)")
end

struct DecreasingIteratorError <: Exception
Expand Down
39 changes: 26 additions & 13 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,33 @@ function reducedvalue(freduce::Function,rank,

N = nchildren(pipe)
leftchild = N > 0
vals = Vector{Tred}(undef,N+1)
selfvalpresent = rank > 0
vals = Vector{Tred}(undef,N + selfvalpresent)
@sync begin
@async begin
selfval = take!(pipe.selfchannels.out)::Tmap
selfvalred = freduce((value(selfval),))
ind = 1 + leftchild
v = pval(rank,selfvalred)
vals[ind] = v
if selfvalpresent
selfval = take!(pipe.selfchannels.out)::Tmap
selfvalred = freduce((value(selfval),))
pv = pval(rank,selfvalred)
ind = selfvalpresent + leftchild
vals[ind] = pv
end
end
@async for i=2:N+1
pv = take!(pipe.childrenchannels.out) :: Tred
shift = pv.rank > rank ? 1 : -1
ind = shift + leftchild + 1
vals[ind] = pv
@async begin
if selfvalpresent
for i=1:N
pv = take!(pipe.childrenchannels.out) :: Tred
shift = pv.rank > rank ? 1 : -1
ind = shift + leftchild + 1
vals[ind] = pv
end
else
for i=1:N
pv = take!(pipe.childrenchannels.out) :: Tred
vals[i] = pv
end
sort!(vals,by=pv->pv.rank)
end
end
end

Expand All @@ -125,7 +138,7 @@ function reduceTreeNode(freduce::Function,rank,pipe::BranchChannel{Tmap,Tred},
anyerr = take!(pipe.selfchannels.err)
else
anyerr = false
end
end
anyerr = anyerr ||
any(take!(pipe.childrenchannels.err) for i=1:nchildren(pipe))

Expand Down Expand Up @@ -542,7 +555,7 @@ function pmapreduce(fmap::Function,Tmap::Type,freduce::Function,Tred::Type,
iterators::Tuple,args...;kwargs...)

tree,branches = createbranchchannels(pval{Tmap},pval{Tred},
iterators,OrderedBinaryTree)
iterators, SegmentedOrderedBinaryTree)
pmapreduceworkers(fmap,freduce,iterators,tree,
branches,Sorted(),args...;kwargs...)
end
Expand Down
Loading

2 comments on commit c398221

@jishnub
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/15649

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.2 -m "<description of version>" c398221e9041ec27558d5d6c412fe1af11a5d54d
git push origin v0.7.2

Please sign in to comment.