[6991] | 1 | #!/bin/env python |
---|
| 2 | |
---|
[7656] | 3 | """Testlet to run the QuadratureParallelInterleaved test.""" |
---|
[6991] | 4 | |
---|
| 5 | import os |
---|
| 6 | import time |
---|
| 7 | import test_utils as util |
---|
| 8 | |
---|
| 9 | Processor_Numbers = [1, 2, 4, 8, 16] |
---|
| 10 | |
---|
[7017] | 11 | name = 'Running quadrature parallel interleaved test' |
---|
| 12 | |
---|
[6991] | 13 | def test(logfile): |
---|
| 14 | result = True |
---|
| 15 | |
---|
| 16 | (cluster, domain) = util.get_hostname() |
---|
| 17 | |
---|
[6993] | 18 | # get python to run |
---|
[6996] | 19 | python_env_var = os.getenv('PYTHON') |
---|
[6993] | 20 | |
---|
[6991] | 21 | # compile C code |
---|
[7017] | 22 | util.log_print_nl(logfile, 'Compiling quadrature_parallel_interleaved.c:') |
---|
[6991] | 23 | obj_file = 'quadrature_parallel_interleaved' |
---|
| 24 | cmd = ('mpicc quadrature_parallel_interleaved.c -lm -o %s' % obj_file) |
---|
[7017] | 25 | util.log_print_nl(logfile, cmd) |
---|
[6991] | 26 | (_, fd) = os.popen4(cmd) |
---|
| 27 | output = fd.read() |
---|
| 28 | status = fd.close() |
---|
| 29 | if status: |
---|
| 30 | util.log_print_nl(logfile, 'ERRORS COMPILING') |
---|
| 31 | util.log_print(logfile, output) |
---|
| 32 | return False |
---|
| 33 | |
---|
[7017] | 34 | util.log_print_nl(logfile) |
---|
[6991] | 35 | |
---|
| 36 | # run the tests |
---|
| 37 | results = [] |
---|
[7656] | 38 | #machines_file = os.path.join('~', '.machines_%s' % cluster) |
---|
| 39 | #machines_file = os.path.join('machines_%s' % cluster) |
---|
[6991] | 40 | single_processor_time = None |
---|
| 41 | for num_procs in Processor_Numbers: |
---|
[7017] | 42 | cmd = ('mpirun -nolocal -np %2d -hostfile %s %s' |
---|
[7656] | 43 | % (num_procs, util.machines_file, obj_file)) |
---|
[6991] | 44 | util.log_print(logfile, cmd + ' ...') |
---|
| 45 | (_, fd) = os.popen4(cmd) |
---|
| 46 | output = fd.readlines() |
---|
| 47 | status = fd.close() |
---|
| 48 | if status: |
---|
| 49 | util.log_print_nl(logfile, 'ERRORS') |
---|
| 50 | util.log_print(logfile, '\n'.join(output)) |
---|
| 51 | return False |
---|
| 52 | |
---|
[7244] | 53 | elapsed_time = None |
---|
[6991] | 54 | for line in output: |
---|
| 55 | if line.startswith('Time'): |
---|
| 56 | (_, elapsed_time) = line.split(' = ', 1) |
---|
| 57 | elapsed_time = elapsed_time.strip() |
---|
| 58 | (elapsed_time, _) = elapsed_time.split(' ', 1) |
---|
| 59 | elapsed_time = float(elapsed_time) |
---|
| 60 | |
---|
| 61 | if elapsed_time is None: |
---|
| 62 | util.log_print_nl(logfile, 'ERRORS') |
---|
| 63 | util.log_print(logfile, '\n'.join(output)) |
---|
| 64 | return False |
---|
| 65 | |
---|
| 66 | results.append((num_procs, elapsed_time)) |
---|
| 67 | util.log_print_nl(logfile, 'took %.1fs' % elapsed_time) |
---|
| 68 | |
---|
| 69 | # interpret the results |
---|
| 70 | util.log_print(logfile, '\nResults of quadrature interleaved parallel test on %s\n' % cluster) |
---|
| 71 | util.log_print(logfile, '%s\t%s\t%s\t%s\n' % ('#procs', 'time', 'speedup', 'parallel efficiency')) |
---|
| 72 | |
---|
| 73 | single_processor_time = None |
---|
| 74 | for (num_processors, elapsed_time) in results: |
---|
| 75 | num_processors = int(num_processors) |
---|
| 76 | if num_processors == 1: |
---|
| 77 | single_processor_time = elapsed_time |
---|
| 78 | |
---|
| 79 | speedup = single_processor_time / elapsed_time |
---|
| 80 | parallel_efficiency = speedup / num_processors |
---|
| 81 | |
---|
| 82 | util.log_print(logfile, '%d\t%.2f\t%.2f\t%.2f\n' |
---|
| 83 | % (num_processors, elapsed_time, speedup, parallel_efficiency)) |
---|
| 84 | |
---|
| 85 | os.remove(obj_file) |
---|
| 86 | |
---|
| 87 | return result |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | if __name__ == '__main__': |
---|
| 91 | import sys |
---|
| 92 | |
---|
| 93 | logfile = 'test.log' |
---|
| 94 | if len(sys.argv) > 1: |
---|
| 95 | logfile = sys.argv[1] |
---|
| 96 | |
---|
| 97 | try: |
---|
| 98 | os.remove(logfile) |
---|
| 99 | except: |
---|
| 100 | pass |
---|
| 101 | |
---|
| 102 | if not test(logfile): |
---|
| 103 | sys.exit(10) |
---|
| 104 | |
---|
| 105 | sys.exit(0) |
---|