本文整理汇总了C++中hpx::async方法的典型用法代码示例。如果您正苦于以下问题:C++ hpx::async方法的具体用法?C++ hpx::async怎么用?C++ hpx::async使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hpx
的用法示例。
在下文中一共展示了hpx::async方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: plain_deferred_arguments
void plain_deferred_arguments()
{
void_f4_count.store(0);
int_f4_count.store(0);
{
future<void> f1 = dataflow(hpx::launch::deferred, &void_f4, 42);
future<int> f2 = dataflow(hpx::launch::deferred, &int_f4, 42);
f1.wait();
HPX_TEST_EQ(void_f4_count, 1u);
HPX_TEST_EQ(f2.get(), 84);
HPX_TEST_EQ(int_f4_count, 1u);
}
void_f5_count.store(0);
int_f5_count.store(0);
{
future<void> f1 = dataflow(&void_f5, 42, async(hpx::launch::deferred, &int_f));
future<int> f2 = dataflow(&int_f5, 42, async(hpx::launch::deferred, &int_f));
f1.wait();
HPX_TEST_EQ(void_f5_count, 1u);
HPX_TEST_EQ(f2.get(), 126);
HPX_TEST_EQ(int_f5_count, 1u);
}
}
示例2: rec_mult
block rec_mult(block A, block B, block C) {
if(C.width <= blocksize || C.height <= blocksize ) {
return serial_mult(A, B, C);
}
future<block> C11 = async(calc_c11, A, B, C);
future<block> C12 = async(calc_c12, A, B, C);
future<block> C21 = async(calc_c21, A, B, C);
future<block> C22 = async(calc_c22, A, B, C);
C11.wait();
C12.wait();
C21.wait();
C22.wait();
/*
auto f_A = make_ready_future(A);
auto f_B = make_ready_future(B);
auto f_C = make_ready_future(C);
future<block> C11 = dataflow(unwrapped(calc_c11), f_A, f_B, f_C);
future<block> C12 = dataflow(unwrapped(calc_c12), f_A, f_B, f_C);
future<block> C21 = dataflow(unwrapped(calc_c21), f_A, f_B, f_C);
future<block> C22 = dataflow(unwrapped(calc_c22), f_A, f_B, f_C);
future<block> result = dataflow(unwrapped(combine_blocks), C11, C12, C21, C22, f_C);
*/
return C;
}
示例3: calc_c22
block calc_c22(block A, block B, block C) {
block tempC = C.block22();
tempC.add_scratch();
future<block> A21B12 = async(rec_mult, A.block21(), B.block12(), C.block22());
future<block> A22B22 = async(rec_mult, A.block22(), B.block22(), tempC);
return add_blocks(A21B12.get(), A22B22.get(), C.block22());
}
示例4: hpx_main
int hpx_main(variables_map& vm)
{
boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>();
boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>();
{
thread_id_type thread_id = register_thread_nullary(
boost::bind(&test_dummy_thread, futures));
HPX_TEST(thread_id != hpx::threads::invalid_thread_id);
// Flood the queues with suspension operations before the rescheduling
// attempt.
unique_future<void> before = async(&tree_boot, futures, grain_size, thread_id);
set_thread_state(thread_id, pending, wait_signaled);
// Flood the queues with suspension operations after the rescheduling
// attempt.
unique_future<void> after = async(&tree_boot, futures, grain_size, thread_id);
before.get();
after.get();
set_thread_state(thread_id, pending, wait_terminate);
}
finalize();
return 0;
}
示例5: plain_arguments
void plain_arguments(Executor& exec)
{
void_f4_count.store(0);
int_f4_count.store(0);
{
future<void> f1 = dataflow(exec, &void_f4, 42);
future<int> f2 = dataflow(exec, &int_f4, 42);
f1.wait();
HPX_TEST_EQ(void_f4_count, 1u);
HPX_TEST_EQ(f2.get(), 84);
HPX_TEST_EQ(int_f4_count, 1u);
}
void_f5_count.store(0);
int_f5_count.store(0);
{
future<void> f1 = dataflow(exec, &void_f5, 42, async(&int_f));
future<int> f2 = dataflow(exec, &int_f5, 42, async(&int_f));
f1.wait();
HPX_TEST_EQ(void_f5_count, 1u);
HPX_TEST_EQ(f2.get(), 126);
HPX_TEST_EQ(int_f5_count, 1u);
}
}
示例6: calc_c11
block calc_c11(block A, block B, block C) {
block tempC = C.block11();//scratch space
tempC.add_scratch();
future<block> A11B11 = async(rec_mult, A.block11(), B.block11(), C.block11());
future<block> A12B21 = async(rec_mult, A.block12(), B.block21(), tempC);
return add_blocks(A11B11.get(), A12B21.get(), C.block11());
}
示例7: future_function_pointers
void future_function_pointers()
{
future_void_f1_count.store(0);
future_void_f2_count.store(0);
future<void> f1
= dataflow(
&future_void_f1, async(&future_void_sf1,
shared_future<void>(make_ready_future()))
);
f1.wait();
HPX_TEST_EQ(future_void_f1_count, 2u);
future_void_f1_count.store(0);
future<void> f2 = dataflow(
&future_void_f2
, async(&future_void_sf1, shared_future<void>(make_ready_future()))
, async(&future_void_sf1, shared_future<void>(make_ready_future()))
);
f2.wait();
HPX_TEST_EQ(future_void_f1_count, 2u);
HPX_TEST_EQ(future_void_f2_count, 1u);
future_void_f1_count.store(0);
future_void_f2_count.store(0);
future<int> f3 = dataflow(
&future_int_f1
, make_ready_future()
);
HPX_TEST_EQ(f3.get(), 1);
HPX_TEST_EQ(future_int_f1_count, 1u);
future_int_f1_count.store(0);
future<int> f4 = dataflow(
&future_int_f2
, dataflow(&future_int_f1, make_ready_future())
, dataflow(&future_int_f1, make_ready_future())
);
HPX_TEST_EQ(f4.get(), 2);
HPX_TEST_EQ(future_int_f1_count, 2u);
HPX_TEST_EQ(future_int_f2_count, 1u);
future_int_f1_count.store(0);
future_int_f2_count.store(0);
future_int_f_vector_count.store(0);
std::vector<future<int> > vf;
for(std::size_t i = 0; i < 10; ++i)
{
vf.push_back(dataflow(&future_int_f1, make_ready_future()));
}
future<int> f5 = dataflow(&future_int_f_vector, boost::ref(vf));
HPX_TEST_EQ(f5.get(), 10);
}
示例8: hpx_main
int hpx_main(variables_map&)
{
{
using hpx::async;
// create an explicit future
null_thread_executed = false;
{
HPX_TEST(async<null_action>(hpx::find_here()).get());
}
HPX_TEST(null_thread_executed);
// create an implicit future
null_thread_executed = false;
{
HPX_TEST(async<null_action>(hpx::find_here()).get());
}
HPX_TEST(null_thread_executed);
//test two successive 'get' from a promise
hpx::lcos::shared_future<int> int_promise(async<int_action>(hpx::find_here()));
HPX_TEST(int_promise.get() == int_promise.get());
}
{
using hpx::async;
null_action do_null;
// create an explicit future
null_thread_executed = false;
{
HPX_TEST(async(do_null, hpx::find_here()).get());
}
HPX_TEST(null_thread_executed);
// create an implicit future
null_thread_executed = false;
{
HPX_TEST(async(do_null, hpx::find_here()).get());
}
HPX_TEST(null_thread_executed);
//test two successive 'get' from a promise
int_action do_int;
hpx::lcos::shared_future<int> int_promise(async(do_int, hpx::find_here()));
HPX_TEST(int_promise.get() == int_promise.get());
}
hpx::finalize(); // Initiate shutdown of the runtime system.
return hpx::util::report_errors();
}
示例9: measure_function_futures
void measure_function_futures(boost::uint64_t count, bool csv)
{
std::vector<unique_future<double> > futures;
futures.reserve(count);
// start the clock
high_resolution_timer walltime;
for (boost::uint64_t i = 0; i < count; ++i)
futures.push_back(async(&null_function));
wait(futures, [&] (std::size_t, double r) { global_scratch += r; });
// stop the clock
const double duration = walltime.elapsed();
if (csv)
cout << ( boost::format("%1%,%2%\n")
% count
% duration)
<< flush;
else
cout << ( boost::format("invoked %1% futures (functions) in %2% seconds\n")
% count
% duration)
<< flush;
}
示例10: function_pointers
void function_pointers(Executor& exec)
{
void_f_count.store(0);
int_f_count.store(0);
void_f1_count.store(0);
int_f1_count.store(0);
int_f2_count.store(0);
future<void> f1 = dataflow(exec, unwrapped(&void_f1), async(&int_f));
future<int>
f2 = dataflow(exec,
unwrapped(&int_f1)
, dataflow(exec,
unwrapped(&int_f1)
, make_ready_future(42))
);
future<int>
f3 = dataflow(exec,
unwrapped(&int_f2)
, dataflow(exec,
unwrapped(&int_f1)
, make_ready_future(42)
)
, dataflow(exec,
unwrapped(&int_f1)
, make_ready_future(37)
)
);
int_f_vector_count.store(0);
std::vector<future<int> > vf;
for(std::size_t i = 0; i < 10; ++i)
{
vf.push_back(dataflow(exec, unwrapped(&int_f1), make_ready_future(42)));
}
future<int> f4 = dataflow(exec, unwrapped(&int_f_vector), std::move(vf));
future<int>
f5 = dataflow(exec,
unwrapped(&int_f1)
, dataflow(exec,
unwrapped(&int_f1)
, make_ready_future(42))
, dataflow(exec,
unwrapped(&void_f)
, make_ready_future())
);
f1.wait();
HPX_TEST_EQ(f2.get(), 126);
HPX_TEST_EQ(f3.get(), 163);
HPX_TEST_EQ(f4.get(), 10 * 84);
HPX_TEST_EQ(f5.get(), 126);
HPX_TEST_EQ(void_f_count, 1u);
HPX_TEST_EQ(int_f_count, 1u);
HPX_TEST_EQ(void_f1_count, 1u);
HPX_TEST_EQ(int_f1_count, 16u);
HPX_TEST_EQ(int_f2_count, 1u);
}
示例11: LU
void LU( int size, int numBlocks)
{
vector<vector<block>> blockList;
vector<vector<vector<shared_future<block>>>> dfArray(2);
shared_future<block> *diag_block, *first_col;
shared_future<int> fsize = make_ready_future(size);
auto rowOp = unwrapped(&ProcessBlockOnRow);
auto colOp = unwrapped(&ProcessBlockOnColumn);
auto innerOp = unwrapped(&ProcessInnerBlock);
auto diagOp = unwrapped(&ProcessDiagonalBlock);
getBlockList(blockList, numBlocks, size);
for(int i = 0; i < 2; i++){
dfArray[i].resize( numBlocks );
for(int j = 0; j < numBlocks; j++){
dfArray[i][j].resize( numBlocks, make_ready_future( block()));
}
}
vector<vector<shared_future<block>>> &last_array = dfArray[0];
vector<vector<shared_future<block>>> ¤t_array = dfArray[1];
//converts blocks to shared_futures for dataflow input in dfArray[0]
dfArray[0][0][0] = async( ProcessDiagonalBlock, size, blockList[0][0] );
diag_block = &dfArray[0][0][0];
for(int i = 1; i < numBlocks; i++) {
dfArray[0][0][i] = dataflow( rowOp, fsize, make_ready_future( blockList[0][i] ), *diag_block);
}
for(int i = 1; i < numBlocks; i++) {
dfArray[0][i][0] = dataflow( colOp, fsize, make_ready_future( blockList[i][0] ), *diag_block);
first_col = &dfArray[0][i][0];
for(int j = 1; j < numBlocks; j++) {
dfArray[0][i][j] = dataflow( innerOp, fsize, make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col);
}
}
//bulk of work, entirely in shared_futures
for(int i = 1; i < numBlocks; i++) {
last_array = dfArray[i-1];
current_array = dfArray[i];
current_array[i][i] = dataflow( diagOp, fsize, last_array[i][i]);
diag_block = ¤t_array[i][i];
for(int j = i + 1; j < numBlocks; j++){
current_array[i][j] = dataflow( rowOp, fsize, last_array[i][j], *diag_block);
}
for(int j = i + 1; j < numBlocks; j++){
current_array[j][i] = dataflow( colOp, fsize, last_array[j][i], *diag_block);
first_col = ¤t_array[j][i];
for(int k = i + 1; k < numBlocks; k++) {
current_array[j][k] = dataflow( innerOp, fsize, last_array[j][k], current_array[i][k], *first_col);
}
}
}
wait_all(current_array[numBlocks-1][numBlocks-1]);
}
示例12: exec_spawn
void exec_spawn(int input){
hpx::threads::thread_id_type id = hpx::threads::get_self_id();
cout << "in spawn #" << input << ", executor: " << hpx::threads::get_executor(id) << endl;
{
local_priority_queue_executor exec1(1);
auto f = async(exec1, thread_setup, input);
f.wait();
}
}
示例13: fibonacci
///////////////////////////////////////////////////////////////////////////////
//[fib_func
boost::uint64_t fibonacci(boost::uint64_t n)
{
if (n < 2)
return n;
// We restrict ourselves to execute the Fibonacci function locally.
hpx::naming::id_type const locality_id = hpx::find_here();
// Invoking the Fibonacci algorithm twice is inefficient.
// However, we intentionally demonstrate it this way to create some
// heavy workload.
using hpx::lcos::future;
using hpx::async;
fibonacci_action fib;
future<boost::uint64_t> n1 = async(fib, locality_id, n - 1);
future<boost::uint64_t> n2 = async(fib, locality_id, n - 2);
return n1.get() + n2.get(); // wait for the Futures to return their values
}
示例14: LU
void LU( int numBlocks)
{
printf("LU\n");
hpx::naming::id_type here = hpx::find_here();
vector<vector<block> > blockList;
getBlockList(blockList, numBlocks);
vector<vector<vector<shared_future<block> > > > dfArray(numBlocks);
shared_future<block> *diag_block, *first_col;
for(int i = 0; i < numBlocks; i++){
dfArray[i].resize(numBlocks);
for(int j = 0; j < numBlocks; j++){
dfArray[i][j].resize(numBlocks, hpx::make_ready_future(block()));
}
}
//first iteration through matrix, initialized vector of futures
dfArray[0][0][0] = async( ProcessDiagonalBlock, blockList[0][0] );
diag_block = &dfArray[0][0][0];
for(int i = 1; i < numBlocks; i++) {
dfArray[0][0][i] = dataflow( unwrapped( &ProcessBlockOnRow ),
hpx::make_ready_future( blockList[0][i] ), *diag_block);
}
for(int i = 1; i < numBlocks; i++) {
dfArray[0][i][0] = dataflow( unwrapped( &ProcessBlockOnColumn ),
hpx::make_ready_future( blockList[i][0] ), *diag_block);
first_col = &dfArray[0][i][0];
for(int j = 1; j < numBlocks; j++) {
dfArray[0][i][j] = dataflow( unwrapped( &ProcessInnerBlock ),
hpx::make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col );
}
}
//all calculation after initialization. Each iteration,
//the number of tasks/blocks spawned is decreased.
for(int i = 1; i < numBlocks; i++) {
dfArray[i][i][i] = dataflow( unwrapped( &ProcessDiagonalBlock ),
dfArray[i-1][i][i]);
diag_block = &dfArray[i][i][i];
for(int j = i + 1; j < numBlocks; j++){
dfArray[i][i][j] = dataflow( unwrapped(&ProcessBlockOnRow),
dfArray[i-1][i][j], *diag_block);
}
for(int j = i + 1; j < numBlocks; j++){
dfArray[i][j][i] = dataflow( unwrapped( &ProcessBlockOnColumn ),
dfArray[i-1][j][i], *diag_block);
first_col = &dfArray[i][j][i];
for(int k = i + 1; k < numBlocks; k++) {
dfArray[i][j][k] = dataflow( unwrapped( &ProcessInnerBlock ),
dfArray[i-1][j][k], dfArray[i][i][k], *first_col );
}
}
}
wait_all(dfArray[numBlocks-1][numBlocks-1][numBlocks-1]);
}
示例15: tree_boot
void tree_boot(
boost::uint64_t count
, boost::uint64_t grain_size
, thread_id_type thread
)
{
HPX_ASSERT(grain_size);
HPX_ASSERT(count);
std::vector<unique_future<void> > promises;
boost::uint64_t const actors = (count > grain_size) ? grain_size : count;
boost::uint64_t child_count = 0;
boost::uint64_t children = 0;
if (count > grain_size)
{
for (children = grain_size; children != 0; --children)
{
child_count = ((count - grain_size) / children);
if (child_count >= grain_size)
break;
}
promises.reserve(children + grain_size);
}
else
promises.reserve(count);
for (boost::uint64_t i = 0; i < children; ++i)
promises.push_back(async(&tree_boot, child_count, grain_size, thread));
for (boost::uint64_t i = 0; i < actors; ++i)
promises.push_back(async(&change_thread_state, thread));
detail::wait(promises);
}