From 66eb6ee9d2c10b95cc69402cce7c8cd9b5d04278 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:13:56 +0900 Subject: [PATCH] add --skip-coeff-calc --- mixnet-rs/ordering/src/iteration.rs | 34 ++++++++++++++++------------- mixnet-rs/ordering/src/main.rs | 20 ++++++++++++++--- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/mixnet-rs/ordering/src/iteration.rs b/mixnet-rs/ordering/src/iteration.rs index e6a9eee..77337c2 100644 --- a/mixnet-rs/ordering/src/iteration.rs +++ b/mixnet-rs/ordering/src/iteration.rs @@ -20,7 +20,7 @@ pub fn run_iteration( out_sent_sequence_path: &str, out_received_sequence_path_prefix: &str, out_queue_data_msg_counts_path: &str, - out_ordering_coeff_path: &str, + out_ordering_coeff_path: Option, out_topology_path: &str, ) -> f32 { // Ensure that all output files do not exist @@ -29,11 +29,13 @@ pub fn run_iteration( out_sent_sequence_path, out_received_sequence_path_prefix, out_queue_data_msg_counts_path, - out_ordering_coeff_path, out_topology_path, ] { assert!(!Path::new(path).exists(), "File already exists: {path}"); } + if let Some(path) = &out_ordering_coeff_path { + assert!(!Path::new(path).exists(), "File already exists: {path}"); + } let (mut mixnodes, sender_peers_list) = if paramset.random_topology { build_random_network(¶mset, seed, out_topology_path) @@ -188,20 +190,22 @@ pub fn run_iteration( format!("{out_received_sequence_path_prefix}_unified.csv").as_str(), ); } - // Calculate ordering coefficients and save them to a CSV file. - if paramset.queue_type != QueueType::NonMix { - if let Some(unified_recv_seq) = &unified_received_sequence { - let casual = sent_sequence.ordering_coefficient(unified_recv_seq, true); - let weak = sent_sequence.ordering_coefficient(unified_recv_seq, false); - save_ordering_coefficients(&[[casual, weak]], out_ordering_coeff_path); - } else { - let mut coeffs: Vec<[u64; 2]> = Vec::new(); - for recv_seq in received_sequences.iter() { - let casual = sent_sequence.ordering_coefficient(recv_seq, true); - let weak = sent_sequence.ordering_coefficient(recv_seq, false); - coeffs.push([casual, weak]); + // Calculate ordering coefficients and save them to a CSV file (if enabled) + if let Some(out_ordering_coeff_path) = &out_ordering_coeff_path { + if paramset.queue_type != QueueType::NonMix { + if let Some(unified_recv_seq) = &unified_received_sequence { + let casual = sent_sequence.ordering_coefficient(unified_recv_seq, true); + let weak = sent_sequence.ordering_coefficient(unified_recv_seq, false); + save_ordering_coefficients(&[[casual, weak]], out_ordering_coeff_path); + } else { + let mut coeffs: Vec<[u64; 2]> = Vec::new(); + for recv_seq in received_sequences.iter() { + let casual = sent_sequence.ordering_coefficient(recv_seq, true); + let weak = sent_sequence.ordering_coefficient(recv_seq, false); + coeffs.push([casual, weak]); + } + save_ordering_coefficients(&coeffs, out_ordering_coeff_path); } - save_ordering_coefficients(&coeffs, out_ordering_coeff_path); } } diff --git a/mixnet-rs/ordering/src/main.rs b/mixnet-rs/ordering/src/main.rs index c8af9f3..6ec5d27 100644 --- a/mixnet-rs/ordering/src/main.rs +++ b/mixnet-rs/ordering/src/main.rs @@ -25,6 +25,8 @@ struct Args { queue_type: QueueType, #[arg(short, long)] outdir: String, + #[arg(short, long, default_value_t = false)] + skip_coeff_calc: bool, #[arg(short, long)] from_paramset: Option, #[arg(short, long)] @@ -41,6 +43,7 @@ fn main() { session_id, queue_type, outdir, + skip_coeff_calc, from_paramset, to_paramset, } = args; @@ -95,14 +98,19 @@ fn main() { &format!("{paramset_dir}/iteration_{i}_sent_seq.csv"), &format!("{paramset_dir}/iteration_{i}_recv_seq"), &wip_queue_data_msgs_counts_path, - &format!("{paramset_dir}/iteration_{i}_ordering_coeff.csv"), + if !skip_coeff_calc { + Some(format!("{paramset_dir}/iteration_{i}_ordering_coeff.csv")) + } else { + None + }, &format!("{paramset_dir}/iteration_{i}_topology.csv"), ); let duration = SystemTime::now().duration_since(start_time).unwrap(); + let duration_human = format_duration(duration); dur_writer .write_record([ i.to_string(), - format_duration(duration), + duration_human.clone(), duration.as_secs().to_string(), vtime.to_string(), ]) @@ -112,7 +120,13 @@ fn main() { wip_queue_data_msgs_counts_path.replace("__WIP__iteration_", "iteration_"); std::fs::rename(&wip_queue_data_msgs_counts_path, &new_queue_data_msgs_counts_path).expect("Failed to rename {wip_queue_data_msgs_counts_path} -> {new_queue_data_msgs_counts_path}: {e}"); - tracing::info!("ParamSet:{}, Iteration:{} completed.", paramset.id, i); + tracing::info!( + "ParamSet:{}, Iteration:{} completed. Duration:{}, vtime:{}", + paramset.id, + i, + duration_human, + vtime + ); } dur_writer.flush().unwrap();