Пример #1
0
 public void AddDataToSolveRequest(SieveResult data)
 {
     //transpose matrix, add it to the coefficients (making sure to offset by startIdx of data)
     for (int i = 0; i < data.V.Count; i++)
     {
         for (int j = 0; j < data.B; j++)
         {
             Coefficients[j][i + V.Count] = data.SmoothRelations[i][j];
         }
     }
     V.AddRange(data.V);
     VOut.AddRange(data.VOut);
     L += data.SmoothsFound;
 }
Пример #2
0
        public bool AddDataToSolveRequestMax(SieveResult data)
        {
            long tmp = L;

            //transpose matrix, add it to the coefficients (making sure to offset by startIdx of data)
            for (int i = 0; i < data.V.Count; i++)
            {
                for (int j = 0; j < data.B; j++)
                {
                    Coefficients[j][i + tmp] = data.SmoothRelations[i][j];
                }
                V.Add(data.V[i]);
                VOut.Add(data.VOut[i]);
                L++;
                if (L >= columns)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        //memory saving method - is slower, but better for multithreading
        public static void Sieve(SieveInitInfo sievereq, SieveResult sieveres, long startIdx, long L)
        {
            //want to optimize this further (predefine size of SmoothRelations to approximated B value)
            sieveres.SmoothRelations = new List <BinaryVector>();
            sieveres.V    = new List <long>();
            sieveres.B    = sievereq.B;
            sieveres.VOut = new List <BigInteger>();

            long[] nextIdxA = new long[sievereq.B];
            long[] nextIdxB = new long[sievereq.B];
            for (int i = 0; i < sievereq.B; i++)
            {
                long interval      = sievereq.PrimeIntervals[i];
                long primeStart    = sievereq.PrimeStarts[i][0];
                long unoffset      = startIdx - primeStart;
                long rounded       = (long)Math.Ceiling((unoffset) * 1D / interval) * interval;
                long remappedStart = rounded + primeStart;
                nextIdxA[i] = remappedStart;

                if (sievereq.PrimeStarts[i].Count == 1)
                {
                    nextIdxB[i] = -1;
                }
                else
                {
                    interval      = sievereq.PrimeIntervals[i];
                    primeStart    = sievereq.PrimeStarts[i][1];
                    unoffset      = startIdx - primeStart;
                    rounded       = (long)Math.Ceiling((unoffset) * 1D / interval) * interval;
                    remappedStart = rounded + primeStart;
                    nextIdxB[i]   = remappedStart;
                }
            }
            BinaryVector currVect = new BinaryVector(sievereq.B);
            BigInteger   currVal;

            for (long i = startIdx; i < L + startIdx; i++)
            {
                currVal = sievereq.PolyFunction.F(i + sievereq.AStart);

                for (int j = 0; j < sievereq.B; j++)
                {
                    if (nextIdxA[j] == i)
                    {
                        while (currVal % sievereq.PrimeIntervals[j] == 0)
                        {
                            currVal    /= sievereq.PrimeIntervals[j];
                            currVect[j] = currVect[j] + 1;
                        }
                        nextIdxA[j] += sievereq.PrimeIntervals[j];
                    }

                    if (nextIdxB[j] == i)
                    {
                        while (currVal % sievereq.PrimeIntervals[j] == 0)
                        {
                            currVal    /= sievereq.PrimeIntervals[j];
                            currVect[j] = currVect[j] + 1;
                        }
                        nextIdxB[j] += sievereq.PrimeIntervals[j];
                    }
                }

                if (currVal == 1)
                {
                    sieveres.SmoothRelations.Add(currVect);
                    currVect = new BinaryVector(sievereq.B);
                    sieveres.V.Add(i + sievereq.AStart);
                    sieveres.VOut.Add(sievereq.PolyFunction.F(i + sievereq.AStart));
                    sieveres.SmoothsFound++;
                }
                else
                {
                    BinaryVector.FastFill(0, currVect);
                }
            }
        }