perf.py 2.03 KB
Newer Older
sfritschi's avatar
sfritschi committed
1
2
3
4
5
6
7
8
9
import sys
sys.path.append('../')
import matplotlib.pyplot as plt

from netflow import *

from time import perf_counter
        
def main():
sfritschi's avatar
sfritschi committed
10
11
    if len(sys.argv) != 6:
        raise AssertionError("Usage: python3 perf.py <2^min threads> <2^max threads> <n1> <n2> <n3>")
sfritschi's avatar
sfritschi committed
12
13
14
15
16
17
18
19
20
    
    basenet = netflow.load_network_from('../netflow/network/network.h5')
    print("Network statistics:")
    print("Throats: %d" % len(basenet.throats))
    pore_throat_counts = [len(pore.throats) for pore in basenet.pores]
    print("Max. number of throats per pore: %d" % max(pore_throat_counts))
    print("Min. number of throats per pore: %d" % min(pore_throat_counts))
    print("Avg. number of throats per pore: %f" % (sum(pore_throat_counts) / len(pore_throat_counts)))
    
sfritschi's avatar
sfritschi committed
21
    target  = [int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5])]
sfritschi's avatar
sfritschi committed
22
23
24
25
    print("Target size: {}".format(target))
    cutoff  = 0.5 * max([basenet.ub[i] - basenet.lb[i] \
                        for i in range(len(basenet.ub))])
    
sfritschi's avatar
sfritschi committed
26
27
    i = int(sys.argv[1])
    max_ = int(sys.argv[2])
sfritschi's avatar
sfritschi committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    
    speedups = []
    threads = []
    times = []
    while (i <= max_):
        nthreads = 1 << i
        print(nthreads)
        
        start = perf_counter()
        dendro = netflow.generate_dendrogram(basenet=basenet, targetsize=target, \
                                        cutoff=cutoff, sd=42, nthreads=nthreads, mute=True)
        end = perf_counter()
        elapsed = end - start
        
sfritschi's avatar
sfritschi committed
42
        print("Elapsed: %e" % elapsed)
sfritschi's avatar
sfritschi committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        print("Generated network statistics:")
        print("Throats: %d" % len(dendro.throats))
        print("Pores:   %d" % len(dendro.pores))
        
        threads.append(nthreads)
        times.append(elapsed)
        
        speedups.append(times[0] / times[i])
        i += 1
        
    plt.figure()
    plt.title(r"Strong Scaling for targetsize {}".format(target))
    plt.xlabel(r"#processes")
    plt.ylabel(r"Speedup")
    plt.plot(threads, speedups, '--bo')
    plt.savefig('plots/strong_scaling.png')
59
    plt.close()
sfritschi's avatar
sfritschi committed
60
61
62
    
if __name__ == '__main__':
    main()