def main(argv): logging_util.setup() solver_path = argv[1] solver_extra_args = argv[2:] solver_args = [solver_path] for p in FLAGS.powerphrase: solver_args.extend(['-p', p]) solver_args.extend(solver_extra_args) if FLAGS.cores: logging.warning('Ignoring CPU cores specified by -c') if FLAGS.timelimit: logging.warning('Ignoring time limit specified by -t') if FLAGS.memlimit: logging.warning('Ignoring memory limit specified by -m') tasks = supervisor_util.load_tasks(FLAGS.problem) solutions = [] for task in tasks: job = supervisor_util.SolverJob(solver_args, task) job.start() job.wait() solutions.append(job.solution) json.dump(solutions, sys.stdout) if FLAGS.show_scores: supervisor_util.show_scores(solutions) if FLAGS.report: supervisor_util.report_to_log_server(solutions)
def main(unused_argv): logging_util.setup() # Set defaults. if FLAGS.cores == 0: FLAGS.cores = supervisor_util.get_cores() if FLAGS.timelimit == 0: FLAGS.timelimit = 24 * 60 * 60 if FLAGS.memlimit == 0: FLAGS.memlimit = supervisor_util.get_free_memory() - 64 if not FLAGS.powerphrase: with open(os.path.join(os.path.dirname(__file__), '..', 'power_phrases.txt')) as f: FLAGS.powerphrase = f.read().splitlines() logging.info( 'Limits: %d cores, %d seconds, %d megabytes', FLAGS.cores, FLAGS.timelimit, FLAGS.memlimit) tasks = supervisor_util.load_tasks(FLAGS.problem) logging.info( 'Input: %d problems, %d tasks', len(FLAGS.problem), len(tasks)) num_threads = FLAGS.cores * 2 deadline = g_start_time + FLAGS.timelimit - 1 # Impose memory limit with cgroup. if not FLAGS.disable_cgroup: solver_memlimit = max(1, FLAGS.memlimit - 128) cgroup_memlimit_path = ( '/sys/fs/cgroup/memory/%s/memory.limit_in_bytes' % CGROUP_NAME) try: with open(cgroup_memlimit_path, 'w') as f: f.write(str(solver_memlimit * 1024 * 1024)) except Exception: logging.exception( 'Failed to set cgroup limit. Maybe you have not run "make"? ' 'If you want to run without cgroup, specify --disable_cgroup.') solutions = solve_tasks(tasks, num_threads, deadline) output_solutions = solutions if FLAGS.strip_extra_fields: output_solutions = copy.deepcopy(output_solutions) for solution in output_solutions: for key in solution.keys(): if key.startswith('_'): del solution[key] json.dump(output_solutions, sys.stdout) sys.stdout.flush() if FLAGS.show_scores: supervisor_util.show_scores(solutions) if FLAGS.report: supervisor_util.report_to_log_server(solutions, override_tag=FLAGS.report_tag)