Skip to content

Commit

Permalink
Run elite gradient descent in separate threads (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass authored Dec 13, 2023
1 parent 3cf3437 commit 8c52ed1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ik_memetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,15 @@ auto ik_memetic_impl(std::vector<double> const& initial_guess,
std::chrono::system_clock::now() + std::chrono::duration<double>(params.max_time);
while ((std::chrono::system_clock::now() < timeout_point) && (iter < params.max_generations)) {
// Do gradient descent on elites.
std::vector<std::thread> gd_threads;
gd_threads.reserve(ik.eliteCount());
for (size_t i = 0; i < ik.eliteCount(); ++i) {
ik.gradientDescent(i, robot, cost_fn, params.gd_params);
gd_threads.push_back(std::thread([&ik, i, &robot, cost_fn, &params] {
ik.gradientDescent(i, robot, cost_fn, params.gd_params);
}));
}
for (auto& t : gd_threads) {
t.join();
}

// Perform mutation and recombination
Expand Down

0 comments on commit 8c52ed1

Please sign in to comment.