source: branches/numpy_misc/tools/acceptance_tests/test_test_pypar.py @ 6991

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

Initial commit of the cluster acceptance package.

  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#!/bin/env python
2
3'''Testlet to run the pypar tests.'''
4
5import os
6import time
7import test_utils as util
8
9Processor_Numbers = [1, 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 pypar test on %s.' % cluster)
18
19    # run the test_pypar.py tests
20    machines_file = '~/.machines_%s' % cluster
21    for num_procs in Processor_Numbers:
22        cmd = ('mpirun -np %2d -hostfile %s python test_pypar.py'
23               % (num_procs, machines_file))
24        util.log_print(logfile, cmd + ' ...')
25        fd = os.popen(cmd)
26        output = fd.readlines()
27        status = fd.close()
28        if status:
29            util.log_print_nl(logfile, 'ERRORS')
30            util.log_print(logfile, '\n'.join(output))
31            util.footer(logfile, start_time)
32            result = False
33        else:
34            util.log_print_nl(logfile, 'OK')
35
36    util.log_print_nl(logfile)
37
38    if result is True:
39        util.log_print_nl(logfile, 'test_pypar.py results: GOOD')
40    else:
41        util.log_print_nl(logfile, 'test_pypar.py results: ***** FAILED *****')
42
43    util.log_print_nl(logfile)
44
45    # now for the mandelbrot test
46    home_directory = os.getcwd()
47    os.chdir('mandelbrot')
48   
49    util.log_print_nl(logfile, 'python compile_mandelbrot_c_extensions.py')
50    fd = os.popen('python compile_mandelbrot_c_extensions.py')
51    compile_result = fd.read()
52    status = fd.close()
53    util.log_print(logfile, compile_result)
54    if status:
55        return False
56
57    # run tests
58    machines_file = '~/.machines_%s' % cluster
59    result_data = []
60    for num_procs in Processor_Numbers:
61        cmd = ('mpirun -np %2d -hostfile %s python mandel_parallel_cyclic.py'
62               % (num_procs, machines_file))
63        util.log_print(logfile, cmd + ' ...')
64        fd = os.popen(cmd)
65        output = fd.readlines()
66        status = fd.close()
67        if status:
68            util.log_print_nl(logfile, 'ERRORS (see logfile %s)' % logfile)
69            util.log(logfile, '\n'.join(output))
70        else:
71            for line in output:
72                if line.startswith('Computed region in'):
73                    line = line.replace('Computed region in ', '')
74                    (line, _) = line.split(' ', 1)
75                    compute_time = float(line)
76                    util.log_print_nl(logfile, 'computed in %.1fs' % compute_time)
77                    break
78            result_data.append((num_procs, compute_time))
79
80    # reduce results
81    one_proc_time = None
82    for (num_procs, compute_time) in result_data:
83        if num_procs == 1:
84            one_proc_time = compute_time
85            break
86
87    if one_proc_time is None:
88        util.log_print_nl(logfile, 'ERROR, cannot find single processor compute time!?')
89        return False
90
91    util.log_print_nl(logfile)
92    util.log_print_nl(logfile, 'Results for Mandelbrot Parallel Cyclic test:')
93    util.log_print_nl(logfile, '%s\t%s\t%s\t%s' % ('#procs', 'time', 'speedup', 'parallel_efficiency'))
94    for res in result_data:
95        (num_procs, compute_time) = res
96       
97        speedup = one_proc_time / compute_time
98        parallel_efficiency = speedup / num_procs
99
100        util.log_print_nl(logfile, '%d\t%.2f\t%.3f\t%.3f'
101                          % (num_procs, compute_time, speedup, parallel_efficiency))
102
103    # return to original directory
104    os.chdir(home_directory)
105
106    util.footer(logfile, start_time)
107
108    return result
109
110
111if __name__ == '__main__':
112    import sys
113   
114    logfile = os.path.join(os.getcwd(), 'test.log')
115    if len(sys.argv) > 1:
116        logfile = sys.argv[1]
117
118    try:
119        os.remove(logfile)
120    except:
121        pass
122
123    if not test(logfile):
124        sys.exit(10)
125
126    sys.exit(0)
127
Note: See TracBrowser for help on using the repository browser.