Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making sure for_loop(par, 0, N, ...) is actually executed in parallel #2295

Merged
merged 1 commit into from Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
45 changes: 45 additions & 0 deletions tests/regressions/parallel/for_loop_2281.cpp
@@ -0,0 +1,45 @@
// 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>

#include <mutex>
#include <set>
#include <string>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
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();
}