MPI: tasks with acceleration=DistributedAcceleration() go missing when ranks spawn them independently

未关闭
#778 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@AnnaLena77 已经在做这个了。

开始于 2026年10月15日。

  • #779 来自 @AnnaLena77 —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
15/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃

调研方向

Start with accel_matches_proc and compatible_processors for DistributedAcceleration, which the report says ignore MPIProcessor, and with the task ID counter that feeds the MPI tags. Run test/mpi/cpu.jl on 2 ranks with 2 threads to reproduce the missing tasks. Done means each rank finishes its local tasks and mixed local/SPMD work gives correct results. The reporter says they plan to open a PR, and the intended way to pass results between local and SPMD tasks is still open, so check with maintainers first.

由索引模型根据 Issue 内容生成。

描述

We'd like to run some tasks only on the local rank inside an MPI program (a parallel loop over the rank's own threads), without every rank planning them. acceleration=Dagger.DistributedAcceleration() looked like the way to do that, and it works on one rank. With two ranks, some of the tasks never run:

# mpiexec -n 2 julia --project --threads=4 min.jl
using Dagger, MPI
Dagger.accelerate!(:mpi)
rank = MPI.Comm_rank(MPI.COMM_WORLD)

busy(i) = (sleep(0.1); i)
ts = [Dagger.@spawn(acceleration = Dagger.DistributedAcceleration(), busy(i)) for i in 1:12]
done = Threads.Atomic{Int}(0)
foreach(t -> Threads.@spawn((fetch(t); Threads.atomic_add!(done, 1))), ts)
t0 = time(); while done[] < 12 && time() - t0 < 20; sleep(0.1); end
println("rank $rank: $(done[])/12 tasks finished")

With -n 1 all 12 finish. With -n 2 only 8–10 per rank do, and we see Hit probable hang on bcast_meta delivery and sometimes AssertionError: MPIRef rank mismatch. Dagger 0.22.7, MPI.jl 0.20.28, Julia 1.13; same on macOS (MPICH_jll) and on a Linux cluster (Open MPI).

We think there are two things going on:

  1. Some of these tasks get placed on MPIProcessors, sometimes on the other rank, and then follow the SPMD execution path. accel_matches_proc(::DistributedAcceleration, proc) is always true, and compatible_processors(::DistributedAcceleration, ...) skips the filter completely. The missing tasks are exactly the ones placed on MPI processors.
  2. Local tasks take IDs from the same counter as SPMD tasks, and the MPI tags are derived from those IDs. If the ranks spawn different numbers of local tasks, later SPMD tasks get different IDs on each rank and hang (Hit hang on bcast_meta delivery with different tags on the two ranks).

I'll open a PR with a small fix for both: MPI processors are excluded for DistributedAcceleration, and local tasks under MPI get IDs from a separate range. With it, the reproducer runs fine (12/12 per rank, about 4× faster than spawning the tasks SPMD-style), local tasks with different counts per rank followed by normal SPMD work give correct results, and test/mpi/cpu.jl passes on 2 ranks × 2 threads.

We're not sure whether this is the intended way to use acceleration= under MPI, though. With the patch, a local task can use an SPMD result owned by its own rank; using one owned by another rank fails with an error, which seems reasonable. We don't know what the intended way is to pass a local task's result back into SPMD work.

Thanks a lot!

The analysis, the fix and this text were written with help from Claude (Anthropic); I checked the results.

主要语言
Julia
星标
734
派生
94
平均合并
4 天 18 小时
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

JuliaParallel/Dagger.jl 的其他 Issue

查看 JuliaParallel/Dagger.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。