root/branches/newmole/tsuite/run_parallel.pl
| Revision 2348, 4.4 kB (checked in by gary, 5 months ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # I have written a little perl script that runs both the auto and slow |
| 4 | # test suites in parallel on suitable machines. The syntax is: |
| 5 | # |
| 6 | # run_parallel.pl cloudy.exe |
| 7 | # |
| 8 | # or |
| 9 | # |
| 10 | # run_parallel.pl cloudy.exe 8 |
| 11 | # |
| 12 | # where the first parameter is the name of the Cloudy executable. |
| 13 | # If the parameter is completely omitted (or a "." is entered), it |
| 14 | # will default to "../source/cloudy.exe". You can also supply the |
| 15 | # name of one of the sys_xxx directories, in which case the path will |
| 16 | # default to "../source/sys_xxx/cloudy.exe". In all other cases |
| 17 | # cloudy.exe should either be in your search path, or the full pathname |
| 18 | # should be used. The second number is the number of processors to use. |
| 19 | # It can be any number >= 0. However, using numbers larger than roughly |
| 20 | # 8 will not give any speed advantage since the time will then be |
| 21 | # set by the longest running test sims. The second number is optional |
| 22 | # and will default to the number of processosrs on your computer |
| 23 | # (this number is only correctly determined under Linux and Windows, |
| 24 | # it will be set to 1 on other systems). |
| 25 | # |
| 26 | # If the number of processors is set to 0, the script will exit after |
| 27 | # creating the Makefile (i.e., the test suite will not be run). |
| 28 | # |
| 29 | # NB NB - The script will first delete any remaining output from a |
| 30 | # previous run of the test suite by calling the script clean_tsuite.pl |
| 31 | # (this includes calls with the number of processors set to 0) ! |
| 32 | # |
| 33 | # The script uses "gmake" (GNU make) to run the test cases. In case |
| 34 | # that doesn't exist, you can try replacing the two calls below with |
| 35 | # "make". If the version is not too old, that should work as well |
| 36 | # provided it supports the -j parameter for parallel execution. |
| 37 | # |
| 38 | # Peter van Hoof |
| 39 | |
| 40 | if( -d "../source/$ARGV[0]" ) { |
| 41 | $exe = "../../source/$ARGV[0]/cloudy.exe"; |
| 42 | } |
| 43 | else { |
| 44 | $exe = "$ARGV[0]"; |
| 45 | } |
| 46 | |
| 47 | if( "$ARGV[1]" eq "" ) { |
| 48 | # the following should work under Windows. |
| 49 | $nproc = $ENV{'NUMBER_OF_PROCESSORS'}; |
| 50 | if( $nproc eq "" ) |
| 51 | { |
| 52 | # this branch is for non-Windows |
| 53 | if( -r "/proc/cpuinfo" ) |
| 54 | { |
| 55 | # this branch is for Linux |
| 56 | $nproc = 0; |
| 57 | open( foo, "</proc/cpuinfo" ); |
| 58 | while( <foo> ) |
| 59 | { |
| 60 | if( /^processor/ ) |
| 61 | { |
| 62 | ++$nproc; |
| 63 | } |
| 64 | } |
| 65 | close( foo ); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | # we don't know how to determine the number of CPUs |
| 70 | $nproc = 1; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | else { |
| 75 | $nproc = $ARGV[1]; |
| 76 | } |
| 77 | |
| 78 | # clean up first |
| 79 | if( -e "./clean_tsuite.pl" ) { |
| 80 | system "./clean_tsuite.pl"; |
| 81 | } |
| 82 | else { |
| 83 | die "./clean_tsuite.pl not found!"; |
| 84 | } |
| 85 | |
| 86 | $all = "all: "; |
| 87 | $rules = ""; |
| 88 | $i = 0; |
| 89 | |
| 90 | # this funny sequence is to assure that the heavy jobs are upfront... |
| 91 | while( defined( $input = glob("slow/h*.in slow/[A-Za-gi-z]*.in auto/o*.in auto/b*.in auto/d*.in auto/l*.in auto/p*.in auto/h*.in auto/n*.in auto/i*.in auto/a*.in auto/[A-Zce-gjkmq-z]*.in") ) ) { |
| 92 | $i++; |
| 93 | @inp = split( '/', $input ); |
| 94 | $output = $inp[1]; |
| 95 | $output2 = $inp[1]; |
| 96 | $output3 = $input; |
| 97 | $output =~ s/\.in/.out/gi; |
| 98 | $output2 =~ s/\.in/.err/gi; |
| 99 | $output3 =~ s/\.in/.out/gi; |
| 100 | $all = "$all$output3 "; |
| 101 | if( $i%4 == 0 ) { |
| 102 | $all = "$all\\\n\t"; |
| 103 | } |
| 104 | $rules = "$rules$output3: $input\n"; |
| 105 | $rules = "$rules\tcd $inp[0] ; $exe < $inp[1] > $output 2> $output2\n" |
| 106 | } |
| 107 | open( foo, ">Makefile" ); |
| 108 | print foo $all; |
| 109 | print foo "\n"; |
| 110 | print foo $rules; |
| 111 | close foo; |
| 112 | |
| 113 | # if number of processors is 0 only create Makefile and exit |
| 114 | if( $nproc > 0 ) { |
| 115 | print "\nNow I will run the test suite using $nproc processors\n\n"; |
| 116 | |
| 117 | # this does the heavy lifting... |
| 118 | # try make instead if gmake doesn't exist on your system |
| 119 | system "gmake -i -j $nproc"; |
| 120 | |
| 121 | # this was produced by the optimizers and is not really part of the test suite |
| 122 | # its presence will fool the checkall.pl script.... |
| 123 | unlink "auto/optimal.in"; |
| 124 | |
| 125 | if( $nproc > 1 ) { |
| 126 | # just in case func_trans_read was run before func_trans_punch was complete |
| 127 | unlink "auto/func_trans_read.out"; |
| 128 | # try make instead if gmake doesn't exist on your system |
| 129 | system "gmake -i -j $nproc"; |
| 130 | } |
| 131 | |
| 132 | # now do the checking |
| 133 | print "\n\n\n"; |
| 134 | print "========================================\n"; |
| 135 | print " Checking auto test suite \n"; |
| 136 | print "========================================\n"; |
| 137 | system "cd auto ; ./checkall.pl"; |
| 138 | print "\n\n\n"; |
| 139 | print "========================================\n"; |
| 140 | print " Checking slow test suite \n"; |
| 141 | print "========================================\n"; |
| 142 | system "cd slow ; ./checkall.pl"; |
| 143 | } |
Note: See TracBrowser
for help on using the browser.
