Skip to content

Commit

Permalink
nthreads() -> nthreads(threadpool)
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Feb 8, 2024
1 parent cc7a8f6 commit 51c0db9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 0.4.0
-------------

- ![BREAKING][badge-breaking] Instead of taking keyword arguments `schedule`, `nchunks`, `split` directly, we now use `Scheduler` structs to specify scheduling options ([#22](https://github.com/JuliaFolds2/OhMyThreads.jl/issues/22)). The latter can be provided to all API functions via the new `scheduler` keyword argument.
- ![BREAKING][badge-breaking] The default scheduler (`DynamicScheduler`) now, by default, creates `2*nthreads()` tasks to provide load-balancing by default. The old behavior can be restored with `DynamicScheduler(nchunks=nthreads())`.
- ![Enhancement][badge-enhancement] We reject unsupported keyword arguments early and give a more helpful error message.

Version 0.3.1
Expand Down
10 changes: 5 additions & 5 deletions src/schedulers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ with other multithreaded code.
## Keyword arguments:
- `nchunks::Int` (default `2 * nthreads()`):
- `nchunks::Int` (default `2 * nthreads(threadpool)`):
* Determines the number of chunks (and thus also the number of parallel tasks).
* Increasing `nchunks` can help with [load balancing](https://en.wikipedia.org/wiki/Load_balancing_(computing)), but at the expense of creating more overhead. For `nchunks <= nthreads()` there are not enough chunks for any load balancing.
* Setting `nchunks < nthreads()` is an effective way to use only a subset of the available threads.
Expand All @@ -34,14 +34,14 @@ with other multithreaded code.
* The high-priority pool `:interactive` should be used very carefully since tasks on this threadpool should not be allowed to run for a long time without `yield`ing as it can interfere with [heartbeat](https://en.wikipedia.org/wiki/Heartbeat_(computing)) processes.
"""
Base.@kwdef struct DynamicScheduler <: Scheduler
nchunks::Int = 2 * nthreads() # a multiple of nthreads to enable load balancing
split::Symbol = :batch
threadpool::Symbol = :default
nchunks::Int = 2 * nthreads(threadpool) # a multiple of nthreads to enable load balancing
split::Symbol = :batch

function DynamicScheduler(nchunks::Int, split::Symbol, threadpool::Symbol)
nchunks > 0 || throw(ArgumentError("nchunks must be a positive integer"))
function DynamicScheduler(threadpool::Symbol, nchunks::Int, split::Symbol)
threadpool in (:default, :interactive) ||
throw(ArgumentError("threadpool must be either :default or :interactive"))
nchunks > 0 || throw(ArgumentError("nchunks must be a positive integer"))
new(nchunks, split, threadpool)
end
end
Expand Down

0 comments on commit 51c0db9

Please sign in to comment.