Esempio n. 1
0
        public override byte[][] DivideProblem(int threadCount)
        {
            if (threadCount < 1)
                throw new ArgumentOutOfRangeException("threadCount");
            var partialProblemsNumbers = new List<int>[threadCount];
            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                partialProblemsNumbers[i] = new List<int>(_minMaxProblem.Numbers.Length/partialProblemsNumbers.Length);
            }
            for (var i = 0; i < _minMaxProblem.Numbers.Length; i++)
            {
                partialProblemsNumbers[i%partialProblemsNumbers.Length].Add(_minMaxProblem.Numbers[i]);
            }

            var partialProblemsData = new byte[partialProblemsNumbers.Length][];
            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                using (var memoryStream = new MemoryStream())
                {
                    var partialProblem = new MmPartialProblem(partialProblemsNumbers[i]);
                    _formatter.Serialize(memoryStream, partialProblem);
                    partialProblemsData[i] = memoryStream.ToArray();
                }
            }
            return partialProblemsData;
        }
Esempio n. 2
0
        public override byte[][] DivideProblem(int threadCount)
        {
            if (threadCount < 1)
            {
                throw new ArgumentOutOfRangeException("threadCount");
            }
            var partialProblemsNumbers = new List <int> [threadCount];

            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                partialProblemsNumbers[i] = new List <int>(_minMaxProblem.Numbers.Length / partialProblemsNumbers.Length);
            }
            for (var i = 0; i < _minMaxProblem.Numbers.Length; i++)
            {
                partialProblemsNumbers[i % partialProblemsNumbers.Length].Add(_minMaxProblem.Numbers[i]);
            }

            var partialProblemsData = new byte[partialProblemsNumbers.Length][];

            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                using (var memoryStream = new MemoryStream())
                {
                    var partialProblem = new MmPartialProblem(partialProblemsNumbers[i]);
                    _formatter.Serialize(memoryStream, partialProblem);
                    partialProblemsData[i] = memoryStream.ToArray();
                }
            }
            return(partialProblemsData);
        }