Ejemplo n.º 1
0
        protected void findPeriodAsParallel(long k)
        {
            CBasicRandomValue random = new CBasicRandomValue();
            random.Skip(k - 1);

            System.Diagnostics.Stopwatch myStopwatch = new System.Diagnostics.Stopwatch();
            myStopwatch.Start();

            long T = k;
            long Xk = (multWithModulo(a, random.getState(), m) + c % m) % m;
            while (Xk != X0 && T <= k + 1000000)
            {
                Xk = (multWithModulo(a, Xk, m) + c % m) % m;
                ++T;
                if (T % (1 << 20) == 0)
                {
                    Console.WriteLine($"[{k}] [{myStopwatch.Elapsed}]: {T}");
                }
            }

            if (Xk == X0) {
                StreamWriter stream = new StreamWriter($@".\period_{k}.txt", false, Encoding.UTF8);
                stream.WriteLine($"Period = {T}");
                stream.Close();
                Console.WriteLine($"[{k}]: Found!");
                periodFound = true;
            } else {
                Console.WriteLine($"[{k} - {T}] [{DateTime.Now} {myStopwatch.Elapsed}]: Not found.");
            }

            readyAsyncResults++;
            if (readyAsyncResults >= blockSize)
                computePeriodAsParallel(curStartParallelIndex + blockSize);
            
            myStopwatch.Stop();
        }