Game of Life example is slower with more processes than just one
@pszufe đang làm issue này rồi.
Từ ngày 5/8/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Hi, I am looking into Dagger.jl to see if I can use it for speeding up cellular automata models. So, I was very happy to see an example of the stencil macro which implemented the game of life. However, when I test it myself with some small adjustments, it is much slower to use multiple processes than it is to just use one.
Below is my code, I'm working in a jupyter notebook.
# Add workers before 'using Dagger'
using Distributed
if nprocs() == 1
addprocs(5)
end
# Before we load the packages, we need make sure the environment is loaded correctly
@everywhere begin
using Pkg; Pkg.activate("juliaenv")
end
using Plots
using Dagger
import Dagger: @stencil, Wrap, Pad
N = 27 # Size of one dimension of a tile
nt = 3 # Number of tiles in each dimension (results in nt x nt grid of tiles)
niters = 100 # Number of iterations for the animation
tiles = zeros(AutoBlocks(), Bool, 512, 512)
outputs = zeros(AutoBlocks(), Bool, 512, 512)
# Create a fun initial state (e.g., a glider and some random noise)
tiles[13, 14] = true
tiles[14, 14] = true
tiles[15, 14] = true
tiles[15, 15] = true
tiles[14, 16] = true
# Add some random noise in one of the tiles
@view(tiles[(2N+1):3N, (2N+1):3N]) .= rand(Bool, N, N)
@time anim = @animate for _ in 1:niters
Dagger.spawn_datadeps() do
@stencil begin
outputs[idx] = begin
nhood = @neighbors(tiles[idx], 1, Wrap())
neighs = sum(nhood) - tiles[idx] # Sum neighborhood, but subtract own value
if tiles[idx] && neighs < 2
0 # Dies of underpopulation
elseif tiles[idx] && neighs > 3
0 # Dies of overpopulation
elseif !tiles[idx] && neighs == 3
1 # Becomes alive by reproduction
else
tiles[idx] # Keeps its prior value
end
end
tiles[idx] = outputs[idx] # Update tiles for the next iteration
end
end
heatmap(Int.(collect(outputs))) # Generate a heatmap visualization
end
path = mp4(anim; fps=5, show_msg=true).filename # Create an animation of the heatmaps over time
To run it with only one process, I comment out
if nprocs() == 1
addprocs(5)
end
On a Macbook M3 Pro, it takes about 6 seconds to run the second cell again, while with more workers, it takes around 23. I'm using Julia 1.11.6.
Now for my question(s):
Is the overhead of Dagger.jl causing the slowdown here? If yes, at what point would this Game of Life simulation benefit from Dagger.jl? When employing an even bigger grid? Or am I doing something wrong that causes the slowdown?
- Ngôn ngữ chính
- Julia
- Star
- 734
- Fork
- 94
- Merge trung bình
- 4 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaParallel/Dagger.jl
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
JuliaParallel/Dagger.jl#786 · 1 bình luận ·
-
MPI: tasks with acceleration=DistributedAcceleration() go missing when ranks spawn them independentlyCó thể đã có người làm @AnnaLena77 đã nhận 39 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
JuliaParallel/Dagger.jl#778 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
JuliaParallel/Dagger.jl#759 · 3 bình luận ·
-
bug datadeps
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
JuliaParallel/Dagger.jl#665 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
JuliaParallel/Dagger.jl#661 · 1 bình luận ·
Tất cả issue của JuliaParallel/Dagger.jl
Issue tương tự
-
docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
path: splitext treats directory references and leading dots as extensionsCó thể đã có người làm @Hiten0305l đã nhận hôm nay. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
JuliaRegistries/RegistryCI.jl#758 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JuliaParallel/Hwloc.jl#93 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày