Compare commits

..

No commits in common. "f5f16fcac7319f5c2644ef88aeae8302749c09dd" and "1845acf65fb42e3a3f008e5ac27a94ff4c209e1d" have entirely different histories.

View File

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