Is there a MPI-based map package?

Is there such a package providing a function like?

function mpi_map(Function, Array, MPI_COMM),

which bechaviours like

result=map(some_input_array, comm) do x
    some_operation(x)
done

I wrote one myself based on send/recv. A manager process listens to all worker process and assign jobs. However, which is very specified only to some certain problems. Is there package that provides more general ones?

This is my own implementation.

Not exactly what you want, but there’s MPICLusterManagers.jl that has @mpi_do that does eg.:

@mpi_do manager begin
  using MPI
  comm=MPI.COMM_WORLD
  println("Hello world, I am $(MPI.Comm_rank(comm)) of $(MPI.Comm_size(comm))")
end

In this case the code is executed only on the workers. Perhaps this might be used for communications?

MPIClusterManagers.jl has more than that, I think it has exactly what OP is asking for, you just need to use Distributed.pmap, e.g:

julia> using MPI, MPIClusterManagers, Distributed

julia> addprocs(MPIManager(np=4))

julia> result = pmap(1:10) do x
           MPI.Comm_rank(MPI.COMM_WORLD)
       end
10-element Array{Int64,1}:
 0
 1
 3
 2
 3
 0
 1
 2
 3
 0

Note you can also use the MPIClusterManagers.start_main_loop way of initializing MPI which lets you use mpiexec -n with a script.

3 Likes