running mpi4py with numpy

658 views
Skip to first unread message

ofenerci

unread,
Jul 27, 2010, 4:39:15 AM7/27/10
to mpi4py
Hello,

I am trying to learn mpi. I saw this code on the net and wanted to
try. I am using a 'lsf' job scheduler to submit this code.

Here is the "mpiJob.lsf" script:
-------------------------------------------------------->--------
#!/bin/bash
#BSUB -a intelmpi
#BSUB -q workshop.q
#BSUB -m anadolu_all
#BSUB -o %JmandelMPI.out
#BSUB -e %JmandelMPI.err
#BSUB -n 8
#BSUB -R "span[ptile=1]"

mpirun.lsf python ./mandelMPI.py
---------------------------------------------------------<-----------

When I run it :
$bsub < mpiJob.lsf

It goes well until the line 49 and get the error:

--------------------------------------------------->----------------
Traceback (most recent call last):
File "./mandelMPI.py", line 73, in ?
__main__()
File "./mandelMPI.py", line 49, in __main__
rows = [ MPI.rank + MPI.size*i for i in range(int(float(h)/
MPI.size)+1) if MPI.rank + MPI.size*i < h ]
AttributeError: 'module' object has no attribute 'size
-------------------------------------------------<-------------------

There is something wrong with MPI.rank an MPI.size. Could you help me
to run the program. I am posting the program below and you can also
look at the source code at "http://blog.mikael.johanssons.org/archive/
2008/05/parallell-and-cluster-mpi4py/"

Regards,
Ozhan


mandelMPI Source Code:
-------------------------------------------------------------------------------------------------
fom mpi4py import MPI
import Image
import numpy
import colorsys
from math import ceil

w = 600
h = 600
its = 80
d2 = 4.0

xmax = 1.5
xmin = -2.5
ymax = 2.0
ymin = -2.0

def step(z,c):
return z**2+c

def point(c,n,d2):
zo = 0.0
zn = zo
i = 0
while abs(zn)**2 < d2 and i<n:
zn = step(zo,c)
zo = zn
i = i+1
return i

def colnorm((r,g,b)):
return (int(256*r)-1,int(256*g)-1,int(256*b)-1)

def col(n,max):
if n == max:
return (0,0,0)
return colnorm(colorsys.hsv_to_rgb(1.0-float(n)/max,1.0,1.0))

def row(n,xmin,xmax,ymin,ymax):
row = []
for x in range(w):
p = complex((xmin+x*(xmax-xmin)/w),(ymin+n*(ymax-ymin)/
h))
row.append(point(p,its,d2))
return row

def __main__():
comm = MPI.COMM_WORLD

rows = [ MPI.rank + MPI.size*i for i in range(int(float(h)/
MPI.size)+1) if MPI.rank + MPI.size*i < h ]

pixels = []
for y in rows:
pixels.append(row(y,xmin,xmax,ymin,ymax))

mandel = comm.Gather(pixels)

if MPI.rank == 0:
img = Image.new("RGB",(w,h),(0,0,0))
rows = []

for i in range(len(mandel[0])):
for j in range(len(mandel)):
r = mandel[j][i]
rows.append([col(p,its) for p in r])

for x in range(w):
for y in range(h):
r = rows[y]
c = r[x]
img.putpixel((x,y),c)
img.save("/home/mik/public_html/mandel.png")

__main__()

Lisandro Dalcin

unread,
Jul 27, 2010, 10:27:55 AM7/27/10
to mpi...@googlegroups.com

That code seems to be written for an ancient version of mpi4py, before
the current Cython-based 1.x series.

You have to do thins like this:

comm = MPI.COMM_WORLD
rank = comm.rank
size = comm.size

Additionally, you'll have to replace the comm.Gather() call by the
lowercased version comm.gather(). The rationale for this is here:
http://code.google.com/p/mpi4py/source/browse/trunk/docs/source/usrman/tutorial.rst

BTW, you should also take a look at the Mandelbrot example here:
http://code.google.com/p/mpi4py/source/browse/trunk/demo/mandelbrot/mandelbrot.py

> --
> You received this message because you are subscribed to the Google Groups "mpi4py" group.
> To post to this group, send email to mpi...@googlegroups.com.
> To unsubscribe from this group, send email to mpi4py+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mpi4py?hl=en.
>
>

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

Reply all
Reply to author
Forward
0 new messages