try fix
This commit is contained in:
parent
6f5cb359b6
commit
6c754232e9
@ -320,9 +320,6 @@ find_row_mask(std::vector<set_t> &sets,
|
||||
return true;
|
||||
};
|
||||
|
||||
std::atomic_bool found{false};
|
||||
std::mutex lock;
|
||||
|
||||
// while (row_mask < last_mask) {
|
||||
// row_mask = next_bit_permutation(row_mask);
|
||||
// }
|
||||
@ -332,14 +329,17 @@ find_row_mask(std::vector<set_t> &sets,
|
||||
if (cpu == 0 && thread_num > 4) { thread_num -= 4; }
|
||||
fprintf(stderr, "thread_num: %d\n", thread_num);
|
||||
|
||||
uint64_t step = 1000 * 10;
|
||||
std::atomic_bool found{false};
|
||||
std::mutex lock;
|
||||
uint64_t inner_step = 1000;
|
||||
uint64_t outer_step = 1000 * 10;
|
||||
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;
|
||||
// if (!step) { ++step; }
|
||||
fprintf(stderr, "worker_step: %ld\n", step);
|
||||
fprintf(stderr, "worker_step: %ld\n", outer_step);
|
||||
|
||||
std::atomic<uint64_t> cnt{0};
|
||||
std::atomic<uint64_t> progress{0};
|
||||
@ -348,17 +348,17 @@ find_row_mask(std::vector<set_t> &sets,
|
||||
while (!found) {
|
||||
uint64_t cur_mask = 0;
|
||||
uint64_t step_count = 0;
|
||||
uint64_t my_pos = 0;
|
||||
uint64_t my_end_pos = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> _(lock);
|
||||
if (row_mask >= last_mask || found) { return; }
|
||||
step_count = g_cur_pos - g_base_pos;
|
||||
|
||||
cur_mask = row_mask;
|
||||
my_pos = g_cur_pos.fetch_add(step);
|
||||
my_end_pos = g_cur_pos.fetch_add(outer_step);
|
||||
}
|
||||
while (cur_mask < last_mask && step_count > 0 && !found.load(std::memory_order_relaxed)) {
|
||||
for (int i = std::min(step_count, step / 10); i > 0 && cur_mask < last_mask; --i) {
|
||||
for (int i = std::min(step_count, inner_step); 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, base_pos: %5ld progress: %ld\n",
|
||||
@ -369,25 +369,25 @@ find_row_mask(std::vector<set_t> &sets,
|
||||
|
||||
if (found) { break; }
|
||||
|
||||
step_count -= std::min(step_count, step / 10);
|
||||
step_count -= std::min(step_count, inner_step);
|
||||
|
||||
// my is new
|
||||
if (my_pos > g_base_pos.load(std::memory_order_relaxed) + step_count) {
|
||||
if (my_end_pos > g_base_pos.load(std::memory_order_relaxed) + step_count) {
|
||||
std::lock_guard<std::mutex> _(lock);
|
||||
if (my_pos > g_base_pos + step_count) {
|
||||
g_base_pos = my_pos;
|
||||
if (my_end_pos > g_base_pos + step_count) {
|
||||
g_base_pos = my_end_pos;
|
||||
row_mask = cur_mask;
|
||||
}
|
||||
} else if (g_base_pos.load(std::memory_order_relaxed) <= my_pos) {
|
||||
} else if (g_base_pos.load(std::memory_order_relaxed) <= my_end_pos) {
|
||||
std::lock_guard<std::mutex> _(lock);
|
||||
if (g_base_pos <= my_pos) {
|
||||
if (g_base_pos <= my_end_pos) {
|
||||
cur_mask = row_mask;
|
||||
step_count = my_pos - g_base_pos;
|
||||
step_count = my_end_pos - g_base_pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = step; i > 0 && cur_mask < last_mask && !found.load(std::memory_order_relaxed); --i) {
|
||||
for (int i = outer_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)) {
|
||||
@ -397,7 +397,7 @@ find_row_mask(std::vector<set_t> &sets,
|
||||
}
|
||||
}
|
||||
}
|
||||
progress.fetch_add(step);
|
||||
progress.fetch_add(outer_step);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user