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:
MPIAssembly: MPI (in MPI.dll)
Version: 1.0.0.0 (1.0.0.0)
Syntax
| C# |
|---|
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++ |
|---|
public: generic<typename T> T Reduce( T value, ReductionOperation<T>^ op, int root ) |
Parameters
- value
- Type: T
The local value that will be combined with the values provided by other processes.
- op
- Type: MPI..::.ReductionOperation<(Of <(T>)>)
The operation used to combine two values. This operation must be associative.
- root
- 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
- T
- Any serializable type.
Return Value
On the root, returns the result of the reduction operation. The other processes receive a default value.
Examples
This example computes the sum of the ranks of all of the processes using
Reduce<(Of <(T>)>)(T, ReductionOperation<(Of <(T>)>), Int32).
CopyC#
using System; using MPI; class Reduce { static void Main(string[] args) { using (MPI.Environment env = new MPI.Environment(ref args)) { Intracommunicator world = Communicator.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); } else { world.Reduce(world.Rank, Operation<int>.Add, root); } } } };