Parallel processing: @everywhere, distributions an

2019-07-04 21:58发布

I have recently started studying parallel processing in Julia and I am having an issue which I don't really understand how to fix.

After having executed Julia with julia -p 4 I want to load the Distributions module in all the processes and I would like to define a Type which depends on Distributions.

The following apparently works correctly when I include it:

 @everywhere using Distributions

 type TypeDistrib{T <: Float64}
      d::Distributions.Normal{T}
 end

If I write exactly the same code as a module, then it doesn't:

 module test

    @everywhere using Distributions

    type TypeDistrib{T <: Float64}
         d::Distributions.Normal{T}
    end

    export TypeDistrib
 end

The above gives the following error message:

ERROR: LoadError: UndefVarError: Distributions not defined in include_from_node1(::String) at ./loading.jl:488 in include_from_node1(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:? while loading /***/test.jl, in expression starting on line 4

Would you please clarify what I am not doing correctly here?

Note: I replaced the full path in the error message with *** since it was confusing.

1条回答
迷人小祖宗
2楼-- · 2019-07-04 22:53

@everywhere something evaluates something in the Main module across all processes. And in this case, not in test module, and therefore the error in the second case and not in the first.

Perhaps

@everywhere module test
    using Distributions

    type TypeDistrib{T <: Float64}
        d::Distributions.Normal{T}
    end

    export TypeDistrib
end

does what is meant.

查看更多
登录 后发表回答