JuliaParallel / Dagger.jl

A framework for out-of-core and parallel execution
Other
621 stars 67 forks source link

Can `Dagger.@spawn` be used instead of `@async`? #477

Closed schlichtanders closed 5 months ago

schlichtanders commented 5 months ago

The current documentation of @aync includes this warning

Warning

It is strongly encouraged to favor Threads.@spawn over @async always even when no parallelism is required especially in publicly distributed libraries. This is because a use of @async disables the migration of the parent task across worker threads in the current implementation of Julia. Thus, seemingly innocent use of @async in a library function can have a large impact on the performance of very different parts of user applications.

Hence a natural question is whether Dagger.@spawn can also be used as a better alternative of @async. This would be so cool, as the whole concurrence interface would be unified.

If this indeed works, it would be great to have this somewhere obvious in the documentation.

jpsamaroo commented 5 months ago

In certain cases, yes, you can use Dagger.@spawn like either Threads.@spawn and @async, as it can express a function executed asynchronously either on the same thread, or a different one. However, the exact semantics differ in significant ways. Some of those differences are: