Skip to content

Commit d42d93c

Browse files
rewrite schedulers (#135)
* rewrite schedulers * Add tests for chunking mode and show(::Scheduler) * replace has_field(typeof(_scheduler), :split) to has_split(_scheduler) * fix test typo --------- Co-authored-by: Mason Protter <[email protected]>
1 parent fd3ac58 commit d42d93c

File tree

3 files changed

+216
-172
lines changed

3 files changed

+216
-172
lines changed

src/implementation.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using OhMyThreads: Scheduler,
77
DynamicScheduler, StaticScheduler, GreedyScheduler,
88
SerialScheduler
99
using OhMyThreads.Schedulers: chunking_enabled,
10+
nchunks, chunksize, chunksplit, has_chunksplit,
1011
chunking_mode, ChunkingMode, NoChunking,
1112
FixedSize, FixedCount, scheduler_from_symbol, NotGiven,
1213
isgiven
@@ -25,13 +26,13 @@ function _index_chunks(sched, arg)
2526
@assert C != NoChunking
2627
if C == FixedCount
2728
index_chunks(arg;
28-
n = sched.nchunks,
29-
split = sched.split)::IndexChunks{
29+
n = nchunks(sched),
30+
split = chunksplit(sched))::IndexChunks{
3031
typeof(arg), ChunkSplitters.Internals.FixedCount}
3132
elseif C == FixedSize
3233
index_chunks(arg;
33-
size = sched.chunksize,
34-
split = sched.split)::IndexChunks{
34+
size = chunksize(sched),
35+
split = chunksplit(sched))::IndexChunks{
3536
typeof(arg), ChunkSplitters.Internals.FixedSize}
3637
end
3738
end
@@ -50,9 +51,9 @@ end
5051
function _check_chunks_incompatible_kwargs(; kwargs...)
5152
ks = keys(kwargs)
5253
if :ntasks in ks || :nchunks in ks || :chunksize in ks || :split in ks
53-
error("You've provided `chunks` or `index_chunks` as input and, at the same time, "*
54-
"chunking related keyword arguments (e.g. `ntasks`, `chunksize`, or `split`). "*
55-
"This isn't supported. "*
54+
error("You've provided `chunks` or `index_chunks` as input and, at the same time, " *
55+
"chunking related keyword arguments (e.g. `ntasks`, `chunksize`, or `split`). " *
56+
"This isn't supported. " *
5657
"Set the chunking options directly in the `chunks` or `index_chunks` call or drop the latter.")
5758
end
5859
if :chunking in ks
@@ -398,8 +399,8 @@ function tmap(f,
398399
if _scheduler isa GreedyScheduler
399400
error("Greedy scheduler isn't supported with `tmap` unless you provide an `OutputElementType` argument, since the greedy schedule requires a commutative reducing operator.")
400401
end
401-
if chunking_enabled(_scheduler) && hasfield(typeof(_scheduler), :split) &&
402-
_scheduler.split != Consecutive()
402+
if chunking_enabled(_scheduler) && has_chunksplit(_scheduler) &&
403+
chunksplit(_scheduler) != Consecutive()
403404
error("Only `split == Consecutive()` is supported because the parallel operation isn't commutative. (Scheduler: $_scheduler)")
404405
end
405406
if (A isa AbstractChunks || A isa ChunkSplitters.Internals.Enumerate)

0 commit comments

Comments
 (0)