Skip to content

Commit

Permalink
add global num vertices/edges query function (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschimek authored Oct 31, 2024
1 parent d61c597 commit 4e51662
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kagen/kagen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,17 @@ std::ostream& operator<<(std::ostream& out, const GraphRepresentation representa

return out << "<invalid>";
}

SInt Graph::NumberOfLocalVertices() const {
return vertex_range.second - vertex_range.first;
}

SInt Graph::NumberOfGlobalVertices() const {
SInt number_vertices = NumberOfLocalVertices();
MPI_Allreduce(MPI_IN_PLACE, &number_vertices, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
return number_vertices;
}

SInt Graph::NumberOfLocalEdges() const {
switch (representation) {
case GraphRepresentation::EDGE_LIST:
Expand All @@ -377,6 +384,12 @@ SInt Graph::NumberOfLocalEdges() const {
__builtin_unreachable();
}

SInt Graph::NumberOfGlobalEdges() const {
SInt number_edges = NumberOfLocalEdges();
MPI_Allreduce(MPI_IN_PLACE, &number_edges, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
return number_edges;
}

void Graph::Clear() {
edges.clear();
xadj.clear();
Expand Down
4 changes: 4 additions & 0 deletions kagen/kagen.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ struct Graph {

SInt NumberOfLocalVertices() const;

SInt NumberOfGlobalVertices() const;

SInt NumberOfLocalEdges() const;

SInt NumberOfGlobalEdges() const;

void SortEdgelist();

void FreeEdgelist();
Expand Down

0 comments on commit 4e51662

Please sign in to comment.