Skip to content

Commit

Permalink
Merge pull request #78 from bwpriest/feature/ygm_container_add_points
Browse files Browse the repository at this point in the history
adding point ingestion from YGM containers to dnnd API
  • Loading branch information
KIwabuchi authored Oct 9, 2024
2 parents e953efd + ecb6505 commit f6ab89a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions include/saltatlas/dnnd/dnnd_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string_view>

#include <ygm/comm.hpp>
#include <ygm/container/detail/base_concepts.hpp>

#include "saltatlas/dnnd/data_reader.hpp"
#include "saltatlas/dnnd/detail/distance.hpp"
Expand Down Expand Up @@ -144,6 +145,42 @@ class dnnd {
m_comm.barrier();
}

/// \brief Add points to the internal point store.
/// All ranks must call this function although some ranks add no points.
/// \tparam ygm_container_type Associative YGM container type for key-value
/// store.
/// \param container Associative YGM container.
template <template <typename, typename> class ygm_container_type>
void add_points(ygm_container_type<id_type, point_type>& container)
requires ygm::container::detail::HasForAll<
ygm_container_type<id_type, point_type>> &&
ygm::container::detail::DoubleItemTuple<
typename ygm_container_type<id_type, point_type>::for_all_args>
{
container.for_all([this](const id_type id, const point_type& point) {
this->priv_add_point(id, point);
});
m_comm.barrier();
}

/// \brief Add points to the internal point store.
/// All ranks must call this function although some ranks add no points.
/// \tparam ygm_container_type Associative YGM container type for key-value
/// store (with array-type template signature).
/// \param container Associative YGM container.
template <template <typename, typename> class ygm_container_type>
void add_points(ygm_container_type<point_type, id_type>& container)
requires ygm::container::detail::HasForAll<
ygm_container_type<id_type, point_type>> &&
ygm::container::detail::DoubleItemTuple<
typename ygm_container_type<id_type, point_type>::for_all_args>
{
container.for_all([this](const id_type id, const point_type& point) {
this->priv_add_point(id, point);
});
m_comm.barrier();
}

/// \brief Load points from files and add to the internal point store.
/// All ranks must call this function although some ranks load no points.
/// \tparam paths_iterator Iterator type for file paths.
Expand Down Expand Up @@ -420,6 +457,21 @@ class dnnd {
return [size](const id_type& id) { return id % size; };
};

/// \brief Add a single point. Only to be used by add_points.
void priv_add_point(const id_type id, const point_type& point) {
auto receiver = [](auto, auto this_ptr, const id_t id,
const auto& sent_point) {
if (this_ptr->m_pstore.contains(id)) {
std::cerr << "Duplicate ID " << id << std::endl;
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
this_ptr->m_pstore[id] = sent_point;
};

const auto dst = priv_get_point_partitioner()(id);
m_comm.async(dst, receiver, m_this, id, point);
}

distance_function_type m_distance_func;
ygm::comm& m_comm;
uint64_t m_rnd_seed;
Expand Down

0 comments on commit f6ab89a

Please sign in to comment.