使用 SharedArray 的并行 for 循环

问题描述

我希望对 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...