import os import shutil import subprocess def performance_score(s): if not ("Result: VALID" in str(s, "utf-8")): return 0 s = str(s, "utf-8").splitlines() for line in s: if "Avg. throughput" in line: flops = float(line.split(" ")[2]) flops = min(max(flops, 0), 200) return flops / 200 * 50 return 0 def validation_score(s): s = str(s, "utf-8") cnt = s.count("Result: VALID") return float(cnt * 5) BASEDIR = "/home/kjp4155/submissions/HW2" usernames = [x.split(',')[1] for x in open('accounts.csv').readlines()[1:]] print(usernames) result = "" for user in usernames: submitpath = f"/home/{user}/submit/HW2/mat_mul.cpp" if not os.path.isfile(f"{BASEDIR}/{user}/mat_mul.cpp"): print(f"{user},0,0,-1") result += f"{user},0,0,-1\n" continue # Prepare files shutil.copytree(f"{BASEDIR}/skel", f"{BASEDIR}/{user}", dirs_exist_ok=True) # Compile subprocess.run(["make" ,"clean"], cwd=f"{BASEDIR}/{user}") subprocess.run(["make" ,"-j"], cwd=f"{BASEDIR}/{user}") # Run sperf = subprocess.run(["./run_performance.sh"], cwd=f"{BASEDIR}/{user}", capture_output=True) sval = subprocess.run(["./run_validate.sh"], cwd=f"{BASEDIR}/{user}", capture_output=True) perf_score = performance_score(sperf.stdout) val_score = validation_score(sval.stdout) print(f"{user},{perf_score},{val_score}") result += f"{user},{perf_score},{val_score}\n" print(result)