2016-11-03 3 views
1

私は別のモジュールでコードを使って並列処理を行う簡単なプログラムを書こうとしています。別々のモジュールでジュリア並列処理

@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 

i「はジュリアメイン持つ単一のプロセスで実行

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

main.jl:私は2つの別々のファイルに次のコードを持っています。 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 
+0

main.jlの '@everywhere importall other'が必要で、other.jlに@ everywhereは必要ありません –

+1

ありがとうございました!私はimportallステートメントでそれを必要としているとは思っていませんでした。 – ciric50

答えて

1

これは、現在の労働者のすべてにotherをロードしますmain.jl

@everywhere importall otherを試してみてください。 otherが通常のスクリプトやモジュール以外のものである必要はありません。したがって、other.jlに@everywhereは必要ありません。