Skip to content

Commit

Permalink
Firming up multiarg variants and revving version
Browse files Browse the repository at this point in the history
  • Loading branch information
tro3 committed Jul 19, 2020
1 parent 068ea5c commit 39241f1
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ThreadPools"
uuid = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"
authors = ["Trey Roessig <[email protected]"]
version = "1.1.1"
version = "1.1.2"

[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand Down
14 changes: 7 additions & 7 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ julia> pool = pwith(ThreadPools.LoggedQueuePool(1,2)) do pool
julia> plot(pool)
```
"""
function tforeach(pool, fn::Function, itr)
function tforeach(pool::AbstractThreadPool, fn::Function, itr)
tmap(pool, fn, itr)
nothing
end

tforeach(fn::Function, pool, itr) = tforeach(pool, fn, itr)
#tforeach(pool, fn::Function, itrs...) = tforeach(pool, (x) -> fn(x...), zip(itrs...))
#tforeach(fn::Function, pool, itrs...) = tforeach(pool, (x) -> fn(x...), zip(itrs...))
tforeach(fn::Function, pool::AbstractThreadPool, itr) = tforeach(pool, fn, itr)
tforeach(pool::AbstractThreadPool, fn::Function, itr1, itrs...) = tforeach(pool, x -> fn(x...), zip(itr1, itrs...))
tforeach(fn::Function, pool::AbstractThreadPool, itr1, itrs...) = tforeach(pool, x -> fn(x...), zip(itr1, itrs...))


"""
Expand Down Expand Up @@ -74,9 +74,9 @@ julia> pool = pwith(ThreadPools.LoggedQueuePool(1,2)) do pool
julia> plot(pool)
```
"""
tmap(fn::Function, pool, itr) = tmap(pool, fn, itr)
# tmap(pool, fn::Function, itrs...) = tmap(pool, (x) -> fn(x...), zip(itrs...))
# tmap(fn::Function, pool, itrs...) = tmap(pool, (x) -> fn(x...), zip(itrs...))
tmap(fn::Function, pool::AbstractThreadPool, itr) = tmap(pool, fn, itr)
tmap(pool::AbstractThreadPool, fn::Function, itr1, itrs...) = tmap(pool, x -> fn(x...), zip(itr1, itrs...))
tmap(fn::Function, pool::AbstractThreadPool, itr1, itrs...) = tmap(pool, x -> fn(x...), zip(itr1, itrs...))


"""
Expand Down
2 changes: 1 addition & 1 deletion src/logqpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ results(pool::LoggedQueuePool) = ResultIterator(pool)

function tmap(pool::LoggedQueuePool, fn::Function, itr)
data = collect(itr)
applicable(fn, data[1]) || error("function can't be applied to iterator contents")
applicable(fn, first(data)) || error("function can't be applied to iterator contents")
N = length(data)
sizehint!(pool.recs, N)
result = Array{_detect_type(fn, data), ndims(data)}(undef, size(data))
Expand Down
2 changes: 1 addition & 1 deletion src/logstaticpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end

function tmap(pool::LoggedStaticPool, fn::Function, itr)
data = collect(itr)
applicable(fn, data[1]) || error("function can't be applied to iterator contents")
applicable(fn, first(data)) || error("function can't be applied to iterator contents")
N = length(data)
sizehint!(pool.recs, N)
result = Array{_detect_type(fn, data), ndims(data)}(undef, size(data))
Expand Down
2 changes: 1 addition & 1 deletion src/qpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Base.IteratorEltype(::ResultIterator) = Base.EltypeUnknown()

function tmap(pool::QueuePool, fn::Function, itr)
data = collect(itr)
applicable(fn, data[1]) || error("function can't be applied to iterator contents")
applicable(fn, first(data)) || error("function can't be applied to iterator contents")
N = length(data)
result = Array{_detect_type(fn, data), ndims(data)}(undef, size(data))
_fn = (ind, x) -> (ind, fn(x))
Expand Down
104 changes: 52 additions & 52 deletions src/simplefuncs.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

@deprecate pmap(fn::Function, itr) tmap(fn::Function, itr)
@deprecate pforeach(fn::Function, itr) tforeach(fn::Function, itr)
@deprecate logpmap(fn::Function, itr) logtmap(fn::Function, itr)
@deprecate logpforeach(fn::Function, itr) logtforeach(fn::Function, itr)
@deprecate pmap(fn::Function, itrs...) tmap(fn::Function, itrs...)
@deprecate pforeach(fn::Function, itrs...) tforeach(fn::Function, itrs...)
@deprecate logpmap(fn::Function, itrs...) logtmap(fn::Function, itrs...)
@deprecate logpforeach(fn::Function, itrs...) logtforeach(fn::Function, itrs...)


"""
tmap(fn::Function, itr) -> collection
tmap(fn::Function, itrs...) -> collection
Mimics `Base.map`, but launches the function evaluations onto all available
threads, using a pre-assigned scheduling strategy appropriate for uniform
Expand All @@ -29,15 +29,15 @@ julia> tmap(x -> begin; println((x,Threads.threadid())); x^2; end, 1:8)'
Note that while the execution order is not guaranteed, the result order is.
Also note that the primary thread is used.
"""
function tmap(fn::Function, itr)
function tmap(fn::Function, itrs...)
pool = StaticPool()
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return result
end

"""
bmap(fn::Function, itr) -> collection
bmap(fn::Function, itrs...) -> collection
Mimics `Base.map`, but launches the function evaluations onto all available
threads except the primary, using a pre-assigned scheduling strategy
Expand All @@ -60,15 +60,15 @@ julia> bmap(x -> begin; println((x,Threads.threadid())); x^2; end, 1:8)'
Note that while the execution order is not guaranteed, the result order is,
Also note that the primary thread is not used.
"""
function bmap(fn, itr)
function bmap(fn::Function, itrs...)
pool = StaticPool(2)
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return result
end

"""
qmap(fn::Function, itr) -> collection
qmap(fn::Function, itrs...) -> collection
Mimics `Base.map`, but launches the function evaluations onto all available
threads, using a queued scheduling strategy appropriate for nonuniform
Expand All @@ -91,15 +91,15 @@ julia> qmap(x -> begin; println((x,Threads.threadid())); x^2; end, 1:8)'
Note that while the execution order is not guaranteed, the result order is.
Also note that the primary thread is used.
"""
function qmap(fn, itr)
function qmap(fn::Function, itrs...)
pool = QueuePool()
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return result
end

"""
qbmap(fn::Function, itr) -> collection
qbmap(fn::Function, itrs...) -> collection
Mimics `Base.map`, but launches the function evaluations onto all available
threads except the primary, using a queued scheduling strategy appropriate
Expand All @@ -122,15 +122,15 @@ julia> qbmap(x -> begin; println((x,Threads.threadid())); x^2; end, 1:8)'
Note that while the execution order is not guaranteed, the result order is,
Also note that the primary thread is not used.
"""
function qbmap(fn, itr)
function qbmap(fn::Function, itrs...)
pool = QueuePool(2)
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return result
end

"""
logtmap(fn::Function, itr) -> (pool, collection)
logtmap(fn::Function, itrs...) -> (pool, collection)
Mimics `Base.map`, but launches the function evaluations onto all available
threads, using a pre-assigned scheduling strategy appropriate for uniform
Expand Down Expand Up @@ -161,15 +161,15 @@ julia> plot(pool)
Note that while the execution order is not guaranteed, the result order is.
Also note that the primary thread is used.
"""
function logtmap(fn::Function, itr)
function logtmap(fn::Function, itrs...)
pool = LoggedStaticPool()
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool, result
end

"""
logbmap(fn::Function, itr) -> (pool, collection)
logbmap(fn::Function, itrs...) -> (pool, collection)
Mimics `Base.map`, but launches the function evaluations onto all available
threads except the primary, using a pre-assigned scheduling strategy
Expand Down Expand Up @@ -200,15 +200,15 @@ julia> plot(pool)
Note that while the execution order is not guaranteed, the result order is,
Also note that the primary thread is not used.
"""
function logbmap(fn, itr)
function logbmap(fn::Function, itrs...)
pool = LoggedStaticPool(2)
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool, result
end

"""
logqmap(fn::Function, itr) -> (pool, collection)
logqmap(fn::Function, itrs...) -> (pool, collection)
Mimics `Base.map`, but launches the function evaluations onto all available
threads, using a queued scheduling strategy appropriate for nonuniform
Expand Down Expand Up @@ -239,15 +239,15 @@ julia> plot(pool)
Note that while the execution order is not guaranteed, the result order is.
Also note that the primary thread is used.
"""
function logqmap(fn, itr)
function logqmap(fn::Function, itrs...)
pool = LoggedQueuePool()
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool, result
end

"""
logqbmap(fn::Function, itr) -> (pool, collection)
logqbmap(fn::Function, itrs...) -> (pool, collection)
Mimics `Base.map`, but launches the function evaluations onto all available
threads except the primary, using a queued scheduling strategy appropriate
Expand Down Expand Up @@ -278,16 +278,16 @@ julia> plot(pool)
Note that while the execution order is not guaranteed, the result order is,
Also note that the primary thread is not used.
"""
function logqbmap(fn, itr)
function logqbmap(fn::Function, itrs...)
pool = LoggedQueuePool(2)
result::Array{_detect_type(fn, itr), ndims(itr)} = tmap(pool, fn, itr)
result = tmap(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool, result
end


"""
tforeach(fn::Function, itr)
tforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads, using a pre-assigned scheduling strategy appropriate for uniform
Expand All @@ -308,16 +308,16 @@ julia> tforeach(x -> println((x,Threads.threadid())), 1:8)
Note that the execution order is not guaranteed, and that the primary thread
is used.
"""
function tforeach(fn::Function, itr)
function tforeach(fn::Function, itrs...)
pool = StaticPool()
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
nothing
end


"""
bforeach(fn::Function, itr)
bforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads except the primary, using a pre-assigned scheduling strategy appropriate
Expand All @@ -338,15 +338,15 @@ julia> bforeach(x -> println((x,Threads.threadid())), 1:8)
Note that the execution order is not guaranteed, and that the primary thread
is not used.
"""
function bforeach(fn, itr)
function bforeach(fn::Function, itrs...)
pool = StaticPool(2)
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
nothing
end

"""
qforeach(fn::Function, itr)
qforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads, using a queued scheduling strategy appropriate for nonuniform
Expand All @@ -367,16 +367,16 @@ julia> qforeach(x -> println((x,Threads.threadid())), 1:8)
Note that the execution order is not guaranteed, and that the primary thread
is used.
"""
function qforeach(fn, itr)
function qforeach(fn::Function, itrs...)
pool = QueuePool()
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
nothing
end


"""
qbforeach(fn::Function, itr)
qbforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads except the primary, using a queued scheduling strategy appropriate for
Expand All @@ -397,17 +397,17 @@ julia> qbforeach(x -> println((x,Threads.threadid())), 1:8)
Note that the execution order is not guaranteed, and that the primary thread
is not used.
"""
function qbforeach(fn, itr)
function qbforeach(fn::Function, itrs...)
pool = QueuePool(2)
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
nothing
end



"""
logtforeach(fn::Function, itr) -> pool
logtforeach(fn::Function, itrs...) -> pool
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads, using a pre-assigned scheduling strategy appropriate for uniform
Expand All @@ -431,16 +431,16 @@ julia> plot(pool)
Note that the execution order is not guaranteed, and that the primary thread
is used.
"""
function logtforeach(fn::Function, itr)
function logtforeach(fn::Function, itrs...)
pool = LoggedStaticPool()
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool
end


"""
logbforeach(fn::Function, itr)
logbforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads except the primary, using a pre-assigned scheduling strategy appropriate
Expand All @@ -464,16 +464,16 @@ julia> plot(pool)
Note that the execution order is not guaranteed, and that the primary thread
is not used.
"""
function logbforeach(fn, itr)
function logbforeach(fn::Function, itrs...)
pool = LoggedStaticPool(2)
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool
end


"""
logqforeach(fn::Function, itr)
logqforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads, using a queued scheduling strategy appropriate for nonuniform
Expand All @@ -497,16 +497,16 @@ Note that the execution order is not guaranteed, and that the primary thread
is used. Returns a logged pool that can be analyzed with the logging functions
and `plot`ted.
"""
function logqforeach(fn, itr)
function logqforeach(fn::Function, itrs...)
pool = LoggedQueuePool()
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool
end


"""
logqbforeach(fn::Function, itr)
logqbforeach(fn::Function, itrs...)
Mimics `Base.foreach`, but launches the function evaluations onto all available
threads except the primary, using a queued scheduling strategy appropriate for
Expand All @@ -530,9 +530,9 @@ julia> plot(pool)
Note that the execution order is not guaranteed, and that the primary thread
is not used.
"""
function logqbforeach(fn, itr)
function logqbforeach(fn::Function, itrs...)
pool = LoggedQueuePool(2)
tforeach(pool, fn, itr)
tforeach(pool, x->fn(x...), zip(itrs...))
close(pool)
return pool
end
2 changes: 1 addition & 1 deletion src/staticpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

function tmap(pool::StaticPool, fn::Function, itr)
data = collect(itr)
applicable(fn, data[1]) || error("function can't be applied to iterator contents")
applicable(fn, first(data)) || error("function can't be applied to iterator contents")
N = length(data)
result = Array{_detect_type(fn, data), ndims(data)}(undef, size(data))
nthrds = length(pool.tids)
Expand Down
Loading

2 comments on commit 39241f1

@tro3
Copy link
Owner Author

@tro3 tro3 commented on 39241f1 Jul 19, 2020

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/18148

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 v1.1.2 -m "<description of version>" 39241f119a28e79f456ce7cfea0466551c9e1b11
git push origin v1.1.2

Please sign in to comment.