Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce with Lambdas #128

Open
Lagrang3 opened this issue Jan 22, 2021 · 7 comments
Open

Reduce with Lambdas #128

Lagrang3 opened this issue Jan 22, 2021 · 7 comments

Comments

@Lagrang3
Copy link

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;
}
@aminiussi
Copy link
Member

The choice was made to remain "old school" to accommodate older compilers.

It's a choice that could be discussed tough.

@Lagrang3
Copy link
Author

The choice was made to remain "old school" to accommodate older compilers.

That's a pity.

@aminiussi
Copy link
Member

aminiussi commented Jan 22, 2021 via email

@Lagrang3
Copy link
Author

Lagrang3 commented Jan 22, 2021

@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?

@aminiussi
Copy link
Member

@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).

@Lagrang3
Copy link
Author

Can we keep this open as an improvement proposal? I would like to implement this sometime.

@aminiussi
Copy link
Member

There is now a cmake build available, ad I copied al the bjam tests into ctest tests.

It's available on develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants