/**************************************************************************** * Copyright (c) 2017-2022 by the ArborX authors * * All rights reserved. * * * * This file is part of the ArborX library. ArborX is * * distributed under a BSD 3-clause license. For the licensing terms see * * the LICENSE file in the top-level directory. * * * * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ #include "ArborX_EnableDeviceTypes.hpp" // ARBORX_DEVICE_TYPES #include "ArborX_EnableViewComparison.hpp" #include #include #include #define BOOST_TEST_MODULE DetailsDistributedTree namespace tt = boost::test_tools; BOOST_AUTO_TEST_CASE_TEMPLATE(count_results, DeviceType, ARBORX_DEVICE_TYPES) { std::vector ids_ref = {4, 3, 2, 1, 4, 3, 2, 4, 3, 4}; std::vector offset_ref = { 0, 0, 1, 3, 6, 10, }; int const m = 5; int const nnz = 10; BOOST_TEST(ids_ref.size() == nnz); BOOST_TEST(offset_ref.size() == m + 1); Kokkos::View ids("Testing::query_ids", nnz); auto ids_host = Kokkos::create_mirror_view(ids); for (int i = 0; i < nnz; ++i) ids_host(i) = ids_ref[i]; Kokkos::deep_copy(ids, ids_host); Kokkos::View offset("Testing::offset", m); using ExecutionSpace = typename DeviceType::execution_space; ArborX::Details::DistributedTree::countResults(ExecutionSpace{}, m, ids, offset); auto offset_host = Kokkos::create_mirror_view(offset); Kokkos::deep_copy(offset_host, offset); BOOST_TEST(offset_host == offset_ref, tt::per_element()); } void checkBufferLayout(std::vector const &ranks, std::vector const &permute_ref, std::vector const &unique_ref, std::vector const &offsets_ref) { std::vector permute(ranks.size()); std::vector unique; std::vector offsets; Kokkos::DefaultHostExecutionSpace space; ArborX::Details::sortAndDetermineBufferLayout( space, Kokkos::View>(ranks.data(), ranks.size()), Kokkos::View>(permute.data(), permute.size()), unique, offsets); BOOST_TEST(permute_ref == permute, tt::per_element()); BOOST_TEST(unique_ref == unique, tt::per_element()); BOOST_TEST(offsets_ref == offsets, tt::per_element()); } BOOST_AUTO_TEST_CASE(sort_and_determine_buffer_layout) { checkBufferLayout({}, {}, {}, {0}); checkBufferLayout({2, 2}, {0, 1}, {2}, {0, 2}); checkBufferLayout({3, 3, 2, 3, 2, 1}, {0, 1, 3, 2, 4, 5}, {3, 2, 1}, {0, 3, 5, 6}); checkBufferLayout({1, 2, 3, 2, 3, 3}, {5, 3, 0, 4, 1, 2}, {3, 2, 1}, {0, 3, 5, 6}); checkBufferLayout({0, 1, 2, 3}, {3, 2, 1, 0}, {3, 2, 1, 0}, {0, 1, 2, 3, 4}); }