[Swift-commit] r4053 - SwiftApps/SwiftR/Swift/exec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Feb 3 11:56:20 CST 2011


Author: tga
Date: 2011-02-03 11:56:19 -0600 (Thu, 03 Feb 2011)
New Revision: 4053

Added:
   SwiftApps/SwiftR/Swift/exec/SwiftRServer.R
Removed:
   SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
Modified:
   SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh
   SwiftApps/SwiftR/Swift/exec/rserver.swift
   SwiftApps/SwiftR/Swift/exec/start-merlot
   SwiftApps/SwiftR/Swift/exec/start-swift
   SwiftApps/SwiftR/Swift/exec/start-swift-Rserver
   SwiftApps/SwiftR/Swift/exec/swiftapply.swift
Log:
* Fixed extension of SwiftRServer.sh to .R to reflect the fact it is an R script
* added in error handling for invalid initialExpr values: previously the R workers would fail silently without reporting the problem back.


Modified: SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/RunSwiftScript.sh	2011-02-03 17:56:19 UTC (rev 4053)
@@ -73,7 +73,7 @@
 
 # FIXME: fossil: was here: cat >RunR.sh <<ENDX  # Note: \$ escapes and nested "<<" in "here document" below 
 
-cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.sh} .
+cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.R} .
 
 script=$(basename $script)
 if [ _$site = _passive ]; then

Copied: SwiftApps/SwiftR/Swift/exec/SwiftRServer.R (from rev 4052, SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh)
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	                        (rev 0)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	2011-02-03 17:56:19 UTC (rev 4053)
@@ -0,0 +1,86 @@
+#! /usr/bin/env Rscript
+
+require(methods)
+argv = commandArgs(TRUE)
+
+fifoDir = argv[1];  # FIXME: test for valid arguments
+
+cat(Sys.getpid(),file=paste(fifoDir,"/R.pid",sep=""))
+
+latestInitializer <- "";
+
+SwiftRFifoServer <- function( fifoBasename )
+{
+  inFifoName = paste(fifoDir,"/toR.fifo",sep="")
+  outFifoName = paste(fifoDir,"/fromR.fifo",sep="")
+  dir = getwd()
+  cat("SwiftRServer starting in dir:",dir,"\n");
+  repeat {
+    cat("SwiftRServer at top of loop is in dir:",getwd(),"\n");
+    setwd(dir) # FIXME: not yet sure what is changing the CWD
+    infifo <- fifo(inFifoName,open="rb",blocking=TRUE)
+    outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
+    cmd <- scan(infifo,what=list("","",""),nlines=1,flush=FALSE,quiet=FALSE,fill=TRUE)
+    op = cmd[[1]]
+    callBatchFileName = cmd[[2]]
+    resultBatchFileName = cmd[[3]]
+    cat("cmd: op=",op," call batch=",callBatchFileName," result batch=",resultBatchFileName,"\n");
+    cat(file=outfifo, "Read from sock: cmd=",cmd[[1]], cmd[[2]],"\n");
+    if(is.null(op)) {
+      cat("op is NULL\n")
+    }
+    else {
+      if( identical(op,"quit")) {
+        cat(file=outfifo,"Server closing down.\n")
+        break
+      }
+      if( identical(op,"run")) {
+        cat(file=outfifo, "About to run batch file: ", callBatchFileName,"\n");
+        runBatch(callBatchFileName,resultBatchFileName)
+        cat(file=outfifo, "Batch completed: result batch file: ", resultBatchFileName,"\n");
+      }
+    }
+    close(infifo)
+    close(outfifo)
+  }
+}
+
+doInit <- function(initializer) {
+  if( initializer != latestInitializer) {
+    initialExpr <- parse(text=initializer)
+    eval(initialExpr)
+    latestInitializer <<- initializer
+    # print(sprintf("after eval: latestInitializer=%s\n", latestInitializer));
+  }
+}
+
+runBatch <- function( callBatchFileName, resultBatchFileName )
+{
+  result <- list()
+  success <- try(load(callBatchFileName));
+  if (!inherits(success, "try-error")) {
+      success <- try(doInit(rcall$initializer))
+  }
+  if (inherits(success, "try-error")) {
+    # Load or initialiser failed, return an error for all elements
+    for (c in 1:length(rcall$arglistbatch)) {
+        result[[c]] <- success
+    }
+    save(result,file=resultBatchFileName)
+  }
+  else {
+    # print(sprintf("received initializer=%s latestInitializer=%s\n",initializer, latestInitializer));
+
+    for(c in 1:length(rcall$arglistbatch)) {
+     # FIXME: run this under try/catch and save error status in results object (need to make it a list: rval + error status)
+        result[[c]] = try(do.call( rcall$func, 
+            as.list(rcall$arglistbatch[[c]] ))) 
+    }
+    save(result,file=resultBatchFileName)
+  }
+}
+
+cat("calling server: dir=",fifoDir,"\n")
+setwd(fifoDir)
+SwiftRFifoServer(fifoDir)
+cat("returned from server: dir=",fifoDir,"\n")

Deleted: SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh	2011-02-03 17:56:19 UTC (rev 4053)
@@ -1,72 +0,0 @@
-#! /usr/bin/env Rscript
-
-require(methods)
-argv = commandArgs(TRUE)
-
-fifoDir = argv[1];  # FIXME: test for valid arguments
-
-cat(Sys.getpid(),file=paste(fifoDir,"/R.pid",sep=""))
-
-latestInitializer <- "";
-
-SwiftRFifoServer <- function( fifoBasename )
-{
-  inFifoName = paste(fifoDir,"/toR.fifo",sep="")
-  outFifoName = paste(fifoDir,"/fromR.fifo",sep="")
-  dir = getwd()
-  cat("SwiftRServer starting in dir:",dir,"\n");
-  repeat {
-    cat("SwiftRServer at top of loop is in dir:",getwd(),"\n");
-    setwd(dir) # FIXME: not yet sure what is changing the CWD
-    infifo <- fifo(inFifoName,open="rb",blocking=TRUE)
-    outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
-    cmd <- scan(infifo,what=list("","",""),nlines=1,flush=FALSE,quiet=FALSE,fill=TRUE)
-    op = cmd[[1]]
-    callBatchFileName = cmd[[2]]
-    resultBatchFileName = cmd[[3]]
-    cat("cmd: op=",op," call batch=",callBatchFileName," result batch=",resultBatchFileName,"\n");
-    cat(file=outfifo, "Read from sock: cmd=",cmd[[1]], cmd[[2]],"\n");
-    if(is.null(op)) {
-      cat("op is NULL\n")
-    }
-    else {
-      if( identical(op,"quit")) {
-        cat(file=outfifo,"Server closing down.\n")
-        break
-      }
-      if( identical(op,"run")) {
-        cat(file=outfifo, "About to run batch file: ", callBatchFileName,"\n");
-        runBatch(callBatchFileName,resultBatchFileName)
-        cat(file=outfifo, "Batch completed: result batch file: ", resultBatchFileName,"\n");
-      }
-    }
-    close(infifo)
-    close(outfifo)
-  }
-}
-
-runBatch <- function( callBatchFileName, resultBatchFileName )
-{
-  load(callBatchFileName);
-
-  result <- list()
-  initializer <- rcall$initializer;
-  # print(sprintf("received initializer=%s latestInitializer=%s\n",initializer, latestInitializer));
-  if( initializer != latestInitializer) {
-    initialExpr <- parse(text=initializer)
-    eval(initialExpr)
-    latestInitializer <<- initializer
-    # print(sprintf("after eval: latestInitializer=%s\n", latestInitializer));
-  }
-  for(c in 1:length(rcall$arglistbatch)) {
-     # FIXME: run this under try/catch and save error status in results object (need to make it a list: rval + error status)
-     result[[c]] = try(do.call( rcall$func, 
-        as.list(rcall$arglistbatch[[c]] ))) 
-  }
-  save(result,file=resultBatchFileName)
-}
-
-cat("calling server: dir=",fifoDir,"\n")
-setwd(fifoDir)
-SwiftRFifoServer(fifoDir)
-cat("returned from server: dir=",fifoDir,"\n")

Modified: SwiftApps/SwiftR/Swift/exec/rserver.swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/rserver.swift	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/rserver.swift	2011-02-03 17:56:19 UTC (rev 4053)
@@ -32,7 +32,7 @@
   file  sterr[]   <simple_mapper; location=runDir, prefix="stderr.", suffix=".txt", padding=0>;
  
   file  runRscript <"EvalRBatchPersistent.sh">;
-  file  rsScript   <"SwiftRServer.sh">;
+  file  rsScript   <"SwiftRServer.R">;
 
   foreach c, i in rcalls {
     (e[i], results[i],stout[i], sterr[i]) = runR(runRscript,rsScript,c);

Modified: SwiftApps/SwiftR/Swift/exec/start-merlot
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-merlot	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/start-merlot	2011-02-03 17:56:19 UTC (rev 4053)
@@ -215,7 +215,7 @@
 #cp $script $SWIFTRBIN/passive-coaster-swift $SWIFTRBIN/swift.properties $rundir
 cp $script .
 script=$(basename $script)
-cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.sh} .
+cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.R} .
 
 # DONE: FIXME: rework this script to transfer all shells and rscripts
 # needed, and to copy in the R prelude for the R server processes (to

Modified: SwiftApps/SwiftR/Swift/exec/start-swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-swift	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/start-swift	2011-02-03 17:56:19 UTC (rev 4053)
@@ -439,7 +439,7 @@
 #cp $script $SWIFTRBIN/passive-coaster-swift $SWIFTRBIN/swift.properties $rundir
 cp $script .
 script=$(basename $script)
-cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.sh} .
+cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.R} .
 
 # DONE: FIXME: rework this script to transfer all shells and rscripts
 # needed, and to copy in the R prelude for the R server processes (to

Modified: SwiftApps/SwiftR/Swift/exec/start-swift-Rserver
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-swift-Rserver	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/start-swift-Rserver	2011-02-03 17:56:19 UTC (rev 4053)
@@ -218,7 +218,7 @@
 
 fi
 
-cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.sh} .
+cp $SWIFTRBIN/{EvalRBatchPersistent.sh,SwiftRServer.R} .
 
 script=$(basename $script)
 
@@ -259,4 +259,4 @@
 
 exit 
 
-## swift -tc.file tc -sites.file sites.xml rserver.swift
\ No newline at end of file
+## swift -tc.file tc -sites.file sites.xml rserver.swift

Modified: SwiftApps/SwiftR/Swift/exec/swiftapply.swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/swiftapply.swift	2011-02-03 00:16:51 UTC (rev 4052)
+++ SwiftApps/SwiftR/Swift/exec/swiftapply.swift	2011-02-03 17:56:19 UTC (rev 4053)
@@ -20,7 +20,7 @@
 #file  runRscript <"RunR.sh">;
 file  runRscript <"EvalRBatchPersistent.sh">;
 file  initScript <"initialize.R">;
-file  rsScript <"SwiftRServer.sh">;
+file  rsScript <"SwiftRServer.R">;
 
 foreach c, i in rcalls {
   (results[i],stout[i], sterr[i]) = runR(runRscript,initScript,rsScript,c);




More information about the Swift-commit mailing list