4

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?

1 Answer 1

4

@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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.