Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use "threads" parameter without crashing #186

Closed
burchds opened this issue Jan 18, 2022 · 8 comments
Closed

Cannot use "threads" parameter without crashing #186

burchds opened this issue Jan 18, 2022 · 8 comments
Labels
Upstream Issue with upstream library

Comments

@burchds
Copy link

burchds commented Jan 18, 2022

I have been using JuMP and Cbc for a couple of years now. It's fantastic. However, I recently upgraded to the latest version of Julia and latest version of JuMP and Cbc. After upgrading my models would not run. In fact, Julia would just crash every time.

I am using the following packages on Julia 1.7.1 (current stable release). {edit: Hardware is AMD 3900x CPU, mentioning in case it's a problem that isn't seen on Intel processors.}
[9961bab8] Cbc v0.9.1
[60bf3e95] GLPK v0.15.2
[4076af6c] JuMP v0.22.2

I've spent some time troubleshooting the problem. It looks like I cannot use the "threads" parameter. If I comment out that line, then the code runs.

Here is a working example of what I am testing to isolate the problem. As you can see, I have commented out the line that attempts to set the "threads" parameter.

This code does work:

using JuMP
using Cbc

function main()
		n = 15
		m = 5
		vecCost = [1115, 1042, 1052, 1059, 1071, 1075, 1089, 1034, 1021, 1027, 1009, 996, 1024, 1011, 907]
        storesMatrix = Bool[1 1 0 0 0;
		                    1 0 1 0 0;
		                    1 0 0 1 0;
		                    1 0 0 0 1;
		                    1 0 0 0 0;
		                    0 1 1 0 0;
		                    0 1 0 1 0;
		                    0 1 0 0 1;
		                    0 1 0 0 0;
		                    0 0 1 1 0;
		                    0 0 1 0 1;
		                    0 0 1 0 0;
		                    0 0 0 1 1;
		                    0 0 0 1 0;
		                    0 0 0 0 1]
		model = Model(Cbc.Optimizer)
		set_optimizer_attribute(model, "seconds", 60)
		set_optimizer_attribute(model, "loglevel", 0)
		set_optimizer_attribute(model, "ratioGap", 0.0001)
		
		#set_optimizer_attribute(model, "threads", 4)
        
		@variable(model, x[1:n], Bin)
        @objective(model, Min, sum(vecCost[i] * x[i] for i in 1:n))
        @constraint(model, column_con1[j in 1:m], sum(storesMatrix[i, j] * x[i] for i in 1:n) == 1)
        JuMP.optimize!(model)
		for i in 1:n
            println(JuMP.value(x[i]))
        end
end

main()

This code does not work:

using JuMP
using Cbc

function main()
		n = 15
		m = 5
		vecCost = [1115, 1042, 1052, 1059, 1071, 1075, 1089, 1034, 1021, 1027, 1009, 996, 1024, 1011, 907]
        storesMatrix = Bool[1 1 0 0 0;
		                    1 0 1 0 0;
		                    1 0 0 1 0;
		                    1 0 0 0 1;
		                    1 0 0 0 0;
		                    0 1 1 0 0;
		                    0 1 0 1 0;
		                    0 1 0 0 1;
		                    0 1 0 0 0;
		                    0 0 1 1 0;
		                    0 0 1 0 1;
		                    0 0 1 0 0;
		                    0 0 0 1 1;
		                    0 0 0 1 0;
		                    0 0 0 0 1]
		model = Model(Cbc.Optimizer)
		set_optimizer_attribute(model, "seconds", 60)
		set_optimizer_attribute(model, "loglevel", 0)
		set_optimizer_attribute(model, "ratioGap", 0.0001)
		
		set_optimizer_attribute(model, "threads", 4)
        
		@variable(model, x[1:n], Bin)
        @objective(model, Min, sum(vecCost[i] * x[i] for i in 1:n))
        @constraint(model, column_con1[j in 1:m], sum(storesMatrix[i, j] * x[i] for i in 1:n) == 1)
        JuMP.optimize!(model)
		for i in 1:n
            println(JuMP.value(x[i]))
        end
end

main()

I have also tried setting it to 1 thread. It just doesn't seem to like the parameter being used at all.

@odow
Copy link
Member

odow commented Feb 13, 2022

I can't reproduce this:

julia> using JuMP

julia> using Cbc

julia> function main()
                       n = 15
                       m = 5
                       vecCost = [1115, 1042, 1052, 1059, 1071, 1075, 1089, 1034, 1021, 1027, 1009, 996, 1024, 1011, 907]
               storesMatrix = Bool[1 1 0 0 0;
                                           1 0 1 0 0;
                                           1 0 0 1 0;
                                           1 0 0 0 1;
                                           1 0 0 0 0;
                                           0 1 1 0 0;
                                           0 1 0 1 0;
                                           0 1 0 0 1;
                                           0 1 0 0 0;
                                           0 0 1 1 0;
                                           0 0 1 0 1;
                                           0 0 1 0 0;
                                           0 0 0 1 1;
                                           0 0 0 1 0;
                                           0 0 0 0 1]
                       model = Model(Cbc.Optimizer)
                       set_optimizer_attribute(model, "seconds", 60)
                       set_optimizer_attribute(model, "loglevel", 0)
                       set_optimizer_attribute(model, "ratioGap", 0.0001)
                       
                       set_optimizer_attribute(model, "threads", 4)
               
                       @variable(model, x[1:n], Bin)
               @objective(model, Min, sum(vecCost[i] * x[i] for i in 1:n))
               @constraint(model, column_con1[j in 1:m], sum(storesMatrix[i, j] * x[i] for i in 1:n) == 1)
               JuMP.optimize!(model)
                       for i in 1:n
                   println(JuMP.value(x[i]))
               end
       end
main (generic function with 1 method)

julia> main()
0.0
0.0
1.0
0.0
0.0
1.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0

julia> 

(cbc) pkg> st
      Status `/private/tmp/cbc/Project.toml`
  [9961bab8] Cbc v0.9.1
  [4076af6c] JuMP v0.22.3

How are you starting Julia? What is versioninfo()? Are you running any things in parallel?

@GregPlowman
Copy link

I can reproduce on Windows.

Seems it might be Windows specific, see https://discourse.julialang.org/t/cbc-solver-crashes-julia-with-multithreading/73859

@odow
Copy link
Member

odow commented Feb 28, 2022

I don't have a Windows machine to debug. At this point I would encourage you instead to use HiGHS.jl. It's actively developed, and has similar or better performance to Cbc.

@odow odow added the Upstream Issue with upstream library label Feb 28, 2022
@GregPlowman
Copy link

Sure. Thanks! I’m using HiGHS now.
(I was really just providing another data point for others)

@odow
Copy link
Member

odow commented Mar 2, 2022

I've confirmed that this is Windows-specific: #190. But this is unlikely to be resolved. If you are on Windows, don't use the threads parameter.

@mlubin
Copy link
Member

mlubin commented Mar 2, 2022

Let's print a warning if we see windows users using threads?

@odow
Copy link
Member

odow commented Mar 2, 2022

Done here: #192

matteorossini added a commit to Electa-Git/FlexPlan.jl that referenced this issue Apr 19, 2022
Cbc cannot be used on Windows with multiple threads: <jump-dev/Cbc.jl#186>
The `threads` argument is already disabled on Windows since Cbc v1.0.0: <jump-dev/Cbc.jl#192>
We cannot use Cbc v1.0.0 at the moment because it requires MathOptInterface v1 and we require MathOptInterface v0.10.9.
Removal of MathOptInterface from FlexPlan.jl dependencies is to be done: <#121 (comment)>
@odow
Copy link
Member

odow commented Dec 5, 2023

Closing because this is unlikely to be fixed and Cbc.jl disables threading on Windows.

@odow odow closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Upstream Issue with upstream library
Development

No branches or pull requests

4 participants