Skip to content

Commit

Permalink
Merge pull request #117 from dvukolov/omp-threads
Browse files Browse the repository at this point in the history
Consistent handling of the number of OpenMP threads
  • Loading branch information
QinbinLi committed Jan 22, 2019
2 parents 7c796a2 + bb5f89e commit ef28a78
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
5 changes: 4 additions & 1 deletion R/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Before you use the R interface, you must build ThunderSVM.
## Methods
By default, the directory for storing the training data and results is the working directory.

*svm_train_R(svm_type = 0, kernel = 2,degree = 3,gamma = 'auto', coef0 = 0.0, nu = 0.5, cost = 1.0, epsilon = 0.1, tol = 0.001, probability = FALSE, class_weight = 'None', cv = -1, verbose = FALSE, max_iter = -1, dataset = 'None', model_file = 'None')*
*svm_train_R(svm_type = 0, kernel = 2,degree = 3,gamma = 'auto', coef0 = 0.0, nu = 0.5, cost = 1.0, epsilon = 0.1, tol = 0.001, probability = FALSE, class_weight = 'None', cv = -1, verbose = FALSE, max_iter = -1, n_cores = -1, dataset = 'None', model_file = 'None')*

*svm_predict_R(test_dataset = 'None', model_file = 'None', out_file = 'None')*

Expand Down Expand Up @@ -81,6 +81,9 @@ svm_predict_R(test_dataset = "../dataset/test_dataset.txt", model_file = "../dat
*max_iter*: int, optional (default=-1)\
hard limit on the number of iterations within the solver, or -1 for no limit.

*n_cores*: int, optional (default=-1)\
set the number of cpu cores to use, -1 for maximum

*dataset*: string\
file path to training dataset.

Expand Down
16 changes: 6 additions & 10 deletions src/thundersvm/cmdparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ void CMDParser::parse_command_line(int argc, char **argv) {
HelpInfo_svmtrain();
}
}
if (n_cores == -1) {
omp_set_num_threads(omp_get_max_threads());
} else if (n_cores <= 0) {
LOG(ERROR) << "cores number must bigger than 0";
} else {
if (n_cores > 0) {
omp_set_num_threads(n_cores);
} else if (n_cores != -1) {
LOG(ERROR) << "the number of cpu cores must be positive or -1";
}
if (i >= argc)
HelpInfo_svmtrain();
Expand Down Expand Up @@ -281,12 +279,10 @@ void CMDParser::parse_python(int argc, char **argv) {
HelpInfo_svmtrain();
}
}
if (n_cores == -1) {
omp_set_num_threads(omp_get_num_procs());
} else if (n_cores <= 0) {
LOG(ERROR) << "cores number must bigger than 0";
} else {
if (n_cores > 0) {
omp_set_num_threads(n_cores);
} else if (n_cores != -1) {
LOG(ERROR) << "the number of cpu cores must be positive or -1";
}
if (i > argc)
HelpInfo_svmtrain();
Expand Down
12 changes: 5 additions & 7 deletions src/thundersvm/svm_R_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,13 @@ extern "C" {
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
else
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
if(n_cores[0] == -1){
omp_set_num_threads(omp_get_num_procs());
}
else if(n_cores[0] <= 0){
LOG(ERROR) << "cores number must bigger than 0";
}
else{

if (n_cores[0] > 0) {
omp_set_num_threads(n_cores[0]);
} else if (n_cores[0] != -1) {
LOG(ERROR) << "n_cores must be positive or -1";
}

char input_file_path[1024] = DATASET_DIR;
char model_file_path[1024] = DATASET_DIR;
strcat(input_file_path, "../R/");
Expand Down
22 changes: 10 additions & 12 deletions src/thundersvm/thundersvm-scikit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ extern "C" {
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
else
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
if(n_cores == -1){
omp_set_num_threads(omp_get_num_procs());
}
else if(n_cores <= 0){
LOG(ERROR) << "cores number must bigger than 0";
}
else{

if (n_cores > 0) {
omp_set_num_threads(n_cores);
} else if (n_cores != -1) {
LOG(ERROR) << "n_jobs must be positive or -1";
}

DataSet train_dataset;
Expand Down Expand Up @@ -162,12 +159,13 @@ extern "C" {
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
else
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
if((n_cores <= 0) && (n_cores != -1)){
LOG(ERROR) << "cores number must bigger than 0";
succeed[0] = -1;
}
else

if (n_cores > 0) {
omp_set_num_threads(n_cores);
} else if (n_cores != -1) {
LOG(ERROR) << "n_jobs must be positive or -1";
}

DataSet train_dataset;
train_dataset.load_from_dense(row_size, features, data, label);
// SvmModel* model;
Expand Down

0 comments on commit ef28a78

Please sign in to comment.