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