Syntax for Scatterv and Gatherv

1,739 views
Skip to first unread message

Jeremy Bejarano

unread,
Apr 30, 2012, 4:29:36 PM4/30/12
to mpi4py
I'm new to mpi4py and I'm having trouble using Scatterv. I haven't
been able to find an example or documentation on how to use the
function. My latest attempt to try and get the function working looks
like this:

import numpy
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
x = numpy.linspace(0,100,11)
xlocal = numpy.zeros(1)
comm.Scatterv([x,(1,1,9),(0,1,2),MPI.DOUBLE],xlocal)

and I get this:

-bash-3.2$ mpiexec -n 3 python26 parallel.py
Traceback (most recent call last):
File "parallel.py", line 10, in <module>
rank 0 xlocal [ 0.]
rank 1 xlocal [ 10.]
x None
comm.Scatterv([x,(1,1,9),(0,1,2),MPI.DOUBLE],xlocal)
File "Comm.pyx", line 454, in mpi4py.MPI.Comm.Scatterv (src/
mpi4py.MPI.c:50830)
mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated
x [ 0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]

Can anybosy correct this or give an example of correct usage?
Also, where could I best find answers to these questions on my own?

Jeremy

Lisandro Dalcin

unread,
May 2, 2012, 4:25:45 PM5/2/12
to mpi...@googlegroups.com
On 30 April 2012 17:29, Jeremy Bejarano <jmbe...@gmail.com> wrote:
> import numpy
> from mpi4py import MPI
> comm = MPI.COMM_WORLD
> rank = comm.Get_rank()
> x = numpy.linspace(0,100,11)
> xlocal = numpy.zeros(1)
> comm.Scatterv([x,(1,1,9),(0,1,2),MPI.DOUBLE],xlocal)

The receive buffer at process 2 is too small, it should have 9 entries
(but xlocal has 1 entry at all processes). The code below is the
correct one:

import numpy
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()

if rank == 0:
x = numpy.linspace(0,100,11)
else:
x = None

if rank == 2:
xlocal = numpy.zeros(9)
else:
xlocal = numpy.zeros(1)

comm.Scatterv([x,(1,1,9),(0,1,2),MPI.DOUBLE],xlocal)
print xlocal

$ mpiexec -n 3 parallel.py
[ 0.]
[ 10.]
[ 20. 30. 40. 50. 60. 70. 80. 90. 100.]


--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169

Jeremy Bejarano

unread,
May 4, 2012, 3:59:45 PM5/4/12
to mpi...@googlegroups.com
Thanks! Works great!

JoseLuis

unread,
Apr 17, 2014, 9:15:21 AM4/17/14
to mpi...@googlegroups.com
Hi, I am trying to use the Scatterv approach here described with a 2D matrix.
 
My code looks like:
 
$ mpiexec -n 4 parallel_2D.py
 
if rank == 0: 
    x = numpy.arange(121, dtype=numpy.float).reshape(11,11)
else:
    x = None
 
scatter_size = (1,2,3,5)   
scatter_pos = (0,1,3,6)
xlocal = numpy.zeros((11,scatter_size[rank]))
comm.Scatterv([x,scatter_size,scatter_pos,MPI.DOUBLE],xlocal)
print xlocal
 
For rank 2 xlocal is:
 
[[ 1. 2.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]
[ 0. 0.]]
 
How can I make that xlocal looks like xlocal = x[:,1:3] for rank = 2 ???
Reply all
Reply to author
Forward
0 new messages