feat: update
This commit is contained in:
parent
fa63c9daac
commit
8a74c8e78f
@ -340,6 +340,35 @@ find_row_mask(std::vector<set_t> &sets,
|
|||||||
// step /= thread_num;
|
// step /= thread_num;
|
||||||
// if (!step) { ++step; }
|
// if (!step) { ++step; }
|
||||||
fprintf(stderr, "worker_step: %ld\n", outer_step);
|
fprintf(stderr, "worker_step: %ld\n", outer_step);
|
||||||
|
auto try_update_row_mask = [&](uint64_t pos, uint64_t mask) {
|
||||||
|
if (pos > g_base_pos.load(std::memory_order_relaxed)) {
|
||||||
|
std::lock_guard<std::mutex> _(lock);
|
||||||
|
if (pos > g_base_pos.load()) {
|
||||||
|
g_base_pos = row_mask;
|
||||||
|
row_mask = mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
auto try_get_row_mask = [&](uint64_t end_pos, uint64_t &diff, uint64_t &cur_mask) {
|
||||||
|
uint64_t v = g_base_pos.load(std::memory_order_relaxed);
|
||||||
|
if (end_pos - diff < v && end_pos >= v) {
|
||||||
|
std::lock_guard<std::mutex> _(lock);
|
||||||
|
v = g_base_pos.load();
|
||||||
|
if (end_pos - diff < v && end_pos >= v) {
|
||||||
|
diff = end_pos - v;
|
||||||
|
cur_mask = row_mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto set_found = [&](uint64_t cur_mask) {
|
||||||
|
bool expected = false;
|
||||||
|
if (found.compare_exchange_strong(expected, true)) {
|
||||||
|
std::lock_guard<std::mutex> _(lock);
|
||||||
|
found.store(true);
|
||||||
|
row_mask = cur_mask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
std::atomic<uint64_t> cnt{0};
|
std::atomic<uint64_t> cnt{0};
|
||||||
std::atomic<uint64_t> progress{0};
|
std::atomic<uint64_t> progress{0};
|
||||||
@ -361,32 +390,12 @@ find_row_mask(std::vector<set_t> &sets,
|
|||||||
cur_mask = next_bit_permutation(cur_mask);
|
cur_mask = next_bit_permutation(cur_mask);
|
||||||
}
|
}
|
||||||
diff -= std::min(inner_step, diff);
|
diff -= std::min(inner_step, diff);
|
||||||
|
try_update_row_mask(end_pos - diff, cur_mask);
|
||||||
if (end_pos - diff > g_base_pos) {
|
try_get_row_mask(end_pos, diff, cur_mask);
|
||||||
std::lock_guard<std::mutex> _(lock);
|
|
||||||
if (found) { break; }
|
|
||||||
if (end_pos - diff > g_base_pos) {
|
|
||||||
g_base_pos = end_pos - diff;
|
|
||||||
row_mask = cur_mask;
|
|
||||||
}
|
|
||||||
} else if (end_pos >= g_base_pos) {
|
|
||||||
std::lock_guard<std::mutex> _(lock);
|
|
||||||
if (end_pos >= g_base_pos) {
|
|
||||||
diff = end_pos - g_base_pos;
|
|
||||||
cur_mask = row_mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = outer_step; i > 0 && cur_mask < last_mask; --i) {
|
for (int i = outer_step; i > 0 && cur_mask < last_mask; --i) {
|
||||||
if (resolve(cur_mask) && !found) {
|
if (resolve(cur_mask)) { set_found(cur_mask); }
|
||||||
bool expected = false;
|
|
||||||
if (found.compare_exchange_strong(expected, true)) {
|
|
||||||
std::lock_guard<std::mutex> _(lock);
|
|
||||||
found.store(true);
|
|
||||||
row_mask = cur_mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cur_mask = next_bit_permutation(cur_mask);
|
cur_mask = next_bit_permutation(cur_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user