1
votes

I have two files

test_file.jl

using Distributed

function inner_function(v)
    v_2 = 2 * v
    return v_2
end

function loop(N, v)
@sync @distributed for i in 1:N
    v_3 = inner_function(v)
    v_3[1] = i
    println(i)
    println(v_3)
end
end

test_file_call.jl

@everywhere include("test_file.jl")
v = [1 2 3 4]
loop(100,v_2)

When I run julia -p 2 test_file_call.jl, I get an error saying that

ERROR: LoadError: UndefVarError: v_2 not defined

I'm not sure why. v_2 is a variable created in a function and I've already used @everywhere include("test_file.jl") so Julia shouldn't say that the variable is undefined. Can I get a hint? Thank you!

1

1 Answers

2
votes

You use v_2 in loop(100, v_2) call, so Julia looks for v_2 in global scope and does not find it there. Probably you wanted to write loop(100, v) as you define v.