Skip to content

Commit

Permalink
Remove num_cpus crate
Browse files Browse the repository at this point in the history
Since Rust 1.59.0, we can use `std::thread::available_parallelism`
to get "an estimate of default amount of parallelism". Since sometimes
the number of CPU is NOT same as *available parallelism*. it's better
to use this function instead of `num_cpus::get()` function.

Related to: #78 (see changelog)
  • Loading branch information
yammmt committed Oct 21, 2023
1 parent 3ca0eb1 commit 4b4263c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ glob = "^0.3"
image = "^0.24"
log = "^0.4"
minifb = "^0.25"
num_cpus = "^1.16"
rand = "^0.8"
rayon = "^1.8"
simple_logger = "^4.2"
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ fn image_buffer_from_filepath<P>(
let (width, height) = rgb.dimensions();
let mut buf: Vec<u32> = vec![0; (width * height) as usize];

let threads = num_cpus::get();
let rows_per_band = height / threads as u32 + 1;
let threads =
std::thread::available_parallelism().expect("Failed to get available parallelism num");
let rows_per_band = height / threads.get() as u32 + 1;
let bands: Vec<&mut [u32]> = buf.chunks_mut((rows_per_band * width) as usize).collect();
bands.into_par_iter().enumerate().for_each(|(i, band)| {
for (j, b) in band.iter_mut().enumerate() {
Expand Down

0 comments on commit 4b4263c

Please sign in to comment.