Exemplo n.º 1
0
        // const int DataSize = 4096;

        static void Main([NotNull][ItemNotNull] string[] args)
        {
            if (args.Length != 2)
            {
                PrintUsage();
                return;
            }

            string source      = args[0];
            string destination = args[1];

            if (!File.Exists(source))
            {
                Console.WriteLine("Source file does not exist");
                return;
            }

            var          initialLogger = new PrefixLogger("[Initial] ");
            var          infoLogger    = new PrefixLogger("[Sorter] ");
            IDataManager manager       = new FileDataManager(source, destination);

            string[] environmentArgs = new string[0];
            using (new Environment(ref environmentArgs))
            {
                var world = Communicator.world;
                initialLogger.Assert(world != null, "Could not retrieve world");
                int processors = world.Size;
                initialLogger.Assert(processors.IsPowerOfTwo(), "Number of processors should be power of two");
                int[] batch         = GetDataBatch(world, initialLogger, manager, processors);
                var   sorter        = new Sorter(batch, world, infoLogger);
                int   numberOfSteps = world.Size.IntegralBinaryLogarithm();

                for (int step = numberOfSteps - 1; step >= 0; step -= 1)
                {
                    sorter.Exchange(step);
                }

                var gathered = world.Gather(sorter.Sort(), 0);
                if (gathered != null)
                {
                    manager.SinkResult(gathered);
                }
            }
        }