Compare commits

...

2 Commits

Author SHA1 Message Date
tqcq
f5f16fcac7 feat: update 2024-10-26 10:01:58 +00:00
tqcq
7262c59d5a feat update 2024-10-26 10:00:58 +00:00

View File

@ -329,12 +329,12 @@ find_row_mask(std::vector<set_t> &sets,
std::vector<std::thread> workers;
int thread_num = cpu == 0 ? std::thread::hardware_concurrency() : cpu;
if (thread_num > 4) { thread_num -= 4; }
if (thread_num > 4) { thread_num = 4; }
fprintf(stderr, "thread_num: %d\n", thread_num);
uint64_t step = 1000;
std::atomic<uint64_t> cur_pos{0};
std::atomic<uint64_t> base_pos{0};
std::atomic<uint64_t> g_cur_pos{0};
std::atomic<uint64_t> g_base_pos{0};
// for (uint64_t i = row_mask; i < last_mask; ++step) { i = next_bit_permutation(i); }
// fprintf(stderr, "total_step: %ld\n", step);
// step /= thread_num;
@ -351,28 +351,29 @@ find_row_mask(std::vector<set_t> &sets,
std::lock_guard<std::mutex> _(lock);
if (row_mask >= last_mask || found) { break; }
cur_mask = row_mask;
step_count = cur_pos - base_pos;
my_pos = cur_pos.fetch_add(1);
step_count = g_cur_pos - g_base_pos;
my_pos = g_cur_pos.fetch_add(step * 10);
}
while (cur_mask < last_mask && step_count > 0 && !found.load(std::memory_order_relaxed)) {
--step_count;
for (int i = 0; i < step && cur_mask < last_mask; ++i) {
for (int i = std::min(step_count, step); i > 0 && cur_mask < last_mask; --i) {
cur_mask = next_bit_permutation(cur_mask);
}
}
// update pos
{
step_count -= std::min(step_count, step);
std::lock_guard<std::mutex> _(lock);
if (my_pos > base_pos) {
base_pos = my_pos;
if (my_pos > g_base_pos) {
g_base_pos = my_pos;
row_mask = cur_mask;
} else if (g_base_pos <= g_cur_pos) {
cur_mask = row_mask;
my_pos = g_base_pos;
}
}
for (int i = 0; i < step && cur_mask < last_mask; ++i) {
if (!found.load(std::memory_order_relaxed) && resolve(cur_mask)) {
std::lock_guard<std::mutex> _(lock);
for (int i = 0; i < step && cur_mask < last_mask && !found.load(std::memory_order_relaxed); ++i) {
if (resolve(cur_mask)) {
if (!found.exchange(true)) {
std::lock_guard<std::mutex> _(lock);
row_mask = cur_mask;
break;
}