Hi, I am trying to use multithreading to make a loop parallel. That loop makes a call to a function to build the model and then optimise it. So individual iterations are independent, except that results are stored in arrays. Essentially inside the loop bound on one of the variables is being changed and the problem is is optimised at each iteration.
The actual problem is complicated and I have not been able to produce a MWE to produce that exact error. Below is a simplified example to give an idea about the code for the actual problem and what may be causing an error. This code sometimes produces an error (i.e. if you run it few times) which I am not sure whether is related to the problem being infeasible or multithreading.
I have also given the error message that I get on the actual problem at the bottom.
What may be causing the error on the actual problem (message shown at the bottom)? How can I fix it?
using DataFrames, JuMP, Clp, CSV
function generate_data(m)
Values = rand(20.0:140.0, m)
return Values
end
function build(c)
model = Model(Clp.Optimizer)
set_optimizer_attribute(model, MOI.Silent(), true)
@variable(model, x[1:length(c)] >=0 )
@variable(model, y <=10 )
@objective(model, Min, sum(c[i] * x[i] for i = 1:length(c))-y)
@constraint(model, con1, sum(x[i] for i = 1:length(c)) == 1)
@constraint(model, con2, sum(c[i] * x[i] for i = 1:length(c)) <= 100)
return model, x, y
end
function summation(Values)
A= cumsum(Values, dims =1)
return A
end
function some_thing(Values)
B = sum(Values, dims =1)
return B
end
function multithread_run(n,m)
A_id = Array{Float64,2}(undef, m,n)
B_id = Vector{Float64}(undef,n)
x_id = Array{Float64,2}(undef, m,n)
Threads.@threads for i in 1:n
Values = generate_data(m)
bound = (i-1)*30 / n
model, x, y = build(Values)
set_upper_bound(y,bound)
optimize!(model)
x1 = JuMP.value.(x)
A = summation(x1)
B = some_thing(x1)
A_id[:,i] = A
B_id[i] = B[1]
x_id[:,i] = x1
end
df1 = DataFrame(x_id)
df2 = DataFrame(A_id)
df3 = DataFrame(ID=1:n,some_thing = B_id)
CSV.write("DataFrame1.csv",df1)
CSV.write("DataFrame2.csv",df2)
CSV.write("DataFrame3.csv",df3)
return A_id, x_id, B_id
end
Running multithread_run(10,3)
few times, give the following error. I don’t know whether that is arising from multithreading or just because the problem is infeasible.
ERROR: TaskFailedException:
Primal solution not available
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] get(::Clp.Optimizer, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at C:\Users\.julia\packages\Clp\3ZgbR\src\MOI_wrapper\MOI_wrapper.jl:467
[3] get(::MathOptInterface.Utilities.CachingOptimizer{Clp.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at C:\Users \.julia\packages\MathOptInterface\k7UUH\src\Utilities\cachingoptimizer.jl:605
[4] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Clp.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at C:\Users \.julia\packages\MathOptInterface\k7UUH\src\Bridges\bridge_optimizer.jl:808
[5] get(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at C:\Users\.julia\packages\MathOptInterface\k7UUH\src\Utilities\cachingoptimizer.jl:605
[6] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at C:\Users \.julia\packages\JuMP\e0Uc2\src\JuMP.jl:848
[7] get(::Model, ::MathOptInterface.VariablePrimal, ::VariableRef) at C:\Users\.julia\packages\JuMP\e0Uc2\src\JuMP.jl:878
[8] value(::VariableRef; result::Int64) at C:\Users\.julia\packages\JuMP\e0Uc2\src\variables.jl:767
[9] value at C:\Users\.julia\packages\JuMP\e0Uc2\src\variables.jl:767 [inlined]
[10] _broadcast_getindex_evalf at .\broadcast.jl:648 [inlined]
[11] _broadcast_getindex at .\broadcast.jl:621 [inlined]
[12] getindex at .\broadcast.jl:575 [inlined]
[13] macro expansion at .\broadcast.jl:932 [inlined]
[14] macro expansion at .\simdloop.jl:77 [inlined]
[15] copyto! at .\broadcast.jl:931 [inlined]
[16] copyto! at .\broadcast.jl:886 [inlined]
[17] copy at .\broadcast.jl:862 [inlined]
[18] materialize at .\broadcast.jl:837 [inlined]
[19] macro expansion at C:\Users\Documents\Julia\Multithreading\multithreadingOpt.jl:66 [inlined]
[20] (::var"#128#threadsfor_fun#15"{Int64,Int64,Array{Float64,2},Array{Float64,1},Array{Float64,2},UnitRange{Int64}})(::Bool) at .\threadingconstructs.jl:81
[21] (::var"#128#threadsfor_fun#15"{Int64,Int64,Array{Float64,2},Array{Float64,1},Array{Float64,2},UnitRange{Int64}})() at .\threadingconstructs.jl:48
Error on the actual problem
Usually I get the following error when I make the for loop multithreaded
ERROR: TaskFailedException:
OptimizeNotCalled()
Stacktrace:
[1] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at C:\Users\.julia\packages\JuMP\e0Uc2\src\JuMP.jl:846
[2] get(::Model, ::MathOptInterface.VariablePrimal, ::VariableRef) at C:\Users\.julia\packages\JuMP\e0Uc2\src\JuMP.jl:878
[3] value(::VariableRef; result::Int64) at C:\Users\.julia\packages\JuMP\e0Uc2\src\variables.jl:767
[4] value at C:\Users\.julia\packages\JuMP\e0Uc2\src\variables.jl:767 [inlined]
[5] _broadcast_getindex_evalf at .\broadcast.jl:648 [inlined]
[6] _broadcast_getindex at .\broadcast.jl:621 [inlined]
[7] getindex at .\broadcast.jl:575 [inlined]
[8] macro expansion at .\broadcast.jl:932 [inlined]
[9] macro expansion at .\simdloop.jl:77 [inlined]
[10] copyto! at .\broadcast.jl:931 [inlined]
[11] copyto! at .\broadcast.jl:886 [inlined]
[12] copy at .\broadcast.jl:862 [inlined]
[13] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(value),Tuple{Array{VariableRef,1}}}) at .\broadcast.jl:837
[14] macro expansion at C:\Users\Documents\Julia\Op.jl:150 [inlined]
[15] (::var"#238#threadsfor_fun#32"{Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Array{Float64,1},Array{Float64,2},Float64,Int64,Int64,Array{Float64,2},Float64,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,2},UnitRange{Int64}})(::Bool) at .\threadingconstructs.jl:81
[16] (::var"#238#threadsfor_fun#32"{Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}},Array{Float64,1},Array{Float64,2},Float64,Int64,Int64,Array{Float64,2},Float64,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,2},UnitRange{Int64}})() at .\threadingconstructs.jl:48
Stacktrace:
[1] wait at .\task.jl:267 [inlined]
[2] threading_run(::Function) at .\threadingconstructs.jl:34
[3] macro expansion at .\threadingconstructs.jl:93 [inlined]
[4] run_eff_front(::String, ::String, ::String, ::String, ::String, ::String; test1_threshold::Float64) at C:\Users\Documents\Julia\Op.jl:143
[5] top-level scope at none:1
Sometimes, I get a different error on the actual code. See example below:
Exception: EXCEPTION_ACCESS_VIOLATION at 0x70a1cb6a -- at 0x70a1cb6a -- g report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x70a1cb6a -- at 0x70a1cb6a -- OLATION with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x70a1cb6a -- at 0x70a1cb6a -- OLATIONClp_logLevel at C:\Users\Clp_logLevel at C:\Users\.julia\artifacts\b6212337a44c46db8ea6bd090bff66ffe4b3d3d3\bin\libClp-1.dll (unknown line)
in expression starting at none:1
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x391e0d0 -- (julia) realloc: Invalid argument
signal (22): SIGABRT
port with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLAin expression starting at at 0x7ffd9b93557a -- at 0x7ffd9b93557a -- at none:1
memset at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
in expression starting at none:1
memset at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
_ZN4llvm15DWARFUnitVector12addUnitsImplERNS_12DWARFContextERKNS_11DWARFObjectERKNS_12DWARFSectionEPKNS_16DWARFDebugAbbrevEPS7_SC_NS_9StringRefES8_SC_S8_bbbNS_16DWARFSectionKindE at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\LLVM.dll (unknown line)
in expression starting at none:1
EM32\ntdll.dll (unknown line)
in expression starting at none:1
RtlAllocateHeap at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
malloc at C:\WINDOWS\System32\msvcrt.dll (unknown line)
Znwy at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\libstdc++-6.dll (unknown line)
ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_mutateEyyPKcy at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\libstdc++-6.dll (unknown line)
ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_replaceEyyPKcy at C:\Users\ \AppData\Local\Programs\Julia 1.5.2\bin\libstdc++-6.dll (unknown line)
ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE3strEv at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\libstdc++-6.dll (unknown line)
crt_sig_handler at /cygdrive/d/buildbot/worker/package_win64/build/src\signals-win.c:92
raise at C:\WINDOWS\System32\msvcrt.dll (unknown line)
abort at C:\WINDOWS\System32\msvcrt.dll (unknown line)
_ZN4llvm15DWARFUnitVector12addUnitsImplERNS_12DWARFContextERKNS_11DWARFObjectERKNS_12DWARFSectionEPKNS_16DWARFDebugAbbrevEPS7_SC_NS_9StringRefES8_SC_S8_bbbNS_16DWARFSectionKindE at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\LLVM.dll (unknown line)
_ZN4llvm15DWARFUnitVector18addUnitsForSectionERNS_12DWARFContextERKNS_12DWARFSectionENS_16DWARFSectionKindE at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\LLVM.dll (unknown line)
realloc_s at /cygdrive/d/buildbot/worker/package_win64/build/src/support\dtypes.h:379 [inlined]
realloc_s at /cygdrive/d/buildbot/worker/package_win64/build/src/support\dtypes.h:371 [inlined]
jl_copy_str at /cygdrive/d/buildbot/worker/package_win64/build/src\julia_internal.h:818 [inlined]
jl_dylib_DI_for_fptr at /cygdrive/d/buildbot/worker/package_win64/build/src\debuginfo.cpp:1098
jl_getDylibFunctionInfo at /cygdrive/d/buildbot/worker/package_win64/build/src\debuginfo.cpp:1176 [inlined]
jl_getFunctionInfo at /cygdrive/d/buildbot/worker/package_win64/build/src\debuginfo.cpp:1243
_ZNK12_GLOBAL__N_116DWARFObjInMemory19forEachInfoSectionsEN4llvm12function_refIFvRKNS1_12DWARFSectionEEEE at C:\Users\AppData\Local\Programs\Julia 1.5.2\bin\LLVM.dll (unknown line)
jl_print_native_codeloc at /cygdrive/d/buildbot/worker/package_win64/build/src\stackwalk.c:652
jl_critical_error at /cygdrive/d/buildbot/worker/package_win64/build/src\signal-handling.c:239 [inlined]
jl_exception_handler at /cygdrive/d/buildbot/worker/package_win64/build/src\signals-win.c:302
ams\Julia 1.5.2\bin\LLVM.dll (unknown line)
jl_exception_handler at /cygdrive/d/buildbot/worker/package_win64/build/src\signals-win.c:302
__julia_personality at /cygdrive/d/buildbot/worker/package_win64/build/src/support\win32_ucontext.c:28
_chkstk at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
RtlRaiseException at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
KiUserExceptionDispatcher at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
The essential steps in the actual problem are similar to the question I asked here. The difference is that in this question multithreading is being used for an optimisation problem.