Add thread and memory resource limits (default unlimited)#384
Merged
Conversation
Add per-type optimize parameters number_of_threads and memory_limit_megabytes (both default 0 = unlimited, preserving current behavior). - New shared header algorithms/thread_pool.hpp: run_in_waves bounded thread executor (unlimited branch spawns all tasks at once, identical to the previous spawn/join loops) and a portable current-RSS reader (Windows GetProcessMemoryInfo, macOS task_info, else /proc/self/statm). - Refactor every src/<type>/optimize.cpp thread spawn loop to collect std::function tasks and run them via run_in_waves, preserving the exception_ptr_list rethrow behavior. - Stop the search at the coarse cooperative checkpoints when RSS reaches the memory limit by setting the shared end flag. - Add --threads and --memory-limit-mb CLI options to every main.cpp. - Link psapi on Windows in each per-type CMakeLists.
Instead of joining a whole batch before starting the next, spin up min(number_of_threads, |tasks|) - 1 background threads plus the calling thread, each pulling the next available task via a shared atomic index. A fast-finishing thread immediately picks up more work with no idle gaps.
40596be to
2912b86
Compare
ae541f7 to
b2393c1
Compare
Owner
|
I rewrote the memory limit check by adding a dedicated thread. I didn't keep the limit on the number of threads for now. The way it was implemented was only relevant for non anytime modes. I don't see how to implement it in a relevant way for the anytime mode. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds optional thread and memory resource limits to optimize, plumbed through the optimize options and CLIs for all problem types. Defaults are unlimited, so behavior is unchanged unless a limit is set.