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
from sklearn.datasets import load_boston
import xgboost as xgb
num_threads = [1,2,3,4,5,6,8,16,32,64]
for n in num_threads:
    start = time.time()
    model = xgb.XGBRegressor(objective='reg:squarederror',nthread=n)
    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