Skip to content

Commit

Permalink
Critical fix for large primes search
Browse files Browse the repository at this point in the history
A lot of amicable candidates were skipped due to data format mismatch in CandidatesData vector.
  • Loading branch information
SChernykh committed Mar 27, 2018
1 parent 7fbb6a7 commit 3470ed8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Amicable/OpenCL.cpp
Expand Up @@ -934,8 +934,32 @@ bool OpenCL::ProcessLargePrimes()
}

const num64 LargestCandidate = LowWord(SearchLimit::value / FirstPrime);
auto it = std::lower_bound(CandidatesData.begin(), CandidatesData.end(), LargestCandidate, [](const AmicableCandidate& a, num64 b) { return a.value <= b; });
const num64 CandidatesCount = static_cast<num64>(it - CandidatesData.begin());
num64 CandidatesCount;
{
const std::pair<unsigned int, unsigned int>* packedCandidates = reinterpret_cast<const std::pair<unsigned int, unsigned int>*>(CandidatesData.data());
int a = 0;
int b = static_cast<int>(CandidatesData.size());
while (a < b)
{
const int c = (a + b) >> 1;

num64 value = packedCandidates[c].first;
if (c >= CandidatesDataHighBitOffsets.first)
{
value |= 0x100000000ULL;
}

if (value <= LargestCandidate)
{
a = c + 1;
}
else
{
b = c;
}
}
CandidatesCount = static_cast<num64>(a);
}

const num64 TotalNumbersToCheck = CandidatesCount * LargePrimesCount;

Expand Down

0 comments on commit 3470ed8

Please sign in to comment.