[Swift-commit] r4058 - SwiftApps/SwiftR/Swift/R

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Feb 3 16:22:37 CST 2011


Author: tga
Date: 2011-02-03 16:22:36 -0600 (Thu, 03 Feb 2011)
New Revision: 4058

Modified:
   SwiftApps/SwiftR/Swift/R/Apply.R
   SwiftApps/SwiftR/Swift/R/Export.R
   SwiftApps/SwiftR/Swift/R/Workers.R
Log:
Added auto-detection of local cpus.


Modified: SwiftApps/SwiftR/Swift/R/Apply.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Apply.R	2011-02-03 21:40:12 UTC (rev 4057)
+++ SwiftApps/SwiftR/Swift/R/Apply.R	2011-02-03 22:22:36 UTC (rev 4058)
@@ -117,7 +117,7 @@
     arglists[[i]] <- list(tlist[[i]], ...);
   }
   names(arglists) = names(tlist)
-  swiftapply(func, arglists)
+  swiftapply(func, arglists, ...)
 }
 
 

Modified: SwiftApps/SwiftR/Swift/R/Export.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Export.R	2011-02-03 21:40:12 UTC (rev 4057)
+++ SwiftApps/SwiftR/Swift/R/Export.R	2011-02-03 22:22:36 UTC (rev 4058)
@@ -39,23 +39,20 @@
 #  swiftRemove()
 #   Implementation of this function is somewhat problematic, as it only
 #   partially undoes previous work
-swiftRemoveAll <- function () {
-    # Cleans up all data in global namespace on workers
-    options(.swift.exports=list(c("removeAll")))
-}
 
 
-
 swiftExportAll <- function () {
     # Exports all functions and data in global environment
     return (swiftExport(list=ls(globalenv())))
 }
 
 #TODO: not implemented
-.swiftExport <- function (..., list=NULL) {
+swiftExport <- function (..., list=NULL) {
     # List of object names (as R symbols or as strings)
     # These will be passed directly to save() to be serialized
     
+        cat("Got here")
+            cat("Got here")
 
 
     #Pseudocode:
@@ -69,3 +66,8 @@
     options(.swift.exports=exportList)
 
 }
+
+swiftRemoveAll <- function () {
+    # Cleans up all data in global namespace on workers
+    options(.swift.exports=list(c("removeAll")))
+}

Modified: SwiftApps/SwiftR/Swift/R/Workers.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Workers.R	2011-02-03 21:40:12 UTC (rev 4057)
+++ SwiftApps/SwiftR/Swift/R/Workers.R	2011-02-03 22:22:36 UTC (rev 4058)
@@ -1,6 +1,5 @@
 
 
-
 swiftInit <- function( cores=NULL, server=NULL, 
                     hosts=NULL, nodes=NULL, project=NULL, 
                     parEnv=NULL, workmode=NULL,
@@ -49,12 +48,17 @@
     if(is.null(cores))
         cores <- getOption("swift.cores")
         if (is.null(cores)) {
-            if (server == "local")
-                cores <- 2
-            else if (server == "ssh")
+            if (server == "local") {
+                cores <- getOption("swift.system.cores")
+                if (is.null(cores)) 
+                    cores <- 2
+            }
+            else if (server == "ssh") {
                 cores <- 4
-            else 
+            }
+            else {
                 cores <- 8
+            }
         }
     if(! is.null(cores) )  {
         cmdString <- paste(cmdString, "-c", shQuote(cores))
@@ -213,6 +217,10 @@
         return (worker$cores * worker$nodes)
 }
 
+.onLoad <- function (libname, packagename) {
+    detectSystemInfo()
+}
+
 .First.lib <- function(libname, packagename) {
     # When the library is loaded, set up the
     # list of workers
@@ -257,3 +265,24 @@
     }
 }
 
+detectSystemInfo <- function () {
+    # Do initial detection and setting of options to
+    # reflect system info.  DOesn't guarantee options will be set
+    os <- tolower(R.version$os)
+    corecount <- 0
+    if (substr(os, 1, 5) == "linux") {
+        corecount <- try(as.numeric(system(
+                    "grep -c '^processor' /proc/cpuinfo", intern=T)))
+    }
+    #if (substr(os, 1, 5) == "darwin") {
+    #}
+    #TODO: detect cores on other systems:
+    #   * MAC OS X
+    #   * BSD?
+    #    
+
+    if (!inherits(corecount, "try-error") && corecount >= 1){
+        options(swift.system.cores=corecount)
+    }
+}
+




More information about the Swift-commit mailing list