Skip to content

Commit

Permalink
Making sure for_loop(par, 0, N, ...) is actually executed in parallel
Browse files Browse the repository at this point in the history
- flyby: fixing typo
  • Loading branch information
hkaiser committed Aug 14, 2016
1 parent 1b7acf0 commit 11243da
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hpx/parallel/algorithms/for_loop.hpp
Expand Up @@ -232,9 +232,13 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v2)
hpx::traits::is_bidirectional_iterator<E>::value);
}

// the for_loop should be executed sequentially either if the
// execution policy enforces sequential execution of if the
// loop boundaries are input or output iterators
typedef std::integral_constant<bool,
is_sequential_execution_policy<ExPolicy>::value ||
!hpx::traits::is_forward_iterator<B>::value
(!std::is_integral<B>::value &&
!hpx::traits::is_forward_iterator<B>::value)
> is_seq;

std::size_t size = parallel::v1::detail::distance(first, last);
Expand Down
3 changes: 2 additions & 1 deletion tests/regressions/parallel/CMakeLists.txt
@@ -1,9 +1,10 @@
# Copyright (c) 2014-2015 Hartmut Kaiser
# Copyright (c) 2014-2016 Hartmut Kaiser
#
# 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)

set(tests
for_loop_2281
minimal_findend
scan_different_inits
scan_non_commutative
Expand Down
40 changes: 40 additions & 0 deletions tests/regressions/parallel/for_loop_2281.cpp
@@ -0,0 +1,40 @@
// Copyright (c) 2016 Hartmut Kaiser
//
// 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_for_loop.hpp>
#include <hpx/util/lightweight_test.hpp>

///////////////////////////////////////////////////////////////////////////////
int hpx_main()
{
hpx::lcos::local::spinlock mtx;
std::set<hpx::thread::id> thread_ids;

hpx::parallel::for_loop(
hpx::parallel::par, 0, 100,
[&](int i)
{
std::lock_guard<hpx::lcos::local::spinlock> l(mtx);
thread_ids.insert(hpx::this_thread::get_id());
});

HPX_TEST(thread_ids.size() > std::size_t(1));

return hpx::finalize();
}

int main(int argc, char* argv[])
{
std::vector<std::string> const cfg = {
"hpx.os_threads=4"
};

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

return hpx::util::report_errors();
}
2 changes: 1 addition & 1 deletion tests/regressions/parallel/minimal_findend.cpp
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char* argv[])
};

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

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

0 comments on commit 11243da

Please sign in to comment.