|
| 1 | + |
1 | 2 | """ |
2 | 3 | save_at(worker, sym, val) |
3 | 4 |
|
@@ -46,7 +47,7 @@ Get a value `val` from a remote `worker`; quoting of `val` works just as with |
46 | 47 | `save_at`. Returns a future with the requested value. |
47 | 48 | """ |
48 | 49 | function get_from(worker, val; mod = Main) |
49 | | - remotecall(() -> Base.eval(mod, :($val)), worker) |
| 50 | + remotecall(() -> Base.eval(mod, val), worker) |
50 | 51 | end |
51 | 52 |
|
52 | 53 | """ |
@@ -358,3 +359,41 @@ Decorate the symbol from `dInfo` with prefix and suffix. |
358 | 359 | function tmp_symbol(dInfo::Dinfo; prefix = "", suffix = "_tmp") |
359 | 360 | return tmp_symbol(dInfo.val, prefix = prefix, suffix = suffix) |
360 | 361 | end |
| 362 | + |
| 363 | +""" |
| 364 | + @remote module expr |
| 365 | +
|
| 366 | +A version of [`@remote`](@ref) that adds additional choice of the module for |
| 367 | +scope. |
| 368 | +""" |
| 369 | +macro remote(mod, x) |
| 370 | + :(Base.eval($mod, $(QuoteNode(x)))) |
| 371 | +end |
| 372 | + |
| 373 | +""" |
| 374 | + @remote expr |
| 375 | +
|
| 376 | +In a function that will get evaluated on a remote worker, this ensures the |
| 377 | +evaluation scope of the expression `expr` (usually a variable) is taken on |
| 378 | +the remote side, preventing namespace clash with the local session. |
| 379 | +
|
| 380 | +This is mainly useful for making the functions from `Distributed` package (such |
| 381 | +as `pmap` and `remotecall`) work with the data stored by `DistributedData` |
| 382 | +package. |
| 383 | +
|
| 384 | +Internally, this is handled by wrapping in `eval`. |
| 385 | +
|
| 386 | +# Example |
| 387 | +``` |
| 388 | +julia> save_at(2, :x, 321) |
| 389 | +Future(2, 1, 162, nothing) |
| 390 | +
|
| 391 | +julia> let x=123 |
| 392 | + remotecall_fetch(() -> x + (@remote x), 2) |
| 393 | + end |
| 394 | +444 |
| 395 | +``` |
| 396 | +""" |
| 397 | +macro remote(x) |
| 398 | + :(@remote Main $x) |
| 399 | +end |
0 commit comments