Merging arrays from all ranks using MPI -
i have array of same length on ranks (lets assume 10). values in array contain rank of processor. example ...
proc 1: [1 0 0 0 0 1 0 0 0 1] proc 2: [0 2 2 0 0 0 0 2 2 0] proc 3: [0 0 0 3 3 0 3 0 0 0] now efficient way (using mpi-2) processors end following array
[1 2 2 3 3 1 3 2 2 1] which can thought of sum of arrays (distributed on ranks). performance important want fast on 1k+ cores.
this doable mpi_allreduce() mpi_sum or mpi_max operator. see documentation of mpi_allreduce. supposed implemented in 1 of best possible ways given architecture.
int arr_a[len], arr_b[len]; ... // fill in arr_a mpi_allreduce(arr_a, arr_b, len, mpi_int, mpi_sum, mpi_comm_world); // result in arr_b or if short on memory use in-place operation hurt performance:
mpi_allreduce(mpi_in_place, arr_a, len, mpi_int, mpi_sum, mpi_comm_world);
Comments
Post a Comment