Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support creation of new vertices in LSCSR #15

Merged
merged 8 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions libgalois/include/galois/graphs/LS_LC_CSR_Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class LS_LC_CSR_Graph : private boost::noncopyable {
static constexpr bool HasEdgeData = !std::is_same_v<EdgeData, void>;

using VertexDataStore =
std::conditional_t<HasVertexData, typename galois::LargeArray<VertexData>,
std::conditional_t<HasVertexData, typename std::vector<VertexData>,
typename std::tuple<>>;
using EdgeDataStore = std::conditional_t<
HasEdgeData,
Expand Down Expand Up @@ -123,7 +123,7 @@ class LS_LC_CSR_Graph : private boost::noncopyable {
LS_LC_CSR_Graph(uint64_t num_vertices)
: m_vertices(num_vertices, VertexMetadata()) {
if constexpr (HasVertexData) {
m_vertex_data.allocateBlocked(num_vertices);
m_vertex_data.resize(num_vertices);
}
}

Expand Down Expand Up @@ -158,6 +158,30 @@ class LS_LC_CSR_Graph : private boost::noncopyable {

VertexRange vertices() { return VertexRange(begin(), end()); }

VertexTopologyID addVertexTopologyOnly() {
m_vertices.emplace_back();
if constexpr (HasVertexData) {
m_vertex_data.resize(m_vertices.size());
}
return m_vertices.size() - 1;
}

// Adds multiple vertices to the graph. The new vertices will be assigned
// consecutive topology IDs, and the lowest new ID is returned.
template <typename V = VertexData, typename = std::enable_if<HasVertexData>>
VertexTopologyID addVertices(std::vector<V> data) {
meyerzinn marked this conversation as resolved.
Show resolved Hide resolved
VertexTopologyID const start = m_vertices.size();
m_vertices.resize(m_vertices.size() + data.size());
m_vertex_data.resize(m_vertices.size());

galois::do_all(
galois::iterate(0ul, data.size()),
[&](VertexTopologyID const& off) { setData(start + off, data[off]); });
return start;
}

size_t getDegree(VertexTopologyID id) { return m_vertices[id].degree; }

VertexTopologyID getEdgeDst(EdgeHandle eh) { return getEdgeMetadata(eh).dst; }

template <typename E = EdgeData, typename = std::enable_if<HasEdgeData>>
Expand Down
9 changes: 9 additions & 0 deletions libgalois/test/graph-compile-lscsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ int main() {
g.setData(3, 3);
GALOIS_ASSERT(g.getData(3) == 3);

size_t four = g.addVertices({4, 5, 6, 7});

for (size_t ii = 0; ii < 4; ++ii) {
// make sure previous data survived the resize
GALOIS_ASSERT(g.getData(ii) == ii);
// check the new vertex data
GALOIS_ASSERT(g.getData(four + ii) == 4 + ii);
}

g.addEdges(0, {1, 2, 3}, {1, 2, 3});
for (auto const& handle : g.edges(0)) {
GALOIS_ASSERT(g.getEdgeDst(handle) == g.getEdgeData(handle));
Expand Down