1 | #!/bin/env python |
---|
2 | |
---|
3 | '''Testlet to run the pypar tests.''' |
---|
4 | |
---|
5 | import os |
---|
6 | import time |
---|
7 | import test_utils as util |
---|
8 | |
---|
9 | Processor_Numbers = [1, 2, 4, 8, 16] |
---|
10 | |
---|
11 | name = 'Running pypar test' |
---|
12 | |
---|
13 | def 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 | # run the test_pypar.py tests |
---|
22 | machines_file = os.path.join('~', '.machines_%s' % cluster) |
---|
23 | for num_procs in Processor_Numbers: |
---|
24 | cmd = ('mpirun -nolocal -np %2d -hostfile %s %s test_pypar.py' |
---|
25 | % (num_procs, machines_file, python_env_var)) |
---|
26 | util.log_print(logfile, cmd + ' ...') |
---|
27 | fd = os.popen(cmd) |
---|
28 | output = fd.readlines() |
---|
29 | status = fd.close() |
---|
30 | if status: |
---|
31 | util.log_print_nl(logfile, 'ERRORS') |
---|
32 | util.log_print(logfile, '\n'.join(output)) |
---|
33 | result = False |
---|
34 | else: |
---|
35 | util.log_print_nl(logfile, 'OK') |
---|
36 | |
---|
37 | util.log_print_nl(logfile) |
---|
38 | |
---|
39 | if result is True: |
---|
40 | util.log_print_nl(logfile, 'test_pypar.py results: GOOD') |
---|
41 | else: |
---|
42 | util.log_print_nl(logfile, 'test_pypar.py results: ***** FAILED *****') |
---|
43 | |
---|
44 | util.log_print_nl(logfile) |
---|
45 | |
---|
46 | # now for the mandelbrot test |
---|
47 | home_directory = os.getcwd() |
---|
48 | os.chdir('mandelbrot') |
---|
49 | |
---|
50 | cmd = '%s compile_mandelbrot_c_extensions.py' % python_env_var |
---|
51 | util.log_print_nl(logfile, cmd) |
---|
52 | fd = os.popen(cmd) |
---|
53 | compile_result = fd.read() |
---|
54 | status = fd.close() |
---|
55 | util.log_print(logfile, compile_result) |
---|
56 | if status: |
---|
57 | return False |
---|
58 | |
---|
59 | # run tests |
---|
60 | machines_file = os.path.join('~', '.machines_%s' % cluster) |
---|
61 | result_data = [] |
---|
62 | for num_procs in Processor_Numbers: |
---|
63 | cmd = ('mpirun -nolocal -np %2d -hostfile %s %s mandel_parallel_cyclic.py' |
---|
64 | % (num_procs, machines_file, python_env_var)) |
---|
65 | util.log_print(logfile, cmd + ' ...') |
---|
66 | fd = os.popen(cmd) |
---|
67 | output = fd.readlines() |
---|
68 | status = fd.close() |
---|
69 | if status: |
---|
70 | util.log_print_nl(logfile, 'ERRORS (see logfile %s)' % logfile) |
---|
71 | util.log(logfile, '\n'.join(output)) |
---|
72 | else: |
---|
73 | for line in output: |
---|
74 | if line.startswith('Computed region in'): |
---|
75 | line = line.replace('Computed region in ', '') |
---|
76 | (line, _) = line.split(' ', 1) |
---|
77 | compute_time = float(line) |
---|
78 | util.log_print_nl(logfile, 'computed in %.1fs' % compute_time) |
---|
79 | break |
---|
80 | result_data.append((num_procs, compute_time)) |
---|
81 | |
---|
82 | # reduce results |
---|
83 | one_proc_time = None |
---|
84 | for (num_procs, compute_time) in result_data: |
---|
85 | if num_procs == 1: |
---|
86 | one_proc_time = compute_time |
---|
87 | break |
---|
88 | |
---|
89 | if one_proc_time is None: |
---|
90 | util.log_print_nl(logfile, 'ERROR, cannot find single processor compute time!?') |
---|
91 | return False |
---|
92 | |
---|
93 | util.log_print_nl(logfile) |
---|
94 | util.log_print_nl(logfile, 'Results for Mandelbrot Parallel Cyclic test:') |
---|
95 | util.log_print_nl(logfile, '%s\t%s\t%s\t%s' % ('#procs', 'time', 'speedup', 'parallel_efficiency')) |
---|
96 | for res in result_data: |
---|
97 | (num_procs, compute_time) = res |
---|
98 | |
---|
99 | speedup = one_proc_time / compute_time |
---|
100 | parallel_efficiency = speedup / num_procs |
---|
101 | |
---|
102 | util.log_print_nl(logfile, '%d\t%.2f\t%.3f\t%.3f' |
---|
103 | % (num_procs, compute_time, speedup, parallel_efficiency)) |
---|
104 | |
---|
105 | # return to original directory |
---|
106 | os.chdir(home_directory) |
---|
107 | |
---|
108 | return result |
---|
109 | |
---|
110 | |
---|
111 | if __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 | |
---|