Exemplo n.º 1
0
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);
    }
}
Exemplo n.º 2
0
void test_timed_executor(std::array<std::size_t, 4> expected)
{
    typedef typename hpx::traits::executor_execution_category<
            Executor
        >::type execution_category;

    HPX_TEST((std::is_same<
            hpx::parallel::execution::sequenced_execution_tag,
            execution_category
        >::value));

    count_sync.store(0);
    count_apply.store(0);
    count_sync_at.store(0);
    count_apply_at.store(0);

    Executor exec;

    test_timed_apply(exec);
    test_timed_sync(exec);
    test_timed_async(exec);

    HPX_TEST_EQ(expected[0], count_sync.load());
    HPX_TEST_EQ(expected[1], count_apply.load());
    HPX_TEST_EQ(expected[2], count_sync_at.load());
    HPX_TEST_EQ(expected[3], count_apply_at.load());
}
Exemplo n.º 3
0
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);
    }
}
Exemplo n.º 4
0
void	LoggingStreamImpl::UpdateIsLogging() const
{
    m_lastLoggingFilterChangeCount.store( g_LoggingFilterChangeCount.load() );

    boost::log::record		testRecord = m_logger.open_record( boost::log::keywords::severity = m_severityLevel );

    m_isLogging.store( (bool)testRecord );
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
void init_globals()
{
    // Retrieve command line using the Boost.ProgramOptions library.
    boost::program_options::variables_map vm;
    if (!hpx::util::retrieve_commandline_arguments(get_commandline_options(), vm))
    {
        HPX_THROW_EXCEPTION(hpx::commandline_option_error,
            "fibonacci_futures_distributed",
            "failed to handle command line options");
        return;
    }

    boost::uint64_t n = vm["n-value"].as<boost::uint64_t>();

    threshold = vm["threshold"].as<unsigned int>();
    if (threshold < 2 || threshold > n) {
        HPX_THROW_EXCEPTION(hpx::commandline_option_error,
            "fibonacci_futures_distributed",
            "wrong command line argument value for option 'threshold', "
            "should be in between 2 and n-value, value specified: " +
                std::to_string(threshold));
        return;
    }

    distribute_at = vm["distribute-at"].as<unsigned int>();
    if (distribute_at < 2 || distribute_at > n) {
        HPX_THROW_EXCEPTION(hpx::commandline_option_error,
            "fibonacci_futures_distributed",
            "wrong command line argument value for option 'distribute-at', "
            "should be in between 2 and n-value, value specified: " +
                std::to_string(distribute_at));
        return;
    }

    here = hpx::find_here();
    next_locality.store(0);
    serial_execution_count.store(0);

    // try to more evenly distribute the work over the participating localities
    std::vector<hpx::id_type> locs = hpx::find_all_localities();
    std::size_t num_repeats = vm["loc-repeat"].as<int>();

    localities.push_back(here);      // add ourselves
    for (std::size_t j = 0; j != num_repeats; ++j)
    {
        for (std::size_t i = 0; i != locs.size(); ++i)
        {
            if (here == locs[i])
                continue;
            localities.push_back(locs[i]);
        }
    }
}
Exemplo n.º 7
0
 inline T get_and_reset_value(boost::atomic<T>& value, bool reset)
 {
     T result = value.load();
     if (reset)
         value.store(0);
     return result;
 }
Exemplo n.º 8
0
    //! デバイスを閉じる
	void CloseDevice() {
		terminated_.store(true);
		process_thread_.join();
		waveOutReset(hwo_);
		waveOutClose(hwo_);

        //! waveOutResetを呼び出したあとで
        //! WAVEHDRの使用済み通知が来ることがある。
        //! つまり、waveOutResetを呼び出した直後に
        //! すぐにWAVEHDRを解放できない(デバイスによって使用中かもしれないため)
        //! そのため、確実にすべてのWAVEHDRの解放を確認する。
		for( ; ; ) {
			int left = 0;
			for(auto &header : headers_ | boost::adaptors::indirected) {
				if(header.get()->dwUser == WaveHeader::DONE) {
					waveOutUnprepareHeader(hwo_, header.get(), sizeof(WAVEHDR));
					header.get()->dwUser = WaveHeader::UNUSED;
				} else if(header.get()->dwUser == WaveHeader::USING) {
					left++;
				}
			}

			if(!left) { break; }
			Sleep(10);
		}
		hwo_ = NULL;
	}
Exemplo n.º 9
0
    void run(void)
    {
        BOOST_WARN(stk.is_lock_free());

        running.store(true);

        thread_group writer;
        thread_group reader;

        BOOST_REQUIRE(stk.empty());

        for (int i = 0; i != reader_threads; ++i)
            reader.create_thread(boost::bind(&stack_tester::get_items, this));

        for (int i = 0; i != writer_threads; ++i)
            writer.create_thread(boost::bind(&stack_tester::add_items, this));

        using namespace std;
        cout << "threads created" << endl;

        writer.join_all();

        cout << "writer threads joined, waiting for readers" << endl;

        running = false;
        reader.join_all();

        cout << "reader threads joined" << endl;

        BOOST_REQUIRE_EQUAL(data.count_nodes(), 0);
        BOOST_REQUIRE(stk.empty());

        BOOST_REQUIRE_EQUAL(push_count, pop_count);
        BOOST_REQUIRE_EQUAL(push_count, writer_threads * node_count);
    }
Exemplo n.º 10
0
int main(int argc, char* argv[])
{
    accumulator.store(0);

    // Initialize and run HPX
    HPX_TEST_EQ_MSG(hpx::init(argc, argv), 0,
        "HPX main exited with non-zero status");

    return hpx::util::report_errors();
}
Exemplo n.º 11
0
 bool try_basic_lock(thread_id_type current_thread_id)
 {
     if (mtx.try_lock())
     {
         locking_thread_id.exchange(current_thread_id);
         util::ignore_lock(&mtx);
         util::register_lock(this);
         recursion_count.store(1);
         return true;
     }
     return false;
 }
Exemplo n.º 12
0
void test_remote_async_cb(hpx::id_type const& target)
{
    typedef hpx::components::client<decrement_server> decrement_client;

    {
        decrement_client dec_f =
            hpx::components::new_<decrement_client>(target);

        call_action call;

        callback_called.store(0);
        hpx::future<std::int32_t> f1 = hpx::async_cb(call, dec_f, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<std::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, call, dec_f, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        decrement_client dec_f =
            hpx::components::new_<decrement_client>(target);
        hpx::id_type dec = dec_f.get_id();

        callback_called.store(0);
        hpx::future<std::int32_t> f1 =
            hpx::async_cb<call_action>(dec_f, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<std::int32_t> f2 =
            hpx::async_cb<call_action>(hpx::launch::all, dec_f, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
int main(int argc, char* argv[])
{
    accumulator.store(0);

    // Initialize and run HPX
    HPX_TEST_EQ_MSG(hpx::init(argc, argv), 0,
        "HPX main exited with non-zero status");

    HPX_TEST_NEQ(boost::uint32_t(-1), locality_id);
    HPX_TEST(on_shutdown_executed || 0 != locality_id);

    return hpx::util::report_errors();
}
Exemplo n.º 15
0
            /// Acquires ownership of the \a recursive_mutex. Suspends the
            /// current HPX-thread if ownership cannot be obtained immediately.
            ///
            /// \throws Throws \a hpx#bad_parameter if an error occurs while
            ///         suspending. Throws \a hpx#yield_aborted if the mutex is
            ///         destroyed while suspended. Throws \a hpx#null_thread_id if
            ///         called outside of a HPX-thread.
            void lock()
            {
                thread_id_type const id = thread_id_from_mutex<Mutex>::call();
                HPX_ASSERT(id != thread_id_from_mutex<Mutex>::invalid_id());

                if (!try_recursive_lock(id))
                {
                    mtx.lock();
                    locking_thread_id.exchange(id);
                    util::ignore_lock(&mtx);
                    util::register_lock(this);
                    recursion_count.store(1);
                }
            }
int main(int argc, char *argv[]) {
  RocketmqSendAndConsumerArgs info;
  if (!ParseArgs(argc, argv, &info)) {
    exit(-1);
  }

  DefaultMQProducer producer("please_rename_unique_group_name");
  PrintRocketmqSendAndConsumerArgs(info);

  producer.setNamesrvAddr(info.namesrv);
  producer.setNamesrvDomain(info.namesrv_domain);
  producer.setGroupName(info.groupname);
  producer.setInstanceName(info.groupname);

  producer.start();

  int msgcount = g_msgCount.load();
  std::vector<std::shared_ptr<std::thread>> work_pool;

  int threadCount = info.thread_count;
  for (int j = 0; j < threadCount; j++) {
    std::shared_ptr<std::thread> th =
        std::make_shared<std::thread>(ProducerWorker, &info, &producer);
    work_pool.push_back(th);
  }

  auto start = std::chrono::system_clock::now();
  {
    std::unique_lock<std::mutex> lck(g_mtx);
    g_finished.wait(lck);
    g_quit.store(true);
  }

  auto end = std::chrono::system_clock::now();
  auto duration =
      std::chrono::duration_cast<std::chrono::milliseconds>(end - start);

  std::cout
      << "per msg time: " << duration.count() / (double)msgcount << "ms \n"
      << "========================finished==============================\n";

  for (size_t th = 0; th != work_pool.size(); ++th) {
    work_pool[th]->join();
  }

  producer.shutdown();

  return 0;
}
Exemplo n.º 17
0
int main(int argc, char* argv[])
{
    accumulator.store(0);

    // Initialize and run HPX
    HPX_TEST_EQ_MSG(hpx::init(argc, argv), 0,
        "HPX main exited with non-zero status");

    // After hpx::init returns, all actions should have been executed
    // The final result is only accumulated on the root locality
    if(root_locality)
        HPX_TEST_EQ(final_result, 13);

    return hpx::util::report_errors();
}
Exemplo n.º 18
0
int hpx_main()
{
    using hpx::make_continuation;

    increment_action inc;
    increment_with_future_action inc_f;
    mult2_action mult;

    // test locally, fully equivalent to plain hpx::async
    {
        callback_called.store(0);
        hpx::future<int> f1 = hpx::async_continue_cb(
            inc, make_continuation(), hpx::find_here(), &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        hpx::promise<boost::int32_t> p;
        hpx::shared_future<boost::int32_t> f = p.get_future();

        callback_called.store(0);
        hpx::future<int> f2 = hpx::async_continue_cb(
            inc_f, make_continuation(), hpx::find_here(), &cb, f);

        p.set_value(42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    // test remotely, if possible, fully equivalent to plain hpx::async
    std::vector<hpx::id_type> localities = hpx::find_remote_localities();
    if (!localities.empty())
    {
        callback_called.store(0);
        hpx::future<int> f1 = hpx::async_continue_cb(
            inc, make_continuation(), localities[0], &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        hpx::promise<boost::int32_t> p;
        hpx::shared_future<boost::int32_t> f = p.get_future();

        callback_called.store(0);
        hpx::future<int> f2 = hpx::async_continue_cb(
            inc_f, make_continuation(), localities[0], &cb, f);

        p.set_value(42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    // test chaining locally
    {
        callback_called.store(0);
        hpx::future<int> f = hpx::async_continue_cb(
            inc, make_continuation(mult), hpx::find_here(), &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, make_continuation()), hpx::find_here(),
            &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, make_continuation(inc)), hpx::find_here(),
            &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, make_continuation(inc, make_continuation())),
            hpx::find_here(), &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    // test chaining remotely, if possible
    if (!localities.empty())
    {
        callback_called.store(0);
        hpx::future<int> f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0]), localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0], make_continuation()),
            localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0],
                make_continuation(inc)), localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0],
                make_continuation(inc, make_continuation())), localities[0],
            &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0],
                make_continuation(inc, localities[0])), localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, localities[0],
                make_continuation(inc, localities[0], make_continuation())),
                localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 87);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult), localities[0], &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        f = hpx::async_continue_cb(inc,
            make_continuation(mult, make_continuation()), localities[0],
            &cb, 42);
        HPX_TEST_EQ(f.get(), 86);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    return hpx::finalize();
}
Exemplo n.º 19
0
 void set_default_executor(scheduled_executor executor)
 {
     default_executor_instance.store(executor);
 }
Exemplo n.º 20
0
void test_remote_async_cb_colocated(test_client const& target)
{
    {
        increment_action inc;

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb(inc, hpx::colocated(target), &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, inc, hpx::colocated(target), &cb, 42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        increment_with_future_action inc;

        hpx::promise<boost::int32_t> p;
        hpx::shared_future<boost::int32_t> f = p.get_future();

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb(inc, hpx::colocated(target), &cb, f);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, inc, hpx::colocated(target), &cb, f);

        p.set_value(42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 2);
    }

    {
        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb<increment_action>(hpx::colocated(target), &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 = hpx::async_cb<increment_action>(
            hpx::launch::all, hpx::colocated(target), &cb, 42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        hpx::future<hpx::id_type> dec_f =
            hpx::components::new_<decrement_server>(hpx::colocated(target));
        hpx::id_type dec = dec_f.get();

        call_action call;

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(call, dec, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, call, dec, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        hpx::future<hpx::id_type> dec_f =
            hpx::components::new_<decrement_server>(hpx::colocated(target));
        hpx::id_type dec = dec_f.get();

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb<call_action>(dec, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb<call_action>(hpx::launch::all, dec, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        increment_with_future_action inc;
        hpx::shared_future<boost::int32_t> f =
            hpx::async(hpx::launch::deferred, hpx::util::bind(&increment, 42));

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(
            inc, hpx::colocated(target), &cb, f);
        hpx::future<boost::int32_t> f2 = hpx::async_cb(
            hpx::launch::all, inc, hpx::colocated(target), &cb, f);

        HPX_TEST_EQ(f1.get(), 44);
        HPX_TEST_EQ(f2.get(), 44);
        HPX_TEST_EQ(callback_called.load(), 2);
    }
}
Exemplo n.º 21
0
	synclist() {
		m_first.store(NULL,boost::memory_order_acquire);
		m_last.store(NULL,boost::memory_order_acquire);
		m_length.store(0,boost::memory_order_acquire);
	}
		void unlock()
		{
			state_.store(Unlocked, boost::memory_order_release);
		}
Exemplo n.º 23
0
void swap( boost::atomic<T>& lhs, boost::atomic<T>& rhs )
{
    lhs.store(rhs.exchange(lhs.load()));
}
Exemplo n.º 24
0
void test_remote_async_cb(hpx::id_type const& target)
{
    {
        increment_action inc;

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(inc, target, &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, inc, target, &cb, 42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        increment_with_future_action inc;

        hpx::promise<boost::int32_t> p;
        hpx::shared_future<boost::int32_t> f = p.get_future();

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(inc, target, &cb, f);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, inc, target, &cb, f);

        p.set_value(42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 2);
    }

//     {
//         increment_action inc;
//
//         callback_called.store(0);
//         hpx::future<boost::int32_t> f1 =
//             hpx::async_cb(hpx::util::bind(inc, target, 42), &cb);
//         HPX_TEST_EQ(f1.get(), 43);
//         HPX_TEST_EQ(callback_called.load(), 1);
//     }

    {
        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb<increment_action>(target, &cb, 42);
        HPX_TEST_EQ(f1.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb<increment_action>(hpx::launch::all, target, &cb, 42);
        HPX_TEST_EQ(f2.get(), 43);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        hpx::future<hpx::id_type> dec_f =
            hpx::components::new_<decrement_server>(target);
        hpx::id_type dec = dec_f.get();

        call_action call;

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(call, dec, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, call, dec, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

//     {
//         hpx::future<hpx::id_type> dec_f =
//             hpx::components::new_<decrement_server>(target);
//         hpx::id_type dec = dec_f.get();
//
//         call_action call;
//
//         callback_called.store(0);
//         hpx::future<boost::int32_t> f1 =
//             hpx::async_cb(hpx::util::bind(call, dec, 42), &cb);
//         HPX_TEST_EQ(f1.get(), 41);
//         HPX_TEST_EQ(callback_called.load(), 1);
//
//         using hpx::util::placeholders::_1;
//         using hpx::util::placeholders::_2;
//
//         callback_called.store(0);
//         hpx::future<boost::int32_t> f2 =
//             hpx::async_cb(hpx::util::bind(call, _1, 42), dec, &cb);
//         HPX_TEST_EQ(f2.get(), 41);
//         HPX_TEST_EQ(callback_called.load(), 1);

//         callback_called.store(0);
//         hpx::future<boost::int32_t> f3 =
//             hpx::async_cb(hpx::util::bind(call, _1, _2), dec, &cb, 42);
//         HPX_TEST_EQ(f3.get(), 41);
//         HPX_TEST_EQ(callback_called.load(), 1);
//     }

    {
        hpx::future<hpx::id_type> dec_f =
            hpx::components::new_<decrement_server>(target);
        hpx::id_type dec = dec_f.get();

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 =
            hpx::async_cb<call_action>(dec, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb<call_action>(hpx::launch::all, dec, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        increment_with_future_action inc;
        hpx::shared_future<boost::int32_t> f =
            hpx::async(hpx::launch::deferred, hpx::util::bind(&increment, 42));

        callback_called.store(0);
        hpx::future<boost::int32_t> f1 = hpx::async_cb(inc, target, &cb, f);
        hpx::future<boost::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, inc, target, &cb, f);

        HPX_TEST_EQ(f1.get(), 44);
        HPX_TEST_EQ(f2.get(), 44);
        HPX_TEST_EQ(callback_called.load(), 2);
    }
}
Exemplo n.º 25
0
int hpx_main(boost::program_options::variables_map& vm)
{
    // extract command line argument, i.e. fib(N)
    boost::uint64_t n = vm["n-value"].as<boost::uint64_t>();
    std::string test = vm["test"].as<std::string>();
    boost::uint64_t max_runs = vm["n-runs"].as<boost::uint64_t>();

    if (max_runs == 0) {
        std::cerr << "fibonacci_futures_distributed: wrong command "
            "line argument value for "
            "option 'n-runs', should not be zero" << std::endl;
        return hpx::finalize(); // Handles HPX shutdown
    }

    bool executed_one = false;
    boost::uint64_t r = 0;

    if (test == "all" || test == "0")
    {
        // Keep track of the time required to execute.
        boost::uint64_t start = hpx::util::high_resolution_clock::now();

        // Synchronous execution, use as reference only.
        r = fibonacci_serial(n);

//        double d = double(hpx::util::high_resolution_clock::now() - start) / 1.e9;
        boost::uint64_t d = hpx::util::high_resolution_clock::now() - start;
        char const* fmt = "fibonacci_serial(%1%) == %2%,"
            "elapsed time:,%3%,[s]\n";
        std::cout << (boost::format(fmt) % n % r % d);

        executed_one = true;
    }

    if (test == "all" || test == "1")
    {
        // Keep track of the time required to execute.
        boost::uint64_t start = hpx::util::high_resolution_clock::now();

        for (std::size_t i = 0; i != max_runs; ++i)
        {
            // Create a Future for the whole calculation and wait for it.
            next_locality.store(0);
            r = fibonacci_future(n).get();
        }

//        double d = double(hpx::util::high_resolution_clock::now() - start) / 1.e9;
        boost::uint64_t d = hpx::util::high_resolution_clock::now() - start;
        char const* fmt = "fibonacci_future(%1%) == %2%,elapsed time:,%3%,[s],%4%\n";
        std::cout << (boost::format(fmt) % n % r % (d / max_runs)
            % next_locality.load());

        get_serial_execution_count_action serial_count;
        for (hpx::id_type const& loc : hpx::find_all_localities())
        {
            std::size_t count = serial_count(loc);
            std::cout << (boost::format("  serial-count,%1%,%2%\n") %
                loc % (count / max_runs));
        }

        executed_one = true;
    }

    if (!executed_one)
    {
        std::cerr << "fibonacci_futures_distributed: wrong command line argument "
            "value for option 'tests', should be either 'all' or a number between "
            "zero and 1, value specified: " << test << std::endl;
    }

    return hpx::finalize(); // Handles HPX shutdown
}
Exemplo n.º 26
0
int hpx_main(
    variables_map& vm
)
{
    {
        std::size_t count = 0;
        callback cb(count);

        ///////////////////////////////////////////////////////////////////////
        HPX_SANITY_EQ(0U, cb.count());

        cb(0);

        HPX_SANITY_EQ(1U, cb.count());

        cb.reset();

        HPX_SANITY_EQ(0U, cb.count());

        ///////////////////////////////////////////////////////////////////////
        id_type const here_ = find_here();

        ///////////////////////////////////////////////////////////////////////
        // Async wait, single future, void return.
        {
            wait(async<null_action>(here_), cb);

            HPX_TEST_EQ(1U, cb.count());
            HPX_TEST_EQ(1U, void_counter.load());

            cb.reset();
            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Async wait, single future, non-void return.
        {
            wait(async<null_result_action>(here_), cb);

            HPX_TEST_EQ(1U, cb.count());
            HPX_TEST_EQ(1U, result_counter.load());

            cb.reset();
            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Async wait, vector of futures, void return.
        {
            std::vector<future<void> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_action>(here_));

            wait(futures, cb);

            HPX_TEST_EQ(64U, cb.count());
            HPX_TEST_EQ(64U, void_counter.load());

            cb.reset();
            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Async wait, vector of futures, non-void return.
        {
            std::vector<future<bool> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_result_action>(here_));

            wait(futures, cb);

            HPX_TEST_EQ(64U, cb.count());
            HPX_TEST_EQ(64U, result_counter.load());

            cb.reset();
            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, single future, void return.
        {
            wait(async<null_action>(here_));

            HPX_TEST_EQ(1U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, single future, non-void return.
        {
            HPX_TEST_EQ(true, wait(async<null_result_action>(here_)));
            HPX_TEST_EQ(1U, result_counter.load());

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, multiple futures, void return.
        {
            wait(async<null_action>(here_)
                 , async<null_action>(here_)
                 , async<null_action>(here_));

            HPX_TEST_EQ(3U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, multiple futures, non-void return.
        {
            HPX_STD_TUPLE<bool, bool, bool> r
                = wait(async<null_result_action>(here_)
                       , async<null_result_action>(here_)
                       , async<null_result_action>(here_));

            HPX_TEST_EQ(true, HPX_STD_GET(0, r));
            HPX_TEST_EQ(true, HPX_STD_GET(1, r));
            HPX_TEST_EQ(true, HPX_STD_GET(2, r));
            HPX_TEST_EQ(3U, result_counter.load());

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, void return.
        {
            std::vector<future<void> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_action>(here_));

            wait(futures);

            HPX_TEST_EQ(64U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, non-void return.
        {
            std::vector<future<bool> > futures;
            futures.reserve(64);

            std::vector<bool> values;
            values.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_result_action>(here_));

            wait(futures, values);

            HPX_TEST_EQ(64U, result_counter.load());

            for (std::size_t i = 0; i < 64; ++i)
                HPX_TEST_EQ(true, values[i]);

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, non-void return ignored.
        {
            std::vector<future<bool> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_result_action>(here_));

            wait(futures);

            HPX_TEST_EQ(64U, result_counter.load());

            result_counter.store(0);
        }
    }

    finalize();

    return report_errors();
}
Exemplo n.º 27
0
int hpx_main(
    variables_map& vm
    )
{
    {
        boost::atomic<std::size_t> count(0);

        ///////////////////////////////////////////////////////////////////////
        id_type const here_ = find_here();

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, single future, void return.
        {
            unwrapped(async<null_action>(here_));

            HPX_TEST_EQ(1U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, single future, non-void return.
        {
            HPX_TEST_EQ(true, unwrapped(async<null_result_action>(here_)));
            HPX_TEST_EQ(1U, result_counter.load());

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, multiple futures, void return.
        {
            unwrapped(async<null_action>(here_)
               , async<null_action>(here_)
               , async<null_action>(here_));

            HPX_TEST_EQ(3U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, multiple futures, non-void return.
        {
            hpx::util::tuple<bool, bool, bool> r
                = unwrapped(async<null_result_action>(here_)
                     , async<null_result_action>(here_)
                     , async<null_result_action>(here_));

            HPX_TEST_EQ(true, hpx::util::get<0>(r));
            HPX_TEST_EQ(true, hpx::util::get<1>(r));
            HPX_TEST_EQ(true, hpx::util::get<2>(r));
            HPX_TEST_EQ(3U, result_counter.load());

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, void return.
        {
            std::vector<future<void> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_action>(here_));

            unwrapped(futures);

            HPX_TEST_EQ(64U, void_counter.load());

            void_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, non-void return.
        {
            std::vector<future<bool> > futures;
            futures.reserve(64);

            std::vector<bool> values;
            values.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_result_action>(here_));

            values = unwrapped(futures);

            HPX_TEST_EQ(64U, result_counter.load());

            for (std::size_t i = 0; i < 64; ++i)
                HPX_TEST_EQ(true, values[i]);

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Sync wait, vector of futures, non-void return ignored.
        {
            std::vector<future<bool> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(async<null_result_action>(here_));

            unwrapped(futures);

            HPX_TEST_EQ(64U, result_counter.load());

            result_counter.store(0);
        }

        ///////////////////////////////////////////////////////////////////////
        // Functional wrapper, single future
        {
            future<int> future = hpx::make_ready_future(42);

            HPX_TEST_EQ(unwrapped(&increment)(future), 42 + 1);
        }

        ///////////////////////////////////////////////////////////////////////
        // Functional wrapper, vector of future
        {
            std::vector<future<int> > futures;
            futures.reserve(64);

            for (std::size_t i = 0; i < 64; ++i)
                futures.push_back(hpx::make_ready_future(42));

            HPX_TEST_EQ(unwrapped(&accumulate)(futures), 42 * 64);
        }

        ///////////////////////////////////////////////////////////////////////
        // Functional wrapper, tuple of future
        {
            hpx::util::tuple<future<int>, future<int> > tuple =
                hpx::util::forward_as_tuple(
                    hpx::make_ready_future(42), hpx::make_ready_future(42));

            HPX_TEST_EQ(unwrapped(&add)(tuple), 42 + 42);
        }

        ///////////////////////////////////////////////////////////////////////
        // Functional wrapper, future of tuple of future
        {
            hpx::future<
                hpx::util::tuple<future<int>, future<int> >
            > tuple_future =
                hpx::make_ready_future(hpx::util::make_tuple(
                    hpx::make_ready_future(42), hpx::make_ready_future(42)));

            HPX_TEST_EQ(unwrapped2(&add)(tuple_future), 42 + 42);
        }
    }

    finalize();

    return report_errors();
}