feat: update

This commit is contained in:
tqcq 2024-10-26 12:54:02 +00:00
parent d1e9def682
commit 449d2b008f

View File

@ -347,57 +347,43 @@ find_row_mask(std::vector<set_t> &sets,
workers.emplace_back([&] { workers.emplace_back([&] {
while (!found) { while (!found) {
uint64_t cur_mask = 0; uint64_t cur_mask = 0;
uint64_t step_count = 0; uint64_t diff = 0;
uint64_t my_end_pos = 0; uint64_t end_pos = 0;
{ {
std::lock_guard<std::mutex> _(lock); std::lock_guard<std::mutex> _(lock);
if (row_mask >= last_mask || found) { return; }
step_count = g_cur_pos - g_base_pos;
cur_mask = row_mask; cur_mask = row_mask;
my_end_pos = g_cur_pos.fetch_add(outer_step); diff = g_cur_pos - g_base_pos;
end_pos = g_cur_pos.fetch_add(outer_step);
} }
while (cur_mask < last_mask && step_count > 0 && !found.load(std::memory_order_relaxed)) {
for (int i = std::min(step_count, inner_step); i > 0 && cur_mask < last_mask; --i) { while (diff > 0 && cur_mask < last_mask) {
for (int i = std::min(inner_step, diff); i > 0 && cur_mask < last_mask; --i) {
cur_mask = next_bit_permutation(cur_mask); cur_mask = next_bit_permutation(cur_mask);
if (cnt.fetch_add(1) % 10000000 == 0) {
fprintf(stderr, "cnt : %ld, step_count: %5ld, base_pos: %5ld progress: %ld\n",
cnt.load(std::memory_order_relaxed), step_count, g_base_pos.load(),
progress.load());
}
} }
diff -= std::min(inner_step, diff);
std::lock_guard<std::mutex> _(lock);
if (end_pos - diff > g_base_pos) {
if (found) { break; } if (found) { break; }
g_base_pos = end_pos - diff;
step_count -= std::min(step_count, inner_step);
// my is new
if (my_end_pos > g_base_pos.load(std::memory_order_relaxed) + step_count) {
std::lock_guard<std::mutex> _(lock);
if (my_end_pos > g_base_pos + step_count) {
g_base_pos = my_end_pos - step_count;
row_mask = cur_mask; row_mask = cur_mask;
} } else if (end_pos >= g_base_pos) {
} else if (g_base_pos.load(std::memory_order_relaxed) <= my_end_pos) { diff = end_pos - g_base_pos;
std::lock_guard<std::mutex> _(lock);
if (g_base_pos <= my_end_pos) {
cur_mask = row_mask; cur_mask = row_mask;
step_count = my_end_pos - g_base_pos;
}
} }
} }
for (int i = outer_step; i > 0 && cur_mask < last_mask && !found.load(std::memory_order_relaxed); --i) { for (int i = outer_step; i > 0 && cur_mask < last_mask; --i) {
if (resolve(cur_mask)) { if (resolve(cur_mask)) {
bool expected = false; bool expected = false;
if (found.compare_exchange_strong(expected, true)) { if (found.compare_exchange_strong(expected, true)) {
std::lock_guard<std::mutex> _(lock); std::lock_guard<std::mutex> _(lock);
found.store(true);
row_mask = cur_mask; row_mask = cur_mask;
break;
} }
} }
cur_mask = next_bit_permutation(cur_mask);
} }
progress.fetch_add(outer_step);
} }
}); });
} }