Search code examples
multithreadingparallel-processingjuliadistributed-computing

Calculate multiple values in parallel


I have a function, xEuclid, for the extended euclidean algorithm, and I want to calculate 3 values using that function, being these values a = xEuclid(a1,b1), b = xEuclid(a2,b2) and c = xEuclid(a3,b3), using different parameters each call, so the idea to optimize the proces is to calculate a, b and c at the same time, in parallel.

I can't figure a way to solve it and unfortunately don't have the time to do the JuliaAcademy Parallel Programming tutorial, so please I need your help to solve it. Thank you!


Solution

  • Try the following

    using Base.Threads: @spawn
    a = @spawn xEuclid(a1,b1)
    b = @spawn xEuclid(a2,b2)
    c = @spawn xEuclid(a3,b3)
    a = fetch(a); b = fetch(b); c = fetch(c)
    

    This requires at least julia v1.3