#!/usr/bin/env python3 """Compute the core-time tradeoff given the experimental results for the private and public channels""" import sys import csv import math if len(sys.argv)!=3: print(f"Usage: {sys.argv[0]} ") sys.exit(0) priv_file = open(sys.argv[1], 'r') pub_file = open(sys.argv[2], 'r') priv_input = csv.DictReader(priv_file) pub_input = csv.DictReader(pub_file) priv_data = sorted( filter(lambda row: row['T']=='1' and row['N']=='1048576', priv_input), key = lambda row: (int(row['T']), int(row['M']), int(row['N']))) pub_data = sorted( filter(lambda row: row['T']=='1' and row['N']=='1048576', pub_input), key = lambda row: (int(row['T']), int(row['M']), int(row['N']))) priv_times = [ ( int(row['M']), float(row['epoch_mean']) + float(row['bytes_max'])*8/13000000000, float(row['wn_mean']) ) for row in priv_data ] pub_times = [ ( int(row['M']), float(row['epoch_mean']) + float(row['bytes_max'])*8/13000000000, float(row['wn_mean']) ) for row in pub_data ] # Sort the list of all times appearing in the data all_times = sorted([ tpl[1] for tpl in priv_times + pub_times ]) # Put integer times in there as well max_int_time = int(all_times[-1]) all_times = sorted(all_times + [t for t in range(1,max_int_time+1)]) # Interpolate 4 points between each pair of points in the sorted list # and flatten the result interp_times = [ x for xs in [[all_times[j] + i/5*(all_times[j+1]-all_times[j]) for i in range(5)] for j in range(len(all_times)-1)] for x in xs ] + [ all_times[-1] ] for target_time in interp_times: # Find the smallest public and private channel configurations that # are at or below the target time try: priv_conf = next(filter(lambda tpl: tpl[1] <= target_time, priv_times)) pub_conf = next(filter(lambda tpl: tpl[1] <= target_time, pub_times)) priv_cores = math.ceil((1 + priv_conf[2] / target_time) * priv_conf[0]) pub_cores = math.ceil((1 + pub_conf[2] / target_time) * pub_conf[0]) print (target_time, priv_conf[0], pub_conf[0], priv_cores, pub_cores, priv_cores + pub_cores) except: # One of the channels couldn't reach a time as small as the # other channel could pass