diff --git a/drama/src/include/rev-mc.h b/drama/src/include/rev-mc.h index 13c4e08..e96325b 100644 --- a/drama/src/include/rev-mc.h +++ b/drama/src/include/rev-mc.h @@ -9,4 +9,5 @@ typedef struct { //---------------------------------------------------------- // Functions -void rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, char *o_file, uint64_t flags); +void +rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, char *o_file, uint64_t flags, uint64_t cpu); diff --git a/drama/src/main.c b/drama/src/main.c index aba8089..60be25c 100644 --- a/drama/src/main.c +++ b/drama/src/main.c @@ -57,6 +57,7 @@ main(int argc, char **argv) size_t rounds = ROUNDS_std; size_t m_size = MEM_SIZE_std; size_t threshold = THRESHOLD_std; + size_t cpu = 1; char *o_file = (char *) O_FILE_std; flags |= F_POPULATE; @@ -74,7 +75,7 @@ main(int argc, char **argv) {"mem", required_argument, 0, 0}, {0, 0, 0, 0} }; - int arg = getopt_long(argc, argv, "o:s:r:t:hv", long_options, &option_index); + int arg = getopt_long(argc, argv, "o:s:r:t:n:hv", long_options, &option_index); if (arg == -1) break; @@ -99,6 +100,8 @@ main(int argc, char **argv) case 'r': rounds = atoi(optarg); break; + case 'n': + cpu = atoi(optarg); case 't': threshold = atoi(optarg); break; @@ -112,7 +115,7 @@ main(int argc, char **argv) } } - rev_mc(sets_cnt, threshold, rounds, m_size, o_file, flags); + rev_mc(sets_cnt, threshold, rounds, m_size, o_file, flags, cpu); return 0; } diff --git a/drama/src/rev-mc.c b/drama/src/rev-mc.c index a99b2b5..d0d71cf 100644 --- a/drama/src/rev-mc.c +++ b/drama/src/rev-mc.c @@ -326,7 +326,9 @@ find_row_mask(std::vector &sets, // } std::vector workers; - for (int i = 0; i < 8; ++i) { + auto thread_num = std::thread::hardware_concurrency(); + if (thread_num > 2) { thread_num -= 2; } + for (int i = 0; i < thread_num; ++i) { workers.emplace_back([&] { while (!found) { uint64_t cur_mask = last_mask; @@ -361,7 +363,7 @@ find_row_mask(std::vector &sets, //---------------------------------------------------------- void -rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, char *o_file, uint64_t flags) +rev_mc(size_t sets_cnt, size_t threshold, size_t rounds, size_t m_size, char *o_file, uint64_t flags, uint64_t cpu) { time_t t;