示例#1
0
    public static void DoTest(string[] args)
    {
        using (new MPI.Environment(ref args))
        {
            Intracommunicator world = Communicator.world;

            world.Barrier();

            // Test addition of integers
            int partial_sum = world.Scan(world.Rank, addInts);
            int expected    = (world.Rank + 1) * world.Rank / 2;
            MPIDebug.Assert(partial_sum == expected);

            if (world.Rank == world.Size - 1)
            {
                System.Console.WriteLine("Sum of ranks = " + partial_sum);
            }

            // Test addition of integer points
            Point point_sum = world.Scan(new Point(world.Rank, 1), Point.Plus);
            MPIDebug.Assert(point_sum.x == partial_sum && point_sum.y == world.Rank + 1);

            if (world.Rank == world.Size - 1)
            {
                System.Console.WriteLine("Sum of points = (" + point_sum.x + ", " + point_sum.y + ")");
            }

            // Test addition of integer arrays
            if (world.Rank == world.Size - 1)
            {
                System.Console.Write("Testing scan of integer arrays...");
            }
            int[] arraySum = world.Scan(new int[] { world.Rank, 1 }, Operation <int> .Add);
            MPIDebug.Assert(arraySum[0] == partial_sum && arraySum[1] == world.Rank + 1);
            if (world.Rank == world.Size - 1)
            {
                System.Console.WriteLine(" done.");
            }

            // Test concatenation of strings
            if (world.Rank == world.Size - 1)
            {
                System.Console.Write("Testing scan of strings...");
            }
            string str         = world.Scan(world.Rank.ToString(), Operation <string> .Add);
            string expectedStr = "";
            for (int p = 0; p <= world.Rank; ++p)
            {
                expectedStr += p.ToString();
            }
            MPIDebug.Assert(expectedStr == str);

            if (world.Rank == world.Size - 1)
            {
                System.Console.WriteLine(" done.");
            }

            // Test concatenation of string arrays
            if (world.Rank == world.Size - 1)
            {
                System.Console.Write("Testing scan of string arrays...");
            }
            string[] strArray     = world.Scan(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add);
            string[] expectedStrs = new string[2] {
                "", ""
            };
            for (int p = 0; p <= world.Rank; ++p)
            {
                expectedStrs[0] += p.ToString();
                expectedStrs[1] += "World";
            }
            MPIDebug.Assert(expectedStrs[0] == strArray[0]);
            MPIDebug.Assert(expectedStrs[1] == strArray[1]);

            if (world.Rank == world.Size - 1)
            {
                System.Console.WriteLine(" done.");
            }
        }
    }