Can I use `pmap` on a recursive program?

Can I use pmap on a recursive program? Take the following recursive function as an example:

using Distributed
addprocs(3)
function mymax(x)
    n = length(x)
    if n == 1
        x[1]
    else
        y = pmap(mymax, [x[1:Int(floor(n/2))], x[Int(floor(n/2))+1:end]])
        maximum(y)
    end
end
mymax(rand(10))

image

Since the myfun function acts independently on each branch, I want the system to coordinate multiple processes to compute them in a distributed way. Can I? And how?


@everywhere function mymax(x)
    n = length(x)
    if n == 1
        x[1]
    else
        y = fetch.(map([x[1:Int(floor(n/2))], x[Int(floor(n/2))+1:end]]) do z
            @spawnat :any @show mymax(z)
        end)
        maximum(y)
    end
end
mymax(rand(10))