Skip to content

Commit

Permalink
Generate sssp app using macro
Browse files Browse the repository at this point in the history
  • Loading branch information
s1ck committed Oct 14, 2023
1 parent 00f35b0 commit f3e90b8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 194 deletions.
8 changes: 4 additions & 4 deletions crates/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use log::info;
mod loading;
mod runner;
mod serialize;
mod sssp;
mod triangle_count;

runner!(page_rank, graph::page_rank::page_rank, PageRankConfig);
runner!(wcc, graph::wcc::wcc_afforest_dss, WccConfig);
runner!(unweighted: page_rank, graph::page_rank::page_rank, PageRankConfig);
runner!(unweighted: wcc, graph::wcc::wcc_afforest_dss, WccConfig);
runner!(weighted: sssp, graph::sssp::delta_stepping, DeltaSteppingConfig, f32);

fn main() -> Result<()> {
let args = setup_clap::<Args>().run()?;
Expand All @@ -23,7 +23,7 @@ fn main() -> Result<()> {

match args.algorithm {
Algorithm::PageRank { config } => page_rank::run(args.args, config)?,
Algorithm::Sssp { config } => sssp::sssp(args.args, config)?,
Algorithm::Sssp { config } => sssp::run(args.args, config)?,
Algorithm::TriangleCount { relabel } => triangle_count::triangle_count(args.args, relabel)?,
Algorithm::Wcc { config } => wcc::run(args.args, config)?,
Algorithm::Loading {
Expand Down
189 changes: 115 additions & 74 deletions crates/app/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,93 +1,134 @@
macro_rules! runner {
($algo_name:ident, $algo_func:expr, $algo_config:ty) => {
(unweighted: $algo_name:ident, $algo_func:expr, $algo_config:ty) => {
mod $algo_name {
use graph::prelude::*;
crate::runner!(__entry: $algo_config);
crate::runner!(__run_file_format_all: $algo_config, ());
crate::runner!(__run_graph_format: $algo_config, ());
crate::runner!(__bench: $algo_func, $algo_config, DirectedNeighbors<NI>, ());
}
};

pub(crate) fn run(
args: $crate::CommonArgs,
config: $algo_config,
) -> ::kommandozeile::Result<()> {
::log::info!(
"Reading graph ({} bit) from: {:?}",
if args.use_32_bit { "32" } else { "64" },
args.path
);
(weighted: $algo_name:ident, $algo_func:expr, $algo_config:ty, $ev_type:ty) => {
mod $algo_name {
use graph::prelude::*;
crate::runner!(__entry: $algo_config);
crate::runner!(__run_file_format_edge_list: $algo_config, $ev_type);
crate::runner!(__run_graph_format: $algo_config, $ev_type);
crate::runner!(__bench: $algo_func, $algo_config, DirectedNeighborsWithValues<NI, $ev_type>, $ev_type);
}
};

(__entry: $algo_config:ty) => {
pub(crate) fn run(
args: $crate::CommonArgs,
config: $algo_config,
) -> ::kommandozeile::Result<()> {
::log::info!(
"Reading graph ({} bit) from: {:?}",
if args.use_32_bit { "32" } else { "64" },
args.path
);

if args.use_32_bit {
run_::<u32>(args, config)
} else {
run_::<u64>(args, config)
}
}
};

if args.use_32_bit {
run_::<u32>(args, config)
} else {
run_::<u64>(args, config)
(__run_file_format_all: $algo_config:ty, $ev_type:ty) => {
fn run_<NI: Idx>(
args: $crate::CommonArgs,
config: $algo_config,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
{
match args.format {
$crate::FileFormat::EdgeList => {
run__::<NI, EdgeListInput<NI, $ev_type>>(args, config, EdgeListInput::default())
}
$crate::FileFormat::Graph500 => {
run__::<NI, Graph500Input<NI>>(args, config, Graph500Input::default())
}
}
}
};

fn run_<NI: Idx>(
args: $crate::CommonArgs,
config: $algo_config,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
{
match args.format {
$crate::FileFormat::EdgeList => {
run__::<NI, EdgeListInput<NI>>(args, config, EdgeListInput::default())
}
$crate::FileFormat::Graph500 => {
run__::<NI, Graph500Input<NI>>(args, config, Graph500Input::default())
}
(__run_file_format_edge_list: $algo_config:ty, $ev_type:ty) => {
fn run_<NI: Idx>(
args: $crate::CommonArgs,
config: $algo_config,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
{
match args.format {
$crate::FileFormat::EdgeList => {
run__::<NI, EdgeListInput<NI, $ev_type>>(args, config, EdgeListInput::default())
}
$crate::FileFormat::Graph500 => {
std::panic!("Graph500 is not supported for weighted graphs")
}
}
}
};

fn run__<NI, Format>(
args: $crate::CommonArgs,
config: $algo_config,
file_format: Format,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
Format: InputCapabilities<NI>,
Format::GraphInput: TryFrom<InputPath<::std::path::PathBuf>>,
<Format as InputCapabilities<NI>>::GraphInput: Edges<NI = NI, EV = ()>,
Error:
From<<Format::GraphInput as TryFrom<InputPath<::std::path::PathBuf>>>::Error>,
{
match args.graph {
$crate::GraphFormat::CompressedSparseRow => {
run___::<DirectedCsrGraph<NI>, NI, Format>(args, config, file_format)
}
$crate::GraphFormat::AdjacencyList => {
run___::<DirectedALGraph<NI>, NI, Format>(args, config, file_format)
}
(__run_graph_format: $algo_config:ty, $ev_type:ty) => {
fn run__<NI, Format>(
args: $crate::CommonArgs,
config: $algo_config,
file_format: Format,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
Format: InputCapabilities<NI>,
Format::GraphInput: TryFrom<InputPath<::std::path::PathBuf>>,
<Format as InputCapabilities<NI>>::GraphInput: Edges<NI = NI, EV = $ev_type>,
Error:
From<<Format::GraphInput as TryFrom<InputPath<::std::path::PathBuf>>>::Error>,
{
match args.graph {
$crate::GraphFormat::CompressedSparseRow => {
run___::<DirectedCsrGraph<NI, (), $ev_type>, NI, Format>(args, config, file_format)
}
$crate::GraphFormat::AdjacencyList => {
run___::<DirectedALGraph<NI, (), $ev_type>, NI, Format>(args, config, file_format)
}
}
}
};

fn run___<G, NI, Format>(
args: $crate::CommonArgs,
config: $algo_config,
file_format: Format,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
Format: InputCapabilities<NI>,
Format::GraphInput: TryFrom<InputPath<::std::path::PathBuf>>,
<Format as InputCapabilities<NI>>::GraphInput: Edges<NI = NI, EV = ()>,
Error:
From<<Format::GraphInput as TryFrom<InputPath<::std::path::PathBuf>>>::Error>,
G: Graph<NI> + DirectedDegrees<NI> + DirectedNeighbors<NI> + Sync,
G: TryFrom<(Format::GraphInput, CsrLayout)>,
Error: From<<G as TryFrom<(Format::GraphInput, CsrLayout)>>::Error>,
{
let graph: G = GraphBuilder::new()
.csr_layout(CsrLayout::Sorted)
.file_format(file_format)
.path(args.path)
.build()?;
(__bench: $algo_func:expr, $algo_config:ty, $neighbors_trait:path, $ev_type:ty) => {
fn run___<G, NI, Format>(
args: $crate::CommonArgs,
config: $algo_config,
file_format: Format,
) -> ::kommandozeile::Result<()>
where
NI: Idx + ::std::hash::Hash,
Format: InputCapabilities<NI>,
Format::GraphInput: TryFrom<InputPath<::std::path::PathBuf>>,
<Format as InputCapabilities<NI>>::GraphInput: Edges<NI = NI, EV = $ev_type>,
Error:
From<<Format::GraphInput as TryFrom<InputPath<::std::path::PathBuf>>>::Error>,
G: Graph<NI> + DirectedDegrees<NI> + $neighbors_trait + Sync,
G: TryFrom<(Format::GraphInput, CsrLayout)>,
Error: From<<G as TryFrom<(Format::GraphInput, CsrLayout)>>::Error>,
{
let graph: G = GraphBuilder::new()
.csr_layout(CsrLayout::Sorted)
.file_format(file_format)
.path(args.path)
.build()?;

$crate::time(args.runs, args.warmup_runs, || {
$algo_func(&graph, config);
});
$crate::time(args.runs, args.warmup_runs, || {
$algo_func(&graph, config);
});

Ok(())
}
Ok(())
}
};
}
Expand Down
116 changes: 0 additions & 116 deletions crates/app/src/sssp.rs

This file was deleted.

0 comments on commit f3e90b8

Please sign in to comment.