fn distributed_vector_add(world: SystemCommunicator, vec1: Evec<i32>, vec2: Evec<i32>) -> Evec<i32>{
    let rank = world.rank(); // Identifier for node running THIS instance
    let size = world.size();

    let smallest_len = if vec1.smaller(&vec2) {
        vec1.size() as i32
    } else {
        vec2.size() as i32
    };

    // Calculate interval for this node
    let start = (smallest_len * rank / size) as i32;
    let len = (smallest_len * (rank + 1) / size) as i32 - (smallest_len * rank / size) as i32;

    let msg: Vec<_> = (0..len)
        .map(|x| vec1.vec[(x+start) as usize] + vec2.vec[(x+start) as usize])
        .collect();

    // Check if the array is dividable with the number of processes
    let counts: Vec<Count> = match smallest_len % size == 0{
        true => {
            vec![len; size as usize]
        }
        false => {
            let mut tmp_v = Vec::new();
            for i in 0..size {
                let tmp_l = (smallest_len * (i + 1) / size) as i32 - (smallest_len * i / size) as i32;
                tmp_v.push(tmp_l);
            }
            tmp_v
        }
    };

    let displs: Vec<Count> = counts
        .iter()
        .scan(0, |acc, &x| {
            let tmp = *acc;
            *acc += x;
            Some(tmp)
        })
        .collect();

    let mut buf = vec![0; smallest_len as usize];

    {
        let mut partition = PartitionMut::new(&mut buf[..], counts, &displs[..]);
        world.all_gather_varcount_into(&msg[..], &mut partition);
    }

    Evec { vec: buf}
}
/// Perform vector in a distributed setting, using MPI capabilities.
///
/// Will only use the number of elements equal to the length of the smallest array, excess
/// elements will be dropped.
Perform vector in a distributed setting, using MPI capabilities.
Will only use the number of elements equal to the length of the smallest array, excess
elements will be dropped.
Perform vector in a distributed setting using MPI capabilities . Will only use the number of elements equal to the length of the smallest array excess elements will be dropped .
fn distributed_vector_add(world: SystemCommunicator, vec1: Evec<i32>, vec2: Evec<i32>) -> Evec<i32>{
    let rank = world.rank(); // Identifier for node running THIS instance
    let size = world.size();
    let smallest_len = if vec1.smaller(&vec2) {
        vec1.size() as i32
    } else {
        vec2.size() as i32
    };
    // Calculate interval for this node
    let start = (smallest_len * rank / size) as i32;
    let len = (smallest_len * (rank + 1) / size) as i32 - (smallest_len * rank / size) as i32;
    let msg: Vec<_> = (0..len)
        .map(|x| vec1.vec[(x+start) as usize] + vec2.vec[(x+start) as usize])
        .collect();
    // Check if the array is dividable with the number of processes
    let counts: Vec<Count> = match smallest_len % size == 0{
        true => {
            vec![len; size as usize]
        }
        false => {
            let mut tmp_v = Vec::new();
            for i in 0..size {
                let tmp_l = (smallest_len * (i + 1) / size) as i32 - (smallest_len * i / size) as i32;
                tmp_v.push(tmp_l);
            }
            tmp_v
        }
    };
    let displs: Vec<Count> = counts
        .iter()
        .scan(0, |acc, &x| {
            let tmp = *acc;
            *acc += x;
            Some(tmp)
        })
        .collect();
    let mut buf = vec![0; smallest_len as usize];
    {
        let mut partition = PartitionMut::new(&mut buf[..], counts, &displs[..]);
        world.all_gather_varcount_into(&msg[..], &mut partition);
    }
    Evec { vec: buf}
}
fn distributed_vector_add ( world : SystemCommunicator , vec1 : Evec < i32 > , vec2 : Evec < i32 > ) -> Evec < i32 > { let rank = world . rank ( ) ; // Identifier for node running THIS instance let size = world . size ( ) ; let smallest_len = if vec1 . smaller ( & vec2 ) { vec1 . size ( ) as i32 } else { vec2 . size ( ) as i32 } ; // Calculate interval for this node let start = ( smallest_len * rank / size ) as i32 ; let len = ( smallest_len * ( rank + 1 ) / size ) as i32 - ( smallest_len * rank / size ) as i32 ; let msg : Vec < _ > = ( 0 .. len ) . map ( | x | vec1 . vec [ ( x + start ) as usize ] + vec2 . vec [ ( x + start ) as usize ] ) . collect ( ) ; // Check if the array is dividable with the number of processes let counts : Vec < Count > = match smallest_len % size == 0 { true => { vec ! [ len size as usize ] } false => { let mut tmp_v = Vec :: new ( ) ; for i in 0 .. size { let tmp_l = ( smallest_len * ( i + 1 ) / size ) as i32 - ( smallest_len * i / size ) as i32 ; tmp_v . push ( tmp_l ) ; } tmp_v } } ; let displs : Vec < Count > = counts . iter ( ) . scan ( 0 , | acc , & x | { let tmp = * acc ; * acc += x ; Some ( tmp ) } ) . collect ( ) ; let mut buf = vec ! [ 0 smallest_len as usize ] ; { let mut partition = PartitionMut :: new ( & mut buf [ .. ] , counts , & displs [ .. ] ) ; world . all_gather_varcount_into ( & msg [ .. ] , & mut partition ) ; } Evec { vec : buf } }
Perform vector in a distributed setting, using MPI capabilities.
Perform vector in a distributed setting using MPI capabilities .
world
SystemCommunicator
vec1
Evec<i32>
vec2
Evec<i32>