示例#1
0
 // Return Value and Index corresponding to minimum over all MPI Processes
 //  Replace Input values by minimum values
 public static void AllReduceMinWithIndex(ref double ProcessValue, ref int ProcessIndex)
 {
     if (MPI_Size > 1)
     {
         var LocalStructure = new MPIReducePlusIndex(ProcessIndex, ProcessValue);
         MPIReducePlusIndex TotalStructure = MPI_communicator.Allreduce(LocalStructure, MinwithIndex);
         ProcessValue = TotalStructure.value;
         ProcessIndex = TotalStructure.index;
     }
 }
 public double readTimerGlobal(int n)
 {
     Intracommunicator comm_setup = Mpi.localComm(this);
     double tmax = comm_setup.Allreduce<double>(this.readTimer(n), Operation<double>.Max);
     return tmax;
 }
示例#3
0
    static void Main(string[] args)
    {
        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            Intracommunicator world = Communicator.world;

            // Test addition of integers
            int sum      = world.Allreduce(world.Rank, addInts);
            int expected = world.Size * (world.Size - 1) / 2;
            Debug.Assert(sum == expected);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Sum of ranks = " + sum);
            }

            // Test addition of integers through the Operations class
            Debug.Assert(world.Allreduce(world.Rank, Operation <int> .Add) == expected);

            // Test addition of integer points
            Point pointSum = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Point.Plus);
            Debug.Assert(pointSum.x == sum && pointSum.y == (world.Size + 1) * world.Size / 2);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Sum of points = (" + pointSum.x + ", " + pointSum.y + ")");
            }

            // Compute the minimum rank
            int minRank = world.Allreduce(world.Rank, Operation <int> .Min);
            Debug.Assert(minRank == 0);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Minimum of ranks = " + minRank);
            }

            // Compute the minimum point
            Point minPoint = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Min);
            Debug.Assert(minPoint.x == 0 && minPoint.y == world.Size);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Minimum point = (" + minPoint.x + ", " + minPoint.y + ")");
            }

            // Compute the maximum rank
            int maxRank = world.Allreduce(world.Rank, Operation <int> .Max);
            Debug.Assert(maxRank == world.Size - 1);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Maximum of ranks = " + maxRank);
            }

            // Compute the maximum point
            Point maxPoint = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Max);
            Debug.Assert(maxPoint.x == world.Size - 1 && maxPoint.y == 1);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Maximum point = (" + maxPoint.x + ", " + maxPoint.y + ")");
            }

            // Test addition of integer points via the Operations class
            Point pointSum2 = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Add);
            Debug.Assert(pointSum2.x == sum && pointSum2.y == (world.Size + 1) * world.Size / 2);

            // Test concatenation of strings
            string strcat      = world.Allreduce(world.Rank.ToString(), concat);
            string expectedStr = "";
            for (int i = 0; i < world.Size; ++i)
            {
                expectedStr += i;
            }
            Debug.Assert(expectedStr == strcat);
            if (world.Rank == 0)
            {
                System.Console.WriteLine("Concatenation of rank strings = " + strcat);
            }

            Debug.Assert(world.Allreduce(world.Rank.ToString(), Operation <string> .Add) == expectedStr);

            // Test addition of integer arrays
            if (world.Rank == 0)
            {
                System.Console.Write("Testing reduction of integer arrays...");
            }
            int[] arraySum = null;
            world.Allreduce(new int[] { world.Rank, world.Size - world.Rank }, Operation <int> .Add, ref arraySum);
            Debug.Assert(arraySum[0] == sum && arraySum[1] == (world.Size + 1) * world.Size / 2);
            if (world.Rank == 0)
            {
                System.Console.WriteLine(" done.");
            }

            // Test concatenation of string arrays
            if (world.Rank == 0)
            {
                System.Console.Write("Testing reduction of string arrays...");
            }
            string[] strArray = null;
            world.Allreduce(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add, ref strArray);

            string[] expectedStrs = new string[2] {
                "", ""
            };
            for (int p = 0; p < world.Size; ++p)
            {
                expectedStrs[0] += p.ToString();
                expectedStrs[1] += "World";
            }
            Debug.Assert(expectedStrs[0] == strArray[0]);
            Debug.Assert(expectedStrs[1] == strArray[1]);

            if (world.Rank == 0)
            {
                System.Console.WriteLine(" done.");
            }
        }
    }
示例#4
0
        public void go_parallel()
        {
            breaking();

            string input = readInput(TEMP_FILE_PATH + Rank);            //(PATH);

            bool sair = false;

            while (!sair)
            {
                splitMap(input);
                input  = "";
                saidas = new Dictionary <int, string> ();
                sair   = true;
                IEnumerator <string> I = KVPair_OMK_OMV.getIteratorKeys();
                while (I.MoveNext())
                {
                    string key = I.Current;
                    reduce(key, KVPair_OMK_OMV.getList(key));
                    string[] words = valorORV.Split(' ');

                    int task_id = Math.Abs((words[0]).GetHashCode()) % Size;
                    if (task_id == Rank)
                    {
                        input = input + valorORV;
                    }
                    else
                    {
                        if (!saidas.ContainsKey(task_id))
                        {
                            saidas [task_id] = "";
                        }
                        saidas [task_id] = saidas [task_id] + valorORV;
                    }
                    if (sair && chaveORV.Equals("0"))
                    {
                        sair = false;
                    }
                }
                for (int i = 0; i < Size; i++)
                {
                    if (i != Rank)
                    {
                        if (!saidas.ContainsKey(i))
                        {
                            saidas [i] = "";
                        }
                        rlist.Add(worldcomm.ImmediateSend <string> (saidas [i], i, 0));
                    }
                }
                for (int i = 0; i < Size; i++)
                {
                    if (i != Rank)
                    {
                        input = input + worldcomm.Receive <string> (i, 0);
                    }
                }
                rlist.WaitAll();
                int exit = worldcomm.Allreduce <int> (sair ? 1 : 0, MPI.Operation <int> .Min);
                sair = exit == 1;
            }
            Randomize.clearFile(OUTPUT_FILE_PATH + Rank);
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@OUTPUT_FILE_PATH + Rank, true)){
                file.WriteLine(input);
            }
        }
示例#5
0
 private static void simpleAllreduce()
 {
     comm.Allreduce(comm.Rank, Operation <int> .Add);
 }