-
Notifications
You must be signed in to change notification settings - Fork 153
Add concurrent lp solve and crossover at root node #602
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
Changes from all commits
6f88f67
94307c9
c0f5886
3cb93e7
3eb950b
4a1cf94
3229b0c
49c97ba
d333846
0351a83
00a89fe
ed71447
bfe9be9
2a9c994
32c6edb
4764d51
b6aad5d
1c0d139
a198738
031b7de
55de62d
63d8b87
68361a5
dcca90b
4a10885
32d984a
94182cc
bc002c4
26ccae5
093cbcb
ca7c9d3
19615e4
5741a17
8b7b6a6
558bb10
62f33b2
359ddff
dfc3102
b4f2aaa
a18b852
0158c41
628d2af
951719c
b819417
27db29a
eb50dda
f89562e
3310d5c
8772731
d33bcc6
a6770c1
deab57a
5fe20f9
b5a7b39
3ff3150
86dd5c2
99e4688
ceb5862
98c92f2
65e655b
606ccaf
140a07f
29ba82a
b960154
a8125c7
cc0b3b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,9 @@ | |
| #include <dual_simplex/pseudo_costs.hpp> | ||
| #include <dual_simplex/simplex_solver_settings.hpp> | ||
| #include <dual_simplex/solution.hpp> | ||
| #include <dual_simplex/solve.hpp> | ||
| #include <dual_simplex/types.hpp> | ||
| #include <utilities/macros.cuh> | ||
| #include <utilities/omp_helpers.hpp> | ||
|
|
||
| #include <omp.h> | ||
|
|
@@ -78,9 +80,29 @@ class branch_and_bound_t { | |
| // Set an initial guess based on the user_problem. This should be called before solve. | ||
| void set_initial_guess(const std::vector<f_t>& user_guess) { guess_ = user_guess; } | ||
|
|
||
| // Set the root solution found by PDLP | ||
| void set_root_relaxation_solution(const std::vector<f_t>& primal, | ||
| const std::vector<f_t>& dual, | ||
| const std::vector<f_t>& reduced_costs, | ||
| f_t objective, | ||
| f_t user_objective, | ||
| i_t iterations) | ||
| { | ||
| root_crossover_soln_.x = primal; | ||
| root_crossover_soln_.y = dual; | ||
| root_crossover_soln_.z = reduced_costs; | ||
| root_objective_ = objective; | ||
| root_crossover_soln_.objective = objective; | ||
| root_crossover_soln_.user_objective = user_objective; | ||
| root_crossover_soln_.iterations = iterations; | ||
| root_crossover_solution_set_.store(true, std::memory_order_release); | ||
| } | ||
|
|
||
| // Set a solution based on the user problem during the course of the solve | ||
| void set_new_solution(const std::vector<f_t>& solution); | ||
|
|
||
| void set_concurrent_lp_root_solve(bool enable) { enable_concurrent_lp_root_solve_ = enable; } | ||
|
|
||
| // Repair a low-quality solution from the heuristics. | ||
| bool repair_solution(const std::vector<f_t>& leaf_edge_norms, | ||
| const std::vector<f_t>& potential_solution, | ||
|
|
@@ -90,6 +112,10 @@ class branch_and_bound_t { | |
| f_t get_upper_bound(); | ||
| f_t get_lower_bound(); | ||
| i_t get_heap_size(); | ||
| bool enable_concurrent_lp_root_solve() const { return enable_concurrent_lp_root_solve_; } | ||
| volatile int* get_root_concurrent_halt() { return &root_concurrent_halt_; } | ||
| void set_root_concurrent_halt(int value) { root_concurrent_halt_ = value; } | ||
|
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace volatile int with std::atomic for thread synchronization. The The pointer returned by Fix: Replace with - volatile int* get_root_concurrent_halt() { return &root_concurrent_halt_; }
- void set_root_concurrent_halt(int value) { root_concurrent_halt_ = value; }
+ std::atomic<int>* get_root_concurrent_halt() { return &root_concurrent_halt_; }
+ void set_root_concurrent_halt(int value) { root_concurrent_halt_.store(value, std::memory_order_release); }- volatile int root_concurrent_halt_{0};
+ std::atomic<int> root_concurrent_halt_{0};Then update all usages to use As per coding guidelines: "Prevent thread-unsafe use of global and static variables; use proper mutex/synchronization in server code accessing shared solver state" and "Ensure race conditions are absent in multi-threaded server implementations." Also applies to: 171-171 🤖 Prompt for AI Agents |
||
| lp_status_t solve_root_relaxation(simplex_solver_settings_t<i_t, f_t> const& lp_settings); | ||
|
|
||
| // The main entry routine. Returns the solver status and populates solution with the incumbent. | ||
| mip_status_t solve(mip_solution_t<i_t, f_t>& solution); | ||
|
|
@@ -137,9 +163,14 @@ class branch_and_bound_t { | |
|
|
||
| // Variables for the root node in the search tree. | ||
| std::vector<variable_status_t> root_vstatus_; | ||
| std::vector<variable_status_t> crossover_vstatus_; | ||
| f_t root_objective_; | ||
| lp_solution_t<i_t, f_t> root_relax_soln_; | ||
| lp_solution_t<i_t, f_t> root_crossover_soln_; | ||
| std::vector<f_t> edge_norms_; | ||
| std::atomic<bool> root_crossover_solution_set_{false}; | ||
| bool enable_concurrent_lp_root_solve_{false}; | ||
| volatile int root_concurrent_halt_{0}; | ||
|
|
||
| // Pseudocosts | ||
| pseudo_costs_t<i_t, f_t> pc_; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure thread-safe access to enable_concurrent_lp_root_solve_ flag.
The
enable_concurrent_lp_root_solve_member (line 170) is a plainboolaccessed via setter (line 103) and getter (line 114) without synchronization. Ifset_concurrent_lp_root_solve()could be called concurrently withenable_concurrent_lp_root_solve()orsolve(), this creates a data race (undefined behavior).Option 1 (Preferred): Make it atomic:
Option 2: Document single-threaded initialization requirement:
+ // Must be called before solve() in single-threaded context void set_concurrent_lp_root_solve(bool enable) { enable_concurrent_lp_root_solve_ = enable; }As per coding guidelines: "Prevent thread-unsafe use of global and static variables; use proper mutex/synchronization in server code accessing shared solver state."
Also applies to: 114-114, 170-170