Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return and args #20

Open
mloubout opened this issue Jun 15, 2020 · 3 comments
Open

Return and args #20

mloubout opened this issue Jun 15, 2020 · 3 comments

Comments

@mloubout
Copy link

mloubout commented Jun 15, 2020

I don't know if I missed somethign but I can't seem to fund a way to return value for the " only workers execute MPI code" mode. While the example seemed exciting, I can't seem to find a way to do a simple (pseudo code)

function do_stuff(args)
        manager=MPIManager(np=np)
        workers = addprocs(manager)
        @mpi_do manager begin
             result = do_mpi_stuff($args)
             result = gather_on_root(results)
             if comm is root
                  return result
            end
       end
end

myresult = do_stuff(a,b,c)

which makes it a bit useless since I can't get a result back.

@aitzkora
Copy link

May be modyfing a little bit the function mpi_do for returning the args, will do the job

function mpi_callfetch(mgr::MPIManager, expr)
    !mgr.initialized && wait(mgr.cond_initialized)
    jpids = keys(mgr.j2mpi)
    refs = Array{Any}(undef, length(jpids))
    for (i,p) in enumerate(Iterators.filter(x -> x != myid(), jpids))
        refs[i] = remotecall(expr, p)
    end
    # Execution on local process should be last, since it can block the main
    # event loop
    if myid() in jpids
        refs[end] = remotecall(expr, myid())
    end

    # Retrieve remote exceptions if any
    @sync begin
        for r in refs
            @async begin
                resp = remotecall_fetch(r.where, r) do rr
                    wrkr_result = rr[]
                end
                isa(resp, Exception) && throw(resp)
            end
        end
    end
    wrkr_result
end

When I have time, I will fork to test that solution. it is a copy-paste of mpi_do function where we do not filter the remote_callfetch results. Authors of the package say that @mpi_do is not a mpi_callfetch (it is logical, "do" in the name explicits it is a void function),
so I agree with you that it would be nice to have such macros in that package...

@mloubout
Copy link
Author

I ended up making an mpicall_fetch locally indeed. I had to bypass kill as well that doesn't play well with my code in a may that is not reliable for this package (I had to remove the MPI.Finilazie() because it's called already by some other code).
I may PR the mpicall_fetch here to make it cleaner.
Thanks for your response.

@aitzkora
Copy link

Nice ! I hope authors will accept your PR. I'm currently writing a poster for Julia Con advocating for @mpi_do, but having also a @mpicall_fetch would be great.
Bests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants