-
Notifications
You must be signed in to change notification settings - Fork 3
/
distribution_calculator.py
108 lines (87 loc) · 3.08 KB
/
distribution_calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/#############################################################################
# Copyright 2023 UT Battelle, LLC
#
# This work was supported by the Oak Ridge Leadership Computing Facility at
# the Oak Ridge National Laboratory, which is managed by UT Battelle, LLC for
# the U.S. DOE (under the contract No. DE-AC05-00OR22725).
#
# This file is part of the LCIO project.
#############################################################################/
import sys
import argparse
import math
import itertools
def convert_val(val):
num_digits = len(str(val))
divisor = 1
if num_digits > 15:
divisor = math.pow(1024, 5)
suffix = 'PiB'
return str(val/divisor) + suffix
elif num_digits > 12:
divisor = math.pow(1024, 4)
suffix = 'TiB'
return str(val/divisor) + suffix
elif num_digits > 9:
divisor = math.pow(1024, 3)
suffix = 'GiB'
return str(val/divisor) + suffix
elif num_digits > 6:
divisor = math.pow(1024, 2)
suffix = 'MiB'
return str(val/divisor) + suffix
elif num_digits > 3:
divisor = 1024
suffix = 'KiB'
return str(val/divisor) + suffix
def convert_suffix(val_bin):
base = int(val_bin[:-1])
suffix = val_bin[-1]
mul = 1
if suffix == 'k':
mul = 1024
elif suffix == 'm':
mul = math.pow(1024, 2)
elif suffix == 'g':
mul = math.pow(1024, 3)
elif suffix == 't':
mul = math.pow(1024, 4)
return base * int(mul)
def calc_params(dist_file):
try:
import configparser as ConfigParser
except ImportError:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read(dist_file)
bin_names = []
counts = []
for i, item in enumerate(config.items('dist')):
bin_names.append(item[0])
counts.append(int(item[1]))
bins = list(map(convert_suffix, bin_names))
sum_counts = sum(counts)
raw_dist = list(map(lambda x: x/sum_counts, counts))
bins_sqd = list(map(lambda x: x * x, bins))
zipped_dist = zip(bins, raw_dist)
zipped_dist_sqd = zip(bins_sqd, raw_dist)
dist = list(itertools.starmap(lambda x, y: x*y, zipped_dist))
dist_sqd = list(itertools.starmap(lambda x, y: x*y, zipped_dist_sqd))
e_val = sum(dist)
e_sqd = sum(dist_sqd)
return round(e_val), round(e_sqd - (e_val * e_val))
def main(argv):
parser = argparse.ArgumentParser(
description="Helper tool to calculate correct parameters for a distribution")
parser.add_argument('--file', metavar="DIST-FILE", nargs=1, type=str, help="distribution ini file from fprof")
args = parser.parse_args(argv)
e_val, var = calc_params(args.file[0])
print("Expected size per file: ", convert_val(e_val))
# print("Variance: ", convert_val(var))
num_files = int(input("Num Files? "))
epochs = int(input("Num Epochs? "))
ops = int(input("Num Ops? "))
print("Expected size needed: ", convert_val(num_files*e_val))
print("Expected total traffic: ", convert_val(epochs*ops*e_val))
if __name__ == "__main__":
main(sys.argv[1:])