@@ -67,8 +67,12 @@ void rins_t<i_t, f_t>::node_callback(const std::vector<f_t>& solution, f_t objec
6767 // opportunistic early test w/ atomic to avoid having to take the lock
6868 if (!rins_thread->cpu_thread_done ) return ;
6969 std::lock_guard<std::mutex> lock (rins_mutex);
70- if (rins_thread->cpu_thread_done && dm.population .current_size () > 0 &&
71- dm.population .is_feasible ()) {
70+ bool population_ready = false ;
71+ if (rins_thread->cpu_thread_done ) {
72+ std::lock_guard<std::recursive_mutex> pop_lock (dm.population .write_mutex );
73+ population_ready = dm.population .current_size () > 0 && dm.population .is_feasible ();
74+ }
75+ if (population_ready) {
7276 lp_optimal_solution = solution;
7377 rins_thread->start_cpu_solver ();
7478 }
@@ -99,8 +103,6 @@ void rins_t<i_t, f_t>::run_rins()
99103{
100104 if (total_calls == 0 ) RAFT_CUDA_TRY (cudaSetDevice (context.handle_ptr ->get_device ()));
101105
102- if (!dm.population .is_feasible ()) return ;
103-
104106 cuopt_assert (lp_optimal_solution.size () == problem_copy->n_variables , " Assignment size mismatch" );
105107 cuopt_assert (problem_copy->handle_ptr == &rins_handle, " Handle mismatch" );
106108 // Do not make assertions based on problem_ptr. The original problem may have been modified within
@@ -111,13 +113,14 @@ void rins_t<i_t, f_t>::run_rins()
111113 // "Problem size mismatch");
112114 // cuopt_assert(problem_copy->n_binary_vars == problem_ptr->n_binary_vars, "Problem size
113115 // mismatch");
114- cuopt_assert (dm.population .current_size () > 0 , " No solutions in population" );
115116
116117 solution_t <i_t , f_t > best_sol (*problem_copy);
117118 rins_handle.sync_stream ();
118119 // copy the best from the population into a solution_t in the RINS stream
119120 {
120121 std::lock_guard<std::recursive_mutex> lock (dm.population .write_mutex );
122+ if (!dm.population .is_feasible ()) return ;
123+ cuopt_assert (dm.population .current_size () > 0 , " No solutions in population" );
121124 auto & best_feasible_ref = dm.population .best_feasible ();
122125 cuopt_assert (best_feasible_ref.assignment .size () == best_sol.assignment .size (),
123126 " Assignment size mismatch" );
0 commit comments