Another julia riddle - parallel processes

question

#1

I have a module which starts a long running cycle of computation.

How do I send it to another process , if I don’t want to define the process beforehand.
I am looking for a way to dynamically add processes.

something along the lines of:

module temp

function f(t,par = false)
    if par
        new_proc = addprocs(1)[1]
        remotecall_fetch(f,new_proc,t,false)
        rmprocs(new_proc)
    else
        print("hello process $(myid())")
        sleep(t)
    end
end

end

of course this doesn’t work , what is the right way to do it?


#2

found a somewhat hairy solution:

module temp

function f(t,par = false)
    if par
        new_proc = addprocs(1)[1]
        eval(Main,quote
             remotecall_fetch(x->Base.require(x),$new_proc,:temp) 
        end)
        remotecall_fetch(f,new_proc,t,false)
        rmprocs(new_proc)
    else
        print("hello process $(myid())")
        sleep(t)
    end
end

end