From 51c0db9247ed997b5d53dbd843acda35748bfe5d Mon Sep 17 00:00:00 2001 From: Carsten Bauer Date: Thu, 8 Feb 2024 19:05:47 +0100 Subject: [PATCH] nthreads() -> nthreads(threadpool) --- CHANGELOG.md | 1 + src/schedulers.jl | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74495ea3..a0ec7586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/schedulers.jl b/src/schedulers.jl index 91705e7c..12d69d54 100644 --- a/src/schedulers.jl +++ b/src/schedulers.jl @@ -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. @@ -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