并行处理:@无处不在,分布和类型 [英] Parallel processing: @everywhere, distributions and types

查看:71
本文介绍了并行处理:@无处不在,分布和类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在Julia中学习并行处理,但遇到了一个我不太了解如何解决的问题.

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

julia -p 4执行Julia之后,我想在所有进程中加载​​Distributions模块,并且我想定义一个依赖于Distributions的Type.

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:

错误:LoadError:UndefVarError:分布未定义 在include_from_node1(:: String)在./loading.jl:488 在/Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib中的include_from_node1(:: String)中: 在加载/***/test.jl时,从第4行开始的表达式中

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.

推荐答案

@everywhere something在所有过程的主模块中评估something.并且在这种情况下,该错误不在test模块中,因此在第二种情况下而不是在第一种情况下出现错误.

@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.

也许

@everywhere module test
    using Distributions

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

    export TypeDistrib
end

是什么意思.

这篇关于并行处理:@无处不在,分布和类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆