O'Reilly logo

Python Parallel Programming Cookbook by Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The reduction operation

Similar to comm.gather, comm.reduce takes an array of input elements in each process and returns an array of output elements to the root process. The output elements contain the reduced result.

In mpi4py, we define the reduction operation through the following statement:

comm.Reduce(sendbuf, recvbuf, rank_of_root_process, op = type_of_reduction_operation)

We must note that the difference with the comm.gather statement resides in the op parameter, which is the operation that you wish to apply to your data, and the mpi4py module contains a set of reduction operations that can be used. Some of the reduction operations defined by MPI are:

  • MPI.MAX: This returns the maximum element
  • MPI.MIN: This returns the minimum element
  • MPI.SUM ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required