提升::MPI 1.53 就位all_reduce

boost::mpi 1.53 in place all_reduce

本文关键字:all reduce 就位 MPI 提升      更新时间:2023-10-16

如何就地使用 1.53 boost::mpi减少?(这是 CentOS 7 的版本(

Boost 1.61 有 boost::mpi::inplace_t (doc(,但 boost 1.53 没有 (doc(。

对于 1.61,我可以使用:

boost::mpi::all_reduce(
    comm, 
    boost::mpi::inplace_t<int*>(ptr_int_array), 
    n_elements, 
    op);

如果您不想有额外的out_value字段,您可以通过设置为返回函数的值来覆盖in_value

#include <boost/mpi.hpp>
int main()
{
    boost::mpi::environment env;
    boost::mpi::communicator comm;    
    // set in_value to whatever you want.
    int in_value = comm.rank() 
    // overwrite.
    in_value = all_reduce(comm, in_value, std::plus<double>());   
    return 0;
}