Skip to content
Snippets Groups Projects
Commit 0ce22beb authored by Christian Engwer's avatar Christian Engwer
Browse files

[!721] fix ctor for Future<void>

Merge branch 'fix_future_of_void' into 'master'

ref:core/dune-common There was a problem with a ctor of Future<void>. This MR
disables the ctor if T is void. Furthermore i changed the autos in the
mpifuturetest.cc to Futures to check for this.

See merge request [!721]

  [!721]: gitlab.dune-project.org/core/dune-common/merge_requests/721
parents 9f3936bf 23f65e57
No related branches found
No related tags found
1 merge request!721fix ctor for Future<void>
Pipeline #23024 passed
......@@ -72,8 +72,9 @@ namespace Dune{
: _future(std::make_unique<FutureModel<F>>(std::forward<F>(f)))
{}
Future(T&& data)
: _future(std::make_unique<FutureModel<PseudoFuture<T>>>(PseudoFuture<T>(std::forward<T>(data))))
template<class U, std::enable_if_t<std::is_same<U,T>::value && !std::is_same<T,void>::value>>
Future(U&& data)
: _future(std::make_unique<FutureModel<PseudoFuture<T>>>(PseudoFuture<T>(std::forward<U>(data))))
{}
Future() = default;
......
......@@ -13,16 +13,16 @@ int main(int argc, char** argv){
// p2p
if(mpihelper.size() > 1){
if(mpihelper.rank() == 0){
auto f = cc.isend(42, 1, 0);
Dune::Future<int> f = cc.isend(42, 1, 0);
f.wait();
int i = 42;
auto f2 = cc.isend<const int&>(i, 1, 0);
Dune::Future<const int&> f2 = cc.isend<const int&>(i, 1, 0);
f2.wait();
}else if(mpihelper.rank() == 1){
auto f = cc.irecv(41, 0, 0);
Dune::Future<int> f = cc.irecv(41, 0, 0);
std::cout << "Rank 1 received " << f.get() << std::endl;
int j = 41;
auto f2 = cc.irecv<int&>(j, 0, 0);
Dune::Future<int&> f2 = cc.irecv<int&>(j, 0, 0);
std::cout << "Rank 1 received " << f2.get() << std::endl;
}
}
......@@ -32,12 +32,12 @@ int main(int argc, char** argv){
std::cout << "Broadcast lvalue-reference" << std::endl;
answer = 42;
}
auto f = cc.template ibroadcast(answer, 0);
Dune::Future<int> f = cc.template ibroadcast(answer, 0);
f.wait();
std::cout << "Rank " << mpihelper.rank() << " knows: The answer is " << answer << std::endl;
if(mpihelper.rank() == 0)
std::cout << "Broadcast value" << std::endl;
auto f2 = cc.template ibroadcast(int(answer), 0);
Dune::Future<int> f2 = cc.template ibroadcast(int(answer), 0);
std::cout << "Rank " << mpihelper.rank() << " knows: The answer is " << f2.get() << std::endl;
Dune::DynamicVector<double> vec(3);
......@@ -45,18 +45,18 @@ int main(int argc, char** argv){
std::cout << "Broadcast vector" << std::endl;
std::iota(vec.begin(), vec.end(), 41);
}
auto f3 = cc.ibroadcast(vec, 0);
Dune::Future<Dune::DynamicVector<double>> f3 = cc.ibroadcast(vec, 0);
f3.wait();
std::cout << "Rank " << mpihelper.rank() << " received vector: " << vec << std::endl;
if(mpihelper.rank() == 0)
std::cout << "nonb Barrier ==========================" << std::endl;
auto f4 = cc.ibarrier();
Dune::Future<void> f4 = cc.ibarrier();
f4.wait();
if(mpihelper.rank() == 0){
std::cout << "nonb gather ===========================" << std::endl;
auto f = cc.igather(mpihelper.rank() + 42, Dune::DynamicVector<int>(mpihelper.size()), 0);
Dune::Future<Dune::DynamicVector<int>> f = cc.igather(mpihelper.rank() + 42, Dune::DynamicVector<int>(mpihelper.size()), 0);
std::cout << "Gather result: " << f.get() << std::endl;
}else{
cc.igather(mpihelper.rank(), {}, 0).wait();
......@@ -66,24 +66,24 @@ int main(int argc, char** argv){
std::cout << "nonb scatter ===========================" << std::endl;
std::vector<int> my_buddies(mpihelper.size());
std::iota(my_buddies.begin(), my_buddies.end(), 42);
auto f = cc.iscatter(my_buddies, 0, 0);
Dune::Future<int> f = cc.iscatter(my_buddies, 0, 0);
std::cout << "Scatter result (Rank " << mpihelper.rank() << "): " << f.get() << std::endl;
}else{
auto f = cc.iscatter(std::vector<int>(0), 0, 0);
Dune::Future<int> f = cc.iscatter(std::vector<int>(0), 0, 0);
std::cout << "Scatter result (Rank " << mpihelper.rank() << "): " << f.get() << std::endl;
}
{
if(mpihelper.rank() == 0)
std::cout << "nonb allreduce ===========================" << std::endl;
auto f = cc.iallreduce<std::plus<int>>(mpihelper.rank()+4, 0);
Dune::Future<int> f = cc.iallreduce<std::plus<int>>(mpihelper.rank()+4, 0);
std::cout << "Allreduce result on rank " << mpihelper.rank() <<": " << f.get() << std::endl;
}
{
if(mpihelper.rank() == 0)
std::cout << "nonb allreduce inplace ===========================" << std::endl;
auto f = cc.iallreduce<std::plus<int>>(Dune::DynamicVector<int>{42, 3+mpihelper.rank()});
Dune::Future<Dune::DynamicVector<int>> f = cc.iallreduce<std::plus<int>>(Dune::DynamicVector<int>{42, 3+mpihelper.rank()});
std::cout << "Allreduce result on rank " << mpihelper.rank() <<": " << f.get() << std::endl;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment