Skip to content

Instantly share code, notes, and snippets.

@iwiwi
Created August 14, 2017 05:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwiwi/f51e86ced0552fff737f0c9bf94a6f58 to your computer and use it in GitHub Desktop.
Save iwiwi/f51e86ced0552fff737f0c9bf94a6f58 to your computer and use it in GitHub Desktop.
All-to-all collective communication for numpy & cupy arrays with ChainerMN (demo)
import chainermn
from chainermn.communicators._memory_utility import array_to_buffer_object
import mpi4py.MPI
comm = chainermn.create_communicator('naive')
def alltoall_demo(xp):
mpi_comm = comm.mpi_comm
n = comm.size
a = xp.arange(n * 3).reshape((n, -1)).astype(xp.float32)
print('BEFORE', comm.rank, ':', a.ravel())
mpi_comm.Alltoall(mpi4py.MPI.IN_PLACE, array_to_buffer_object(a))
print('AFTER', comm.rank, ':', a.ravel())
import cupy as cp
import numpy as np
alltoall_demo(np)
alltoall_demo(cp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment