Skip to content

Commit

Permalink
cache kwarg to store loaded data in memory and reuse (half of #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi committed Aug 9, 2020
1 parent 3229145 commit 06cf374
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/parallelism.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ lazy(f; kw...) = delayed(f; kw...)
maybe_lazy(f, x) = any(x->x isa Union{Thunk, Chunk}, x) ? lazy(f)(x...) : f(x...)
maybe_lazy(f) = (x...) -> maybe_lazy(f, x)

function compute(ctx, d::Dir; kw...)
function compute(ctx, d::Dir; cache=true, kw...)
thunks = []
mapvalues(d; lazy=false) do x
if x isa Thunk
if cache
x.cache = true
end
push!(thunks, x)
end
end
Expand All @@ -25,6 +28,6 @@ function compute(ctx, d::Dir; kw...)
end
end

exec(d::Dir) = mapvalues(exec, compute(d); lazy=false)
exec(d::Dir) = mapvalues(exec, compute(Dagger.Context(), d, compute=false); lazy=false)
exec(d::Union{Thunk, Chunk}) = collect(compute(d))
exec(x) = x

0 comments on commit 06cf374

Please sign in to comment.