Skip to content

Commit deb3dc0

Browse files
committed
clean up the naming of all functions
1 parent 3ddc08c commit deb3dc0

6 files changed

Lines changed: 160 additions & 178 deletions

File tree

src/DiDa.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ export save_at,
1111
get_from,
1212
get_val_from,
1313
remove_from,
14-
distribute_array,
15-
distribute_darray,
16-
undistribute,
17-
distributed_transform,
18-
distributed_mapreduce,
19-
distributed_foreach,
20-
distributed_collect
14+
scatter_array,
15+
unscatter,
16+
dexec,
17+
dtransform,
18+
dmapreduce,
19+
dmap,
20+
gather_array,
21+
tmp_symbol
2122

2223
include("io.jl")
23-
export distributed_export,
24-
distributed_import,
25-
distributed_unlink
24+
export dstore,
25+
dload,
26+
dunlink
2627

2728
include("tools.jl")
2829
export dcopy,
@@ -34,7 +35,6 @@ export dcopy,
3435
dcount,
3536
dcount_buckets,
3637
dscale,
37-
dtransform_asinh,
3838
dmedian,
3939
dmedian_buckets,
4040
mapbuckets,

src/base.jl

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ The symbols are saved in Main module on the corresponding worker. For example,
3030
`save_at(1, :x, nothing)` _will_ erase your local `x` variable. Beware of name
3131
collisions.
3232
"""
33-
function save_at(worker, sym::Symbol, val)
34-
remotecall(() -> Base.eval(Main, :(
33+
function save_at(worker, sym::Symbol, val; mod=Main)
34+
remotecall(() -> Base.eval(mod, :(
3535
begin
3636
$sym = $val
3737
nothing
@@ -45,8 +45,8 @@ end
4545
Get a value `val` from a remote `worker`; quoting of `val` works just as with
4646
`save_at`. Returns a future with the requested value.
4747
"""
48-
function get_from(worker, val)
49-
remotecall(() -> Base.eval(Main, :($val)), worker)
48+
function get_from(worker, val; mod=Main)
49+
remotecall(() -> Base.eval(mod, :($val)), worker)
5050
end
5151

5252
"""
@@ -68,14 +68,14 @@ function remove_from(worker, sym::Symbol)
6868
end
6969

7070
"""
71-
distribute_array(sym, x::Array, pids; dim=1)::Dinfo
71+
scatter_array(sym, x::Array, pids; dim=1)::Dinfo
7272
7373
Distribute roughly equal parts of array `x` separated on dimension `dim` among
7474
`pids` into a worker-local variable `sym`.
7575
7676
Returns the `Dinfo` structure for the distributed data.
7777
"""
78-
function distribute_array(sym::Symbol, x::Array, pids; dim = 1)::Dinfo
78+
function scatter_array(sym::Symbol, x::Array, pids; dim = 1)::Dinfo
7979
n = length(pids)
8080
dims = size(x)
8181

@@ -93,33 +93,33 @@ function distribute_array(sym::Symbol, x::Array, pids; dim = 1)::Dinfo
9393
end
9494

9595
"""
96-
undistribute(sym, workers)
96+
unscatter(sym, workers)
9797
9898
Remove the loaded data from workers.
9999
"""
100-
function undistribute(sym::Symbol, workers)
100+
function unscatter(sym::Symbol, workers)
101101
for f in [remove_from(pid, sym) for pid in workers]
102102
fetch(f)
103103
end
104104
end
105105

106106
"""
107-
undistribute(dInfo::Dinfo)
107+
unscatter(dInfo::Dinfo)
108108
109109
Remove the loaded data described by `dInfo` from the corresponding workers.
110110
"""
111-
function undistribute(dInfo::Dinfo)
112-
undistribute(dInfo.val, dInfo.workers)
111+
function unscatter(dInfo::Dinfo)
112+
unscatter(dInfo.val, dInfo.workers)
113113
end
114114

115115
"""
116-
distributed_exec(val, fn, workers)
116+
dexec(val, fn, workers)
117117
118118
Execute a function on workers, taking `val` as a parameter. Results are not
119119
collected. This is optimal for various side-effect-causing computations that
120-
are not expressible with `distributed_transform`.
120+
are not easily expressible with `dtransform`.
121121
"""
122-
function distributed_exec(val, fn, workers)
122+
function dexec(val, fn, workers)
123123
for f in [get_from(pid, :(
124124
begin
125125
$fn($val)
@@ -131,47 +131,47 @@ function distributed_exec(val, fn, workers)
131131
end
132132

133133
"""
134-
distributed_exec(dInfo::Dinfo, fn)
134+
dexec(dInfo::Dinfo, fn)
135135
136-
Variant of `distributed_exec` that works with `Dinfo`.
136+
Variant of `dexec` that works with `Dinfo`.
137137
"""
138-
function distributed_exec(dInfo::Dinfo, fn)
139-
distributed_exec(dInfo.val, fn, dInfo.workers)
138+
function dexec(dInfo::Dinfo, fn)
139+
dexec(dInfo.val, fn, dInfo.workers)
140140
end
141141

142142
"""
143-
distributed_transform(val, fn, workers, tgt::Symbol=val)
143+
dtransform(val, fn, workers, tgt::Symbol=val)
144144
145145
Transform the worker-local distributed data available as `val` on `workers`
146146
in-place, by a function `fn`. Store the result as `tgt` (default `val`)
147147
148148
# Example
149149
150150
# multiply all saved data by 2
151-
distributed_transform(:myData, (d)->(2*d), workers())
151+
dtransform(:myData, (d)->(2*d), workers())
152152
"""
153-
function distributed_transform(val, fn, workers, tgt::Symbol = val)::Dinfo
153+
function dtransform(val, fn, workers, tgt::Symbol = val)::Dinfo
154154
for f in [save_at(pid, tgt, :($fn($val))) for pid in workers]
155155
fetch(f)
156156
end
157157
return Dinfo(tgt, workers)
158158
end
159159

160160
"""
161-
distributed_transform(dInfo::Dinfo, fn, tgt::Symbol=dInfo.val)::Dinfo
161+
dtransform(dInfo::Dinfo, fn, tgt::Symbol=dInfo.val)::Dinfo
162162
163-
Same as `distributed_transform`, but specialized for `Dinfo`.
163+
Same as `dtransform`, but specialized for `Dinfo`.
164164
"""
165-
function distributed_transform(
165+
function dtransform(
166166
dInfo::Dinfo,
167167
fn,
168168
tgt::Symbol = dInfo.val,
169169
)::Dinfo
170-
distributed_transform(dInfo.val, fn, dInfo.workers, tgt)
170+
dtransform(dInfo.val, fn, dInfo.workers, tgt)
171171
end
172172

173173
"""
174-
distributed_mapreduce(val, map, fold, workers)
174+
dmapreduce(val, map, fold, workers)
175175
176176
Run `map`s (non-modifying transforms on the data) and `fold`s (2-to-1
177177
reductions) on the worker-local data (in `val`s) distributed on `workers` and
@@ -186,7 +186,7 @@ main process.
186186
187187
# Example
188188
# compute the mean of all distributed data
189-
sum,len = distributed_mapreduce(:myData,
189+
sum,len = dmapreduce(:myData,
190190
(d) -> (sum(d),length(d)),
191191
((s1, l1), (s2, l2)) -> (s1+s2, l1+l2),
192192
workers())
@@ -198,12 +198,12 @@ The `val` here does not necessarily need to refer to a symbol, you can easily
198198
pass in a quoted tuple, which will be unquoted in the function parameter. For
199199
example, distributed values `:a` and `:b` can be joined as such:
200200
201-
distributed_mapreduce(:((a,b)),
201+
dmapreduce(:((a,b)),
202202
((a,b)::Tuple) -> [a b],
203203
vcat,
204204
workers())
205205
"""
206-
function distributed_mapreduce(val, map, fold, workers)
206+
function dmapreduce(val, map, fold, workers)
207207
if isempty(workers)
208208
return nothing
209209
end
@@ -223,33 +223,33 @@ function distributed_mapreduce(val, map, fold, workers)
223223
end
224224

225225
"""
226-
distributed_mapreduce(dInfo::Dinfo, map, fold)
226+
dmapreduce(dInfo::Dinfo, map, fold)
227227
228-
Distributed map/reduce (just as the other overload of `distributed_mapreduce`)
228+
Distributed map/reduce (just as the other overload of `dmapreduce`)
229229
that works with `Dinfo`.
230230
"""
231-
function distributed_mapreduce(dInfo::Dinfo, map, fold)
232-
distributed_mapreduce(dInfo.val, map, fold, dInfo.workers)
231+
function dmapreduce(dInfo::Dinfo, map, fold)
232+
dmapreduce(dInfo.val, map, fold, dInfo.workers)
233233
end
234234

235235
"""
236-
distributed_mapreduce(vals::Vector, map, fold, workers)
236+
dmapreduce(vals::Vector, map, fold, workers)
237237
238-
Variant of `distributed_mapreduce` that works with more distributed variables
238+
Variant of `dmapreduce` that works with more distributed variables
239239
at once.
240240
"""
241-
function distributed_mapreduce(vals::Vector, map, fold, workers)
242-
return distributed_mapreduce(Expr(:vect, vals...), vals -> map(vals...), fold, workers)
241+
function dmapreduce(vals::Vector, map, fold, workers)
242+
return dmapreduce(Expr(:vect, vals...), vals -> map(vals...), fold, workers)
243243
end
244244

245245
"""
246-
distributed_mapreduce(dInfo1::Dinfo, dInfo2::Dinfo, map, fold)
246+
dmapreduce(dInfo1::Dinfo, dInfo2::Dinfo, map, fold)
247247
248-
Variant of `distributed_mapreduce` that works with more `Dinfo`s at
248+
Variant of `dmapreduce` that works with more `Dinfo`s at
249249
once. The data must be distributed on the same set of workers, in the same
250250
order.
251251
"""
252-
function distributed_mapreduce(dInfos::Vector{Dinfo}, map, fold)
252+
function dmapreduce(dInfos::Vector{Dinfo}, map, fold)
253253
if (isempty(dInfos))
254254
return nothing
255255
end
@@ -259,27 +259,27 @@ function distributed_mapreduce(dInfos::Vector{Dinfo}, map, fold)
259259
error("data distribution mismatch")
260260
end
261261

262-
return distributed_mapreduce([di.val for di in dInfos], map, fold, dInfos[1].workers)
262+
return dmapreduce([di.val for di in dInfos], map, fold, dInfos[1].workers)
263263
end
264264

265265
"""
266-
distributed_collect(val::Symbol, workers, dim=1; free=false)
266+
gather_array(val::Symbol, workers, dim=1; free=false)
267267
268268
Collect the arrays distributed on `workers` under value `val` into an array. The
269269
individual arrays are pasted in the dimension specified by `dim`, i.e. `dim=1`
270270
is roughly equivalent to using `vcat`, and `dim=2` to `hcat`.
271271
272272
`val` must be an Array-based type; the function will otherwise fail.
273273
274-
If `free` is true, the `val` is undistributed after collection.
274+
If `free` is true, the `val` is `unscatter`ed after being gathered.
275275
276276
This preallocates the array for results, and is thus more efficient than e.g.
277-
using `distributed_mapreduce` with `vcat` for folding.
277+
using `dmapreduce` with `vcat` for folding.
278278
"""
279-
function distributed_collect(val::Symbol, workers, dim = 1; free = false)
279+
function gather_array(val::Symbol, workers, dim = 1; free = false)
280280
size0 = get_val_from(workers[1], :(size($val)))
281281
innerType = get_val_from(workers[1], :(typeof($val).parameters[1]))
282-
sizes = distributed_mapreduce(val, d -> size(d, dim), vcat, workers)
282+
sizes = dmapreduce(val, d -> size(d, dim), vcat, workers)
283283
ressize = [size0[i] for i = 1:length(size0)]
284284
ressize[dim] = sum(sizes)
285285
result = zeros(innerType, ressize...)
@@ -291,50 +291,50 @@ function distributed_collect(val::Symbol, workers, dim = 1; free = false)
291291
off += sizes[i]
292292
end
293293
if free
294-
undistribute(val, workers)
294+
unscatter(val, workers)
295295
end
296296
return result
297297
end
298298

299299
"""
300-
distributed_collect(dInfo::Dinfo, dim=1; free=false)
300+
gather_array(dInfo::Dinfo, dim=1; free=false)
301301
302-
Distributed collect (just as the other overload) that works with
302+
Distributed gather_array (just as the other overload) that works with
303303
`Dinfo`.
304304
"""
305-
function distributed_collect(dInfo::Dinfo, dim = 1; free = false)
306-
return distributed_collect(dInfo.val, dInfo.workers, dim, free = free)
305+
function gather_array(dInfo::Dinfo, dim = 1; free = false)
306+
return gather_array(dInfo.val, dInfo.workers, dim, free = free)
307307
end
308308

309309
"""
310-
distributed_foreach(arr::Vector, fn, workers)
310+
dmap(arr::Vector, fn, workers)
311311
312312
Call a function `fn` on `workers`, with a single parameter arriving from the
313313
corresponding position in `arr`.
314314
"""
315-
function distributed_foreach(arr::Vector, fn, workers)
315+
function dmap(arr::Vector, fn, workers)
316316
futures = [
317-
remotecall(() -> Base.eval(Main, :($fn($(arr[i])))), pid)
317+
remotecall(() -> Base.eval(Main, :($fn($(arr[i])))), pid) #TODO convert to get_from
318318
for (i, pid) in enumerate(workers)
319319
]
320320
return [fetch(f) for f in futures]
321321
end
322322

323323
"""
324-
tmpSym(s::Symbol; prefix="", suffix="_tmp")
324+
tmp_symbol(s::Symbol; prefix="", suffix="_tmp")
325325
326326
Decorate a symbol `s` with prefix and suffix, to create a good name for a
327327
related temporary value.
328328
"""
329-
function tmpSym(s::Symbol; prefix = "", suffix = "_tmp")
329+
function tmp_symbol(s::Symbol; prefix = "", suffix = "_tmp")
330330
return Symbol(prefix * String(s) * suffix)
331331
end
332332

333333
"""
334-
tmpSym(dInfo::Dinfo; prefix="", suffix="_tmp")
334+
tmp_symbol(dInfo::Dinfo; prefix="", suffix="_tmp")
335335
336336
Decorate the symbol from `dInfo` with prefix and suffix.
337337
"""
338-
function tmpSym(dInfo::Dinfo; prefix = "", suffix = "_tmp")
339-
return tmpSym(dInfo.val, prefix = prefix, suffix = suffix)
338+
function tmp_symbol(dInfo::Dinfo; prefix = "", suffix = "_tmp")
339+
return tmp_symbol(dInfo.val, prefix = prefix, suffix = suffix)
340340
end

0 commit comments

Comments
 (0)