On 5 March 2015 at 04:44, Oliver <
pyth...@gmail.com> wrote:
> hi -
>
> I am new to mpi4py, and trying out a simple reduce example:
>
> #!/usr/bin/env python
> from mpi4py import MPI
> comm = MPI.COMM_WORLD
> x = comm.rank
> y = 0
> comm.reduce(x, y, MPI.SUM)
> print "rank %s, x= %s, y=%s" % (comm.rank, x, y
>
>
> I was expecting x is being sent, y is being sumed, and the result should be
> 0+1+2+3, am I missing something?
>
y = comm.reduce(x, op=MPI.SUM)
I had to make it work this way simply because some Python types (int,
float, tuple, etc.) are immutable, so you cannot just pass y as an
argument and get the reduction by modifying "y" internally.
Otherwise, you have to use NumPy arrays
x = np.asarray(x)
y = np.asarray(y)
comm.Reduce(x, y, op=MPI.SUM) # note uppercase "Reduce"
--
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Numerical Porous Media Center (NumPor)
King Abdullah University of Science and Technology (KAUST)
http://numpor.kaust.edu.sa/
4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 4332
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa
Office Phone:
+966 12 808-0459