Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bfs/bfs/scripts/startbfs.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
83 lines (62 sloc)
3.28 KB
This file contains 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
import os | |
import argparse | |
import subprocess | |
import multiprocessing as mp | |
from buildbfs import build_bfs | |
os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
def start_program(program): | |
if not isinstance(program, str): | |
raise ValueError("Argument passed to start_program_sync() should be a string") | |
return os.system("START /wait \""+ program +"\" CMD /c " + program) | |
def start_program_async(program): | |
# TODO: This needs to account for the number of cores... | |
# Add another function called start_programs_async that takes a list | |
# of programs and starts them on the proper cores. | |
print("\n======> Starting ASYNC: %s <======" % program) | |
p = mp.Process(target=start_program, args=(program,)) | |
p.start() | |
return p | |
def flatten_list(lst): | |
flat = [] | |
for l in lst: | |
if isinstance(l, list): | |
flat.extend(flatten_list(l)) | |
else: | |
flat.append(l) | |
return flat | |
def get_exe_names(algo_args, io_proc_args, config_file): | |
names = [] | |
if algo_args is not None: | |
names.append(algo_args) | |
if io_proc_args is not None: | |
names.extend(flatten_list(io_proc_args)) | |
return names | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-a", "--algorithm", default=None, | |
help="""Specify the name of the algorithm .exe file to run in a separate process. Specifying | |
an algorithm like this eliminates the ability for the user to specify a specify configuration for this algorithm. | |
the created algorithm process will use the configuration file located in it's default config directory.""") | |
parser.add_argument("-p", "--io_processor", action='append', nargs='+', default=None, | |
help="""Specify the name of the IO Processor .exe file to run in a separate process. Specifying | |
an IO Processor like this eliminates the ability for the user to specify a specify configuration for this IO Processor. | |
the created IO Processor process will use the configuration file located in it's default config directory.""") | |
parser.add_argument("-c", "--config", default=None, | |
help="""Specify the configuration file to use. This can specify the algorithm and IO | |
processors to run. It can also specify settings for the individual IO Processors and algorithm themselves. The | |
config file will be divided up into smaller config files (one for each process run) that the respective processes | |
will read and adjust their settings accordingly. That way, each process only has access to their own config settings. | |
Note: this can be used in conjunction with -a and -p, but care is necessary to not produce any duplicate proceses.""") | |
parser.add_argument("-b", "--build", help="If specified, run buildbfs.py before proceeding.", action="store_true") | |
args = parser.parse_args() | |
if args.build: | |
print("=====> Building BFS") | |
build_bfs() | |
binary_path = os.path.abspath("..\\bin") | |
exe_ending = ".exe" | |
exe_names = get_exe_names(args.algorithm, args.io_processor, args.config) | |
procs = [start_program_async(os.path.join(binary_path, x) + exe_ending) for x in exe_names] | |
[proc.join() for proc in procs] | |
print("DONE") | |
if __name__ == "__main__": | |
main() |