I apologise if I ask an already-answered question. I looked through similar questions on the Forum, but couldn’t recognise any that really match my question; I’m still very new to Rust.
Working in Swift, I created a program which iterated over sections of an array in parallel. These sections are set by markers from a different array; the sections are different sizes. I create a DispatchQueue.concurrentPerform, which lets me set the number of iterators/threads, and run loops on each section chosen by the thread number.
In Swift, the code looks like this:
// variables:
// array: a large, mutable array of u32 numbers
// threads: the number of threads/iterations
// sections: an array of integers marking the start/stop indexes of each section, as set by ‘threads’.
DispatchQueue.concurrentPerform(iterations: threads) { k in // k is each thread number
let min = sections[k]
let max = sections[k + 1]
for i in min..<max {
// perform operations on array[i]
}
}
This works well in Swift, but I’m trying to work out what the equivalent code in Rust would be. I know that Rayon can let me set the number of threads vis ThreadPoolBuilder, but I’m not yet clear as to how to set particular sections to each thread.