From ecb9bb952eefbd428b830824164b8c8197d9fd4c Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 24 Feb 2023 21:12:31 +0800 Subject: [PATCH] test: match cpu core number automatically --- test/global/global_utils.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/global/global_utils.cc b/test/global/global_utils.cc index 786ffb2..d2d5803 100644 --- a/test/global/global_utils.cc +++ b/test/global/global_utils.cc @@ -1,5 +1,8 @@ +#include #include "global_utils.h" +const static uint32_t DEFAULT_THREAD_NUM = 1; + range_split_t range_split(uint64_t start, uint64_t end, uint64_t size) { uint64_t rear = end - (end - start) % size; // (rear - start) % size == 0 range_split_t ranges; @@ -13,8 +16,6 @@ range_split_t range_split(uint64_t start, uint64_t end, uint64_t size) { } uint32_t thread_num() { - - // TODO: use CPU core number - - return 16; + auto num = std::thread::hardware_concurrency(); // CPU core number + return (num == 0) ? DEFAULT_THREAD_NUM : num; // fetch failed -> use default number }