Skip to content

Commit

Permalink
progressbar = TRUE reports progress on each iteration
Browse files Browse the repository at this point in the history
- only when `tasks` is not defined
  • Loading branch information
mtmorgan committed Aug 8, 2021
1 parent d29c40b commit b944679
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/BiocParallelParam-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ setMethod("bpprogressbar", "BiocParallelParam",
setReplaceMethod("bpprogressbar", c("BiocParallelParam", "logical"),
function(x, value)
{
x$progressbar <- value
x$progressbar <- value
x
})

Expand Down
3 changes: 3 additions & 0 deletions R/MulticoreParam-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ MulticoreParam <- function(workers=multicoreWorkers(), tasks=0L,
workers = 1L
}

if (progressbar && missing(tasks))
tasks <- .Machine$integer.max

clusterargs <- c(list(spec=workers, type="FORK"), list(...))

manager.hostname <-
Expand Down
3 changes: 3 additions & 0 deletions R/SnowParam-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ SnowParam <- function(workers=snowWorkers(type),
if (type %in% c("MPI", "FORK") && is(workers, "character"))
stop("'workers' must be integer(1) when 'type' is MPI or FORK")

if (progressbar && missing(tasks))
tasks <- .Machine$integer.max

clusterargs <- c(list(spec=workers, type=type), list(...))

manager.hostname <-
Expand Down
12 changes: 12 additions & 0 deletions inst/unitTests/test_MulticoreParam.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_MulticoreParam_progressbar <- function()
{
if (.Platform$OS.type == "windows")
return()

checkIdentical(bptasks(MulticoreParam()), 0L)
checkIdentical(bptasks(MulticoreParam(tasks = 0L, progressbar = TRUE)), 0L)
checkIdentical(
bptasks(MulticoreParam(progressbar = TRUE)),
.Machine$integer.max
)
}
7 changes: 7 additions & 0 deletions inst/unitTests/test_SnowParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ test_SnowParam_workers <- function()
checkException(SnowParam("host", "MPI"), silent=TRUE)
checkException(SnowParam("host", "FORK"), silent=TRUE)
}

test_SnowParam_progressbar <- function()
{
checkIdentical(bptasks(SnowParam()), 0L)
checkIdentical(bptasks(SnowParam(tasks = 0L, progressbar = TRUE)), 0L)
checkIdentical(bptasks(SnowParam(progressbar = TRUE)), .Machine$integer.max)
}
19 changes: 13 additions & 6 deletions man/MulticoreParam-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ multicoreWorkers()

In this documentation a job is defined as a single call to a function, such
as \code{bplapply}, \code{bpmapply} etc. A task is the division of the
\code{X} argument into chunks. When \code{tasks == 0} (default), \code{X}
is divided as evenly as possible over the number of workers.
\code{X} argument into chunks.

A \code{tasks} value of > 0 specifies the exact number of tasks. Values
can range from 1 (all of \code{X} to a single worker) to the length of
\code{X} (each element of \code{X} to a different worker).
When \code{tasks == 0} (default, except when \code{progressbar =
TRUE}), \code{X} is divided as evenly as possible over the number of
workers.

A \code{tasks} value of > 0 specifies the exact number of
tasks. Values can range from 1 (all of \code{X} to a single worker)
to the length of \code{X} (each element of \code{X} to a different
worker).

When the length of \code{X} is less than the number of workers each
element of \code{X} is sent to a worker and \code{tasks} is ignored.
Expand All @@ -202,7 +206,10 @@ multicoreWorkers()
\code{logical(1)} Enable stop on error.
}
\item{progressbar}{
\code{logical(1)} Enable progress bar (based on plyr:::progress_text).
\code{logical(1)} Enable progress bar (based on
plyr:::progress_text). Enabling the progress bar changes the
\emph{default} value of \code{tasks} to \code{.Machine$integer.max}, so
that progress is reported for each element of \code{X}.
}
\item{RNGseed}{
\code{integer(1)} Seed for random number generation. When not \code{NULL},
Expand Down

0 comments on commit b944679

Please sign in to comment.