Skip to content

Commit 9ea3308

Browse files
author
Shashi Gowda
committed
rename gather to collect
1 parent 471c4b2 commit 9ea3308

File tree

9 files changed

+84
-72
lines changed

9 files changed

+84
-72
lines changed

Diff for: README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ b = compute(a)
7979
# => Computed(10000x10000 Array{Float64,2} in 9 parts each of (max size) 4000x4000)
8080
```
8181

82-
The result is an object containing metadata about the various pieces. They may be created on different workers and will stay there until a another worker needs it. However, you can request and get the whole data with the `gather` function.
82+
The result is an object containing metadata about the various pieces. They may be created on different workers and will stay there until a another worker needs it. However, you can request and get the whole data with the `collect` function.
8383

8484
```julia
85-
gather(b)
85+
collect(b)
8686
# => 10000x10000 Array{Float64,2}:
8787
....
8888
```
@@ -153,7 +153,7 @@ X[[20,30,40], :]
153153
X[20:40, [30,40,60]]
154154
```
155155

156-
Note that indexing again results in a `Computation` object of the type `GetIndex`. You can use it as input to another computation or call `gather` on it to get the indexed sub array.
156+
Note that indexing again results in a `Computation` object of the type `GetIndex`. You can use it as input to another computation or call `collect` on it to get the indexed sub array.
157157

158158
#### Sparse matrix support
159159

@@ -186,7 +186,7 @@ julia> compute(save(s1, "s1"))
186186
julia> x = load(Context(), "s1")
187187
Computed(10000x10000 Array{Float64,2} in 3x3 parts each of (max size) 4000x4000)
188188
189-
julia> gather(x)
189+
julia> collect(x)
190190
10000x10000 sparse matrix with 999793 Float64 entries:
191191
...
192192
```
@@ -227,7 +227,7 @@ result = compute(save(saved_A+saved_A', "ApAt"))
227227
- `reduceblock(f, c)` - reduce each block of data by applying `f` to the block. In block distributed array, the result has the same dimensionality as the input.
228228
- `reducebykey(f, c)` - given a collection of tuples or pairs, use the first element of the tuples as the key, and reduce the values of each key. Computes a Dict of results.
229229

230-
*Note: all these operations result in a `Computation` object. You need to call `compute` or `gather` on them to actually do the computation.*
230+
*Note: all these operations result in a `Computation` object. You need to call `compute` or `collect` on them to actually do the computation.*
231231

232232
**Array API**
233233
- Unary element-wise operations:
@@ -251,10 +251,10 @@ $, &, (.!=), (.<), (.<=), (.==), (.>),
251251
- `*` on Computations can either stand for matrix-matrix or matrix-vector multiplications.
252252
- transpose on a matrix can be done using the `x'` syntax
253253

254-
**Compute and gather**
254+
**Compute and collect**
255255

256256
- `compute(ctx, c)` - compute a computation `c`
257-
- `gather(ctx, c)` - compute the result, and collate the result on the host process (usually pid 1).
257+
- `collect(ctx, c)` - compute the result, and collate the result on the host process (usually pid 1).
258258

259259
**Context**
260260

Diff for: src/Dagger.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ module Dagger
22

33
using Compat
44

5+
import Base.collect
6+
57
include("lib/util.jl")
68
include("lib/logging.jl")
79
include("lib/dumbref.jl")
810

9-
# Data and slices of data
11+
# Distributed data
12+
include("processor.jl")
1013
include("thunk.jl")
1114
include("domain.jl")
1215
include("chunks.jl")
1316

1417
# Task scheduling
15-
include("processor.jl")
1618
include("compute.jl")
1719

1820
# Array computations

Diff for: src/array/darray.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ domain(x::AbstractArray) = ArrayDomain([1:l for l in size(x)])
7676
compute(ctx, x::ArrayOp) =
7777
compute(ctx, cached_stage(ctx, x)::DArray)
7878

79-
gather(ctx, x::ArrayOp) =
80-
gather(ctx, cached_stage(ctx, x)::DArray)
79+
collect(ctx::Context, x::ArrayOp) =
80+
collect(ctx, compute(ctx, x))
81+
82+
collect(x::ArrayOp) = collect(Context(), x)
8183

8284
@compat function Base.show(io::IO, ::MIME"text/plain", x::ArrayOp)
8385
write(io, string(typeof(x)))
@@ -101,12 +103,12 @@ domainchunks(d::DArray) = d.subdomains
101103
size(x::DArray) = size(domain(x))
102104
stage(ctx, c::DArray) = c
103105

104-
function gather(ctx, d::DArray)
106+
function collect(ctx::Context, d::DArray)
105107
a = compute(ctx, d, persist=false)
106108
ps_input = chunks(a)
107109
ps = Array{Any}(size(ps_input))
108110
@sync for i in 1:length(ps_input)
109-
@async ps[i] = gather(ctx, ps_input[i])
111+
@async ps[i] = collect(ctx, ps_input[i])
110112
end
111113
if isempty(ps)
112114
emptyarray(Array{eltype(d), ndims(d)}, size(d)...)

Diff for: src/array/sort.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function compute(ctx, s::Sort)
4141
DArray(compute(ctx, shuffle_merge(inp, splitter_ranks, splitters, s.order)))
4242
end
4343

44-
function delayed_map_and_gather(f, ctx, Xs...)
44+
function delayed_map_and_collect(f, ctx, Xs...)
4545
result_parts = map(delayed(f, get_result=true), Xs...)
46-
gather(ctx, delayed(tuple)(result_parts...))
46+
collect(ctx, delayed(tuple)(result_parts...))
4747
end
4848

4949
function pselect(ctx, A, ranks, ord)
@@ -72,7 +72,7 @@ function pselect(ctx, A, ranks, ord)
7272
# find medians
7373
chunk_ranges = [vec(active_ranges[i,:]) for i in 1:Nc]
7474

75-
chunk_medians = delayed_map_and_gather(ctx, chunk_ranges, cs) do ranges, data
75+
chunk_medians = delayed_map_and_collect(ctx, chunk_ranges, cs) do ranges, data
7676
# as many ranges as ranks to find
7777
map(r->submedian(data, r), ranges)
7878
end
@@ -85,7 +85,7 @@ function pselect(ctx, A, ranks, ord)
8585
Ms = vec(mapslices(x->weightedmedian(x, ls, ord), median_matrix, 1))
8686

8787
# scatter weighted
88-
LEGs = delayed_map_and_gather(ctx, cs, chunk_ranges) do chunk, ranges
88+
LEGs = delayed_map_and_collect(ctx, cs, chunk_ranges) do chunk, ranges
8989
# for each median found right now, locate G,T,E vals
9090
map((range, m)->locate_pivot(chunk, range, m, ord), ranges, Ms)
9191
end

Diff for: src/chunks.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
export chunk, gather
2+
export chunk, collect
33

44
export domain, UnitDomain, project, alignfirst, ArrayDomain
55

@@ -52,14 +52,14 @@ function unrelease{T}(c::Chunk{T,MemToken})
5252
end
5353
unrelease(c::Chunk) = c
5454

55-
function gather(ctx, chunk::Chunk)
55+
function collect(ctx::Context, chunk::Chunk)
5656
# delegate fetching to handle by default.
57-
gather(ctx, chunk.handle)
57+
collect(ctx, chunk.handle)
5858
end
5959

6060

6161
### ChunkIO
62-
function gather(ctx, ref::MemToken)
62+
function collect(ctx::Context, ref::MemToken)
6363
res = fetch(ref)
6464
if isnull(res)
6565
throw(KeyError(ref))

Diff for: src/compute.jl

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
export stage, cached_stage, compute, debug_compute, cached, free!
22
using Compat
33

4+
compute(x) = compute(Context(), x)
5+
compute(ctx, c::Chunk) = c
6+
7+
collect(ctx::Context, c) = collect(ctx, compute(ctx, c))
8+
collect(d::Union{Chunk,Thunk}) = collect(Context(), d)
9+
410
@compat abstract type Computation end
511

6-
compute(x) = compute(Context(), x)
7-
gather(d) = gather(Context(), d)
812
compute(ctx, c::Computation) = compute(ctx, stage(ctx, c))
9-
gather(ctx, c) = gather(compute(ctx, c))
13+
collect(c::Computation) = collect(Context(), c)
14+
1015

1116
function finish_task!(state, node, node_order; free=true)
1217
if istask(node) && node.cache
@@ -278,7 +283,7 @@ function start_state(deps::Dict, node_order)
278283
end
279284

280285
_move(ctx, to_proc, x) = x
281-
_move(ctx, to_proc::OSProc, x::Union{Chunk, Thunk}) = gather(ctx, x)
286+
_move(ctx, to_proc::OSProc, x::Union{Chunk, Thunk}) = collect(ctx, x)
282287

283288
function do_task(ctx, proc, thunk_id, f, data, send_result, persist)
284289
@dbg timespan_start(ctx, :comm, thunk_id, proc)
@@ -319,3 +324,6 @@ function debug_compute(arg; profile=false)
319324
dbgctx = Context(procs(ctx), LocalEventLog(), profile)
320325
debug_compute(dbgctx, arg)
321326
end
327+
328+
Base.@deprecate gather(ctx, x) collect(ctx, x)
329+
Base.@deprecate gather(x) collect(x)

Diff for: src/file-io.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function save(ctx, io::IO, chunk::Chunk, file_path)
6262
write(io, meta)
6363
data_offset = position(io)
6464

65-
save(ctx, io, gather(ctx, chunk))
65+
save(ctx, io, collect(ctx, chunk))
6666

6767
Chunk(chunktype(chunk), domain(chunk), FileReader(file_path, chunktype(chunk), data_offset, false), false)
6868
end
@@ -172,7 +172,7 @@ function save(ctx, io::IO, m::BitArray)
172172
save(ctx, io, convert(Array{Bool}, m))
173173
end
174174

175-
function gather{X,T<:Array}(ctx, c::Chunk{X,FileReader{T}})
175+
function collect{X,T<:Array}(ctx::Context, c::Chunk{X,FileReader{T}})
176176
h = c.handle
177177
io = open(h.file, "r+")
178178
seek(io, h.data_offset)
@@ -182,7 +182,7 @@ function gather{X,T<:Array}(ctx, c::Chunk{X,FileReader{T}})
182182
arr
183183
end
184184

185-
function gather{X,T<:BitArray}(ctx, c::Chunk{X, FileReader{T}})
185+
function collect{X,T<:BitArray}(ctx::Context, c::Chunk{X, FileReader{T}})
186186
h = c.handle
187187
io = open(h.file, "r+")
188188
seek(io, h.data_offset)
@@ -210,7 +210,7 @@ function save{Tv, Ti}(ctx, io::IO, m::SparseMatrixCSC{Tv,Ti})
210210
m
211211
end
212212

213-
function gather{X, T<:SparseMatrixCSC}(ctx, c::Chunk{X, FileReader{T}})
213+
function collect{X, T<:SparseMatrixCSC}(ctx::Context, c::Chunk{X, FileReader{T}})
214214
h = c.handle
215215
io = open(h.file, "r+")
216216
seek(io, h.data_offset)
@@ -237,7 +237,7 @@ function gather{X, T<:SparseMatrixCSC}(ctx, c::Chunk{X, FileReader{T}})
237237
end
238238

239239
function getsub{X,T<:AbstractArray}(ctx, c::Chunk{X,FileReader{T}}, d)
240-
Chunk(gather(ctx, c)[d])
240+
Chunk(collect(ctx, c)[d])
241241
end
242242

243243

0 commit comments

Comments
 (0)