Specifying number of threads using XGBoost.train

When using the xgboost.train() function, all the threads are used. I would like to use a specific amount. Unfortunately, this function does not accept the parameters nthread nor n_jobs. How can I control the number of threads being used?

Thanks.

// Edit

It seems that I found a solution. In contrast with the method, how one provides the nthread (or n_jobs) parameter to XGBClassifier of XGBRegressor, by adding this parameter directly to the brackets as xgb.XGBRegressor(nthread=n) then as indicated on xgboost document (page 46), I added an additional parameter parameters["nthread"] = number_of_threads to the parameters (a dictionary) I am using. After testing with different numbers, the number of threads being used reported in htop was the same as the number_of_threads parameter provided. Can anyone confirm this to be the right method?

You can set the number of threads by nthread parameter in XGBClassifier or XGBRegressor

import time
import numpy as np
import xgboost as xgb
start = time.time()
model.fit(X, y)
elapsed = time.time() - start
print(n, round(elapsed,3))
results.append(elapsed)


The output after execution of this code is

    1 0.059
2 0.071
3 0.063
4 0.094
5 0.075
6 0.078
8 0.09
16 0.099
32 0.157
64 0.235

• I think that XGBRegressor is only a wrapper of xgboost.train. Isn't there a way to specify the nthread or n_jobs for train() function? At the moment when running the code, it automatically uses all the available threads – LauritsT Sep 5 '19 at 5:06