julia - 在工人 2 上:UndefVarError
问题描述
我正在尝试一个简单的 Julia 代码:
using Distributed
addprocs(1)
@everywhere include("count_heads.jl")
a = @spawn count_heads(100000000)
b = @spawn count_heads(100000000)
fetch(a)+fetch(b)
但是 count_heads.jl 包含以下函数:
function count_heads(n)
c::Int = 0
for i = 1:n
c += rand(Bool)
end
c
end
但是上面的代码显示了错误: On worker 2: UndefVarError: count_heads not defined
有谁知道如何解决这个错误??
解决方案
@spawn
已弃用,您应该@spawnat :any
改用:
a = @spawnat :any count_heads(100000000)
否则你的代码是完全正确的,我设法运行它。
很可能,在您的生产代码中,函数名称中有一些拼写错误,或者您之前运行@everywhere include("count_heads.jl")
过addprocs
推荐阅读
- sql - Postgres 不同的查询计划 Prod/QA
- python - 为什么底部打印乱序?
- scala - 抽象类 Scala。教程和匿名课程中的错误
- django - 自定义社交表单
- java - SpringBootTest javax.validation.ValidationException
- azure-devops - 在什么情况下 VSTS 会自动为现有的存储库目录创建一个新的存储库目录?
- html - 为什么我的样式表不能链接到索引?
- rust - 用 0 向左填充字符串的最简单方法是什么?
- javascript - Qualtrics“挑选、分组和排名”分组框高度
- php - PHP 正则表达式字符串提取与文本和逗号