Skip to content

Commit

Permalink
Merge pull request #398 from katarinaking/838
Browse files Browse the repository at this point in the history
MNEMONIC-838: Code Expansion Commentary
  • Loading branch information
katarinaking committed Jul 12, 2024
2 parents 5aeb58e + c5f913e commit bdf4a79
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions mnemonic-benches/mnemonic-sort-bench/bin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
#

# Import necessary modules
import argparse
import sys
import os.path
Expand All @@ -25,30 +26,43 @@
from shlex import quote
from benchcommon import *

# Initialize argument parser to handle command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument("input", type=str, help="specify an input file that contains a set of absolute paths of data files.")
args = parser.parse_args()

# Read the input file which contains a list of file paths
with open(args.input, "r") as sfinput:
fns = sfinput.readlines()
fns = sfinput.readlines()

# Change the current working directory to the home directory found by findHomeDir()
os.chdir(findHomeDir())

# Templates for the commands to run and compare outputs
runcmdtmp = "mvn exec:exec -Pbench -pl mnemonic-benches/mnemonic-sort-bench -Dmode={0} -Dinput={1} -Doutput={1}_{0}.out"
cmpcmdtmp = "diff {1}_{0}.out {3}_{2}.out"
rstfntmp = "{1}_{0}.out"

# Loop through each file name obtained from the input file
for efn in fns:
fn = efn.strip().rstrip('\n')
if fn:
if os.path.isfile(fn):
print("Processing {0}, run mode A".format(fn))
subprocess.check_call(quote(runcmdtmp.format('A', fn)), shell=True);
print("Processing {0}, run mode B".format(fn))
subprocess.check_call(quote(runcmdtmp.format('B', fn)), shell=True);
print("Comparing results {0} - {1}".format(rstfntmp.format('A', fn), rstfntmp.format('B', fn)))
subprocess.check_call(quote(cmpcmdtmp.format('A', fn, 'B', fn)), shell=True);
else:
print("Input data file {0} does not exist.".format(fn))
fn = efn.strip().rstrip('\n') # Strip any extra whitespace and newlines
if fn: # Ensure the filename is not empty
if os.path.isfile(fn): # Check if the file exists
# Process the file in mode A
print("Processing {0}, run mode A".format(fn))
subprocess.check_call(quote(runcmdtmp.format('A', fn)), shell=True)

# Process the file in mode B
print("Processing {0}, run mode B".format(fn))
subprocess.check_call(quote(runcmdtmp.format('B', fn)), shell=True)

# Compare the results of mode A and mode B
print("Comparing results {0} - {1}".format(rstfntmp.format('A', fn), rstfntmp.format('B', fn)))
subprocess.check_call(quote(cmpcmdtmp.format('A', fn, 'B', fn)), shell=True)
else:
# Print an error message if the file does not exist
print("Input data file {0} does not exist.".format(fn))

# Indicate that the processing is finished
print("Finished!")

0 comments on commit bdf4a79

Please sign in to comment.