[6991] | 1 | #!/bin/env python |
---|
| 2 | |
---|
| 3 | '''Testlet to run the LatencyBandwidth test.''' |
---|
| 4 | |
---|
| 5 | import os |
---|
| 6 | import time |
---|
| 7 | import test_utils as util |
---|
| 8 | |
---|
| 9 | Processor_Numbers = [2, 4, 8, 16] |
---|
| 10 | |
---|
| 11 | def test(logfile): |
---|
| 12 | result = True |
---|
| 13 | start_time = time.time() |
---|
| 14 | |
---|
| 15 | (cluster, domain) = util.get_hostname() |
---|
| 16 | |
---|
| 17 | util.header(logfile, 'Running latency/bandwidth test on %s.' % cluster) |
---|
| 18 | |
---|
[6993] | 19 | # get python to run |
---|
[6996] | 20 | python_env_var = os.getenv('PYTHON') |
---|
[6993] | 21 | |
---|
[6991] | 22 | # compile C code |
---|
| 23 | obj_file = 'ctiming_%s' % cluster |
---|
| 24 | cmd = ('mpicc ctiming.c -lm -o %s' % obj_file) |
---|
| 25 | util.log_print(logfile, 'Compiling ctiming.c ...') |
---|
| 26 | (_, fd) = os.popen4(cmd) |
---|
| 27 | output = fd.read() |
---|
| 28 | status = fd.close() |
---|
| 29 | if status: |
---|
| 30 | util.log_print_nl(logfile, 'ERRORS COMPILING') |
---|
| 31 | util.log_print(logfile, output) |
---|
| 32 | util.footer(logfile, start_time) |
---|
| 33 | return False |
---|
| 34 | |
---|
| 35 | util.log_print_nl(logfile, 'OK\n') |
---|
| 36 | |
---|
| 37 | # run the tests |
---|
| 38 | results = [] |
---|
[6996] | 39 | machines_file = os.path.join('~', '.machines_%s' % cluster) |
---|
[6991] | 40 | for num_procs in Processor_Numbers: |
---|
| 41 | cmd = ('mpirun -np %2d -hostfile %s %s' |
---|
| 42 | % (num_procs, machines_file, obj_file)) |
---|
| 43 | util.log_print(logfile, cmd + ' ...') |
---|
| 44 | (_, fd) = os.popen4(cmd) |
---|
| 45 | output = fd.readlines() |
---|
| 46 | status = fd.close() |
---|
| 47 | if status: |
---|
| 48 | util.log_print_nl(logfile, 'ERRORS') |
---|
| 49 | util.log_print(logfile, '\n'.join(output)) |
---|
| 50 | util.footer(logfile, start_time) |
---|
| 51 | return False |
---|
| 52 | |
---|
| 53 | estimated_bandwidth = None |
---|
| 54 | estimated_latency = None |
---|
| 55 | for line in output: |
---|
| 56 | if line.startswith('Estimated bandwith'): |
---|
| 57 | (_, estimated_bandwidth) = line.split(': ', 1) |
---|
| 58 | estimated_bandwidth = estimated_bandwidth.strip() |
---|
| 59 | (estimated_bandwidth, _) = estimated_bandwidth.split(' ', 1) |
---|
| 60 | if line.startswith('Estimated latency'): |
---|
| 61 | (_, estimated_latency) = line.split(': ', 1) |
---|
| 62 | estimated_latency = estimated_latency.strip() |
---|
| 63 | (estimated_latency, _) = estimated_latency.split(' ', 1) |
---|
| 64 | |
---|
| 65 | if estimated_bandwidth is None or estimated_latency is None: |
---|
| 66 | util.log_print_nl(logfile, 'ERRORS') |
---|
| 67 | util.log_print(logfile, '\n'.join(output)) |
---|
| 68 | util.footer(logfile, start_time) |
---|
| 69 | return False |
---|
| 70 | |
---|
| 71 | results.append((num_procs, float(estimated_bandwidth), int(estimated_latency))) |
---|
| 72 | util.log_print_nl(logfile, 'done') |
---|
| 73 | |
---|
| 74 | # interpret the results |
---|
| 75 | util.log_print(logfile, '\nResults of latency/bandwidth test on %s\n' % cluster) |
---|
| 76 | util.log_print(logfile, '%s\t%s\t%s\n' % ('#procs', 'b/width', 'latency')) |
---|
| 77 | |
---|
| 78 | for (num_processors, estimated_bandwidth, estimated_latency) in results: |
---|
| 79 | util.log_print(logfile, '%d\t%.1f\t%d\n' |
---|
| 80 | % (num_processors, estimated_bandwidth, estimated_latency)) |
---|
| 81 | |
---|
| 82 | util.footer(logfile, start_time) |
---|
| 83 | |
---|
| 84 | os.remove(obj_file) |
---|
| 85 | |
---|
| 86 | return result |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | if __name__ == '__main__': |
---|
| 90 | import sys |
---|
| 91 | |
---|
| 92 | logfile = 'test.log' |
---|
| 93 | if len(sys.argv) > 1: |
---|
| 94 | logfile = sys.argv[1] |
---|
| 95 | |
---|
| 96 | try: |
---|
| 97 | os.remove(logfile) |
---|
| 98 | except: |
---|
| 99 | pass |
---|
| 100 | |
---|
| 101 | if not test(logfile): |
---|
| 102 | sys.exit(10) |
---|
| 103 | |
---|
| 104 | sys.exit(0) |
---|