References:
Reduce is a classic concept from functional programming. Data reduction involves reducing a set of numbers into a smaller set of numbers via a function. For example, let’s say we have a list of numbers { 1,2,3,4,5 }. Reducing this list of numbers with the sum function would produce sum({ 1,2,3,4,5 }) = 15. Similarly, the multiplication reduction would yield multiply({ 1,2,3,4,5 }) = 120.
Following the concept, this function allows the programmer to reduce data from multiple processes grouped by a communicator.
int MPI_Reduce(
const void *sendbuf, //Address of the data to be reduced
void *recvbuf, //Reduced result(s) receiver address
int count, //Quantity of elements from **each process**
MPI_Datatype datatype, //Type of data
MPI_Op op, //Operation to reduce data
int root, //Rank of the process that receives reduced data
MPI_Comm comm //Communicator
);
The count parameter determines how many elements will be reduced from each process (it is possible to reduce several data at once), the sending and receiving buffers must have a length equal to count, to work properly.
The receive buffer can be null for processes that will only send data.
MPI_Op is an enum for operations to be applied, you can see all of them here: https://learn.microsoft.com/en-us/message-passing-interface/mpi-op-enumeration. But what the most used operations do is listed below: