#!/bin/env python """Testlet to run the pypar tests.""" import os import time import test_utils as util Processor_Numbers = [1, 2, 4, 8, 16] name = 'Running pypar test' def test(logfile): result = True (cluster, domain) = util.get_hostname() # get python to run python_env_var = os.getenv('PYTHON') # run the test_pypar.py tests #machines_file = os.path.join('~', '.machines_%s' % cluster) for num_procs in Processor_Numbers: cmd = ('mpirun -nolocal -np %2d -hostfile %s %s test_pypar.py' % (num_procs, util.machines_file, python_env_var)) util.log_print(logfile, cmd + ' ...') fd = os.popen(cmd) output = fd.readlines() status = fd.close() if status: util.log_print_nl(logfile, 'ERRORS') util.log_print(logfile, '\n'.join(output)) result = False else: util.log_print_nl(logfile, 'OK') util.log_print_nl(logfile) if result is True: util.log_print_nl(logfile, 'test_pypar.py results: GOOD') else: util.log_print_nl(logfile, 'test_pypar.py results: ***** FAILED *****') util.log_print_nl(logfile) # now for the mandelbrot test home_directory = os.getcwd() os.chdir('mandelbrot') cmd = '%s compile.py mandel_ext.c' % python_env_var util.log_print_nl(logfile, cmd) fd = os.popen(cmd) compile_result = fd.read() status = fd.close() util.log_print(logfile, compile_result) if status: return False cmd = '%s compile.py mandelplot_ext.c' % python_env_var util.log_print_nl(logfile, cmd) fd = os.popen(cmd) compile_result = fd.read() status = fd.close() util.log_print(logfile, compile_result) if status: return False # run tests machines_file = os.path.join('..', util.machines_file) result_data = [] for num_procs in Processor_Numbers: cmd = ('mpirun -nolocal -np %2d -hostfile %s %s mandel_parallel_cyclic.py' % (num_procs, machines_file, python_env_var)) util.log_print(logfile, cmd + ' ...') fd = os.popen(cmd) output = fd.readlines() status = fd.close() if status: util.log_print_nl(logfile, 'ERRORS (see logfile %s)' % logfile) util.log(logfile, '\n'.join(output)) else: for line in output: if line.startswith('Computed region in'): line = line.replace('Computed region in ', '') (line, _) = line.split(' ', 1) compute_time = float(line) util.log_print_nl(logfile, 'computed in %.1fs' % compute_time) break result_data.append((num_procs, compute_time)) # reduce results one_proc_time = None for (num_procs, compute_time) in result_data: if num_procs == 1: one_proc_time = compute_time break if one_proc_time is None: util.log_print_nl(logfile, 'ERROR, cannot find single processor compute time!?') return False util.log_print_nl(logfile) util.log_print_nl(logfile, 'Results for Mandelbrot Parallel Cyclic test:') util.log_print_nl(logfile, '%s\t%s\t%s\t%s' % ('#procs', 'time', 'speedup', 'parallel_efficiency')) for res in result_data: (num_procs, compute_time) = res speedup = one_proc_time / compute_time parallel_efficiency = speedup / num_procs util.log_print_nl(logfile, '%d\t%.2f\t%.3f\t%.3f' % (num_procs, compute_time, speedup, parallel_efficiency)) # return to original directory os.chdir(home_directory) return result if __name__ == '__main__': import sys logfile = os.path.join(os.getcwd(), 'test.log') if len(sys.argv) > 1: logfile = sys.argv[1] try: os.remove(logfile) except: pass if not test(logfile): sys.exit(10) sys.exit(0)