andreafranceschini
andreafranceschini
MModular
Created by andreafranceschini on 10/24/2023 in #questions
UniversalExceptionRaise - (os/kern) failure when running montecarlo with high number of samples
For reference, the code is the following
from random import rand
from tensor import Tensor
from algorithm import vectorize, parallelize
from sys.info import simdbitwidth

alias type = DType.float64
alias nelts: Int = simdwidthof[type]()

fn est_pi(n: Int) -> Float64:
let pts = rand[type](n * 2)

print(pts.simd_load[10](0))

var inside = 0

@parameter
fn calc_distance[nelts: Int](idx: Int) -> None:
let dist = pts.simd_load[nelts](idx).__pow__(2) + pts.simd_load[nelts](n + idx).__pow__(2)
inside += (dist < 1).cast[DType.int16]().reduce_add().to_int()

vectorize[nelts, calc_distance](n)

return inside / n * 4

fn main():
let N = 100_000_000
let est = est_pi(N)
print(est)
from random import rand
from tensor import Tensor
from algorithm import vectorize, parallelize
from sys.info import simdbitwidth

alias type = DType.float64
alias nelts: Int = simdwidthof[type]()

fn est_pi(n: Int) -> Float64:
let pts = rand[type](n * 2)

print(pts.simd_load[10](0))

var inside = 0

@parameter
fn calc_distance[nelts: Int](idx: Int) -> None:
let dist = pts.simd_load[nelts](idx).__pow__(2) + pts.simd_load[nelts](n + idx).__pow__(2)
inside += (dist < 1).cast[DType.int16]().reduce_add().to_int()

vectorize[nelts, calc_distance](n)

return inside / n * 4

fn main():
let N = 100_000_000
let est = est_pi(N)
print(est)
Thanks in advance!
2 replies