Skip to content

Commit b218609

Browse files
Fix Gauss. elim.
1 parent 04e710b commit b218609

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,7 @@ struct Factorizer {
896896
for (size_t row = colPlus1; row < rows; ++row) {
897897
++mRowIt;
898898
++nRowIt;
899-
const boost::dynamic_bitset<size_t> rowCopy = *mRowIt;
900-
if (rowCopy[col]) {
899+
if ((*mRowIt)[col]) {
901900
// Swapping matrix rows corresponds
902901
// with swapping factorized numbers.
903902
std::swap(*mColIt, *mRowIt);
@@ -906,44 +905,48 @@ struct Factorizer {
906905
// Mark this column as having a pivot.
907906
result.marks[col] = true;
908907

909-
// Pivot found, now eliminate entries in this column
910-
const boost::dynamic_bitset<size_t> &cm = *mColIt;
911-
const BigInteger &cn = *nColIt;
912-
auto emRowIt = smoothNumberValues.begin();
913-
auto enRowIt = smoothNumberKeys.begin();
914-
const size_t maxLcv = std::min((size_t)CpuCount, rows);
915-
for (size_t cpu = 0U; cpu < maxLcv; ++cpu) {
916-
dispatch.dispatch([cpu, &cpuCount, &col, &rows, &cm, &cn, emRowIt, enRowIt]() -> bool {
917-
// Notice that each thread updates rows with space increments of cpuCount,
918-
// based on the same unchanged outer-loop row, and this covers the inner-loop set.
919-
auto mrIt = emRowIt;
920-
auto nrIt = enRowIt;
921-
for (size_t row = cpu; ; row += cpuCount) {
922-
boost::dynamic_bitset<size_t> &rm = *mrIt;
923-
BigInteger &rn = *nrIt;
924-
if ((row != col) && rm[col]) {
925-
// XOR-ing factorization rows
926-
// is like multiplying the numbers.
927-
rm ^= cm;
928-
rn *= cn;
929-
}
930-
if ((row + cpuCount) >= rows) {
931-
// This is the completion condition.
932-
return false;
933-
}
934-
// Every row advance is staggered according to cpuCount.
935-
std::advance(mrIt, cpuCount);
936-
std::advance(nrIt, cpuCount);
908+
break;
909+
}
910+
}
911+
912+
if (result.marks[col]) {
913+
// Pivot found, now eliminate entries in this column
914+
const boost::dynamic_bitset<size_t> &cm = *mColIt;
915+
const BigInteger &cn = *nColIt;
916+
auto emRowIt = smoothNumberValues.begin();
917+
auto enRowIt = smoothNumberKeys.begin();
918+
const size_t maxLcv = std::min((size_t)CpuCount, rows);
919+
for (size_t cpu = 0U; cpu < maxLcv; ++cpu) {
920+
dispatch.dispatch([cpu, &cpuCount, &col, &rows, &cm, &cn, emRowIt, enRowIt]() -> bool {
921+
// Notice that each thread updates rows with space increments of cpuCount,
922+
// based on the same unchanged outer-loop row, and this covers the inner-loop set.
923+
auto mrIt = emRowIt;
924+
auto nrIt = enRowIt;
925+
for (size_t row = cpu; ; row += cpuCount) {
926+
boost::dynamic_bitset<size_t> &rm = *mrIt;
927+
BigInteger &rn = *nrIt;
928+
if ((row != col) && rm[col]) {
929+
// XOR-ing factorization rows
930+
// is like multiplying the numbers.
931+
rm ^= cm;
932+
rn *= cn;
937933
}
938-
return false;
939-
});
940-
// Next inner-loop row (all at once by dispatch).
941-
++emRowIt;
942-
++enRowIt;
943-
}
944-
// All dispatched work must complete.
945-
dispatch.finish();
934+
if ((row + cpuCount) >= rows) {
935+
// This is the completion condition.
936+
return false;
937+
}
938+
// Every row advance is staggered according to cpuCount.
939+
std::advance(mrIt, cpuCount);
940+
std::advance(nrIt, cpuCount);
941+
}
942+
return false;
943+
});
944+
// Next inner-loop row (all at once by dispatch).
945+
++emRowIt;
946+
++enRowIt;
946947
}
948+
// All dispatched work must complete.
949+
dispatch.finish();
947950
}
948951

949952
// Next outer-loop row

0 commit comments

Comments
 (0)