HenrikBengtsson / doFuture

:rocket: R package: doFuture - Use Foreach to Parallelize via Future Framework
https://doFuture.futureverse.org
84 stars 6 forks source link

WISH: Add support for `.verbose = TRUE`, which is currently ignored #80

Open HenrikBengtsson opened 9 months ago

HenrikBengtsson commented 9 months ago

(Created from Issue #76)

From help("foreach", package = "foreach"):

.verbose: logical flag enabling verbose messages. This can be very useful for trouble shooting.

Foreach adapters doMC, doMPI, doParallel, doRedis, doRNG, and legacy doSNOW all support it one way or the other.

Currently, the doFuture package completely ignores the .verbose argument. There's logical R option doFuture.debug, which can be used to output debugging information.

Given that the other doNNN packages support .verbose, users probably expect doFuture to also support .verbose = TRUE. Because of this, we should add verbose output to the same level/detail as the other packages.

HenrikBengtsson commented 9 months ago

Here's what the different *doNNN** package outputs with .verbose = TRUE:

doSNOW

cat(sprintf('bundling all tasks into %d chunks\n', length(cl)))
cat("attaching export environment\n")

cat("progress will be called as each result is returned\n")

cat(sprintf('discovered package(s): %s\n', paste(packages, collapse=', ')))
cat('automatically exporting the following variables', 'from the local environment:\n'); cat(' ', paste(vars, collapse=', '), '\n')
cat('no variables are automatically exported\n')
cat(sprintf('explicitly exporting variables(s): %s\n', paste(export, collapse=', ')))
cat(sprintf('explicitly exporting package(s): %s\n', paste(packages, collapse=', ')))

doParallel

cat(sprintf('setting mc.preschedule option to %d\n', options$preschedule))
cat(sprintf('setting mc.set.seed option to %d\n', options$set.seed))
cat(sprintf('bundling all tasks into %d chunks\n', length(cl)))
cat("attaching export environment\n")
cat(sprintf('discovered package(s): %s\n', paste(packages, collapse=', ')))
cat('automatically exporting the following variables', 'from the local environment:\n'); cat(' ', paste(vars, collapse=', '), '\n')
cat('no variables are automatically exported\n')
cat(sprintf('explicitly exporting variables(s): %s\n', paste(export, collapse=', ')))
cat(sprintf('explicitly exporting package(s): %s\n', paste(packages, collapse=', ')))

doMC

cat(sprintf('setting mc.preschedule option to %d\n', options$preschedule))
cat(sprintf('setting mc.set.seed option to %d\n', options$set.seed))
cat(sprintf('setting mc.silent option to %d\n', options$silent))
cat(sprintf('setting mc.cores option to %d\n', options$cores))

doMPI

cat(sprintf('setting chunkSize option to %d\n', options$chunkSize))
cat(sprintf('setting info option to %s\n', options$info))
cat('setting initEnvir option to:\n'); print(options$initEnvir)
cat('setting initArgs option to:\n'); print(options$initArgs)
cat('setting initEnvirMaster option to:\n'); print(options$initEnvirMaster)
cat('setting initArgsMaster option to:\n'); print(options$initArgsMaster)
cat('setting finalEnvir option to:\n'); print(options$finalEnvir)
cat('setting finalArgs option to:\n'); print(options$finalArgs)
cat(sprintf('setting profile option to %s\n', options$profile))
cat(sprintf('setting bcastThreshold option to %d\n', options$bcastThreshold))
cat(sprintf('setting forcePiggyback option to %s\n', options$forcePiggyback))
cat(sprintf('setting nocompile option to %s\n', options$nocompile))
cat(sprintf('setting seed option to %s\n', options$seed))

doRedis

cat('automatically exporting the following variables', 'from the local environment:\n'); cat(' ', paste(vars, collapse=', '), '\n')
message("Submitting task(s) ", j, ":", k)
cat(sprintf('explicitly exporting variables(s): %s\n', paste(export, collapse=', ')))
cat("no objects are automatically exported\n")

Above, message() is an outlier; reported at https://github.com/bwlewis/doRedis/issues/62.

doRNG

message("NOTE -- .Random.seed is not initialized: sampling once to ensure reproducibility.")
message("* Registered backend: ", .getDoParName(version = TRUE))
message("* Registering computing backend: ", .getDoParName(rngBackend$data$backend, version = TRUE))
message("* Restoring previous backend: ", .getDoParName(rngBackend))
message("* Detected known RNG side effect: ", dp)
message("* Restoring RNG as after RNG sequence generation")
message("OK")

In addition, doRNG forwards .verbose = TRUE do the registered foreach backend used next.

Note also how doRNG outputs a message condition, whereas the other doNNN packages outputs directly to stdout.