##// END OF EJS Templates
Fix in MPI psum example....
Brian Granger -
Show More
@@ -85,7 +85,7 b' Actually using MPI'
85 85 Once the engines are running with MPI enabled, you are ready to go. You can
86 86 now call any code that uses MPI in the IPython engines. And, all of this can
87 87 be done interactively. Here we show a simple example that uses mpi4py
88 [mpi4py]_.
88 [mpi4py]_ version 1.1.0 or later.
89 89
90 90 First, lets define a simply function that uses MPI to calculate the sum of a
91 91 distributed array. Save the following text in a file called :file:`psum.py`:
@@ -94,10 +94,14 b' distributed array. Save the following text in a file called :file:`psum.py`:'
94 94
95 95 from mpi4py import MPI
96 96 import numpy as np
97
97
98 98 def psum(a):
99 99 s = np.sum(a)
100 return MPI.COMM_WORLD.Allreduce(s,MPI.SUM)
100 rcvBuf = np.array(0.0,'d')
101 MPI.COMM_WORLD.Allreduce([s, MPI.DOUBLE],
102 [rcvBuf, MPI.DOUBLE],
103 op=MPI.SUM)
104 return rcvBuf
101 105
102 106 Now, start an IPython cluster in the same directory as :file:`psum.py`::
103 107
General Comments 0
You need to be logged in to leave comments. Login now