perf.py 1.93 KB
Newer Older
sfritschi's avatar
sfritschi committed
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
import sys
sys.path.append('../')
import matplotlib.pyplot as plt

from netflow import *

from time import perf_counter
        
def main():
    if len(sys.argv) != 4:
        raise AssertionError("Usage: python3 generate.py <n1> <n2> <n3>")
    
    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)))
    
    target  = [int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])]
    print("Target size: {}".format(target))
    cutoff  = 0.5 * max([basenet.ub[i] - basenet.lb[i] \
                        for i in range(len(basenet.ub))])
    
    i = 0
    max_ = 5
    
    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
        
        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')
58
    plt.close()
sfritschi's avatar
sfritschi committed
59
60
61
    
if __name__ == '__main__':
    main()