Index: /tags/ipp-pv3-20140717/ippTasks/remote.pro
===================================================================
--- /tags/ipp-pv3-20140717/ippTasks/remote.pro	(revision 37280)
+++ /tags/ipp-pv3-20140717/ippTasks/remote.pro	(revision 37281)
@@ -5,4 +5,5 @@
 # define chips
 
+book init remotePrepCompRuns
 book init remotePrepRuns
 book init remoteExecRuns
@@ -10,9 +11,13 @@
 
 $remote_label_iter = 0
-$remote_label_iter2 = 0
+$remote_label_warp = 0
 $remote_stage_iter = 0
-$remoteP_DB = 0
-$remoteE_DB = 0
-$remoteL_DB = 0
+
+$remoteDefine_DB = 0
+$remoteDefineWarp_DB = 0
+$remotePrepComp_DB = 0
+$remotePrep_DB = 0
+$remoteExec_DB = 0
+$remotePoll_DB = 0
 
 list STAGES
@@ -30,4 +35,10 @@
     active false
   end
+  task  remote.prepcomp.load
+    active false
+  end
+  task  remote.prepcomp.run
+    active false
+  end
   task  remote.prep.load
     active false
@@ -57,4 +68,10 @@
     active true
   end
+  task  remote.prepcomp.load
+    active true
+  end
+  task  remote.prepcomp.run
+    active true
+  end
   task  remote.prep.load
     active true
@@ -76,5 +93,4 @@
   end
 end
-
 
 task          remote.define
@@ -84,4 +100,5 @@
   periods     -timeout 30
   npending    1
+  active      true
 
   task.exec
@@ -94,4 +111,5 @@
     $remote_stage_iter ++
 
+    # loop over all stages x all labels
     if ($remote_stage_iter >= $STAGES:n) 
        set remote_stage_iter = 0
@@ -101,12 +119,13 @@
     end
 
+    # min entry limit?
     $run = remotetool -definebyquery -label $label -stage $stage -path_base neb://@HOST@.0/remote/$label -limit 500
     if ($DB:n == 0)
       option DEFAULT
     else
-      option $DB:$remoteP_DB
-      $run = $run -dbname $DB:$remoteP_DB
-      $remoteP_DB ++
-      if ($remoteP_DB >= $DB:n) set remoteP_DB = 0
+      option $DB:$remoteDefine_DB
+      $run = $run -dbname $DB:$remoteDefine_DB
+      $remoteDefine_DB ++
+      if ($remoteDefine_DB >= $DB:n) set remoteDefine_DB = 0
     end
 
@@ -137,4 +156,5 @@
   periods     -timeout 30
   npending    1
+  active      false
 
   task.exec
@@ -142,8 +162,8 @@
     stderr $LOGDIR/remote.define.chip
 
-    $label = $LABEL:$remote_label_iter2
-
-    if ($remote_label_iter >= $LABEL:n) set remote_label_iter = 0
-    echo  $remote_label_iter $label warp
+    $label = $LABEL:$remote_label_warp
+
+    if ($remote_label_warp >= $LABEL:n) set remote_label_warp = 0
+    echo $remote_label_warp $label warp
 
     $run = remotetool -definebyquery -label $label -stage warp -path_base neb://@HOST@.0/remote/$label -limit 500
@@ -151,8 +171,8 @@
       option DEFAULT
     else
-      option $DB:$remoteP_DB
-      $run = $run -dbname $DB:$remoteP_DB
-      $remoteP_DB ++
-      if ($remoteP_DB >= $DB:n) set remoteP_DB = 0
+      option $DB:$remoteDefineWarp_DB
+      $run = $run -dbname $DB:$remoteDefineWarp_DB
+      $remoteDefineWarp_DB ++
+      if ($remoteDefineWarp_DB >= $DB:n) set remoteDefineWarp_DB = 0
     end
 
@@ -161,5 +181,6 @@
     
   end
-    # success
+
+  # success
   task.exit  0
   end
@@ -174,4 +195,121 @@
   task.exit    timeout
     showcommand timeout
+  end
+end
+
+task         remote.prepcomp.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec 30
+  npending   1
+  active     true
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.prepcomp.load
+
+    $run = remotetool -listcomponent -state new
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remotePrepComp_DB
+      $run = $run -dbname $DB:$remotePrepComp_DB
+      $remotePrepComp_DB ++
+      if ($remotePrepComp_DB >= $DB:n) set remotePrepComp_DB = 0
+    end
+
+    add_poll_args run
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit  0
+    ipptool2book stdout remotePrepCompRuns -uniq -key remote_id:stage_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remotePrepCompRuns
+
+    if ($VERBOSE > 2)
+      book listbook remotePrepCompRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the prep component operations in parallel
+task           remote.prepcomp.run
+  host         anyhost
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 600
+  active       true
+  npending     10
+
+  task.exec
+    stdout $LOGDIR/remote.prepcomp.run
+    stderr $LOGDIR/remote.prepcomp.run
+
+    book npages remotePrepCompRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remotePrepCompRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remotePrepCompRuns $pageName pantaskState RUN
+    book getword remotePrepCompRuns $pageName remote_id -var REMOTE_ID
+    book getword remotePrepCompRuns $pageName stage_id  -var STAGE_ID
+    book getword remotePrepCompRuns $pageName stage     -var STAGE
+    book getword remotePrepCompRuns $pageName run_path_base -var RUN_PATH_BASE
+    book getword remotePrepCompRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s/stage_%s" $RUN_PATH_BASE $STAGE $REMOTE_ID $STAGE_ID
+
+    if ("$STAGE" == "chip")
+      $command = sc_prepare_chip.pl --camera GPC1 --chip_id $STAGE_ID --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "camera")
+      $command = sc_prepare_camera.pl --camera GPC1 --stage_id $STAGE_ID --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+      echo "skipping camera until scripts are ready"
+      break
+    end
+    if ("$STAGE" == "warp")
+      $command = sc_prepare_warp.pl --camera GPC1 --stage_id $STAGE_ID --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+      echo "skipping warp until scripts are ready"
+      break
+    end
+    if ("$STAGE" == "stack")
+      $command = sc_prepare_stack.pl --camera GPC1 --stage_id $STAGE_ID --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+      echo "skipping stack until scripts are ready"
+      break
+    end
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remotePrepCompRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remotePrepCompRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remotePrepCompRuns $options:0 pantaskState TIMEOUT
   end
 end
@@ -181,4 +319,5 @@
   periods    -poll $LOADPOLL
   periods    -exec 30
+  active     false
   npending   1
 
@@ -187,13 +326,13 @@
     stderr $LOGDIR/remote.prep.load
 
-    $run = remotetool -listrun -state new
+    $run = remotetool -listrun -state new -done-prep
 
     if ($DB:n == 0)
       option DEFAULT
     else
-      option $DB:$remoteP_DB
-      $run = $run -dbname $DB:$remoteP_DB
-      $remoteP_DB ++
-      if ($remoteP_DB >= $DB:n) set remoteP_DB = 0
+      option $DB:$remotePrep_DB
+      $run = $run -dbname $DB:$remotePrep_DB
+      $remotePrep_DB ++
+      if ($remotePrep_DB >= $DB:n) set remotePrep_DB = 0
     end
 
@@ -201,4 +340,5 @@
     command $run
   end
+
   # success
   task.exit  0
@@ -229,5 +369,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 600000
-  active       true
+  active       false
   npending     10
 
@@ -247,21 +387,10 @@
     book getword remotePrepRuns $pageName stage     -var STAGE
     book getword remotePrepRuns $pageName path_base -var PATH_BASE
-#    book getword remotePrepRuns $pageName label     -var LABEL
+#   book getword remotePrepRuns $pageName label     -var LABEL
     book getword remotePrepRuns $pageName dbname    -var DBNAME
 
     sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
 
-    if ("$STAGE" == "chip")
-      $command = sc_prepare_chip.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
-    end
-    if ("$STAGE" == "camera")
-      $command = sc_prepare_camera.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
-    end
-    if ("$STAGE" == "warp")
-      $command = sc_prepare_warp.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
-    end
-    if ("$STAGE" == "stack")
-      $command = sc_prepare_stack.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
-    end
+    $command = sc_prepare_run.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
 
     options $pageName
@@ -290,4 +419,5 @@
   periods    -poll $LOADPOLL
   periods    -exec $LOADEXEC
+  active     false
   npending   1
 
@@ -303,8 +433,8 @@
       option DEFAULT
     else
-      option $DB:$remoteE_DB
-      $run = $run -dbname $DB:$remoteE_DB
-      $remoteE_DB ++
-      if ($remoteE_DB >= $DB:n) set remoteE_DB = 0
+      option $DB:$remoteExec_DB
+      $run = $run -dbname $DB:$remoteExec_DB
+      $remoteExec_DB ++
+      if ($remoteExec_DB >= $DB:n) set remoteExec_DB = 0
     end
 
@@ -340,5 +470,5 @@
   periods      -exec 30
   periods      -timeout 6000000
-  active       true
+  active       false
   npending     3
 
@@ -391,4 +521,5 @@
   periods    -poll $LOADPOLL
   periods    -exec $LOADEXEC
+  active       false
   npending   1
 
@@ -403,8 +534,8 @@
       option DEFAULT
     else
-      option $DB:$remoteL_DB
-      $run = $run -dbname $DB:$remoteL_DB
-      $remoteL_DB ++
-      if ($remoteL_DB >= $DB:n) set remoteL_DB = 0
+      option $DB:$remotePoll_DB
+      $run = $run -dbname $DB:$remotePoll_DB
+      $remotePoll_DB ++
+      if ($remotePoll_DB >= $DB:n) set remotePoll_DB = 0
     end
 
@@ -440,5 +571,5 @@
   periods      -exec 30
   periods      -timeout 6000000
-  active       true
+  active       false
   npending     3
 
