source: misc/tools/acceptance_tests/test_quadrature_parallel_interleaved.py @ 7659

Last change on this file since 7659 was 7656, checked in by gray, 14 years ago

Updating acceptance test files. Still pre-2010 tests.

  • 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    #machines_file = os.path.join('machines_%s' % cluster)
40    single_processor_time = None
41    for num_procs in Processor_Numbers:
42        cmd = ('mpirun -nolocal -np %2d -hostfile %s %s'
43               % (num_procs, util.machines_file, obj_file))
44        util.log_print(logfile, cmd + ' ...')
45        (_, fd) = os.popen4(cmd)
46        output = fd.readlines()
47        status = fd.close()
48        if status:
49            util.log_print_nl(logfile, 'ERRORS')
50            util.log_print(logfile, '\n'.join(output))
51            return False
52
53        elapsed_time = None
54        for line in output:
55            if line.startswith('Time'):
56                (_, elapsed_time) = line.split(' = ', 1)
57                elapsed_time = elapsed_time.strip()
58                (elapsed_time, _) = elapsed_time.split(' ', 1)
59                elapsed_time = float(elapsed_time)
60
61        if elapsed_time is None:
62            util.log_print_nl(logfile, 'ERRORS')
63            util.log_print(logfile, '\n'.join(output))
64            return False
65           
66        results.append((num_procs, elapsed_time))
67        util.log_print_nl(logfile, 'took %.1fs' % elapsed_time)
68
69    # interpret the results
70    util.log_print(logfile, '\nResults of quadrature interleaved parallel test on %s\n' % cluster)
71    util.log_print(logfile, '%s\t%s\t%s\t%s\n' % ('#procs', 'time', 'speedup', 'parallel efficiency'))
72
73    single_processor_time = None
74    for (num_processors, elapsed_time) in results:
75        num_processors = int(num_processors)
76        if num_processors == 1:
77            single_processor_time = elapsed_time
78
79        speedup = single_processor_time / elapsed_time
80        parallel_efficiency = speedup / num_processors
81
82        util.log_print(logfile, '%d\t%.2f\t%.2f\t%.2f\n'
83                       % (num_processors, elapsed_time, speedup, parallel_efficiency))
84
85    os.remove(obj_file)
86
87    return result
88
89
90if __name__ == '__main__':
91    import sys
92
93    logfile = 'test.log'
94    if len(sys.argv) > 1:
95        logfile = sys.argv[1]
96
97    try:
98        os.remove(logfile)
99    except:
100        pass
101
102    if not test(logfile):
103        sys.exit(10)
104
105    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.