From 908abbbea0c491de061f43b246581e0cf4f3f02e Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 30 Jun 2010 14:22:25 +0000 Subject: par w/o -e dir git-svn-id: https://ws10smt.googlecode.com/svn/trunk@77 ec762483-ff6d-05da-a07a-a48fb63a330f --- vest/parallelize.pl | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'vest') diff --git a/vest/parallelize.pl b/vest/parallelize.pl index d89dcd33..cd2576a9 100755 --- a/vest/parallelize.pl +++ b/vest/parallelize.pl @@ -23,7 +23,7 @@ use Cwd qw(getcwd); my $recycle_clients; # spawn new clients when previous ones terminate my $stay_alive; # dont let server die when having zero clients my $joblist = ""; -my $errordir; +my $errordir=""; my $multiline; my @files_to_stage; my $verbose = 1; @@ -71,6 +71,32 @@ sub preview_files { debug($cmd,$text); $text } +sub prefix_dirname($) { + #like `dirname but if ends in / then return the whole thing + local ($_)=@_; + if (/\/$/) { + $_; + } else { + s#/[^/]$##; + $_ ? $_ : ''; + } +} +sub extend_path($$;$$) { + my ($base,$ext,$mkdir,$baseisdir)=@_; + if (-d $base) { + $base.="/"; + } else { + my $dir; + if ($baseisdir) { + $dir=$base; + $base.='/' unless $base =~ /\/$/; + } else { + $dir=prefix_dirname($base); + } + system("mkdir -p '$dir'") if $mkdir; + } + return $base.$ext; +} my $abscwd=abspath(&getcwd); sub print_help; @@ -110,10 +136,6 @@ for my $arg (@ARGV) { die "Please specify a command to parallelize\n" if $cmd eq ''; -if ($errordir){ - `mkdir -p $errordir`; -} - if ($verbose){ print STDERR "Parallelizing: $cmd\n\n"; } # set cleanup handler @@ -225,7 +247,7 @@ sub numof_live_jobs { return ($#livejobs + 1); } my (@errors,@outs,@cmds); -my $scriptfile="$errordir/$executable.sh"; +my $scriptfile=extend_path("$errordir/","$executable.sh",1,1); if ($errordir) { open SF,">",$scriptfile || die; print SF $cmd,"\n"; -- cgit v1.2.3