How can I scatter an object array using MPI.NET

1k Views Asked by At

I'm trying to scatter a 2d boxed array. here is the summerized code:

using (new MPI.Environment(ref args))
{    
    Intracommunicator comm = Communicator.world;
    object[] boxedArrays = new object[] { };

    if (comm.Rank == 0)
    {
        [... //some initialization ]
        boxedArrays = new object[comm.size];
        for (int p = 0; p < comm.Size; p++)
        {
            [...  //some code to init the array]
            boxedArrays[p] = array;
        }
    }
object myChunk= comm.Scatter(boxedArrays, 0); 
var myArray = (int[,])myChunk;
}

When I print myArray it's empty.I tried the other variation of the scatter method but they also didn't work.

I'm using mpi.net sdk with Microsoft HPC Pack 2012.

1

There are 1 best solutions below

2
On

Scattering messages in MPI.NET

An array of integers is scattered to all ranks, from the rank 0:

class Program
{
    static void Main(string[] args)
    {
        using (MPI.Environment environment = new MPI.Environment(ref args))
        {
            Intracommunicator comm = Communicator.world;

            if (comm.Rank == 0)
            {
                int [] numbers = new int[comm.Size];

                for (int k = 0; k < numbers.Length; k++)
                    numbers[k] = k * k;

                int r = comm.Scatter(numbers);

                Console.WriteLine("Received {0} at {1}", r, comm.Rank);
            }
            else
            {
                int r = comm.Scatter<int>(0);
                Console.WriteLine("Received {0} at {1}", r, comm.Rank);
            }
        }
    }
}