Skip to main content

pop_prepare

Function pop_prepare 

Source
pub fn pop_prepare()
Expand description

Give every worker a slot. Call once before the timed repetitions.

Does nothing until engage or LINKCELL_POP.

Examples found in repository?
examples/knn_scale.rs (line 103)
80fn main() {
81    let nside = nside_of(env_usize("KNN_SCALE_N", 262_144));
82    let k = env_usize("KNN_SCALE_K", 4);
83    let reps = env_usize("KNN_SCALE_REPS", 6);
84    let shape = std::env::var("KNN_SCALE_SHAPE").unwrap_or_else(|_| "cubic".to_string());
85    let hint: f64 = std::env::var("KNN_SCALE_HINT")
86        .ok()
87        .and_then(|s| s.parse().ok())
88        .unwrap_or(3.0);
89    let (mut xyz, cell) = match shape.as_str() {
90        "cubic" => cubic(nside),
91        "tilt" => tilt(nside),
92        other => panic!("unknown KNN_SCALE_SHAPE {other}"),
93    };
94    if let Some(seed) = std::env::var("KNN_SCALE_SHUFFLE")
95        .ok()
96        .and_then(|s| s.parse().ok())
97    {
98        shuffle(&mut xyz, seed);
99    }
100    let threads = std::env::var("RAYON_NUM_THREADS").unwrap_or_else(|_| "default".to_string());
101    let mut out = vec![-1i32; xyz.len() * k];
102    linkcell::pop_engage();
103    linkcell::pop_prepare();
104    knearest_into(&xyz, &cell, k, None, Some(hint), &mut out).expect("warmup");
105    linkcell::pop_reset();
106    let mut acc = 0i32;
107    let started = Instant::now();
108    for _ in 0..reps {
109        knearest_into(&xyz, &cell, k, None, Some(hint), &mut out).expect("knearest");
110        acc = acc.wrapping_add(out[0]);
111    }
112    let wall_ns = started.elapsed().as_nanos() as u64;
113    std::hint::black_box(acc);
114    let useful = linkcell::pop_snapshot();
115    let ms = wall_ns as f64 / 1e6;
116    println!(
117        "shape={shape} threads={threads} n={} k={k} reps={reps} ms={ms:.1} ms_per={:.2}",
118        xyz.len(),
119        ms / reps as f64
120    );
121    let (lb, ce, pe) = linkcell::pop_efficiencies(&useful, wall_ns);
122    let list = useful
123        .iter()
124        .map(|ns| ns.to_string())
125        .collect::<Vec<_>>()
126        .join(",");
127    println!(
128        "pop shape={shape} threads={threads} n={} reps={reps} wall_ns={wall_ns} useful_ns={list} lb={lb:.4} ce={ce:.4} pe={pe:.4}",
129        xyz.len()
130    );
131}
More examples
Hide additional examples
examples/pairs_scale.rs (line 73)
56fn main() {
57    let n = env_usize("PAIRS_N", 4096);
58    let reps = env_usize("PAIRS_REPS", 5).max(1);
59    let half = std::env::var("PAIRS_HALF").ok().as_deref() == Some("1");
60    let hint = std::env::var("PAIRS_HINT")
61        .ok()
62        .and_then(|s| s.parse().ok());
63    let threads = std::env::var("RAYON_NUM_THREADS").unwrap_or_else(|_| "default".to_string());
64    let mut xyz = fill(n);
65    if let Some(seed) = std::env::var("PAIRS_SHUFFLE")
66        .ok()
67        .and_then(|s| s.parse().ok())
68    {
69        shuffle(&mut xyz, seed);
70    }
71    let cell = Cell::ortho(18.0, 18.0, 18.0).expect("box");
72    linkcell::pop_engage();
73    linkcell::pop_prepare();
74    let mut pairs = Vec::new();
75    let mut early = Vec::new();
76    for _ in 0..3 {
77        let t = Instant::now();
78        pairs = pairs_within(&xyz, &cell, 4.0, None, hint, half).expect("pairs");
79        early.push(t.elapsed().as_secs_f64() * 1e3);
80    }
81    linkcell::pop_reset();
82    let t0 = Instant::now();
83    let mut acc = 0usize;
84    for _ in 0..reps {
85        let got = pairs_within(&xyz, &cell, 4.0, None, hint, half).expect("pairs");
86        acc += got.len();
87    }
88    let wall_ns = t0.elapsed().as_nanos() as u64;
89    let ms = wall_ns as f64 / 1e6;
90    println!(
91        "n={} half={} hint={:?} pairs={} cold={:.3} call2={:.3} call3={:.3} reps={} ms_per={:.4} acc={}",
92        xyz.len(),
93        half as u8,
94        hint,
95        pairs.len(),
96        early[0],
97        early[1],
98        early[2],
99        reps,
100        ms / reps as f64,
101        acc
102    );
103    let useful = linkcell::pop_snapshot();
104    let (lb, ce, pe) = linkcell::pop_efficiencies(&useful, wall_ns);
105    let list = useful
106        .iter()
107        .map(|ns| ns.to_string())
108        .collect::<Vec<_>>()
109        .join(",");
110    println!(
111        "pop shape=pairs-{n}-h{} threads={threads} n={n} reps={reps} wall_ns={wall_ns} useful_ns={list} lb={lb:.4} ce={ce:.4} pe={pe:.4}",
112        half as u8
113    );
114}