Parallel processing 独立模块中的Julia并行处理

Parallel processing 独立模块中的Julia并行处理,parallel-processing,julia,Parallel Processing,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

我正在尝试编写一个简单的程序,在不同的模块中使用代码进行并行处理。我在两个单独的文件中有以下代码:

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
@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
other.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
@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-main.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
ERROR:LoadError:LoadError:在辅助进程2上:
UndefVarError:##5#7未定义
在./serialize.jl:823处的反序列化\u数据类型中
在句柄中,在./serialize.jl:571处反序列化
在./multi.jl:120处反序列化消息
在./multi.jl:1317处的消息\u handler\u循环中
进程中\u tcp\u流位于./multi.jl:1276
在#618 at./event.jl:68
在#remotecall_fetch#606(::数组{Any,1},::函数,::函数,::Base.Worker)中./multi.jl:1070
在./multi.jl:1062处的remotecall_fetch(::Function,::Base.Worker)中
在#remotecall_fetch#609(::数组{Any,1},::函数,::函数,::Int64)at./multi.jl:1080
在远程调用中,./multi.jl:1080处获取(::函数,::Int64)
in(::other.#6#8)at./multi.jl:1959
…和其他3个例外。
在./task.jl:311处同步
宏观扩张;at./multi.jl:1968[内联]
匿名地址:/?
在./boot.jl:234的eval(::模块,::任意)中
在(::#1#3)at./multi.jl:1957
在./task.jl:311处同步
宏观扩张;at./multi.jl:1968[内联]
匿名地址:/?
在./loading.jl:488处的include_from_node1(::字符串)
在./boot.jl:234的eval(::模块,::任意)中
在./loading.jl:409处需要(::符号)
在./loading.jl:488处的include_from_node1(::字符串)
进程中的_选项(::Base.jl选项)位于./client.jl:262
在_start()中./client.jl:318
在从第1行开始的表达式中加载/mnt/mint320/home/bmaier/BillHome/Programs/Julia/parallel/modules/other.jl时
在从第5行开始的表达式中加载/mnt/mint320/home/bmaier/BillHome/Programs/Julia/parallel/modules/main.jl时

试试main.jl中的
@where-importall-other


这将在所有当前工作人员上加载
other
。不要求
other
必须是普通脚本或模块以外的任何内容,因此您不需要other.jl中的
@everywhere

您需要main.jl中的“@everywhere importall other”,也不需要other.jl中的@everywhere's。谢谢,这很有效!我不会猜到我需要它在importall声明上。