Index: scripts/ems/experiment.perl
===================================================================
--- scripts/ems/experiment.perl	(revision 3799)
+++ scripts/ems/experiment.perl	(working copy)
@@ -1071,7 +1071,7 @@
 
 sub get_qsub_args {
     my ($step) = @_;
-    my $qsub_args = &get("$step:qsub-settings");
+    my $qsub_args = &backoff_and_get("$step:qsub-settings");
     $qsub_args = "" unless defined($qsub_args);
     my $memory = &get("$step:qsub-memory");
     $qsub_args .= " -pe memory $memory" if defined($memory);
@@ -2051,7 +2051,13 @@
     }
     if ($jobs && $CLUSTER) {
 	if ($qsub_filter) {
-	    $cmd = "qsub $filter\n";
+	    my $jobscript="$dir/evaluation/filterscript$$.sh";
+	    my $qsubout = "$dir/evaluation/filterscript$$.out";
+	    my $qsuberr = "$dir/evaluation/filterscript$$.err";
+#	    $cmd = "qsub $filter\n";
+	    $cmd = "echo -e '#!/bin/bash\\n\\n$filter' > $jobscript\n\n";
+	    $cmd .= "chmod 755 $jobscript\n";
+	    $cmd .= "qsub -o $qsubout -e $qsuberr $jobscript > $jobscript.log 2>&1\n";
 	    $cmd .= "perl -e 'while(! -e \"$dir/evaluation/filtered.$set.$VERSION/info\") { sleep(10); }'\n";
 	}
 	else {
@@ -2066,7 +2072,7 @@
 	    $cmd .= "$scripts/generic/moses-parallel.pl";
 	}
 	my $qsub_args = &get_qsub_args($DO_STEP[$step_id]);
-	$cmd .= " -queue-parameters \"$qsub_args\"" if ($CLUSTER && $qsub_args);
+	$cmd .= " -old-sge -queue-parameters \"$qsub_args\"" if ($CLUSTER && $qsub_args);
 	$cmd .= " -decoder $decoder -config $dir/evaluation/filtered.$set.$VERSION/moses.ini -input-file $input --jobs $jobs  -decoder-parameters \"$settings\" > $system_output";
 	
 	$cmd .= " -n-best-file $system_output.best$nbest_size -n-best-size $nbest" if $nbest;
Index: scripts/generic/qsub-wrapper.pl
===================================================================
--- scripts/generic/qsub-wrapper.pl	(revision 3799)
+++ scripts/generic/qsub-wrapper.pl	(working copy)
@@ -149,9 +149,10 @@
 open (IN,"$jobscript.log") or die "Can't read main job id: $jobscript.log";
 chomp($res=<IN>);
 split(/\s+/,$res);
-my $id=$_[2];
+#my $id=$_[2];
+my $id=$res;
 die "Failed to get job id from $jobscript.log, got: $res"
-  if $id !~ /^[0-9]+$/;
+  if $id !~ /^[0-9]+\.draxx$/;
 close(IN);
 
 print STDERR " res:$res\n";
@@ -169,7 +170,8 @@
   safesystem("\\rm -f $checkpointfile") or die;
 
   # start the 'hold' job, i.e. the job that will wait
-  $cmd="qsub -cwd $queueparameters -hold_jid $id -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript >& $qsubname.W.log";
+#  $cmd="qsub -cwd $queueparameters -hold_jid $id -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript >& $qsubname.W.log";
+  $cmd="qsub $queueparameters -W depend=afterok:$id -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript >& $qsubname.W.log";
   safesystem($cmd) or die;
   
   # and wait for checkpoint file to appear
@@ -194,6 +196,13 @@
 sub check_exit_status(){
   my $failure=0;
 
+  # Wait a little in case $qsubout is slow to appear
+  my $i=0;
+  while (! -e $qsubout && $i < 100) {
+    sleep(5);
+    $i++;
+  } 
+
   print STDERR "check_exit_status of submitted job $id\n";
   open(IN,"$qsubout") or die "Can't read $qsubout";
   while (<IN>){
Index: scripts/generic/moses-parallel.pl
===================================================================
--- scripts/generic/moses-parallel.pl	(revision 3799)
+++ scripts/generic/moses-parallel.pl	(working copy)
@@ -439,7 +439,8 @@
   my $batch_and_join = undef;
   if ($old_sge) {
     # old SGE understands -b no as the default and does not understand 'yes'
-    $batch_and_join = "-j y";
+#    $batch_and_join = "-j y";
+    $batch_and_join = "-j eo";
   } else {
     $batch_and_join = "-b no -j yes";
   }
@@ -454,16 +455,18 @@
     or die "Can't read id of job ${jobscript}${idx}.log";
   chomp($res=<IN>);
   split(/\s+/,$res);
-  $id=$_[2];
+#  $id=$_[2];
+  $id=$res;
   die "Failed to guess job id from $jobscript$idx.log, got: $res"
-    if $id !~ /^[0-9]+$/;
+    if $id !~ /^[0-9]+\.draxx$/;
   close(IN);
 
   push @sgepids, $id;
  }
 
  #waiting until all jobs have finished
- my $hj = "-hold_jid " . join(" -hold_jid ", @sgepids);
+# my $hj = "-hold_jid " . join(" -hold_jid ", @sgepids);
+ my $hj = "-W depend=afterok:" . join(":", @sgepids);
 
  if ($old_sge) {
   # we need to implement our own waiting script
@@ -478,7 +481,8 @@
   safesystem("\\rm -f $checkpointfile") or kill_all_and_quit();
 
   # start the 'hold' job, i.e. the job that will wait
-  $cmd="qsub -cwd $queueparameters $hj -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript 2> $qsubname.W.log";
+#  $cmd="qsub -cwd $queueparameters $hj -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript 2> $qsubname.W.log";
+  $cmd="qsub $queueparameters $hj -z -o $checkpointfile -e /dev/null -N $qsubname.W $syncscript 2> $qsubname.W.log";
   safesystem($cmd) or kill_all_and_quit();
   
   # and wait for checkpoint file to appear
Index: scripts/Makefile
===================================================================
--- scripts/Makefile	(revision 3799)
+++ scripts/Makefile	(working copy)
@@ -8,8 +8,8 @@
 # Set TARGETDIR to directory where you want the compiled scripts to be copied
 # to.
 # Set BINDIR to the directory where GIZA++ and other tools are installed.
-TARGETDIR=/mnt/odin3/bhaddow/moses
-BINDIR=/mnt/odin3/bhaddow/moses/bin
+TARGETDIR=/usr/local/bin/moses-scripts
+BINDIR=/usr/local/bin
 
 MAIN_SCRIPTS_TARGET_DIR=$(TARGETDIR)
 # MAIN_SCRIPTS_TARGET_DIR=$(shell echo `pwd`/temp)
