futureverse / parallelly

R package: parallelly - Enhancing the 'parallel' Package
https://parallelly.futureverse.org
130 stars 7 forks source link

is the parallele result orderly #88

Closed asmlgkj closed 2 years ago

asmlgkj commented 2 years ago

Thanks a lot. is the result of parallelly orderly?

HenrikBengtsson commented 2 years ago

Hi. Exactly what is the question? I'm not sure I understand

asmlgkj commented 2 years ago

thanks a lot, for example, many files as input, and deal with parallely, will it return as input order?

HenrikBengtsson commented 2 years ago

I see.

The parallelly package itself does not have any, so called, map-reduce function. It is used to create a cluster of parallel workers, which then can take on tasks.

Sending tasks to the parallel workers can be done by, for instance, parLapply() of the parallel package. y <- parLapply(x, ...), just like y <- lapply(x, ...), guarantees to return the results in the same order as the input (x). This is true for all map-reduce functions I'm aware of, e.g. mclapply() of the parallel package, future_lapply() of the future.apply package, map() of the purrr package, future_map() of the furrr package, y <- foreach(...) %dopar% { ... } of the foreach package, bplapply() of the Bioconductor package, pblapply() of the pbapply package, and so on. So, you can count on getting the results in the same order as your input when you use map-reduce functions in R.

PS. It is of course possible to create functions that does not respect the input order, but I'm not aware of anyone on CRAN or Bioconductor. I think this is, because they would not be very useful.

asmlgkj commented 2 years ago

Thank you very much for your professional answer, you not only answered my question, but also expanded on it, you are a very nice person, so to summarize, as you said, all results are in the same order of output as the input, right?

HenrikBengtsson commented 2 years ago

Correct. Your welcome