6 merge requests!368Update prace.md to document the change from qprace to qprod as the default...,!367Update prace.md to document the change from qprace to qprod as the default...,!366Update prace.md to document the change from qprace to qprod as the default...,!323extended-acls-storage-section,!196Master,!161Gajdusek cleaning
In this example, we run MPI4Py enabled code on 4 nodes, 16 cores per node (total of 64 processes), each python process is bound to a different core. More examples and documentation can be found on [MPI for Python webpage](https://pypi.python.org/pypi/mpi4py).
In this example, we run MPI4Py enabled code on 4 nodes, 16 cores per node (total of 64 processes), each python process is bound to a different core. More examples and documentation can be found on [MPI for Python webpage](https://pypi.python.org/pypi/mpi4py).
###Adding numbers
Task: count sum of numbers from 1 to 1 000 000. (There is an easy formula to count the sum of arithmetic sequence, but we are showing the MPI solution with adding numbers one by one).
```python
#!/usr/bin/python
importnumpy
frommpi4pyimportMPI
importtime
comm=MPI.COMM_WORLD
rank=comm.Get_rank()
size=comm.Get_size()
a=1
b=1000000
perrank=b//size
summ=numpy.zeros(1)
comm.Barrier()
start_time=time.time()
temp=0
foriinrange(a+rank*perrank,a+(rank+1)*perrank):
temp=temp+i
summ[0]=temp
ifrank==0:
total=numpy.zeros(1)
else:
total=None
comm.Barrier()
comm.Reduce(summ,total,op=MPI.SUM,root=0)
stop_time=time.time()
ifrank==0:
#add the rest numbers to 1 000 000
foriinrange(a+(size)*perrank,b+1):
total[0]=total[0]+i
print ("The sum of numbers from 1 to 1 000 000: ",int(total[0]))
print ("time spent with ",size," threads in milliseconds")