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

tga at ci.uchicago.edu tga at ci.uchicago.edu
Fri Apr 8 16:00:25 CDT 2011


Author: tga
Date: 2011-04-08 16:00:23 -0500 (Fri, 08 Apr 2011)
New Revision: 4328

Modified:
   SwiftApps/SwiftR/Swift/R/Init.R
Log:
iAdded core count detection for mac OS X


Modified: SwiftApps/SwiftR/Swift/R/Init.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Init.R	2011-04-08 20:59:21 UTC (rev 4327)
+++ SwiftApps/SwiftR/Swift/R/Init.R	2011-04-08 21:00:23 UTC (rev 4328)
@@ -64,14 +64,18 @@
     corecount <- 0
     if (substr(os, 1, 5) == "linux") {
         corecount <- try(as.numeric(system(
-                    "grep -c '^processor' /proc/cpuinfo", intern=T)))
+            "grep -c '^processor' /proc/cpuinfo 2> /dev/null", intern=T)))
     }
-    #if (substr(os, 1, 5) == "darwin") {
-    #}
+    if (substr(os, 1, 5) == "darwin") {
+        #Mac OS X / Darwin
+        corecount <- try(as.numeric(unlist(
+            system(paste("/usr/sbin/sysctl hw.ncpu 2> /dev/null | ",
+                    "awk '{ print $NF }' 2> /dev/null"), intern=T), 
+                    )))
+    }
     #TODO: detect cores on other systems:
-    #   * MAC OS X
     #   * BSD?
-    #    
+    #   * windows? 
 
     if (!inherits(corecount, "try-error") && corecount >= 1){
         options(swift.system.cores=corecount)




More information about the Swift-commit mailing list