Replies: 3 comments
-
For use on a single machine, you want to avoid these nested hierarchies. A single set of 5 daemons would be optimal in your example, rather than splitting them into 2 levels. Either run the inner loop sequentially, or the outer loop. You don't gain anything from doing a nested map, you only add the coordination overhead of running more things than necessary in parallel. |
Beta Was this translation helpful? Give feedback.
-
Makes sense. Is there a way to still have the nested mirai_maps but reuse the same daemons or is this addressed by #268 or not possible? |
Beta Was this translation helpful? Give feedback.
-
It's not possible to have everything use the same daemons, as this can easily lead to deadlock. E.g. 4 daemons launch 4 mirai tasks. Each of those then tries to launch 4 mirai tasks. All daemons are already busy at this point, so none of the tasks from the daemons get done, and those daemons keep on waiting. The best case would be for #268, but even there it's more for multiple applications on the computer sharing the same resources, e.g. if you have multiple Shiny or Plumber apps on the same server. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a package A that internally uses
mirai_map()
in functioninner_loop
.The problem is that this function might or might not be wrapped in another
mirai_map()
call by the user. That is, I need to structure my code that it works in three cases: 1) the user did not specify daemons, 2) the user called daemons, 3) the user usedmirai_map()
to call the function in parallel.1 and 2 are working, but the nested mirai_maps calls I cannot get to work.
https://mirai.r-lib.org/articles/v01-map.html#nested-maps mentions that including a call to
daemons()
in the function provided to the outer map should work, but it does not work for me.So besides a solution here, maybe it would be great to have a working sample in the vignettes (happy to write something up if I have a solution).
A simple MWE would be the following.
Ideally, I would like to use the existing daemons, eg. I set up 5 daemons, but the outer loop only utilizes 3 so the other daemons + the idle cores of the 3 could be used by the inner loop.
Beta Was this translation helpful? Give feedback.
All reactions