Skip to content

Commit d112c36

Browse files
committed
Merge pull request #117 from JuliaParallel/anj/main
Evaluate expressions in @mpi_do in Main module
2 parents c546ee8 + f7c81e0 commit d112c36

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/cman.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function mpi_do(mgr::MPIManager, expr)
444444
!mgr.initialized && wait(mgr.cond_initialized)
445445
jpids = keys(mgr.j2mpi)
446446
refs = cell(length(jpids))
447-
for (i,p) in enumerate(filter(x->x!=myid(), jpids))
447+
for (i,p) in enumerate(filter(x -> x != myid(), jpids))
448448
refs[i] = remotecall(expr, p)
449449
end
450450
# Execution on local process should be last, since it can block the main
@@ -458,7 +458,7 @@ function mpi_do(mgr::MPIManager, expr)
458458
for r in refs
459459
@async begin
460460
resp = remotecall_fetch(r.where, r) do rr
461-
wrkr_result = take!(rr)
461+
wrkr_result = rr[]
462462
# Only return result if it is an exception, i.e. don't
463463
# return a valid result of a worker computation. This is
464464
# a mpi_do and not mpi_callfetch.
@@ -472,8 +472,11 @@ function mpi_do(mgr::MPIManager, expr)
472472
end
473473

474474
macro mpi_do(mgr, expr)
475-
expr = Base.localize_vars(:(()->$expr), false)
476-
:(mpi_do($(esc(mgr)), $(esc(expr))))
475+
quote
476+
# Evaluate expression in Main module
477+
thunk = () -> (eval(Main, $(Expr(:quote, expr))); nothing)
478+
mpi_do($(esc(mgr)), thunk)
479+
end
477480
end
478481

479482
# All managed Julia processes

test/test_cman_julia.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ s = @parallel (+) for i in 1:10
2424
i^2
2525
end
2626
@test s == 385
27+
28+
@mpi_do mgr n = 2
29+
@mpi_do mgr n + 2

0 commit comments

Comments
 (0)