#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/collectives.hpp>
namespace mpi = boost::mpi;
#include <iostream>
#include <algorithm>
int main()
{
mpi::environment env;
mpi::communicator world;
{
int a=1;
int s = mpi::all_reduce(world,a,std::plus<int>()); // ok
std::vector<int> v{1,2,3};
int s2 = std::accumulate(v.begin(),v.end(),0,std::plus<int>()); // ok
}
{
int a=1;
//int s = mpi::all_reduce(world,a,[](int x,int y){return x+y;}); // error: deleted default constructor for lambdas
std::vector<int> v{1,2,3};
int s2 = std::accumulate(v.begin(),v.end(),0,[](int x,int y){return x+y;}); // ok
}
return 0;
}
In the standard library lambdas can be used for reduction operations in
std::accumulate.Is there any reason why
boost::mpi::all_reducedoes not accept lambda functions as custom reduction operation?Example: