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 for GreedyScheduler in tests #80

Merged
merged 1 commit into from
Mar 13, 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
3 changes: 0 additions & 3 deletions src/implementation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,6 @@ end
_Arrs::AbstractArray...;
scheduler::Scheduler = DynamicScheduler(),
kwargs...)
if hasfield(typeof(scheduler), :split) && scheduler.split != :batch
error("Only `split == :batch` is supported because the parallel operation isn't commutative. (Scheduler: $scheduler)")
end
Arrs = (A, _Arrs...)
if scheduler isa SerialScheduler
map!(f, out, Arrs...; kwargs...)
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Test, OhMyThreads
using OhMyThreads: TaskLocalValue, WithTaskLocals, @fetch, promise_task_local



sets_to_test = [(~ = isapprox, f = sin ∘ *, op = +,
itrs = (rand(ComplexF64, 10, 10), rand(-10:10, 10, 10)),
init = complex(0.0))
Expand All @@ -12,11 +10,13 @@ sets_to_test = [(~ = isapprox, f = sin ∘ *, op = +,
itrs = ([1 => "a", 2 => "b", 3 => "c", 4 => "d", 5 => "e"],),
init = "")]

ChunkedGreedy(;kwargs...) = GreedyScheduler(;kwargs...)

@testset "Basics" begin
for (; ~, f, op, itrs, init) in sets_to_test
@testset "f=$f, op=$op, itrs::$(typeof(itrs))" begin
@testset for sched in (
StaticScheduler, DynamicScheduler, GreedyScheduler, DynamicScheduler{OhMyThreads.Schedulers.NoChunking}, SerialScheduler)
StaticScheduler, DynamicScheduler, GreedyScheduler, DynamicScheduler{OhMyThreads.Schedulers.NoChunking}, SerialScheduler, ChunkedGreedy)
@testset for split in (:batch, :scatter)
for nchunks in (1, 2, 6)
if sched == GreedyScheduler
Expand All @@ -30,7 +30,7 @@ sets_to_test = [(~ = isapprox, f = sin ∘ *, op = +,
end

kwargs = (; scheduler)
if (split == :scatter || sched == GreedyScheduler) || op ∉ (vcat, *)
if (split == :scatter || sched ∈ (GreedyScheduler, ChunkedGreedy)) || op ∉ (vcat, *)
# scatter and greedy only works for commutative operators!
else
mapreduce_f_op_itr = mapreduce(f, op, itrs...)
Expand All @@ -51,7 +51,7 @@ sets_to_test = [(~ = isapprox, f = sin ∘ *, op = +,
@test tcollect(RT, (f(x...) for x in collect(zip(itrs...))); kwargs...) ~ map_f_itr
@test tcollect(RT, f.(itrs...); kwargs...) ~ map_f_itr

if sched !== GreedyScheduler
if sched ∉ (GreedyScheduler, ChunkedGreedy)
@test tmap(f, itrs...; kwargs...) ~ map_f_itr
@test tcollect((f(x...) for x in collect(zip(itrs...))); kwargs...) ~ map_f_itr
@test tcollect(f.(itrs...); kwargs...) ~ map_f_itr
Expand Down
Loading