2024-03-01 21:57:29 +08:00
|
|
|
#![feature(portable_simd)]
|
2024-03-03 17:12:29 +08:00
|
|
|
#![feature(slice_swap_unchecked)]
|
2024-03-01 21:57:29 +08:00
|
|
|
|
2024-03-03 17:12:29 +08:00
|
|
|
mod cacluate;
|
2024-03-03 13:44:04 +08:00
|
|
|
mod evaluate;
|
2024-03-03 17:12:29 +08:00
|
|
|
mod generate;
|
2024-03-03 14:51:01 +08:00
|
|
|
mod name;
|
2024-02-28 19:04:57 +08:00
|
|
|
|
2024-03-03 17:12:29 +08:00
|
|
|
use std::path::PathBuf;
|
2024-03-02 00:09:53 +08:00
|
|
|
|
2024-02-29 01:05:41 +08:00
|
|
|
use clap::Parser;
|
2024-03-02 02:06:54 +08:00
|
|
|
use tracing::{info, warn};
|
2024-02-28 23:33:59 +08:00
|
|
|
|
2024-03-03 17:12:29 +08:00
|
|
|
use crate::cacluate::CacluateConfig;
|
2024-02-28 23:33:59 +08:00
|
|
|
|
|
|
|
#[allow(non_upper_case_globals)]
|
2024-02-29 00:25:19 +08:00
|
|
|
const allow_d: u32 = 10;
|
|
|
|
|
2024-03-02 00:09:53 +08:00
|
|
|
#[derive(Parser, Debug, Clone)]
|
2024-02-29 01:05:41 +08:00
|
|
|
pub struct Command {
|
2024-03-02 01:38:13 +08:00
|
|
|
/// 开始的 id
|
2024-02-29 01:05:41 +08:00
|
|
|
#[arg(long, default_value_t = 0)]
|
|
|
|
pub start: u64,
|
2024-03-02 01:38:13 +08:00
|
|
|
/// 结束的 id
|
2024-02-29 01:05:41 +08:00
|
|
|
#[arg(long, default_value_t = u64::MAX)]
|
|
|
|
pub end: u64,
|
2024-03-02 01:38:13 +08:00
|
|
|
/// 线程数
|
2024-02-29 01:05:41 +08:00
|
|
|
#[arg(long, short = 't', default_value_t = 10)]
|
|
|
|
pub thread_count: u32,
|
2024-03-02 01:38:13 +08:00
|
|
|
/// 八围预期值
|
|
|
|
#[arg(long = "prop-expected", short = 'p', default_value_t = 740)]
|
|
|
|
pub prop_expect: u32,
|
|
|
|
/// 队伍名称
|
2024-02-29 01:05:41 +08:00
|
|
|
#[arg(long)]
|
|
|
|
pub team: String,
|
2024-03-02 01:38:13 +08:00
|
|
|
/// 预期状态输出时间间隔 (秒)
|
2024-03-02 02:40:16 +08:00
|
|
|
#[arg(long, short = 'r', default_value_t = 10)]
|
2024-03-02 01:38:13 +08:00
|
|
|
pub report_interval: u64,
|
2024-02-29 01:05:41 +08:00
|
|
|
}
|
|
|
|
|
2024-03-03 17:12:29 +08:00
|
|
|
impl Command {
|
|
|
|
pub fn as_cacl_config(&self) -> CacluateConfig {
|
|
|
|
CacluateConfig {
|
|
|
|
start: self.start,
|
|
|
|
end: self.end,
|
|
|
|
thread_count: self.thread_count,
|
|
|
|
prop_expect: self.prop_expect,
|
|
|
|
prop_allow: allow_d,
|
|
|
|
team: self.team.clone(),
|
|
|
|
report_interval: self.report_interval,
|
2024-02-29 00:25:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 23:33:59 +08:00
|
|
|
|
2024-02-28 19:04:57 +08:00
|
|
|
fn main() {
|
2024-02-28 23:33:59 +08:00
|
|
|
tracing_subscriber::fmt::init();
|
2024-02-29 01:05:41 +08:00
|
|
|
let mut cli_arg = Command::parse();
|
2024-02-28 23:33:59 +08:00
|
|
|
|
|
|
|
// 将数据量处理成可被 thread_count 整除
|
2024-02-29 01:05:41 +08:00
|
|
|
let left = cli_arg.start % cli_arg.thread_count as u64;
|
2024-02-29 01:07:57 +08:00
|
|
|
cli_arg.end = cli_arg.end.wrapping_add(left);
|
2024-02-29 01:05:41 +08:00
|
|
|
|
2024-02-29 00:25:19 +08:00
|
|
|
let mut n = 0;
|
2024-02-29 01:05:41 +08:00
|
|
|
let mut threads = Vec::with_capacity(cli_arg.thread_count as usize);
|
2024-03-02 00:09:53 +08:00
|
|
|
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
|
|
|
|
// namerena-<team>-<time>.txt
|
2024-03-02 00:08:56 +08:00
|
|
|
// <time>: %Y-%m-%d-%H-%M-%S
|
2024-03-02 01:38:13 +08:00
|
|
|
let output_filename = format!("namerena-{}-{}.txt", cli_arg.team, now);
|
2024-03-02 00:09:53 +08:00
|
|
|
let out_path = PathBuf::from(format!("./namerena/{}", output_filename));
|
|
|
|
info!("输出文件: {:?}", out_path);
|
|
|
|
// 先创建文件夹
|
|
|
|
if let Err(e) = std::fs::create_dir_all(&out_path.parent().unwrap()) {
|
|
|
|
warn!("创建文件夹失败: {}", e);
|
|
|
|
}
|
|
|
|
|
2024-03-02 02:06:54 +08:00
|
|
|
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
|
|
|
info!("线程数: {}", cli_arg.thread_count);
|
2024-03-02 01:43:18 +08:00
|
|
|
info!("八围预期: {}", cli_arg.prop_expect);
|
2024-03-02 02:06:54 +08:00
|
|
|
info!("队伍名: {}", cli_arg.team);
|
|
|
|
info!("输出文件名: {:?}", out_path);
|
2024-03-02 00:09:53 +08:00
|
|
|
|
2024-02-29 01:05:41 +08:00
|
|
|
for i in 0..cli_arg.thread_count {
|
2024-02-29 00:25:19 +08:00
|
|
|
n += 1;
|
2024-03-03 17:12:29 +08:00
|
|
|
let config = cli_arg.as_cacl_config();
|
2024-03-02 00:09:53 +08:00
|
|
|
let out_path = out_path.clone();
|
2024-02-29 00:25:19 +08:00
|
|
|
let thread_name = format!("thread_{}", i);
|
|
|
|
threads.push(std::thread::spawn(move || {
|
|
|
|
info!("线程 {} 开始计算", thread_name);
|
2024-03-03 17:12:29 +08:00
|
|
|
cacluate::cacl(config, n, &out_path);
|
2024-02-29 00:25:19 +08:00
|
|
|
info!("线程 {} 结束计算", thread_name);
|
|
|
|
}));
|
2024-02-28 23:33:59 +08:00
|
|
|
}
|
2024-02-29 00:25:19 +08:00
|
|
|
info!("开始计算");
|
2024-02-28 23:33:59 +08:00
|
|
|
|
|
|
|
for t in threads {
|
|
|
|
t.join().unwrap();
|
|
|
|
}
|
2024-02-28 19:04:57 +08:00
|
|
|
}
|