Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 617
valware_xyz Avatar asked Jan 27 '26 11:01

valware_xyz


1 Answers

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

like image 104
Fredrik Bagge Avatar answered Jan 29 '26 02:01

Fredrik Bagge