# Multithreading unstable with JuMP

**URL:** <https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, multithreading\
**Created:** [November 3, 2020, 1:05am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494 "2020-11-03T01:05:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 3, 2020, 1:05am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/1 "2020-11-03T01:05:54Z")

</div>

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?**

```julia
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.

```julia
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

```julia
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:

```nohighlight
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](https://discourse.julialang.org/t/multithreading-of-a-simple-loop/49478/5). The difference is that in this question multithreading is being used for an optimisation problem.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 3, 2020, 7:05pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/2 "2020-11-03T19:05:36Z")

</div>

Sometimes your model is infeasible and does not have a solution.

After `optimize!`, you should check `termination_status(model) == MOI.OPTIMAL` and/or `primal_status(model) == MOI.FEASIBLE_POINT` before accessing `value.(x)`.

Documentation: [https://jump.dev/JuMP.jl/stable/solutions/#Obtaining-solutions-1](https://jump.dev/JuMP.jl/stable/solutions/#Obtaining-solutions-1)

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 3, 2020, 7:25pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/3 "2020-11-03T19:25:44Z")

</div>

> [@odow](#):
>
> Sometimes your model is infeasible and does not have a solution.

That makes sense for the example of the code I provided. The bit I am struggling is with the error I am getting on my actual problem for which I have not been able to put together a MWE.

> [@JohnZ](#):
>
> ```julia
> ERROR: TaskFailedException:
> OptimizeNotCalled()
> 
> ```

I get this error on the actual problem when I use the `@threads` macro before the for loop. The code for this optimisation problem is more complex but the loop where I am trying to use multithreading is doing operations in a very similar manner to the example code provided above.

Does this error message suggest a problem with the use of `@threads` macro? In serial the same code runs without any issues.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 3, 2020, 7:33pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/4 "2020-11-03T19:33:10Z")

</div>

I don’t think we can provide advice without a MWE.

`OptimizeNotCalled` suggests you are attempting querying the solution of a variable before calling `optimize!`.

Note that every thread should have a separate copy of the model, and that you cannot pass a model between threads.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 3, 2020, 7:37pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/5 "2020-11-03T19:37:29Z")

</div>

> [@odow](#):
>
> I don’t think we can provide advice without a MWE.

Ok. I will try to create a MWE that reproduces this error and post it here.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 3, 2020, 11:48pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/6 "2020-11-03T23:48:25Z")

</div>

> [@JohnZ](#):
>
> ```julia
> 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.
> 
> ```

Errors similar to the one I get has been reported by others. I think it may be a bug in multithreading.

> [@Multi-thread issue on Windows 10 home or libuv?](https://discourse.julialang.org/t/multi-thread-issue-on-windows-10-home-or-libuv/49089):
>
> Hello, has anyone experienced multi-thread issue on Windows? Just installed Julia on brand new laptop, Windows 10 Home, and running a test script where JULIA\_NUM\_THREADS=1 works fine, but the same after setting JULIA\_NUM\_THREADS=4 results in the following error: signal (22): SIGABRT in expression starting at C:\Evovest\EvoTrees.jl\experiments\random\_test.jl:36 crt\_sig\_handler at /cygdrive/d/buildbot/worker/package\_win64/build/src\signals-win.c:92 raise at C:\Windows\System32\msvcrt.dll (unknow…

> <https://github.com/JuliaLang/julia/issues/32939>
>
> The following script processes a couple of images with some file I/O. Running it… with \`@threads\` causes a failure. It always breaks when calling the script directly with \`JULIA\_NUM\_THREADS\>1\` , though when \`include\`ing it in a running session it seems it breaks the first time and later it works.
> 
> Am I wrong in assuming this code is thread-safe in the first place, or could this be a bug somewhere?
> 
> \`\`\`julia
> using FileIO
> using Images
> 
> imgs = \[
> "https://images.unsplash.com/photo-1554266183-2696fdafe3ff?ixlib=rb-1.2.1&auto=format&fit=crop&w=564&q=80"
> "https://images.unsplash.com/photo-1527026950045-9e066846bae4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1419&q=80"
> "https://images.unsplash.com/photo-1549287748-f095932c9f81?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=606&q=80"
> "https://images.unsplash.com/photo-1437448317784-3a480be9571e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80"
> \]
> 
> files = download.(imgs)
> 
> Threads.@threads for f in files
> a = load(f)
> r = rand(eltype(a), size(a)...)
> a .= map(clamp01nan, a + 0.5\*r)
> save(f\*".png", a)
> end
> \`\`\`
> 
> The error:
> \`\`\`
> $ JULIA\_NUM\_THREADS=4 julia mycode.jl
> Error encountered while loading "/tmp/jl\_5OG85C".
> Fatal error:
> Error encountered while loading "/tmp/jl\_hZpwGF".
> Fatal error:
> Error encountered while loading "/tmp/jl\_BlmZ9H".
> Fatal error:
> ERROR: LoadError: concurrency violation detected
> Stacktrace:
> \[1\] try\_yieldto(::typeof(Base.ensure\_rescheduled), ::Base.RefValue{Task}) at ./task.jl:552
> \[2\] wait() at ./task.jl:609
> \[3\] wait(::Base.GenericCondition{Base.Threads.SpinLock}) at ./condition.jl:107
> \[4\] wait(::Task) at ./task.jl:214
> \[5\] top-level scope at ./threadingconstructs.jl:75
> \[6\] include at ./boot.jl:328 \[inlined\]
> \[7\] include\_relative(::Module, ::String) at ./loading.jl:1094
> \[8\] include(::Module, ::String) at ./Base.jl:31
> \[9\] exec\_options(::Base.JLOptions) at ./client.jl:295
> \[10\] \_start() at ./client.jl:468
> in expression starting at /home/user/src/julia-test/mycode.jl:13
> \`\`\`
> 
> \`\`\`
> julia\> versioninfo()
> Julia Version 1.3.0-alpha.1
> Commit f2513a8ca6\* (2019-07-23 05:06 UTC)
> Platform Info:
> OS: Linux (x86\_64-linux-gnu)
> CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
> Environment:
> JULIA\_NUM\_THREADS = 4
> JULIA\_EDITOR = emacsclient
> \`\`\`

> [@Julia is crashing. What to do with the error?](https://discourse.julialang.org/t/julia-is-crashing-what-to-do-with-the-error/46008/2):
>
> looks like a PyCall bug can you provide a MWE?

> <https://github.com/JuliaLang/julia/issues/37143>
>
> Julia crashes a couple times a week with the following error after I execute the… following code. It seems to happen randomly and not depend on the content of the called qml script.
> 
> Code:
> \`\`\`
> using QML
> using Observables
> load("GUI//Main.qml")
> exec()
> \`\`\`
> 
> Error:
> \`\`\`
> 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 0x7ff8c3baade3 -- RegisterProcTableCallback at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> in expression starting at C:\\Users\\a\_ill\\Documents\\GitHub\\project\\source\\GUI.jl:4
> RegisterProcTableCallback at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> RegisterProcTableCallback at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> DumpRegistryKeyDefinitions2 at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> DrvCreateLayerContext at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> wglSwapMultipleBuffers at C:\\WINDOWS\\SYSTEM32\\OPENGL32.dll (unknown line)
> wglCreateLayerContext at C:\\WINDOWS\\SYSTEM32\\OPENGL32.dll (unknown line)
> DumpRegistryKeyDefinitions2 at C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\iigd\_dch.inf\_amd64\_317c1bae0b648571\\ig9icd64.dll (unknown line)
> unknown function (ip: 000000004E17BEFB)
> unknown function (ip: 000000004E17D9B7)
> unknown function (ip: 000000004E12F554)
> ZN14QOpenGLContext6createEv at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> ZN14QSGOpenGLLayer13updateTextureEv at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Quick.dll (unknown line)
> ZN14QSGOpenGLLayer13updateTextureEv at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Quick.dll (unknown line)
> ZN7QWindow5eventEP6QEvent at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> ZN12QQuickWindow5eventEP6QEvent at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Quick.dll (unknown line)
> ZN19QApplicationPrivate13notify\_helperEP7QObjectP6QEvent at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Widgets.dll (unknown line)
> ZN12QApplication6notifyEP7QObjectP6QEvent at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Widgets.dll (unknown line)      
> ZN16QCoreApplication20sendSpontaneousEventEP7QObjectP6QEvent at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Core.dll (unknown line)
> ZN22QGuiApplicationPrivate18processExposeEventEPN29QWindowSystemInterfacePrivate11ExposeEventE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> ZN22QGuiApplicationPrivate24processWindowSystemEventEPN29QWindowSystemInterfacePrivate17WindowSystemEventE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> ZN22QWindowSystemInterface22sendWindowSystemEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> ZN22QWindowSystemInterface23flushWindowSystemEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Gui.dll (unknown line)
> unknown function (ip: 000000004E1289AB)
> qt\_plugin\_instance at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\plugins\\platforms\\qwindows.dll (unknown line)
> unknown function (ip: 000000004E13442A)
> CallWindowProcW at C:\\WINDOWS\\System32\\USER32.dll (unknown line)
> DispatchMessageW at C:\\WINDOWS\\System32\\USER32.dll (unknown line)
> SendMessageTimeoutW at C:\\WINDOWS\\System32\\USER32.dll (unknown line)
> KiUserCallbackDispatcher at C:\\WINDOWS\\SYSTEM32\\ntdll.dll (unknown line)
> NtUserDispatchMessage at C:\\WINDOWS\\System32\\win32u.dll (unknown line)
> DispatchMessageW at C:\\WINDOWS\\System32\\USER32.dll (unknown line)
> ZN21QEventDispatcherWin3213processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Core.dll (unknown line)
> qt\_plugin\_instance at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\plugins\\platforms\\qwindows.dll (unknown line)
> ZN10QEventLoop4execE6QFlagsINS\_17ProcessEventsFlagEE at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Core.dll (unknown line)
> ZN16QCoreApplication4execEv at C:\\Users\\a\_ill\\.julia\\artifacts\\fb208e0d5ea6127e0a53e7212e75d3ca79b88b7f\\bin\\Qt5Core.dll (unknown line)
> \_ZN7qmlwrap18ApplicationManager4execEv at C:\\Users\\a\_ill\\.julia\\artifacts\\998b10d1488e1115e652a32dab1485863cf571a7\\bin\\libjlqml.dll (unknown line)
> \_ZN5jlcxx6detail11CallFunctorIvJEE5applyEPKv at C:\\Users\\a\_ill\\.julia\\artifacts\\998b10d1488e1115e652a32dab1485863cf571a7\\bin\\libjlqml.dll (unknown line)     
> exec at C:\\Users\\a\_ill\\.julia\\packages\\CxxWrap\\ZOkSN\\src\\CxxWrap.jl:590
> unknown function (ip: 0000000043E80F03)
> jl\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\julia.h:1690 \[inlined\]
> do\_call at /cygdrive/d/buildbot/worker/package\_win64/build/src\\interpreter.c:117
> eval\_value at /cygdrive/d/buildbot/worker/package\_win64/build/src\\interpreter.c:206
> eval\_stmt\_value at /cygdrive/d/buildbot/worker/package\_win64/build/src\\interpreter.c:157 \[inlined\]
> eval\_body at /cygdrive/d/buildbot/worker/package\_win64/build/src\\interpreter.c:548
> jl\_interpret\_toplevel\_thunk at /cygdrive/d/buildbot/worker/package\_win64/build/src\\interpreter.c:660
> jl\_toplevel\_eval\_flex at /cygdrive/d/buildbot/worker/package\_win64/build/src\\toplevel.c:840
> jl\_parse\_eval\_all at /cygdrive/d/buildbot/worker/package\_win64/build/src\\ast.c:913
> jl\_load\_file\_string at /cygdrive/d/buildbot/worker/package\_win64/build/src\\ast.c:953
> include\_string at .\\loading.jl:1088
> include\_string at .\\loading.jl:1096 \[inlined\]
> \#216 at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:174
> withpath at C:\\Users\\a\_ill\\.julia\\packages\\CodeTools\\VsjEq\\src\\utils.jl:30
> unknown function (ip: 0000000043EC5EC4)
> withpath at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:9
> \#215 at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:171
> unknown function (ip: 000000001E0B84D3)
> with\_logstate at .\\logging.jl:408
> with\_logger at .\\logging.jl:514 \[inlined\]
> \#214 at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:170 \[inlined\]
> hideprompt at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\repl.jl:127
> macro expansion at C:\\Users\\a\_ill\\.julia\\packages\\Media\\ItEPc\\src\\dynamic.jl:24 \[inlined\]
> evalall at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:160
> jl\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\julia.h:1690 \[inlined\]
> do\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\builtins.c:655
> jl\_f\_\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\builtins.c:669 \[inlined\]
> jl\_f\_\_apply\_latest at /cygdrive/d/buildbot/worker/package\_win64/build/src\\builtins.c:705
> \#invokelatest#1 at .\\essentials.jl:710
> jl\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\julia.h:1690 \[inlined\]
> do\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\builtins.c:655
> invokelatest at .\\essentials.jl:709
> jl\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\julia.h:1690 \[inlined\]
> do\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\builtins.c:655
> macro expansion at C:\\Users\\a\_ill\\.julia\\packages\\Atom\\ipSjf\\src\\eval.jl:41 \[inlined\]
> \#184 at .\\task.jl:356
> unknown function (ip: 000000001DFF5A13)
> jl\_apply at /cygdrive/d/buildbot/worker/package\_win64/build/src\\julia.h:1690 \[inlined\]
> start\_task at /cygdrive/d/buildbot/worker/package\_win64/build/src\\task.c:707
> Allocations: 102480780 (Pool: 102441887; Big: 38893); GC: 103
> \`\`\`
> versioninfo:
> \`\`\`
> Julia Version 1.5.0
> Commit 96786e22cc (2020-08-01 23:44 UTC)
> Platform Info:
> OS: Windows (x86\_64-w64-mingw32)      
> CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
> Environment:
> JULIA\_EDITOR = "C:\\Users\\a\_ill\\AppData\\Local\\atom\\app-1.50.0\\atom.exe" -a
> JULIA\_NUM\_THREADS = 6
> \`\`\`

> <https://github.com/JuliaLang/julia/issues/36752>
>
> I tried my absolute best looking for equivalent issues. I saw similar errors, bu…t do not know enough to understand if they are the same problem. But the output said to post this as an issue, so here I am.
> 
> The idea is very simple, train some Flux models on the gpu, but have the models generated and trained from different cpu threads. As near as I can tell, this should be thread-safe to do, because everything that would get mutated in training is thread-local. The data should not be mutated by training.
> 
> https://gist.github.com/MacKenzieHnC/7596910b83f7351e92a5fd5c5dcdc94d
> 
> \`\`\`
> \# simple\_double\_threaded.jl
> 
> using Flux
> using Statistics
> import CuArrays
> CuArrays.allowscalar(false)
> 
> \# generate a bunch of data
> X = rand(100)
> Y = 0.5X + rand(100)
> Xd = reduce(hcat,X)
> Yd = reduce(hcat,Y)
> 
> \# global gpu data
> data = gpu(\[(Xd,Yd)\])
> 
> \# cpu threads
> Threads.@threads for i in 1:100 # lower values only fail sometimes???
> 
> # gpu model
> model = gpu(Dense(1,1))
> loss(x, y) = mean((model(x).-y).^2)
> opt = ADAM()
> par = params(model);
> 
> for j in 1:100 # lower values only fail sometimes???
> # Training crashes gloriously
> Flux.train!(loss,par,data,opt)
> end
> end
> \`\`\`
> 
> So why does it fail so dramatically? And so inconsistently when using real-world values??
> 
> Version Info:
> \`\`\`
> julia\> using InteractiveUtils
> 
> julia\> versioninfo()
> Julia Version 1.4.2
> Commit 44fa15b150\* (2020-05-23 18:35 UTC)
> Platform Info:
> OS: Windows (x86\_64-w64-mingw32)
> CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
> Environment:
> JULIA\_DEPOT\_PATH = C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1;C:\\Users\\Lepre\\AppData\\Local\\JuliaPro 1.4.2-1\\Julia-1.4.2\\local\\share\\julia;C:\\Users\\Lepre\\AppData\\Local\\JuliaPro 1.4.2-1\\Julia-1.4.2\\share\\julia
> JULIA\_EDITOR = "C:\\Users\\Lepre\\AppData\\Local\\JuliaPro 1.4.2-1\\app-1.47.0\\atom.exe" -a
> JULIA\_NUM\_THREADS = 6
> JULIA\_PKG\_SERVER = pkg.juliacomputing.com
> \`\`\`
> 
> And then this is the output:
> 
> \`\`\`
> 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 0x668432c5 -- at 0x668432c5 -- g report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
> Exception:
> Please submit a bug repor at 0x668432c5 -- at 0x668432c5 -- g report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
> Exception: EXCEPTION\_ACCESS\_VIOLATION at 0x668432c5 -- at 0x668432c5 -- OLATION with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.     
> Exception: EXCEPTION\_ACCESS\_VIOLATION at 0x668432c5 -- at 0x668432c5 -- OLATION ve/d/buildbotin expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> trampoline\_alloc at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:197 \[inlined\]
> jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> in expression starting at C:\\Users\\Leprein expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> ety). Thanks.
> Exception: EXCEPTION\_ACCESS\_VIOLATIONtrampoline\_alloc atrampoline\_alloc at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:197 \[inlined\]
> jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> ety). Thanks.
> Exception: EXCEPTION\_ACCESS\_VIOLATION at 0x668432c5 -- at 0x668432c5 -- OLATION ve/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:197 \[inlined\]
> jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> trampoline\_alloc at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:197 \[inlined\]
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threadjl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> \#launch\_configuration#578 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupjl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> \#launch\_configuration#578 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:61 \[inlined\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CuArrays\\YFdj7\\src\\mapreduce.jl:199 \[inlined\]
> lined\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> e\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> \]
> lined\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> e\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupan#launch\_configuration#578 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:61 \[inlined\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CuArrays\\YFdj7\\src\\mapreduce.jl:199 \[inlinmacro expansion at C:\\Users\\Lepre\\.juliamacro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CuArrays\\YFdj7\\src\\mapreduce.jl:199 \[inlined\]
> \#mapreducedim!#72 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:83
> mapreducedim!##kw at C:\\Users\\Lepre\\.julmapreducedim!##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:81
> 
> \#mapreducedim!#72 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:83
> mapreducedim!##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:81
> unknown function (ip: 000000006535BC85)
> apro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highljl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> in expression starting at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:18
> 
> 
> \#mapreducedim!#72 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highljl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> jl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> el.jl:83
> unknown function (ip: 000000006535BC85)
> unknown function (ip: 000000006535BC85)
> re\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:61 #\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreducejl\_get\_cfunction\_trampoline at /cygdrive/d/buildbot/worker/package\_win64/build/src\\runtime\_ccall.cpp:329
> \#launch\_configuration#578 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:61 \[inlined\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> e\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:unknown function (ip: 000000006537CC8C)
> e\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006535BC85)
> \#\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:62
> \#\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:62
> 5
> \[i#mapreducedim!#72 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:83
> mapreducedim!##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:81
> unknown function (ip: 000000006535BC85)
> \#\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:62
> \#\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:62
> 81
> ned\]
> \#mapreduce#25 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> mapreduce at C:\\Users\\Lepre\\.juliapro\\Jumapreduce at C:\\Users\\Lepre\\.juliapro\\Ju\_mapreduce##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:34 \_mapreduce##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:34 \[inlined\]
> \#mapreduce#25 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> mapreduce at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> \_sum at .\\reducedim.jl:657 \[inlined\]
> \_sum at .\\reducedim.jl:656 \[inlined\]
> \#sum#583 at .\\reducedim.jl:652 \[inlined\]
> sum at .\\reducedim.jl:652 \[inlined\]
> \_mean at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:160 \[inlined\]
> \#mean#4 at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> mean##kw at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> \#adjoint#667 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\array.jl:278 \[inlined\]
> adjoint at .\\none:0 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> loss at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:22 \[inlined\]
> adjoint at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\lib.jl:179 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> \#15 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:89 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> d\]
> lined\]
> #mapreduce#25 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> mapreduce##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> \_sum at .\\reducedim.jl:679 \[inlined\]
> \_sum at .\\reducedim.jl:678 \[inlined\]
> \#sum#583 at .\\reducedim.jl:652 \[inlined\]
> sum##kw at .\\reducedim.jl:652 \[inlined\]
> \#accum\_sum#1083 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\broadcast.jl:42 \[inlined\]
> accum\_sum##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\broadcast.jl:42 \[inlined\]
> unbroadcast at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\broadcast.jl:53
> unbroadcast at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\broadcast.jl:53
> \[gradient at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:53
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:88 \[inlined\]
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Juno\\tLMZd\\src\\progress.jl:119 \[inlined\]
> \#train!#12 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:81
> train! at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:79
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:28 \[inlined\]
> \#373#threadsfor\_fun at .\\threadingconstructs.jl:61
> \#373#threadsfor\_fun at .\\threadingconstrmacro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CuArrays\\YFdj7\\src\\mapreduce.jl:199 \[inlined\]\_sum at .\\reducedim.jl:657 \[inlined\]
> \_sum at .\\reducedim.jl:656 \[inlined\]
> \#sum#583 at .\\reducedim.jl:652 \[inlined\]
> sum at .\\reducedim.jl:652 \[inlined\]
> \_mean at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:160 \[inlined\]
> \#mean#4 at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> mean##kw at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> \#adjoint#667 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\array.jl:278 \[inlined\]
> adjoint at .\\none:0 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> loss at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:22 \[inlined\]
> adjoint at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\lib.jl:179 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> \#15 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:89 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:172
> map at .\\tuple.jl:158 \[inlined\]
> \#1090 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\broadcast.jl:74 \[inlined\]
> \#2457#back at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:49 \[inlined\]
> Dense at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\layers\\basic.jl:122 \[inlined\]
> Pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> Dense at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\layers\\basic.jl:133 \[inlined\]
> Pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> Pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.unknown function (ip: 000000003568D1C3)
> \_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:22 \[inlined\]
> ned\]
> line#mapreducedim!#72 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevegradient at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:53
> gradient at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:53
> l.jl:83
> ed\]
> #mapreduce#25 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jPullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> \#175 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\lib.jl:182
> erface2.jl:0
> 28 \[inlimapreducedim!##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAnative\\C91oY\\src\\nvtx\\highlevel.jl:81
> unknown function (ip: 000000006535BC85)
> \#\_mapreduce#27 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:62
> 81
> ed\]
> mapreduce at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> \_sum at .\\reducedim.jl:657 \[inlined\]
> \_sum at .\\reducedim.jl:656 \[inlined\]
> \#sum#583 at .\\reducedim.jl:652 \[inlined\]
> sum at .\\reducedim.jl:652 \[inlined\]
> \_mean at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:160 \[inlined\]
> \#mean#4 at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> mean##kw at C:\\Users\\julia\\AppData\\Local\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4\\Statistics\\src\\Statistics.jl:157 \[inlined\]
> \#adjoint#667 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\array.jl:278 \[inlined\]
> adjoint at .\\none:0 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> loss at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:22 \[inlined\]
> adjoint at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\lib\\lib.jl:179 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:47 \[inlined\]
> \#15 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:89 \[inlined\]
> \_pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:172
> gradient at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:53
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:88 \[inlined\]
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Juno\\tLMZd\\src\\progress.jl:119 \[inlined\]
> \#train!#12 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:81
> train! at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:79
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:28 \[inlined\]
> \#373#threadsfor\_fun at .\\threadingconstructs.jl:61
> \#373#threadsfor\_fun at .\\threadingconstructs.jl:28
> \_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:28 \[inliunknown function (ip: 000000006537CC8C)
> unknown function (ip: 000000006537CC8C)
> cts.jl:28
> \_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_t#347#back at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\ZygoteRules\\6nssF\\src\\adjoint.jl:49 \[inlined\]
> \#15 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:89 \[inlined\]
> Pullback at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface2.jl:0
> \#50 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:177
> unknown function (ip: 000000006536C31A)
> v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\instart\_task at /cygdrive/d/buildbot/worker/package\_win64/build/src\\task.c:687
> Allocations: 216670028 (Pool: 216622719; Big: 47309); GC: 146
> Allocations: 216670028 (Pool: 216622719; Big: 47309unknown function (ip: 000000003568D1C3)
> unknown function (ip: 000000003568D1C3)
> gradient at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Zygote\\1GXzF\\src\\compiler\\interface.jl:54
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:88 \[inlined\]
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Juno\\tLMZd\\src\\progress.jl:119 \[inlined\]
> \#train!#12 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:81
> train! at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:79
> 81
> inlined\]
> ed\]
> d\]
> d\]
> launch\_configuration##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> unknown function (ip: 000000006536812A)
> unknown function (ip: 000000006536812A)
> e\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CUDAdrv\\Uc14X\\src\\occupancy.jl:55
> \]
> d\]
> \#mapreduce#25 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> mapreduce##kw at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\GPUArrays\\JqOUg\\src\\host\\mapreduce.jl:28 \[inlined\]
> \_sum at .\\reducedim.jl:679 \[inlined\]
> \_sum at .\\reducedim.jl:678 \[inlined\]
> \#sum#583 at .\\reducedim.jl:652 \[inlined\]
> sum##kw at .\\reducedim.jl:652 \[inlined\]
> \#accum\_sum#1083 at C:\\Users\\Lepre\\.juliamacro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\CuArrays\\YFdj7\\sstart\_task at /cygdrive/d/buildbot/worker/package\_win64/build/src\\task.c:687
> Allocations: 216670028 (Pool: 216622719; Big: 47309); GC: 146
> rc\\task.c:687
> s\\YFdj7\\src\\mapreduce.jl:199 \[inlined\]
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Juno\\tLMZd\\src\\progress.jl:119 \[inlined\]
> \#train!#12 at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:81
> train! at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\packages\\Flux\\Fj3bt\\src\\optimise\\train.jl:79
> macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\macro expansion at C:\\Users\\Lepre\\.juliapro\\JuliaPro\_v1.4.2-1\\dev\\SIREN\\test\\simple\_double\_threaded.jl:28 \[inlined\]
> \`\`\`

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 4, 2020, 5:17am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/7 "2020-11-04T05:17:22Z")

</div>

The error is almost certainly due to how you are calling Clp, and not a bug in multithreading. We need a MWE.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 5, 2020, 12:59am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/8 "2020-11-05T00:59:53Z")

</div>

Hi @odow, I have finally managed to create a MWE that reproduces the error! If I get rid of `Threads.@threads` before the for loop in `run_modelthreading(;α=0.05)` function then the error goes away.

Please could you advise on this?

_Source of the error_  
The lines 2-4 of the function `run_modelthreading(;α=0.05)` apparently are causing this error. If I get rid of them and replace with `Limit = 50` then the code runs fine.

```julia
model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
optimize!(model)
Limit = objective_value(model)

```

_ **MWE** _

```julia
using JuMP
using Clp
function generate_data()
    # Generate random data
    InitialValue= float(rand(80:140,1,5))
    FutureValue = float(rand(40:150,1000,5))
    Demand = float(rand(40:50,1000))
    nscen = size(FutureValue,1)
    nproducts = size(FutureValue,2)
    prob = 1/nscen*ones(nscen)
    Loss = zeros(Float64,nscen,nproducts)
    Loss = -FutureValue.+InitialValue
    return FutureValue, Loss, Demand,nproducts, prob, nscen
end

function build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    model = Model(Clp.Optimizer)
    @variable(model,x[b=1:nproducts]>=0)
    @variable(model,y[b=1:nscen]>=0)
    @variable(model,γ>=0)
    @constraint(model,budget,sum(x[i] for i =1:nproducts) == 1)
    @constraint(model,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:nproducts) + γ >= 0)
    @constraint(model,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:nproducts)-Demand[j] >= 0)
    @objective(model,Min,γ+1/(α)*sum(y[j]*prob[j] for j =1:nscen))
    return model, x, y, γ
end

function run_modelthreading(;α=0.05)
    FutureValue, Loss, Demand,nproducts, prob, nscen = generate_data()
    model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    optimize!(model)
    Limit = objective_value(model)
    n = 10
    VaR = Vector{Float64}(undef,n)
    CVaR = Vector{Float64}(undef,n)
    Product = Array{Float64,2}(undef, nproducts,n)
    Threads.@threads for i in 1:n
        α = (10-(i-1))/Limit
        model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
        set_optimizer_attribute(model, MOI.Silent(), true)
        optimize!(model)
        VaR[i] = JuMP.value.(γ)
        CVaR[i] = objective_value(model)
        Product[:,i] = JuMP.value.(x)
    end
    return VaR, CVaR, Product
end

```

_Runtime code_  
`run_modelthreading(;α=0.05)`

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 5, 2020, 1:18am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/9 "2020-11-05T01:18:43Z")

</div>

Try it with [https://github.com/jump-dev/Clp.jl/pull/108](https://github.com/jump-dev/Clp.jl/pull/108)

```julia
] add Clp#od/c

```

Otherwise, try encapsulating the optimize call in the buildmodel function, and just return the data you need, rather than the model and variables.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 5, 2020, 4:04am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/10 "2020-11-05T04:04:48Z")

</div>

Maybe there is something weird:

```nohighlight
using GLPK

mutable struct Foo
    ptr::Ptr{Cvoid}
    function Foo()
        ptr = glp_create_prob()
        @info "Creating $(ptr)"
        foo = new(ptr)
        finalizer(foo) do f
            ccall(:jl_safe_printf, Cvoid, (Cstring, Cstring), "Finalizing %s.\n", repr(f.ptr))
            glp_delete_prob(f)
        end
        return foo
    end
end

Base.cconvert(::Type{Ptr{Cvoid}}, f::Foo) = f
Base.unsafe_convert(::Type{Ptr{Cvoid}}, f::Foo) = f.ptr

function main_pass()
    for i = 1:2
        Foo()
    end
end

function main_fail()
    Threads.@threads for i = 1:2
        Foo()
    end
end

julia> main_pass()
[ Info: Creating Ptr{Nothing} @0x00007ff24a155980
[ Info: Creating Ptr{Nothing} @0x00007ff24a380d70

julia> GC.gc()
Finalizing Ptr{Nothing} @0x00007ff24a380d70.
Finalizing Ptr{Nothing} @0x00007ff24a155980.

julia> main_fail()
[ Info: Creating Ptr{Nothing} @0x00007ff24a389140
[ Info: Creating Ptr{Nothing} @0x00007ff24a13cad0

julia> GC.gc()
Finalizing Ptr{Nothing} @0x00007ff24a13cad0.
Finalizing Ptr{Nothing} @0x00007ff24a389140.
glp_free: memory allocation error
Error detected in file env/alloc.c at line 72

signal (6): Abort trap: 6
in expression starting at REPL[10]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 8019758 (Pool: 8017483; Big: 2275); GC: 9

```

I don’t fully understand the ramifications of external C libraries and threads.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 5, 2020, 10:43am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/11 "2020-11-05T10:43:55Z")

</div>

Thanks.

> [@odow](#):
>
> Maybe there is something weird:  
> ` `

I agree there is something weird happening. I don’t think the error is specific to Clp solver, as GLPK also gives an error.

```julia
glp_free: ptr = 0000000036172DF0; invalid pointer
glp_set_col_bnds: j = 3; column number out of range
Error detected in file api/prob1.c at line 632

signal (22): SIGABRT
in expression starting at none:1
Error detected in file env/alloc.c at line 59

Julia has exited.
Press Enter to start a new session.

```

My workaround is similar to the one you suggested to return values by defining an extra function `build_model_t(.......)`. I have given my my code below for the benefit of others in case it helps with fixing the issue or documenting how to use multithreading with JuMP.

```julia
using JuMP
using Clp
function generate_data()
    # Generate random data
    InitialValue= float(rand(80:140,1,5))
    FutureValue = float(rand(40:150,1000,5))
    Demand = float(rand(40:50,1000))
    nscen = size(FutureValue,1)
    nproducts = size(FutureValue,2)
    prob = 1/nscen*ones(nscen)
    Loss = zeros(Float64,nscen,nproducts)
    Loss = -FutureValue.+InitialValue
    return FutureValue, Loss, Demand,nproducts, prob, nscen
end

function build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    model = Model(Clp.Optimizer)
    @variable(model,x[b=1:nproducts]>=0)
    @variable(model,y[b=1:nscen]>=0)
    @variable(model,γ>=0)
    @constraint(model,budget,sum(x[i] for i =1:nproducts) == 1)
    @constraint(model,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:nproducts) + γ >= 0)
    @constraint(model,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:nproducts)-Demand[j] >= 0)
    @objective(model,Min,γ+1/(α)*sum(y[j]*prob[j] for j =1:nscen))
    return model, x, y, γ
end
function build_model_t(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    model = Model(Clp.Optimizer)
    @variable(model,x[b=1:nproducts]>=0)
    @variable(model,y[b=1:nscen]>=0)
    @variable(model,γ>=0)
    @constraint(model,budget,sum(x[i] for i =1:nproducts) == 1)
    @constraint(model,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:nproducts) + γ >= 0)
    @constraint(model,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:nproducts)-Demand[j] >= 0)
    @objective(model,Min,γ+1/(α)*sum(y[j]*prob[j] for j =1:nscen))
    optimize!(model)
    Limit = objective_value(model)
    return Limit
end

function run_modelthreading(;α=0.05)
    FutureValue, Loss, Demand,nproducts, prob, nscen = generate_data()
    Limit = build_model_t(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    n = 10
    VaR = Vector{Float64}(undef,n)
    CVaR = Vector{Float64}(undef,n)
    Product = Array{Float64,2}(undef, nproducts,n)
    Threads.@threads for i in 1:n
        α = (10-(i-1))/Limit
        model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
        set_optimizer_attribute(model, MOI.Silent(), true)
        optimize!(model)
        VaR[i] = JuMP.value.(γ)
        CVaR[i] = objective_value(model)
        Product[:,i] = JuMP.value.(x)
    end
    return VaR, CVaR, Product
end

```

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 8, 2020, 7:54pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/12 "2020-11-08T19:54:38Z")

</div>

You are maybe having a [race condition](https://discourse.julialang.org/t/race-condition-with-local-variable-in-threads-for-loop/49163) do to the `model` variable (and others) assignment outside the `@threads` loop. That can cause a thread to use a model that is not `optimize!` yet as pointed out by @odow.

> [@odow](#):
>
> `OptimizeNotCalled` suggests you are attempting querying the solution of a variable before calling `optimize!` .

That could explain also this:

> [@JohnZ](#):
>
> If I get rid of `Threads.@threads` before the for loop in `run_modelthreading(;α=0.05)` function then the error goes away.

It can be fixed (I think) in your `MWE` making the model asigment inside the `@threads` loop `local`

```julia
function run_modelthreading(;α=0.05)
    [...]
    # This make all this variables visibles between all threads
    model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    [...]
    Threads.@threads for i in 1:n
       [...]
       # This will force this variables to be local for each thread
       local model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
       [...]
    end
    return [...]
end

```

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 9, 2020, 12:37am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/13 "2020-11-09T00:37:18Z")

</div>

> [@josePereiro](#):
>
> > [@odow](#):
> >
> > `OptimizeNotCalled` suggests you are attempting querying the solution of a variable before calling `optimize!` .
> 
> That could explain also this:

In my MWE, I am querying the solution after calling optimize.

> [@josePereiro](#):
>
> You are maybe having a [race condition](https://discourse.julialang.org/t/race-condition-with-local-variable-in-threads-for-loop/49163) do to the `model` variable (and others) assignment outside the `@threads` loop. That can cause a thread to use a model that is not `optimize!` yet as pointed out by @odow.

I do not understand how a race condition can arise for assignment outside the `@threads` loop. My workaround is to not call the `build_model` function before the parallel loop, but to return the optimisation results from another function. Inside the parallel loop I have not made the variable/model assignment local (see code above).

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 9, 2020, 12:49am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/14 "2020-11-09T00:49:54Z")

</div>

> [@JohnZ](#):
>
> I do not understand how a race condition can arise for assignment outside the `@threads` loop.

I hit this same issue recently, see the [link](https://discourse.julialang.org/t/race-condition-with-local-variable-in-threads-for-loop/49163). julia scope rule is not very intuitively in this case. An assignment to a variable, before or after, the `@threads` for loop will make it have an scope outside the threads section.

Run this example `julia t3 test.jl`

```julia
# test.jl
import Base.Threads: @threads, nthreads

function test()
    @threads :static for i in 1:100

        d = Dict(:a => Dict())
        a = d[:a]
        @assert a === d[:a]

        # Line 12: This throw an AssertionError
        for j in 1:100; @assert a === d[:a] end 
    end
    a = [] # If this line is commented the problem disappears 
end

println("Running test (-t$(nthreads()))")
for i = 1:500; test() end

```

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 9, 2020, 12:53am UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/15 "2020-11-09T00:53:49Z")

</div>

> [@JohnZ](#):
>
> I do not understand how a race condition can arise for assignment outside the `@threads` loop. My workaround is to not call the `build_model` function before the parallel loop, but to return the optimisation results from another function. Inside the parallel loop I have not made the variable/model assignment local (see code above).

But now you are not assigning any of the variables used inside the `@threads` loop in the outside.

```julia
function run_modelthreading(;α=0.05)
    [...]
    # Not the sames variables (not as before)
    Limit = build_model_t(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    [...]
    Threads.@threads for i in 1:n
        α = (10-(i-1))/Limit
        # The only place where you assign this variables (not as before)
        model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
        set_optimizer_attribute(model, MOI.Silent(), true)
        optimize!(model)
        [...]
    end
    return VaR, CVaR, Product
end

```

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [November 9, 2020, 6:18pm UTC](https://discourse.julialang.org/t/multithreading-unstable-with-jump/49494/16 "2020-11-09T18:18:53Z")

</div>

I have tested your suggestion of making the variable assignment inside the loop `local`. On another model with actual data this gives incorrect results. If a race condition arises then use of `local` may be not be a good idea. It may have worked for your specific case, but in the MWE above it is mixing up something.

Locks can be used in a race condition, but this tend to slowdown the program. If possible, I would prefer to code it in a way that race condition is avoided. I also got into problem with my workaround code above when I tried to use it on another problem.

This is my code for the MWE that works well and avoids race condition. I believe this is exactly what @odow suggested using.

```julia
using JuMP
using Clp
function generate_data()
    # Generate random data
    InitialValue= float(rand(80:140,1,5))
    FutureValue = float(rand(40:150,100,5))
    Demand = float(rand(40:50,100))
    nscen = size(FutureValue,1)
    nproducts = size(FutureValue,2)
    prob = 1/nscen*ones(nscen)
    Loss = zeros(Float64,nscen,nproducts)
    Loss = -FutureValue.+InitialValue
    return FutureValue, Loss, Demand,nproducts, prob, nscen
end

function build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    model = Model(Clp.Optimizer)
    set_optimizer_attribute(model, MOI.Silent(), true)
    @variable(model,x[b=1:nproducts]>=0)
    @variable(model,y[b=1:nscen]>=0)
    @variable(model,γ>=0)
    @constraint(model,budget,sum(x[i] for i =1:nproducts) == 1)
    @constraint(model,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:nproducts) + γ >= 0)
    @constraint(model,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:nproducts)-Demand[j] >= 0)
    @objective(model,Min,γ+1/(α)*sum(y[j]*prob[j] for j =1:nscen))
    optimize!(model)
    γ_result = JuMP.value.(γ)
    Objective_result = objective_value(model)
    DecisionVariable_result = JuMP.value.(x)
    return γ_result, Objective_result, DecisionVariable_result
end

function run_modelthreading(;n=10,α=0.05)
    FutureValue, Loss, Demand,nproducts, prob, nscen = generate_data()
    γ_result, Objective_result, DecisionVariable_result = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
    Limit = Objective_result
    VaR = Vector{Float64}(undef,n)
    CVaR = Vector{Float64}(undef,n)
    Product = Array{Float64,2}(undef, nproducts,n)
    Threads.@threads for i in 1:n
        α = (n-(i-1))/Limit
        γ_result, Objective_result, DecisionVariable_result = 
        build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
        VaR[i] = γ_result
        CVaR[i] = Objective_result
        Product[:,i] = DecisionVariable_result
    end
    return VaR, CVaR, Product
end

```

` run_modelthreading(;n=10,α=0.05)`
