6 #ifndef TURI_SGRAPH_SGRAPH_SYNCHRONIZE_HPP 7 #define TURI_SGRAPH_SGRAPH_SYNCHRONIZE_HPP 9 #include<core/storage/sgraph_data/sgraph_synchronize_interface.hpp> 10 #include<core/logging/assertions.hpp> 23 namespace sgraph_compute {
86 void init(
size_t num_partitions) {
87 m_vertex_partitions.clear();
88 m_is_partition_loaded.clear();
90 m_num_partitions = num_partitions;
91 m_vertex_partitions.resize(num_partitions);
92 m_is_partition_loaded.resize(num_partitions,
false);
96 DASSERT_LT(partition_id, m_num_partitions);
98 m_vertex_partitions[partition_id] = &vertices;
99 m_is_partition_loaded[partition_id] =
true;
105 auto& vertex_partition = *(m_vertex_partitions[vpartition_exchange.
partition_id]);
106 auto& update_field_index = vpartition_exchange.
field_ids;
108 for (
auto& vid_data_pair : vpartition_exchange.
vertices) {
109 size_t id = vid_data_pair.first;
111 for (
size_t i = 0; i < update_field_index.size(); ++i) {
112 size_t fid = vpartition_exchange.
field_ids[i];
113 vertex_partition[id][fid] = vdata[i];
123 auto& vertex_partition = *(m_vertex_partitions[partition_id]);
124 for (
size_t vid: vertex_ids) {
125 auto& vdata = vertex_partition[vid];
127 for (
auto fid: field_ids) vdata_subset.push_back(vdata[fid]);
128 ret.
vertices.push_back({vid, std::move(vdata_subset)});
134 std::vector<std::vector<sgraph_vertex_data>*> m_vertex_partitions;
135 std::vector<bool> m_is_partition_loaded;
136 size_t m_num_partitions;
void load_vertex_partition(size_t partition_id, std::vector< sgraph_vertex_data > &vertices)
Given a vector of all vertices of partition, initialize the local vertex storage. ...
void update_vertex_partition(vertex_partition_exchange &vpartition_exchange)
Given a vertex exchange object, update the local vertex storage.
std::vector< std::pair< size_t, sgraph_vertex_data > > vertices
#define DASSERT_FALSE(cond)
std::vector< flexible_type > sgraph_vertex_data
std::vector< size_t > field_ids
A subset of field ids the vertex data contain.
vertex_partition_exchange get_vertex_partition_exchange(size_t partition_id, const std::unordered_set< size_t > &vertex_ids, const std::vector< size_t > &field_ids)
Obtain a vertex exchange object containing a subset of vertices and fields.
#define DASSERT_TRUE(cond)
size_t partition_id
id of the partition that vertices belong to.