-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathordered_pmap.jl
32 lines (28 loc) · 975 Bytes
/
ordered_pmap.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export ordered_pmap
function ordered_pmap(pool::WorkerPool, f, list)
pids = pool.workers
np = length(pids)
n = length(list)
results = Vector{Any}(undef,n)
i = 1
nextidx() = (idx=i; i+=1; idx)
@sync begin
for p in pids
if p != myid() || np == 1
@async begin
while true
idx = nextidx()
if idx > n
break
end
results[idx] = remotecall_fetch(f, p, list[idx])
end
end
end
end
end
return results
end
ordered_pmap(f, c1,) = ordered_pmap(default_worker_pool(), f, c1)
ordered_pmap(f, c1, c...) = ordered_pmap(default_worker_pool(), a->f(a...), zip(c1,c))
ordered_pmap(p::WorkerPool, f, c1, c...) = ordered_pmap(p, a->f(a...),zip(c1,c))