Skip to content

Commit

Permalink
Adding test reproducing the issue
Browse files Browse the repository at this point in the history
- disambiguate calls to hpx::util::invoke in merge algorithm
  • Loading branch information
hkaiser committed Nov 4, 2017
1 parent cbc0a13 commit a89256b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
22 changes: 8 additions & 14 deletions hpx/parallel/algorithms/merge.hpp
Expand Up @@ -52,15 +52,13 @@ namespace hpx { namespace parallel { inline namespace v1
InIter2 first2, InIter2 last2,
OutIter dest, Comp && comp, Proj1 && proj1, Proj2 && proj2)
{
using hpx::util::invoke;

if (first1 != last1 && first2 != last2)
{
while (true)
{
if (invoke(comp,
invoke(proj2, *first2),
invoke(proj1, *first1)))
if (hpx::util::invoke(comp,
hpx::util::invoke(proj2, *first2),
hpx::util::invoke(proj1, *first1)))
{
*dest++ = *first2++;
if (first2 == last2)
Expand Down Expand Up @@ -91,16 +89,15 @@ namespace hpx { namespace parallel { inline namespace v1
typedef typename std::iterator_traits<RandIter>::difference_type
difference_type;

using hpx::util::invoke;

difference_type count = std::distance(first, last);

while (count > 0)
{
difference_type step = count / 2;
RandIter mid = std::next(first, step);

if (!invoke(comp, value, invoke(proj, *mid)))
if (!hpx::util::invoke(
comp, value, hpx::util::invoke(proj, *mid)))
{
first = ++mid;
count -= step + 1;
Expand Down Expand Up @@ -128,16 +125,15 @@ namespace hpx { namespace parallel { inline namespace v1
typedef typename std::iterator_traits<RandIter>::difference_type
difference_type;

using hpx::util::invoke;

difference_type count = std::distance(first, last);

while (count > 0)
{
difference_type step = count / 2;
RandIter mid = std::next(first, step);

if (invoke(comp, invoke(proj, *mid), value))
if (hpx::util::invoke(
comp, hpx::util::invoke(proj, *mid), value))
{
first = ++mid;
count -= step + 1;
Expand Down Expand Up @@ -168,8 +164,6 @@ namespace hpx { namespace parallel { inline namespace v1
RandIter3 dest, Comp comp,
Proj1 proj1, Proj2 proj2, BinarySearchHelper)
{
using hpx::util::invoke;

const std::size_t threshold = 65536ul;
HPX_ASSERT(threshold >= 1ul);

Expand Down Expand Up @@ -200,7 +194,7 @@ namespace hpx { namespace parallel { inline namespace v1

RandIter1 mid1 = first1 + size1 / 2;
RandIter2 boundary2 = BinarySearchHelper::call(
first2, last2, invoke(proj1, *mid1), comp, proj2);
first2, last2, hpx::util::invoke(proj1, *mid1), comp, proj2);
RandIter3 target = dest + (mid1 - first1) + (boundary2 - first2);

*target = *mid1;
Expand Down
1 change: 1 addition & 0 deletions tests/regressions/parallel/CMakeLists.txt
Expand Up @@ -11,6 +11,7 @@ set(tests
scan_non_commutative
scan_shortlength
search_zerolength
stable_merge_2964
static_chunker_2282
)

Expand Down
65 changes: 65 additions & 0 deletions tests/regressions/parallel/stable_merge_2964.cpp
@@ -0,0 +1,65 @@
// Copyright (c) 2017 Jeff Trull
//
// 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/parallel/algorithms/merge.hpp>

#include <iostream>

int main(int argc, char* argv[])
{
// By default this should run on all available cores
std::vector<std::string> const cfg = {
"hpx.os_threads=1"
};

// Initialize and run HPX
return hpx::init(argc, argv, cfg);
}

int hpx_main(int argc, char **argv)
{
// these two vectors are sorted by the first value of each tuple
std::vector<std::tuple<int, char>> a1{
{1, 'a'},
{2, 'b'},
{3, 'a'},
{3, 'b'},
{4, 'a'},
{5, 'a'},
{5, 'b'}
};
std::vector<std::tuple<int, char>> a2{
{0, 'c'},
{3, 'c'},
{4, 'c'},
{5, 'c'}
};

std::vector<std::tuple<int, char>> result(a1.size() + a2.size());

// I expect a stable merge to order {3, 'a'} and {3, 'b'} before {3, 'c'}
// because they come from the first sequence
using namespace hpx::parallel;
using namespace hpx::util;
merge(execution::par,
a1.begin(), a1.end(),
a2.begin(), a2.end(),
result.begin(),
[](auto const& a, auto const& b)
{
return std::get<0>(a) < std::get<0>(b);
});

std::for_each(result.begin(), result.end(),
[](auto const& a)
{
std::cout << "(" << std::get<0>(a) << ", " << std::get<1>(a) << ") ";
});
std::cout << "\n";

return hpx::finalize();
}
3 changes: 2 additions & 1 deletion tests/unit/resource/throttle.cpp
Expand Up @@ -89,7 +89,8 @@ int hpx_main(int argc, char* argv[])
// hpx::util::high_resolution_timer t;
// while (t.elapsed() < 2)
// {
// for (std::size_t i = 0; i < hpx::resource::get_num_threads("default") * 10; ++i)
// for (std::size_t i = 0; i < hpx::resource::get_num_threads("default") * 10;
// ++i)
// {
// fs.push_back(hpx::async([](){}));
// }
Expand Down

0 comments on commit a89256b

Please sign in to comment.