Syntax error in parallel computing

I’m trying to learn parallel computing using Distributed and I tried the Pi computation as an example:

using Distributed
addprocs(4)
function points_inside(n)
    n_in= 0
    for i=1:n
        x,y= rand(), rand()
        n_in+= (x*x+ y*y)<= 1
    end
    return n_in
end

points_inside (generic function with 1 method)
In [8]:

function pi_p(n)
    p= nworkers()
    n_in= @distributed(+) for i=1:p
        points_inside(n/p)
    end
    return 4*n_in/n
end

and I get this syntax error:

syntax: "function" at In[8]:1 expected "end", got "for"

Stacktrace:
 [1] top-level scope
   @ In[8]:3
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
1 Like

add a space
@distributed (+)

2 Likes

oh yeah i didn’t pay attention to that it is working now.