Skip to content

Commit

Permalink
Adding unit test for used pu mask.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Heller committed Sep 15, 2017
1 parent 23d9710 commit 1135443
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit/resource/CMakeLists.txt
Expand Up @@ -5,9 +5,11 @@

set(tests
resource_partitioner
used_pus
)

set(resource_partitioner_PARAMETERS THREADS_PER_LOCALITY 4)
set(used_pus_PARAMETERS THREADS_PER_LOCALITY 4)

foreach(test ${tests})
set(sources
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/resource/used_pus.cpp
@@ -0,0 +1,48 @@
// Copyright (c) 2017 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)

// Simple test verifying basic resource_partitioner functionality.

#include <hpx/hpx_init.hpp>
#include <hpx/include/resource_partitioner.hpp>
#include <hpx/include/threads.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <cstddef>
#include <string>
#include <utility>
#include <vector>

int hpx_main(int argc, char* argv[])
{
std::size_t num_threads = hpx::resource::get_num_threads("default");
hpx::threads::detail::thread_pool_base& tp =
hpx::resource::get_thread_pool("default");

auto used_pu_mask = tp.get_used_processing_units();
HPX_TEST_EQ(hpx::threads::count(used_pu_mask), num_threads);

for (std::size_t t = 0; t < num_threads; ++t)
{
auto thread_mask = hpx::resource::get_partitioner().get_pu_mask(t);
HPX_TEST(hpx::threads::bit_or(used_pu_mask, thread_mask));
}

return hpx::finalize();
}

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

// set up the resource partitioner
hpx::resource::partitioner rp(argc, argv, std::move(cfg));

// now run the test
HPX_TEST_EQ(hpx::init(), 0);
return hpx::util::report_errors();
}

0 comments on commit 1135443

Please sign in to comment.