@@ -15,13 +15,11 @@ def run_command(command, silent=False):
1515 if not silent :
1616 print (f"Error running command: { command } " )
1717 print (f"Exit code: { e .returncode } " )
18- # We don't raise here to allow the script to continue to cleanup
1918
20- def draw_menu (stdscr , selected_row_idx , options ):
19+ def draw_menu (stdscr , selected_row_idx , options , title ):
2120 stdscr .clear ()
2221 h , w = stdscr .getmaxyx ()
2322
24- title = "Select Benchmark to Run (Use Arrow Keys + Enter)"
2523 stdscr .addstr (h // 2 - len (options )// 2 - 2 , w // 2 - len (title )// 2 , title )
2624
2725 for idx , row in enumerate (options ):
@@ -36,17 +34,10 @@ def draw_menu(stdscr, selected_row_idx, options):
3634
3735 stdscr .refresh ()
3836
39- def main (stdscr ):
40- # Setup colors
41- curses .start_color ()
42- curses .init_pair (1 , curses .COLOR_BLACK , curses .COLOR_WHITE )
43- curses .curs_set (0 )
44-
45- options = ["Serial" , "OMP" , "MPI" , "ALL" , "Exit" ]
37+ def select_option (stdscr , title , options ):
4638 selected_row_idx = 0
47-
4839 while True :
49- draw_menu (stdscr , selected_row_idx , options )
40+ draw_menu (stdscr , selected_row_idx , options , title )
5041 key = stdscr .getch ()
5142
5243 if key == curses .KEY_UP and selected_row_idx > 0 :
@@ -56,47 +47,82 @@ def main(stdscr):
5647 elif key == curses .KEY_ENTER or key in [10 , 13 ]:
5748 return options [selected_row_idx ]
5849
50+ def get_datasets ():
51+ data_dir = "data-generation"
52+ if not os .path .exists (data_dir ):
53+ return []
54+ files = [f for f in os .listdir (data_dir ) if f .endswith (".csv" )]
55+ files .sort ()
56+ # Return relative paths
57+ return [os .path .join (data_dir , f ) for f in files ]
58+
59+ def main (stdscr ):
60+ # Setup colors
61+ curses .start_color ()
62+ curses .init_pair (1 , curses .COLOR_BLACK , curses .COLOR_WHITE )
63+ curses .curs_set (0 )
64+
65+ # Select Dataset
66+ datasets = get_datasets ()
67+ if not datasets :
68+ return None , "No CSV files found in data-generation/"
69+
70+ datasets .append ("Exit" )
71+ dataset = select_option (stdscr , "Select Dataset (Use Arrow Keys + Enter)" , datasets )
72+
73+ if dataset == "Exit" :
74+ return "Exit" , None
75+
76+ # Select Benchmark Version
77+ benchmarks = ["Serial" , "OMP" , "MPI" , "ALL" , "Exit" ]
78+ benchmark = select_option (stdscr , "Select Benchmark to Run" , benchmarks )
79+
80+ return benchmark , dataset
81+
5982def run_benchmark ():
6083 # Run make silently
6184 print ("Building project... (this may take a moment)" )
6285 run_command ("make" , silent = True )
6386
6487 # Show Menu
6588 try :
66- # curses.wrapper handles initialization and cleanup of curses
67- selection = curses .wrapper (main )
89+ selection , dataset = curses .wrapper (main )
6890 except Exception as e :
6991 print (f"Error in UI: { e } " )
70- # Ensure cleanup happens even if UI fails
7192 run_command ("make clean" , silent = True )
7293 return
7394
74- if selection == "Exit" :
95+ if selection == "Exit" or selection is None :
96+ if dataset and dataset != "Exit" :
97+ print (dataset ) # Print error message if any
7598 print ("Exiting..." )
7699 run_command ("make clean" , silent = True )
77100 return
78101
79- print (f"\n Running { selection } Benchmark... \n " + "=" * 40 + "\n " )
102+ print (f"\n Running { selection } Benchmark with dataset: { dataset } \n " + "=" * 60 + "\n " )
80103
81104 # Run Selected
82- start_time = time .time ()
105+ start_time = time .time ()
106+
107+ # Pass dataset as ARGS
108+ args = f'ARGS="{ dataset } "'
83109
84110 if selection == "Serial" :
85- run_command ("make run" )
111+ run_command (f "make run { args } " )
86112 elif selection == "OMP" :
87- run_command ("make run-omp" )
113+ run_command (f "make run-omp { args } " )
88114 elif selection == "MPI" :
89- run_command ("make run-mpi" )
115+ run_command (f "make run-mpi { args } " )
90116 elif selection == "ALL" :
91117 print ("--- Running Serial ---" )
92- run_command ("make run" )
118+ run_command (f "make run { args } " )
93119 print ("\n --- Running OMP ---" )
94- run_command ("make run-omp" )
120+ run_command (f "make run-omp { args } " )
95121 print ("\n --- Running MPI ---" )
96- run_command ("make run-mpi" )
122+ run_command (f "make run-mpi { args } " )
97123
98124 end_time = time .time ()
99- print ("\n " + "=" * 40 )
125+ print ("\n " + "=" * 60 )
100126 print (f"Total Benchmark Time: { end_time - start_time :.4f} seconds" )
101127
102128 # Run make clean silently
0 commit comments