-
Book Overview & Buying
-
Table Of Contents
Julia High Performance
By :
The low-level facilities that we saw in the previous section are quite flexible and very powerful. However, they leave a lot to be desired in terms of ease of use. Julia, therefore, has built-in set of higher-level programming tools that make it much easier to write parallel code. We will discuss some of them in the next section.
The @everywhere macro is used to run the same code in all the processes in the cluster. This is useful to set up the environment to run the actual parallel computation later. The following code loads the Distributions package and calls the rand method on all the nodes simultaneously, as follows:
julia> @everywhere using Distributions julia> @everywhere rand(Normal())
The @spawn macro is a simpler way to run a function in a remote process without having to specify the remote node or having to work through ambiguous syntax. Take a look at the following code:
julia> a=@spawn randn(5,5)^2
RemoteRef{Channel{Any}}(2,1...