[mlpack-git] master: Add OpenMP support to density estimation tree code (fecccd3)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed May 20 11:13:27 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/322deab1ff056e33d4e6aea5f4d0ef9a5b62ab4c...77d750c8fd46140b1d6060424f68768a21c89377
>---------------------------------------------------------------
commit fecccd38d96f24a3c774586a078b4e8e2749b8bd
Author: Janzen Brewer <jahabrewer at gmail.com>
Date: Thu May 14 07:53:25 2015 -0700
Add OpenMP support to density estimation tree code
There are two parts to the OpenMP support. First, cmake was instructed
to compile with compiler-appropriate OpenMP flags. Second, three OpenMP
pragmas were added to dt_utils.cpp to parallelize the cross-validation
loop. No non-pragma code changes were necessary.
>---------------------------------------------------------------
fecccd38d96f24a3c774586a078b4e8e2749b8bd
CMakeLists.txt | 10 +++++-----
src/mlpack/methods/det/dt_utils.cpp | 5 +++++
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7c47aa1..2949dc8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -250,13 +250,13 @@ endif (MSVC)
add_definitions(-DBOOST_TEST_DYN_LINK)
# We require OpenMP now.
-#find_package(OpenMP REQUIRED)
-#if (OPENMP_FOUND)
-# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
-# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
+find_package(OpenMP REQUIRED)
+if (OPENMP_FOUND)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
# ${OpenMP_EXE_LINKER_FLAGS}")
-#endif (OPENMP_FOUND)
+endif (OPENMP_FOUND)
# Create a 'distclean' target in case the user is using an in-source build for
# some reason.
diff --git a/src/mlpack/methods/det/dt_utils.cpp b/src/mlpack/methods/det/dt_utils.cpp
index 273ed98..e1aab34 100644
--- a/src/mlpack/methods/det/dt_utils.cpp
+++ b/src/mlpack/methods/det/dt_utils.cpp
@@ -177,6 +177,9 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
regularizationConstants.resize(prunedSequence.size(), 0);
// Go through each fold.
+ #pragma omp parallel for default(none) \
+ shared(testSize,cvData,prunedSequence,regularizationConstants,dataset) \
+ private(alpha,oldAlpha)
for (size_t fold = 0; fold < folds; fold++)
{
// Break up data into train and test sets.
@@ -228,6 +231,7 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
}
// Update the cv regularization constant.
+ #pragma omp atomic
regularizationConstants[i] += 2.0 * cvVal / (double) dataset.n_cols;
// Determine the new alpha value and prune accordingly.
@@ -245,6 +249,7 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
}
if (prunedSequence.size() > 2)
+ #pragma omp atomic
regularizationConstants[prunedSequence.size() - 2] += 2.0 * cvVal /
(double) dataset.n_cols;
More information about the mlpack-git
mailing list