Comments (4)
Okay, I took a deeper look at this, and it's a subtle issue that might not have a resolution.
It's not the outgoing ccall
s that are blocking, but the incoming callbacks from C into Julia that Ipopt uses to evaluate functions and derivatives. Ipopt is particularly bad for threaded parallelism, because most of the time spent in the solver is actually in Julia, not in C. MILP solvers like HiGHS don't have this problem because they don't call back into Julia.
We can't use @threadcall
because of the callback issue. (From the docstring Note that the called function should never call back into Julia.
)
There's no good way around this in Ipopt, but you can use AmplNLWriter, which uses AMPL to compute derivatives instead of calling back into Julia:
using JuMP, Ipopt
function main(filename, optimizer, f)
replicas = Threads.nthreads()
models = [read_from_file(filename) for _ in 1:replicas]
for model in models
set_optimizer(model, optimizer)
relax_integrality(model)
end
@time f(models)
end
function test_serial(models)
for m in models
optimize!(m)
end
end
function test_threaded(models)
Threads.@threads for m in models
optimize!(m)
end
end
optimizer = optimizer_with_attributes(Ipopt.Optimizer, MOI.Silent() => true)
@time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_serial)
@time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_threaded)
# Install with `] add [email protected] Ipopt_jll`
import AmplNLWriter, Ipopt_jll
optimizer = optimizer_with_attributes(
() -> AmplNLWriter.Optimizer(Ipopt_jll.amplexe),
"print_level" => 0, "sb" => "yes",
)
@time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_serial)
@time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_threaded)
Removing all the prints and running twice to ignore compilation, I get:
julia> @time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_serial)
5.263893 seconds (69.52 k allocations: 9.701 MiB)
5.526651 seconds (701.39 k allocations: 253.097 MiB, 1.25% gc time)
julia> @time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_threaded)
5.145869 seconds (80.00 k allocations: 10.416 MiB, 1.31% compilation time)
5.498476 seconds (753.88 k allocations: 256.707 MiB, 1.64% gc time, 2.42% compilation time)
julia> @time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_serial)
5.883419 seconds (1.06 M allocations: 53.135 MiB, 0.17% gc time)
6.141101 seconds (1.69 M allocations: 296.599 MiB, 1.23% gc time, 0.06% compilation time)
julia> @time main("/Users/Oscar/Downloads/QPLIB_2353.lp", optimizer, test_threaded)
2.550396 seconds (1.06 M allocations: 53.128 MiB, 0.39% gc time)
2.849068 seconds (1.69 M allocations: 296.558 MiB, 3.57% gc time)
So AmplNLWriter is a fraction slower (expected, it has to write a file), but is faster then threaded.
from ipopt.jl.
@odow Thank you very much for looking into this issue. I have tried the AmplNLWriter workaround, but could not make it work. It works with 4 threads, but when I use 16 threads, the execution hangs and I'm getting this message from multiple threads:
Problem with integer stack size 1 1 14
For now I have implemented a workaround using the Distributed module. It is a bit inconvenient compared to @threads
, but at least it achieves excellent CPU utilization. If there is no hope of making Ipopt threads-friendly, you can close this issue.
from ipopt.jl.
Ah. The problem is that Ipopt_jll that works with AmplNLWriter is old and uses a version of MUMPS that isn't thread-safe.
I'd stick with Distributed for now.
from ipopt.jl.
Related Issues (20)
- Failed to precompile Ipopt HOT 5
- add `MathOptInterface.Name()` attribute HOT 1
- `max_wall_time` is still not working HOT 5
- Allow user to specify the Ipopt binary HOT 2
- copy_to does not copy attributes for variable bound constraints HOT 6
- Only evaluate QP callbacks if needed HOT 1
- Problem with HSL solvers since updating to MacOS 13.0 HOT 3
- double free or corruption (out) error HOT 20
- Linking full hsl library to Ipopt.jl on ubuntu HOT 19
- julia 0.6.0 install Ipopt cannot connect to mumps dependency HOT 2
- Add support for GetIpoptCurrentViolations
- Incorrect number of Hessian structure (nonzero entries) HOT 10
- Does Ipopt.jl support giving hessian matrix in JuMP directly, without using the C_wrapper? HOT 2
- pointer being freed was not allocated HOT 33
- Invalid number in NLP function or derivative detected. HOT 8
- Issue with non-negative variable tolerance. HOT 2
- does not allow Ipopt_jll current version HOT 2
- Add some pre-built "debugging" callbacks HOT 1
- Crash on Windows when optimizing with SPRAL_jll HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipopt.jl.