R Under development (unstable) (2024-10-28 r87274 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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") > > library(future) > > supportedStrategies <- function(cores = NA_integer_, excl = "cluster", ...) { + strategies <- future:::supportedStrategies(...) + strategies <- setdiff(strategies, excl) + if (!is.na(cores)) { + if (cores == 1L) { + strategies <- setdiff(strategies, c("multicore", "multisession")) + } else if (cores > 1L) { + strategies <- setdiff(strategies, "sequential") + } + } + + strategies + } > > isWin32 <- FALSE > availCores <- 2L > > message("*** Demos ...") *** Demos ... > > message("*** Mandelbrot demo ...") *** Mandelbrot demo ... > > if (!isWin32) { + options(future.demo.mandelbrot.nrow = 2L) + options(future.demo.mandelbrot.resolution = 50L) + options(future.demo.mandelbrot.delay = FALSE) + + for (cores in 1:availCores) { + message(sprintf("Testing with %d cores ...", cores)) + options(mc.cores = cores) + + for (strategy in supportedStrategies(cores)) { + message(sprintf("- plan('%s') ...", strategy)) + plan(strategy) + demo("mandelbrot", package = "progressr", ask = FALSE) + + ## Explicitly close any PSOCK clusters to avoid 'R CMD check' NOTE + ## on "detritus in the temp directory" on MS Windows + plan(sequential) + + message(sprintf("- plan('%s') ... DONE", strategy)) + } + + message(sprintf("Testing with %d cores ... DONE", cores)) + } ## for (cores ...) + } else { + message(" - This demo requires R (>= 3.2.0). Skipping test. (Skipping also on Win32 i386 for speed)") + } Testing with 1 cores ... - plan('sequential') ... demo(mandelbrot) ---- ~~~~~~~~~~ > library(progressr) > library(future) > library(graphics) > p <- function(...) NULL > plot_what_is_done <- function(counts) { + done <- 0L + + for (kk in seq_along(counts)) { + f <- counts[[kk]] + + ## Already plotted? + if (!inherits(f, "Future")) { + done <- done + 1L + next + } + + ## Not resolved? + ## NOTE: This will block, if all workers are busy! + if (runif(1) < 0.8*(1-(done/length(counts))) || !resolved(f)) next + + message(sprintf("Plotting tile #%d of %d ...", kk, n)) + counts[[kk]] <- value(f) + screen(kk) + plot(counts[[kk]]) + + done <- done + 1L + } + + 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", 5L) > resolution <- getOption("future.demo.mandelbrot.resolution", 1024L) > delay <- getOption("future.demo.mandelbrot.delay", interactive()) > if (isTRUE(delay)) { + delay <- function(counts) Sys.sleep(runif(1L, min=0.5, max=5)) + } 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) > message("Tiles: ", paste(dim(Cs), collapse = " by ")) Tiles: 2 by 2 > 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)) * Creating 4 Mandelbrot tiles > with_progress({ + p <- progressor(along = Cs) + counts <- lapply(seq_along(Cs), FUN=function(ii) { + C <- Cs[[ii]] + future({ + message(sprintf("Calculating tile #%d of %d ...", ii, n), appendLF = FALSE) + fit <- mandelbrot(C) + + ## Emulate slowness + delay(fit) + + p(sprintf("Tile #%d (PID %d)", ii, Sys.getpid())) + + message(" done") + fit + }, lazy = TRUE) + }) + str(counts) + + pp <- 0L + while (any(sapply(counts, FUN = inherits, "Future"))) { + counts <- plot_what_is_done(counts) + } + }) | | | 0% | | | 0% Plotting tile #3 of 4 ... Calculating tile #3 of 4 ... done | | | 0% Plotting tile #4 of 4 ... Calculating tile #4 of 4 ... done | | | 0% Plotting tile #2 of 4 ... Calculating tile #2 of 4 ... done | | | 0% List of 4 $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' Plotting tile #1 of 4 ... Calculating tile #1 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). - plan('sequential') ... DONE Testing with 1 cores ... DONE Testing with 2 cores ... - plan('multisession') ... demo(mandelbrot) ---- ~~~~~~~~~~ > library(progressr) > library(future) > library(graphics) > p <- function(...) NULL > plot_what_is_done <- function(counts) { + done <- 0L + + for (kk in seq_along(counts)) { + f <- counts[[kk]] + + ## Already plotted? + if (!inherits(f, "Future")) { + done <- done + 1L + next + } + + ## Not resolved? + ## NOTE: This will block, if all workers are busy! + if (runif(1) < 0.8*(1-(done/length(counts))) || !resolved(f)) next + + message(sprintf("Plotting tile #%d of %d ...", kk, n)) + counts[[kk]] <- value(f) + screen(kk) + plot(counts[[kk]]) + + done <- done + 1L + } + + 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", 5L) > resolution <- getOption("future.demo.mandelbrot.resolution", 1024L) > delay <- getOption("future.demo.mandelbrot.delay", interactive()) > if (isTRUE(delay)) { + delay <- function(counts) Sys.sleep(runif(1L, min=0.5, max=5)) + } 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) > message("Tiles: ", paste(dim(Cs), collapse = " by ")) Tiles: 2 by 2 > 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] 5 6 7 8 > ## Create all Mandelbrot tiles via lazy futures > n <- length(Cs) > message(sprintf("* Creating %d Mandelbrot tiles", n)) * Creating 4 Mandelbrot tiles > with_progress({ + p <- progressor(along = Cs) + counts <- lapply(seq_along(Cs), FUN=function(ii) { + C <- Cs[[ii]] + future({ + message(sprintf("Calculating tile #%d of %d ...", ii, n), appendLF = FALSE) + fit <- mandelbrot(C) + + ## Emulate slowness + delay(fit) + + p(sprintf("Tile #%d (PID %d)", ii, Sys.getpid())) + + message(" done") + fit + }, lazy = TRUE) + }) + str(counts) + + pp <- 0L + while (any(sapply(counts, FUN = inherits, "Future"))) { + counts <- plot_what_is_done(counts) + } + }) | | | 0% List of 4 $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' $ :Classes 'Future', 'environment' | | | 0% Plotting tile #1 of 4 ... Calculating tile #1 of 4 ... done | | | 0% Plotting tile #2 of 4 ... Calculating tile #2 of 4 ... done | | | 0% | |==================================================== | 75% Plotting tile #4 of 4 ... Calculating tile #4 of 4 ... done | |==================================================== | 75% Plotting tile #3 of 4 ... Calculating tile #3 of 4 ... done > close.screen() [1] 1 2 3 4 5 6 7 8 > 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). - plan('multisession') ... DONE Testing with 2 cores ... DONE > > message("*** Mandelbrot demo ... DONE") *** Mandelbrot demo ... DONE > > message("*** Demos ... DONE") *** Demos ... DONE > > source("incl/end.R") Failed to undo environment variables: - Expected environment variables: [n=201] '!ExitCode', 'ALLUSERSPROFILE', 'APPDATA', 'BIBINPUTS', 'BINDIR', 'BSTINPUTS', 'COMMONPROGRAMFILES', 'COMPUTERNAME', 'COMSPEC', 'CURL_CA_BUNDLE', 'CYGWIN', 'CommonProgramFiles(x86)', 'CommonProgramW6432', 'DriverData', 'HOME', 'HOMEDRIVE', 'HOMEPATH', 'JAGS_ROOT', 'JAVA_HOME', 'LANGUAGE', 'LC_COLLATE', 'LC_MONETARY', 'LC_TIME', 'LOCALAPPDATA', 'LOGONSERVER', 'LS_HOME', 'LS_LICENSE_PATH', 'MAKE', 'MAKEFLAGS', 'MAKELEVEL', 'MFLAGS', 'MSMPI_BENCHMARKS', 'MSMPI_BIN', 'MSYS2_ENV_CONV_EXCL', 'NUMBER_OF_PROCESSORS', 'OCL', 'OMP_THREAD_LIMIT', 'OS', 'PATH', 'PATHEXT', 'PROCESSOR_ARCHITECTURE', 'PROCESSOR_IDENTIFIER', 'PROCESSOR_LEVEL', 'PROCESSOR_REVISION', 'PROGRAMFILES', 'PROMPT', 'PSModulePath', 'PUBLIC', 'PWD', 'ProgramData', 'ProgramFiles(x86)', 'ProgramW6432', 'RTOOLS43_HOME', 'RTOOLS44_HOME', 'R_ARCH', 'R_BROWSER', 'R_BZIPCMD', 'R_CMD', 'R_COMPILED_BY', 'R_CRAN_WEB', 'R_CUSTOM_TOOLS_PATH', 'R_CUSTOM_TOOLS_SOFT', 'R_DOC_DIR', 'R_ENVIRON_USER', 'R_GSCMD', 'R_GZIPCMD', 'R_HOME', 'R_INCLUDE_DIR', 'R_INSTALL_TAR', 'R_LIBS', 'R_LIBS_SITE', 'R_LIBS_USER', 'R_MAX_NUM_DLLS', 'R_OSTYPE', 'R_PAPERSIZE', 'R_PAPERSIZE_USER', 'R_PARALLEL_PORT', 'R_RD4PDF', 'R_RTOOLS44_PATH', 'R_SCRIPT_LEGACY', 'R_SHARE_DIR', 'R_TESTS', 'R_UNZIPCMD', 'R_USER', 'R_VERSION', 'R_ZIPCMD', 'SED', 'SHLVL', 'SYSTEMDRIVE', 'SYSTEMROOT', 'TAR', 'TAR_OPTIONS', 'TEMP', 'TERM', 'TEXINPUTS', 'TMP', 'TMPDIR', 'USERDOMAIN', 'USERDOMAIN_ROAMINGPROFILE', 'USERNAME', 'USERPROFILE', 'WINDIR', '_', '_R_CHECK_AUTOCONF_', '_R_CHECK_BOGUS_RETURN_', '_R_CHECK_BROWSER_NONINTERACTIVE_', '_R_CHECK_BUILD_VIGNETTES_SEPARATELY_', '_R_CHECK_CODETOOLS_PROFILE_', '_R_CHECK_CODE_ASSIGN_TO_GLOBALENV_', '_R_CHECK_CODE_ATTACH_', '_R_CHECK_CODE_CLASS_IS_STRING_', '_R_CHECK_CODE_DATA_INTO_GLOBALENV_', '_R_CHECK_CODE_USAGE_VIA_NAMESPACES_', '_R_CHECK_CODE_USAGE_WITHOUT_LOADING_', '_R_CHECK_CODE_USAGE_WITH_ONLY_BASE_ATTACHED_', '_R_CHECK_CODOC_VARIABLES_IN_USAGES_', '_R_CHECK_COMPACT_DATA2_', '_R_CHECK_COMPILATION_FLAGS_', '_R_CHECK_CONNECTIONS_LEFT_OPEN_', '_R_CHECK_CRAN_INCOMING_', '_R_CHECK_CRAN_INCOMING_CHECK_FILE_URIS_', '_R_CHECK_CRAN_INCOMING_CHECK_URLS_IN_PARALLEL_', '_R_CHECK_CRAN_INCOMING_NOTE_GNU_MAKE_', '_R_CHECK_CRAN_INCOMING_REMOTE_', '_R_CHECK_CRAN_INCOMING_USE_ASPELL_', '_R_CHECK_DATALIST_', '_R_CHECK_DEPRECATED_DEFUNCT_', '_R_CHECK_DOC_SIZES2_', '_R_CHECK_DOT_FIRSTLIB_', '_R_CHECK_DOT_INTERNAL_', '_R_CHECK_EXAMPLE_TIMING_THRESHOLD_', '_R_CHECK_EXECUTABLES_', '_R_CHECK_EXECUTABLES_EXCLUSIONS_', '_R_CHECK_FF_CALLS_', '_R_CHECK_FF_DUP_', '_R_CHECK_FORCE_SUGGESTS_', '_R_CHECK_FUTURE_FILE_TIMESTAMPS_', '_R_CHECK_FUTURE_FILE_TIMESTAMPS_LEEWAY_', '_R_CHECK_HAVE_MYSQL_', '_R_CHECK_HAVE_ODBC_', '_R_CHECK_HAVE_PERL_', '_R_CHECK_HAVE_POSTGRES_', '_R_CHECK_INSTALL_DEPENDS_', '_R_CHECK_INTERNALS2_', '_R_CHECK_LENGTH_1_CONDITION_', '_R_CHECK_LICENSE_', '_R_CHECK_LIMIT_CORES_', '_R_CHECK_LOG_USE_INFO_', '_R_CHECK_MATRIX_DATA_', '_R_CHECK_MBCS_CONVERSION_FAILURE_', '_R_CHECK_NATIVE_ROUTINE_REGISTRATION_', '_R_CHECK_NEWS_IN_PLAIN_TEXT_', '_R_CHECK_NO_RECOMMENDED_', '_R_CHECK_NO_STOP_ON_TEST_ERROR_', '_R_CHECK_ORPHANED_', '_R_CHECK_OVERWRITE_REGISTERED_S3_METHODS_', '_R_CHECK_PACKAGES_USED_IGNORE_UNUSED_IMPORTS_', '_R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_', '_R_CHECK_PACKAGE_DATASETS_SUPPRESS_NOTES_', '_R_CHECK_PACKAGE_NAME_', '_R_CHECK_PKG_SIZES_', '_R_CHECK_PKG_SIZES_THRESHOLD_', '_R_CHECK_PRAGMAS_', '_R_CHECK_RD_EXAMPLES_T_AND_F_', '_R_CHECK_RD_LINE_WIDTHS_', '_R_CHECK_RD_MATH_RENDERING_', '_R_CHECK_RD_NOTE_LOST_BRACES_', '_R_CHECK_RD_VALIDATE_RD2HTML_', '_R_CHECK_REPLACING_IMPORTS_', '_R_CHECK_R_DEPENDS_', '_R_CHECK_S3_METHODS_SHOW_POSSIBLE_ISSUES_', '_R_CHECK_SCREEN_DEVICE_', '_R_CHECK_SERIALIZATION_', '_R_CHECK_SHLIB_OPENMP_FLAGS_', '_R_CHECK_SRC_MINUS_W_IMPLICIT_', '_R_CHECK_SUBDIRS_NOCASE_', '_R_CHECK_SUGGESTS_ONLY_', '_R_CHECK_SYSTEM_CLOCK_', '_R_CHECK_TESTS_NLINES_', '_R_CHECK_TEST_TIMING_', '_R_CHECK_TIMINGS_', '_R_CHECK_TOPLEVEL_FILES_', '_R_CHECK_UNDOC_USE_ALL_NAMES_', '_R_CHECK_UNSAFE_CALLS_', '_R_CHECK_URLS_SHOW_301_STATUS_', '_R_CHECK_VC_DIRS_', '_R_CHECK_VIGNETTES_NLINES_', '_R_CHECK_VIGNETTES_SKIP_RUN_MAYBE_', '_R_CHECK_VIGNETTE_TIMING_', '_R_CHECK_VIGNETTE_TITLES_', '_R_CHECK_WINDOWS_DEVICE_', '_R_CHECK_XREFS_NOTE_MISSING_PACKAGE_ANCHORS_', '_R_CHECK_XREFS_USE_ALIASES_FROM_CRAN_', '_R_CLASS_MATRIX_ARRAY_', '_R_DEPRECATED_IS_R_', '_R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_', '_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_', '_R_USE_STRICT_R_HEADERS_', '__R_CHECK_DOC_FILES_NOTE_IF_ALL_SPECIAL__', 'maj.version', 'nextArg--timingsnextArg--install' - Environment variables still there: [n=0] - Environment variables missing: [n=1] 'MAKEFLAGS' Differences environment variable by environment variable: List of 3 $ name : chr "MAKEFLAGS" $ expected: 'Dlist' chr "" $ actual : 'Dlist' chr NA > > proc.time() user system elapsed 1.78 0.25 3.18