Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion rust/bambam-gtfs/src/schedule/bundle_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ pub fn batch_process(
.map_err(|e| ScheduleError::GtfsApp(format!("failure reading directory: {e}")))?
.collect::<Result<Vec<_>, _>>()
.map_err(|e| ScheduleError::GtfsApp(format!("failure reading directory: {e}")))?;
let chunk_size = archive_paths.len() / std::cmp::max(1, parallelism);

let n_archives = archive_paths.len();
if n_archives == 0 {
let msg = format!(
"directory {} is empty",
bundle_directory_path.to_string_lossy()
);
return Err(ScheduleError::InvalidData(msg));
}

let chunk_size = calculate_chunk_size(n_archives, parallelism);

// a progress bar shared across threads
let bar: Arc<Mutex<Bar>> = Arc::new(Mutex::new(
Expand Down Expand Up @@ -700,3 +710,13 @@ fn archive_intersects_extent(gtfs: &Gtfs, extent: &Geometry) -> Result<bool, Sch
}
Ok(false)
}

/// safely calculates a chunk size argument which is non-zero
fn calculate_chunk_size(archives: usize, parallelism: usize) -> usize {
let par_denom = std::cmp::max(1, parallelism);
if archives < par_denom {
1
} else {
archives / par_denom
}
}
2 changes: 1 addition & 1 deletion rust/bambam/src/app/gtfs_config/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ where
Ok(result)
}

/// finds what modes are already available via other edge lists in the config.
/// finds what modes are already available via other edge lists via the Label model in the config.
/// assumes that each edge list has a "multimodal" TraversalModel type.
/// enforces that the mode list matches the listing in the label model.
pub fn get_available_modes(base_conf: &CompassAppConfig) -> Result<Vec<String>, GtfsConfigError> {
Expand Down
Loading