futureverse / futureverse/future

[Feature request] function that tells what is the current strategy

Open
#625 5 comments 0 reactions 1 assignee Claimed by @HenrikBengtsson View on GitHub
feature request feature/resources question
Dominant language
R
Stars
1k
Forks
92
PR merge metrics
No merged PRs in 30d

Description

Let define a simplified function in a package that looks like that:

```r
pkg_fun <- function(fun, x) {
f <- vector("list", length(x))
for (i in seq_along(x)) {
f[[i]] <- future::future({ fun(x) })
}

# some code to handle resolution and get values of futures...
}
```

Users can use it like that

```r
library(pkg)
library(future)
plan(multisession)
pkg_fun(myfunction, mydata)
```

There is no way for the developer to know what is the plan used by the user. It is sequential? multicore on a single machine? multiple remote machine? I do agree that most of the time the developer do no need to know. But I'm personally facing multiple cases were I need to know to handle stuff internally or to throw informative warning or error. For examples:

1. `myfunction` may already be parallelized in C++ with OpenMP. Testing the strategy allows to enable or disable OpenMP and avoid nested parallelism
2. `mydata` can contain non serializable objects and the code subsequently fails with no informative error for parallel strategies (but works with `plan(sequential)`). Being able to catch those cases early would allow to handle them nicely.
3. `myfunction` can return non serializable objects. Same issue than 2.

So far I'm using a [custom parser](https://github.com/r-lidar/lidR/blob/master/R/utils_threads.R#L87) than analyses the ouptut of `future::plan()` but I think it would be a useful addition to add easy to parse functions for developpers in `future`. Something like that maybe

```r
future::is_parallel_strategy()
future::get_strategy_workers()
future::is_remote_stragety()
future::is_nested_strategy()
# ...
```

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.