mpi
mpi copied to clipboard
Reduce with Lambdas
In the standard library lambdas can be used for reduction operations in std::accumulate
.
Is there any reason why boost::mpi::all_reduce
does not accept lambda functions as custom reduction operation?
Example:
#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;
}
The choice was made to remain "old school" to accommodate older compilers.
It's a choice that could be discussed tough.
The choice was made to remain "old school" to accommodate older compilers.
That's a pity.
Yes.
Alain Miniussi DSI, Pôles Calcul et Genie Log. Observatoire de la Côte d'Azur Tél. : +33492003009 (Mont-Gros) +33483618544 (Sophia Antipolis) +33609650665
----- On 22 Jan 21, at 15:35, Eduardo Quintana [email protected] wrote:
The choice was made to remain "old school" to accommodate older compilers. That's a pity.
— You are receiving this because you commented. Reply to this email directly, [ https://github.com/boostorg/mpi/issues/128#issuecomment-765443912 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/AAEGZDGSVF27VWZG32GVEU3S3GEMPANCNFSM4WORRK7Q | unsubscribe ] .
@aminiussi How do you test changes in the repository? There's no makefile nor anything like it.
I mean is there an automatic way to get your new changes immediately on you custom boost install.
Or do you just copy everything from include
into boost_<version>/boost/mpi
and the rest into boost_<version>/libs/mpi
and then run the bootstraph.sh
?
@Lagrang3 I don't do that very often but yes, I do a bootstrap.sh (either with the --prefix option or I edit the bottom of the project bjam config, as the mpi section and python section usually need some manual editing) and then I call the ./b2 install (and the b2 test, although I usually go into the ./lib/mpi/tests directory and run ../../../b2 from there).
Can we keep this open as an improvement proposal? I would like to implement this sometime.
There is now a cmake build available, ad I copied al the bjam tests into ctest tests.
It's available on develop.