Skip to content

Commit ee55aa2

Browse files
committed
Build with multicore
1 parent 93a1ae7 commit ee55aa2

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

.github/workflows/build.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ jobs:
2020
- name: Configure CMake
2121
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
2222
- name: Build
23-
run: ninja -C ${{github.workspace}}/build
23+
run: |
24+
cores=$(sysctl -n hw.ncpu)
25+
ninja -C ${{github.workspace}}/build -j$((cores + 1))
2426
- name: Test
2527
working-directory: ${{github.workspace}}/build
2628
run: |
27-
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
29+
cores=$(sysctl -n hw.ncpu)
30+
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel $cores
2831
2932
ubuntu:
3033
runs-on: ubuntu-latest
@@ -39,12 +42,15 @@ jobs:
3942
-DCMAKE_C_FLAGS="-fsanitize=leak" \
4043
-DCMAKE_CXX_FLAGS="-fsanitize=leak"
4144
- name: Build
42-
run: ninja -C ${{github.workspace}}/build
45+
run: |
46+
cores=$(nproc)
47+
ninja -C ${{github.workspace}}/build -j$((cores + 1))
4348
- name: Test with LSan
4449
working-directory: ${{github.workspace}}/build
4550
run: |
4651
export ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:verbosity=1"
47-
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
52+
cores=$(nproc)
53+
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel $cores
4854
4955
selfhosted:
5056
runs-on: self-hosted
@@ -53,7 +59,11 @@ jobs:
5359
- name: Configure CMake
5460
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_GLCACHE=on -DENABLE_LRB=on
5561
- name: Build
56-
run: ninja -C ${{github.workspace}}/build
62+
run: |
63+
cores=$(nproc)
64+
ninja -C ${{github.workspace}}/build -j$((cores + 1))
5765
- name: Test
5866
working-directory: ${{github.workspace}}/build
59-
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
67+
run: |
68+
cores=$(nproc)
69+
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel $cores

scripts/install_dependency.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ install_cmake() {
158158
# Install XGBoost
159159
install_xgboost() {
160160
log_info "Installing XGBoost..."
161+
local cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
161162
pushd /tmp/ >/dev/null
162163
if [[ ! -d "xgboost" ]]; then
163164
git clone --recursive https://github.com/dmlc/xgboost
@@ -166,11 +167,7 @@ install_xgboost() {
166167
mkdir -p build
167168
pushd build >/dev/null
168169
cmake -G Ninja ..
169-
if [[ ${GITHUB_ACTIONS-} == "true" ]]; then
170-
ninja
171-
else
172-
ninja
173-
fi
170+
ninja -j$((cores + 1))
174171
sudo ninja install
175172
popd >/dev/null
176173
popd >/dev/null
@@ -180,6 +177,7 @@ install_xgboost() {
180177
# Install LightGBM
181178
install_lightgbm() {
182179
log_info "Installing LightGBM..."
180+
local cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
183181
pushd /tmp/ >/dev/null
184182
if [[ ! -d "LightGBM" ]]; then
185183
git clone --recursive https://github.com/microsoft/LightGBM
@@ -188,11 +186,7 @@ install_lightgbm() {
188186
mkdir -p build
189187
pushd build >/dev/null
190188
cmake -G Ninja ..
191-
if [[ ${GITHUB_ACTIONS-} == "true" ]]; then
192-
ninja
193-
else
194-
ninja
195-
fi
189+
ninja -j$((cores + 1))
196190
sudo ninja install
197191
popd >/dev/null
198192
popd >/dev/null
@@ -202,6 +196,7 @@ install_lightgbm() {
202196
# Install Zstd
203197
install_zstd() {
204198
log_info "Installing Zstd..."
199+
local cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
205200
pushd /tmp/ >/dev/null
206201
local zstd_version="1.5.0"
207202
if [[ ! -f "zstd-${zstd_version}.tar.gz" ]]; then
@@ -212,7 +207,7 @@ install_zstd() {
212207
mkdir -p _build
213208
pushd _build >/dev/null
214209
cmake -G Ninja ..
215-
ninja
210+
ninja -j$((cores + 1))
216211
sudo ninja install
217212
popd >/dev/null
218213
popd >/dev/null

0 commit comments

Comments
 (0)