Skip to content

Add thread and memory resource limits (default unlimited)#384

Merged
fontanf merged 3 commits into
fontanf:masterfrom
HamzaYslmn:pr/resource-limits
Jun 15, 2026
Merged

Add thread and memory resource limits (default unlimited)#384
fontanf merged 3 commits into
fontanf:masterfrom
HamzaYslmn:pr/resource-limits

Conversation

@HamzaYslmn

Copy link
Copy Markdown
Contributor

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.

HamzaYslmn and others added 2 commits June 14, 2026 01:11
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.
@fontanf fontanf force-pushed the pr/resource-limits branch from 40596be to 2912b86 Compare June 14, 2026 22:57
@fontanf fontanf force-pushed the pr/resource-limits branch from ae541f7 to b2393c1 Compare June 15, 2026 05:30
@fontanf fontanf merged commit c00753c into fontanf:master Jun 15, 2026
3 checks passed
@fontanf

fontanf commented Jun 15, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants