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