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__()