This experiment is designed to show a pecularity in Julia'd scoping. Julia uses a layered scoping where the scope of the inner function has access to the values of the outer function. For example:
x=5; y=7; #Defined globally
function scopeTest(z)
x += z #Changes global value
y = Vector{Float64}(1) #Declares a variable, local scope
y[1] = 2
return x + y + z
end
However, what is happening here, and why?
using Distributed
addprocs(1)
function f1()
@distributed for i = 1:100
x = 10
if x < 100
x = x + 1
end
end
x = x + 100 + 10
return x
end
f1()
function f2()
@distributed for i = 1:100
x = 10
if x < 100
x = x + 1
end
end
return x
end
f2()