Пример #1
0
        //Generates the modulus using more thread
        private static BigInteger ParGenMod(GeneratorWrap gen, uint wordSize, int threads, uint precision)
        {
            IPrime mainGenerator, workerGenerator;

            //threads distribution for primes creation
            if (threads < 4)
            {
                mainGenerator   = new SequentialPrime(gen.GetInt(), precision, wordSize);
                workerGenerator = new SequentialPrime(gen.GetInt(), precision, wordSize);
            }
            else
            {
                mainGenerator   = new ParallelPrime(gen.GetInt(), precision, wordSize, threads - threads / 2);
                workerGenerator = new ParallelPrime(gen.GetInt(), precision, wordSize, threads / 2);
            }

            //primes creation
            var firstPrime  = gen.GetBig();
            var secondPrime = gen.GetBig();

            while (!SecurityCheck(firstPrime, secondPrime))
            {
                secondPrime = gen.GetBig();
            }

            var worker = new Task <BigInteger>(() => workerGenerator.NextPrime(firstPrime));

            worker.Start();
            secondPrime = mainGenerator.NextPrime(secondPrime);

            worker.Wait();
            firstPrime = worker.Result;
            worker.Dispose();

            return(firstPrime * secondPrime);
        }
        //Generates the modulus using more thread
        private static BigInteger ParGenMod(GeneratorWrap gen, uint wordSize, int threads, uint precision)
        {
            IPrime mainGenerator, workerGenerator;
            //threads distribution for primes creation
            if (threads < 4)
            {
                mainGenerator = new SequentialPrime(gen.GetInt(), precision, wordSize);
                workerGenerator = new SequentialPrime(gen.GetInt(), precision, wordSize);
            }
            else
            {
                mainGenerator = new ParallelPrime(gen.GetInt(), precision, wordSize, threads - threads / 2);
                workerGenerator = new ParallelPrime(gen.GetInt(), precision, wordSize, threads / 2);
            }

            //primes creation
            var firstPrime = gen.GetBig();
            var secondPrime = gen.GetBig();
            while (!SecurityCheck(firstPrime, secondPrime))
            {
                secondPrime = gen.GetBig();
            }

            Task<BigInteger> worker = new Task<BigInteger>(workerGenerator.NextPrime, firstPrime);
            worker.Start();
            secondPrime = mainGenerator.NextPrime(secondPrime);

            worker.Wait();
            firstPrime = worker.Result;
            worker.Dispose();

            return firstPrime*secondPrime;
        }