[Swift-commit] r4026 - in SwiftApps/SwiftR/Swift: R exec man
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Fri Jan 21 14:15:14 CST 2011
Author: tga
Date: 2011-01-21 14:15:14 -0600 (Fri, 21 Jan 2011)
New Revision: 4026
Added:
SwiftApps/SwiftR/Swift/man/swiftInit.Rd
SwiftApps/SwiftR/Swift/man/swiftShutdown.Rd
SwiftApps/SwiftR/Swift/man/swiftapply.Rd
Modified:
SwiftApps/SwiftR/Swift/R/Fifo.R
SwiftApps/SwiftR/Swift/R/Swift.R
SwiftApps/SwiftR/Swift/R/Workers.R
SwiftApps/SwiftR/Swift/exec/RunAllR.sh
SwiftApps/SwiftR/Swift/exec/RunR.sh
SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
SwiftApps/SwiftR/Swift/exec/start-swift
SwiftApps/SwiftR/Swift/man/Swift-package.Rd
Log:
Checking in a bunch of changes working towards a new release:
* Documentation for init, apply, shutdown functions.
* Code to ensure that local R worker servers are correctly terminated: previously they would persist.
* Various tweaks to ensure that stray messages don't show up in the user's R terminal: e.g. if kill tries to kill a non-existent process.
* When a worker process is shutdown, it is removed from list of active workers.
* swiftapply is more flexible in accepting c() vectors as arguments.
Modified: SwiftApps/SwiftR/Swift/R/Fifo.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Fifo.R 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/R/Fifo.R 2011-01-21 20:15:14 UTC (rev 4026)
@@ -64,8 +64,8 @@
# through stdout
# want to suppress warning message about exit codea
toutMsg <- "_FIFOTIMEOUT_"
- if (length(fifodata) == 0
- || substr(fifodata[[1]], 1,nchar(toutMsg)) == toutMsg) {
+ if ( (! length(fifodata) == 0)
+ && substr(fifodata[[1]], 1,nchar(toutMsg)) == toutMsg) {
return (NA)
}
else {
Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/R/Swift.R 2011-01-21 20:15:14 UTC (rev 4026)
@@ -10,7 +10,6 @@
quiet=FALSE)
{
# Set Swift default options if not passed as keywords or pre-set by user
-
if(is.null(server))
server <- getOption("swift.server")
if(is.null(server))
@@ -20,6 +19,7 @@
callsperbatch <- getOption("swift.callsperbatch")
if(is.null(callsperbatch))
callsperbatch <- 1
+ #cat("Got ", length(arglists), " arguments with batching factor ", callsperbatch)
if(is.null(runmode))
runmode <- getOption("swift.runmode")
@@ -52,7 +52,7 @@
tmpdir <- "/tmp";
if (! quiet) {
cat("\nSwift properties:\n")
- cat(" server =", server,"\n");
+ cat(" server =", server,"\n")
cat(" callsperbatch =", callsperbatch,"\n")
cat(" runmode =", runmode,"\n")
cat(" tmpdir =", tmpdir,"\n")
@@ -139,9 +139,10 @@
# shuts down, so we know if the requestPipe still exists there
# should still be a worker (or the worker crashed in a funny way).
if (file.exists(requestPipeName)) {
- #TODO: there is a race condition here if the fifo disappears in
- # between checking for existence and opening the fifo
- writeTimeout <- 2000
+ # there is a race condition here if the fifo disappears in
+ # between checking for existence and opening the fifo, but
+ # the timeout will catch that unlikely case
+ writeTimeout <- 4000
success <- writeFifo(requestPipeName,paste(reqdir,"\n",sep=""),
timeout=writeTimeout)
if (! success) {
Modified: SwiftApps/SwiftR/Swift/R/Workers.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Workers.R 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/R/Workers.R 2011-01-21 20:15:14 UTC (rev 4026)
@@ -94,26 +94,29 @@
return (output)
}
-swiftShutdown <- function(pid=NULL)
+swiftShutdown <- function(handle=NULL)
{
- if (is.null(pid)) {
+ if (is.null(handle)) {
if (is.null(.swift.workers)) {
return
}
workers = .swift.workers
+ .swift.workers <<- list()
}
else {
- workers=pid
+ workers=handle
+ .swift.workers <<- Filter(
+ function (p) { return (p != as.character(handle)) ; },
+ .swift.workers)
}
cat("Shutting down Swift worker processes\n")
# shut down all worker processes using kill
for (pid in workers) {
- cmdString <- file.path(.find.package("Swift"), "exec/killtree")
+ cmdString <- file.path(.find.package("Swift"), "exec/killtree &> /dev/null ")
killCmd <- paste(cmdString,pid)
system(killCmd, wait=FALSE)
}
- .swift.workers <<- list()
}
Modified: SwiftApps/SwiftR/Swift/exec/RunAllR.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/RunAllR.sh 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/exec/RunAllR.sh 2011-01-21 20:15:14 UTC (rev 4026)
@@ -18,7 +18,8 @@
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)
cat("Running call # ", c, "\n");
- result[[c]] <- do.call( rcall$func, rcall$arglistbatch[[c]] )
+ result[[c]] <- do.call( rcall$func,
+ as.list(rcall$arglistbatch[[c]]) )
}
save(result,file=ofile)
}
Modified: SwiftApps/SwiftR/Swift/exec/RunR.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/RunR.sh 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/exec/RunR.sh 2011-01-21 20:15:14 UTC (rev 4026)
@@ -7,7 +7,9 @@
result=list()
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]] = do.call( rcall$func, rcall$arglistbatch[[c]] )
+ result[[c]] = do.call( rcall$func,
+ as.list(rcall$arglistbatch[[c]]) )
+ # Coerce to list in case vector provided
}
save(result,file=argv[2])
Modified: SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.sh 2011-01-21 20:15:14 UTC (rev 4026)
@@ -60,7 +60,8 @@
}
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]] ))
+ result[[c]] = try(do.call( rcall$func,
+ as.list(rcall$arglistbatch[[c]] )))
}
save(result,file=resultBatchFileName)
}
Modified: SwiftApps/SwiftR/Swift/exec/start-swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-swift 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/exec/start-swift 2011-01-21 20:15:14 UTC (rev 4026)
@@ -370,15 +370,13 @@
out=swift.stdouterr
touch $out
+function stdcleanup {
+ # don't accept any more requests: unlink fifo from filesystem
+ if [ -p requestpipe ]; then
+ rm requestpipe
+ fi
+}
-# Reset signal handling behaviour to default:
-# sending a HUP to this process should then trigger termination
-# of all subprocess unless we change it by hand. This is added
-# here to work around problems where parent processes had changed
-# signal handlers
-#trap " echo quitting; exit 0 " $TRAPEVENTS
-
-
if [ $server = local ]; then
if [ $cores -eq 0 ]; then
@@ -389,10 +387,14 @@
source $SWIFTRBIN/configure-server-local $cores
function onexit {
- # don't accept any more requests: unlink fifo from filesystem
- if [ -p requestpipe ]; then
- rm requestpipe
- fi
+ stdcleanup
+ # Find and terminate R workers: they should register their PiD
+ # in a standard location based on the pid of this start-swift
+ # script
+ for pidfile in ../Rworkers/worker.$$/*/R.pid
+ do
+ kill `cat $pidfile` &> /dev/null
+ done
exit 0
}
@@ -414,10 +416,7 @@
TRAPEVENTS="EXIT 1 2 3 15" # Signals and conditions to trap
function onexit {
- # don't accept any more requests: unlink fifo from filesystem
- if [ -p requestpipe ]; then
- rm requestpipe
- fi
+ stdcleanup
coasterservicepid="" # null: saved in case we go back to using coaster servers
trap - $TRAPEVENTS
sshpids=$(cat $sshpidfile)
@@ -453,10 +452,8 @@
TRAPEVENTS="EXIT 1 2 3 15" # Signals and conditions to trap
function onexit {
- # don't accept any more requests: unlink fifo from filesystem
- if [ -p requestpipe ]; then
- rm requestpipe
- fi
+ stdcleanup
+
coasterservicepid="" # null: saved in case we go back to using coaster servers
trap - $TRAPEVENTS
jobid=$(cat $jobidfile)
Modified: SwiftApps/SwiftR/Swift/man/Swift-package.Rd
===================================================================
--- SwiftApps/SwiftR/Swift/man/Swift-package.Rd 2011-01-21 17:41:44 UTC (rev 4025)
+++ SwiftApps/SwiftR/Swift/man/Swift-package.Rd 2011-01-21 20:15:14 UTC (rev 4026)
@@ -1,8 +1,6 @@
\name{Swift-package}
\alias{Swift-package}
\alias{Swift}
-\alias{swiftapply}
-\alias{swiftLapply}
\docType{package}
\title{
R interface to for parallel apply() calls using Swift
@@ -29,8 +27,8 @@
\tabular{ll}{
Package: \tab Swift\cr
Type: \tab Package\cr
-Version: \tab 0.1.0\cr
-Date: \tab 2010-10-15\cr
+Version: \tab 0.2.0\cr
+Date: \tab 2011-01-21\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
@@ -516,19 +514,20 @@
Kenny, Ioan Raicu, Luiz Gadelha, Allan Espinosa, Zhao Zhang, David
Kelly, Jon Monette, Glen Hocky, Tom Uram, Wenjun Wu, and other users.
-Swift R package developed by Michael Wilde and the OpenMx project
+Swift R package developed by Michael Wilde, Tim Armstrong and the OpenMx project
Maintainer: Michael Wilde <wilde at mcs.anl.gov>
}
\references{
-http://www.ci/uchicago.edu/swift
+\url{http://www.ci.uchicago.edu/swift}
}
\keyword{ parallel and distributed execution }
-%%\seealso{
-%%~~ Optional links to other man pages, e.g. ~~
-%%~~ \code{\link[<pkg>:<pkg>-package]{<pkg>}} ~~
-%%}
+\seealso{
+\code{\link{swiftInit}}
+\code{\link{swiftShutdown}}
+\code{\link{swiftapply}}
+}
\examples{
myfunc <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
Added: SwiftApps/SwiftR/Swift/man/swiftInit.Rd
===================================================================
--- SwiftApps/SwiftR/Swift/man/swiftInit.Rd (rev 0)
+++ SwiftApps/SwiftR/Swift/man/swiftInit.Rd 2011-01-21 20:15:14 UTC (rev 4026)
@@ -0,0 +1,136 @@
+\name{swiftInit}
+\alias{swiftInit}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{Starting Swift Workers
+}
+\description{
+This function prepares for parallel Swift jobs to be run by initialising a pool of workers. Depending on the arguments, these workers may be on the local host, or on a remote host.
+}
+\usage{
+swiftInit(cores = NULL, server = NULL, hosts = NULL, nodes = NULL, project = NULL, parEnv = NULL, workmode = NULL, throttle = NULL, queue = NULL, rcmd = NULL, time = NULL, workerLogging = NULL)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{cores}{
+ The number of cores per host. The default values vary from 2 to 8 depending on the server type.
+}
+ \item{server}{
+ One of: "local", "ssh", "pbs", "sge", "pbsf".
+ How Swift will run the jobs: for example, if "local" is chosen, they
+ will be run on the local machine, or if "pbs" is chosen, they will be
+ run through the pbs scheduler.
+ This must correspond to a server type started by swiftInit()
+ If server argument is not provided, the swift.server option will
+ be used, and if that is unavailable, "local" will be assumed.
+}
+ \item{hosts}{
+ A string containing a list of remote hosts to run jobs on
+ , separated by spaces. This only is used if server is "ssh".
+}
+ \item{nodes}{
+ The number of nodes to request from the batch scheduler. This only
+ is used if server is "pbs", "sge" or "pbsf".
+}
+ \item{project}{
+ The project name passed to the PBS or SGE batch scheduler. Site-specific.
+}
+ \item{parEnv}{
+ SGE only.
+}
+ \item{workmode}{
+ Can be "node" or "slot".
+ node: start one worker for all slots on a node. slot: start one worker
+ per slot (multiple workers per node).
+}
+ \item{throttle}{
+%% ~~Describe \code{throttle} here~~
+}
+ \item{queue}{
+ The scheduler queue to put jobs in. This is only relevant for PBS
+ and SGE.
+}
+ \item{rcmd}{
+ Specific to SGE: the remote shell command. The default value is
+ typically fine, but if you have issues it may need to be changed.
+}
+ \item{time}{
+ The duration to request nodes for from the PBS or SGE scheduler.
+ Time should be specified in hh:mm:ss format.
+ Note that for "local" and "ssh" servers, workers remain indefinitely
+ until shut down.
+
+}
+ \item{workerLogging}{
+ For testing purposes: the swift worker loggin level.
+}
+
+}
+\details{
+ As a result of calling swiftInit(), a swift server process is started
+ in the background. This process will be cleaned up automatically when
+ you exit your R session. Alternatively, swiftShutdown can shut down
+ some or all server processes without closing R.
+
+}
+\value{
+ swiftInit returns a handle to the swift server process started.
+ This handle can be used later as an argument to swiftShutdown to
+ shut down the server process. The actual data in the handle may
+ change in later versions of Swift.
+}
+\references{
+\url{http://www.ci.uchicago.edu/swift}
+}
+\author{
+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 R package developed by Michael Wilde, Tim Armstrong and the OpenMx project
+
+Maintainer: Michael Wilde <wilde at mcs.anl.gov>
+}
+\note{
+%% ~~further notes~~
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+\code{\link{Swift-package}}
+\code{\link{swiftShutdown}}
+}
+\examples{
+# Running a job on the local machine with 8 cores
+option(swift.server="local")
+serverHandle <- swiftInit(cores=8)
+swiftApply(log,list(list(3), list(4)))
+swiftLapply(list(3, 4),
+ function (x) { return (2*x); })
+# Now shut down the server
+swiftShutdown(serverHandle)
+
+# Now run remotely via ssh on 2 remote machines called foo and bar
+option(swift.server="ssh")
+swiftInit(hosts="foo bar")
+swiftLapply(list(3, 4), log)
+# ssh servers will keep running
+
+# Run using the PBS scheduler
+option(swift.server="pbs")
+# start a worker through pbs. Note that, depending on your PBS
+# installation's utilization level and policies, it may take
+# a while before swiftapply calls can be processed.
+swiftInit()
+swiftLapply(c(3, 4), log)
+
+# Close all the workers we started up
+swiftShutdown()
+
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
Added: SwiftApps/SwiftR/Swift/man/swiftShutdown.Rd
===================================================================
--- SwiftApps/SwiftR/Swift/man/swiftShutdown.Rd (rev 0)
+++ SwiftApps/SwiftR/Swift/man/swiftShutdown.Rd 2011-01-21 20:15:14 UTC (rev 4026)
@@ -0,0 +1,57 @@
+\name{swiftShutdown}
+\alias{swiftShutdown}
+\title{
+Shut Down Swift Workers
+}
+\description{
+%% ~~ A concise (1-5 lines) description of what the function does. ~~
+}
+\usage{
+swiftShutdown(handle = NULL)
+}
+\arguments{
+ \item{handle}{
+ The handle value returned by "\code{swiftInit}" when a worker was
+ started up. If provided, only that worker will be shut down.
+ If handle is not provided, all workers started during this R
+ session will be shut down.
+
+}
+}
+\details{
+%% ~~ If necessary, more details than the description above ~~
+}
+\value{
+ No return value
+}
+\references{
+\url{http://www.ci.uchicago.edu/swift}
+}
+\author{
+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 R package developed by Michael Wilde, Tim Armstrong and the OpenMx project
+
+Maintainer: Michael Wilde <wilde at mcs.anl.gov>
+}
+\note{
+%% ~~further notes~~
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+\code{\link{Swift-package}}
+\code{\link{swiftInit}}
+
+}
+\examples{
+
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
Added: SwiftApps/SwiftR/Swift/man/swiftapply.Rd
===================================================================
--- SwiftApps/SwiftR/Swift/man/swiftapply.Rd (rev 0)
+++ SwiftApps/SwiftR/Swift/man/swiftapply.Rd 2011-01-21 20:15:14 UTC (rev 4026)
@@ -0,0 +1,109 @@
+\name{swiftapply}
+\alias{swiftLapply}
+\alias{swiftapply}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+ swiftapply: Applying a Function to a List of Arguments
+}
+\description{
+ swiftapply takes a function, and list of argument lists,
+ and applies the function to each of the argument lists.
+ This is done in parallel using the Swift engine.
+}
+\usage{
+swiftapply(func, arglists, server = NULL, callsperbatch = NULL, runmode = NULL, initialexpr = NULL, workerhosts = NULL, keepwork = NULL, tmpdir = NULL, timeout = NULL, quiet = FALSE)
+
+}
+\arguments{
+ \item{func}{
+ The function to apply.
+}
+ \item{arglists}{
+ A list of argument lists to be given to the function.
+}
+ \item{server}{
+ The swift server type to use to run. The possible values are
+ "local", "ssh", "pbs", "sge" and "pbsf", the same as swiftInit.
+}
+ \item{callsperbatch}{
+ The number of function calls to group together into a single batch.
+ A higher batching factor reduces the overhead of running many batchs,
+ but reduces the available amount of parallelism. Consider a low
+ value if each function call involves a substantial amount of work:
+ 1 may be an appropriate value if each function call takes more than 2-3
+ seconds to complete. Consider a high value if each function call
+ involves a minimal amount of worker.
+}
+ \item{runmode}{
+ For testing purposes only.
+}
+ \item{initialexpr}{
+ Each function call is run in a fresh R session. initialexpr is a
+ fragment of R code that performs any required setup in the session.
+}
+ \item{workerhosts}{
+ For testing purposes only.
+}
+ \item{keepwork}{
+ Whether to store intermediate files. For testing purposes.
+}
+ \item{tmpdir}{
+ The system's temporary directory to store working files under.
+ The default value is generally sufficient.
+}
+ \item{timeout}{
+ If provided, swiftapply will return if a response is not received by
+ the swift server in the specified time window in milliseconds.
+
+}
+ \item{quiet}{
+ Whether to suppress informational output about the job.
+}
+}
+\details{
+Before running swiftapply for the first time in a session you will likely
+want to run swiftInit to start a Swift server.
+}
+\value{
+ Returns a list with return values corresponding to the argument
+ lists provided to swiftapply.
+ An error will be raised if for some reason no results could be
+ retrieved. If individual argument lists cause an error when
+ the function is run, the corresponding list entry in the
+ return list will contain a "\code{try-error}" object.
+}
+\references{
+\url{http://www.ci.uchicago.edu/swift}
+}
+\author{
+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 R package developed by Michael Wilde, Tim Armstrong and the OpenMx project
+
+Maintainer: Michael Wilde <wilde at mcs.anl.gov>
+}
+\note{
+%% ~~further notes~~
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+\code{\link{swiftInit}}
+\code{\link{Swift-package}}
+}
+\examples{
+##---- Should be DIRECTLY executable !! ----
+##-- ==> Define data, use random,
+##-- or do help(data=index) for the standard data sets.
+
+swiftapply(log, list(list(5),list(6)))
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
More information about the Swift-commit
mailing list