[This is preliminary documentation and is subject to change.]

Gather the values from each process into an array of values at the root process. On the root process, outValues[p] will be equal to the value parameter of the process with rank p when this routine returns. Use this variant of the routine when you want to pre-allocate storage for the outValues array.

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


public void Gather<T>(
	T inValue,
	int root,
	ref T[] outValues
Visual Basic (Declaration)
Public Sub Gather(Of T) ( _
	inValue As T, _
	root As Integer, _
	ByRef outValues As T() _
Visual C++
generic<typename T>
void Gather(
	T inValue, 
	int root, 
	array<T>^% outValues


Type: T
The value contributed by this process.
Type: System..::.Int32
The rank of the process that will receive values for all of the processes in the communicator.
Type: array< T >[]()[] %
An array that will store the values contributed by each process. This value is only significant at the root, and can be omitted by non-root processes. Supply this argument when you have pre-allocated space for the resulting array.

Type Parameters

Any serializable type.


This example demonstrates the use of Gather to gather the ranks of all processes together at root 0.
using System;
using MPI;

class Gather
    static void Main(string[] args)
        using (MPI.Environment env = new MPI.Environment(ref args))
            Communicator world = Communicator.world;
            if (world.Rank == 0)
                int[] ranks = new int[world.Size];
                world.Gather(world.Rank, 0, ref ranks);
                System.Console.Write("Ranks of all of the processes:");
                for (int i = 0; i < ranks.Length; ++i)
                    System.Console.Write(" " + i);
                world.Gather(world.Rank, 0);

See Also