JuliaParallel / JuliaParallel/Dagger.jl

Help with speedup of parallel task

Open
#204 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
723
Forks
90
Avg merge
1d 37m
Merged PRs (30d)
9

Description

Sorry if this should be a discourse thread instead, just close an I'll repost over there. I was thinking that in case the use case is valid it could be a decent benchmark.

I'm using Dagger (well, FileTrees actually) to parallelize processing of a number of .mat files but I see a large loss in performance of parallel vs sequential operation. The code below is a decent proxy of how I do it right now, although there is a fair bit of more processing done per file in reality. Numbers of "files" vs size of each file is kinda corresponding to their relative sizes (there are basically more files than they are big).

```julia
module DaggerTest

using Dagger

# Names can be read from the file before the whole thing is processed
getnames(n) = ["data$i" for i in 1:n]

# This is basically the result of reading the file (i.e matread(filename))
getdata(names) = Dict(n => randn(1000,100) for n in names)

processdata(d, n) = sum(d[n], dims=1)

function process(n; parallel=false)
pfun = parallel ? delayed : identity

names = getnames(n)

data = pfun(getdata)(names)

result = pfun((xs...) -> [xs...])((pfun(processdata)(data, name) for name in names)...)

parallel ? collect(result) : result
end
end
```

Benchmarks:

```julia

julia> versioninfo()
Julia Version 1.6.0-rc1
Commit a58bdd9010 (2021-02-06 15:49 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = "Microsoft VS Code\Code.exe"
JULIA_NUM_THREADS = 8

julia> include("DaggerTest.jl")
Main.DaggerTest

julia> using BenchmarkTools

julia> @benchmark DaggerTest.process(1000;parallel=false)
BenchmarkTools.Trial:
memory estimate: 764.24 MiB
allocs estimate: 9998
--------------
minimum time: 646.210 ms (0.39% GC)
median time: 742.727 ms (10.39% GC)
mean time: 737.141 ms (9.00% GC)
maximum time: 781.049 ms (9.88% GC)
--------------
samples: 7
evals/sample: 1

julia> @benchmark DaggerTest.process(1000;parallel=true)
BenchmarkTools.Trial:
memory estimate: 1.90 GiB
allocs estimate: 7844502
--------------
minimum time: 1.952 s (8.42% GC)
median time: 2.370 s (11.91% GC)
mean time: 2.310 s (11.05% GC)
maximum time: 2.609 s (10.82% GC)
--------------
samples: 3
evals/sample: 1

# I hope this will not assume 8 threads per processor, but maybe that is why it doesn't work...
julia> using Distributed

julia> addprocs(8; exeflags="--project");

julia> @everywhere include("DaggerTest.jl")
WARNING: replacing module DaggerTest.

# This just stalls indefinitely on my computer. With the real data it works, but is about 5 times slower than the threaded version
julia> @benchmark DaggerTest.process(1000;parallel=true)
```

Are the large number of allocations in the parallel cases expected or is it something wrong with my code? I'd ofc be happy to know if there is a better way to write it.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.