-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathpi.rs
35 lines (27 loc) · 844 Bytes
/
pi.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
#[macro_use(mem_info)]
extern crate arrayfire as af;
use std::time::Instant;
use af::*;
#[allow(unused_must_use)]
#[allow(unused_variables)]
fn main() {
set_device(0);
info();
let samples = 20_000_000;
let dims = Dim4::new(&[samples, 1, 1, 1]);
let x = &randu::<f32>(dims);
let y = &randu::<f32>(dims);
let start = Instant::now();
mem_info!("Before benchmark");
for bench_iter in 0..100 {
let xsqrd = &mul(x, x, false);
let ysqrd = &mul(y, y, false);
let xplusy = &add(xsqrd, ysqrd, false);
let root = &sqrt(xplusy);
let cnst = &constant(1, dims);
let (real, imag) = sum_all(&le(root, cnst, false));
let pi_val = real*4.0/(samples as f64);
}
println!("Estimated Pi Value in {:?}", start.elapsed());
mem_info!("After benchmark");
}