Skip to content

Commit 8c52ed1

Browse files
authored
Run elite gradient descent in separate threads (#61)
1 parent 3cf3437 commit 8c52ed1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/ik_memetic.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,15 @@ auto ik_memetic_impl(std::vector<double> const& initial_guess,
227227
std::chrono::system_clock::now() + std::chrono::duration<double>(params.max_time);
228228
while ((std::chrono::system_clock::now() < timeout_point) && (iter < params.max_generations)) {
229229
// Do gradient descent on elites.
230+
std::vector<std::thread> gd_threads;
231+
gd_threads.reserve(ik.eliteCount());
230232
for (size_t i = 0; i < ik.eliteCount(); ++i) {
231-
ik.gradientDescent(i, robot, cost_fn, params.gd_params);
233+
gd_threads.push_back(std::thread([&ik, i, &robot, cost_fn, &params] {
234+
ik.gradientDescent(i, robot, cost_fn, params.gd_params);
235+
}));
236+
}
237+
for (auto& t : gd_threads) {
238+
t.join();
232239
}
233240

234241
// Perform mutation and recombination

0 commit comments

Comments
 (0)