[37] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | # find projections of LEDs in images |
---|
| 4 | # it spreads the job to all specified processors/machines |
---|
| 5 | # It requires: |
---|
| 6 | # - matlab |
---|
| 7 | # - configdata.m |
---|
| 8 | # - expname |
---|
| 9 | # |
---|
| 10 | # script is useful if more machines or more processors |
---|
| 11 | # are available. |
---|
| 12 | # automatic ssh authentication is necessary, see |
---|
| 13 | # http://www.cs.umd.edu/~arun/misc/ssh.html |
---|
| 14 | # http://www.cvm.uiuc.edu/~ms-drake/linux/ssh_nopw.html |
---|
| 15 | |
---|
| 16 | # $Author: svoboda $ |
---|
| 17 | # $Revision: 2.0 $ |
---|
| 18 | # $Id: im2pmultiproc.pl,v 2.0 2003/06/19 12:07:11 svoboda Exp $ |
---|
| 19 | # $State: Exp $ |
---|
| 20 | |
---|
| 21 | use Env; |
---|
| 22 | # use XML::Simple; |
---|
| 23 | # use Data::Dumper; |
---|
| 24 | |
---|
| 25 | # name of the m-file template |
---|
| 26 | $mfile="im2imstat"; |
---|
| 27 | $mvariable="CamsIds"; |
---|
| 28 | $donefile=".done"; |
---|
| 29 | |
---|
| 30 | # not yet ready |
---|
| 31 | # $config = XMLin('multiprocAtlantic.xml'); |
---|
| 32 | # print Dumper($config); |
---|
| 33 | # @processes = @$config-> |
---|
| 34 | |
---|
| 35 | # load the info about local machines and parallel processes |
---|
| 36 | use virooms; |
---|
| 37 | |
---|
| 38 | # just a debug cycle |
---|
| 39 | foreach $process (@processes) { |
---|
| 40 | print "$process->{'compname'} \n"; |
---|
| 41 | foreach $camId (@{$process->{'camIds'}}) { |
---|
| 42 | print "$camId \n"; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | # create temporary m-files with using the template m-file |
---|
| 47 | # store their names for delete at the very end |
---|
| 48 | # each process must have its own temporary m-file |
---|
| 49 | |
---|
| 50 | # compose the names and commands |
---|
| 51 | foreach $process (@processes) { |
---|
| 52 | $idfile=""; |
---|
| 53 | $str4cmd=""; |
---|
| 54 | foreach $camId (@{$process->{'camIds'}}) { |
---|
| 55 | $idfile = "$idfile$camId"; |
---|
| 56 | $str4cmd = "$str4cmd $camId"; |
---|
| 57 | } |
---|
| 58 | $process->{'scriptName'} = "$ENV{'PWD'}/$mfile${idfile}.m"; |
---|
| 59 | $process->{'donefile'} = "$ENV{'PWD'}/${donefile}${idfile}"; |
---|
| 60 | $process->{'catcmd'} = "echo \"${mvariable} = [${str4cmd}]; donefile='$process->{'donefile'}'; addpath $ENV{'PWD'}; addpath $ENV{'PWD'}/../Cfg; \" | cat - ${mfile}.m > $process->{'scriptName'}"; |
---|
| 61 | $process->{'mcmd'} = "ssh $process->{'compname'} /pub/bin/matlab -nosplash -nojvm < $process->{'scriptName'} > $process->{'scriptName'}.out &"; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | print "*************************** \n"; |
---|
| 65 | |
---|
| 66 | # create the auxiliary scripts |
---|
| 67 | foreach $process (@processes) { |
---|
| 68 | system($process->{'catcmd'}); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | # run the parallel matlabs |
---|
| 72 | foreach $process (@processes) { |
---|
| 73 | system($process->{'mcmd'}); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | # wait until all processing is done |
---|
| 77 | print "Image processing in progress. Plase be patient \n"; |
---|
| 78 | do { |
---|
| 79 | sleep 10; |
---|
| 80 | @donefiles = glob("${donefile}*"); |
---|
| 81 | } while (@donefiles < @processes); |
---|
| 82 | |
---|
| 83 | # copy the data files to a coomon disc space yet to be implemented |
---|
| 84 | |
---|
| 85 | # final cleaning of the auxiliary files |
---|
| 86 | foreach $process (@processes) { |
---|
| 87 | system("rm -f $process->{'donefile'}"); |
---|
| 88 | system("rm -f $process->{'scriptName'}"); |
---|
| 89 | system("rm -f $process->{'scriptName'}.out"); |
---|
| 90 | } |
---|
| 91 | # system("rm -f *.out"); |
---|
| 92 | |
---|