Rayon implementation of Triple modular redundancy

Hello all,
What is the best way to implement TMR in Rayon?
In TMR the computation is replicated in several threads (three) that work on replicas of the same data. Once they finish, the results are compared to find mismatches.
The equivalence in openMP would be something like:

data0=data;
data1=data;
data2=data;

  #pragma omp parallel sections num_threads(MAX_THREADS){
            #pragma omp section    {
                int ithread = omp_get_thread_num();
                test(ithread);
            }
            #pragma omp section  {
                int ithread = omp_get_thread_num();
                test(ithread);                
            }
            #pragma omp section {
                int ithread = omp_get_thread_num();
                test(ithread);
            }
        }
test(ithread){
   switch(ithread){
     case 0: process(data0); break
     case 1: process(data1); break
     case 2: process(data2); break
   }
}

Thanks

I think broadcast into a thread pool with three threads is what you are looking for:

fn process(_: [u8; 3]) {}

fn main() {
    let pool = rayon::ThreadPoolBuilder::new().num_threads(3).build().unwrap();
    
    let data = [0, 1, 2];
    
    let data1 = data.clone();
    let data2 = data.clone();
    let data3 = data.clone();
    
    pool.broadcast(|ctx| {
        println!("thread: {}", ctx.index());
        
        match ctx.index() {
            0 => process(data1),
            1 => process(data2),
            2 => process(data3),
            _ => panic!(),
        }
    });
}

Stdout:

thread: 0
thread: 2
thread: 1

Playground.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.