MPI4py

  1. 分布式环境下,内存不可能共享,因此不可能在所有 rank/进程之间设置一个共享变量

  2. mpi4py 应用在联邦学习的代码 mpi-federated-learning-simulation

  3. comm.recv() 中的 status 参数可以获取接收到的消息的相关信息,比如消息来源 使用方法参考: python - mpi4py Send/Recv with tag - Stack Overflow

  4. 阻塞通信与非阻塞通信:

    1. 阻塞通信: Python objects with blocking communication: comm.send comm.recv Numpy objects with non-blocking communication: comm.Send comm.Recv

    2. 非阻塞通信: Python objects with non-blocking communication: comm.isend comm.irecv Numpy objects with non-blocking communication: comm.Isend comm.Irecv 注意: irecv 可以没有缓冲区接收,通过 data=req.wait() 来返回数据 但是 Irecv 必须有缓冲区

      (method) def irecv( buf: Buffer | None = None, source: int = ANY_SOURCE, tag: int = ANY_TAG ) -> Request

      (method) def Irecv( buf: BufSpec, source: int = ANY_SOURCE, tag: int = ANY_TAG ) -> Request

  5. 注意统一发送和接收的数据的格式,一定要确认格式一致,一旦出现发送的 dtype 和接收的 dtype 不一致的情况,最终结果、准确率就会受到影响。

  6. 参考资料

    MPI4py crash course

参考资料

MPI for Python c++ - Defining global variables in mpi - Stack Overflow