2
我想并行运行一个函数,其中函数是通过字符串参数提供的。它首先从字符串解析为表达式,然后并行运行。在Julia中并行运行解析函数
的问题是,将字符串参数是不知道的所有工作进程。
我怎样才能使这项工作:
module test
function run(f)
@everywhere f_exp = eval(parse(f))
values = SharedArray(Float64,2)
@sync @parallel for i = 1:2
values[i] = f_exp(i)
end
return mean(values)
end
end
# RUN AS FOLLOWS
# @everywhere include("c:\\projects\\evaluator\\test.jl")
# test.run("function func(x) return 2*x end")
我也试过@everywhere f_exp = eval(parse("@everywhere $f"))
,虽然我没想到它的工作...它没有。
我该如何让每个过程都知道这个论点?
做@everywhere f
在函数运行的第一行还没有做任何事情。