示例#1
0
int main()
{
    X x;

    Y<X> px(&x);
    Y<X const> pcx(&x);

    hpx::util::mem_fn(&X::f0)(px);
    hpx::util::mem_fn(&X::g0)(pcx);

    hpx::util::mem_fn(&X::f1)(px, 1);
    hpx::util::mem_fn(&X::g1)(pcx, 1);

    hpx::util::mem_fn(&X::f2)(px, 1, 2);
    hpx::util::mem_fn(&X::g2)(pcx, 1, 2);

    hpx::util::mem_fn(&X::f3)(px, 1, 2, 3);
    hpx::util::mem_fn(&X::g3)(pcx, 1, 2, 3);

    hpx::util::mem_fn(&X::f4)(px, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::g4)(pcx, 1, 2, 3, 4);

    hpx::util::mem_fn(&X::f5)(px, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);

    hpx::util::mem_fn(&X::f6)(px, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);

    hpx::util::mem_fn(&X::f7)(px, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);

    hpx::util::mem_fn(&X::f8)(px, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);

    HPX_TEST(hash == 2155);

    return hpx::util::report_errors();
}
void test_for_each_async(ExPolicy && p, IteratorTag, Proj && proj)
{
    typedef std::vector<std::size_t>::iterator base_iterator;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<std::size_t> c(10007);
    std::fill(boost::begin(c), boost::end(c), std::size_t(42));

    boost::atomic<std::size_t> count(0);

    hpx::future<iterator> f =
        hpx::parallel::for_each(std::forward<ExPolicy>(p),
            iterator(boost::begin(c)), iterator(boost::end(c)),
            [&count, &proj](std::size_t v) {
                HPX_TEST_EQ(v, proj(std::size_t(42)));
                ++count;
            },
            proj);
    f.wait();

    HPX_TEST(f.get() == iterator(boost::end(c)));
    HPX_TEST_EQ(count, c.size());
}
示例#3
0
void test_for_each_n_async(ExPolicy p, IteratorTag)
{
    typedef std::vector<int>::iterator base_iterator;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<int> c(10007);
    std::iota(std::begin(c), std::end(c), gen());

    hpx::future<iterator> f =
        hpx::parallel::for_each_n(p,
            iterator(std::begin(c)), c.size(),
            set_42());
    HPX_TEST(f.get() == iterator(std::end(c)));

    // verify values
    std::size_t count = 0;
    std::for_each(std::begin(c), std::end(c),
        [&count](int v) -> void {
            HPX_TEST_EQ(v, int(42));
            ++count;
        });
    HPX_TEST_EQ(count, c.size());
}
示例#4
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;
}
示例#5
0
void test_initialization_from_vector(std::size_t max_size)
{
    for (std::size_t size = 1; size <= max_size; size *= 2)
    {
        std::vector<T> send_vec;
        std::vector<T> recv_vec;
        send_vec.reserve(size);
        for (std::size_t i = 0; i < size; ++i) {
            send_vec.push_back(size - i);
        }

        // default init mode is "copy"
        hpx::serialization::serialize_buffer<T> send_buffer(
            send_vec[0], send_vec.size());
        hpx::serialization::serialize_buffer<T> recv_buffer;
        std::copy(send_vec.begin(), send_vec.end(), send_buffer.begin());
        recv_buffer = send_buffer;

        std::copy(recv_buffer.begin(), recv_buffer.end(),
            std::back_inserter(recv_vec));
        HPX_TEST(send_vec == recv_vec);
    }
}
示例#6
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));
    }
}
示例#7
0
void test_sort1_async(ExPolicy && policy, T, Compare comp = Compare())
{
    static_assert(
        hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
        "hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
    msg(typeid(ExPolicy).name(), typeid(T).name(), typeid(Compare).name(),
        async, random);

    // Fill vector with random values
    std::vector<T> c(HPX_SORT_TEST_SIZE);
    rnd_fill<T>(c, (std::numeric_limits<T>::min)(),
        (std::numeric_limits<T>::max)(), T(std::rand()));

    std::uint64_t t = hpx::util::high_resolution_clock::now();
    // sort, non blocking
    hpx::future<void> f = hpx::parallel::sort(std::forward<ExPolicy>(policy),
            c.begin(), c.end(), comp);
    f.get();
    std::uint64_t elapsed = hpx::util::high_resolution_clock::now() - t;

    bool is_sorted = (verify_(c, comp, elapsed, true)!=0);
    HPX_TEST(is_sorted);
}
示例#8
0
void test_sorted2_async(ExPolicy p, IteratorTag)
{
    typedef std::vector<std::size_t>::iterator base_iterator;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<std::size_t> c(10007);
    //Fill with sorted values from 0 to 10006
    std::iota(boost::begin(c), boost::end(c), 0);
    //Add a certain large value in middle of array to ignore
    std::size_t ignore = 20000;
    c[c.size()/2] = ignore;
    //Provide custom predicate to ignore the value of ignore
    //pred should return true when it is given something deemed not sorted
    auto pred = [&ignore](std::size_t ahead, std::size_t behind)
    {
        return behind > ahead && behind != ignore;
    };

    hpx::future<bool> f = hpx::parallel::is_sorted(p,
        iterator(boost::begin(c)), iterator(boost::end(c)), pred);
    f.wait();

    HPX_TEST(f.get());
}
void verify_values(hpx::partitioned_vector<T> v1, std::vector<T> v2)
{
    auto first = v1.begin();
    auto last = v1.end();

    typedef hpx::traits::segmented_iterator_traits<decltype(first)> traits;
    typedef typename traits::segment_iterator segment_iterator;
    typedef typename traits::local_iterator local_iterator_type;

    segment_iterator sit = traits::segment(first);
    segment_iterator send = traits::segment(last);

    auto beg2 = v2.begin();

    std::vector<bool> results;

    for (; sit != send; ++sit)
    {
        local_iterator_type beg = traits::begin(sit);
        local_iterator_type end = traits::end(sit);

        std::vector<T> test(std::distance(beg, end));
        std::copy_n(beg2, test.size(), test.begin());

        results.push_back(
            hpx::parallel::v1::detail::dispatch(traits::get_id(sit),
                verify<bool>(), hpx::parallel::seq, std::true_type(), beg, end, test
        ));

        beg2 += std::distance(beg, end);
    }
    bool final_result = std::all_of(results.begin(), results.end(),
        [](bool v) { return v; });

    HPX_TEST(final_result);
}
示例#10
0
void test_uninitialized_copy_async(ExPolicy && p, IteratorTag)
{
    typedef std::vector<std::size_t>::iterator base_iterator;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

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

    hpx::future<base_iterator> f =
        hpx::parallel::uninitialized_copy(std::forward<ExPolicy>(p),
            iterator(boost::begin(c)), iterator(boost::end(c)),
            boost::begin(d));
    f.wait();

    std::size_t count = 0;
    HPX_TEST(std::equal(boost::begin(c), boost::end(c), boost::begin(d),
        [&count](std::size_t v1, std::size_t v2) -> bool {
            HPX_TEST_EQ(v1, v2);
            ++count;
            return v1 == v2;
        }));
    HPX_TEST_EQ(count, d.size());
}
示例#11
0
文件: get_ptr.cpp 项目: Bcorde5/hpx
int main()
{
    HPX_TEST(test_get_ptr1(hpx::find_here()));
    HPX_TEST(test_get_ptr2(hpx::find_here()));


    std::vector<hpx::id_type> localities = hpx::find_remote_localities();
    for (hpx::id_type const& id : localities)
    {
        HPX_TEST(!hpx::expect_exception());

        HPX_TEST(!test_get_ptr1(id));
        HPX_TEST(!test_get_ptr2(id));

        HPX_TEST(hpx::expect_exception(false));
    }

    return hpx::util::report_errors();
}
示例#12
0
void member_function_test()
{
    X x;

    // 0

    hpx::util::bind(&X::f0, &x)();
    hpx::util::bind(&X::f0, boost::ref(x))();

    hpx::util::bind(&X::g0, &x)();
    hpx::util::bind(&X::g0, x)();
    hpx::util::bind(&X::g0, boost::ref(x))();

    // 1

    hpx::util::bind(&X::f1, &x, 1)();
    hpx::util::bind(&X::f1, boost::ref(x), 1)();

    hpx::util::bind(&X::g1, &x, 1)();
    hpx::util::bind(&X::g1, x, 1)();
    hpx::util::bind(&X::g1, boost::ref(x), 1)();

    // 2

    hpx::util::bind(&X::f2, &x, 1, 2)();
    hpx::util::bind(&X::f2, boost::ref(x), 1, 2)();

    hpx::util::bind(&X::g2, &x, 1, 2)();
    hpx::util::bind(&X::g2, x, 1, 2)();
    hpx::util::bind(&X::g2, boost::ref(x), 1, 2)();

    // 3

    hpx::util::bind(&X::f3, &x, 1, 2, 3)();
    hpx::util::bind(&X::f3, boost::ref(x), 1, 2, 3)();

    hpx::util::bind(&X::g3, &x, 1, 2, 3)();
    hpx::util::bind(&X::g3, x, 1, 2, 3)();
    hpx::util::bind(&X::g3, boost::ref(x), 1, 2, 3)();

    // 4

    hpx::util::bind(&X::f4, &x, 1, 2, 3, 4)();
    hpx::util::bind(&X::f4, boost::ref(x), 1, 2, 3, 4)();

    hpx::util::bind(&X::g4, &x, 1, 2, 3, 4)();
    hpx::util::bind(&X::g4, x, 1, 2, 3, 4)();
    hpx::util::bind(&X::g4, boost::ref(x), 1, 2, 3, 4)();

    // 5

    hpx::util::bind(&X::f5, &x, 1, 2, 3, 4, 5)();
    hpx::util::bind(&X::f5, boost::ref(x), 1, 2, 3, 4, 5)();

    hpx::util::bind(&X::g5, &x, 1, 2, 3, 4, 5)();
    hpx::util::bind(&X::g5, x, 1, 2, 3, 4, 5)();
    hpx::util::bind(&X::g5, boost::ref(x), 1, 2, 3, 4, 5)();

    // 6

    hpx::util::bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
    hpx::util::bind(&X::f6, boost::ref(x), 1, 2, 3, 4, 5, 6)();

    hpx::util::bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
    hpx::util::bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
    hpx::util::bind(&X::g6, boost::ref(x), 1, 2, 3, 4, 5, 6)();

    // 7

    hpx::util::bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
    hpx::util::bind(&X::f7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();

    hpx::util::bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
    hpx::util::bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
    hpx::util::bind(&X::g7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();

    // 8

    hpx::util::bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
    hpx::util::bind(&X::f8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();

    hpx::util::bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
    hpx::util::bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
    hpx::util::bind(&X::g8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();

    HPX_TEST( x.hash == 23558 );
}
示例#13
0
int hpx_main()
{
    // count_down_and_wait
    {
        hpx::lcos::local::latch l(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));

        HPX_TEST(!l.is_ready());

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

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // count_down
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        hpx::future<void> f = hpx::async(&test_count_down, std::ref(l));

        HPX_TEST(!l.is_ready());
        l.count_down_and_wait();

        f.get();

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), std::size_t(1));
    }

    // wait
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(NUM_THREADS);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));

        hpx::wait_all(results);

        l.wait();

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // count_up
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
            l.count_up(1);
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
        }

        HPX_TEST(!l.is_ready());

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

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // reset
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(0);
        l.reset(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
        }

        HPX_TEST(!l.is_ready());

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

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    HPX_TEST_EQ(hpx::finalize(), 0);
    return 0;
}
void bulk_test( hpx::lcos::spmd_block block,
                std::size_t size_x,
                std::size_t size_y,
                std::size_t size_z,
                std::size_t elt_size,
                std::string vec_name)
{
    using const_iterator
        = typename std::vector<double>::const_iterator;
    using vector_type
        = hpx::partitioned_vector<double>;
    using view_type
        = hpx::partitioned_vector_view<double,3>;
    using view_type_iterator
        = typename view_type::iterator;
    using const_view_type_iterator
        = typename view_type::const_iterator;

    vector_type my_vector;
    my_vector.connect_to(hpx::launch::sync, vec_name);

    view_type my_view(block,
        my_vector.begin(), my_vector.end(), {size_x,size_y,size_z});

    int idx = 0;

    // Ensure that only one image is putting data into the different
    // partitions
    if(block.this_image() == 0)
    {
        // Traverse all the co-indexed elements
        for(auto i = my_view.begin(); i != my_view.end(); i++)
        {
            // It's a Put operation
            *i = std::vector<double>(elt_size,idx++);
        }

        auto left_it  = my_view.begin();
        auto right_it = my_view.cbegin();

        // Note: Useless computation, since we assign segments to themselves
        for(; left_it != my_view.end(); left_it++, right_it++)
        {
            // Check that dereferencing iterator and const_iterator does not
            // retrieve the same type
            HPX_TEST((
                !std::is_same<decltype(*left_it),decltype(*right_it)>::value));

            // It's a Put operation
            *left_it = *right_it;
        }
    }

    block.sync_all();

    if(block.this_image() == 0)
    {
        int idx = 0;

        for (std::size_t k = 0; k<size_z; k++)
            for (std::size_t j = 0; j<size_y; j++)
                for (std::size_t i = 0; i<size_x; i++)
                {
                    std::vector<double> result(elt_size,idx);

                    // It's a Get operation
                    std::vector<double> value =
                        (std::vector<double>)my_view(i,j,k);

                    const_iterator it1 = result.begin(), it2 = value.begin();
                    const_iterator end1 = result.end();

                    for (; it1 != end1; ++it1, ++it2)
                    {
                        HPX_TEST_EQ(*it1, *it2);
                    }

                    idx++;
                }

        idx = 0;

        // Re-check by traversing all the co-indexed elements
        for(auto i = my_view.cbegin(); i != my_view.cend(); i++)
        {
            std::vector<double> result(elt_size,idx);

            // It's a Get operation
            std::vector<double> value = (std::vector<double>)(*i);

            const_iterator it1 = result.begin(), it2 = value.begin();
            const_iterator end1 = result.end();

            for (; it1 != end1; ++it1, ++it2)
            {
                HPX_TEST_EQ(*it1, *it2);
            }

            idx++;
        }
    }
}
bool test_local_priority_queue_scheduler(hpx::util::section& ini)
{
    // load all components as described in the configuration information
    if (!ini.has_section("hpx.plugins"))
    {
        std::cout << "No plugins found/loaded." << std::endl;
        return true;     // no plugins to load
    }

    // each shared library containing plugins may have an ini section
    //
    // # mandatory section describing the component module
    // [hpx.plugins.instance_name]
    //  name = ...           # the name of this component module
    //  path = ...           # the path where to find this component module
    //  enabled = false      # optional (default is assumed to be true)
    //
    // # optional section defining additional properties for this module
    // [hpx.plugins.instance_name.settings]
    //  key = value
    //
    hpx::util::section* sec = ini.get_section("hpx.plugins");
    if (NULL == sec)
    {
        std::cout << "NULL section found" << std::endl;
        return false;     // something bad happened
    }

    hpx::util::section::section_map const& s = (*sec).get_sections();
    typedef hpx::util::section::section_map::const_iterator iterator;

    iterator end = s.end();
    for (iterator i = s.begin (); i != end; ++i)
    {
        // the section name is the instance name of the component
        hpx::util::section const& sect = i->second;
        std::string instance (sect.get_name());
        std::string component;

        if (i->second.has_entry("name"))
            component = sect.get_entry("name");
        else
            component = instance;

        if (sect.has_entry("enabled"))
        {
            std::string tmp = sect.get_entry("enabled");
            boost::algorithm::to_lower(tmp);
            if (tmp == "no" || tmp == "false" || tmp == "0")
            {
                std::cout << "plugin factory disabled: " << instance << std::endl;
                continue;     // this plugin has been disabled
            }
        }

        // initialize the factory instance using the preferences from the
        // ini files
        hpx::util::section const* glob_ini = NULL;
        if (ini.has_section("settings"))
            glob_ini = ini.get_section("settings");

        hpx::util::section const* plugin_ini = NULL;
        std::string plugin_section("hpx.plugins." + instance);
        if (ini.has_section(plugin_section))
            plugin_ini = ini.get_section(plugin_section);

        boost::filesystem::path lib_path;
        std::string component_path = sect.get_entry("path");

        typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
        boost::char_separator<char> sep(HPX_INI_PATH_DELIMITER);
        tokenizer tokens(component_path, sep);
        boost::system::error_code fsec;
        for(tokenizer::iterator it = tokens.begin(); it != tokens.end(); ++it)
        {
            boost::filesystem::path dir = boost::filesystem::path(*it);
            lib_path = dir / std::string(HPX_MAKE_DLL_STRING(component));
            if(boost::filesystem::exists(lib_path, fsec))
            {
                break;
            }
            lib_path.clear();
        }

        if (lib_path.string().empty())
            continue;       // didn't find this plugin

        hpx::util::plugin::dll module(lib_path.string(), HPX_MANGLE_STRING(component));

        // get the factory
        typedef hpx::threads::policies::scheduler_plugin_factory_base fbase;
        hpx::util::plugin::plugin_factory<fbase> pf(module, "scheduler_factory");

        try {
            // create the plugin factory object, if not disabled
            std::shared_ptr<fbase> factory (
                pf.create(instance, glob_ini, plugin_ini, true));

            // use factory to create an instance of the plugin
            std::shared_ptr<hpx::threads::policies::scheduler_base
                > plugin(factory->create());

            // now test for local priority queue scheduler plugin
            typedef hpx::threads::policies::local_priority_queue_scheduler<> lpq;
            hpx::threads::policies::scheduler_base* base = plugin.get();
            HPX_TEST(dynamic_cast<lpq*>(base) != NULL);
        }
        catch(...) {
            // different type of factory (not "example_factory"), ignore here
            HPX_TEST(false);
        }
    }
    return true;
}
示例#16
0
void function_test()
{
    int const i = 1;

    HPX_TEST( test( hpx::util::bind(f_0), i ) == 17041L );
    HPX_TEST( test( hpx::util::bind(f_1, placeholders::_1), i ) == 1L );
    HPX_TEST( test( hpx::util::bind(f_2, placeholders::_1, 2), i ) == 21L );
    HPX_TEST( test( hpx::util::bind(f_3, placeholders::_1, 2, 3), i ) == 321L );
    HPX_TEST( test( hpx::util::bind(f_4, placeholders::_1, 2, 3, 4), i ) == 4321L );
    HPX_TEST( test( hpx::util::bind(f_5, placeholders::_1, 2, 3, 4, 5), i ) == 54321L );
    HPX_TEST( test( hpx::util::bind(f_6, placeholders::_1, 2, 3, 4, 5,
        6), i ) == 654321L );
    HPX_TEST( test( hpx::util::bind(f_7, placeholders::_1, 2, 3, 4, 5,
        6, 7), i ) == 7654321L );
    HPX_TEST( test( hpx::util::bind(f_8, placeholders::_1, 2, 3, 4, 5,
        6, 7, 8), i ) == 87654321L );
    HPX_TEST( test( hpx::util::bind(f_9, placeholders::_1, 2, 3, 4, 5,
        6, 7, 8, 9), i ) == 987654321L );

    HPX_TEST( testv( hpx::util::bind(fv_0), i ) == 17041L );
    HPX_TEST( testv( hpx::util::bind(fv_1, placeholders::_1), i ) == 1L );
    HPX_TEST( testv( hpx::util::bind(fv_2, placeholders::_1, 2), i ) == 21L );
    HPX_TEST( testv( hpx::util::bind(fv_3, placeholders::_1, 2, 3), i ) == 321L );
    HPX_TEST( testv( hpx::util::bind(fv_4, placeholders::_1, 2, 3, 4), i ) == 4321L );
    HPX_TEST( testv( hpx::util::bind(fv_5, placeholders::_1, 2, 3, 4, 5),
        i ) == 54321L );
    HPX_TEST( testv( hpx::util::bind(fv_6, placeholders::_1, 2, 3, 4, 5,
        6), i ) == 654321L );
    HPX_TEST( testv( hpx::util::bind(fv_7, placeholders::_1, 2, 3, 4, 5,
        6, 7), i ) == 7654321L );
    HPX_TEST( testv( hpx::util::bind(fv_8, placeholders::_1, 2, 3, 4, 5,
        6, 7, 8), i ) == 87654321L );
    HPX_TEST( testv( hpx::util::bind(fv_9, placeholders::_1, 2, 3, 4, 5,
        6, 7, 8, 9), i ) == 987654321L );
}
示例#17
0
void test_can_lock_upgrade_if_currently_locked_shared()
{
    typedef hpx::lcos::local::shared_mutex shared_mutex_type;
    typedef hpx::lcos::local::mutex mutex_type;

    test::thread_group pool;

    shared_mutex_type rw_mutex;
    unsigned unblocked_count = 0;
    unsigned simultaneous_running_count = 0;
    unsigned max_simultaneous_running = 0;
    mutex_type unblocked_count_mutex;
    hpx::lcos::local::condition_variable unblocked_condition;
    mutex_type finish_mutex;
    boost::unique_lock<mutex_type> finish_lock(finish_mutex);

    unsigned const reader_count = 10;

    try
    {
        for(unsigned i = 0; i != reader_count; ++i)
        {
            pool.create_thread(
                test::locking_thread<boost::shared_lock<shared_mutex_type> >(
                    rw_mutex, unblocked_count,  unblocked_count_mutex,
                    unblocked_condition, finish_mutex,
                    simultaneous_running_count, max_simultaneous_running
                )
            );
        }

        hpx::this_thread::sleep_for(boost::chrono::seconds(1));

        pool.create_thread(
            test::locking_thread<boost::upgrade_lock<shared_mutex_type> >(
                rw_mutex, unblocked_count, unblocked_count_mutex,
                unblocked_condition, finish_mutex,
                simultaneous_running_count, max_simultaneous_running
            )
        );

        {
            boost::unique_lock<mutex_type> lk(unblocked_count_mutex);
            while(unblocked_count < (reader_count + 1))
            {
                unblocked_condition.wait(lk);
            }
        }

        CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,
            unblocked_count, reader_count + 1);

        finish_lock.unlock();
        pool.join_all();
    }
    catch(...)
    {
        pool.interrupt_all();
        pool.join_all();
        HPX_TEST(false);
    }

    CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,
        unblocked_count, reader_count + 1);
    CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,
        max_simultaneous_running, reader_count + 1);
}
示例#18
0
template<class F> void test(F f, int a, int b)
{
    HPX_TEST( f() == a +   b );
    HPX_TEST( f() == a + 2*b );
    HPX_TEST( f() == a + 3*b );
}
示例#19
0
std::vector<hpx::id_type> test_binpacking_multiple()
{
    std::vector<hpx::id_type> keep_alive;

    // create an increasing number of instances on all available localities
    std::vector<std::vector<hpx::id_type> > targets;

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

    for (std::size_t i = 0; i != localities.size(); ++i)
    {
        hpx::id_type const& loc = localities[i];

        targets.push_back(hpx::new_<test_server[]>(loc, i + 1).get());
        for (hpx::id_type const& id: targets.back())
        {
            HPX_TEST(hpx::async<call_action>(id).get() == loc);
            keep_alive.push_back(id);
        }
    }

    std::string counter_name(hpx::components::default_binpacking_counter_name);
    counter_name += "test_server";

    std::uint64_t count = 0;
    for (std::size_t i = 0; i != localities.size(); ++i)
    {
        hpx::performance_counters::performance_counter instances(
            counter_name, localities[i]);

        std::uint64_t c = instances.get_value<std::uint64_t>(hpx::launch::sync);
        count += c;
        HPX_TEST_EQ(c, i + 1);
    }

    HPX_TEST_EQ(count, keep_alive.size());

    // now use bin-packing policy to fill up the number of instances
    std::vector<hpx::id_type> filled_targets =
        hpx::new_<test_server[]>(hpx::binpacked(localities), count).get();

    // now, all localities should have the same number of instances
    std::uint64_t new_count = 0;
    for (std::size_t i = 0; i != localities.size(); ++i)
    {
        hpx::performance_counters::performance_counter instances(
            counter_name, localities[i]);

        std::uint64_t c =
            instances.get_value<std::uint64_t>(hpx::launch::sync);
        new_count += c;
        HPX_TEST_EQ(c, localities.size() + 1);
    }

    HPX_TEST_EQ(2*count, new_count);

    for (hpx::id_type const& id: filled_targets)
        keep_alive.push_back(id);

    return keep_alive;
}
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;
}
示例#21
0
void test_nullary()
{
    hpx::future<A> f1 = hpx::make_ready_future<A>();
    HPX_TEST(f1.is_ready());
}
 void update()
 {
     HPX_TEST(this->get_unmanaged_id());
     std::cout << "update() at viewer "
         << this->get_unmanaged_id() << std::endl;
 }
示例#23
0
int main()
{
    X x;

    X const & rcx = x;
    X const * pcx = &x;

    boost::shared_ptr<X> sp(new X);

    hpx::util::mem_fn(&X::f0)(x);
    hpx::util::mem_fn(&X::f0)(&x);
    hpx::util::mem_fn(&X::f0)(sp);

    hpx::util::mem_fn(&X::g0)(x);
    hpx::util::mem_fn(&X::g0)(rcx);
    hpx::util::mem_fn(&X::g0)(&x);
    hpx::util::mem_fn(&X::g0)(pcx);
    hpx::util::mem_fn(&X::g0)(sp);

    hpx::util::mem_fn(&X::f1)(x, 1);
    hpx::util::mem_fn(&X::f1)(&x, 1);
    hpx::util::mem_fn(&X::f1)(sp, 1);

    hpx::util::mem_fn(&X::g1)(x, 1);
    hpx::util::mem_fn(&X::g1)(rcx, 1);
    hpx::util::mem_fn(&X::g1)(&x, 1);
    hpx::util::mem_fn(&X::g1)(pcx, 1);
    hpx::util::mem_fn(&X::g1)(sp, 1);

    hpx::util::mem_fn(&X::f2)(x, 1, 2);
    hpx::util::mem_fn(&X::f2)(&x, 1, 2);
    hpx::util::mem_fn(&X::f2)(sp, 1, 2);

    hpx::util::mem_fn(&X::g2)(x, 1, 2);
    hpx::util::mem_fn(&X::g2)(rcx, 1, 2);
    hpx::util::mem_fn(&X::g2)(&x, 1, 2);
    hpx::util::mem_fn(&X::g2)(pcx, 1, 2);
    hpx::util::mem_fn(&X::g2)(sp, 1, 2);

    hpx::util::mem_fn(&X::f3)(x, 1, 2, 3);
    hpx::util::mem_fn(&X::f3)(&x, 1, 2, 3);
    hpx::util::mem_fn(&X::f3)(sp, 1, 2, 3);

    hpx::util::mem_fn(&X::g3)(x, 1, 2, 3);
    hpx::util::mem_fn(&X::g3)(rcx, 1, 2, 3);
    hpx::util::mem_fn(&X::g3)(&x, 1, 2, 3);
    hpx::util::mem_fn(&X::g3)(pcx, 1, 2, 3);
    hpx::util::mem_fn(&X::g3)(sp, 1, 2, 3);

    hpx::util::mem_fn(&X::f4)(x, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::f4)(&x, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::f4)(sp, 1, 2, 3, 4);

    hpx::util::mem_fn(&X::g4)(x, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::g4)(&x, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
    hpx::util::mem_fn(&X::g4)(sp, 1, 2, 3, 4);

    hpx::util::mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);

    hpx::util::mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
    hpx::util::mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);

    hpx::util::mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);

    hpx::util::mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
    hpx::util::mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);

    hpx::util::mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);

    hpx::util::mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
    hpx::util::mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);

    hpx::util::mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);

    hpx::util::mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
    hpx::util::mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);

    HPX_TEST(hpx::util::mem_fn(&X::hash)(x) == 17610);
    HPX_TEST(hpx::util::mem_fn(&X::hash)(sp) == 2155);

    return hpx::util::report_errors();
}
示例#24
0
int hpx_main()
{
    {
        HPX_TEST(!test_simple_server1::alive);
        HPX_TEST(!test_simple_server2::alive);

        // creating test_server2 instance
        hpx::id_type server2 = hpx::new_<test_simple_server2>(hpx::find_here()).get();
        HPX_TEST(!test_simple_server1::alive);
        HPX_TEST(test_simple_server2::alive);

        // creating test_server1 instance
        hpx::id_type server1 = hpx::async(
            test_simple_server2::create_test_server1_action(), server2).get();
        server2 = hpx::invalid_id;
        ensure_garbage_collect();

        HPX_TEST(test_simple_server1::alive);
        HPX_TEST(test_simple_server2::alive);

        test_simple_server1::test_action()(server1);
        server1 = hpx::invalid_id;
        ensure_garbage_collect();
    }
    {
        HPX_TEST(!test_managed_server1::alive);
        HPX_TEST(!test_managed_server2::alive);

        // creating test_server2 instance
        hpx::id_type server2 = hpx::new_<test_managed_server2>(hpx::find_here()).get();
        HPX_TEST(!test_managed_server1::alive);
        HPX_TEST(test_managed_server2::alive);

        // creating test_server1 instance
        hpx::id_type server1 = hpx::async(
            test_managed_server2::create_test_server1_action(), server2).get();
        server2 = hpx::invalid_id;
        ensure_garbage_collect();

        HPX_TEST(test_managed_server1::alive);
        HPX_TEST(test_managed_server2::alive);

        test_managed_server1::test_action()(server1);
        server1 = hpx::invalid_id;
        ensure_garbage_collect();
    }

    return hpx::finalize();
}
示例#25
0
template<class F> void test(F f, int r)
{
    F const & cf = f;
    HPX_TEST( cf() == -r );
    HPX_TEST( f() == r );
}
示例#26
0
 ~test_server()
 {
     HPX_TEST(!destructor_called);
     destructor_called = true;
 }
示例#27
0
template<class F, class A1, class R> void test( F f, A1 a1, R r )
{
    HPX_TEST( f(a1) == r );
}
示例#28
0
void test_sort_exception_async(ExPolicy && policy, T, Compare comp)
{
    static_assert(
        hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
        "hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
    msg(typeid(ExPolicy).name(), typeid(T).name(), typeid(Compare).name(),
        async, random);

    // Fill vector with random values
    std::vector<T> c(5000);
    rnd_fill<T>(c, (std::numeric_limits<T>::min)(),
        (std::numeric_limits<T>::max)(), T(std::rand()));

    {
        // sort, blocking when seq, par, par_vec
        bool caught_exception = false;
        bool returned_from_algorithm = false;
        try {
            typedef typename std::vector<T>::iterator base_iterator;
            typedef test::decorated_iterator<
                    base_iterator, std::random_access_iterator_tag
                > decorated_iterator;

            hpx::future<void> f =
                hpx::parallel::sort(std::forward<ExPolicy>(policy),
                    decorated_iterator(
                        c.begin(), [](){ throw std::runtime_error("test"); }),
                    decorated_iterator(c.end()),
                    comp);

            returned_from_algorithm = true;
            f.get();

            HPX_TEST(false);
        }
        catch(hpx::exception_list const&) {
            caught_exception = true;
        }
        catch(...) {
            HPX_TEST(false);
        }

        HPX_TEST(caught_exception);
        HPX_TEST(returned_from_algorithm);
        if (caught_exception && returned_from_algorithm)
            std::cout << "OK, ";
        else
            std::cout << "Failed, ";
    }

    {
        // sort, blocking when seq, par, par_vec
        bool caught_exception = false;
        bool returned_from_algorithm = false;
        try {
            typedef typename std::vector<T>::iterator base_iterator;
            typedef test::decorated_iterator<
                    base_iterator, std::random_access_iterator_tag
                > decorated_iterator;

            hpx::future<void> f =
                hpx::parallel::sort(std::forward<ExPolicy>(policy),
                    decorated_iterator(
                        c.begin(), [](){ throw std::bad_alloc(); }),
                    decorated_iterator(c.end()),
                    comp);

            returned_from_algorithm = true;
            f.get();

            HPX_TEST(false);
        }
        catch(std::bad_alloc const&) {
            caught_exception = true;
        }
        catch(...) {
            HPX_TEST(false);
        }

        HPX_TEST(caught_exception);
        HPX_TEST(returned_from_algorithm);
        if (caught_exception && returned_from_algorithm)
            std::cout << "OK " << std::endl;
        else
            std::cout << "Failed " << std::endl;
    }
}
示例#29
0
文件: new_.cpp 项目: Bcorde5/hpx
void test_create_multiple_instances()
{
    // make sure created objects live on locality they are supposed to be
    for (hpx::id_type const& loc: hpx::find_all_localities())
    {
        std::vector<hpx::id_type> ids = hpx::new_<test_server[]>(loc, 10).get();
        HPX_TEST_EQ(ids.size(), std::size_t(10));

        for (hpx::id_type const& id: ids)
        {
            HPX_TEST(hpx::async<call_action>(id).get() == loc);
        }
    }

    for (hpx::id_type const& loc: hpx::find_all_localities())
    {
        std::vector<test_client> ids = hpx::new_<test_client[]>(loc, 10).get();
        HPX_TEST_EQ(ids.size(), std::size_t(10));

        for (test_client const& c: ids)
        {
            HPX_TEST(c.call() == loc);
        }
    }

    // make sure distribution policy is properly used
    std::vector<hpx::id_type> ids =
        hpx::new_<test_server[]>(hpx::default_layout, 10).get();
    HPX_TEST_EQ(ids.size(), std::size_t(10));
    for (hpx::id_type const& id: ids)
    {
        HPX_TEST(hpx::async<call_action>(id).get() == hpx::find_here());
    }

    std::vector<test_client> clients =
        hpx::new_<test_client[]>(hpx::default_layout, 10).get();
    HPX_TEST_EQ(clients.size(), std::size_t(10));
    for (test_client const& c: clients)
    {
        HPX_TEST(c.call() == hpx::find_here());
    }

    for (hpx::id_type const& loc: hpx::find_all_localities())
    {
        std::vector<hpx::id_type> ids =
            hpx::new_<test_server[]>(hpx::default_layout(loc), 10).get();
        HPX_TEST_EQ(ids.size(), std::size_t(10));

        for (hpx::id_type const& id: ids)
        {
            HPX_TEST(hpx::async<call_action>(id).get() == loc);
        }
    }

    for (hpx::id_type const& loc: hpx::find_all_localities())
    {
        std::vector<test_client> ids =
            hpx::new_<test_client[]>(hpx::default_layout(loc), 10).get();
        HPX_TEST_EQ(ids.size(), std::size_t(10));

        for (test_client const& c: ids)
        {
            HPX_TEST(c.call() == loc);
        }
    }
}
示例#30
0
void test_server1<ComponentBase>::test()
{
    HPX_TEST(test_server2<ComponentBase>::alive);
    HPX_TEST(other);
}