honeycomb_benches/
cli.rs

1use std::{num::NonZero, path::PathBuf};
2
3use clap::{Args, Parser, Subcommand, ValueEnum};
4
5/// Honeycomb benchmarks binary
6///
7/// Each command of this binary correspond to a (category of) benchmark(s). More information
8/// about each is available using `hc-bench <COMMAND> --help`
9#[derive(Parser)]
10#[command(version, about, arg_required_else_help(true))]
11pub struct Cli {
12    #[command(subcommand)]
13    pub benches: Benches,
14    /// Serialize the map returned by the benchmark, if applicable
15    #[arg(short, long("save-as"), value_enum, value_name("FORMAT"))]
16    pub save_as: Option<Format>,
17    /// Execute benchmarks using `f32` instead of the default `f64`
18    #[arg(long("simple-precision"))]
19    pub simple_precision: bool,
20}
21
22#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
23pub enum Format {
24    Cmap,
25    Vtk,
26}
27
28#[derive(Subcommand)]
29pub enum Benches {
30    /// 2D grid generation using `CMapBuilder` and `GridDescriptor`
31    #[command(name = "generate-2d-grid")]
32    Generate2dGrid(Generate2dGridArgs),
33    /// Edge size reduction in triangular meshes using vertex/edge insertions
34    CutEdges(CutEdgesArgs),
35    /// `grisubal` kernel execution
36    Grisubal(GrisubalArgs),
37    /// Simple vertex relaxation routine
38    Shift(ShiftArgs),
39}
40
41#[derive(Args)]
42pub struct Generate2dGridArgs {
43    /// Number of cells along the X-axis
44    #[arg(required(true))]
45    pub nx: NonZero<usize>,
46    /// Number of cells along the Y-axis
47    #[arg(required(true))]
48    pub ny: NonZero<usize>,
49    /// Length of cells along the X-axis
50    #[arg(required(true), allow_negative_numbers(false))]
51    pub lx: f64,
52    /// Length of cells along the Y-axis
53    #[arg(required(true), allow_negative_numbers(false))]
54    pub ly: f64,
55    /// If present, split diagonal according to the specified option
56    #[arg(short, long, value_enum)]
57    pub split: Option<Split>,
58}
59
60#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
61pub enum Split {
62    Uniform,
63    Random,
64}
65
66#[derive(Args)]
67pub struct CutEdgesArgs {
68    /// Input map as a VTK file
69    #[arg(short, long, required(true))]
70    pub input: PathBuf,
71    /// Execution backend; number of threads used is determined using `std::thread::available_parallelism`
72    #[arg(long, value_enum, default_value_t = Backend::StdThreads)]
73    pub backend: Backend,
74    /// Target threshold for edge length; any edge equal or above is split in half
75    #[arg(
76        short('l'),
77        long("target-length"),
78        required(true),
79        allow_negative_numbers(false)
80    )]
81    pub target_length: f64,
82}
83
84#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
85pub enum Backend {
86    RayonIter,
87    RayonChunks,
88    StdThreads,
89}
90
91#[derive(Args)]
92pub struct GrisubalArgs {
93    /// Input mesh as a VTK file
94    #[arg(required(true))]
95    pub input: PathBuf,
96    /// Length of cells along the X-axis of the overlapping grid
97    #[arg(required(true), allow_negative_numbers(false))]
98    pub lx: f64,
99    /// Length of cells along the Y-axis of the overlapping grid
100    #[arg(required(true), allow_negative_numbers(false))]
101    pub ly: f64,
102    /// If present, clip cells on one side of the captured boundary
103    #[arg(long, value_enum, value_name("SIDE"))]
104    pub clip: Option<Clip>,
105}
106
107#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
108pub enum Clip {
109    Left,
110    Right,
111}
112
113#[derive(Args)]
114pub struct ShiftArgs {
115    /// Input map as a VTK file
116    #[arg(short, long, required(true))]
117    pub input: PathBuf,
118    /// Number of applications of the relaxation algorithm
119    #[arg(long = "n-rounds", default_value_t = NonZero::new(100).unwrap())]
120    pub n_rounds: NonZero<usize>,
121    /// UNIMPLEMENTED - Use a partitioning algorithm to avoid conflicts between transactions
122    #[arg(long = "no-conflict")]
123    pub no_conflict: bool,
124}