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, util.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.py mandel_ext.c' % 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 | cmd = '%s compile.py mandelplot_ext.c' % python_env_var |
---|
60 | util.log_print_nl(logfile, cmd) |
---|
61 | fd = os.popen(cmd) |
---|
62 | compile_result = fd.read() |
---|
63 | status = fd.close() |
---|
64 | util.log_print(logfile, compile_result) |
---|
65 | if status: |
---|
66 | return False |
---|
67 | |
---|
68 | # run tests |
---|
69 | machines_file = os.path.join('..', util.machines_file) |
---|
70 | result_data = [] |
---|
71 | for num_procs in Processor_Numbers: |
---|
72 | cmd = ('mpirun -nolocal -np %2d -hostfile %s %s mandel_parallel_cyclic.py' |
---|
73 | % (num_procs, machines_file, python_env_var)) |
---|
74 | util.log_print(logfile, cmd + ' ...') |
---|
75 | fd = os.popen(cmd) |
---|
76 | output = fd.readlines() |
---|
77 | status = fd.close() |
---|
78 | if status: |
---|
79 | util.log_print_nl(logfile, 'ERRORS (see logfile %s)' % logfile) |
---|
80 | util.log(logfile, '\n'.join(output)) |
---|
81 | else: |
---|
82 | for line in output: |
---|
83 | if line.startswith('Computed region in'): |
---|
84 | line = line.replace('Computed region in ', '') |
---|
85 | (line, _) = line.split(' ', 1) |
---|
86 | compute_time = float(line) |
---|
87 | util.log_print_nl(logfile, 'computed in %.1fs' % compute_time) |
---|
88 | break |
---|
89 | result_data.append((num_procs, compute_time)) |
---|
90 | |
---|
91 | # reduce results |
---|
92 | one_proc_time = None |
---|
93 | for (num_procs, compute_time) in result_data: |
---|
94 | if num_procs == 1: |
---|
95 | one_proc_time = compute_time |
---|
96 | break |
---|
97 | |
---|
98 | if one_proc_time is None: |
---|
99 | util.log_print_nl(logfile, 'ERROR, cannot find single processor compute time!?') |
---|
100 | return False |
---|
101 | |
---|
102 | util.log_print_nl(logfile) |
---|
103 | util.log_print_nl(logfile, 'Results for Mandelbrot Parallel Cyclic test:') |
---|
104 | util.log_print_nl(logfile, '%s\t%s\t%s\t%s' % ('#procs', 'time', 'speedup', 'parallel_efficiency')) |
---|
105 | for res in result_data: |
---|
106 | (num_procs, compute_time) = res |
---|
107 | |
---|
108 | speedup = one_proc_time / compute_time |
---|
109 | parallel_efficiency = speedup / num_procs |
---|
110 | |
---|
111 | util.log_print_nl(logfile, '%d\t%.2f\t%.3f\t%.3f' |
---|
112 | % (num_procs, compute_time, speedup, parallel_efficiency)) |
---|
113 | |
---|
114 | # return to original directory |
---|
115 | os.chdir(home_directory) |
---|
116 | |
---|
117 | return result |
---|
118 | |
---|
119 | |
---|
120 | if __name__ == '__main__': |
---|
121 | import sys |
---|
122 | |
---|
123 | logfile = os.path.join(os.getcwd(), 'test.log') |
---|
124 | if len(sys.argv) > 1: |
---|
125 | logfile = sys.argv[1] |
---|
126 | |
---|
127 | try: |
---|
128 | os.remove(logfile) |
---|
129 | except: |
---|
130 | pass |
---|
131 | |
---|
132 | if not test(logfile): |
---|
133 | sys.exit(10) |
---|
134 | |
---|
135 | sys.exit(0) |
---|
136 | |
---|