Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GreedyScheduler with ntasks and chunksize, closes #120 #122

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/schedulers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ function GreedyScheduler(;
else
# only choose nchunks default if chunksize hasn't been specified
if !isgiven(nchunks) && !isgiven(chunksize)
# neither nchunks nor chunksize has been specified but chunking = true
nchunks = 10 * nthreads(:default)
chunksize = -1
else
nchunks = isgiven(nchunks) ? nchunks :
isgiven(ntasks) ? ntasks : -1
chunksize = isgiven(chunksize) ? chunksize : -1
elseif !isgiven(nchunks)
nchunks = -1
elseif !isgiven(chunksize)
chunksize = -1
end
end
GreedyScheduler(ntasks, nchunks, chunksize, split; chunking)
Expand Down
43 changes: 29 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ end;
end;

@testset "chunking mode + chunksize option" begin
for sched in (DynamicScheduler, StaticScheduler)
for sched in (DynamicScheduler, StaticScheduler, GreedyScheduler)
@test sched() isa sched
@test sched(; chunksize = 2) isa sched

Expand All @@ -328,26 +328,41 @@ end;
OhMyThreads.Schedulers.FixedCount
@test OhMyThreads.Schedulers.chunking_mode(sched(; chunking = false)) ==
OhMyThreads.Schedulers.NoChunking
@test OhMyThreads.Schedulers.chunking_mode(sched(;
nchunks = 2, chunksize = 4, chunking = false)) ==
OhMyThreads.Schedulers.NoChunking
@test OhMyThreads.Schedulers.chunking_mode(sched(;
nchunks = -2, chunksize = -4, split = :whatever, chunking = false)) ==
OhMyThreads.Schedulers.NoChunking
if sched != GreedyScheduler
# For (Dynamic|Static)Scheduler `chunking = false` overrides `nchunks` and
# `chunksize`
@test OhMyThreads.Schedulers.chunking_mode(sched(;
nchunks = 2, chunksize = 4, chunking = false)) ==
OhMyThreads.Schedulers.NoChunking
@test OhMyThreads.Schedulers.chunking_mode(sched(;
nchunks = -2, chunksize = -4, split = :whatever, chunking = false)) ==
OhMyThreads.Schedulers.NoChunking
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
nchunks = -2, chunksize = -4, chunking = false)) == false
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
nchunks = 2, chunksize = 4, chunking = false)) == false
else
# For GreedyScheduler `nchunks` or `chunksize` overrides `chunking = false`
@test OhMyThreads.Schedulers.chunking_mode(sched(;
nchunks = 2, chunking = false)) ==
OhMyThreads.Schedulers.FixedCount
@test OhMyThreads.Schedulers.chunking_mode(sched(;
chunksize = 2, chunking = false)) ==
OhMyThreads.Schedulers.FixedSize
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
nchunks = 2, chunking = false)) == true
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
chunksize = 4, chunking = false)) == true
end
@test OhMyThreads.Schedulers.chunking_enabled(sched(; chunksize = 2)) == true
@test OhMyThreads.Schedulers.chunking_enabled(sched(; nchunks = 2)) == true
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
nchunks = -2, chunksize = -4, chunking = false)) == false
@test OhMyThreads.Schedulers.chunking_enabled(sched(;
nchunks = 2, chunksize = 4, chunking = false)) == false

@test_throws ArgumentError sched(; nchunks = 2, chunksize = 3)
@test_throws ArgumentError sched(; nchunks = 0, chunksize = 0)
@test_throws ArgumentError sched(; nchunks = -2, chunksize = -3)

let scheduler = sched(; chunksize = 2)
let scheduler = sched(; chunksize = 2, split = :batch)
@test tmapreduce(sin, +, 1:10; scheduler) ≈ mapreduce(sin, +, 1:10)
@test tmap(sin, 1:10; scheduler) ≈ map(sin, 1:10)
@test tmap(sin, Float64, 1:10; scheduler) ≈ map(sin, 1:10)
@test isnothing(tforeach(sin, 1:10; scheduler))
@test treduce(+, 1:10; scheduler) ≈ reduce(+, 1:10)
end
Expand Down
Loading