source: branches/numpy_misc/tools/acceptance_tests/test_quadrature_parallel_interleaved.py @ 7077

Last change on this file since 7077 was 7017, checked in by rwilson, 16 years ago

Improved reporting.

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/bin/env python
2
3'''Testlet to run the QuadratureParallelInterleaved test.'''
4
5import os
6import time
7import test_utils as util
8
9Processor_Numbers = [1, 2, 4, 8, 16]
10
11name = 'Running quadrature parallel interleaved test'
12
13def test(logfile):
14    result = True
15
16    (cluster, domain) = util.get_hostname()
17
18    # get python to run
19    python_env_var = os.getenv('PYTHON')
20
21    # compile C code
22    util.log_print_nl(logfile, 'Compiling quadrature_parallel_interleaved.c:')
23    obj_file = 'quadrature_parallel_interleaved'
24    cmd = ('mpicc quadrature_parallel_interleaved.c -lm -o %s' % obj_file)
25    util.log_print_nl(logfile, cmd)
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
34    util.log_print_nl(logfile)
35
36    # run the tests
37    results = []
38    machines_file = os.path.join('~', '.machines_%s' % cluster)
39    single_processor_time = None
40    for num_procs in Processor_Numbers:
41        cmd = ('mpirun -nolocal -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            return False
51
52        for line in output:
53            if line.startswith('Time'):
54                (_, elapsed_time) = line.split(' = ', 1)
55                elapsed_time = elapsed_time.strip()
56                (elapsed_time, _) = elapsed_time.split(' ', 1)
57                elapsed_time = float(elapsed_time)
58
59        if elapsed_time is None:
60            util.log_print_nl(logfile, 'ERRORS')
61            util.log_print(logfile, '\n'.join(output))
62            return False
63           
64        results.append((num_procs, elapsed_time))
65        util.log_print_nl(logfile, 'took %.1fs' % elapsed_time)
66
67    # interpret the results
68    util.log_print(logfile, '\nResults of quadrature interleaved parallel test on %s\n' % cluster)
69    util.log_print(logfile, '%s\t%s\t%s\t%s\n' % ('#procs', 'time', 'speedup', 'parallel efficiency'))
70
71    single_processor_time = None
72    for (num_processors, elapsed_time) in results:
73        num_processors = int(num_processors)
74        if num_processors == 1:
75            single_processor_time = elapsed_time
76
77        speedup = single_processor_time / elapsed_time
78        parallel_efficiency = speedup / num_processors
79
80        util.log_print(logfile, '%d\t%.2f\t%.2f\t%.2f\n'
81                       % (num_processors, elapsed_time, speedup, parallel_efficiency))
82
83    os.remove(obj_file)
84
85    return result
86
87
88if __name__ == '__main__':
89    import sys
90
91    logfile = 'test.log'
92    if len(sys.argv) > 1:
93        logfile = sys.argv[1]
94
95    try:
96        os.remove(logfile)
97    except:
98        pass
99
100    if not test(logfile):
101        sys.exit(10)
102
103    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.