Skip to content

Commit 4a5ea80

Browse files
committed
Merge branch 'master' into froll-n0
2 parents c9d5cd7 + 0687c40 commit 4a5ea80

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

R/frollapply.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
262262
}
263263
## prepare templates for errors and warnings
264264
err.collect = gettext("frollapply calling parallel::mccollect to collect results from forked processes raised an error.\n%s")
265-
warn.collect = gettext("frollapply calling parallel::mccollect to collect results from forked processes raised a warning.\n%s")
265+
warn.collect = gettext("frollapply internal call to parallel::mccollect raised a warning, FUN warnings should have been suppressed by parallel.\n%s")
266266
if (is.function(simplify)) {
267267
err.simplify = gettext("frollapply completed successfully but raised an error when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s")
268268
warn.simplify = gettext("frollapply completed successfully but raised a warning when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s")
@@ -317,7 +317,9 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
317317
tryCatch(
318318
parallel::mccollect(jobs),
319319
error = function(e) stopf(err.collect, e[["message"]]),
320-
warning = function(w) warningf(warn.collect, w[["message"]])
320+
warning = function(w) {
321+
warningf(warn.collect, w[["message"]]) # nocov
322+
}
321323
),
322324
interrupt = function(e) {
323325
# nocov start
@@ -348,11 +350,14 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
348350
tryCatch(
349351
thisans <- lapply(ansi, FUN = tightFUN, dest = cpy(w), src = thisx, n = thisn),
350352
error = function(e) h$err = conditionMessage(e)
351-
), warning = function(w) {h$warn = c(h$warn, conditionMessage(w)); invokeRestart("muffleWarning")}
353+
), warning = function(w) {
354+
#h$warn = c(h$warn, conditionMessage(w)) ## warnings are suppressed for consistency to parallel processing code
355+
invokeRestart("muffleWarning")
356+
}
352357
)
353358
setDTthreads(oldDTthreads)
354-
if (!is.null(h$warn))
355-
warningf("frollapply received a warning(s) when evaluating FUN:\n%s", paste(unique(h$warn), collapse="\n"))
359+
#if (!is.null(h$warn)) ## warnings are suppressed for consistency to parallel processing code
360+
# warningf("frollapply received a warning(s) when evaluating FUN:\n%s", paste(unique(h$warn), collapse="\n"))
356361
if (!is.null(h$err))
357362
stopf("frollapply received an error(s) when evaluating FUN:\n%s", h$err)
358363
}

inst/tests/froll.Rraw

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,12 +1249,17 @@ if (use.fork) {
12491249
}
12501250
old = setDTthreads(1L)
12511251
options(datatable.verbose=TRUE)
1252-
test(6010.025, frollapply(1:2, 1, identity), c(2L,2L), output="running on single CPU thread")
1252+
test(6010.025, frollapply(1:2, 1, copy), c(1L,2L), output="running on single CPU thread")
12531253
options(datatable.verbose=FALSE)
1254-
test(6010.026, frollapply(1:2, 1, function(x) {warning("warn"); x}), c(2L,2L), warning="warn")
1255-
test(6010.027, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); x}), c(2L,2L), warning="warn:1\nwarn:2")
1256-
test(6010.028, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); x}), error="err:1") ## only first
1254+
test(6010.026, frollapply(1:2, 1, function(x) {warning("warn"); copy(x)}), c(1L,2L))
1255+
test(6010.027, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); copy(x)}), c(1L,2L))
1256+
test(6010.028, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); copy(x)}), error="err:1") ## only first
12571257
setDTthreads(old)
1258+
if (getDTthreads()>1L) { ## check for consistency
1259+
test(6010.036, frollapply(1:2, 1, function(x) {warning("warn"); copy(x)}), c(1L,2L))
1260+
test(6010.037, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); copy(x)}), c(1L,2L))
1261+
test(6010.038, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); copy(x)}), error="err:1") ## only first
1262+
}
12581263

12591264
#### corner cases from examples - handled properly after frollapply rewrite to R
12601265
test(6010.101, frollapply(1:5, 3, function(x) head(x, 2)), list(NA, NA, 1:2, 2:3, 3:4))

man/frollapply.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ frollapply(c(1, 9), N=1L, FUN=function(x) copy(list(x)))
7474
}
7575
\item \code{FUN} calls are internally passed to \code{parallel::mcparallel} to evaluate them in parallel. We inherit few limitations from \code{parallel} package explained below. This optimization can be disabled completely by calling \code{setDTthreads(1)}, then limitations listed below do not apply because all iterations of \code{FUN} evaluation will be made sequentially without use of \code{parallel} package. Note that on Windows platform this optimization is always disabled due to lack of \emph{fork} used by \code{parallel} package. One can use \code{options(datatable.verbose=TRUE)} to get extra information if \code{frollapply} is running multithreaded or not.
7676
\itemize{
77-
\item Warnings produced inside the function are silently ignored.
77+
\item Warnings produced inside the function are silently ignored; for consistency we ignore warnings also when running single threaded path.
7878
\item \code{FUN} should not use any on-screen devices, GUI elements, tcltk, multithreaded libraries. Note that \code{setDTthreads(1L)} is passed to forked processes, therefore any data.table code inside \code{FUN} will be forced to be single threaded. It is advised to not call \code{setDTthreads} inside \code{FUN}. \code{frollapply} is already parallelized and nested parallelism is rarely a good idea.
7979
\item Any operation that could misbehave when run in parallel has to be handled. For example writing to the same file from multiple CPU threads.
8080
\preformatted{

0 commit comments

Comments
 (0)