source: branches/numpy_misc/tools/acceptance_tests/test_latency_bandwidth.py @ 6996

Last change on this file since 6996 was 6996, checked in by rwilson, 15 years ago

Changes to allow for python 2.4 and 2.5 testing.

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/bin/env python
2
3'''Testlet to run the LatencyBandwidth test.'''
4
5import os
6import time
7import test_utils as util
8
9Processor_Numbers = [2, 4, 8, 16]
10
11def 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
19    # get python to run
20    python_env_var = os.getenv('PYTHON')
21
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 = []
39    machines_file = os.path.join('~', '.machines_%s' % cluster)
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
89if __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)
Note: See TracBrowser for help on using the repository browser.