问题描述
我希望对 SharedArray 的每一列进行操作的时间和内存效率最高的负载平衡应用程序,以生成相应的列,这些列正在就地修改预分配的输出 SharedArray。我应该如何改进以下代码?
using SharedArrays,distributed
nCores = length(Sys.cpu_info())
addprocs(nCores - 1);
@everywhere using SharedArrays,distributed
@everywhere addConstant = 10000;
@everywhere function divideColByMeanConstant(x)
return (x ./ mean(x)) .+ addConstant
end
inputMAT = SharedArray(rand(10000,20000))
outputMAT = SharedArray(Array{Float64,2}(undef,size(inputMAT)))
function Array2ArrayColumnwise_forloop!(output::SharedArray{Float64,2},operation::Function,input::SharedArray{Float64,rowRange::Array{Int64,1},colRange::Array{Int64,1})
@async @distributed for colInd in colRange
@views output[rowRange,colInd] = operation(input[rowRange,colInd])
end
end
rowRange = [1,4,6,8,10,15];
colRange = [1,5,7,15];
Array2ArrayColumnwise_forloop!(outputMAT,divideColByMeanConstant,inputMAT,rowRange,colRange)
提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)