R Under development (unstable) (2025-06-05 r88281 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > source("incl/start.R") Loading required package: parallelly Loading required package: future > > plan(batchtools_local) > > ## CRAN processing times: > ## On Windows 32-bit, don't run these tests via batchtools > if (!fullTest && isWin32) plan(sequential) > > options(future.demo.mandelbrot.nrow = 2L) > options(future.demo.mandelbrot.resolution = 50L) > options(future.demo.mandelbrot.delay = FALSE) > > message("*** Demos ...") *** Demos ... > > message("*** Mandelbrot demo of the 'future' package ...") *** Mandelbrot demo of the 'future' package ... > > demo("mandelbrot", package = "future", ask = FALSE) demo(mandelbrot) ---- ~~~~~~~~~~ > library(future) > library(graphics) > plot_what_is_done <- function(counts) { + for (kk in seq_along(counts)) { + f <- counts[[kk]] + + ## Already plotted? + if (!inherits(f, "Future")) next + + ## Not resolved? + if (!resolved(f)) next + + message(sprintf("Plotting tile #%d of %d ...", kk, n)) + counts[[kk]] <- value(f) + screen(kk) + plot(counts[[kk]]) + } + + counts + } > ## Options > region <- getOption("future.demo.mandelbrot.region", 1L) > if (!is.list(region)) { + if (region == 1L) { + region <- list(xmid = -0.75, ymid = 0.0, side = 3.0) + } else if (region == 2L) { + region <- list(xmid = 0.283, ymid = -0.0095, side = 0.00026) + } else if (region == 3L) { + region <- list(xmid = 0.282989, ymid = -0.01, side = 3e-8) + } + } > nrow <- getOption("future.demo.mandelbrot.nrow", 3L) > resolution <- getOption("future.demo.mandelbrot.resolution", 400L) > delay <- getOption("future.demo.mandelbrot.delay", interactive()) > if (isTRUE(delay)) { + delay <- function(counts) Sys.sleep(1.0) + } else if (!is.function(delay)) { + delay <- function(counts) {} + } > ## Generate Mandelbrot tiles to be computed > Cs <- mandelbrot_tiles(xmid = region$xmid, ymid = region$ymid, + side = region$side, nrow = nrow, + resolution = resolution) > if (interactive()) { + dev.new() + plot.new() + split.screen(dim(Cs)) + for (ii in seq_along(Cs)) { + screen(ii) + par(mar = c(0, 0, 0, 0)) + text(x = 1 / 2, y = 1 / 2, sprintf("Future #%d\nunresolved", ii), cex = 2) + } + } else { + split.screen(dim(Cs)) + } [1] 1 2 3 4 > ## Create all Mandelbrot tiles via lazy futures > n <- length(Cs) > message(sprintf("Creating %d Mandelbrot tiles:", n), appendLF = FALSE) Creating 4 Mandelbrot tiles: > counts <- lapply(seq_along(Cs), FUN=function(ii) { + message(" ", ii, appendLF = FALSE) + C <- Cs[[ii]] + future({ + message(sprintf("Calculating tile #%d of %d ...", ii, n), appendLF = FALSE) + fit <- mandelbrot(C) + + ## Emulate slowness + delay(fit) + + message(" done") + fit + }, lazy = TRUE) + }) 1 2 3 4 > message(".") . > ## Calculate and plot tiles > repeat { + counts <- plot_what_is_done(counts) + if (!any(sapply(counts, FUN = inherits, "Future"))) break + } [04:37:47.758] Attaching 1 packages ('future') ... [04:37:47.766] Attaching 1 packages ('future') ... done [04:37:49.080] Launched future #1 Plotting tile #1 of 4 ... Calculating tile #1 of 4 ... done [04:37:49.519] Attaching 1 packages ('future') ... [04:37:49.533] Attaching 1 packages ('future') ... done [04:37:50.862] Launched future #1 Plotting tile #2 of 4 ... Calculating tile #2 of 4 ... done [04:37:50.982] Attaching 1 packages ('future') ... [04:37:50.993] Attaching 1 packages ('future') ... done [04:37:52.318] Launched future #1 Plotting tile #3 of 4 ... Calculating tile #3 of 4 ... done [04:37:52.464] Attaching 1 packages ('future') ... [04:37:52.478] Attaching 1 packages ('future') ... done [04:37:53.710] Launched future #1 Plotting tile #4 of 4 ... Calculating tile #4 of 4 ... done > close.screen() [1] 1 2 3 4 > message("SUGGESTION: Try to rerun this demo after changing strategy for how futures are resolved, e.g. plan(multisession).\n") SUGGESTION: Try to rerun this demo after changing strategy for how futures are resolved, e.g. plan(multisession). > > message("*** Demos ... DONE") *** Demos ... DONE > > source("incl/end.R") > > proc.time() user system elapsed 2.17 0.53 7.76