Search code examples
rparallel-processingtidyversepurrr

Parallel version of `map()`


I have a function that takes multiple arguments.

my_function <- function(list_of_vectors, list_of_scalars){
 ....
return(list)
}

I want to use map() over my function but using a parallel call that would use multicores. my_function() is very computationally expensive, and I need to call it to create output for over 1000 points. ( list_of_vectors is a list of 1000 vectors and list_of_scalars is a list of 1000 scalars)

Is there a mcmap() equivalent or any other formulation ? I had a look at other threads but none solved my issue.


Solution

  • You can use future_map() from the furrr package as a drop-in replacement.

    This is a very flexible function; how it distributes your computation will depend on a previous call to future::plan() (furrr is built on top of the future package), e.g.

    future::plan(multicore, workers = 4)
    future_map(...)
    

    to run your job on 4 cores on the same machine.