Skip to content

Commit c603a79

Browse files
committed
document use of @eval with @Everywhere for broadcast of local variables. (#15960)
Proposed by Ben Arthur (@bjarthur)
1 parent 2e4513b commit c603a79

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

base/docs/helpdb/Base.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,19 @@ download
144144
@everywhere
145145
146146
Execute an expression on all processes. Errors on any of the processes are collected into a
147-
`CompositeException` and thrown.
147+
`CompositeException` and thrown. For example :
148+
149+
@everywhere bar=1
150+
151+
will define `bar` under module `Main` on all processes.
152+
153+
Unlike `@spawn` and `@spawnat`, `@everywhere` does not capture any local variables. Prefixing
154+
`@everywhere` with `@eval` allows us to broadcast local variables using interpolation :
155+
156+
foo = 1
157+
@eval @everywhere bar=\$foo
158+
159+
148160
"""
149161
:@everywhere
150162

doc/stdlib/parallel.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,20 @@ General Parallel Computing Support
502502

503503
.. Docstring generated from Julia source
504504
505-
Execute an expression on all processes. Errors on any of the processes are collected into a ``CompositeException`` and thrown.
505+
Execute an expression on all processes. Errors on any of the processes are collected into a ``CompositeException`` and thrown. For example :
506+
507+
.. code-block:: julia
508+
509+
@everywhere bar=1
510+
511+
will define ``bar`` under module ``Main`` on all processes.
512+
513+
Unlike ``@spawn`` and ``@spawnat``\ , ``@everywhere`` does not capture any local variables. Prefixing ``@everywhere`` with ``@eval`` allows us to broadcast local variables using interpolation :
514+
515+
.. code-block:: julia
516+
517+
foo = 1
518+
@eval @everywhere bar=$foo
506519
507520
.. function:: Base.remoteref_id(r::AbstractRemoteRef) -> (whence, id)
508521

0 commit comments

Comments
 (0)