131 std::vector<int>
const &new_bond_ids,
132 BondListT &bond_list, BondIDT &bond_ids,
133 int total_bond_count) {
134 if (new_bond_list.empty())
137 auto new_data_view = Kokkos::View<
const int *, Kokkos::HostSpace,
138 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
139 new_bond_list.data(), new_bond_list.size());
140 auto new_id_view = Kokkos::View<
const int *, Kokkos::HostSpace,
141 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
142 new_bond_ids.data(), new_bond_ids.size());
144 auto old_count = total_bond_count -
static_cast<int>(new_bond_ids.size());
146 using execution_space = Kokkos::DefaultHostExecutionSpace;
147 BondListT rebuilt_list(Kokkos::view_alloc(execution_space{},
148 Kokkos::WithoutInitializing,
149 "bond_list_rebuild"),
151 BondIDT rebuilt_ids(Kokkos::view_alloc(execution_space{},
152 Kokkos::WithoutInitializing,
157 Kokkos::subview(rebuilt_list, std::make_pair(0, old_count),
159 Kokkos::subview(bond_list, std::make_pair(0, old_count), Kokkos::ALL()));
160 Kokkos::deep_copy(Kokkos::subview(rebuilt_ids, std::make_pair(0, old_count)),
161 Kokkos::subview(bond_ids, std::make_pair(0, old_count)));
163 Kokkos::parallel_for(
165 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
166 std::size_t{0}, new_bond_list.size()),
167 [&bond_view = rebuilt_list, old_count, &new_data_view](
auto flat_idx) {
168 constexpr int NCols =
169 BondListT::rank == 2 ?
static_cast<int>(BondListT::static_extent(1))
171 auto bond_idx = old_count +
static_cast<int>(flat_idx / NCols);
172 auto col_idx =
static_cast<int>(flat_idx % NCols);
173 bond_view(bond_idx, col_idx) = new_data_view(flat_idx);
176 Kokkos::parallel_for(
178 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
179 std::size_t{0}, new_bond_ids.size()),
180 [&id_view = rebuilt_ids, old_count, &new_id_view](
auto idx) {
181 id_view(old_count +
static_cast<int>(idx)) = new_id_view(idx);
184 bond_list = rebuilt_list;
185 bond_ids = rebuilt_ids;