Skip to content

Commit

Permalink
Update mpi4py_ex.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WonyoungCho committed Jun 19, 2019
1 parent d3a9c80 commit cbfcce7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/mpi4py_ex.md
Expand Up @@ -177,3 +177,31 @@ rank = 3 after : [8]
rank = 2 after : [7]
rank = 0 gathered : [5 6 7 8]
```

# Reduce

```
from mpi4py import MPI
import numpy as np
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
ista = rank * size
iend = (rank + 1) * size
rsum = np.zeros(1)
for i in range(ista,iend):
rsum = rsum + i
print rank, 'sum =', rsum
tsum = np.zeros(1)
comm.Reduce(rsum, tsum, op=MPI.SUM, root=0)
if rank == 0:
print 'sum =', tsum
```

0 comments on commit cbfcce7

Please sign in to comment.