Skip to content

Commit

Permalink
Merge pull request #1373 from dcbdan/master
Browse files Browse the repository at this point in the history
 Modifying parallel search algorithm for zero length searches
  • Loading branch information
hkaiser committed Feb 5, 2015
2 parents c523187 + f32fdf4 commit a9bb0e4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hpx/parallel/algorithms/search.hpp
Expand Up @@ -66,7 +66,7 @@ namespace hpx {namespace parallel { HPX_INLINE_NAMESPACE(v1)

s_difference_type diff = std::distance(s_first, s_last);
if (diff <= 0)
return result::get(std::move(last));
return result::get(std::move(first));

difference_type count = std::distance(first, last);
if (diff > count)
Expand Down
1 change: 1 addition & 0 deletions tests/regressions/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ set(subdirs
threads
traits
util
parallel
)

if(HPX_HAVE_CXX11_LAMBDAS)
Expand Down
1 change: 1 addition & 0 deletions tests/regressions/parallel/CMakeLists.txt
Expand Up @@ -5,6 +5,7 @@

set(tests
minimal_findend
search_zerolength
)

foreach(test ${tests})
Expand Down
50 changes: 50 additions & 0 deletions tests/regressions/parallel/search_zerolength.cpp
@@ -0,0 +1,50 @@
// Copyright (c) 2015 Daniel Bourgeois
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/include/parallel_search.hpp>
#include <hpx/util/lightweight_test.hpp>

void search_zero_dist_test()
{
using hpx::parallel::execution_policy;
using hpx::parallel::seq;
using hpx::parallel::par;
using hpx::parallel::search;
using hpx::parallel::task;

typedef std::vector<int>::iterator iterator;

std::vector<int> c(10007);
std::iota(c.begin(), c.end(), 1);
std::vector<int> h(0);

hpx::future<iterator> fut_seq = search(seq(task), c.begin(), c.end(),
h.begin(), h.end());
hpx::future<iterator> fut_par = search(par(task), c.begin(), c.end(),
h.begin(), h.end());

HPX_TEST(fut_seq.get() == c.begin());
HPX_TEST(fut_par.get() == c.begin());
}

int hpx_main()
{
search_zero_dist_test();
return hpx::finalize();
}

int main(int argc, char* argv[])
{
std::vector<std::string> cfg;
cfg.push_back("hpx.os_threads=" + boost::lexical_cast<std::string>
(hpx::threads::hardware_concurrency()));

HPX_TEST_EQ_MSG(hpx::init(argc, argv, cfg), 0,
"HPX main exted with non-zero status");

return hpx::util::report_errors();
}

0 comments on commit a9bb0e4

Please sign in to comment.