source: branches/anuga_1_2_0/misc/tools/acceptance_tests/test_quadrature_parallel_interleaved.py @ 8071

Last change on this file since 8071 was 8071, checked in by gray, 13 years ago

modified acceptance tests to test the cen-4470-test HPC.

  • Property svn:executable set to *
File size: 3.3 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, 5, 8, 16, 32, 38, 64, 76]
10
11name = 'Running quadrature parallel interleaved test'
12
13def test(logfile):
14    result = True
15
16    (cluster, domain) = util.get_hostname()
17    print "cluster", cluster
18    print "domain", domain
19    # get python to run
20    python_env_var = os.getenv('PYTHON')
21
22    # compile C code
23    util.log_print_nl(logfile, 'Compiling quadrature_parallel_interleaved.c:')
24    obj_file = 'quadrature_parallel_interleaved'
25    cmd = ('mpicc quadrature_parallel_interleaved.c -lm -o %s' % obj_file)
26    util.log_print_nl(logfile, cmd)
27    (_, fd) = os.popen4(cmd)
28    output = fd.read()
29    status = fd.close()
30    if status:
31        util.log_print_nl(logfile, 'ERRORS COMPILING')
32        util.log_print(logfile, output)
33        return False
34
35    util.log_print_nl(logfile)
36
37    # run the tests
38    results = []
39    #machines_file = os.path.join('~', '.machines_%s' % cluster)
40    #machines_file = os.path.join('machines_%s' % cluster)
41    single_processor_time = None
42    for num_procs in Processor_Numbers: 
43        if cluster == 'cen-4470-test':
44            cmd = ('mpirun -np %2d %s'
45                   % (num_procs, obj_file))
46        else:
47            cmd = ('mpirun -nolocal -np %2d -hostfile %s %s'
48                   % (num_procs, util.machines_file, obj_file))
49        util.log_print(logfile, cmd + ' ...')
50        (_, fd) = os.popen4(cmd)
51        output = fd.readlines()
52        status = fd.close()
53        if status:
54            util.log_print_nl(logfile, 'ERRORS')
55            util.log_print(logfile, '\n'.join(output))
56            return False
57
58        elapsed_time = None
59        for line in output:
60            if line.startswith('Time'):
61                (_, elapsed_time) = line.split(' = ', 1)
62                elapsed_time = elapsed_time.strip()
63                (elapsed_time, _) = elapsed_time.split(' ', 1)
64                elapsed_time = float(elapsed_time)
65
66        if elapsed_time is None:
67            util.log_print_nl(logfile, 'ERRORS')
68            util.log_print(logfile, '\n'.join(output))
69            return False
70           
71        results.append((num_procs, elapsed_time))
72        util.log_print_nl(logfile, 'took %.1fs' % elapsed_time)
73
74    # interpret the results
75    util.log_print(logfile, '\nResults of quadrature interleaved parallel test on %s\n' % cluster)
76    util.log_print(logfile, '%s\t%s\t%s\t%s\n' % ('#procs', 'time', 'speedup', 'parallel efficiency'))
77
78    single_processor_time = None
79    for (num_processors, elapsed_time) in results:
80        num_processors = int(num_processors)
81        if num_processors == 1:
82            single_processor_time = elapsed_time
83
84        speedup = single_processor_time / elapsed_time
85        parallel_efficiency = speedup / num_processors
86
87        util.log_print(logfile, '%d\t%.2f\t%.2f\t%.2f\n'
88                       % (num_processors, elapsed_time, speedup, parallel_efficiency))
89
90    os.remove(obj_file)
91
92    return result
93
94
95if __name__ == '__main__':
96    import sys
97
98    logfile = 'test.log'
99    if len(sys.argv) > 1:
100        logfile = sys.argv[1]
101
102    try:
103        os.remove(logfile)
104    except:
105        pass
106
107    if not test(logfile):
108        sys.exit(10)
109
110    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.