Skip to content
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

Do not fire useless threads #607

Closed
jcoupey opened this issue Nov 3, 2021 · 0 comments
Closed

Do not fire useless threads #607

jcoupey opened this issue Nov 3, 2021 · 0 comments

Comments

@jcoupey
Copy link
Collaborator

jcoupey commented Nov 3, 2021

The CVRP::solve implementation fires a number of threads based on the nb_threads parameter (same for VRPTW::solve):

for (const auto& param_ranks : thread_ranks) {
solving_threads.emplace_back(run_solve, param_ranks);
}

Here each param_ranks refers to a vector of parameters to apply, so each thread is responsible for as many searches that there are parameters in param_ranks.

Possible enhancement

What happens if more threads are provided than searches? For example using -x 0 -t 8, there are 4 searches, so 4 threads out of 8 will run on a empty vector of parameters. One may argue that since the run_solve lambda loops over parameters, nothing is done and it's fine. Fair enough and this is what has been happening ever since the first implementation. Now that would be better still to only fire threads on non-empty parameter sets.

Now a bug

It gets worse with the time-out introduced in #595 since run_solve now divides the available time by the number of parameters:

auto run_solve = [&](const std::vector<std::size_t>& param_ranks) {
try {
// Decide time allocated for each search.
Timeout search_time;
if (timeout.has_value()) {
search_time = timeout.value() / param_ranks.size();
}

$ vroom -i input.json -x 0 -t 8
# output OK
$ vroom -i input.json -x 0 -t 8 -l 0
Floating point exception (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant