Add command-line parameter for workers

This allows users to adjust the number of CPU threads that the solver uses, which may be useful if you want to leave it running while you use it.
This commit is contained in:
TheTaques 2021-06-18 23:18:40 +02:00 committed by GitHub
parent a8b835aba3
commit eb94bb3b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -1179,7 +1179,7 @@ class OccasionalBuyer(Enum):
] ]
def Solve(bone_market_fluctuations, zoological_mania, occasional_buyer = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), stdscr = None): def Solve(bone_market_fluctuations, zoological_mania, occasional_buyer = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), workers = cpu_count(), stdscr = None):
model = cp_model.CpModel() model = cp_model.CpModel()
actions = {} actions = {}
@ -2136,7 +2136,7 @@ def Solve(bone_market_fluctuations, zoological_mania, occasional_buyer = None, d
printer = SkeletonPrinter() printer = SkeletonPrinter()
solver = cp_model.CpSolver() solver = cp_model.CpSolver()
solver.parameters.num_search_workers = cpu_count() solver.parameters.num_search_workers = workers
solver.parameters.max_time_in_seconds = time_limit solver.parameters.max_time_in_seconds = time_limit
# There's no window in verbose mode # There's no window in verbose mode
@ -2254,10 +2254,17 @@ def main():
help="maximum number of seconds that solver runs for", help="maximum number of seconds that solver runs for",
dest='time_limit' dest='time_limit'
) )
parser.add_argument(
"-w", "--workers",
default=cpu_count(),
type=int,
help="number of search worker threads to run in parallel (default: one worker per available CPU thread)",
dest='workers'
)
args = parser.parse_args() args = parser.parse_args()
arguments = (args.bone_market_fluctuations, args.zoological_mania, args.occasional_buyer, args.desired_buyers, args.maximum_cost, args.maximum_exhaustion, args.time_limit) arguments = (args.bone_market_fluctuations, args.zoological_mania, args.occasional_buyer, args.desired_buyers, args.maximum_cost, args.maximum_exhaustion, args.time_limit, args.workers)
if not args.verbose: if not args.verbose:
def WrappedSolve(stdscr, arguments): def WrappedSolve(stdscr, arguments):