Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-examples / python / mp-sched / run_synthetic.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2008 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 """
23 Run synthetic.py for npipes in [1,16], nstages in [1,16]
24 """
25
26 import re
27 import sys
28 import os
29 import tempfile
30 from optparse import OptionParser
31
32
33 def write_shell_script(f, data_filename, description, ncores, gflops, max_pipes_and_stages):
34     """
35     f is the file to write the script to
36     data_filename is the where the data ends up
37     description describes the machine
38     ncores is the number of cores (used to size the workload)
39     gflops is the estimated GFLOPS per core (used to size the workload)
40     """
41
42     f.write("#!/bin/sh\n")
43     f.write("(\n")
44     if description:
45         f.write("echo '#D %s'\n" % (description,))
46
47     for npipes in range(1, max_pipes_and_stages + 1):
48         for nstages in range(1, max_pipes_and_stages + 1):
49             # We'd like each run of synthetic to take ~10 seconds
50             desired_time_per_run = 10
51             est_gflops_avail = min(nstages * npipes, ncores) * gflops
52             nsamples = (est_gflops_avail * desired_time_per_run)/(512.0 * nstages * npipes)
53             nsamples = int(nsamples * 1e9)
54
55             cmd = "./synthetic.py -m -s %d -p %d -N %d\n" % (nstages, npipes, nsamples)
56             f.write(cmd)
57             f.write('if test $? -ge 128; then exit 128; fi\n')
58
59     f.write(") 2>&1 | grep --line-buffered -v '^>>>' | tee %s\n" % (data_filename,))
60     f.flush()
61     
62     
63
64 def main():
65     description = """%prog gathers multiprocessor scaling data using the ./synthetic.py benchmark.
66 All combinations of npipes and nstages between 1 and --max-pipes-and-stages are tried.
67 The -n and -f options provides hints used to size the workload.  We'd like each run
68 of synthetic to take about 10 seconds.  For the full 16x16 case this results in a
69 total runtime of about 43 minutes, assuming that your values for -n and -f are reasonable.
70 For x86 machines, assume 3 FLOPS per processor Hz. E.g., 3 GHz machine -> 9 GFLOPS.
71 plot_flops.py will make pretty graphs from the output data generated by %prog.
72 """
73     usage = "usage: %prog [options] output.dat"
74     parser = OptionParser(usage=usage, description=description)
75     parser.add_option("-d", "--description", metavar="DESC",
76                       help="machine description, e.g., \"Dual quad-core Xeon 3 GHz\"", default=None)
77     parser.add_option("-n", "--ncores", type="int", default=1,
78                       help="number of processor cores [default=%default]")
79     parser.add_option("-g", "--gflops", metavar="GFLOPS", type="float", default=3.0,
80                       help="estimated GFLOPS per core [default=%default]")
81     parser.add_option("-m", "--max-pipes-and-stages", metavar="MAX", type="int", default=16,
82                       help="maximum number of pipes and stages to use [default=%default]")
83     (options, args) = parser.parse_args()
84     if len(args) != 1:
85         parser.print_help()
86         raise SystemExit, 1
87
88     output_filename = args[0]
89
90     shell = os.popen("/bin/sh", "w")
91     
92     write_shell_script(shell,
93                        output_filename,
94                        options.description,
95                        options.ncores,
96                        options.gflops,
97                        options.max_pipes_and_stages)
98     
99 if __name__ == '__main__':
100     main()
101