Skip to content

MPI: drop a plain task's ref-id counter when the task is done - #793

Closed
AnnaLena77 wants to merge 2 commits into
JuliaParallel:masterfrom
AnnaLena77:pr/a8c-refid-leak
Closed

AnnaLena77 wants to merge 2 commits into
JuliaParallel:masterfrom
AnnaLena77:pr/a8c-refid-leak

Conversation

@AnnaLena77

Copy link
Copy Markdown
Collaborator

_MPIREF_TID holds one sub-counter per task id for the ref ids a task takes while it is moved and executed. It was reclaimed only at the end of a Datadeps region, so a program that only uses @spawn grew it by one entry per task for the whole session. A task that is not part of a Datadeps region (no tag option) takes ids only during its own move and execute!, never during planning, so its counter is dead once execute! returns; it is deleted there. Tagged (Datadeps) tasks keep the later cleanup, since their planning shares the key with their execution and reclaiming in between would collide on sub-ids.

Test in test/mpi/spawn.jl: 300 plain tasks (unscoped, pinned, and with a body that may throw) must leave the table within 20 entries, and task ids stay uniform afterwards. At 2 ranks x 2 threads the test fails on current master (the table grows) and passes with this change.

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

_MPIREF_TID holds one sub-counter per task id for the ref ids a task takes
while it is moved and executed. It was reclaimed only at the end of a Datadeps
region, so a program that only uses @Spawn grew it by one entry per task for
the whole session. A task that is not part of a Datadeps region (no tag
option) takes ids only during its own move and execute!, never during
planning, so its counter is dead once execute! returns: delete it there.
Tagged (Datadeps) tasks keep the later cleanup, since their planning shares
the key with their execution and reclaiming in between would collide on
sub-ids.

Test (test/mpi/spawn.jl): 300 plain tasks (unscoped, pinned, and with a body
that may throw) must leave the table within 20 entries, and task ids stay
uniform afterwards. At 2 ranks x 2 threads (MPICH) the test fails on upstream
master (the table grows) and passes with this change.

@jpsamaroo jpsamaroo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Two questions (desiring changes or an explanation for why things are written like this), but otherwise it's good to go.

Comment thread ext/MPIExt.jl Outdated
# `@spawn` never reaches. Datadeps tasks (tagged) keep the later cleanup: their planning shares
# the key with their execution, and reclaiming between the two would collide on sub-ids.
function execute!(proc::MPIProcessor, f, args...; kwargs...)
if Dagger.in_task()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need the in_task() check here, as it's by definition always true within execute! (execute! should only be called within a Dagger task).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, execute! always runs inside a task, so the check was dead code. Removed in 6b68d4d.

Comment thread test/mpi/spawn.jl Outdated
foreach(wait, [Dagger.@spawn(mpi_spawn_checked(i)) for i in 1:100])
MPI.Barrier(comm)
# Nothing is left behind by 300 tasks (a few entries may belong to tasks still finishing)
@test reftid_size() - before < 20

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be reftid_size() == before, what other tasks might be still finishing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. The cleanup runs in the task's own finally before the result is published, so nothing is left after wait. My "tasks still finishing" comment was wrong. The test now checks equality; 5 of 5 runs pass at 2 ranks × 2 threads.

…le size in the test)

execute! is only ever called from inside a Dagger task, so the in_task() guard
around the cleanup was dead code; read the task options directly.

The regression test compared the table size with a slack of 20 entries. The
cleanup runs in the task's own finally block, before its result is published,
so once the tasks have been waited for nothing of theirs is left: require the
size to be exactly what it was before.
@fda-tome

Copy link
Copy Markdown
Collaborator

Thanks so much! Squashed into a single commit and merged as part of #804.

@fda-tome fda-tome closed this Nov 27, 2026
fda-tome pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 27, 2026
…arallel#793)

* MPI: drop a plain task's ref-id counter when the task is done
* MPI: review fixes for the ref-id cleanup (no in_task check, exact table size in the test)
AnnaLena77 pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 29, 2026
Buildkite reports one commit status per step
(`buildkite/dagger-dot-jl/julia-1-dot-11-cuda-mpi`), not the
`Julia 1.11 (CUDA, MPI)` names the patterns were written for. Every GPU
and GPU+MPI configuration therefore read "absent" even when it ran and
passed (PR JuliaParallel#793: mpi-cuda passed but was reported absent, and a
reviewer had to correct the evidence by hand). MPI CPU and OpenCL+MPI
had no configuration at all.

Also stop calling a configuration `fail` when one of its jobs passed on
one run and failed on another (a re-run or a flaky job): report it as
`mixed`, so the reviewer reads the logs before attributing a failure to
the change. With these patterns every configuration of PR JuliaParallel#793 resolves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
AnnaLena77 pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 29, 2026
On PRs JuliaParallel#792 and JuliaParallel#793, both merged essentially unchanged, reviewers
returned 6 and 7 `concern` verdicts. `concern` meant anything from
"silently loses buffers" to "a comment names wait_all imprecisely",
so the verdict table could not tell the maintainer what to look at.

Problem claims now carry `blocker`, `should-fix` or `nit`, and the
worst supported severity fixes the verdict (blocker -> fail,
should-fix -> concern, nits only -> pass). A category whose only
findings are nits now passes instead of reading as a concern. The task
rules also say that a weakness predating the change is at most a nit.

Schema version 2; reports written for version 1 must be redone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
AnnaLena77 pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 29, 2026
The PR JuliaParallel#792 and JuliaParallel#793 briefs repeated one defect under every category
that noticed it (the unfreed NoAliasing copies three times, the removed
in_task() guard three times), clipped each repetition at ~300
characters, and put the result in "Read these" lists of 49 and 73
lines. The maintainer had to reconstruct which items were the same
issue before deciding anything.

A consolidation step (`review.py findings`, fragments/_findings.json)
now groups problem claims by the defect they describe; submit requires
every problem claim to be in exactly one finding. A finding carries
the worst severity of its claims and says how many reviewers raised it
independently, which is evidence that it is real rather than noise.

The brief now opens with at most three blocker/should-fix findings,
each with a plain-words title and the merged lines to read; further
findings follow the verdict table, and nits are counted, not listed
(`render --nits`; folded in brief.md). Categories that are unverified
only because their measurement was never collected, and that raised
nothing, share one UNMEASURED line instead of one line each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
AnnaLena77 pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 29, 2026
Reviewers of PR JuliaParallel#793 flagged removing an `in_task()` guard from
`execute!(::MPIProcessor)` as a regression in three categories, because
`execute!` is listed in the manual and nothing says it is only called
inside a task. The maintainer had asked for that removal. Rules like
this live only in the maintainer's head or in review comments, so
every fresh reviewer rediscovers them as bugs.

The new Invariants section holds such rules, starting with that one;
the review tooling will hand it to every reviewer verbatim. Lesson 99
records why NoAliasing values still reach aliased_object! (the
maintainer's own first reading of PR JuliaParallel#792 was that they could not).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
AnnaLena77 pushed a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 29, 2026
A fresh reviewer knows only the code and the evidence. On PR JuliaParallel#793,
three categories independently reported the removal of an `in_task()`
guard from `execute!(::MPIProcessor)` as a regression, although the
maintainer had asked for it: `execute!` is only ever called inside a
task, a rule written nowhere a reviewer looks. The maintainer could
not tell the reviewers so; every re-review would repeat the finding.

Reviewers may now ask (`questions`, at most two per category) when a
finding hinges on intent or usage the code cannot show, and tie each
affected claim to its question. The brief lists open questions with
the findings that hang on them. The maintainer answers in
answers.toml; `review.py rerun` sends each answer to the asking
category and to every category with a claim in the same finding (one
defect, one answer), sets those fragments aside, and lists what to
redo. `review.py task` then shows the answers and the category's
previous fragment, and `submit` rejects a redone fragment that does
not list the answers in `answers_considered`. The brief reports which
verdicts the answers changed.

Every task prompt also carries AGENTS.md's Invariants section, and
`review.py promote` copies answers marked `scope = "project"` into it,
so a rule explained once is known to every later review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
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.

3 participants