UniversalExceptionRaise - (os/kern) failure when running montecarlo with high number of samples

Hey guys, I am trying to implement a pi estimator using a montecarlo simulation. It works when I use relatively small Ns but when I put N > around 100,000,000 it gives the following error
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo run /Users/andreafranceschini/Documents/Coding/utils/est_pi_fast.mojo
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mojo 0x0000000104f91990 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 mojo 0x0000000104f8faf0 llvm::sys::RunSignalHandlers() + 112
2 mojo 0x0000000104f9202c SignalHandler(int) + 344
3 libsystem_platform.dylib 0x000000018f6d2a84 _sigtramp + 56
4 libsystem_platform.dylib 0xffff80028003433c _sigtramp + 18446603340257564912
5 mojo 0x00000001052e224c M::KGEN::ExecutionEngine::runProgram(llvm::StringRef, llvm::StringRef, llvm::function_ref<M::ErrorOrSuccess (void*)>) + 1156
6 mojo 0x0000000104eebc64 run(M::State const&) + 3980
7 mojo 0x0000000104ed48e4 main + 1088
8 dyld 0x000000018f34bf28 start + 2236
[9974:226712:20231024,023119.566940:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo run /Users/andreafranceschini/Documents/Coding/utils/est_pi_fast.mojo
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mojo 0x0000000104f91990 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 mojo 0x0000000104f8faf0 llvm::sys::RunSignalHandlers() + 112
2 mojo 0x0000000104f9202c SignalHandler(int) + 344
3 libsystem_platform.dylib 0x000000018f6d2a84 _sigtramp + 56
4 libsystem_platform.dylib 0xffff80028003433c _sigtramp + 18446603340257564912
5 mojo 0x00000001052e224c M::KGEN::ExecutionEngine::runProgram(llvm::StringRef, llvm::StringRef, llvm::function_ref<M::ErrorOrSuccess (void*)>) + 1156
6 mojo 0x0000000104eebc64 run(M::State const&) + 3980
7 mojo 0x0000000104ed48e4 main + 1088
8 dyld 0x000000018f34bf28 start + 2236
[9974:226712:20231024,023119.566940:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
Thanks in advance!
1 Reply
andreafranceschini
andreafranceschiniOP15mo ago
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!
Want results from more Discord servers?
Add your server