print progress while calculating paths in parallel

This commit is contained in:
Dustin Carlino 2019-03-06 12:05:54 -08:00
parent 4ae478a7a5
commit a975d0efd4
4 changed files with 29 additions and 13 deletions

View File

@ -13,10 +13,11 @@ geom = { path = "../geom" }
histogram = "0.6.9"
map_model = { path = "../map_model" }
more-asserts = "0.2.1"
num_cpus = "1.10.0"
pretty_assertions = "0.5.1"
rand = { version = "0.6.5", features = ["serde1"] }
rand_xorshift = "0.1.1"
rayon = "1.0"
scoped_threadpool = "0.1.9"
serde = "1.0.87"
serde_derive = "1.0.87"
structopt = "0.2"

View File

@ -302,13 +302,23 @@ impl TripSpec {
}
fn calculate_paths(map: &Map, requests: Vec<PathRequest>, timer: &mut Timer) -> Vec<Option<Path>> {
use rayon::prelude::*;
scoped_threadpool::Pool::new(num_cpus::get() as u32).scoped(|scope| {
let (tx, rx) = std::sync::mpsc::channel();
let mut results: Vec<Option<Path>> = vec![None; requests.len()];
for (idx, req) in requests.into_iter().enumerate() {
let tx = tx.clone();
scope.execute(move || {
let path = Pathfinder::shortest_distance(map, req);
tx.send((idx, path)).unwrap();
});
}
drop(tx);
timer.start(&format!("calculate {} paths", requests.len()));
let paths: Vec<Option<Path>> = requests
.into_par_iter()
.map(|req| Pathfinder::shortest_distance(map, req))
.collect();
timer.stop(&format!("calculate {} paths", paths.len()));
paths
timer.start_iter("calculate paths", results.len());
for (idx, path) in rx.iter() {
timer.next();
results[idx] = path;
}
results
})
}

View File

@ -416,14 +416,17 @@ impl DrivingSimState {
return true;
}
None => {
scheduler.push(time + BLIND_RETRY, Command::UpdateCar(car.vehicle.id));
// TODO For now, always use BLIND_RETRY. Measured things to be slower
// otherwise. :(
/*
// If this car wasn't blocked at all, when would it reach its goal?
let ideal_end_time = match car.crossing_state(our_dist, time, map) {
CarState::Crossing(time_int, _) => time_int.end,
_ => unreachable!(),
};
// TODO For now, always use BLIND_RETRY. Measured things to be slower
// otherwise. :(
if ideal_end_time == time || true {
if ideal_end_time == time {
// Haha, no such luck. We're super super close to the goal, but not
// quite there yet.
scheduler.push(time + BLIND_RETRY, Command::UpdateCar(car.vehicle.id));
@ -432,6 +435,8 @@ impl DrivingSimState {
}
// TODO For cars stuck on their last step, this will spam a fair bit. But
// that should be pretty rare.
*/
return true;
}
}

View File

@ -555,7 +555,7 @@ impl Sim {
format!(
"{}: {} active agents",
self.time,
self.trips.num_active_trips()
abstutil::prettyprint_usize(self.trips.num_active_trips())
)
}