logo

How to Parallel Process in Julia 📂Julia

How to Parallel Process in Julia

Code

While the original sushi restaurant with fresh shrimp includes detailed explanations, Julia wants to omit explanations on purpose to emphasize how easy it is to do parallel processing.

using Base.Threads

for i in 1:10
    println(i^2)
end

If you want to parallelize the above loop, you just need to prepend @threads to the for loop.

@threads for i in 1:10
    println(i^2)
end

However, if I must add one piece of advice, it is that not everything gets faster with parallel processing. Proper use of parallel processing can yield very high performance, but just because it’s easier to write code doesn’t mean optimization is easy as well. Take your time to measure and pay attention to the execution time.

Environment

  • OS: Windows
  • julia: v1.5.0