|
| 1 | +// Copyright (c) 2026 Mo'men Samir |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: BSL-1.0 |
| 4 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + |
| 7 | +// Regression test to make sure default distribution policy works correctly |
| 8 | +// when the number of localities is more than the number partitions |
| 9 | + |
| 10 | +#include <hpx/config.hpp> |
| 11 | +#if !defined(HPX_COMPUTE_DEVICE_CODE) |
| 12 | +#include <hpx/hpx_main.hpp> |
| 13 | +#include <hpx/include/partitioned_vector_predef.hpp> |
| 14 | +#include <hpx/include/runtime.hpp> |
| 15 | +#include <hpx/modules/testing.hpp> |
| 16 | + |
| 17 | +#include <cstddef> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +/////////////////////////////////////////////////////////////////////////////// |
| 21 | +template <typename T, typename InIter> |
| 22 | +void verify_values(InIter first, InIter last, T const& val) |
| 23 | +{ |
| 24 | + for (InIter it = first; it != last; ++it) |
| 25 | + { |
| 26 | + HPX_TEST_EQ(*it, val); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +template <typename T> |
| 31 | +void test_with_policy(std::size_t length, std::size_t num_partitions, |
| 32 | + std::vector<hpx::id_type> const& localities) |
| 33 | +{ |
| 34 | + hpx::partitioned_vector<T> v( |
| 35 | + length, T(42), hpx::container_layout(num_partitions, localities)); |
| 36 | + |
| 37 | + verify_values(v.begin(), v.end(), T(42)); |
| 38 | + HPX_TEST_EQ(v.size(), length); |
| 39 | +} |
| 40 | + |
| 41 | +template <typename T> |
| 42 | +void test_partition_locality_combinations() |
| 43 | +{ |
| 44 | + std::vector<hpx::id_type> localities = hpx::find_all_localities(); |
| 45 | + std::size_t const nlocs = localities.size(); |
| 46 | + std::size_t const length = 12; |
| 47 | + |
| 48 | + // fewer partitions than localities |
| 49 | + if (nlocs >= 2) |
| 50 | + test_with_policy<T>(length, nlocs - 1, localities); |
| 51 | + |
| 52 | + // same number of partitions as localities |
| 53 | + test_with_policy<T>(length, nlocs, localities); |
| 54 | +} |
| 55 | + |
| 56 | +int main() |
| 57 | +{ |
| 58 | + test_partition_locality_combinations<int>(); |
| 59 | + test_partition_locality_combinations<double>(); |
| 60 | + |
| 61 | + return hpx::util::report_errors(); |
| 62 | +} |
| 63 | +#endif |
0 commit comments