feat: fast update

This commit is contained in:
tqcq 2024-10-26 09:34:46 +00:00
parent cc0f2e9414
commit a9fe57bf38

View File

@ -307,7 +307,6 @@ find_row_mask(std::vector<set_t> &sets,
uint64_t row_mask = init_row_mask; uint64_t row_mask = init_row_mask;
const uint64_t last_mask = init_last_mask; const uint64_t last_mask = init_last_mask;
row_mask <<= CL_SHIFT;// skip the lowest 6 bits since they're used for CL addressing row_mask <<= CL_SHIFT;// skip the lowest 6 bits since they're used for CL addressing
bool need_update_row_mask = false;
auto resolve = [=](uint64_t row_mask) -> bool { auto resolve = [=](uint64_t row_mask) -> bool {
if (row_mask & LS_BITMASK(CL_SHIFT)) { return false; } if (row_mask & LS_BITMASK(CL_SHIFT)) { return false; }
@ -334,6 +333,8 @@ find_row_mask(std::vector<set_t> &sets,
fprintf(stderr, "thread_num: %d\n", thread_num); fprintf(stderr, "thread_num: %d\n", thread_num);
uint64_t step = 1000000; uint64_t step = 1000000;
std::atomic<uint64_t> cur_pos{0};
std::atomic<uint64_t> base_pos{0};
// for (uint64_t i = row_mask; i < last_mask; ++step) { i = next_bit_permutation(i); } // for (uint64_t i = row_mask; i < last_mask; ++step) { i = next_bit_permutation(i); }
// fprintf(stderr, "total_step: %ld\n", step); // fprintf(stderr, "total_step: %ld\n", step);
// step /= thread_num; // step /= thread_num;
@ -344,16 +345,28 @@ find_row_mask(std::vector<set_t> &sets,
workers.emplace_back([&] { workers.emplace_back([&] {
while (!found) { while (!found) {
uint64_t cur_mask = last_mask; uint64_t cur_mask = last_mask;
uint64_t step_count = 0;
uint64_t my_pos = 0;
{ {
std::lock_guard<std::mutex> _(lock); std::lock_guard<std::mutex> _(lock);
if (row_mask >= last_mask || found) { break; } if (row_mask >= last_mask || found) { break; }
if (need_update_row_mask) { cur_mask = row_mask;
step_count = cur_pos - base_pos;
my_pos = cur_pos.fetch_add(1);
}
while (row_mask < last_mask && step_count > 0) {
--step_count;
for (int i = 0; i < step && row_mask < last_mask; ++i) { for (int i = 0; i < step && row_mask < last_mask; ++i) {
row_mask = next_bit_permutation(row_mask); row_mask = next_bit_permutation(row_mask);
} }
} }
cur_mask = row_mask; // update pos
need_update_row_mask = true; {
std::lock_guard<std::mutex> _(lock);
if (my_pos > base_pos) {
base_pos = my_pos;
row_mask = cur_mask;
}
} }
for (int i = 0; i < step && cur_mask < last_mask; ++i) { for (int i = 0; i < step && cur_mask < last_mask; ++i) {