Skip to content

Commit

Permalink
Update partition_network.rs script. We will run it on the head node b…
Browse files Browse the repository at this point in the history
…efore copying input files to the compute nodes, so that each compute node will have a partitioned network available
  • Loading branch information
janekdererste committed Sep 2, 2024
1 parent 0bff843 commit f27e580
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 69 deletions.
89 changes: 21 additions & 68 deletions src/bin/partition_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,43 @@ use clap::{arg, Parser};
use tracing::info;

use rust_q_sim::simulation::config::{MetisOptions, PartitionMethod};
use rust_q_sim::simulation::id;
use rust_q_sim::simulation::network::global_network::Network;

fn main() {
rust_q_sim::simulation::logging::init_std_out_logging();
let args = InputArgs::parse();

let input_path = PathBuf::from(&args.in_path);
let folder = input_path.parent().unwrap();
let mut name_parts: Vec<&str> = input_path
if let Some(id_path) = args.id_path {
id::load_from_file(&id_path);
}

//let input_path = PathBuf::from(&args.in_path);
let folder = args.net_path.parent().unwrap();
let mut name_parts: Vec<&str> = args
.net_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.split('.')
.collect();
let num_parts_string = args.num_parts.to_string();
name_parts.insert(name_parts.len() - 2, num_parts_string.as_str());
name_parts.insert(name_parts.len() - 1, num_parts_string.as_str());
let out_path = folder.join(name_parts.join("."));
info!("Writing to {:?}", out_path);
name_parts.insert(name_parts.len() - 3, "internal-ids");
let out_path_internal = folder.join(name_parts.join("."));
info!("Writing to {:?}", out_path_internal);
//info!("Writing to {:?}", out_path);
//name_parts.insert(name_parts.len() - 3, "internal-ids");
// let out_path_internal = folder.join(name_parts.join("."));
//info!("Writing to {:?}", out_path_internal);

info!(
"Partition network: {} into {} parts",
args.in_path, args.num_parts
args.net_path.to_str().unwrap(),
args.num_parts
);

let net1 = Network::from_file(
&args.in_path,
let net1 = Network::from_file_path(
&args.net_path,
args.num_parts,
PartitionMethod::Metis(MetisOptions::default()),
);
Expand All @@ -44,70 +51,16 @@ fn main() {
);

net1.to_file(&out_path);
//to_file_internal_ids(&net1, &out_path_internal);

info!("Finished partitioning Network.")
}
/*
fn to_file_internal_ids(network: &Network, file_path: &Path) {
let mut result = IONetwork::new(None);
for node in &network.nodes {
let attributes = Attrs {
attributes: vec![Attr {
name: String::from("partition"),
value: node.partition.to_string(),
class: String::from("java.lang.Integer"),
}],
};
let io_node = IONode {
id: node.id.internal().to_string(),
x: node.x,
y: node.y,
attributes: Some(attributes),
};
result.nodes_mut().push(io_node);
}
for link in &network.links {
let modes = link
.modes
.iter()
.map(|m| m.external().to_string())
.reduce(|modes, mode| format!("{modes},{mode}"))
.unwrap();
let attributes = Attrs {
attributes: vec![Attr {
name: String::from("partition"),
value: link.partition.to_string(),
class: String::from("java.lang.Integer"),
}],
};

let io_link = IOLink {
id: link.id.internal().to_string(),
from: link.from.internal().to_string(),
to: link.to.external().to_string(),
length: link.length,
capacity: link.capacity,
freespeed: link.freespeed,
permlanes: link.permlanes,
modes,
attributes: Some(attributes),
};
result.links.effective_cell_size = Some(network.effective_cell_size);
result.links_mut().push(io_link);
}
result.to_file(file_path);
}
*/
#[derive(Parser, Debug)]
struct InputArgs {
#[arg(short, long)]
pub in_path: String,
pub net_path: PathBuf,
#[arg(short, long)]
pub id_path: Option<PathBuf>,
#[arg(long)]
pub num_parts: u32,
}
5 changes: 4 additions & 1 deletion src/simulation/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ fn execute_partition<C: SimCommunicator + 'static>(comm: C, args: &CommandLineAr
config.partitioning().num_parts,
)
} else {
io::resolve_path(config_path, &config.proto_files().network)
insert_number_in_proto_filename(
&io::resolve_path(config_path, &config.proto_files().network),
config.partitioning().num_parts,
)
};
let network = Network::from_file_as_is(&network_path);
let mut garage = Garage::from_file(&io::resolve_path(
Expand Down

0 comments on commit f27e580

Please sign in to comment.