Skip to content

Commit

Permalink
example1: fix execution on machines having more than 15 threads/cores
Browse files Browse the repository at this point in the history
Fix execution on machines having more than 15 threads/cores.
Also substract by 1 (the main thread) the amount of all threads
to get the amount of helper thread in all cases.
  • Loading branch information
illwieckz committed Jul 7, 2024
1 parent 73a6d5c commit 488a847
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions example1/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,17 @@ int main(int argc, char* argv[]) {
}

// Determine the # of helper threads (in addition to the main thread) to use during compression. NumberOfCPU's-1 is reasonable.
int num_helper_threads = 1;
int number_of_processors = 1;
#if defined(_WIN32)
SYSTEM_INFO g_system_info;
GetSystemInfo(&g_system_info);
num_helper_threads = std::max<int>(0, (int)g_system_info.dwNumberOfProcessors - 1);
number_of_processors = std::max<int>(1, (int)g_system_info.dwNumberOfProcessors);
#elif defined(__FreeBSD__) || defined(__APPLE__)
num_helper_threads = std::max<int>(1, sysconf(_SC_NPROCESSORS_ONLN));
number_of_processors = std::max<int>(1, sysconf(_SC_NPROCESSORS_ONLN));
#elif defined(__GNUC__)
num_helper_threads = std::max<int>(1, get_nprocs());
number_of_processors = std::max<int>(1, get_nprocs());
#endif
comp_params.m_num_helper_threads = num_helper_threads;
comp_params.m_num_helper_threads = std::min(number_of_processors - 1, (int)cCRNMaxHelperThreads);

comp_params.m_pProgress_func = progress_callback_func;

Expand Down

0 comments on commit 488a847

Please sign in to comment.