Skip to content

Commit

Permalink
[IO] Add experimental/freight-netl-ep output format
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Dec 5, 2023
1 parent e6c11ab commit 412241d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kagen/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ std::unordered_map<std::string, FileFormat> GetOutputFormatMap() {
{"parhip", FileFormat::PARHIP},
{"xtrapulp", FileFormat::XTRAPULP},

{"experimental/freight-netl-ep", FileFormat::FREIGHT_NETL_EP},

{"none", FileFormat::NOOP}, // @deprecated
{"edge-list", FileFormat::EDGE_LIST}, // @deprecated
{"binary-parhip", FileFormat::PARHIP}, // @deprecated
Expand Down Expand Up @@ -88,6 +90,9 @@ std::ostream& operator<<(std::ostream& out, FileFormat output_format) {

case FileFormat::XTRAPULP:
return out << "xtrapulp";

case FileFormat::FREIGHT_NETL_EP:
return out << "experimental/freight-netl-ep";
}

return out << "<invalid>";
Expand Down
2 changes: 2 additions & 0 deletions kagen/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "kagen/io/coordinates.h"
#include "kagen/io/dot.h"
#include "kagen/io/edgelist.h"
#include "kagen/io/freight-netl.h"
#include "kagen/io/hmetis.h"
#include "kagen/io/metis.h"
#include "kagen/io/parhip.h"
Expand Down Expand Up @@ -38,6 +39,7 @@ const std::unordered_map<FileFormat, std::unique_ptr<FileFormatFactory>>& GetGra
factories[FileFormat::DOT_DIRECTED] = std::make_unique<DirectedDotFactory>();
factories[FileFormat::COORDINATES] = std::make_unique<CoordinatesFactory>();
factories[FileFormat::PARHIP] = std::make_unique<ParhipFactory>();
factories[FileFormat::FREIGHT_NETL_EP] = std::make_unique<FreightNetlEpFactory>();
}
return factories;
}
Expand Down
46 changes: 46 additions & 0 deletions kagen/io/freight-netl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "kagen/io/freight-netl.h"

#include "kagen/io/buffered_writer.h"

namespace kagen {
FreightNetlEpWriter::FreightNetlEpWriter(
const OutputGraphConfig& config, Graph& graph, const GraphInfo info, const PEID rank, const PEID size)
: StandardGraphWriter(config, graph, info, rank, size) {}

void FreightNetlEpWriter::WriteHeader(const std::string& filename, const SInt n, const SInt m) {
BufferedTextOutput<> out(tag::append, filename);
out.WriteInt(m / 2).WriteChar(' ').WriteInt(n).WriteChar(' ').WriteString("11").WriteChar('\n').Flush();
}

bool FreightNetlEpWriter::WriteBody(const std::string& filename) {
BufferedTextOutput<> out(tag::append, filename);

// Ignores edge and node weights

for (SInt e = 0; e < graph_.edges.size(); ++e) {
const auto& [from, to] = graph_.edges[e];
if (from >= to) {
continue;
}

out.WriteChar('1')
.WriteChar(' ')
.WriteInt(from)
.WriteChar(' ')
.WriteChar('1')
.WriteChar(' ')
.WriteInt(to)
.WriteChar(' ')
.WriteChar('1')
.WriteChar('\n')
.Flush();
}

return false;
}

std::unique_ptr<GraphWriter> FreightNetlEpFactory::CreateWriter(
const OutputGraphConfig& config, Graph& graph, const GraphInfo info, const PEID rank, const PEID size) const {
return std::make_unique<FreightNetlEpWriter>(config, graph, info, rank, size);
}
} // namespace kagen
29 changes: 29 additions & 0 deletions kagen/io/freight-netl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "kagen/io/graph_format.h"

#include <mpi.h>

#include <string>

namespace kagen {
class FreightNetlEpWriter : public StandardGraphWriter {
public:
FreightNetlEpWriter(const OutputGraphConfig& config, Graph& graph, GraphInfo info, PEID rank, PEID size);

protected:
void WriteHeader(const std::string& filename, SInt n, SInt m) final;

bool WriteBody(const std::string& filename) final;
};

class FreightNetlEpFactory : public FileFormatFactory {
public:
std::vector<std::string> DefaultExtensions() const final {
return {"ep.netl"};
}

std::unique_ptr<GraphWriter> CreateWriter(
const OutputGraphConfig& config, Graph& graph, GraphInfo info, const PEID rank, const PEID size) const final;
};
} // namespace kagen
1 change: 1 addition & 0 deletions kagen/kagen.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ enum class FileFormat {
COORDINATES,
PARHIP,
XTRAPULP,
FREIGHT_NETL_EP,
};

enum class GeneratorType {
Expand Down

0 comments on commit 412241d

Please sign in to comment.