예제 #1
0
        /// <summary>
        /// This method returns the calculated amount of subbatches which is assumed to be the opimum.
        /// To determine all possible subbatches, the batchsize must be factorized into its primes.
        /// </summary>
        /// <param name="keyTranslator"></param>
        /// <returns></returns>
        public int GetAmountOfSubbatches(IKeyTranslator keyTranslator)
        {
            if (this.keyTranslator != keyTranslator)
            {
                //init code:
                this.keyTranslator = keyTranslator;

                //Find factors of OpenCL batch size:
                List <Msieve.Factor> factors = Msieve.TrivialFactorization(keyTranslator.GetOpenCLBatchSize());
                amountOfSubbatchesFactors = new List <int>();
                foreach (var fac in factors)
                {
                    for (int i = 0; i < fac.count; i++)
                    {
                        amountOfSubbatchesFactors.Add((int)fac.factor);
                    }
                }
                amountOfSubbatches = keyTranslator.GetOpenCLBatchSize();

                batchSizeFactors = new List <int>();
                DecreaseAmountOfSubbatches();

                lastDuration       = TimeSpan.MaxValue;
                optimisticDecrease = false;
                lastStepIncrease   = false;

                if (openCLMode == 1)    //normal load
                {
                    DecreaseAmountOfSubbatches();
                }
            }

            return(amountOfSubbatches);
        }
예제 #2
0
        private void DecreaseAmountOfSubbatches()
        {
            if (amountOfSubbatchesFactors.Count < 1)
            {
                return;
            }

            if (keyTranslator.GetOpenCLBatchSize() / amountOfSubbatches >= maxNumberOfThreads)   //not more than MAXNUMBEROFTHREADS threads concurrently
            {
                return;
            }

            do
            {
                int maxElement = amountOfSubbatchesFactors.Max();
                batchSizeFactors.Add(maxElement);
                amountOfSubbatchesFactors.Remove(maxElement);

                amountOfSubbatches = amountOfSubbatchesFactors.Aggregate(1, (current, i) => current * i);
            } while (keyTranslator.GetOpenCLBatchSize() / amountOfSubbatches < (256 * 256));        //each batch should have at least size 256*256
        }