Skip to content

Commit

Permalink
Add missing calls to Finalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Nov 30, 2023
1 parent 70a5be6 commit 4ace8ef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
10 changes: 7 additions & 3 deletions kagen/generators/file/file_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@ void FileGraphGenerator::GenerateImpl(const GraphRepresentation representation)
}

void FileGraphGenerator::FinalizeEdgeList(MPI_Comm comm) {
if (graph_.representation == GraphRepresentation::CSR) {
std::cout << "FinalizeEdgeList" << std::endl;
if (fragment_.graph.representation == GraphRepresentation::CSR) {
FinalizeCSR(comm);

if (Output()) {
std::cout << "converting to edge list ... " << std::flush;
}

graph_.edges = BuildEdgeListFromCSR(graph_.vertex_range, graph_.xadj, graph_.adjncy);
graph_.edges = BuildEdgeListFromCSR(graph_.vertex_range, graph_.xadj, graph_.adjncy);
graph_.representation = GraphRepresentation::EDGE_LIST;
graph_.FreeCSR();
} else {
graph_ = FinalizeGraphFragment(std::move(fragment_), Output(), comm);
}
}

void FileGraphGenerator::FinalizeCSR(MPI_Comm comm) {
if (graph_.representation == GraphRepresentation::EDGE_LIST) {
std::cout << "FinalizeCSR" << std::endl;
if (fragment_.graph.representation == GraphRepresentation::EDGE_LIST) {
FinalizeEdgeList(comm);

if (Output()) {
Expand All @@ -53,6 +56,7 @@ void FileGraphGenerator::FinalizeCSR(MPI_Comm comm) {

std::tie(graph_.xadj, graph_.adjncy) =
BuildCSRFromEdgeList(graph_.vertex_range, graph_.edges, graph_.edge_weights);
graph_.representation = GraphRepresentation::CSR;
graph_.FreeEdgelist();
} else {
graph_ = FinalizeGraphFragment(std::move(fragment_), Output(), comm);
Expand Down
10 changes: 6 additions & 4 deletions kagen/generators/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ Generator::~Generator() = default;

void Generator::Generate(const GraphRepresentation representation) {
Reset();
desired_representation_ = representation;

graph_.representation = representation;

switch (graph_.representation) {
switch (desired_representation_) {
case GraphRepresentation::EDGE_LIST:
GenerateEdgeList();
break;
Expand All @@ -29,7 +28,8 @@ void Generator::Generate(const GraphRepresentation representation) {
}

void Generator::Finalize(MPI_Comm comm) {
switch (graph_.representation) {
std::cout << "Finalize" << std::endl;
switch (desired_representation_) {
case GraphRepresentation::EDGE_LIST:
FinalizeEdgeList(comm);
break;
Expand All @@ -38,6 +38,8 @@ void Generator::Finalize(MPI_Comm comm) {
FinalizeCSR(comm);
break;
}

graph_.representation = desired_representation_;
}

void Generator::FinalizeEdgeList(MPI_Comm) {}
Expand Down
3 changes: 2 additions & 1 deletion kagen/generators/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Generator {

void FilterDuplicateEdges();

Graph graph_;
GraphRepresentation desired_representation_;
Graph graph_;

private:
void Reset();
Expand Down
2 changes: 2 additions & 0 deletions tests/file/generic_file_generator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ inline Graph ReadStaticGraph(

FileGraphGenerator generator(config, rank, size);
generator.Generate(representation);
generator.Finalize(MPI_COMM_WORLD);
return generator.Take();
}

Expand Down Expand Up @@ -96,6 +97,7 @@ inline Graph ReadStaticGraphOnRoot(

FileGraphGenerator generator(config, 0, 1);
generator.Generate(representation);
generator.Finalize(MPI_COMM_WORLD);
return generator.Take();
} else {
return {};
Expand Down
20 changes: 12 additions & 8 deletions tests/path/general_path_generator_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include <gtest/gtest.h>

#include "kagen/context.h"
#include "kagen/generators/path/path_directed.h"

#include <gtest/gtest.h>

#include "tests/util/utils.h"

class PathGeneratorTestFixture : public ::testing::TestWithParam<kagen::SInt> {};
INSTANTIATE_TEST_SUITE_P(PathGenerationTests, PathGeneratorTestFixture, ::testing::Values(10, 500, 16384, 30001));

namespace {
constexpr bool debug_output = false;
auto ComputeStartEndVertexAndSuccesors(const kagen::Graph& graph, kagen::SInt n) {

auto ComputeStartEndVertexAndSuccesors(const kagen::Graph& graph, kagen::SInt n) {
using namespace kagen;
std::vector<SInt> in_degree(n);
std::vector<SInt> out_degree(n);
Expand Down Expand Up @@ -54,7 +56,7 @@ auto ComputeStartEndVertexAndSuccesors(const kagen::Graph& graph, kage
void WalkPath(const kagen::Graph& graph, kagen::SInt n) {
using namespace kagen;
const auto [first_vertex, last_vertex, successor_array] = ComputeStartEndVertexAndSuccesors(graph, n);
SInt cur_vertex = first_vertex;
SInt cur_vertex = first_vertex;
for (SInt i = 0; i + 1 < n; ++i) {
cur_vertex = successor_array[cur_vertex];
}
Expand All @@ -77,8 +79,9 @@ TEST_P(PathGeneratorTestFixture, path_generation_without_permutation) {

PathDirected generator(config, rank, size);
generator.Generate(GraphRepresentation::EDGE_LIST);
const Graph local_graph = generator.Take();
const Graph graph = kagen::testing::GatherGraph(local_graph);
generator.Finalize(MPI_COMM_WORLD);
const Graph graph = kagen::testing::GatherGraph(generator.Take());

WalkPath(graph, config.n);
}

Expand All @@ -95,7 +98,8 @@ TEST_P(PathGeneratorTestFixture, path_generation_with_permutation) {

PathDirected generator(config, rank, size);
generator.Generate(GraphRepresentation::EDGE_LIST);
const Graph local_graph = generator.Take();
const Graph graph = kagen::testing::GatherGraph(local_graph);
generator.Finalize(MPI_COMM_WORLD);
const Graph graph = kagen::testing::GatherGraph(generator.Take());

WalkPath(graph, config.n);
}

0 comments on commit 4ace8ef

Please sign in to comment.