コード例 #1
0
ファイル: DatatypesTest.cs プロジェクト: jmhal/MPI.NET
    static void Main(string[] args)
    {
        int dataSize = 10000000;
        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (Communicator.world.Size != 2)
            {
                System.Console.WriteLine("The Datatypes test must be run with two processes.");
                System.Console.WriteLine("Try: mpiexec -np 2 datatypes.exe");
            }
            else if (Communicator.world.Rank == 0)
            {
                // Send an object that contains a "fixed" field
                Dimensions dims;
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                        dims.values[i] = (float)i;
                }
                Communicator.world.Send(dims, 1, 0);

                // Send an object that contains non-public fields
                Secretive secret = new Secretive(17, 25);
                Communicator.world.Send(secret, 1, 1);

                // Send an object with complex data
                AggregateData aggregate = new AggregateData(dataSize);
                Communicator.world.Send(aggregate, 1, 2);

                // Send an object with a private type
                Hidden hidden = new Hidden(17, 25);
                Communicator.world.Send(hidden, 1, 3);

                // Send a struct that requires serialization.
                ContainsBool containsBool = new ContainsBool(17);
                Communicator.world.Send(containsBool, 1, 4);
            }
            else
            {
                // Receive and check an object that contains a "fixed" field
                Dimensions dims;
                Communicator.world.Receive(0, 0, out dims);
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        System.Console.WriteLine(dims.values[i].ToString() + " ");
                        Debug.Assert(dims.values[i] == (float)i);
                    }
                }

                // Receive and check an object that contains non-public fields
                Secretive secret;
                Communicator.world.Receive(0, 1, out secret);
                System.Console.WriteLine(secret);
                Debug.Assert(secret == new Secretive(17, 25));

                // Receive and check the "complex data"
                AggregateData aggregate = Communicator.world.Receive<AggregateData>(0, 2);
                if (!aggregate.Check(dataSize))
                {
                    System.Console.Error.WriteLine("Error: complex data not properly transmitted");
                    MPI.Environment.Abort(1);
                }

                // Receive and check an object with a private type
                Hidden hidden;
                Communicator.world.Receive(0, 3, out hidden);
                System.Console.WriteLine(hidden);
                Debug.Assert(hidden == new Hidden(17, 25));

                // Receive and check a struct that requires serialization
                ContainsBool containsBool;
                Communicator.world.Receive(0, 4, out containsBool);
                System.Console.WriteLine(containsBool);
                Debug.Assert(containsBool == new ContainsBool(17));
            }

        }
    }
コード例 #2
0
    static void Main(string[] args)
    {
        int dataSize = 10000000;

        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (Communicator.world.Size != 2)
            {
                System.Console.WriteLine("The Datatypes test must be run with two processes.");
                System.Console.WriteLine("Try: mpiexec -np 2 datatypes.exe");
            }
            else if (Communicator.world.Rank == 0)
            {
                // Send an object that contains a "fixed" field
                Dimensions dims;
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        dims.values[i] = (float)i;
                    }
                }
                Communicator.world.Send(dims, 1, 0);

                // Send an object that contains non-public fields
                Secretive secret = new Secretive(17, 25);
                Communicator.world.Send(secret, 1, 1);

                // Send an object with complex data
                AggregateData aggregate = new AggregateData(dataSize);
                Communicator.world.Send(aggregate, 1, 2);

                // Send an object with a private type
                Hidden hidden = new Hidden(17, 25);
                Communicator.world.Send(hidden, 1, 3);

                // Send a struct that requires serialization.
                ContainsBool containsBool = new ContainsBool(17);
                Communicator.world.Send(containsBool, 1, 4);
            }
            else
            {
                // Receive and check an object that contains a "fixed" field
                Dimensions dims;
                Communicator.world.Receive(0, 0, out dims);
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        System.Console.WriteLine(dims.values[i].ToString() + " ");
                        Debug.Assert(dims.values[i] == (float)i);
                    }
                }

                // Receive and check an object that contains non-public fields
                Secretive secret;
                Communicator.world.Receive(0, 1, out secret);
                System.Console.WriteLine(secret);
                Debug.Assert(secret == new Secretive(17, 25));

                // Receive and check the "complex data"
                AggregateData aggregate = Communicator.world.Receive <AggregateData>(0, 2);
                if (!aggregate.Check(dataSize))
                {
                    System.Console.Error.WriteLine("Error: complex data not properly transmitted");
                    MPI.Environment.Abort(1);
                }

                // Receive and check an object with a private type
                Hidden hidden;
                Communicator.world.Receive(0, 3, out hidden);
                System.Console.WriteLine(hidden);
                Debug.Assert(hidden == new Hidden(17, 25));

                // Receive and check a struct that requires serialization
                ContainsBool containsBool;
                Communicator.world.Receive(0, 4, out containsBool);
                System.Console.WriteLine(containsBool);
                Debug.Assert(containsBool == new ContainsBool(17));
            }
        }
    }