from mpi4py import MPI
import numpy as np

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
data = np.array(rank, dtype='int')
result = np.zeros(1, dtype='int')
comm.Reduce([data, MPI.DOUBLE], [result, MPI.DOUBLE],
            op=MPI.SUM, root=0)
print("reduce", rank, result)
comm.Allreduce([data, MPI.DOUBLE], [result, MPI.DOUBLE],
            op=MPI.SUM)
print("allreduce", rank, result)

