Parallel execution of functions outside a loop is possible in Julia?



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 !


Yep! Have a look at @spawn and @spawnat which you can find more information about here:

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:

And some general information on parallelism in Julia can be found here:


@Muninn Great ! I will try that ! Thank you very much !