You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
warn.simplify= gettext("frollapply completed successfully but raised a warning when attempting to simplify results using our internal 'simplifylist' function. 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. If you believe your results could be automatically simplified please submit your use case as new issue in our issue tracker.\n%s")
279
279
}
280
280
281
-
DTths= getDTthreads(FALSE)
282
-
use.fork=.Platform$OS.type!="windows"&&DTths>1L
283
-
if (verbose) {
284
-
if (use.fork) cat("frollapply running on multiple CPU threads using parallel::mcparallel\n")
285
-
else cat("frollapply running on single CPU thread\n")
286
-
}
281
+
DTths0= getDTthreads(FALSE)
282
+
use.fork0=.Platform$OS.type!="windows"&&DTths0>1L
287
283
ans= vector("list", nx*nn)
288
284
## vectorized x
289
285
for (iin seq_len(nx)) {
290
286
thisx=X[[i]]
291
287
thislen=len[i]
292
288
if (!thislen)
293
289
next
290
+
if (!use.fork0) {
291
+
use.fork=use.fork0
292
+
if (verbose)
293
+
cat("frollapply running on single CPU thread\n")
294
+
} else {
295
+
# throttle
296
+
DTths= getDTthreadsC(thislen, TRUE)
297
+
use.fork=DTths>1L
298
+
if (verbose) {
299
+
if (DTths<DTths0)
300
+
catf("frollapply run on %d CPU threads throttled to %d threads, input length %d\n", DTths0, DTths, thislen)
301
+
else
302
+
catf("frollapply running on %d CPU threads\n", DTths)
test(6010.0201, frollapply(1:2, 1, copy), 1:2, output=sprintf("frollapply run on %d CPU threads throttled to 1 threads, input length 2", ths), options=c(datatable.verbose=TRUE))
1269
+
test(6010.0202, frollapply(1:1024, 1, copy), 1:1024, output=sprintf("frollapply run on %d CPU threads throttled to 1 threads, input length 1024", ths), options=c(datatable.verbose=TRUE))
1270
+
if (ths > 2L) { ## setDTthreads(8); ths = getDTthreads()
1271
+
test(6010.0203, frollapply(1:1025, 1, copy), 1:1025, output=sprintf("frollapply run on %d CPU threads throttled to 2 threads, input length 1025", ths), options=c(datatable.verbose=TRUE))
1272
+
test(6010.0204, frollapply(1:2048, 1, copy), 1:2048, output=sprintf("frollapply run on %d CPU threads throttled to 2 threads, input length 2048", ths), options=c(datatable.verbose=TRUE))
1273
+
} else { ## CRAN: setDTthreads(2); ths = 2
1274
+
test(6010.0205, frollapply(1:1025, 1, copy), 1:1025, output="frollapply running on 2 CPU threads", options=c(datatable.verbose=TRUE))
1275
+
test(6010.0206, frollapply(1:2048, 1, copy), 1:2048, output="frollapply running on 2 CPU threads", options=c(datatable.verbose=TRUE))
1276
+
}
1277
+
if (ths > 3L) { ## setDTthreads(8); ths = getDTthreads()
1278
+
test(6010.0207, frollapply(1:2049, 1, copy), 1:2049, output=sprintf("frollapply run on %d CPU threads throttled to 3 threads, input length 2049", ths), options=c(datatable.verbose=TRUE))
1279
+
test(6010.0208, frollapply(1:3072, 1, copy), 1:3072, output=sprintf("frollapply run on %d CPU threads throttled to 3 threads, input length 3072", ths), options=c(datatable.verbose=TRUE))
test(6010.023, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); copy(x)}), error="err:1") ## second error not printed for consistency to single threaded
test(6010.712, as.null(frollapply(1:3, 1, function(x) if (x==1L) sum else if (x==2L) mean else `[`, simplify=TRUE)), NULL) ## as.null as we are only interested in codecov here
1495
1514
test(6010.713, as.null(frollapply(1:3, 1, function(x) `[`, simplify = TRUE)), NULL) ## as.null as we are only interested in codecov here
1496
1515
1497
-
#### fixing .internal.selfref
1516
+
#### mutlithreading throttle caveats from manual: copy, fixing .internal.selfref
\item CPU threads utilization in \code{frollapply} can be controlled by \code{\link{setDTthreads}}, which by default uses half of available CPU threads.
158
+
\item CPU threads utilization in \code{frollapply} can be controlled by \code{\link{setDTthreads}}, which by default uses half of available CPU threads. Usage of multiple CPU threads will be throttled for small input, as described in \code{\link{setDTthreads}} manual.
158
159
\item Optimization that avoids repeated allocation of a window subset (see \emph{Implementation} section for details), in case of adaptive rolling function, depends on R's \emph{growablebit}.ThisfeaturehasbeenaddedinR3.4.0.Adaptive \code{frollapply} willstillworkonolderversionsofRbut, duetorepeatedallocationofwindowsubset, itwillbemuchslower.
0 commit comments