2

I would like to perform the following processing in multi-threads using tokio or async-std. I have read tutorials but I haven't seen any mention of parallelizing a for loop. In my program, all threads refer to the same array but will access different locations:

let input_array: Array2<f32>;  
let output_array: Array2<f32>;
for i in 0..roop_num {
  let res = do_some_func(&input_array, idx);
  output_array.slice_mut(s![idx, ...]) .assign(&res);
}

I would like to change the for loop to use parallel processing.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
musako
  • 897
  • 2
  • 10
  • 26

1 Answers1

3

Tokio or async-std deal with concurrency, not parallelism. If you need the data parallelism then rayon is a better choice. If you are using an Iterator, then .chunks() method is good. For more imperative approach you can use .par_chunks_mut().

kmdreko
  • 42,554
  • 6
  • 57
  • 106
slsy
  • 1,257
  • 8
  • 21