Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary allocations in HistogramSumReducer #6132

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

jameslamb
Copy link
Collaborator

@jameslamb jameslamb commented Oct 8, 2023

Contributes to #4705.

Int32HistogramSumReducer and Int16HistogramSumReducer allocate an int and assign to it the value of OMP_NUM_THREADS(), then only use that value immediately after, for one OpenMP for loop.

This PR proposes just directly passing OMP_NUM_THREADS() to the configuration for those OpenMP for loop pragmas, to avoid the unnecessary allocation.

This also resolves the following compiler warnings that show up on clang when OpenMP support is disabled:

LightGBM/include/LightGBM/bin.h:66:13: warning: unused variable 'num_threads' [-Wunused-variable]
  const int num_threads = OMP_NUM_THREADS();
            ^
LightGBM/include/LightGBM/bin.h:77:13: warning: unused variable 'num_threads' [-Wunused-variable]
  const int num_threads = OMP_NUM_THREADS();
            ^
2 warnings generated.

How I tested this

LightGBM's CI covers the cases where OpenMP is available. I ran the following locally to confirm that this suppresses the compiler warnings when building without OpenMP support.

rm -rf ./build
mkdir ./build
cd ./build
cmake -DUSE_OPENMP=off ..
make -j3 _lightgbm

@jameslamb jameslamb changed the title WIP: remove unnecessary allocations in HistogramSumReducer remove unnecessary allocations in HistogramSumReducer Oct 8, 2023
@jameslamb jameslamb marked this pull request as ready for review October 8, 2023 21:19
@jameslamb jameslamb merged commit ad02551 into master Oct 9, 2023
41 checks passed
@jameslamb jameslamb deleted the standardize-omp-config branch October 9, 2023 01:35
Ten0 pushed a commit to Ten0/LightGBM that referenced this pull request Jan 12, 2024
Copy link

github-actions bot commented Oct 9, 2024

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants