-
Notifications
You must be signed in to change notification settings - Fork 7
/
read_hfx_concurrent.rs
43 lines (34 loc) · 1.19 KB
/
read_hfx_concurrent.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! This example reads the same dataset from multiple threads at the same time (concurrently).
use hidefix::prelude::*;
use std::sync::Arc;
fn main() -> anyhow::Result<()> {
let args: Vec<String> = std::env::args().collect();
let f = &args[1];
println!("Indexing file: {f}..");
let i = Arc::new(Index::index(&f)?);
for var in &args[2..] {
let i = Arc::clone(&i);
println!("Reading values from {var}..");
const ITERATIONS: usize = 100;
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(8)
.build()
.unwrap();
pool.scope(move |s| {
for ii in 0..ITERATIONS {
let i = Arc::clone(&i);
s.spawn(move |_| {
let mut r = i.reader(var).unwrap();
let values = &r.values::<f32, _>(..).unwrap();
println!("Iteration: {}, Number of values: {}", ii, values.len());
println!(
"Iteration: {}, First value: {}",
ii,
values.first().unwrap()
);
});
}
});
}
Ok(())
}