/
concept-collection
/
math-webgpu-sandbox
Jump to
/
Appearance
Match my system
Paper
GitHub
Slate
Midnight
Terminal
Sign in
concept-collection
/
math-webgpu-sandbox
Code
Commits
Issues
0
Pull requests
0
Actions
Branches
1
Tags
0
Site
e01ddf1
Branches
main
math-webgpu-sandbox
/
examples
/
monte_carlo_pi.m
9 lines · 287 B
Copy
Copied
Blame
History
Raw
1
% Monte Carlo estimate of pi: comparisons and logicals fuse too, so the
2
% mask never touches memory -- one fused pass plus the reduction.
3
n =
10000000
;
4
tic;
5
x =
2
*rand(n,
1
) -
1
;
6
y =
2
*rand(n,
1
) -
1
;
7
pi_est =
4
*mean((x.^
2
+ y.^
2
) <=
1
);
8
toc
9
fprintf(
'pi ~ %.6f (n = %d)\n'
, pi_est, n);
↑
↓
move
↵
open
esc
close