[Swift-commit] r3675 - in SwiftApps/SwiftR: . Swift/R Swift/exec Swift/man Swift/tests

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sat Oct 9 09:27:21 CDT 2010


Author: wilde
Date: 2010-10-09 09:27:20 -0500 (Sat, 09 Oct 2010)
New Revision: 3675

Modified:
   SwiftApps/SwiftR/Swift/R/Swift.R
   SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
   SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
   SwiftApps/SwiftR/Swift/exec/rserver.swift
   SwiftApps/SwiftR/Swift/man/Swift-package.Rd
   SwiftApps/SwiftR/Swift/tests/TestSwift.R
   SwiftApps/SwiftR/TODO
Log:
Enhanced user-specified initializtion script to run in any server and whenever script is changed.

Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/R/Swift.R	2010-10-09 14:27:20 UTC (rev 3675)
@@ -83,9 +83,6 @@
   dir.create(reqdir,showWarnings=FALSE)
   cat("Swift request is in",reqdir,"\n")
 
-  cat(initialize,file=paste(reqdir,"/initialize.R",sep=""))  # FIXME: honor this on calls after the first in an R server?
-                                                             # FIXME: eliminate this oevrhead on each call to swiftapply
-
   narglists <- length(arglists) # number of arglists to process
   batch <- 1   # Next arglist batch number to fill
   arglist <- 1 # Next arglist number to insert
@@ -102,7 +99,7 @@
       arglistbatch[[i]] <- arglists[[arglist]]
       arglist <- arglist +1 
     }
-    rcall <- list(func=func,arglistbatch=arglistbatch)
+    rcall <- list(initializer=initialize,func=func,arglistbatch=arglistbatch)
     save(rcall,file=paste(reqdir,"/cbatch.",as.character(batch),".Rdata",sep=""))
     batch <- batch + 1;
   }
@@ -128,8 +125,6 @@
 
     swiftServerDir = paste(tmpdir,"/",user,"/SwiftR/swift.",swiftserver,sep="")
 
-cat(initialize,file=paste(swiftServerDir,"/initialize.R",sep="")) # FIXME
-
     requestPipeName=paste(swiftServerDir,"/requestpipe",sep="")
     resultPipeName=paste(swiftServerDir,"/resultpipe",sep="")
 
@@ -185,3 +180,416 @@
 #swiftapply: no visible binding for '<<-' assignment to 'swiftprops'
 #swiftapply: no visible binding for global variable 'swiftprops'
 #swiftapply: no visible binding for global variable 'result'
+
+
+#------------------ Tests moved here from test dir:
+
+
+initSwiftTestOptions <- function()
+{
+  options(swift.site="service")
+  options(swift.keepwork=TRUE)
+  initcmds <- "initVar1 <<- 19; initVar2 <<- sqrt(400)+3"
+  options(swift.initialize=initcmds) # Set here; used in test group 4
+}
+
+swiftTest_1.1 <- function()
+{
+
+  initSwiftTestOptions()
+
+  cat("\n*** Starting  test 1.1 ***\n\n")
+
+  sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+  data(cars)
+  data(trees)
+
+  args=list(trees,cars)
+  arglist = rep(list(args),1)
+
+  cat("Test of local do.call(sumstuff)\n")
+  localres = do.call(sumstuff,args)
+  cat("local result=\n")
+  print(localres)
+
+  cat("\nTest of swiftapply(sumstuff,arglist)\n")
+  swiftres = swiftapply(sumstuff,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 1.1 passed\n")
+  } else {
+    cat("\n==> test 1.1 FAILED !!!!!\n")
+  }
+}
+
+basicSwiftTest <- function() { swiftTest_1.1() }
+
+# .... more tests from below to move here
+
+swiftTest_4.1 <- function()
+{
+  sumivars <- function() { initVar1+initVar2 }
+
+  args=list()
+  arglist = rep(list(args),1)
+
+  localres = 42
+
+  cat("\nTest of swiftapply(sumivars,arglist)\n")
+  swiftres = swiftapply(sumivars,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 4.1 passed\n")
+  } else {
+    cat("\n==> test 4.1 FAILED !!!!!\n")
+  }
+}
+
+swiftTest_4.2 <- function()
+{
+
+  options(swift.initialize="initVar3 <<- 123; initVar4 <<- 100");
+
+  mulivars <- function() { initVar3*initVar4 }
+
+  args=list()
+  arglist = rep(list(args),1)
+
+  localres = 12300;
+
+  cat("\nTest of swiftapply(mulivars,arglist)\n")
+  swiftres = swiftapply(mulivars,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 4.2 passed\n")
+  } else {
+    cat("\n==> test 4.2 FAILED !!!!!\n")
+  }
+}
+
+runAllSwiftTests <- function()
+{
+
+### FIXME: Save prior options here: restore them when tests are done.  Recovery if interrrupted?
+
+failures=0
+
+startTime = proc.time()[["elapsed"]]
+
+cat("\n*** Starting test group 1 - functions on simple data structures ***\n\n")
+
+swiftTest_1.1()
+
+##### Test 1.2
+
+# test 10 remote calls
+
+sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+data(cars)
+data(trees)
+
+args=list(trees,cars)
+arglist <- rep(list(args),10)
+
+localres = do.call(sumstuff,args)
+
+cat("\n*** Test 1.2.1: 10 calls to substuff()\n")
+swiftres <- swiftapply(sumstuff,arglist)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !identical(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 1.2.1 passed\n")
+} else {
+  cat("\n!!!==> test 1.2.1 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+cat("\n*** Test 1.2.2: 10 calls to substuff() - callsperbatch=10\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=10)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !identical(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 1.2.2 passed\n")
+} else {
+  cat("\n!!!==> test 1.2.2 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+cat("\n*** Test 1.2.3: 10 calls to substuff() - callsperbatch=2\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=2)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !identical(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i, format( swiftres[[i]] )))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 1.2.3 passed\n")
+} else {
+  cat("\n!!!==> test 1.2.3 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+cat("\n*** Test 1.2.4: 10 calls to substuff() - callsperbatch=3\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=3)
+swiftres <- swiftapply(sumstuff,arglist)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !identical(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i, format( swiftres[[i]] )))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 1.2.4 passed\n")
+} else {
+  cat("\n!!!==> test 1.2.4 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+# swiftres = swiftapply(sumstuff,arglist,callsperbatch=2,site="pbs")
+# test variations on local vs ssh vs pbs; coasters vs non; etc.
+
+
+
+##### Test Group  2
+
+cat("\n*** Starting test group 2 - test matrix passing***\n")
+
+matfunc <- function( m1, m2 )
+{
+  (1/m1) %*% m2
+}
+
+n <- 5
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+localres = matfunc(m1,m2)
+
+cat("\n*** Test 2.1: 100 calls to matfunc(dim=5x5) - callsperbatch=9\n")
+
+args=list(m1,m2)
+arglist <- rep(list(args),100)
+
+swiftres = swiftapply(matfunc,arglist,callsperbatch=9)
+
+diffs <- 0
+#for(i in 1:length(swiftres) ) {
+for(i in c(seq(1,100,10),100)) {
+  if( !all.equal(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 2.1 passed\n")
+} else {
+  cat("\n!!!==> test 2.2 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+n <- 237
+n <- 50
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+localres = matfunc(m1,m2)
+
+cat("\n*** Test 2.2: 123 calls to matfunc(dim=bigger) - callsperbatch=7\n") # FIXME make n easy to adjust and print actual value
+
+args=list(m1,m2)
+arglist <- rep(list(args),123)
+
+swiftres = swiftapply(matfunc,arglist,callsperbatch=7)
+
+diffs <- 0
+#for(i in 1:length(swiftres) ) {
+for(i in c(seq(1,length(swiftres),10),length(swiftres))) {
+
+  if( !all.equal(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 2.2 passed\n")
+} else {
+  cat("\n!!!==> test 2.2 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+
+##### Test Group 3
+
+cat("\n*** Starting test group 3 - test list element and name passing***\n")
+
+# Test if list element names are being sent and returned correctly
+
+n <- 5
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+inlist = list()
+inlist[[1]]=123
+inlist[[2]]=456
+inlist$name1=789
+inlist$name2=987
+inlist$mat1 =  m1
+inlist[[99]] = m2
+
+listfunc <- function(ilist)
+{
+  olist = ilist
+  olist$sum = ilist[[1]] + ilist[[2]] + ilist$name1 + ilist$name2
+  olist$names = names(ilist)
+  olist$mprod = ilist$mat1 %*% ilist[[99]]
+  return(olist)
+}
+localres = listfunc(inlist)
+
+cat("\n*** Starting test 3.1 - 4 calls in one batch of 5 ***\n")
+
+args=list(inlist)
+arglist <- rep(list(args),4)
+
+swiftres = swiftapply(listfunc,arglist,callsperbatch=5)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !all.equal(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d=%s\n",i,format(swiftres[[i]])))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 3.1 passed\n")
+} else {
+  cat("\n!!!==> test 3.1 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+cat("\n*** Starting test 3.2 - 99 calls in batches of 11 ***\n")
+
+args=list(inlist)
+arglist <- rep(list(args),99)
+
+swiftres = swiftapply(listfunc,arglist,callsperbatch=11)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( !all.equal(swiftres[[i]],localres) ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 3.2 passed\n")
+} else {
+  cat("\n!!!==> test 3.2 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+##### Test Group 4 # test initializer string
+
+cat("\n*** Starting test group 4 - test remote R service initialization string ***\n")
+
+swiftTest_4.1()
+swiftTest_4.2()
+
+
+
+
+##### Test Group 5 # test error handling
+
+cat("\n*** Starting test group 5 - test remote R service error ***\n")
+
+arglist = list(list(1.0),list(2.0),list("3.0"),list(4.0),list(5.0))
+
+cat("\nTest of swiftapply(sumivars,arglist)\n")
+swiftres = swiftapply(log,arglist)
+cat("Swift result:\n")
+print(swiftres)
+
+goodres = c("numeric","numeric","try-error","numeric","numeric")
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+  if( class(swiftres[[i]]) != goodres[i] ) { 
+    diffs <- diffs + 1
+    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+  }
+}
+
+if(diffs == 0) {
+  cat("\n==> test 5.1 passed\n")
+} else {
+  cat("\n!!!==> test 5.1 failed.\n")
+  cat(sprintf(" %d result elements failed to match.\n",diffs));
+  failures=failures+1
+}
+
+endTime <- proc.time()[["elapsed"]]
+runTime <- endTime - startTime
+
+cat("\n\n ===> Total elapsed test time = ",runTime," seconds.\n\n") 
+
+} # end function runAllTests
+
+#options(swift.site="local")
+#runAllTests()
+
+testloop <- function(npass)
+{
+  for(i in 1:npass) {
+    cat("\n\n\n ***** Starting test pass ", i, " ***** \n\n\n");
+    runAllSwiftTests()
+    cat("\n\n\n ***** Completed test pass ", i, " ***** \n\n\n");
+    system("sleep 3")
+  }
+}

Modified: SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2010-10-09 14:27:20 UTC (rev 3675)
@@ -1,9 +1,10 @@
 #! /bin/bash
 
 # Arguments: inputBatchSaveFile outputBatchSaveFile
-#   bash @shellscript @initRScript @RServerScript @rcall @result stdout=@stout stderr=@sterr;
+#   bash @shellscript @RServerScript @rcall @result stdout=@stout stderr=@sterr;
 
-if [ $# != 4 ]; then
+#if [ $# != 4 ]; then
+if [ $# != 3 ]; then
   echo $0: expecting 4 arguments, got $#: $* 1>&2
   exit 1
 fi
@@ -12,10 +13,9 @@
 # tmp=/scratch/local # FIXME: allow this to change eg for sites with main tmp dir elsewhere
 tmp=${SWIFTR_TMP:-/tmp}
 
-initRScript=$1
-RServerScript=$2
-callFile=$3
-resultFile=$4
+RServerScript=$1
+callFile=$2
+resultFile=$3
 
 # Find our bin dir (to use for running utility scripts)
 
@@ -86,7 +86,7 @@
   mkfifo $SLOTDIR/toR.fifo
   mkfifo $SLOTDIR/fromR.fifo
   chmod +x $RServerScript
-  PATH=.:$PATH $RServerScript $SLOTDIR $initRScript >& $SLOTDIR/R.log &   # launch R server
+  PATH=.:$PATH $RServerScript $SLOTDIR >& $SLOTDIR/R.log &   # launch R server
   # idletimer $SLOTDIR </dev/null >/dev/null 2>&1 & # R saves pid in R.pid for idletimer to kill it
   echo "$0: INFO: Launched $RServerScript $SLOTDIR Rscript"
 else

Modified: SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh	2010-10-09 14:27:20 UTC (rev 3675)
@@ -1,17 +1,12 @@
 #! /usr/bin/env Rscript
 
-# require(OpenMx)  # FIXME: make this a variable set of statements to exec or source
-
 argv = commandArgs(TRUE)
 
 fifoDir = argv[1];  # FIXME: test for valid arguments
-initScript = argv[2];
 
 cat(Sys.getpid(),file=paste(fifoDir,"/R.pid",sep=""))
 
-source(initScript)
-cat("After sourcing initscript: ", initScript, "\n")
-ls()
+latestInitializer <- "";
 
 SwiftRFifoServer <- function( fifoBasename )
 {
@@ -53,7 +48,13 @@
 {
   load(callBatchFileName);
 
-  result=list()
+  result <- list()
+  initializer <- rcall$initializer;
+  if( initializer != latestInitializer) {
+    initialExpr <- parse(text=initializer)
+    eval(initialExpr)
+    latestInitializer <<- initializer
+  }
   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, rcall$arglistbatch[[c]] )) 

Modified: SwiftApps/SwiftR/Swift/exec/rserver.swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/rserver.swift	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/exec/rserver.swift	2010-10-09 14:27:20 UTC (rev 3675)
@@ -4,10 +4,13 @@
 # fixme: extend to enable coaster and non-coaster execution
 #        needs to select between EvalRPersistent and simple RunR
 #        enable persistent for local mode (not sure how)
+#        condense stdout/err to 1 file
+#        replace ack with ftracef to result pipe
+#        condense shellscript and rserverscript to one?
 
-app (external e, RData result, file stout, file sterr) runR (file shellscript, file initRScript, file RServerScript, RData rcall)
+app (external e, RData result, file stout, file sterr) runR (file shellscript, file RServerScript, RData rcall)
 {
-  bash @shellscript @initRScript @RServerScript @rcall @result stdout=@stout stderr=@sterr;
+  bash @shellscript @RServerScript @rcall @result stdout=@stout stderr=@sterr;
 }
 
 app ack (external e[])
@@ -29,11 +32,10 @@
   file  sterr[]   <simple_mapper; location=runDir, prefix="stderr.", suffix=".txt", padding=0>;
  
   file  runRscript <"EvalRBatchPersistent.sh">;
-  file  initScript <"initialize.R">;
   file  rsScript   <"SwiftRServer.sh">;
 
   foreach c, i in rcalls {
-    (e[i], results[i],stout[i], sterr[i]) = runR(runRscript,initScript,rsScript,c);
+    (e[i], results[i],stout[i], sterr[i]) = runR(runRscript,rsScript,c);
   }
 }
 

Modified: SwiftApps/SwiftR/Swift/man/Swift-package.Rd
===================================================================
--- SwiftApps/SwiftR/Swift/man/Swift-package.Rd	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/man/Swift-package.Rd	2010-10-09 14:27:20 UTC (rev 3675)
@@ -8,9 +8,13 @@
 R interface to Swift parallel scripting language
 }
 \description{
-Description: Routines to invoke R functions and Swift scripts on remote resources through Swift.
-R functions can be remotely executed in parallel in a manner similar to Snow using a list of argument lists.
-Eventually more general Swift functions can be embedded and invked remotely as well.
+
+Description: Routines to invoke R functions and Swift scripts on
+remote resources through Swift.  R functions can be remotely executed
+in parallel in a manner similar to Snow using a list of argument
+lists.  Eventually more general Swift functions can be embedded and
+invked remotely as well.
+
 }
 \details{
 \tabular{ll}{
@@ -18,51 +22,44 @@
 Type: \tab Package\cr
 Version: \tab 1.0\cr
 Date: \tab 2010-02-25\cr
-License: \tab Globus Toolkit Public License v3 (based on Apache License 2.0): http://www.globus.org/toolkit/legal/4.0/license-v3.html \cr
+License: \tab Globus Toolkit Public License v3 (based on Apache License 2.0):
+http://www.globus.org/toolkit/legal/4.0/license-v3.html \cr
 LazyLoad: \tab yes\cr
 }
-To use this package, create a list of argument lists, and then invoke: swiftapply(function,arglists).
 
-As a preliminary interface, you can set R options() to control Swift's operation:
+To use this package, create a list of argument lists, and then invoke:
+swiftapply(function,arglists).
 
-options(swift.callsperbatch=n) #  n = number of R calls to perform in each Swift job.
+As a preliminary interface, you can set R options() to control Swift's
+operation:
 
-options(swift.site=sitename) # sitename = "local" to run on the current host and "pbs" to submit to a local PBS cluster.
+options(swift.callsperbatch=n) # n = number of R calls to perform in
+each Swift job.
+
+options(swift.site=sitename) # sitename = "local" to run on the
+current host and "pbs" to submit to a local PBS cluster.
  
-PREREQS
+PREREQUISITES
 
 Sun Java (pref 1.6 - will it work below?)
-How to get Java if needed
 
+FIXME: How to install Java if needed
+
 R v2.11 or higher in your PATH (on client and server machines)
 
-Ability to ssh to server machines (without password: agents, master control channel, etc)
-? Needed?  Passwords or ssh key passphrases OK for some scenarios.
+Ability to ssh to server machines (without password: agents, master
+control channel, etc) (FIXME: Are these limitations necessary?)
+Passwords or ssh key passphrases OK for some scenarios.
 
 ssh from Mac
+
 ssh -A when jumping to a new host (to forward the ssh agent)
 
-or set up ssh agents manually
+(or set up ssh agents manually)
 
 (document ssh tricks here for pw-less access)
 
 
-CAVEATS
-
-# fixed: Only one Swift server running per user; can only be used by one R client workspace at a time.
-
-when fifos get hung, need to use kill or Quit to break out of R; will fix.
-
-no auto-restart yet if swift dies in server loop.
-
-only lapply is implemented (also SwiftApply) - need to see if we can cut down arg passing overhead for many of the apply() cases
-
-log records build up fast; these will be reduced as we get more confidence withthe code and shake out bugs
-
-initVar only affects first calls on a server - if you change these you need to start a new server (FIXME)!
-
-
-
 INSTALL
 
 cd ???
@@ -79,22 +76,47 @@
 
 can put local cores into an ssh pool
 
+swift $HOME/.ssh/auth-defaults file for additional shs servers
 
+access remote systems via ssh
+
+Export SWIFTR_TMP in your environment 
+
 START SERVERS
 
-# do this outside of R
+# do this outside of R - BEFORE trying to run R Swift functions
 
 SWIFT=<your package install dir>/Swift/
 $SWIFT/exec/start-swift-workers hostname
 $SWIFT/exec/start-swift-server 
 
 local and ssh servers can be started and left running, across R runs
+
 found via:
 
 HELLO WORLD TEST
 
+# Start swift local server as above
+
+require(Swift)
+basicSwiftTest()
+
 RUN FULL TEST
 
+As a regular user:
+
+require(Swift)
+fullSwiftTest()
+
+# Then
+
+n=10 # 1o times through full test loop
+
+swiftTestLoop(n)
+
+
+In source tree:
+
 source("Swift/tests/TestSwift.R")
 
   or R CMD TEST etc?
@@ -114,23 +136,70 @@
 
 OPENMX EXAMPLES
 
-DEBUGGING
+This section is specific to users of the OpenMX R package for
+structural equation modeling.
 
+DIRECTORY STRUCTURE USED FOR SWIFT RUNTIME
+
+PROCEESS STRUCTURE USE FOR SWIFT RUNTIME
+
+DEBUGGING AND TROUBLESHOOTING
+
 * manual mode
 
 * logs to look at
 
+* is my swift server responding?
+
+tail -f $TMP/
+
 * reporting bugs: what to send  (FIXME: need swiftsnapshot script)
 
-* setting Swift worker logging with $HOME/.globus/coasters/loglevel file. This file should contain a single text integer: 0=most detailed, 4=least detaild, 5=off.  This is an interim log control mechanism and may be deprecated in the future.
+* setting Swift worker logging with $HOME/.globus/coasters/loglevel
+file. This file should contain a single text integer: 0=most detailed,
+4=least detaild, 5=off.  This is an interim log control mechanism and
+may be deprecated in the future.
 
+CAVEATS
+
+You MUST start the Swift server before running a swiftapply() call
+from R. Otherwise R hangs and must be killed and restarted.
+
+When Swift fifos (named pipes) get hung, you need to use kill or Quit
+to break out of R. FIXME
+
+There is no automatic restart yet if swift dies in its server
+loop. FIXME
+
+Variables set in the initialze script must typically be set in global
+environment ( var <<- value);
+
+Only lapply is implemented (also SwiftApply) - need to see if we can
+cut down arg passing overhead for many of the apply() cases
+
+Log records build up fast; these will be reduced as we get more
+confidence with the code and shake out bugs
+
+There is no easy way yet to alter Swift configuration file variables
+such as number of cores to use, etc. Do this for now by editing an
+existing configuration under Swift/exec/conigure-swift-NNN where NNN
+is the Swift server name.
+
+Each swiftapply() is pretty noisy - it echos its options etc. This
+will quiet down.
+
+
+
 }
 
 \author{
 
 Swift R package developed by Michael Wilde
 
-Swift was developed by: Mihael Hategan, Ben Clifford, Justin Wozniak, Yong Zhao, Ian Foster, and Michael Wilde with contributions from Sarah Kenny, Ioan Raicu, Luiz Gadelha, Allan Espinosa, Zhao Zhang, David Kelly, Jon Monette, Glen Hocky, Tom Uram, Wenjun Wu, and other users.
+Swift was developed by: Mihael Hategan, Ben Clifford, Justin Wozniak,
+Yong Zhao, Ian Foster, and Michael Wilde with contributions from Sarah
+Kenny, Ioan Raicu, Luiz Gadelha, Allan Espinosa, Zhao Zhang, David
+Kelly, Jon Monette, Glen Hocky, Tom Uram, Wenjun Wu, and other users.
 
 Maintainer: Michael Wilde <wilde at mcs.anl.gov>
 

Modified: SwiftApps/SwiftR/Swift/tests/TestSwift.R
===================================================================
--- SwiftApps/SwiftR/Swift/tests/TestSwift.R	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/Swift/tests/TestSwift.R	2010-10-09 14:27:20 UTC (rev 3675)
@@ -1,17 +1,6 @@
 
 ##### Setup
 
-require(Swift)
-
-initcmds <- "
-initVar1 <- 19
-initVar2 <- sqrt(400)+3
-"
-
-failures=0
-
-options(swift.initialize=initcmds) # Set here; used in test group 4
-
 # To paste for quick testing: ###########
 
 if (FALSE) {
@@ -39,366 +28,12 @@
 
 } ####################################
 
-# NOTE: swift.initialize statements must be set before any swiftapply() calls when running in "service" mode.
+require(Swift)
 
-runAllTests <- function()
-{
+runAllSwiftTests()
 
-startTime = proc.time()[["elapsed"]]
 
-cat("\n*** Starting test group 1 - functions on simple data structures ***\n\n")
 
-##### Test 1.1
-
-cat("\n*** Starting  test 1.1 ***\n\n")
-
-sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
-data(cars)
-data(trees)
-
-args=list(trees,cars)
-arglist = rep(list(args),1)
-
-cat("Test of local do.call(sumstuff)\n")
-localres = do.call(sumstuff,args)
-cat("local result=\n")
-print(localres)
-
-cat("\nTest of swiftapply(sumstuff,arglist)\n")
-swiftres = swiftapply(sumstuff,arglist)
-cat("Swift result:\n")
-print(swiftres)
-
-if(identical(localres,swiftres[[1]])) {
-  cat("\n==> test 1.1 passed\n")
-} else {
-  cat("\n==> test 1.1 FAILED !!!!!\n")
-}
-
-
-##### Test 1.2
-
-# test 10 remote calls
-
-sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
-data(cars)
-data(trees)
-
-args=list(trees,cars)
-arglist <- rep(list(args),10)
-
-cat("\n*** Test 1.2.1: 10 calls to substuff()\n")
-swiftres <- swiftapply(sumstuff,arglist)
-cat("Swift result:\n")
-format(swiftres)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !identical(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 1.2.1 passed\n")
-} else {
-  cat("\n!!!==> test 1.2.1 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-cat("\n*** Test 1.2.2: 10 calls to substuff() - callsperbatch=10\n")
-swiftres = swiftapply(sumstuff,arglist,callsperbatch=10)
-cat("Swift result:\n")
-format(swiftres)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !identical(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 1.2.2 passed\n")
-} else {
-  cat("\n!!!==> test 1.2.2 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-cat("\n*** Test 1.2.3: 10 calls to substuff() - callsperbatch=2\n")
-swiftres = swiftapply(sumstuff,arglist,callsperbatch=2)
-cat("Swift result:\n")
-format(swiftres)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !identical(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i, format( swiftres[[i]] )))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 1.2.3 passed\n")
-} else {
-  cat("\n!!!==> test 1.2.3 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-cat("\n*** Test 1.2.4: 10 calls to substuff() - callsperbatch=3\n")
-swiftres = swiftapply(sumstuff,arglist,callsperbatch=3)
-swiftres <- swiftapply(sumstuff,arglist)
-cat("Swift result:\n")
-format(swiftres)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !identical(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i, format( swiftres[[i]] )))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 1.2.4 passed\n")
-} else {
-  cat("\n!!!==> test 1.2.4 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-# swiftres = swiftapply(sumstuff,arglist,callsperbatch=2,site="pbs")
-# test variations on local vs ssh vs pbs; coasters vs non; etc.
-
-
-
-##### Test Group  2
-
-cat("\n*** Starting test group 2 - test matrix passing***\n")
-
-matfunc <- function( m1, m2 )
-{
-  (1/m1) %*% m2
-}
-
-n <- 5
-m1 <- array(sin(1:n**2), dim=c(n,n))
-m2 <- t(m1)
-
-localres = matfunc(m1,m2)
-
-cat("\n*** Test 2.1: 100 calls to matfunc(dim=5x5) - callsperbatch=9\n")
-
-args=list(m1,m2)
-arglist <- rep(list(args),100)
-
-swiftres = swiftapply(matfunc,arglist,callsperbatch=9)
-
-diffs <- 0
-#for(i in 1:length(swiftres) ) {
-for(i in c(seq(1,100,10),100)) {
-  if( !all.equal(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 2.1 passed\n")
-} else {
-  cat("\n!!!==> test 2.2 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-n <- 237
-n <- 50
-m1 <- array(sin(1:n**2), dim=c(n,n))
-m2 <- t(m1)
-
-localres = matfunc(m1,m2)
-
-cat("\n*** Test 2.2: 123 calls to matfunc(dim=bigger) - callsperbatch=7\n") # FIXME make n easy to adjust and print actual value
-
-args=list(m1,m2)
-arglist <- rep(list(args),123)
-
-swiftres = swiftapply(matfunc,arglist,callsperbatch=7)
-
-diffs <- 0
-#for(i in 1:length(swiftres) ) {
-for(i in c(seq(1,length(swiftres),10),length(swiftres))) {
-
-  if( !all.equal(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 2.2 passed\n")
-} else {
-  cat("\n!!!==> test 2.2 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-
-##### Test Group 3
-
-cat("\n*** Starting test group 3 - test list element and name passing***\n")
-
-# Test if list element names are being sent and returned correctly
-
-n <- 5
-m1 <- array(sin(1:n**2), dim=c(n,n))
-m2 <- t(m1)
-
-inlist = list()
-inlist[[1]]=123
-inlist[[2]]=456
-inlist$name1=789
-inlist$name2=987
-inlist$mat1 =  m1
-inlist[[99]] = m2
-
-listfunc <- function(ilist)
-{
-  olist = ilist
-  olist$sum = ilist[[1]] + ilist[[2]] + ilist$name1 + ilist$name2
-  olist$names = names(ilist)
-  olist$mprod = ilist$mat1 %*% ilist[[99]]
-  return(olist)
-}
-localres = listfunc(inlist)
-
-cat("\n*** Starting test 3.1 - 4 calls in one batch of 5 ***\n")
-
-args=list(inlist)
-arglist <- rep(list(args),4)
-
-swiftres = swiftapply(listfunc,arglist,callsperbatch=5)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !all.equal(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d=%s\n",i,format(swiftres[[i]])))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 3.1 passed\n")
-} else {
-  cat("\n!!!==> test 3.1 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-cat("\n*** Starting test 3.2 - 99 calls in batches of 11 ***\n")
-
-args=list(inlist)
-arglist <- rep(list(args),99)
-
-swiftres = swiftapply(listfunc,arglist,callsperbatch=11)
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( !all.equal(swiftres[[i]],localres) ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 3.2 passed\n")
-} else {
-  cat("\n!!!==> test 3.2 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-##### Test Group 4 # test initializer string
-
-cat("\n*** Starting test group 4 - test remote R service initialization string ***\n")
-
-sumivars <- function() { initVar1+initVar2 }
-
-args=list()
-arglist = rep(list(args),1)
-
-localres = 42
-
-cat("\nTest of swiftapply(sumivars,arglist)\n")
-swiftres = swiftapply(sumivars,arglist)
-cat("Swift result:\n")
-print(swiftres)
-
-if(identical(localres,swiftres[[1]])) {
-  cat("\n==> test 4.1 passed\n")
-} else {
-  cat("\n==> test 4.1 FAILED !!!!!\n")
-}
-
-##### Test Group 5 # test error handling
-
-cat("\n*** Starting test group 5 - test remote R service error ***\n")
-
-arglist = list(list(1.0),list(2.0),list("3.0"),list(4.0),list(5.0))
-
-cat("\nTest of swiftapply(sumivars,arglist)\n")
-swiftres = swiftapply(log,arglist)
-cat("Swift result:\n")
-print(swiftres)
-
-goodres = c("numeric","numeric","try-error","numeric","numeric")
-
-diffs <- 0
-for(i in 1:length(swiftres) ) {
-  if( class(swiftres[[i]]) != goodres[i] ) { 
-    diffs <- diffs + 1
-    if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
-  }
-}
-
-if(diffs == 0) {
-  cat("\n==> test 5.1 passed\n")
-} else {
-  cat("\n!!!==> test 5.1 failed.\n")
-  cat(sprintf(" %d result elements failed to match.\n",diffs));
-  failures=failures+1
-}
-
-endTime <- proc.time()[["elapsed"]]
-runTime <- endTime - startTime
-
-cat("\n\n ===> Total elapsed test time = ",runTime," seconds.\n\n") 
-
-} # end function runAllTests
-
-#options(swift.site="local")
-#runAllTests()
-
-testloop <- function(npass)
-{
-  for(i in 1:npass) {
-    cat("\n\n\n ***** Starting test pass ", i, " ***** \n\n\n");
-    runAllTests()
-    cat("\n\n\n ***** Completed test pass ", i, " ***** \n\n\n");
-    system("sleep 3")
-  }
-}
-
-options(swift.site="service")
-options(swift.keepwork=TRUE)
-runAllTests()
-
-
 if(FALSE) { # Test various batch sizes
 
     cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")

Modified: SwiftApps/SwiftR/TODO
===================================================================
--- SwiftApps/SwiftR/TODO	2010-10-08 19:35:09 UTC (rev 3674)
+++ SwiftApps/SwiftR/TODO	2010-10-09 14:27:20 UTC (rev 3675)
@@ -36,14 +36,27 @@
 - make tmpdir a param; for start-nnn scripts use SWIFTR_TMP, ~/.SwiftR
 - make ports flexible and non-conflicting
 
-- initVar only affects first calls on a server - if you change these you need to start a new server (FIXME)!
-- better handlig of initvars: detet if it changes; work corrcetly if its empty or missing.
+X initVar only affects first calls on a server - if you change these you need to start a new server (FIXME)!
+X better handlig of initvars: detet if it changes; work corrcetly if its empty or missing.
 
 See if we can get Swift to just shut down the channel and start it again?
 - no extended idle timer
 - start new swift worker
 - kill old R workers?
 
+- replace all cat() calls with printf()
+
+- implement swiftping(serverName): access fifo non-blocking and poll for results with 1-sec sleeps.  Try N times, echoing response or lack of.  options: rualive, do-simple-R-eval.
+
+- implement swiftserver(configName, hosts=c("h1",...,"hN"), cpus=N, ... )
+
+  swiftserver(start,stop,ping,status)
+
+
+- dont put full Swift release in package; download automatically at install time, and build from source. This is needed to make SwiftR CRAN-eligible.
+
+- streamline RPC calling path by minimizing file creation and any other costly operations.
+
 test logic for creating trundir in start-swift-Rserver
 
 test for suitable java in start-swift command.
@@ -233,7 +246,7 @@
   specify swift scripts
   specify data files to be passed to remote side
   setup the R envs (???)
-  specify initial R code to run on remote side: (if !initialized_swift) { initialRCodeHere }
+X specify initial R code to run on remote side: (if !initialized_swift) { initialRCodeHere }
   run async and grab status (track 'runs' in R)
   increm result collect
   specifiy unique swift scritps ala Dirk's tools




More information about the Swift-commit mailing list