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

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

Changes from acceptance testing on cyclone.

  • 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        elapsed_time = None
53        for line in output:
54            if line.startswith('Time'):
55                (_, elapsed_time) = line.split(' = ', 1)
56                elapsed_time = elapsed_time.strip()
57                (elapsed_time, _) = elapsed_time.split(' ', 1)
58                elapsed_time = float(elapsed_time)
59
60        if elapsed_time is None:
61            util.log_print_nl(logfile, 'ERRORS')
62            util.log_print(logfile, '\n'.join(output))
63            return False
64           
65        results.append((num_procs, elapsed_time))
66        util.log_print_nl(logfile, 'took %.1fs' % elapsed_time)
67
68    # interpret the results
69    util.log_print(logfile, '\nResults of quadrature interleaved parallel test on %s\n' % cluster)
70    util.log_print(logfile, '%s\t%s\t%s\t%s\n' % ('#procs', 'time', 'speedup', 'parallel efficiency'))
71
72    single_processor_time = None
73    for (num_processors, elapsed_time) in results:
74        num_processors = int(num_processors)
75        if num_processors == 1:
76            single_processor_time = elapsed_time
77
78        speedup = single_processor_time / elapsed_time
79        parallel_efficiency = speedup / num_processors
80
81        util.log_print(logfile, '%d\t%.2f\t%.2f\t%.2f\n'
82                       % (num_processors, elapsed_time, speedup, parallel_efficiency))
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.