Skip to content

Commit

Permalink
Adapt broadcast() to non-unwrapping async<Action>
Browse files Browse the repository at this point in the history
This fixes #2885
  • Loading branch information
hkaiser committed Sep 7, 2017
1 parent 3542836 commit 67af823
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hpx/lcos/broadcast.hpp
Expand Up @@ -506,7 +506,9 @@ namespace hpx { namespace lcos
std::vector<Result>
wrap_into_vector(hpx::future<Result> r)
{
return std::vector<Result>(1, r.get());
std::vector<Result> result;
result.push_back(r.get());
return result;
}

template <
Expand Down
2 changes: 2 additions & 0 deletions tests/regressions/lcos/CMakeLists.txt
Expand Up @@ -11,6 +11,7 @@ set(tests
async_callback_non_deduced_context
async_unwrap_1037
barrier_hang
broadcast_unwrap_future_2885
broadcast_wait_for_2822
call_promise_get_gid_more_than_once
channel_register_as_2722
Expand Down Expand Up @@ -60,6 +61,7 @@ set(after_588_PARAMETERS LOCALITIES 2)
set(async_action_1813_PARAMETERS LOCALITIES 2)
set(async_callback_with_bound_callback_PARAMETERS LOCALITIES 2)
set(async_callback_non_deduced_context_PARAMETERS THREADS_PER_LOCALITY 4)
set(broadcast_unwrap_future_2885_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 4)
set(broadcast_wait_for_2822_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 4)
set(future_hang_on_get_629_PARAMETERS LOCALITIES 2 THREADS_PER_LOCALITY 2)
set(dataflow_future_swap2_FLAGS DEPENDENCIES iostreams_component)
Expand Down
54 changes: 54 additions & 0 deletions tests/regressions/lcos/broadcast_unwrap_future_2885.cpp
@@ -0,0 +1,54 @@
// Copyright (c) 2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_init.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/lcos/broadcast.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <vector>

hpx::future<void> bcast_void(double bcast)
{
return hpx::make_ready_future();
}

HPX_PLAIN_ACTION(bcast_void);

HPX_REGISTER_BROADCAST_ACTION_DECLARATION(bcast_void_action)
HPX_REGISTER_BROADCAST_ACTION(bcast_void_action)

hpx::future<double> bcast(double bcast)
{
return hpx::make_ready_future(bcast);
}

HPX_PLAIN_ACTION(bcast);

HPX_REGISTER_BROADCAST_ACTION_DECLARATION(bcast_action)
HPX_REGISTER_BROADCAST_ACTION(bcast_action)

int hpx_main()
{
std::vector<hpx::id_type> localities = hpx::find_all_localities();

auto f1 = hpx::lcos::broadcast<bcast_void_action>(localities, 42.0);
f1.get();

auto f2 = hpx::lcos::broadcast<bcast_action>(localities, 42.0);
for (hpx::future<double>& f : f2.get())
{
HPX_TEST_EQ(42.0, f.get());
}

return hpx::finalize();
}

int main(int argc, char* argv[])
{
HPX_TEST_EQ(hpx::init(argc, argv), 0);
return hpx::util::report_errors();
}

0 comments on commit 67af823

Please sign in to comment.