title: Using MPI's Scatterv returns different data than data sent
body: <p>I am trying to partially solve the Travelling Salesman Problem for 10 cities to show the best tour and its cost. The first part of the solution using mpi4py should have the root process=0 share partial tours equally between the other processes using Scatterv.
  This is the code that attempts to do that below:</p>
  <pre><code>def partition_tree(my_rank, my_stack, comm_size):
  # Process 0 will generate a list of comm_size partial tours .
  # Memory wont be shared, it will send the initial partial tours to the ap
  # So it will send many tours using scatter to each process  
  # process 0 will need to send the initial tours to the appropriate process 
  partial_tours = []
  split_sizes = []
  split =[]
  if my_rank == 0:
      # first to create the different partial tours 
      for i in range(1, n):
          partial_tours.append([0, i])
  
      snd_buf = np.array(partial_tours)
  
      # now to equally divide the number of processes 
  
      split = np.array_split(partial_tours, comm_size, axis = 0)
      print(f&quot;This is split {split}&quot;)
      
      split_sizes = []
  
      for i in range(0,len(split),1):
          split_sizes = np.append(split_sizes, len(split[i]))
  
      # displacement: the starting index of each sub-task
      # displ = [sum(count[:p]) for p in range(comm_size)]
      # displ = np.array(displ)
      split_sizes_input = split_sizes * (n-1)
      
      displacements_input = np.insert(np.cumsum(split_sizes_input), 0, 0)[0:-1]
      print(f&quot;this is displ {displacements_input}&quot;)
  
      split_sizes_output = split_sizes* (n-1)
      displacements_output = np.insert(np.cumsum(split_sizes_output),0,0)[0:-1]
  
      print(&quot;Input data split into vectors of sizes %s&quot; %split_sizes_input)
      print(&quot;Input data split with displacements of %s&quot; %displacements_input)
  
      
  else:
      snd_buf = None
      # initialize count on worker processes
      # count = np.zeros(comm_size, dtype=np.intc)
      displacements_input = None
      split_sizes_input = None
      displacements_input = None
      split_sizes_output = None
      displacements_output = None
  
  # on all processes we have the initial rcv_buf 
  # recv_buf = np.zeros(count[my_rank])
  
  split = comm_world.bcast(split, root = 0)
  split_sizes = comm_world.bcast(split_sizes_input, root = 0)
  displacements = comm_world.bcast(displacements_input, root = 0)
  split_sizes_output = comm_world.bcast(split_sizes_output, root = 0)
  displacements_output = comm_world.bcast(displacements_output, root = 0) 
  
  recv_buf = np.empty(np.shape(split[my_rank]))
  print(f&quot;this is recv_buf {recv_buf} for process {my_rank}&quot;)
  
  print(f&quot;this is snd_buf {snd_buf}&quot;)
  
  # recv_buf = np.empty(np.shape(split[my_rank]))  
  print(&quot;Rank %d with recv_buf shape %s&quot; %(my_rank,recv_buf.shape))
  
  comm_world.Scatterv([snd_buf, split_sizes_input, displacements_input, MPI.INT], recv_buf, root = 0)
  
  
  print(f&quot;After scatter this is the partial tour {recv_buf} with process {my_rank}&quot;)
  </code></pre>
  <p>However, the output of the console yields this:</p>
  <pre><code>This is split [array([[0, 1],
         [0, 2],
         [0, 3]]), array([[0, 4],
         [0, 5],
         [0, 6]]), array([[0, 7],
         [0, 8],
         [0, 9]])]
  this is displ [ 0. 27. 54.]
  Input data split into vectors of sizes [27. 27. 27.]
  Input data split with displacements of [ 0. 27. 54.]
  this is recv_buf [0.         2.73861279 2.23606798 4.70372193 2.73861279 2.23606798
   4.70372193 2.73861279 2.23606798 0.        ] for process 1
  this is snd_buf None
  Rank 1 with recv_buf shape (10,)
  this is recv_buf [[0.0000e+000 1.0094e-320]
   [4.9407e-324 0.0000e+000]
   [0.0000e+000 0.0000e+000]] for process 0
  this is recv_buf [0.00000000e+000 1.99803933e+161 8.11662299e+217 5.59943824e-067
   4.26215333e+180 1.36559641e+161 8.38861115e+242 6.96409704e+252
   0.00000000e+000 0.00000000e+000] for process 2
  this is snd_buf None
  Rank 2 with recv_buf shape (10,)
  this is snd_buf [[0 1]
   [0 2]
   [0 3]
   [0 4]
   [0 5]
   [0 6]
   [0 7]
   [0 8]
   [0 9]]
  Rank 0 with recv_buf shape (3, 2)
  After scatter this is the partial tour [[0.0e+000 4.9e-324]
   [0.0e+000 9.9e-324]
   [0.0e+000 1.5e-323]] with process 0
  Traceback (most recent call last):
    File &quot;/Users/jahan/Desktop/CS381-16/Assignments/Project/tree-search.py&quot;, line 230, in &lt;module&gt;
  Traceback (most recent call last):
    File &quot;/Users/jahan/Desktop/CS381-16/Assignments/Project/tree-search.py&quot;, line 230, in &lt;module&gt;
      partition_tree(my_rank, my_stack, comm_size)
    File &quot;/Users/jahan/Desktop/CS381-16/Assignments/Project/tree-search.py&quot;, line 199, in partition_tree
      partition_tree(my_rank, my_stack, comm_size)
    File &quot;/Users/jahan/Desktop/CS381-16/Assignments/Project/tree-search.py&quot;, line 199, in partition_tree
      comm_world.Scatterv([snd_buf, split_sizes_input, displacements_input, MPI.INT], recv_buf, root = 0)
    File &quot;mpi4py/MPI/Comm.pyx&quot;, line 759, in mpi4py.MPI.Comm.Scatterv
      comm_world.Scatterv([snd_buf, split_sizes_input, displacements_input, MPI.INT], recv_buf, root = 0)
    File &quot;mpi4py/MPI/Comm.pyx&quot;, line 759, in mpi4py.MPI.Comm.Scatterv
  mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated
  mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated
  --------------------------------------------------------------------------
  Primary job  terminated normally, but 1 process returned
  a non-zero exit code. Per user-direction, the job has been aborted.
  --------------------------------------------------------------------------
  --------------------------------------------------------------------------
  mpirun detected that one or more processes exited with non-zero status, thus causing
  the job to be terminated. The first process to do so was:
  
    Process name: [[55033,1],2]
    Exit code:    1
  --------------------------------------------------------------------------
  
  </code></pre>
  <p>The receive buffer receives these results. I suspect it might have to do with the shape of the snd_buf and the recv_buf not matching but this still has the errors. Does anyone know how to use the scatterv function?
  Specifically:</p>
  <pre><code>    comm_world.Scatterv([snd_buf, split_sizes_input, displacements_input, MPI.INT], recv_buf, root = 0)
  </code></pre>