gpt4 book ai didi

parallel-processing - MMap 和 SharedArrays

转载 作者:行者123 更新时间:2023-12-04 10:57:56 27 4
gpt4 key购买 nike

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

@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

此函数正被迭代过程中的另一个函数调用。在第一次迭代中它有效,但在第二次迭代中我收到以下错误
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,我希望它可以使事情变得更加透明:
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



随着错误:
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

最佳答案

这是一个与您的场景类似的场景的 MWE 模式:

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();

关于parallel-processing - MMap 和 SharedArrays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59060050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com