Compare commits
3 Commits
81f156be08
...
a53cedd6d5
Author | SHA1 | Date | |
---|---|---|---|
|
a53cedd6d5 | ||
|
9b95b11f4d | ||
|
6374c128af |
@ -329,7 +329,7 @@ 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 (cpu == 0 && 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;
|
||||||
@ -341,6 +341,7 @@ find_row_mask(std::vector<set_t> &sets,
|
|||||||
// if (!step) { ++step; }
|
// if (!step) { ++step; }
|
||||||
fprintf(stderr, "worker_step: %ld\n", step);
|
fprintf(stderr, "worker_step: %ld\n", step);
|
||||||
|
|
||||||
|
std::atomic<uint64_t> cnt{0};
|
||||||
for (int i = 0; i < thread_num; ++i) {
|
for (int i = 0; i < thread_num; ++i) {
|
||||||
workers.emplace_back([&] {
|
workers.emplace_back([&] {
|
||||||
while (!found) {
|
while (!found) {
|
||||||
@ -357,18 +358,26 @@ find_row_mask(std::vector<set_t> &sets,
|
|||||||
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) {
|
for (int i = std::min(step_count, step); i > 0 && cur_mask < last_mask; --i) {
|
||||||
cur_mask = next_bit_permutation(cur_mask);
|
cur_mask = next_bit_permutation(cur_mask);
|
||||||
|
if (cnt.fetch_add(1) % 10000 == 0) {
|
||||||
|
fprintf(stderr, "cnt : %5ld\n", cnt.load(std::memory_order_relaxed));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
step_count -= std::min(step_count, step);
|
step_count -= std::min(step_count, step);
|
||||||
|
|
||||||
|
if (my_pos > g_base_pos) {
|
||||||
std::lock_guard<std::mutex> _(lock);
|
std::lock_guard<std::mutex> _(lock);
|
||||||
if (my_pos > g_base_pos) {
|
if (my_pos > g_base_pos) {
|
||||||
g_base_pos = my_pos;
|
g_base_pos = my_pos;
|
||||||
row_mask = cur_mask;
|
row_mask = cur_mask;
|
||||||
|
}
|
||||||
} else if (g_base_pos <= g_cur_pos) {
|
} else if (g_base_pos <= g_cur_pos) {
|
||||||
|
std::lock_guard<std::mutex> _(lock);
|
||||||
|
if (g_base_pos < g_cur_pos) {
|
||||||
cur_mask = row_mask;
|
cur_mask = row_mask;
|
||||||
my_pos = g_base_pos;
|
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 && !found.load(std::memory_order_relaxed); ++i) {
|
||||||
if (resolve(cur_mask)) {
|
if (resolve(cur_mask)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user