Skip to content

Commit

Permalink
document use of @eval with @Everywhere for broadcast of local variabl…
Browse files Browse the repository at this point in the history
…es. (#15960)

Proposed by Ben Arthur (@bjarthur)
  • Loading branch information
amitmurthy committed Apr 21, 2016
1 parent 2e4513b commit c603a79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,19 @@ download
@everywhere
Execute an expression on all processes. Errors on any of the processes are collected into a
`CompositeException` and thrown.
`CompositeException` and thrown. For example :
@everywhere bar=1
will define `bar` under module `Main` on all processes.
Unlike `@spawn` and `@spawnat`, `@everywhere` does not capture any local variables. Prefixing
`@everywhere` with `@eval` allows us to broadcast local variables using interpolation :
foo = 1
@eval @everywhere bar=\$foo
"""
:@everywhere

Expand Down
15 changes: 14 additions & 1 deletion doc/stdlib/parallel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,20 @@ General Parallel Computing Support

.. Docstring generated from Julia source
Execute an expression on all processes. Errors on any of the processes are collected into a ``CompositeException`` and thrown.
Execute an expression on all processes. Errors on any of the processes are collected into a ``CompositeException`` and thrown. For example :

.. code-block:: julia
@everywhere bar=1
will define ``bar`` under module ``Main`` on all processes.

Unlike ``@spawn`` and ``@spawnat``\ , ``@everywhere`` does not capture any local variables. Prefixing ``@everywhere`` with ``@eval`` allows us to broadcast local variables using interpolation :

.. code-block:: julia
foo = 1
@eval @everywhere bar=$foo
.. function:: Base.remoteref_id(r::AbstractRemoteRef) -> (whence, id)

Expand Down

0 comments on commit c603a79

Please sign in to comment.