feat: optim

This commit is contained in:
tqcq 2024-10-24 06:47:57 +00:00
parent a7d47c26f6
commit d2953a8981

View File

@ -329,7 +329,8 @@ find_row_mask(std::vector<set_t> &sets,
if (thread_num > 2) { thread_num -= 2; } if (thread_num > 2) { thread_num -= 2; }
fprintf(stderr, "thread_num: %ld\n", thread_num); fprintf(stderr, "thread_num: %ld\n", thread_num);
uint64_t step = 1 << 20; uint64_t step = 1 << 20;
bool lazy_advance_step = false;
// 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;
@ -337,16 +338,19 @@ find_row_mask(std::vector<set_t> &sets,
fprintf(stderr, "worker_step: %ld\n", step); fprintf(stderr, "worker_step: %ld\n", step);
for (int i = 0; i < thread_num; ++i) { for (int i = 0; i < thread_num; ++i) {
workers.emplace_back([=, &row_mask, &found, &lock] { workers.emplace_back([=, &row_mask, &found, &lock, &lazy_advance_step] {
while (!found) { while (!found) {
uint64_t cur_mask = last_mask; uint64_t cur_mask = last_mask;
{ {
std::lock_guard<std::mutex> _(lock); std::lock_guard<std::mutex> _(lock);
if (row_mask >= last_mask) { break; } if (row_mask >= last_mask) { break; }
cur_mask = row_mask; if (lazy_advance_step) {
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;
lazy_advance_step = true;
} }
for (int i = 0; i < step && cur_mask < last_mask; ++i) { for (int i = 0; i < step && cur_mask < last_mask; ++i) {