Compare commits
3 Commits
b20270b869
...
5b416e076a
Author | SHA1 | Date | |
---|---|---|---|
5b416e076a | |||
f6c32973ac | |||
a09c6a9332 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1831,7 +1831,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "tswn"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"base16384",
|
||||
"chrono",
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "tswn"
|
||||
description = "tool shenjack work shop namerena"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -2,6 +2,14 @@
|
||||
|
||||
## 0.3.x
|
||||
|
||||
### 0.3.1
|
||||
|
||||
- 去掉了 `--bench` 选项
|
||||
- 现在可以直接使用 `--core-pick` 选项来选择核心了
|
||||
- 并且单线程模式下效果和 benchmark 模式下一样了
|
||||
|
||||
> 然后我准备改成内置多进程模式
|
||||
|
||||
### 0.3.0
|
||||
|
||||
把 `--bench-core` 改成了 `--core-pick`
|
||||
|
@ -26,8 +26,8 @@ pub struct CacluateConfig {
|
||||
pub start: u64,
|
||||
/// 结束的 id
|
||||
pub end: u64,
|
||||
/// 线程数
|
||||
pub thread_count: u32,
|
||||
/// 线程 id
|
||||
pub thread_id: u32,
|
||||
/// 八围预期值
|
||||
pub prop_expect: u32,
|
||||
/// qp 预期值
|
||||
@ -40,6 +40,63 @@ pub struct CacluateConfig {
|
||||
pub core_affinity: Option<usize>,
|
||||
}
|
||||
|
||||
/// 用于收集统计信息的结构体
|
||||
pub struct RunStatus {
|
||||
/// 工作位置
|
||||
/// 每一个线程对应一组
|
||||
pub work_batches: Vec<(u128, u128)>,
|
||||
/// 每个线程的效率回报
|
||||
pub work_speed: Vec<u32>,
|
||||
/// 每个线程是否需要干活
|
||||
/// work batch 大小
|
||||
pub work_batch: u32,
|
||||
}
|
||||
|
||||
/// 启动计算的调度函数
|
||||
pub fn start_main(cli_config: crate::Command, outfile: PathBuf) {
|
||||
if cli_config.is_single_core() {
|
||||
// 单核的处理
|
||||
}
|
||||
// if cli_arg.bench {
|
||||
// info!("开始 benchmark");
|
||||
// cli_arg.thread_count = 1;
|
||||
// let mut config = cli_arg.as_cacl_config();
|
||||
// config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||
// set_process_cores(config.core_affinity.unwrap());
|
||||
// cacluate::cacl(config, 1, &out_path);
|
||||
// } else {
|
||||
// let mut n = 0;
|
||||
// let mut cores = 0;
|
||||
// if cli_arg.thread_count == 1 {
|
||||
// // 单线程运行的时候也是让他放在主线程跑
|
||||
// let mut config = cli_arg.as_cacl_config();
|
||||
// config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||
// set_process_cores(config.core_affinity.unwrap());
|
||||
// cacluate::cacl(config, 1, &out_path);
|
||||
// } else {
|
||||
// for i in 0..cli_arg.thread_count {
|
||||
// n += 1;
|
||||
// let mut config = cli_arg.as_cacl_config();
|
||||
// // 核心亲和性: n, n+1
|
||||
// config.core_affinity = Some(1 << i);
|
||||
// cores |= 1 << i;
|
||||
// let out_path = out_path.clone();
|
||||
// let thread_name = format!("thread_{}", n);
|
||||
// threads.push(std::thread::spawn(move || {
|
||||
// info!("线程 {} 开始计算", thread_name);
|
||||
// cacluate::cacl(config, n, &out_path);
|
||||
// info!("线程 {} 结束计算", thread_name);
|
||||
// }));
|
||||
// }
|
||||
// set_process_cores(cores);
|
||||
// }
|
||||
// }
|
||||
|
||||
// for t in threads {
|
||||
// t.join().unwrap();
|
||||
// }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
||||
// 初始猜测的时间间隔
|
||||
@ -56,16 +113,16 @@ pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
||||
// 提前准备好 team_namer
|
||||
let team_namer = TeamNamer::new(&config.team).unwrap();
|
||||
|
||||
let mut main_namer = Namer::new_from_team_namer_unchecked(&team_namer, "dummy");
|
||||
let mut main_namer = Namer::new_from_team_namer_unchecked(&team_namer, "看到这个说明有问题出现");
|
||||
|
||||
for i in (config.start + id..config.end).step_by(config.thread_count as usize) {
|
||||
for i in config.start..config.end {
|
||||
k += 1;
|
||||
if k >= report_interval {
|
||||
let now = std::time::Instant::now();
|
||||
let d_t: std::time::Duration = now.duration_since(start_time);
|
||||
let new_run_speed = k as f64 / d_t.as_secs_f64();
|
||||
// 预估剩余时间
|
||||
let wait_time = (config.end - i) / config.thread_count as u64 / new_run_speed as u64;
|
||||
let wait_time = (config.end - i) / new_run_speed as u64;
|
||||
let wait_time = chrono::Duration::seconds(wait_time as i64);
|
||||
// 转换成 时:分:秒
|
||||
// 根据实际运行速率来调整 report_interval
|
||||
|
@ -36,12 +36,12 @@ pub struct Command {
|
||||
/// 预期状态输出时间间隔 (秒)
|
||||
#[arg(long, short = 'r', default_value_t = 10)]
|
||||
pub report_interval: u64,
|
||||
/// Windows 下会强制单线程, 且设置线程亲和性为核心 0
|
||||
#[arg(long = "bench", default_value_t = false)]
|
||||
pub bench: bool,
|
||||
/// 单线程模式 / benchmark 模式下的核心亲和性核心号 (从 0 开始)
|
||||
/// 单线程模式模式下的核心亲和性核心号 (从 0 开始)
|
||||
#[arg(long = "core-pick", default_value_t = 0)]
|
||||
pub pick_core: usize,
|
||||
/// 是否是子进程
|
||||
#[arg(short = 's')]
|
||||
pub is_sub_process: bool,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
@ -49,14 +49,18 @@ impl Command {
|
||||
CacluateConfig {
|
||||
start: self.start,
|
||||
end: self.end,
|
||||
thread_count: self.thread_count,
|
||||
thread_id: 0,
|
||||
prop_expect: self.prop_expect,
|
||||
qp_expect: self.qp_expect,
|
||||
team: self.team.clone(),
|
||||
report_interval: self.report_interval,
|
||||
core_affinity: if self.bench { Some(1 << self.pick_core) } else { None },
|
||||
core_affinity: if self.thread_count == 1 { Some(1 << self.pick_core) } else { None },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_single_core(&self) -> bool {
|
||||
self.thread_count == 1
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_thread2core(core: usize) {
|
||||
@ -102,7 +106,6 @@ fn main() {
|
||||
let left = cli_arg.start % cli_arg.thread_count as u64;
|
||||
cli_arg.end = cli_arg.end.wrapping_add(left);
|
||||
|
||||
let mut threads = vec![];
|
||||
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
|
||||
// namerena-<team>-<time>.csv
|
||||
// <time>: %Y-%m-%d-%H-%M-%S
|
||||
@ -112,6 +115,7 @@ fn main() {
|
||||
// 先创建文件夹
|
||||
if let Err(e) = std::fs::create_dir_all(out_path.parent().unwrap()) {
|
||||
warn!("创建文件夹失败: {}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
||||
@ -120,44 +124,7 @@ fn main() {
|
||||
info!("队伍名: {}", cli_arg.team);
|
||||
info!("输出文件名: {:?}", out_path);
|
||||
info!("预期状态输出时间间隔: {} 秒", cli_arg.report_interval);
|
||||
info!("是否启动 benchmark 模式: {}", cli_arg.bench);
|
||||
|
||||
if cli_arg.bench {
|
||||
info!("开始 benchmark");
|
||||
cli_arg.thread_count = 1;
|
||||
let mut config = cli_arg.as_cacl_config();
|
||||
config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||
set_process_cores(config.core_affinity.unwrap());
|
||||
cacluate::cacl(config, 1, &out_path);
|
||||
} else {
|
||||
let mut n = 0;
|
||||
let mut cores = 0;
|
||||
if cli_arg.thread_count == 1 {
|
||||
// 单线程运行的时候也是让他放在主线程跑
|
||||
let mut config = cli_arg.as_cacl_config();
|
||||
config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||
set_process_cores(config.core_affinity.unwrap());
|
||||
cacluate::cacl(config, 1, &out_path);
|
||||
} else {
|
||||
for i in 0..cli_arg.thread_count {
|
||||
n += 1;
|
||||
let mut config = cli_arg.as_cacl_config();
|
||||
// 核心亲和性: n, n+1
|
||||
config.core_affinity = Some(1 << i);
|
||||
cores |= 1 << i;
|
||||
let out_path = out_path.clone();
|
||||
let thread_name = format!("thread_{}", n);
|
||||
threads.push(std::thread::spawn(move || {
|
||||
info!("线程 {} 开始计算", thread_name);
|
||||
cacluate::cacl(config, n, &out_path);
|
||||
info!("线程 {} 结束计算", thread_name);
|
||||
}));
|
||||
}
|
||||
set_process_cores(cores);
|
||||
}
|
||||
}
|
||||
cacluate::start_main(cli_arg, out_path);
|
||||
|
||||
for t in threads {
|
||||
t.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -494,35 +494,6 @@ impl Namer {
|
||||
}
|
||||
}
|
||||
}
|
||||
// let mut simd_val = self.val;
|
||||
// let mut simd_val_b = self.val;
|
||||
// let simd_181 = u8x32::splat(181);
|
||||
// let simd_199 = u8x32::splat(199);
|
||||
// let simd_128 = u8x32::splat(128);
|
||||
// let simd_53 = u8x32::splat(53);
|
||||
// let simd_63 = u8x32::splat(63);
|
||||
// let simd_32 = u8x32::splat(32);
|
||||
|
||||
// for i in (0..256).step_by(32) {
|
||||
// unsafe {
|
||||
// let mut x = u8x32::from_slice(simd_val.get_unchecked(i..));
|
||||
// let mut y = u8x32::from_slice(simd_val_b.get_unchecked(i..));
|
||||
// x = (x * simd_181 + simd_199) & simd_128;
|
||||
// y = (y * simd_53) & simd_63 ^ simd_32;
|
||||
// x.copy_to_slice(simd_val.get_unchecked_mut(i..));
|
||||
// y.copy_to_slice(simd_val_b.get_unchecked_mut(i..));
|
||||
// }
|
||||
// }
|
||||
|
||||
// let mut mod_count = 0;
|
||||
// for i in 0..256 {
|
||||
// unsafe {
|
||||
// if simd_val.get_unchecked(i) != &0 {
|
||||
// *self.name_base.get_unchecked_mut(mod_count as usize) = *simd_val_b.get_unchecked(i);
|
||||
// mod_count += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// const int N = 256, M = 128, K = 64, skill_cnt = 40, max_len = 25;
|
||||
let mut a: u8 = 0;
|
||||
let mut b: u8 = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user