Я пытаюсь написать простую программу для параллельной обработки с кодом в отдельных модулях. У меня есть следующий код в двух отдельных файлах:Julia параллельная обработка в отдельных модулях
main.jl
push!(LOAD_PATH, ".")
#using other # This doesn't work either
importall other
np = 4
b = [Bounds(k, k+8) for k in 1:np]
fut = Array{Future}(np)
for k = 1:np
fut[k] = @spawn center(b[k])
end
for k = 1:np
xc = fetch(fut[k])
println("Center for k ", k, " is ", xc)
end
other.jl
@everywhere module other
export Bounds
export center
@everywhere type Bounds
x1::Int
x2::Int
end
@everywhere function center(bound::Bounds)
return (bound.x1 + bound.x2)/2
end
end
Когда я бегу с одного процесса с «JuLiA магистралью. jl "он работает без ошибок, но если я попытаюсь добавить процессы с" julia -p4 main.jl ", я получаю ошибку ниже. Похоже, что дополнительные процессы не могут видеть код в other.jl, но у меня есть макрос @everywhere во всех подходящих местах. В чем проблема?
ERROR: LoadError: LoadError: On worker 2:
UndefVarError: ##5#7 not defined
in deserialize_datatype at ./serialize.jl:823
in handle_deserialize at ./serialize.jl:571
in deserialize_msg at ./multi.jl:120
in message_handler_loop at ./multi.jl:1317
in process_tcp_streams at ./multi.jl:1276
in #618 at ./event.jl:68
in #remotecall_fetch#606(::Array{Any,1}, ::Function, ::Function, ::Base.Worker) at ./multi.jl:1070
in remotecall_fetch(::Function, ::Base.Worker) at ./multi.jl:1062
in #remotecall_fetch#609(::Array{Any,1}, ::Function, ::Function, ::Int64) at ./multi.jl:1080
in remotecall_fetch(::Function, ::Int64) at ./multi.jl:1080
in (::other.##6#8)() at ./multi.jl:1959
...and 3 other exceptions.
in sync_end() at ./task.jl:311
in macro expansion; at ./multi.jl:1968 [inlined]
in anonymous at ./<missing>:?
in eval(::Module, ::Any) at ./boot.jl:234
in (::##1#3)() at ./multi.jl:1957
in sync_end() at ./task.jl:311
in macro expansion; at ./multi.jl:1968 [inlined]
in anonymous at ./<missing>:?
in include_from_node1(::String) at ./loading.jl:488
in eval(::Module, ::Any) at ./boot.jl:234
in require(::Symbol) at ./loading.jl:409
in include_from_node1(::String) at ./loading.jl:488
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
while loading /mnt/mint320/home/bmaier/BillHome/Programs/Julia/parallel/modules/other.jl, in expression starting on line 1
while loading /mnt/mint320/home/bmaier/BillHome/Programs/Julia/parallel/modules/main.jl, in expression starting on line 5
Вам нужно «@everywhere importall other» в main.jl, и вам не нужно @ везде в other.jl –
Спасибо, это сработало! Я бы не догадался, что мне нужно это в заявлении importall. – ciric50