Fred
1
Hi !
In Julia 0.5 it is possible to parallelize a function in a loop :
@parallel (+) for i=1:100
Threads.@threads for i = 1:10
or to apply a function to all elements in some collection :
pmap(f, c)
But is it possible to execute independent functions in parallel outside a loop, like goroutines in golang for example?
go func1(x, channel1)
go func2(y, channel2)
Thank you very much for your comments !
2 Likes
Muninn
2
Yep! Have a look at @spawn and @spawnat which you can find more information about here: http://docs.julialang.org/en/release-0.5/stdlib/parallel/#Base.@spawn
If you have multiple processes running for Julia you can do
func1_future = @spawn func1(x, channel1)
func2_future = @spawn func2(y, channel2)
These return a Future so to get the return value you need to do a fetch which blocks until the value is ready like so
func1_result = fetch(func1_future)
func2_result = fetch(func2_future)
You can find information about fetch here: http://docs.julialang.org/en/release-0.5/stdlib/parallel/#Base.fetch
And some general information on parallelism in Julia can be found here: http://docs.julialang.org/en/release-0.5/manual/parallel-computing/
3 Likes
Fred
3
@Muninn Great ! I will try that ! Thank you very much !