Skip to content

Commit

Permalink
Resolve a-b-street#50 by parallelizing raw->map jobs using std::thread
Browse files Browse the repository at this point in the history
  • Loading branch information
JavedNissar committed May 9, 2020
1 parent ed4cf78 commit 76f43b8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion importer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod los_angeles;
mod seattle;
mod soundcast;
mod utils;
use std::thread;

struct Job {
city: String,
Expand Down Expand Up @@ -51,6 +52,7 @@ fn main() {
abstutil::list_all_objects(format!("../data/input/{}/polygons", job.city))
};

let mut handles = vec![];
for name in names {
if job.osm_to_raw {
match job.city.as_ref() {
Expand All @@ -63,7 +65,13 @@ fn main() {
}

if job.raw_to_map {
utils::raw_to_map(&name, job.use_fixes);
let thread_name = name.clone();
//Fetch use_fixes after already loading into job in order to avoid move compile error
let use_fixes = job.use_fixes;
let handle = thread::spawn(move || {
utils::raw_to_map(&thread_name, use_fixes);
});
handles.push(handle);
}

if job.scenario {
Expand All @@ -84,4 +92,7 @@ fn main() {
soundcast::make_weekday_scenario_with_everyone(&map, &mut timer).save();
}
}
for handle in handles {
handle.join().unwrap();
}
}

0 comments on commit 76f43b8

Please sign in to comment.