code: def chunked_bcast_obj(
      obj, mpi_comm, max_buf_len=256 * 1024 * 1024, root=0
  ):
      """Split object to max_buf_len size chunks and send them out
  
      As mpi4py does not accept an object whose pickled size is larger
      than signed integer max (2147483647) the object is pickled and
      split into chunks.
  
      Another hack could be try with mpi_comm.bcast(obj) then rank 0
      node will receive OverflowError from mpi4py. But in that case rank
      > 0 nodes shall block busy waiting forever at mpi_comm.bcast(obj).
  
      Args:
          obj: A Python object that is to be broadcasted.
          comm: ChainerMN communicator or MPI4py communicator.
          root (int): The root process of the scatter operation.
          max_buf_len (int): Max buffer size to be used at broadcasting
              binaries. Must not be larger than 2147483647 (INT_MAX).
              Default value is 256MB.
      Returns:
          Broadcasted object.
  
      """
      assert max_buf_len < INT_MAX
      assert max_buf_len > 0
  
      # check XOR condition of obj is None and rank==0
      # rank \ obj | None | not None |
      #   == 0     |  NG  |   OK     |
      #    > 0     |  OK  |   NG     |
      assert not (obj is None and mpi_comm.rank == root)
      assert not (obj is not None and mpi_comm.rank != root)
  
      if obj is not None and mpi_comm.rank == root:
          pickled_bytes = pickle.dumps(
              obj, protocol=pickle.HIGHEST_PROTOCOL
          )
      else:
          pickled_bytes = bytearray()
  
      total_bytes = len(pickled_bytes)
      total_chunk_num = total_bytes // max_buf_len
      if (total_bytes % max_buf_len) > 0:
          total_chunk_num += 1
  
      data = mpi_comm.bcast(
          (total_chunk_num, max_buf_len, total_bytes), root=root
      )
      assert data is not None
      (total_chunk_num, max_buf_len, total_bytes) = data
  
      for i in range(total_chunk_num):
          b = i * max_buf_len
          e = min(b + max_buf_len, total_bytes)
  
          if mpi_comm.rank == root:
              buf = pickled_bytes[b:e]
          else:
              buf = bytearray(e - b)
  
          mpi_comm.Bcast(buf, root=root)
  
          if mpi_comm.rank != root:
              pickled_bytes[b:e] = buf
  
      if mpi_comm.rank != root:
          obj = pickle.loads(pickled_bytes)
  
      return obj
  
file_path: chainer/chainermn/communicators/_communication_utility.py
imports: from chainermn import nccl
  import collections
  import numpy
  import pickle
  import mpi4py.MPI
label_desc: Use image node_id 6 for calling a global function with example usage: chunked_bcast_obj(obj, mpi_comm, max_buf_len, root) and returns: obj