Segmentation fault for array larger than 1022x1022 -


i don't know rust wanted investigate performance in scientific computing compare julia , fortran. managed write following program problem runtime segmentation fault when max larger 1022. advice?

fn main() {     const max: usize = 1023;     let mut arr2: [[f64;  max];  max] = [[0.0;  max];  max];       let pi: f64 = 3.1415926535;     // compute useless , put in matrix     ii in 0.. max {         jj in 0.. max {             let = ii f64;             let j = jj f64;             arr2[ii][jj] = ((i + j) * pi * 41.0).sqrt().sin();         }     }  let mut sum0:f64 = 0.0;  //collapse scalar sum(sum(array,1),2) in other langs iii in 0..max {     let vec1:&[f64] = &arr2[iii][..];     sum0 += vec1.iter().sum(); } println!("this {}", sum0); } 

so no error 'segmentaion fault' in terminal. i'm using ubuntu 16 , installed command on www.rustup.rs. stable version rustc 1.12.1 (d4f39402a 2016-10-19).

you have stack overflow (how ironic, hey?).

there 2 solutions issue:

  1. do not allocate large array on stack, use heap instead (vec)
  2. only on large stack.

needless say, using vec easier; , can use vec[f64; max] if wish.

if insist on using stack, redirect to question.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -