Ejemplo n.º 1
0
        public PipelinedBroadcastReduceDriver(
            [Parameter(typeof(GroupTestConfig.NumEvaluators))] int numEvaluators,
            [Parameter(typeof(GroupTestConfig.NumIterations))] int numIterations,
            [Parameter(typeof(GroupTestConfig.StartingPort))] int startingPort,
            [Parameter(typeof(GroupTestConfig.PortRange))] int portRange,
            [Parameter(typeof(GroupTestConfig.ChunkSize))] int chunkSize,
            [Parameter(typeof(GroupTestConfig.ArraySize))] int arraySize,
            GroupCommDriver groupCommDriver,
            IEvaluatorRequestor evaluatorRequestor)
        {
            Logger.Log(Level.Info, "entering the driver code " + chunkSize);

            _numEvaluators      = numEvaluators;
            _numIterations      = numIterations;
            _arraySize          = arraySize;
            _evaluatorRequestor = evaluatorRequestor;

            _tcpPortProviderConfig = TangFactory.GetTang().NewConfigurationBuilder()
                                     .BindNamedParameter <TcpPortRangeStart, int>(GenericType <TcpPortRangeStart> .Class,
                                                                                  startingPort.ToString(CultureInfo.InvariantCulture))
                                     .BindNamedParameter <TcpPortRangeCount, int>(GenericType <TcpPortRangeCount> .Class,
                                                                                  portRange.ToString(CultureInfo.InvariantCulture))
                                     .Build();

            _codecConfig = StreamingCodecConfiguration <int[]> .Conf
                           .Set(StreamingCodecConfiguration <int[]> .Codec, GenericType <IntArrayStreamingCodec> .Class)
                           .Build();

            var reduceFunctionConfig = ReduceFunctionConfiguration <int[]> .Conf
                                       .Set(ReduceFunctionConfiguration <int[]> .ReduceFunction, GenericType <ArraySumFunction> .Class)
                                       .Build();

            var dataConverterConfig = TangFactory.GetTang().NewConfigurationBuilder(
                PipelineDataConverterConfiguration <int[]> .Conf
                .Set(PipelineDataConverterConfiguration <int[]> .DataConverter,
                     GenericType <PipelineIntDataConverter> .Class)
                .Build())
                                      .BindNamedParameter <GroupTestConfig.ChunkSize, int>(
                GenericType <GroupTestConfig.ChunkSize> .Class,
                chunkSize.ToString(CultureInfo.InvariantCulture))
                                      .Build();

            _groupCommDriver = groupCommDriver;

            _commGroup = _groupCommDriver.DefaultGroup
                         .AddBroadcast <int[]>(
                GroupTestConstants.BroadcastOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                dataConverterConfig)
                         .AddReduce <int[]>(
                GroupTestConstants.ReduceOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                reduceFunctionConfig,
                dataConverterConfig)
                         .Build();

            _groupCommTaskStarter = new TaskStarter(_groupCommDriver, numEvaluators);
        }
        public void TestScatterOperator2()
        {
            string groupName    = "group1";
            string operatorName = "scatter";
            string masterTaskId = "task0";
            string driverId     = "Driver Id";
            int    numTasks     = 5;
            int    fanOut       = 2;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);

            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddScatter <int>(operatorName, masterTaskId, TopologyTypes.Tree, GetDefaultDataConverterConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IScatterSender <int>   sender    = commGroups[0].GetScatterSender <int>(operatorName);
            IScatterReceiver <int> receiver1 = commGroups[1].GetScatterReceiver <int>(operatorName);
            IScatterReceiver <int> receiver2 = commGroups[2].GetScatterReceiver <int>(operatorName);
            IScatterReceiver <int> receiver3 = commGroups[3].GetScatterReceiver <int>(operatorName);
            IScatterReceiver <int> receiver4 = commGroups[4].GetScatterReceiver <int>(operatorName);

            Assert.NotNull(sender);
            Assert.NotNull(receiver1);
            Assert.NotNull(receiver2);
            Assert.NotNull(receiver3);
            Assert.NotNull(receiver4);

            List <int> data = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            sender.Send(data);
            var data1 = receiver1.Receive().ToArray();

            Assert.Equal(1, data1[0]);
            Assert.Equal(2, data1[1]);
            Assert.Equal(3, data1[2]);
            Assert.Equal(4, data1[3]);

            var data2 = receiver2.Receive().ToArray();

            Assert.Equal(5, data2[0]);
            Assert.Equal(6, data2[1]);
            Assert.Equal(7, data2[2]);
            Assert.Equal(8, data2[3]);

            var data3 = receiver3.Receive();

            Assert.Equal(1, data3.First());
            Assert.Equal(2, data3.Last());

            var data4 = receiver4.Receive();

            Assert.Equal(3, data4.First());
            Assert.Equal(4, data4.Last());
        }
Ejemplo n.º 3
0
        public void TestBroadcastReduceOperators()
        {
            string groupName             = "group1";
            string broadcastOperatorName = "broadcast";
            string reduceOperatorName    = "reduce";
            string masterTaskId          = "task0";
            string driverId = "Driver Id";
            int    numTasks = 3;
            int    fanOut   = 2;

            var groupCommunicationDriver        = GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);
            ICommunicationGroupDriver commGroup = groupCommunicationDriver.DefaultGroup
                                                  .AddBroadcast <int>(
                broadcastOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                GetDefaultDataConverterConfig())
                                                  .AddReduce <int>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                GetDefaultDataConverterConfig(),
                GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = CommGroupClients(groupName, numTasks, groupCommunicationDriver, commGroup, GetDefaultCodecConfig());

            // for master task
            IBroadcastSender <int> broadcastSender = commGroups[0].GetBroadcastSender <int>(broadcastOperatorName);
            IReduceReceiver <int>  sumReducer      = commGroups[0].GetReduceReceiver <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver1    = commGroups[1].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender1 = commGroups[1].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver2    = commGroups[2].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender2 = commGroups[2].GetReduceSender <int>(reduceOperatorName);

            for (int j = 1; j <= 10; j++)
            {
                broadcastSender.Send(j);

                int n1 = broadcastReceiver1.Receive();
                int n2 = broadcastReceiver2.Receive();
                Assert.Equal(j, n1);
                Assert.Equal(j, n2);

                int triangleNum1 = TriangleNumber(n1);
                triangleNumberSender1.Send(triangleNum1);
                int triangleNum2 = TriangleNumber(n2);
                triangleNumberSender2.Send(triangleNum2);

                int sum      = sumReducer.Reduce();
                int expected = TriangleNumber(j) * (numTasks - 1);
                Assert.Equal(sum, expected);
            }
        }
Ejemplo n.º 4
0
        private KMeansDriverHandlers(
            [Parameter(typeof(NumPartitions))] int numPartitions,
            GroupCommDriver groupCommDriver,
            IEvaluatorRequestor evaluatorRequestor,
            CommandLineArguments arguments)
        {
            _executionDirectory = Path.Combine(Directory.GetCurrentDirectory(), Constants.KMeansExecutionBaseDirectory, Guid.NewGuid().ToString("N").Substring(0, 4));
            string dataFile = arguments.Arguments.First();

            DataVector.ShuffleDataAndGetInitialCentriods(
                dataFile,
                numPartitions,
                _clustersNumber,
                _executionDirectory);

            _totalEvaluators = numPartitions + 1;

            _groupCommDriver    = groupCommDriver;
            _evaluatorRequestor = evaluatorRequestor;

            _centroidCodecConf = CodecToStreamingCodecConfiguration <Centroids> .Conf
                                 .Set(CodecToStreamingCodecConfiguration <Centroids> .Codec, GenericType <CentroidsCodec> .Class)
                                 .Build();

            IConfiguration dataConverterConfig1 = PipelineDataConverterConfiguration <Centroids> .Conf
                                                  .Set(PipelineDataConverterConfiguration <Centroids> .DataConverter, GenericType <DefaultPipelineDataConverter <Centroids> > .Class)
                                                  .Build();

            _controlMessageCodecConf = CodecToStreamingCodecConfiguration <ControlMessage> .Conf
                                       .Set(CodecToStreamingCodecConfiguration <ControlMessage> .Codec, GenericType <ControlMessageCodec> .Class)
                                       .Build();

            IConfiguration dataConverterConfig2 = PipelineDataConverterConfiguration <ControlMessage> .Conf
                                                  .Set(PipelineDataConverterConfiguration <ControlMessage> .DataConverter, GenericType <DefaultPipelineDataConverter <ControlMessage> > .Class)
                                                  .Build();

            _processedResultsCodecConf = CodecToStreamingCodecConfiguration <ProcessedResults> .Conf
                                         .Set(CodecToStreamingCodecConfiguration <ProcessedResults> .Codec, GenericType <ProcessedResultsCodec> .Class)
                                         .Build();

            IConfiguration reduceFunctionConfig = ReduceFunctionConfiguration <ProcessedResults> .Conf
                                                  .Set(ReduceFunctionConfiguration <ProcessedResults> .ReduceFunction, GenericType <KMeansMasterTask.AggregateMeans> .Class)
                                                  .Build();

            IConfiguration dataConverterConfig3 = PipelineDataConverterConfiguration <ProcessedResults> .Conf
                                                  .Set(PipelineDataConverterConfiguration <ProcessedResults> .DataConverter, GenericType <DefaultPipelineDataConverter <ProcessedResults> > .Class)
                                                  .Build();

            _commGroup = _groupCommDriver.DefaultGroup
                         .AddBroadcast <Centroids>(Constants.CentroidsBroadcastOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, dataConverterConfig1)
                         .AddBroadcast <ControlMessage>(Constants.ControlMessageBroadcastOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, dataConverterConfig2)
                         .AddReduce <ProcessedResults>(Constants.MeansReduceOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, reduceFunctionConfig, dataConverterConfig3)
                         .Build();

            _groupCommTaskStarter = new TaskStarter(_groupCommDriver, _totalEvaluators);
        }
Ejemplo n.º 5
0
        public KMeansDriverHandlers([Parameter(typeof(NumPartitions))] int numPartitions, GroupCommDriver groupCommDriver)
        {
            Identifier          = "KMeansDriverId";
            _executionDirectory = Path.Combine(Directory.GetCurrentDirectory(), Constants.KMeansExecutionBaseDirectory, Guid.NewGuid().ToString("N").Substring(0, 4));
            ISet <string> arguments = ClrHandlerHelper.GetCommandLineArguments();
            string        dataFile  = arguments.Single(a => a.StartsWith("DataFile", StringComparison.Ordinal)).Split(':')[1];

            DataVector.ShuffleDataAndGetInitialCentriods(
                Path.Combine(Directory.GetCurrentDirectory(), "reef", "global", dataFile),
                numPartitions,
                _clustersNumber,
                _executionDirectory);

            _totalEvaluators = numPartitions + 1;

            _groupCommDriver = groupCommDriver;

            _centroidCodecConf = CodecToStreamingCodecConfiguration <Centroids> .Conf
                                 .Set(CodecConfiguration <Centroids> .Codec, GenericType <CentroidsCodec> .Class)
                                 .Build();

            IConfiguration dataConverterConfig1 = PipelineDataConverterConfiguration <Centroids> .Conf
                                                  .Set(PipelineDataConverterConfiguration <Centroids> .DataConverter, GenericType <DefaultPipelineDataConverter <Centroids> > .Class)
                                                  .Build();

            _controlMessageCodecConf = CodecToStreamingCodecConfiguration <ControlMessage> .Conf
                                       .Set(CodecConfiguration <ControlMessage> .Codec, GenericType <ControlMessageCodec> .Class)
                                       .Build();

            IConfiguration dataConverterConfig2 = PipelineDataConverterConfiguration <ControlMessage> .Conf
                                                  .Set(PipelineDataConverterConfiguration <ControlMessage> .DataConverter, GenericType <DefaultPipelineDataConverter <ControlMessage> > .Class)
                                                  .Build();

            _processedResultsCodecConf = CodecToStreamingCodecConfiguration <ProcessedResults> .Conf
                                         .Set(CodecConfiguration <ProcessedResults> .Codec, GenericType <ProcessedResultsCodec> .Class)
                                         .Build();

            IConfiguration reduceFunctionConfig = ReduceFunctionConfiguration <ProcessedResults> .Conf
                                                  .Set(ReduceFunctionConfiguration <ProcessedResults> .ReduceFunction, GenericType <KMeansMasterTask.AggregateMeans> .Class)
                                                  .Build();

            IConfiguration dataConverterConfig3 = PipelineDataConverterConfiguration <ProcessedResults> .Conf
                                                  .Set(PipelineDataConverterConfiguration <ProcessedResults> .DataConverter, GenericType <DefaultPipelineDataConverter <ProcessedResults> > .Class)
                                                  .Build();

            _commGroup = _groupCommDriver.DefaultGroup
                         .AddBroadcast <Centroids>(Constants.CentroidsBroadcastOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, dataConverterConfig1)
                         .AddBroadcast <ControlMessage>(Constants.ControlMessageBroadcastOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, dataConverterConfig2)
                         .AddReduce <ProcessedResults>(Constants.MeansReduceOperatorName, Constants.MasterTaskId, TopologyTypes.Flat, reduceFunctionConfig, dataConverterConfig3)
                         .Build();

            _groupCommTaskStarter = new TaskStarter(_groupCommDriver, _totalEvaluators);

            CreateClassHierarchy();
        }
        public void TestReduceOperator()
        {
            string groupName    = "group1";
            string operatorName = "reduce";
            int    numTasks     = 10;
            string driverId     = "driverId";
            string masterTaskId = "task0";
            int    fanOut       = 3;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);

            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddReduce <int>(operatorName, masterTaskId, TopologyTypes.Tree, GetDefaultDataConverterConfig(), GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IReduceReceiver <int> receiver = commGroups[0].GetReduceReceiver <int>(operatorName);
            IReduceSender <int>   sender1  = commGroups[1].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender2  = commGroups[2].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender3  = commGroups[3].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender4  = commGroups[4].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender5  = commGroups[5].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender6  = commGroups[6].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender7  = commGroups[7].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender8  = commGroups[8].GetReduceSender <int>(operatorName);
            IReduceSender <int>   sender9  = commGroups[9].GetReduceSender <int>(operatorName);

            Assert.NotNull(receiver);
            Assert.NotNull(sender1);
            Assert.NotNull(sender2);
            Assert.NotNull(sender3);
            Assert.NotNull(sender4);
            Assert.NotNull(sender5);
            Assert.NotNull(sender6);
            Assert.NotNull(sender7);
            Assert.NotNull(sender8);
            Assert.NotNull(sender9);

            sender9.Send(9);
            sender8.Send(8);
            sender7.Send(7);
            sender6.Send(6);
            sender5.Send(5);
            sender4.Send(4);
            sender3.Send(3);
            sender2.Send(2);
            sender1.Send(1);

            Assert.Equal(45, receiver.Reduce());
        }
        public BroadcastReduceDriver(
            [Parameter(typeof(GroupTestConfig.NumEvaluators))] int numEvaluators,
            [Parameter(typeof(GroupTestConfig.NumIterations))] int numIterations,
            [Parameter(typeof(GroupTestConfig.StartingPort))] int startingPort,
            [Parameter(typeof(GroupTestConfig.PortRange))] int portRange,
            GroupCommDriver groupCommDriver)
        {
            Identifier       = "BroadcastStartHandler";
            _numEvaluators   = numEvaluators;
            _numIterations   = numIterations;
            _groupCommDriver = groupCommDriver;

            _tcpPortProviderConfig = TangFactory.GetTang().NewConfigurationBuilder()
                                     .BindNamedParameter <TcpPortRangeStart, int>(GenericType <TcpPortRangeStart> .Class,
                                                                                  startingPort.ToString(CultureInfo.InvariantCulture))
                                     .BindNamedParameter <TcpPortRangeCount, int>(GenericType <TcpPortRangeCount> .Class,
                                                                                  portRange.ToString(CultureInfo.InvariantCulture))
                                     .Build();


            _codecConfig = StreamingCodecConfiguration <int> .Conf
                           .Set(StreamingCodecConfiguration <int> .Codec, GenericType <IntStreamingCodec> .Class)
                           .Build();

            IConfiguration reduceFunctionConfig = ReduceFunctionConfiguration <int> .Conf
                                                  .Set(ReduceFunctionConfiguration <int> .ReduceFunction, GenericType <SumFunction> .Class)
                                                  .Build();

            IConfiguration dataConverterConfig = PipelineDataConverterConfiguration <int> .Conf
                                                 .Set(PipelineDataConverterConfiguration <int> .DataConverter, GenericType <DefaultPipelineDataConverter <int> > .Class)
                                                 .Build();

            _commGroup = _groupCommDriver.DefaultGroup
                         .AddBroadcast <int>(
                GroupTestConstants.BroadcastOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                dataConverterConfig)
                         .AddReduce <int>(
                GroupTestConstants.ReduceOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                reduceFunctionConfig,
                dataConverterConfig)
                         .Build();

            _groupCommTaskStarter = new TaskStarter(_groupCommDriver, numEvaluators);

            CreateClassHierarchy();
        }
Ejemplo n.º 8
0
        public ScatterReduceDriver(
            [Parameter(typeof(GroupTestConfig.NumEvaluators))] int numEvaluators,
            GroupCommDriver groupCommDriver)
        {
            Identifier       = "BroadcastStartHandler";
            _numEvaluators   = numEvaluators;
            _groupCommDriver = groupCommDriver;

            _codecConfig = StreamingCodecConfiguration <int> .Conf
                           .Set(StreamingCodecConfiguration <int> .Codec, GenericType <IntStreamingCodec> .Class)
                           .Build();

            IConfiguration reduceFunctionConfig = ReduceFunctionConfiguration <int> .Conf
                                                  .Set(ReduceFunctionConfiguration <int> .ReduceFunction, GenericType <SumFunction> .Class)
                                                  .Build();

            IConfiguration dataConverterConfig = PipelineDataConverterConfiguration <int> .Conf
                                                 .Set(PipelineDataConverterConfiguration <int> .DataConverter, GenericType <DefaultPipelineDataConverter <int> > .Class)
                                                 .Build();

            _commGroup = _groupCommDriver.DefaultGroup
                         .AddScatter <int>(
                GroupTestConstants.ScatterOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                dataConverterConfig)
                         .AddReduce <int>(
                GroupTestConstants.ReduceOperatorName,
                GroupTestConstants.MasterTaskId,
                TopologyTypes.Tree,
                reduceFunctionConfig,
                dataConverterConfig)

                         .Build();

            _groupCommTaskStarter = new TaskStarter(_groupCommDriver, numEvaluators);

            CreateClassHierarchy();
        }
Ejemplo n.º 9
0
        public static List <ICommunicationGroupClient> CommGroupClients(string groupName, int numTasks, IGroupCommDriver groupCommDriver, ICommunicationGroupDriver commGroupDriver, IConfiguration userServiceConfig)
        {
            List <ICommunicationGroupClient> commGroups = new List <ICommunicationGroupClient>();
            IConfiguration serviceConfig = groupCommDriver.GetServiceConfiguration();

            serviceConfig = Configurations.Merge(serviceConfig, userServiceConfig);

            List <IConfiguration> partialConfigs = new List <IConfiguration>();

            for (int i = 0; i < numTasks; i++)
            {
                string         taskId            = "task" + i;
                IConfiguration partialTaskConfig = TangFactory.GetTang().NewConfigurationBuilder(
                    TaskConfiguration.ConfigurationModule
                    .Set(TaskConfiguration.Identifier, taskId)
                    .Set(TaskConfiguration.Task, GenericType <MyTask> .Class)
                    .Build())
                                                   .Build();
                commGroupDriver.AddTask(taskId);
                partialConfigs.Add(partialTaskConfig);
            }

            for (int i = 0; i < numTasks; i++)
            {
                // get task configuration at driver side
                string         taskId = "task" + i;
                IConfiguration groupCommTaskConfig = groupCommDriver.GetGroupCommTaskConfiguration(taskId);
                IConfiguration mergedConf          = Configurations.Merge(groupCommTaskConfig, partialConfigs[i], serviceConfig);

                var conf = TangFactory.GetTang()
                           .NewConfigurationBuilder(mergedConf)
                           .BindNamedParameter(typeof(GroupCommConfigurationOptions.Initialize), "false")
                           .Build();
                IInjector injector = TangFactory.GetTang().NewInjector(conf);

                // simulate injection at evaluator side
                IGroupCommClient groupCommClient = injector.GetInstance <IGroupCommClient>();
                commGroups.Add(groupCommClient.GetCommunicationGroup(groupName));
            }
            return(commGroups);
        }
Ejemplo n.º 10
0
        public void TestScatterReduceOperators()
        {
            string groupName           = "group1";
            string scatterOperatorName = "scatter";
            string reduceOperatorName  = "reduce";
            string masterTaskId        = "task0";
            string driverId            = "Driver Id";
            int    numTasks            = 5;
            int    fanOut = 2;

            IGroupCommDriver groupCommDriver = GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);

            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddScatter <int>(
                scatterOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                GetDefaultDataConverterConfig())
                                                  .AddReduce <int>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                GetDefaultReduceFuncConfig(),
                GetDefaultDataConverterConfig())
                                                  .Build();

            List <ICommunicationGroupClient> commGroups = CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IScatterSender <int>  sender     = commGroups[0].GetScatterSender <int>(scatterOperatorName);
            IReduceReceiver <int> sumReducer = commGroups[0].GetReduceReceiver <int>(reduceOperatorName);

            IScatterReceiver <int> receiver1  = commGroups[1].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender1 = commGroups[1].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver2  = commGroups[2].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender2 = commGroups[2].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver3  = commGroups[3].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender3 = commGroups[3].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver4  = commGroups[4].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender4 = commGroups[4].GetReduceSender <int>(reduceOperatorName);

            Assert.NotNull(sender);
            Assert.NotNull(receiver1);
            Assert.NotNull(receiver2);
            Assert.NotNull(receiver3);
            Assert.NotNull(receiver4);

            List <int>    data  = Enumerable.Range(1, 100).ToList();
            List <string> order = new List <string> {
                "task4", "task3", "task2", "task1"
            };

            sender.Send(data, order);

            ScatterReceiveReduce(receiver4, sumSender4);
            ScatterReceiveReduce(receiver3, sumSender3);
            ScatterReceiveReduce(receiver2, sumSender2);
            ScatterReceiveReduce(receiver1, sumSender1);

            int sum = sumReducer.Reduce();

            Assert.Equal(sum, data.Sum());
        }
Ejemplo n.º 11
0
        public void TestGetBroadcastReduceOperatorsForIntArrayMessageType()
        {
            const string groupName             = "group1";
            const string broadcastOperatorName = "broadcast";
            const string reduceOperatorName    = "reduce";
            const string masterTaskId          = "task0";
            const string driverId = "Driver Id";
            const int    numTasks = 3;
            const int    fanOut   = 2;

            IConfiguration codecConfig = StreamingCodecConfiguration <int[]> .Conf
                                         .Set(StreamingCodecConfiguration <int[]> .Codec, GenericType <IntArrayStreamingCodec> .Class)
                                         .Build();

            IConfiguration reduceFunctionConfig = ReduceFunctionConfiguration <int[]> .Conf
                                                  .Set(ReduceFunctionConfiguration <int[]> .ReduceFunction, GenericType <ArraySumFunction> .Class)
                                                  .Build();

            IConfiguration dataConverterConfig = TangFactory.GetTang().NewConfigurationBuilder(
                PipelineDataConverterConfiguration <int[]> .Conf
                .Set(PipelineDataConverterConfiguration <int[]> .DataConverter,
                     GenericType <PipelineIntDataConverter> .Class)
                .Build())
                                                 .BindNamedParameter <GroupTestConfig.ChunkSize, int>(
                GenericType <GroupTestConfig.ChunkSize> .Class,
                GroupTestConstants.ChunkSize.ToString(CultureInfo.InvariantCulture))
                                                 .Build();

            var groupCommunicationDriver        = GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);
            ICommunicationGroupDriver commGroup = groupCommunicationDriver.DefaultGroup
                                                  .AddBroadcast <int[]>(
                broadcastOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                dataConverterConfig)
                                                  .AddReduce <int[]>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Flat,
                dataConverterConfig,
                reduceFunctionConfig)
                                                  .Build();

            var commGroups = CommGroupClients(groupName, numTasks, groupCommunicationDriver, commGroup, codecConfig);

            // for master task
            IBroadcastSender <int[]> broadcastSender = commGroups[0].GetBroadcastSender <int[]>(broadcastOperatorName);
            IReduceReceiver <int[]>  sumReducer      = commGroups[0].GetReduceReceiver <int[]>(reduceOperatorName);

            IBroadcastReceiver <int[]> broadcastReceiver1    = commGroups[1].GetBroadcastReceiver <int[]>(broadcastOperatorName);
            IReduceSender <int[]>      triangleNumberSender1 = commGroups[1].GetReduceSender <int[]>(reduceOperatorName);

            IBroadcastReceiver <int[]> broadcastReceiver2    = commGroups[2].GetBroadcastReceiver <int[]>(broadcastOperatorName);
            IReduceSender <int[]>      triangleNumberSender2 = commGroups[2].GetReduceSender <int[]>(reduceOperatorName);

            Assert.NotNull(broadcastSender);
            Assert.NotNull(sumReducer);
            Assert.NotNull(broadcastReceiver1);
            Assert.NotNull(triangleNumberSender1);
            Assert.NotNull(broadcastReceiver2);
            Assert.NotNull(triangleNumberSender2);
        }
Ejemplo n.º 12
0
        private void AddGroupCommunicationOperators()
        {
            var reduceFunctionConfig = _configurationManager.ReduceFunctionConfiguration;
            var mapOutputPipelineDataConverterConfig = _configurationManager.MapOutputPipelineDataConverterConfiguration;
            var mapInputPipelineDataConverterConfig  = _configurationManager.MapInputPipelineDataConverterConfiguration;

            try
            {
                TangFactory.GetTang()
                .NewInjector(mapInputPipelineDataConverterConfig)
                .GetInstance <IPipelineDataConverter <TMapInput> >();

                mapInputPipelineDataConverterConfig =
                    TangFactory.GetTang()
                    .NewConfigurationBuilder(mapInputPipelineDataConverterConfig)
                    .BindImplementation(
                        GenericType <IPipelineDataConverter <MapInputWithControlMessage <TMapInput> > > .Class,
                        GenericType <MapInputwithControlMessagePipelineDataConverter <TMapInput> > .Class)
                    .Build();
            }
            catch (Exception)
            {
                mapInputPipelineDataConverterConfig = TangFactory.GetTang()
                                                      .NewConfigurationBuilder()
                                                      .BindImplementation(
                    GenericType <IPipelineDataConverter <MapInputWithControlMessage <TMapInput> > > .Class,
                    GenericType <DefaultPipelineDataConverter <MapInputWithControlMessage <TMapInput> > > .Class)
                                                      .Build();
            }

            try
            {
                TangFactory.GetTang()
                .NewInjector(mapOutputPipelineDataConverterConfig)
                .GetInstance <IPipelineDataConverter <TMapOutput> >();
            }
            catch (Exception)
            {
                mapOutputPipelineDataConverterConfig =
                    TangFactory.GetTang()
                    .NewConfigurationBuilder()
                    .BindImplementation(GenericType <IPipelineDataConverter <TMapOutput> > .Class,
                                        GenericType <DefaultPipelineDataConverter <TMapOutput> > .Class)
                    .Build();
            }

            _commGroup =
                _groupCommDriver.DefaultGroup
                .AddBroadcast <MapInputWithControlMessage <TMapInput> >(
                    IMRUConstants.BroadcastOperatorName,
                    IMRUConstants.UpdateTaskName,
                    TopologyTypes.Tree,
                    mapInputPipelineDataConverterConfig)
                .AddReduce <TMapOutput>(
                    IMRUConstants.ReduceOperatorName,
                    IMRUConstants.UpdateTaskName,
                    TopologyTypes.Tree,
                    reduceFunctionConfig,
                    mapOutputPipelineDataConverterConfig)
                .Build();
        }
        public void TestScatterReduceOperatorsWithCancelation()
        {
            string groupName           = "group1";
            string scatterOperatorName = "scatter";
            string reduceOperatorName  = "reduce";
            string masterTaskId        = "task0";
            string driverId            = "Driver Id";
            int    numTasks            = 5;
            int    fanOut = 2;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);
            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddScatter <int>(
                scatterOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig())
                                                  .AddReduce <int>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig(),
                GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IScatterSender <int>  sender     = commGroups[0].GetScatterSender <int>(scatterOperatorName);
            IReduceReceiver <int> sumReducer = commGroups[0].GetReduceReceiver <int>(reduceOperatorName);

            IScatterReceiver <int> receiver1  = commGroups[1].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender1 = commGroups[1].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver2  = commGroups[2].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender2 = commGroups[2].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver3  = commGroups[3].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender3 = commGroups[3].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver4  = commGroups[4].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender4 = commGroups[4].GetReduceSender <int>(reduceOperatorName);

            Assert.NotNull(sender);
            Assert.NotNull(receiver1);
            Assert.NotNull(receiver2);
            Assert.NotNull(receiver3);
            Assert.NotNull(receiver4);

            List <int> data = Enumerable.Range(1, 100).ToList();

            sender.Send(data);

            List <int> data1 = receiver1.Receive();
            List <int> data2 = receiver2.Receive();

            List <int> data3 = receiver3.Receive();
            List <int> data4 = receiver4.Receive();

            int sum3 = data3.Sum();

            sumSender3.Send(sum3);

            int sum4 = data4.Sum();

            sumSender4.Send(sum4);

            int sum2 = data2.Sum();

            sumSender2.Send(sum2);

            int sum1 = data1.Sum();

            var token = new CancellationTokenSource();

            token.Cancel();
            Action send = () => sumSender1.Send(sum1, token);

            Assert.Throws <OperationCanceledException>(send);

            var taskThread = new Thread(() =>
            {
                Action reduce = () => sumReducer.Reduce(token);
                Assert.Throws <OperationCanceledException>(reduce);
            });

            taskThread.Start();
            token.Cancel();
        }
        public void TestBroadcastReduceOperators()
        {
            string groupName             = "group1";
            string broadcastOperatorName = "broadcast";
            string reduceOperatorName    = "reduce";
            string masterTaskId          = "task0";
            string driverId = "Driver Id";
            int    numTasks = 10;
            int    fanOut   = 3;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);

            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddBroadcast <int>(
                broadcastOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig())
                                                  .AddReduce <int>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig(),
                GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            // for master task
            IBroadcastSender <int> broadcastSender = commGroups[0].GetBroadcastSender <int>(broadcastOperatorName);
            IReduceReceiver <int>  sumReducer      = commGroups[0].GetReduceReceiver <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver1    = commGroups[1].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender1 = commGroups[1].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver2    = commGroups[2].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender2 = commGroups[2].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver3    = commGroups[3].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender3 = commGroups[3].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver4    = commGroups[4].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender4 = commGroups[4].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver5    = commGroups[5].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender5 = commGroups[5].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver6    = commGroups[6].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender6 = commGroups[6].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver7    = commGroups[7].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender7 = commGroups[7].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver8    = commGroups[8].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender8 = commGroups[8].GetReduceSender <int>(reduceOperatorName);

            IBroadcastReceiver <int> broadcastReceiver9    = commGroups[9].GetBroadcastReceiver <int>(broadcastOperatorName);
            IReduceSender <int>      triangleNumberSender9 = commGroups[9].GetReduceSender <int>(reduceOperatorName);

            for (int i = 1; i <= 10; i++)
            {
                broadcastSender.Send(i);

                int n1 = broadcastReceiver1.Receive();
                int n2 = broadcastReceiver2.Receive();
                int n3 = broadcastReceiver3.Receive();
                int n4 = broadcastReceiver4.Receive();
                int n5 = broadcastReceiver5.Receive();
                int n6 = broadcastReceiver6.Receive();
                int n7 = broadcastReceiver7.Receive();
                int n8 = broadcastReceiver8.Receive();
                int n9 = broadcastReceiver9.Receive();
                Assert.Equal(i, n1);
                Assert.Equal(i, n2);
                Assert.Equal(i, n3);
                Assert.Equal(i, n4);
                Assert.Equal(i, n5);
                Assert.Equal(i, n6);
                Assert.Equal(i, n7);
                Assert.Equal(i, n8);
                Assert.Equal(i, n9);

                int triangleNum9 = GroupCommunicationTests.TriangleNumber(n9);
                triangleNumberSender9.Send(triangleNum9);

                int triangleNum8 = GroupCommunicationTests.TriangleNumber(n8);
                triangleNumberSender8.Send(triangleNum8);

                int triangleNum7 = GroupCommunicationTests.TriangleNumber(n7);
                triangleNumberSender7.Send(triangleNum7);

                int triangleNum6 = GroupCommunicationTests.TriangleNumber(n6);
                triangleNumberSender6.Send(triangleNum6);

                int triangleNum5 = GroupCommunicationTests.TriangleNumber(n5);
                triangleNumberSender5.Send(triangleNum5);

                int triangleNum4 = GroupCommunicationTests.TriangleNumber(n4);
                triangleNumberSender4.Send(triangleNum4);

                int triangleNum3 = GroupCommunicationTests.TriangleNumber(n3);
                triangleNumberSender3.Send(triangleNum3);

                int triangleNum2 = GroupCommunicationTests.TriangleNumber(n2);
                triangleNumberSender2.Send(triangleNum2);

                int triangleNum1 = GroupCommunicationTests.TriangleNumber(n1);
                triangleNumberSender1.Send(triangleNum1);

                int sum      = sumReducer.Reduce();
                int expected = GroupCommunicationTests.TriangleNumber(i) * (numTasks - 1);
                Assert.Equal(sum, expected);
            }
        }
        public void TestBroadcastOperator()
        {
            string groupName    = "group1";
            string operatorName = "broadcast";
            string driverId     = "driverId";
            string masterTaskId = "task0";
            int    numTasks     = 10;
            int    value1       = 1337;
            int    value2       = 42;
            int    value3       = 99;
            int    fanOut       = 3;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);

            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddBroadcast <int>(operatorName, masterTaskId, TopologyTypes.Tree, GetDefaultDataConverterConfig(), GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IBroadcastSender <int>   sender    = commGroups[0].GetBroadcastSender <int>(operatorName);
            IBroadcastReceiver <int> receiver1 = commGroups[1].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver2 = commGroups[2].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver3 = commGroups[3].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver4 = commGroups[4].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver5 = commGroups[5].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver6 = commGroups[6].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver7 = commGroups[7].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver8 = commGroups[8].GetBroadcastReceiver <int>(operatorName);
            IBroadcastReceiver <int> receiver9 = commGroups[9].GetBroadcastReceiver <int>(operatorName);

            Assert.NotNull(sender);
            Assert.NotNull(receiver1);
            Assert.NotNull(receiver2);
            Assert.NotNull(receiver3);
            Assert.NotNull(receiver4);
            Assert.NotNull(receiver5);
            Assert.NotNull(receiver6);
            Assert.NotNull(receiver7);
            Assert.NotNull(receiver8);
            Assert.NotNull(receiver9);

            sender.Send(value1);
            Assert.Equal(value1, receiver1.Receive());
            Assert.Equal(value1, receiver2.Receive());
            Assert.Equal(value1, receiver3.Receive());
            Assert.Equal(value1, receiver4.Receive());
            Assert.Equal(value1, receiver5.Receive());
            Assert.Equal(value1, receiver6.Receive());
            Assert.Equal(value1, receiver7.Receive());
            Assert.Equal(value1, receiver8.Receive());
            Assert.Equal(value1, receiver9.Receive());

            sender.Send(value2);
            Assert.Equal(value2, receiver1.Receive());
            Assert.Equal(value2, receiver2.Receive());
            Assert.Equal(value2, receiver3.Receive());
            Assert.Equal(value2, receiver4.Receive());
            Assert.Equal(value2, receiver5.Receive());
            Assert.Equal(value2, receiver6.Receive());
            Assert.Equal(value2, receiver7.Receive());
            Assert.Equal(value2, receiver8.Receive());
            Assert.Equal(value2, receiver9.Receive());

            sender.Send(value3);
            Assert.Equal(value3, receiver1.Receive());
            Assert.Equal(value3, receiver2.Receive());
            Assert.Equal(value3, receiver3.Receive());
            Assert.Equal(value3, receiver4.Receive());
            Assert.Equal(value3, receiver5.Receive());
            Assert.Equal(value3, receiver6.Receive());
            Assert.Equal(value3, receiver7.Receive());
            Assert.Equal(value3, receiver8.Receive());
            Assert.Equal(value3, receiver9.Receive());
        }
        public void TestScatterReduceOperators()
        {
            string groupName           = "group1";
            string scatterOperatorName = "scatter";
            string reduceOperatorName  = "reduce";
            string masterTaskId        = "task0";
            string driverId            = "Driver Id";
            int    numTasks            = 5;
            int    fanOut = 2;

            var groupCommDriver = GroupCommunicationTests.GetInstanceOfGroupCommDriver(driverId, masterTaskId, groupName, fanOut, numTasks);
            ICommunicationGroupDriver commGroup = groupCommDriver.DefaultGroup
                                                  .AddScatter <int>(
                scatterOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig())
                                                  .AddReduce <int>(
                reduceOperatorName,
                masterTaskId,
                TopologyTypes.Tree,
                GetDefaultDataConverterConfig(),
                GetDefaultReduceFuncConfig())
                                                  .Build();

            var commGroups = GroupCommunicationTests.CommGroupClients(groupName, numTasks, groupCommDriver, commGroup, GetDefaultCodecConfig());

            IScatterSender <int>  sender     = commGroups[0].GetScatterSender <int>(scatterOperatorName);
            IReduceReceiver <int> sumReducer = commGroups[0].GetReduceReceiver <int>(reduceOperatorName);

            IScatterReceiver <int> receiver1  = commGroups[1].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender1 = commGroups[1].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver2  = commGroups[2].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender2 = commGroups[2].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver3  = commGroups[3].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender3 = commGroups[3].GetReduceSender <int>(reduceOperatorName);

            IScatterReceiver <int> receiver4  = commGroups[4].GetScatterReceiver <int>(scatterOperatorName);
            IReduceSender <int>    sumSender4 = commGroups[4].GetReduceSender <int>(reduceOperatorName);

            Assert.IsNotNull(sender);
            Assert.IsNotNull(receiver1);
            Assert.IsNotNull(receiver2);
            Assert.IsNotNull(receiver3);
            Assert.IsNotNull(receiver4);

            List <int> data = Enumerable.Range(1, 100).ToList();

            sender.Send(data);

            List <int> data1 = receiver1.Receive();
            List <int> data2 = receiver2.Receive();

            List <int> data3 = receiver3.Receive();
            List <int> data4 = receiver4.Receive();

            int sum3 = data3.Sum();

            sumSender3.Send(sum3);

            int sum4 = data4.Sum();

            sumSender4.Send(sum4);

            int sum2 = data2.Sum();

            sumSender2.Send(sum2);

            int sum1 = data1.Sum();

            sumSender1.Send(sum1);

            int sum = sumReducer.Reduce();

            Assert.AreEqual(sum, 6325);
        }