Reduce is a collective algorithm that combines the values stored by each process into a single value available at the designated root process. The values are combined in a user-defined way, specified via a delegate. If value1, value2, ..., valueN are the values provided by the N processes in the communicator, the result will be the value value1 op value2 op ... op valueN. This result is only available to the root process. If all processes need the result of the reduction, use Allreduce<(Of <(T>)>)(T, ReductionOperation<(Of <(T>)>)).

Namespace:  MPI
Assembly:  MPI (in MPI.dll)
Version: (


public T Reduce<T>(
	T value,
	ReductionOperation<T> op,
	int root
Visual Basic (Declaration)
Public Function Reduce(Of T) ( _
	value As T, _
	op As ReductionOperation(Of T), _
	root As Integer _
) As T
Visual C++
generic<typename T>
T Reduce(
	T value, 
	ReductionOperation<T>^ op, 
	int root


Type: T
The local value that will be combined with the values provided by other processes.
Type: MPI..::.ReductionOperation<(Of <(T>)>)
The operation used to combine two values. This operation must be associative.
Type: System..::.Int32
The rank of the process that is the root of the reduction operation, which will receive the result of the reduction operation in its outValue argument.

Type Parameters

Any serializable type.

Return Value

On the root, returns the result of the reduction operation. The other processes receive a default value.


This example computes the sum of the ranks of all of the processes using Reduce<(Of <(T>)>)(T, ReductionOperation<(Of <(T>)>), Int32).
using System;
using MPI;

class Reduce
  static void Main(string[] args)
    using (MPI.Environment env = new MPI.Environment(ref args))
      Intracommunicator world =;

      int root = 0;
      if (world.Rank == root)
        int sum;
        world.Reduce(world.Rank, out sum, Operation<int>.Add, root);
        System.Console.WriteLine("Sum of ranks = " + sum);
        world.Reduce(world.Rank, Operation<int>.Add, root);

See Also