Skip to content

Sched: cheaper placement under uniform execution (sort once per candidate set, no wake-ups of non-stealers, no stale cache entry) - #790

Open
AnnaLena77 wants to merge 3 commits into
JuliaParallel:masterfrom
AnnaLena77:pr/a0b-placement-constants
Open

AnnaLena77 wants to merge 3 commits into
JuliaParallel:masterfrom
AnnaLena77:pr/a0b-placement-constants

Conversation

@AnnaLena77

@AnnaLena77 AnnaLena77 commented Nov 20, 2026 •

Copy link
Copy Markdown

Three small scheduler changes that make placement of unscoped tasks independent of the processor count under MPI. They share a test file, so they are one pull request; each commit can be reviewed alone.

  1. Sort the candidates once per candidate set, not per task. Under a uniform-execution acceleration (MPI) every task re-sorted all candidate processors with a comparison sort whose key formats a short_name string on every comparison, and schedule_one! first built the candidate vector with a quadratic proc in input_procs scan and ran estimate_task_costs!, whose result the uniform selection discards. The keys are now computed once per processor, the canonical order is cached next to the compatible set, and only the per-task part (owner preference, thunk-id rotation) is computed per task. The resulting order is identical to the old algorithm's, which uniformity across ranks depends on: test/uniform-placement.jl compares it with a copy of the old implementation on randomized candidate sets (5 770 assertions).
  2. Do not wake processors that cannot steal when a task is enqueued. do_tasks kicks every other processor of the scheduler to make it try to steal. A runner whose processor may not steal (stealing_permitted false, i.e. every MPIProcessor) woke up, found that out and went back to sleep: 256 wake-ups per task at 256 processors. Skipping them cannot change which task runs where.
  3. Replace a stale compatible-processor cache entry instead of keeping it. compat_entry used BasicLFUCache.get!, which returns the existing value for a present key. After the processor list changed without a cache flush, every later lookup missed and recomputed, and the stale entry stayed: unscoped tasks became 5.3x slower with 10x the allocations in a suite that registers processors mid-run.

Measured with the task-overhead suite (see #788 ), 4 ranks x 16 threads per node (AMD Opteron 6272), Open MPI, Julia 1.13, median of 7, unscoped spawn of 64 tasks:

processors before after
64 (1 node) 244.3 ms 11.7 ms
128 (2 nodes) 547.2 ms 12.2 ms
256 (4 nodes) 1257.9 ms 14.0 ms

The wake-up change alone (1 / 2 / 4 nodes) takes unscoped spawns from 11.0 / 12.8 / 15.9 ms to 7.3 / 9.8 / 10.4 ms and cuts allocations by 20-65 %; all 27 benchmark/size cells are faster or equal. Pinned (ExactScope) tasks have a single candidate and are within noise. This is the placement cost reported in #771 (about 85 ms per task at 832 processors).

On a laptop (Julia 1.13, 4 threads, 1 worker) the Allocations, Thunk, Scheduler, Processors, Uniform Placement and Options suites pass; no failures.

AI disclosure: I prepared this change with the help of Claude (Anthropic) and reviewed it myself.
🤖 Generated with Claude Code

…per task

Under a uniform-execution acceleration (MPI) every task re-sorted all of its
candidate processors with a comparison sort whose key (processor_order_key)
formats a short_name string on every comparison, and schedule_one! first
built the candidate vector with a quadratic 'proc in input_procs' scan and
ran estimate_task_costs!, whose result the uniform selection discards.
Unscoped @Spawn therefore cost O(P log P) string constructions per task and
grew with the processor count: ~85 ms/task at 832 processors (see JuliaParallel#771).

* sort_processors_canonical!: compute the keys once per processor, then sortperm.
* compatible_processors_ordered: cache the canonical order of a candidate set
  next to the compatible set (CompatEntry), so it is built once per set.
* place_processors_uniform!: the per-task part only -- owner preference
  (binary search over the owner-sorted canonical order, three in-place
  reversals) and the thunk-id rotation. No scratch, no per-candidate boxing.
* schedule_one!: under uniform execution start from the cached order and skip
  estimate_task_costs!; otherwise drop the redundant quadratic membership
  scan (the candidates come from a Set).
* select_processors_uniform! keeps its contract (Datadeps and proc grids call
  it) and is now sort_processors_canonical! + place_processors_uniform!.

The resulting order is identical to the old algorithm's, which uniformity
across ranks depends on: test/uniform-placement.jl compares it against a copy
of the old implementation on randomized candidate sets (partial scopes, absent
preferred ranks, all rotations; 5770 assertions) and test/mpi/spawn.jl still
passes (2 ranks x 2 threads).

Measured with the new benchmark/suites/tasks.jl (suite 'tasks', ntasks=256),
4 ranks x 16 threads per node, Fulda (Opteron 6272), master vs this commit,
median of 7 samples, same suite and nodes for both:

  unscoped spawn, 64 tasks     64 procs (1 node)    244.3 ms -> 11.7 ms   (21x)
                              128 procs (2 nodes)   547.2 ms -> 12.2 ms   (45x)
                              256 procs (4 nodes)  1257.9 ms -> 14.0 ms   (90x)
  allocations of that benchmark                      0.75 M -> 13 k, 1.74 M -> 19 k, 4.0 M -> 18.7 k

The unscoped cost no longer grows with the processor count (about 0.2 ms/task
at 256 processors). Pinned (ExactScope) benchmarks have a single candidate (the old
cost estimate returned immediately for it) and are within noise; test/allocations.jl is
unchanged (task spawn 183 allocs vs a bound of 500).
do_tasks ends every enqueue by 'kicking' the doorbell of every other processor
of the scheduler, to make it try to steal. A runner whose processor may not
steal (stealing_permitted false: every MPIProcessor) wakes up, finds that out
and goes back to sleep, so under MPI each enqueued task woke ranks x threads
runners on every rank: 256 wake-ups per task at 256 processors, about 832 at
the application's size. The wake-ups are task switches on threads that could be
running tasks, plus the allocations of the runner loop.

Skip processors for which stealing_permitted is false. A kick only makes a
runner try to steal, so skipping them cannot change which task runs where.

Measured with benchmark/suites/tasks.jl on Fulda (Opteron 6272), 4 ranks x 16
threads per node, median of 7, before = 83475c6 (previous commit), 1/2/4 nodes
= 4/8/16 ranks:
  unscoped (64 tasks)              11.0 / 12.8 / 15.9 ms -> 7.3 / 9.8 / 10.4 ms
  pinned, round robin (256)        44.6 / 58.9 / 47.8 ms -> 38.3 / 39.3 / 39.8 ms
  dependent hops (64)              55.4 / 66.2 / 64.8 ms -> 41.8 / 43.5 / 42.8 ms
  fan-in tree (256 leaves)         95.5 / 98.4 / 134.2 ms -> 87.9 / 90.4 / 94.0 ms
  allocations, pinned round robin  64.6 k / 83.1 k / 67.5 k -> 40.7 k / 41.1 k / 42.9 k
  allocations per pinned task in a clean loop (4 ranks x 16 threads): 183.7 -> 159.0
Every one of the 27 benchmark/size cells is faster or equal; allocations fall by
20-65 %. No semantic change: the skipped runners would not have stolen anything.
…eping it

compat_entry inserted with BasicLFUCache.get!, which for a present key returns
the existing value. After the processor list changed without a cache flush
(here: a one-rank communicator's processors joining the context after the
world's tasks had warmed the cache) the entry for that key no longer matched
its procs, so every following lookup missed, recomputed the compatible set and
re-sorted it, and the stale entry stayed. Measured on 4 ranks x 16 threads: a
suite that registers the extra processors mid-run made unscoped tasks 5.3x
slower with 10x the allocations (7.5 -> 40.1 ms per 64 tasks); without the
registration they stay at 1.15x. Replace the entry on a miss.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant