diff --git a/drama/src/rev-mc.c b/drama/src/rev-mc.c index b8c795c..7d7215a 100644 --- a/drama/src/rev-mc.c +++ b/drama/src/rev-mc.c @@ -332,7 +332,7 @@ find_row_mask(std::vector &sets, if (cpu == 0 && thread_num > 4) { thread_num -= 4; } fprintf(stderr, "thread_num: %d\n", thread_num); - uint64_t step = 1000; + uint64_t step = 1000 * 10; std::atomic g_cur_pos{0}; std::atomic g_base_pos{0}; // for (uint64_t i = row_mask; i < last_mask; ++step) { i = next_bit_permutation(i); } @@ -354,10 +354,10 @@ find_row_mask(std::vector &sets, if (row_mask >= last_mask || found) { break; } cur_mask = row_mask; step_count = g_cur_pos - g_base_pos; - my_pos = g_cur_pos.fetch_add(step * 10); + my_pos = g_cur_pos.fetch_add(step); } 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) { + for (int i = std::min(step_count, step / 10); i > 0 && cur_mask < last_mask; --i) { cur_mask = next_bit_permutation(cur_mask); if (cnt.fetch_add(1) % 10000000 == 0) { fprintf(stderr, "cnt : %ld, step_count: %5ld, cur_pos: %5ld progress: %ld\n", @@ -375,16 +375,16 @@ find_row_mask(std::vector &sets, g_base_pos = my_pos; row_mask = cur_mask; } - } else if (g_base_pos.load(std::memory_order_relaxed) < g_cur_pos.load(std::memory_order_relaxed)) { + } else if (g_base_pos.load(std::memory_order_relaxed) < my_pos) { std::lock_guard _(lock); - if (g_base_pos < g_cur_pos) { - cur_mask = row_mask; - my_pos = g_base_pos; + if (g_base_pos <= my_pos) { + cur_mask = row_mask; + step_count = my_pos - g_base_pos; } } } - for (int i = step * 10; i > 0 && cur_mask < last_mask && !found.load(std::memory_order_relaxed); --i) { + for (int i = step; i > 0 && cur_mask < last_mask && !found.load(std::memory_order_relaxed); --i) { if (resolve(cur_mask)) { bool expected = false; if (found.compare_exchange_strong(expected, true)) { @@ -394,7 +394,7 @@ find_row_mask(std::vector &sets, } } } - progress.fetch_add(step * 10); + progress.fetch_add(step); } }); }