LoadError @parallel

Hi,

I’m new to Julia (just installed it yesterday on Ubuntu 18.04) and I ran into a problem. No matter what simple example code using the @parallel macro I download, I don’t get it working. For instance, the code

function p_rand()
    n = 10^4
    x = @parallel (+) for i in 1:n
        sum(rand(10^4))
    end
    x / n
end

p_rand()

results in

jeroend:~$ julia -p 4 test.jl 
ERROR: LoadError: LoadError: UndefVarError: @parallel not defined
Stacktrace:
 [1] top-level scope
 [2] include at ./boot.jl:317 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1038
 [4] include(::Module, ::String) at ./sysimg.jl:29
 [5] exec_options(::Base.JLOptions) at ./client.jl:229
 [6] _start() at ./client.jl:421
in expression starting at /home/jeroend/test.jl:3
in expression starting at /home/jeroend/test.jl:1

Of course I tried googling “parallel not defined”, but that doesn’t produce any helpful answers. I must be making a stupid mistake, but I can’t figure it out. Is there anyone who could help me out?

Jeroen

1 Like

Welcome to Julia!!!

You need to import it via using Distributed as @parallel has been moved to there with Julia 1.0. (Running this in Julia 0.7 will tell you this.)

PS: have a look at PSA: how to quote code with backticks

Thank you very much for the quick reply!
Next time I’ll try to quote the code correctly :slight_smile:

I added a line

using Distributed

to the top of the code, but still get the same error message…

Hasn’t it been renamed to @distributed?

4 Likes

Thanks!
Replaced @parallel by @distributed and the errors are gone!

2 Likes

You might want to consider using 0.7 for now if you’re running a lot of code that was written on older Julia versions, as it shows you deprecation warnings where v1.0 errors out: PSA: use Julia 0.7 if you are upgrading

2 Likes