'Error obtained in rsmpi using MPI_Gather function

I a writing a simple code for MPI Gather, but I am getting the error: An error occurred in MPI_Gather reported by process [1154023425,0] on communicator MPI_COMM_WORLD.

My code is:

extern crate mpi;

use mpi::request::WaitGuard;
use mpi::topology::CommunicatorRelation;
use mpi::traits::*;

const N_x_total:usize = 12;
const N_ghost:usize = 1;
const N_t:usize = 20;

fn main() {
    let universe = mpi::initialize().unwrap();
    let world = universe.world();
    let size = world.size();
    let rank = world.rank();
    let root_rank = 0;
    let root_process = world.process_at_rank(root_rank);
    let N_x = N_x_total/(size as usize);
    let start = N_ghost;
    let end = start + N_x - 1;
    let mut u_old = vec!(10.0; N_x + 2*N_ghost);
    let mut u_new = vec!(0.0; N_x + 2*N_ghost);
    let mut u_global = vec!(0.0; N_x_total + 2*N_ghost);
    if world.rank() == root_rank {
        root_process.gather_into_root(&u_old[start..=end], &mut u_global[start..=(start+N_x_total-1)]);
    }
    else {
        root_process.gather_into(&u_old[start..=end]);
    }
    if rank == 0 {
        println!("Solution is: {:?}", u_global);
    }
}

The aim is to copy gather the values from all the processes of u_old to u_global starting from index start. Please help!

For reference, in C++ this MPI Gather works:

MPI_Gather(u_old+start, N_x, MPI_DOUBLE, u_global+start, N_x, MPI_DOUBLE, 0, MPI_COMM_WORLD);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source