首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MMap和SharedArrays

MMap和SharedArrays
EN

Stack Overflow用户
提问于 2019-11-27 06:05:09
回答 1查看 149关注 0票数 2

在并行化某些函数时,我遇到了一个非常奇怪的问题。我知道我应该发布一个MWE,但我不能在一个简单的问题中重现这个问题。

代码语言:javascript
复制
@everywhere function simulSample(Profits,ν,J,TerminalT,RelevantT,N,S,params,thresh;RelevantPer=RelevantPeriod)
    Dₑ = rand([0],J,1) # Final Condition
    Dᵢ = rand([0],J,1) # Initial Condition
    tempData=SharedArray{Int8}(J,RelevantT,S*N)
    @inbounds @sync @distributed for n=1:S*N
    #for n=1:N
        #println(n)
        tempData[:,:,n]=solver(Dᵢ,Dₑ,Profits[:,:,n],continent,cont_lang,language,J,TerminalT,RelevantT,RelevantPeriod,params,thresh,ν[:,:,n])
    end
    return tempData
end

此函数正由另一个函数在迭代过程中调用。在第一次迭代中,它可以工作,但在第二次迭代中,我得到了以下错误

代码语言:javascript
复制
SystemError: mmap: The operation completed successfully. 
#windowserror#45(::Nothing, ::typeof(Base.windowserror), ::Symbol, ::Bool) at error.jl:148
windowserror at error.jl:148 [inlined]
#mmap#1(::Bool, ::Bool, ::typeof(Mmap.mmap), ::Mmap.Anonymous, ::Type{Array{Int8,3}}, ::Tuple{Int64,Int64,Int64}, ::Int64) at Mmap.jl:221
mmap(::Mmap.Anonymous, ::Type{Array{Int8,3}}, ::Tuple{Int64,Int64,Int64}, ::Int64) at Mmap.jl:186
_shm_mmap_array(::Type, ::Tuple{Int64,Int64,Int64}, ::String, ::UInt16) at SharedArrays.jl:670
shm_mmap_array(::Type, ::Tuple{Int64,Int64,Int64}, ::String, ::UInt16) at SharedArrays.jl:649
#call#3(::Bool, ::Array{Int64,1}, ::Type{SharedArray{Int8,3}}, ::Tuple{Int64,Int64,Int64}) at SharedArrays.jl:118
Type at SharedArrays.jl:105 [inlined]
#call#10 at SharedArrays.jl:161 [inlined]
Type at SharedArrays.jl:161 [inlined]
#call#15 at SharedArrays.jl:171 [inlined]
SharedArray{Int8,N} where N(::Int64, ::Int64, ::Int64) at SharedArrays.jl:171
#simulatedMoments#67(::Float64, ::Int64, ::typeof(simulatedMoments), ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Int64, ::Int64, ::Int64, ::Int64, ::Array{Any,3}, ::Array{Float64,1}, ::Int64, ::Int64, ::Int64, ::Float64) at 13-Estimation_Stable.jl:1255
simulatedMoments at 13-Estimation_Stable.jl:1232 [inlined]
#gmm_fun#70(::Float64, ::Float64, ::Int64, ::typeof(gmm_fun), ::SharedArray{Int64,3}, ::Array{Any,3}, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Int64, ::Int64, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Float64,2}) at 13-Estimation_Stable.jl:1297
gmm_fun(::SharedArray{Int64,3}, ::Array{Any,3}, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Int64, ::Int64, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Float64,4}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Array,1}, ::Array{Float64,2}) at 13-Estimation_Stable.jl:1284
obj_function_final(::Array{Float64,1}, ::Array{Any,1}) at 13-Estimation_Stable.jl:1370
top-level scope at util.jl:156

我添加了一个带有错误的MWE,希望它能让事情变得更透明:

代码语言:javascript
复制
using Distributed, SharedArrays

rmprocs()
addprocs()
big_array = rand(100,11,20000)

function donothing(a)
   shared_array = convert(SharedArray,a)
end

for i=1:1000
    donothing(big_array)
end

出现以下错误:

代码语言:javascript
复制
SystemError: mmap: The operation completed successfully. 
#windowserror#45(::Nothing, ::typeof(Base.windowserror), ::Symbol, ::Bool) at error.jl:148
windowserror at error.jl:148 [inlined]
#mmap#1(::Bool, ::Bool, ::typeof(Mmap.mmap), ::Mmap.Anonymous, ::Type{Array{Float64,3}}, ::Tuple{Int64,Int64,Int64}, ::Int64) at Mmap.jl:218
mmap(::Mmap.Anonymous, ::Type{Array{Float64,3}}, ::Tuple{Int64,Int64,Int64}, ::Int64) at Mmap.jl:186
_shm_mmap_array(::Type, ::Tuple{Int64,Int64,Int64}, ::String, ::UInt16) at SharedArrays.jl:670
shm_mmap_array(::Type, ::Tuple{Int64,Int64,Int64}, ::String, ::UInt16) at SharedArrays.jl:649
#call#3(::Bool, ::Array{Int64,1}, ::Type{SharedArray{Float64,3}}, ::Tuple{Int64,Int64,Int64}) at SharedArrays.jl:118
Type at SharedArrays.jl:105 [inlined]
Type at SharedArrays.jl:357 [inlined]
convert at SharedArrays.jl:369 [inlined]
donothing(::Array{Float64,3}) at mwproblem.jl:8
top-level scope at mwproblem.jl:12
EN

回答 1

Stack Overflow用户

发布于 2019-11-27 08:15:28

以下是一个场景的MWE模式,它应该与您的场景类似:

代码语言:javascript
复制
using Distributed
addprocs(4)
using SharedArrays


@everywhere function compute()
    rand() + myid()*100
end

function dothejob()
    s = SharedArray(zeros(10000000))
    @sync @distributed for i in 1:10000000
        s[i] = compute()
    end
    s
end

myres = dothejob();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59060050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档