125 std::vector<int>
const &new_bond_ids,
126 BondListT &bond_list, BondIDT &bond_ids,
127 int total_bond_count) {
128 if (new_bond_list.empty())
131 auto new_data_view = Kokkos::View<
const int *, Kokkos::HostSpace,
132 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
133 new_bond_list.data(), new_bond_list.size());
134 auto new_id_view = Kokkos::View<
const int *, Kokkos::HostSpace,
135 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
136 new_bond_ids.data(), new_bond_ids.size());
138 auto old_count = total_bond_count -
static_cast<int>(new_bond_ids.size());
140 using execution_space = Kokkos::DefaultHostExecutionSpace;
141 BondListT rebuilt_list(Kokkos::view_alloc(execution_space{},
142 Kokkos::WithoutInitializing,
143 "bond_list_rebuild"),
145 BondIDT rebuilt_ids(Kokkos::view_alloc(execution_space{},
146 Kokkos::WithoutInitializing,
151 Kokkos::subview(rebuilt_list, std::make_pair(0, old_count),
153 Kokkos::subview(bond_list, std::make_pair(0, old_count), Kokkos::ALL()));
154 Kokkos::deep_copy(Kokkos::subview(rebuilt_ids, std::make_pair(0, old_count)),
155 Kokkos::subview(bond_ids, std::make_pair(0, old_count)));
157 Kokkos::parallel_for(
159 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
160 std::size_t{0}, new_bond_list.size()),
161 [&bond_view = rebuilt_list, old_count, &new_data_view](
auto flat_idx) {
162 constexpr int NCols =
163 BondListT::rank == 2 ?
static_cast<int>(BondListT::static_extent(1))
165 auto bond_idx = old_count +
static_cast<int>(flat_idx / NCols);
166 auto col_idx =
static_cast<int>(flat_idx % NCols);
167 bond_view(bond_idx, col_idx) = new_data_view(flat_idx);
170 Kokkos::parallel_for(
172 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
173 std::size_t{0}, new_bond_ids.size()),
174 [&id_view = rebuilt_ids, old_count, &new_id_view](
auto idx) {
175 id_view(old_count +
static_cast<int>(idx)) = new_id_view(idx);
178 bond_list = rebuilt_list;
179 bond_ids = rebuilt_ids;