void test_custom_factory()
{
    std::vector<char> buffer;

    {
        std::shared_ptr<B> struct_a(new B(1981, false));
        hpx::serialization::output_archive oarchive(buffer);
        oarchive << struct_a;
    }
    {
        std::shared_ptr<B> struct_b;
        hpx::serialization::input_archive iarchive(buffer);
        iarchive >> struct_b;
        HPX_TEST_EQ(struct_b->b, 1981);
    }
}
示例#2
0
int hpx_main()
{
    // List of currently available resources
    hpx::lcos::channel<locality_id_t> free_resources(hpx::find_here());

    std::size_t os_thread_count = hpx::get_os_thread_count();

    // At the beginning all threads on all localities are free
    for (locality_id_t id : hpx::find_all_localities())
    {
        for (std::size_t i = 0; i != os_thread_count; ++i)
        {
            free_resources.set(id);
            ++count;
        }
    }

    for (int i = 0; i < 1000; ++i)
    {
        // Ask for resources
        hpx::shared_future<locality_id_t> target = free_resources.get();

        // Do some work, once we have acquired resources
        hpx::shared_future<int> result = target.then(
            [](hpx::shared_future<locality_id_t> t)
            ->  hpx::shared_future<int>
            {
                --count;
                return hpx::make_ready_future(0);
            });

        // Free resources
        result.then(
            [free_resources, target](hpx::shared_future<int>) mutable
            {
                ++count;
                free_resources.set(target.get());
            });

        result.get();
    }

    std::size_t remaining_count = free_resources.close(true);
    HPX_TEST_EQ(remaining_count, count.load());

    return hpx::finalize();
}
int main()
{
  std::vector<char> vector;
  {
      hpx::serialization::output_archive archive{vector};
      boost::shared_ptr<A<int> > b = boost::make_shared<B<int> >(-4);
      boost::shared_ptr<A<char> > c = boost::make_shared<B<char> >(44);
      boost::shared_ptr<A<double> > d = boost::make_shared<B<double> >(99);
      boost::shared_ptr<A<float> > e = boost::make_shared<C<short, float> >(222);
      archive << b << c << d << e;
  }

  {
      hpx::serialization::input_archive archive{vector};
      boost::shared_ptr<A<int> > b;
      boost::shared_ptr<A<char> > c;
      boost::shared_ptr<A<double> > d;
      boost::shared_ptr<A<float> > e;

      archive >> b;
      archive >> c;
      archive >> d;
      archive >> e;

      HPX_TEST_EQ(b->a, -5);
      HPX_TEST_EQ(boost::static_pointer_cast<B<int> >(b)->b, -4);

      HPX_TEST_EQ(c->a, 43);
      HPX_TEST_EQ(boost::static_pointer_cast<B<char> >(c)->b, 44);

      HPX_TEST_EQ(d->a, 98);
      HPX_TEST_EQ(boost::static_pointer_cast<B<double> >(d)->b, 99);

      HPX_TEST_EQ(e->a, 221);
      HPX_TEST_EQ((boost::static_pointer_cast<C<short, float> >(e)->b), 222);
      HPX_TEST_EQ((boost::static_pointer_cast<C<short, float> >(e)->c), 223);
  }

}
示例#4
0
文件: used_pus.cpp 项目: K-ballo/hpx
int hpx_main(int argc, char* argv[])
{
    std::size_t num_threads = hpx::resource::get_num_threads("default");
    hpx::threads::thread_pool_base& tp =
                hpx::resource::get_thread_pool("default");

    auto used_pu_mask = tp.get_used_processing_units();
    HPX_TEST_EQ(hpx::threads::count(used_pu_mask), num_threads);

    for (std::size_t t = 0; t < num_threads; ++t)
    {
        auto thread_mask = hpx::resource::get_partitioner().get_pu_mask(t);
        HPX_TEST(hpx::threads::bit_or(used_pu_mask, thread_mask));
    }

    return hpx::finalize();
}
示例#5
0
void test_count_if_async(ExPolicy p, IteratorTag)
{
    typedef std::vector<int>::iterator base_iterator;
    typedef std::vector<int>::difference_type diff_type;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<int> c(10007);
    std::iota(boost::begin(c), boost::begin(c) + 50, 0);
    std::iota(boost::begin(c) + 50, boost::end(c), std::rand() + 50);

    hpx::future<diff_type> f =
        hpx::parallel::count_if(p,
            iterator(boost::begin(c)), iterator(boost::end(c)),
            smaller_than_50());

    HPX_TEST_EQ(f.get(), 50);
}
bool test_migrate_component_to_storage(hpx::id_type const& source,
    hpx::id_type const& target, hpx::components::component_storage storage,
    hpx::id_type::management_type t)
{
    hpx::id_type oldid;

    {
        // create component on given locality
        test_client t1(source);
        HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_id());

        // the new object should live on the source locality
        HPX_TEST_EQ(t1.call(), source);

        // remember the original id for later resurrection
        oldid = hpx::id_type(t1.get_id().get_gid(), t);

        try {
            // migrate of t1 to the target storage
            test_client t2(hpx::components::migrate_to_storage(t1, storage));
            HPX_TEST_EQ(hpx::naming::invalid_id, t2.get_id());
        }
        catch (hpx::exception const&) {
            return false;
        }

        HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1));

        // make sure all local references go out of scope if t == unmanaged
    }

    HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1));

    {
        test_client t1(hpx::components::migrate_from_storage<test_server>(
            oldid, target));

        // the id of the newly resurrected object should be the same as the old id
        HPX_TEST_EQ(oldid, t1.get_id());

        // the new object should now live on the target locality
        HPX_TEST_EQ(t1.call(), target);

        HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(0));
    }

    return true;
}
示例#7
0
void test_uninitialized_copy_exception_async(ExPolicy p, IteratorTag)
{
    typedef std::vector<test::count_instances>::iterator base_iterator;
    typedef test::decorated_iterator<base_iterator, IteratorTag>
        decorated_iterator;

    std::vector<test::count_instances> c(10007);
    std::vector<test::count_instances> d(c.size());
    std::iota(boost::begin(c), boost::end(c), std::rand());

    boost::atomic<std::size_t> throw_after(std::rand() % c.size()); //-V104
    test::count_instances::instance_count.store(0);

    bool caught_exception = false;
    bool returned_from_algorithm = false;
    try {
        hpx::future<base_iterator> f =
            hpx::parallel::uninitialized_copy(p,
                decorated_iterator(
                    boost::begin(c),
                    [&throw_after]()
                    {
                        if (throw_after-- == 0)
                            throw std::runtime_error("test");
                    }),
                decorated_iterator(boost::end(c)),
                boost::begin(d));

        returned_from_algorithm = true;
        f.get();

        HPX_TEST(false);
    }
    catch (hpx::exception_list const& e) {
        caught_exception = true;
        test::test_num_exceptions<ExPolicy, IteratorTag>::call(p, e);
    }
    catch (...) {
        HPX_TEST(false);
    }

    HPX_TEST(caught_exception);
    HPX_TEST(returned_from_algorithm);
    HPX_TEST_EQ(test::count_instances::instance_count.load(), std::size_t(0));
}
示例#8
0
文件: make_future.cpp 项目: 7ev3n/hpx
void test_make_shared_future()
{
    // test make_future<T>(shared_future<T>)
    {
        hpx::shared_future<int> f1 = hpx::make_ready_future(42);
        hpx::shared_future<int> f2 = hpx::make_future<int>(f1);
        HPX_TEST_EQ(42, f1.get());
        HPX_TEST_EQ(42, f2.get());
    }

    // test make_future<T>(shared_future<U>) where is_convertible<U, T>
    {
        hpx::shared_future<int> f1 = hpx::make_ready_future(42);
        hpx::shared_future<double> f2 = hpx::make_future<double>(f1);
        HPX_TEST_EQ(42, f1.get());
        HPX_TEST_EQ(42.0, f2.get());
    }

    // test make_future<void>(shared_future<U>)
    {
        hpx::shared_future<int> f1 = hpx::make_ready_future(42);
        hpx::shared_future<void> f2 = hpx::make_future<void>(f1);
        HPX_TEST_EQ(42, f1.get());
    }

    // test make_future<void>(shared_future<void>)
    {
        hpx::shared_future<void> f1 = hpx::make_ready_future();
        hpx::shared_future<void> f2 = hpx::make_future<void>(f1);
    }

    // test make_future<T>(shared_future<U>) with given T conv(U)
    {
        hpx::shared_future<int> f1 = hpx::make_ready_future(42);
        hpx::shared_future<std::string> f2 =
            hpx::make_future<std::string>(
                f1,
                [](int value) -> std::string
                {
                    return std::to_string(value);
                });

        HPX_TEST_EQ(42, f1.get());
        HPX_TEST_EQ(std::string("42"), f2.get());
    }
}
示例#9
0
// this test must be run with 4 threads
int main(int argc, char* argv[])
{
    std::vector<std::string> cfg = {
        "hpx.os_threads=" + std::to_string(max_threads)
    };

    // create the resource partitioner
    hpx::resource::partitioner rp(argc, argv, std::move(cfg));

    // before adding pools - set the default pool name to "pool-0"
    rp.set_default_pool_name("pool-0");

    // create N pools
    for (int i=0; i<max_threads; i++) {
        std::string pool_name = "pool-"+std::to_string(i);
        rp.create_thread_pool(pool_name,
            hpx::resource::scheduling_policy::local_priority_fifo);
    }

    // add one PU to each pool
    int thread_count = 0;
    for (const hpx::resource::numa_domain& d : rp.numa_domains())
    {
        for (const hpx::resource::core& c : d.cores())
        {
            for (const hpx::resource::pu& p : c.pus())
            {
                if (thread_count < max_threads)
                {
                    std::string pool_name = "pool-" + std::to_string(thread_count);
                    std::cout << "Added pu " << thread_count
                              << " to " << pool_name << "\n";
                    rp.add_resource(p, pool_name);
                    thread_count++;
                }
            }
        }
    }

    // now run the test
    HPX_TEST_EQ(hpx::init(), 0);
    return hpx::util::report_errors();
}
示例#10
0
int hpx_main()
{
    hpx::id_type here = hpx::find_here();
    hpx::id_type there = here;
    if (hpx::get_num_localities_sync() > 1)
    {
        std::vector<hpx::id_type> localities = hpx::find_remote_localities();
        there = localities[0];
    }

    {
        increment_action inc;
        hpx::apply_colocated(inc, there, here, 1);
    }

    {
        hpx::unique_future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        increment_action inc;
        hpx::apply_colocated(inc, where, here, 1);
    }

    {
        hpx::unique_future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        hpx::apply_colocated<increment_action>(where, here, 1);
    }

    // finalize will synchronize will all pending operations
    int result = hpx::finalize();

    hpx::util::spinlock::scoped_lock l(result_mutex);
    result_cv.wait_for(result_mutex, boost::chrono::seconds(1),
        hpx::util::bind(std::equal_to<boost::int32_t>(), boost::ref(final_result), 3));

    HPX_TEST_EQ(final_result, 3);

    return result;
}
示例#11
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);
    }
}
int main()
{
    ///////////////////////////////////////////////////////////////////////////

    { // Client to A, instance of C
        clientA obj(hpx::components::new_<C>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "C");
    }

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);
    HPX_TEST(c_ctor); HPX_TEST(c_dtor);

    reset_globals();

    ///////////////////////////////////////////////////////////////////////////

    { // Client to B, instance of C
        clientB obj(hpx::components::new_<C>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "C");
        HPX_TEST_EQ(obj.test1(), "C");
    }

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);
    HPX_TEST(c_ctor); HPX_TEST(c_dtor);

    reset_globals();

    ///////////////////////////////////////////////////////////////////////////

    { // Client to C, instance of C
        clientC obj(hpx::components::new_<C>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "C");
        HPX_TEST_EQ(obj.test1(), "C");
        HPX_TEST_EQ(obj.test2(), "C");
    }

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);
    HPX_TEST(c_ctor); HPX_TEST(c_dtor);

    reset_globals();

    return 0;
}
示例#13
0
void test_leak()
{
    {
        hpx::shared_future<test> f;

        {
            hpx::lcos::promise<test> p;
            f = p.get_future();
            hpx::apply_c<call_action>(p.get_id(), hpx::find_here());
        }

        test t = f.get();
    }

    hpx::agas::garbage_collect();
    hpx::this_thread::yield();
    hpx::agas::garbage_collect();
    hpx::this_thread::yield();
    HPX_TEST_EQ(test::count, 0);
}
示例#14
0
void force_recursion_test2()
{
    std::vector<hpx::lcos::local::promise<void> > promises;
    promises.reserve(NUM_FUTURES);

    std::vector<hpx::shared_future<void> > futures;
    futures.reserve(NUM_FUTURES);

    for (std::size_t i = 0; i != NUM_FUTURES; ++i)
    {
        promises.push_back(hpx::lcos::local::promise<void>());
        futures.push_back(promises[i].get_future());
    }

    boost::atomic<std::size_t> executed_continuations(0);
    make_ready_continue(0, promises, futures, executed_continuations);

    hpx::wait_all(futures);
    HPX_TEST_EQ(executed_continuations.load(), NUM_FUTURES);
}
示例#15
0
void test_count_if(ExPolicy policy, IteratorTag)
{
    static_assert(
        hpx::parallel::is_execution_policy<ExPolicy>::value,
        "hpx::parallel::is_execution_policy<ExPolicy>::value");

    typedef std::vector<int>::iterator base_iterator;
    typedef std::vector<int>::difference_type diff_type;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<int> c(100007);
    std::iota(boost::begin(c), boost::begin(c) + 50, 0);
    std::iota(boost::begin(c) + 50, boost::end(c), std::rand() + 50);

    diff_type num_items = hpx::parallel::count_if(policy,
        iterator(boost::begin(c)), iterator(boost::end(c)),
        smaller_than_50());

    HPX_TEST_EQ(num_items, 50u);
}
示例#16
0
int hpx_main()
{
    std::vector<double> large(64);

    auto zip_it_begin = hpx::util::make_zip_iterator(large.begin());
    auto zip_it_end = hpx::util::make_zip_iterator(large.end());

    hpx::parallel::for_each(
        hpx::parallel::execution::datapar, zip_it_begin, zip_it_end,
        [](auto& t) -> void
        {
            hpx::util::get<0>(t) = 10.0;
        });

    HPX_TEST_EQ(
        std::count(large.begin(), large.end(), 10.0),
        std::ptrdiff_t(large.size()));

    return hpx::finalize();    // Handles HPX shutdown
}
示例#17
0
int hpx_main()
{
    locality_id = hpx::get_locality_id();

    hpx::id_type here = hpx::find_here();
    hpx::id_type there = here;
    if (hpx::get_num_localities_sync() > 1)
    {
        std::vector<hpx::id_type> localities = hpx::find_remote_localities();
        there = localities[0];
    }

    {
        increment_action inc;
        hpx::apply(inc, hpx::colocated(there), here, 1);
    }

    {
        hpx::future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        increment_action inc;
        hpx::apply(inc, hpx::colocated(where), here, 1);
    }

    {
        hpx::future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        hpx::apply<increment_action>(hpx::colocated(where), here, 1);
    }

    // register function which will verify final result
    hpx::register_shutdown_function(on_shutdown);

    HPX_TEST_EQ(hpx::finalize(), 0);

    return 0;
}
示例#18
0
// dereference element to the right of current
void test_right_element_full()
{
    // demonstrate use of 'previous' and 'next' transformers
    std::vector<int> values(10);
    std::iota(boost::begin(values), boost::end(values), 0);

    auto transformer = test::make_next_transformer(
        boost::end(values)-1, &values.front());

    std::ostringstream str;

    std::for_each(
        hpx::util::make_transform_iterator(boost::begin(values), transformer),
        hpx::util::make_transform_iterator(boost::end(values), transformer),
        [&str](int d)
        {
            str << d << " ";
        });

    HPX_TEST_EQ(str.str(), std::string("1 2 3 4 5 6 7 8 9 0 "));
}
示例#19
0
void test_uninitialized_copy_exception(ExPolicy policy, IteratorTag)
{
    BOOST_STATIC_ASSERT(hpx::parallel::is_execution_policy<ExPolicy>::value);

    typedef std::vector<test::count_instances>::iterator base_iterator;
    typedef test::decorated_iterator<base_iterator, IteratorTag>
        decorated_iterator;

    std::vector<test::count_instances> c(10007);
    std::vector<test::count_instances> d(c.size());
    std::iota(boost::begin(c), boost::end(c), std::rand());

    boost::atomic<std::size_t> throw_after(std::rand() % c.size()); //-V104
    test::count_instances::instance_count.store(0);

    bool caught_exception = false;
    try {
        hpx::parallel::uninitialized_copy(policy,
            decorated_iterator(
                boost::begin(c),
                [&throw_after]()
                {
                    if (throw_after-- == 0)
                        throw std::runtime_error("test");
                }),
            decorated_iterator(boost::end(c)),
            boost::begin(d));
        HPX_TEST(false);
    }
    catch (hpx::exception_list const& e) {
        caught_exception = true;
        test::test_num_exceptions<ExPolicy, IteratorTag>::call(policy, e);
    }
    catch (...) {
        HPX_TEST(false);
    }

    HPX_TEST(caught_exception);
    HPX_TEST_EQ(test::count_instances::instance_count.load(), std::size_t(0));
}
示例#20
0
int hpx_main()
{
    std::vector<hpx::id_type> const localities =
        hpx::find_all_localities(foo::get_component_type());

    std::vector<hpx::future<hpx::id_type> > components;
    for (int i = 0; i != NUM_INSTANCES; ++i)
    {
        for (std::size_t j = 0; j != localities.size(); ++j)
        {
            components.push_back(hpx::new_<foo>(localities[j]));
        }
    }
    hpx::wait_all(components);

    for (std::size_t j = 0; j != localities.size(); ++j)
    {
        HPX_TEST_EQ(NUM_INSTANCES, get_count_action()(localities[j]));
    }

    return hpx::finalize();
}
示例#21
0
int hpx_main(boost::program_options::variables_map& vm)
{
    typedef hpx::future<void> wait_for_worker;
    std::vector<wait_for_worker> futures;

    // get locations and start workers
    std::string expected;

    std::vector<hpx::id_type> localities = hpx::find_all_localities();
    for (hpx::id_type const& l : localities)
    {
        futures.push_back(hpx::async(worker_action(), l));
        expected += "hello!\n";
    }

    hpx::register_shutdown_function(hpx::util::bind(&on_shutdown, expected));
    hpx::wait_all(futures);

    HPX_TEST_EQ(hpx::finalize(), 0);

    return 0;
}
示例#22
0
static void cl_test(hpx::opencl::device cldevice)
{

    hpx::opencl::buffer buffer = cldevice.create_buffer(CL_MEM_READ_WRITE,
                                                              DATASIZE,
                                                              initdata);

    // test if buffer initialization worked
    size_t buffer_size = buffer.size().get();
    HPX_TEST_EQ(buffer_size, DATASIZE);

    // read and compare
    TEST_CL_BUFFER(buffer, initdata);

    // create program
    hpx::opencl::program prog = cldevice.create_program_with_source(
                                                                    square_src);

    // build program
    prog.build();

    // create kernel
    hpx::opencl::kernel square_kernel = prog.create_kernel("square");

    // set kernel arg
    square_kernel.set_arg(0, buffer);

    // create work_size
    hpx::opencl::work_size<1> dim;
    dim[0].offset = 3;
    dim[0].size = 5;

    // run kernel
    square_kernel.enqueue(dim).get().await();

    // test if kernel executed successfully
    TEST_CL_BUFFER(buffer, refdata1);

}
示例#23
0
void test(hpx::id_type dest, char* send_buffer, std::size_t size)
{
    typedef Buffer buffer_type;
    buffer_type recv_buffer;

    std::vector<hpx::future<buffer_type> > recv_buffers;
    recv_buffers.reserve(10);

    Action act;
    for(std::size_t j = 0; j != 10; ++j)
    {
        recv_buffers.push_back(hpx::async(act, dest,
            buffer_type(send_buffer, size, buffer_type::reference)));
    }
    hpx::wait_all(recv_buffers);

    for (hpx::future<buffer_type>& f : recv_buffers)
    {
        buffer_type b = f.get();
        HPX_TEST_EQ(b.size(), size);
        HPX_TEST(0 == memcmp(b.data(), send_buffer, size));
    }
}
示例#24
0
bool test_copy_component_here(hpx::id_type id)
{
    // create component on given locality
    test_client t1;
    t1.create(id);
    HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_gid());

    try {
        // create a copy of t1 here
        test_client t2(hpx::components::copy<test_server>(t1.get_gid(), hpx::find_here()));
        HPX_TEST_NEQ(hpx::naming::invalid_id, t2.get_gid());

        // the new object should life here
        HPX_TEST_EQ(t2.call(), hpx::find_here());

        return true;
    }
    catch (hpx::exception const&) {
        HPX_TEST(false);
    }

    return false;
}
示例#25
0
int hpx_main()
{
    boost::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync);

    // count_down_and_wait
    {
        hpx::lcos::latch l = create_latch(num_localities, 0);
        HPX_TEST(!l.is_ready());

        // Wait for all localities to reach this point.
        l.count_down_and_wait();

        HPX_TEST(l.is_ready());
    }

    // count_down/wait
    {
        hpx::lcos::latch l = create_latch(num_localities, 1);
        HPX_TEST(!l.is_ready());

        // Wait for all localities to reach this point.
        if (hpx::get_locality_id() == 0)
        {
            l.count_down_and_wait();
            HPX_TEST(l.is_ready());
        }
        else
        {
            l.count_down(1);
            l.wait();
            HPX_TEST(l.is_ready());
        }
    }

    HPX_TEST_EQ(hpx::finalize(), 0);
    return 0;
}
示例#26
0
bool test_migrate_component_from_storage(hpx::id_type const& source,
    hpx::components::component_storage storage)
{
    hpx::id_type oldid;

    {
        // create component on given locality
        test_client t1(source);
        HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_id());

        // the new object should live on the source locality
        HPX_TEST_EQ(t1.call(), source);

        // remember the original id for later action invocation
        oldid = t1.get_id();

        try {
            // migrate of t1 to the target storage
            test_client t2(hpx::components::migrate_to_storage(t1, storage));
            HPX_TEST_EQ(hpx::naming::invalid_id, t2.get_id());
        }
        catch (hpx::exception const&) {
            return false;
        }

        HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1));
    }

    HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1));

    // The object is stored in the storage now, apply an action which should
    // transparently bring it back.
    {
        test_client t1;
        t1.reset(oldid);

        // transparently resurrect object on the original source locality
        HPX_TEST_EQ(t1.call(), source);

        HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(0));
    }

    return true;
}
示例#27
0
文件: make_future.cpp 项目: 7ev3n/hpx
int main(int argc, char* argv[])
{
    HPX_TEST_EQ(hpx::init(argc, argv), 0);
    return hpx::util::report_errors();
}
示例#28
0
void worker2_ref(tuple_base_type const&t)
{
    HPX_TEST_EQ(hpx::util::get<0>(t), 42);
    HPX_TEST_EQ(hpx::util::get<1>(t), 3.14);
    HPX_TEST_EQ(hpx::util::get<2>(t), "test");
}
示例#29
0
void worker1(tuple_type t)
{
    HPX_TEST_EQ(hpx::util::get<0>(t), 42);
    HPX_TEST_EQ(hpx::util::get<1>(t), 3.14);
    HPX_TEST_EQ(hpx::util::get<2>(t), "test");
}
示例#30
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);
    }
}