From c603a7941089cbb11bda70ef67743b468fce21e5 Mon Sep 17 00:00:00 2001 From: Amit Murthy Date: Thu, 21 Apr 2016 15:03:34 +0530 Subject: [PATCH] document use of @eval with @everywhere for broadcast of local variables. (#15960) Proposed by Ben Arthur (@bjarthur) --- base/docs/helpdb/Base.jl | 14 +++++++++++++- doc/stdlib/parallel.rst | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 35c06a6709730..a1edb8279b6ba 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -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 diff --git a/doc/stdlib/parallel.rst b/doc/stdlib/parallel.rst index 27c1cd9c8cc25..39c4b21660dd9 100644 --- a/doc/stdlib/parallel.rst +++ b/doc/stdlib/parallel.rst @@ -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)