Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: @async and multiple CPU cores/threads

Suppose I'm running an expensive computation in the background with @async. Will this computation be performed on the same thread the Julia runtime is running on (i.e. on the same CPU core)? If yes, will I have to then start Julia like julia --threads 2 and use Base.Threads?

like image 641
mwk Avatar asked Oct 28 '25 04:10

mwk


1 Answers

@async spawns a green thread coroutine. They will be all spawned in the same system thread and hence are good for types of parallelism where you are waiting for external resources (IO, remote jobs) it is not good for things such as parallelizing your numerical computations (unless they are done on remote workers).

Basically, in Julia you have the following parallelism types:

  • @simd - utilize Single instruction, multiple data (SIMD) feature of a CPU
  • @async - coroutines
  • @threads - multithreading, requires seting JULIA_NUM_THREADS environment variable
  • @distributed - multiprocessing on a single or multiple machines
  • GPU computing - start this journey with CUDA.jl

You can find several more detailed examples on StackOverflow for each topic above.

like image 61
Przemyslaw Szufel Avatar answered Oct 30 '25 22:10

Przemyslaw Szufel