[Swift-commit] r4052 - in SwiftApps/SwiftR: Swift/R mxtests/swift

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Feb 2 18:16:51 CST 2011


Author: tga
Date: 2011-02-02 18:16:51 -0600 (Wed, 02 Feb 2011)
New Revision: 4052

Modified:
   SwiftApps/SwiftR/Swift/R/Swift.R
   SwiftApps/SwiftR/mxtests/swift/BootstrapParallelBigger.R
Log:
Initial work and notes on new swift functions to match snowfall functions:
    * swiftLibrary
    * swiftExportAll


Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R	2011-02-02 17:36:20 UTC (rev 4051)
+++ SwiftApps/SwiftR/Swift/R/Swift.R	2011-02-03 00:16:51 UTC (rev 4052)
@@ -58,11 +58,27 @@
     # service: send requests to Swift service loop via fifo
     # script:  run swift for each request, via RunSwiftScript.sh (currently broken)
     # manual:  for testing, let user run remote R server manually
+    
+  # Build a list of "Library" statements for all of the libraries
+  # already specified through swiftLibrary commands.
+  lib <- getOption("swift.libraries")
+  if (!is.null(lib)) {
+    # library statements
+    stmts <- lapply(lib, 
+                function (l) { 
+                    return (sprintf("library(%s);", l));
+                })
+    libstr = paste(stmts, collapse=" ")
+  }
+  else {
+    libstr = ""
+  }
+    
 
   if(is.null(initialexpr))
     initialexpr <- getOption("swift.initialexpr")
-  if(is.null(initialexpr))
-    initialexpr <- "";
+  # Have library imports before other expressions
+  initialexpr <- paste(libstr, initialexpr, collapse=" ");
 
   if(is.null(workerhosts))
     workerhosts <- getOption("swift.workerhosts")
@@ -253,3 +269,67 @@
   names(arglists) = names(tlist)
   swiftapply(func, arglists)
 }
+
+swiftLibrary <- function (newlib, reset=FALSE)
+{
+    # Add a library to be included on all workers
+    # The package can be provided directly or alternatively
+    # the package name can be provided.
+    if (reset) {
+        libs = list()
+    }
+    else {
+        libs <- getOption("swift.libraries")
+        if (is.null(libs))
+            libs <- list()
+    }
+    for (l in newlib) {
+        if (!is.character(l)) {
+            # Maybe library was provided unquoted
+            #FIXME: doesn't work because l is evaluated above
+            l <- deparse(substitute(l))
+        }
+        libs[[length(libs) + 1]] <- l
+    }
+    options(swift.libraries=libs)
+}
+#TODO: not implemented
+.swiftExport <- function (...) {
+    # List of object names (as R symbols or as strings)
+    # These will be passed directly to save() to be serialized
+    
+    #TODO:
+    # We want the protocol to support workers coming and going from the 
+    #  cluster.  We want to rely on less implicit state.  Ie. if we run
+    # swiftExport, then a worker is added to cluster, then an apply call
+    # is run, we want the worker to include the exported objects.
+    # One approach to doing this is to enforce the export at apply
+    # time.
+    #
+    #
+    # When swiftExport() is called:
+    # * Save all of the objects to a file 
+    #    - Q:Can we assume its on a shared filesystem?
+    # * MAYBE: put the file somewhere accessible by all workers
+    # * append the file's path to a stored list of files
+    # * MAYBE LATER: asynchronously start swift tasks to distribute
+    #   the data, to get a headstart on the work
+    # When swiftApply() is called:
+    #   - Inform all worker R processes through some mechanism (TBD)
+    #       of the list of all exported data files. (extra file?)
+    #   - The worker goes through the list in order to ensure that name 
+    #       conflicts are resolved in the way you would expect.  
+    #       If it has loaded a file previously, it does nothing.
+    #       If it hasn't loaded the file, it accesses the file (mechanism TBD)
+    #       and loads it into the global namespace.
+    #       data 
+    # 
+    # swiftRemoveAll():
+    #   delete the list of exported files from above and have a single
+    #   entry which instructs workers to delete all their data.  This is
+    #   mainly important because it eliminates possibility of using huge
+    #   amounts of memory.
+    #  swiftRemove()
+    #   Implementation of this function is somewhat problematic, as it only
+    #   partially undoes previous work
+}

Modified: SwiftApps/SwiftR/mxtests/swift/BootstrapParallelBigger.R
===================================================================
--- SwiftApps/SwiftR/mxtests/swift/BootstrapParallelBigger.R	2011-02-02 17:36:20 UTC (rev 4051)
+++ SwiftApps/SwiftR/mxtests/swift/BootstrapParallelBigger.R	2011-02-03 00:16:51 UTC (rev 4052)
@@ -16,13 +16,13 @@
 require(OpenMx)
 require(Swift)
 
-#hostfile <- Sys.getenv(c("PBS_NODEFILE"))
+hostfile <- Sys.getenv(c("PBS_NODEFILE"))
 
-#hostnames <- read.table(hostfile, stringsAsFactors=FALSE)[[1]]
-#ncpus <- length(hostnames)
+hostnames <- read.table(hostfile, stringsAsFactors=FALSE)[[1]]
 
-options(swift.initialexpr="library(OpenMx)")
 
+swiftSess <- swiftInit(server="ssh", cores=8, hosts=hostnames)
+swiftLibrary("OpenMx")
 
 set.seed(10)
 
@@ -101,11 +101,11 @@
 
 topModel <- mxModel(name = 'container')
 
-sfExportAll()
+#sfExportAll()
 
-submodels <- lapply(1:nReps, createNewModel, 'stErrSim', template)
+submodels <- swiftLapply(1:nReps, createNewModel, 'stErrSim', template)
 
-names(submodels) <- omxExtractNames(submodels)
+names(submodels) <- imxExtractNames(submodels)
 topModel at submodels <- submodels
 
 modelResults <- mxRun(topModel, silent=TRUE, suppressWarnings=TRUE)
@@ -113,5 +113,4 @@
 print(ncpus)
 print(modelResults at output$wallTime)
 
-sfStop()
-
+swiftShutdown(swiftSess)




More information about the Swift-commit mailing list