Pure Mpi.NET

This example illustrates how to send a string from all service hosts to the first host. 

Each host will send the string to the first host participating in the world communication handle.  This first host will receive all the strings and print them out.

    class Program

    {

        static void Main(string[] args)

        {

           using (ProcessorGroup processors =

                    new ProcessorGroup("MPIEnvironment",

                                       MpiProcess))

            {

                processors.Start();

                processors.WaitForCompletion();

            }

        }

 

        static void MpiProcess(IDictionary<string, Comm> comms)

        {

            Comm comm = comms["MPI_COMM_WORLD"];

            Console.WriteLine(comm.Rank);

            IAsyncResult result =

                comm.BeginSend<string>(0, "", "Rank: " + comm.Rank,

                             TimeSpan.FromSeconds(30), null, null);

            if (comm.Rank == 0)

            {

                for (int i = 0; i < comm.Size; i++)

                {

                    string receivedMsg =

                        comm.Receive<string>(i, Constants.AnyTag,

                                        TimeSpan.FromSeconds(30));

                    Console.WriteLine(receivedMsg);

                }

            }              

            comm.EndSend<string>(result);

        }

    }