From 31465ac0c97612f9079843eefdfd395ea9badb0d Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Sat, 4 Dec 2010 04:03:10 +0000 Subject: [PATCH] Starting on the distributed kde driver. --- .../mlpack/distributed_kde/distributed_kde.cc | 5 +- .../mlpack/distributed_kde/distributed_kde.h | 46 ++++++++-------- .../distributed_kde/distributed_kde_dev.h | 55 ++++++++++--------- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc index 872697aad1..9b1c95ffd5 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc +++ b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc @@ -12,6 +12,7 @@ #include "core/tree/gen_kdtree.h" #include "core/tree/gen_metric_tree.h" #include "mlpack/kde/kde_dualtree.h" +#include "mlpack/distributed_kde/distributed_kde_dev.h" typedef core::tree::GenMetricTree TreeSpecType; typedef core::tree::GeneralBinarySpaceTree < TreeSpecType > TreeType; @@ -22,12 +23,14 @@ void Compute( // Each process does the work owned by itself. + // This is the exchange loop. do { // Each process grabs the necessary work. This is the exchange // phase. + // Each process computes. } @@ -87,7 +90,7 @@ int main(int argc, char *argv[]) { // Initialize the memory allocator. core::table::global_m_file_ = new core::table::MemoryMappedFile(); core::table::global_m_file_->Init( - std::string("tmp_file"), world.rank(), world.rank(), 50000000); + std::string("tmp_file"), world.rank(), world.rank(), 5000000); // Seed the random number. srand(time(NULL) + world.rank()); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.h b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.h index 688c3d9f7f..a95d3ad694 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.h @@ -6,31 +6,31 @@ #ifndef MLPACK_DISTRIBUTED_KDE_DISTRIBUTED_KDE_H #define MLPACK_DISTRIBUTED_KDE_DISTRIBUTED_KDE_H -#include -#include "boost/program_options.hpp" - -#include "core/table/table.h" -#include "kde_dualtree.h" -#include "kde_arguments.h" +#include +#include "core/table/distributed_table.h" +#include "mlpack/kde/kde_dualtree.h" +#include "mlpack/kde/kde_arguments.h" namespace mlpack { -namespace kde { -template +namespace distributed_kde { +template class DistributedKde { public: - typedef IncomingTableType TableType; + typedef core::table::Table TableType; - typedef ml::KdePostponed PostponedType; + typedef core::table::DistributedTable DistributedTableType; - typedef ml::KdeGlobal GlobalType; + typedef mlpack::kde::::KdePostponed PostponedType; - typedef ml::KdeResult< std::vector > ResultType; + typedef mlpack::kde::KdeGlobal GlobalType; - typedef ml::KdeDelta DeltaType; + typedef mlpack::kde::KdeResult< std::vector > ResultType; - typedef ml::KdeSummary SummaryType; + typedef mlpack::kde::KdeDelta DeltaType; - typedef ml::KdeStatistic StatisticType; + typedef mlpack::kde::KdeSummary SummaryType; + + typedef mlpack::kde::KdeStatistic StatisticType; public: @@ -42,12 +42,12 @@ class DistributedKde { /** * @brief returns a pointer to the query table */ - TableType *query_table(); + core::table::DistributedTable *query_table(); /** * @brief returns a pointer to the reference table */ - TableType *reference_table(); + core::table::DistributedTable *reference_table(); /** * @brief returns a GlobalType structure that has the normalization statistics @@ -63,25 +63,25 @@ class DistributedKde { /** * @brief Initialize a Kde engine with the arguments. */ - void Init(ml::KdeArguments &arguments_in); + void Init(mlpack::kde::KdeArguments &arguments_in); void Compute( - const ml::KdeArguments &arguments_in, + const mlpack::kde::KdeArguments &arguments_in, ResultType *result_out); static void ParseArguments( const std::vector &args, - ml::KdeArguments *arguments_out); + mlpack::kde::KdeArguments *arguments_out); static void ParseArguments( int argc, char *argv[], - ml::KdeArguments *arguments_out); + mlpack::kde::KdeArguments *arguments_out); private: - TableType *query_table_; - TableType *reference_table_; + DistributedTableType *query_table_; + DistributedTableType *reference_table_; GlobalType global_; bool is_monochromatic_; diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde_dev.h b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde_dev.h index a443fea513..378f621166 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde_dev.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde_dev.h @@ -8,43 +8,45 @@ #include "core/gnp/dualtree_dfs_dev.h" #include "core/metric_kernels/lmetric.h" -#include "distributed_kde.h" +#include "mlpack/distributed_kde/distributed_kde.h" -template -TableType *mlpack::DistributedKde::query_table() { +template +TableType *mlpack::distributed_kde::DistributedKde::query_table() { return query_table_; } -template -TableType *mlpack::DistributedKde::reference_table() { +template +TableType *mlpack::distributed_kde::DistributedKde::reference_table() { return reference_table_; } -template -typename mlpack::DistributedKde::GlobalType &mlpack::DistributedKde::global() { +template +typename mlpack::distributed_kde::DistributedKde::GlobalType & +mlpack::distributed_kde::DistributedKde::global() { return global_; } -template -bool mlpack::DistributedKde::is_monochromatic() const { +template +bool mlpack::distributed_kde::DistributedKde::is_monochromatic() const { return is_monochromatic_; } -template -void mlpack::DistributedKde::Compute( - const mlpack::DistributedKdeArguments &arguments_in, - mlpack::DistributedKdeResult< std::vector > *result_out) { +template +void mlpack::distributed_kde::DistributedKde::Compute( + const mlpack::distributed_kde::DistributedKdeArguments &arguments_in, + mlpack::distributed_kde::DistributedKdeResult< std::vector > *result_out) { // Instantiate a dual-tree algorithm of the KDE. - core::gnp::DualtreeDfs > dualtree_dfs; + core::gnp::DualtreeDfs > dualtree_dfs; dualtree_dfs.Init(*this); // Compute the result. dualtree_dfs.Compute(* arguments_in.metric_, result_out); } -template -void mlpack::DistributedKde::Init(mlpack::DistributedKdeArguments &arguments_in) { +template +void mlpack::distributed_kde::DistributedKde::Init( + mlpack::distributed_kde::DistributedKdeArguments &arguments_in) { reference_table_ = arguments_in.reference_table_; if(arguments_in.query_table_ == NULL) { @@ -63,13 +65,14 @@ void mlpack::DistributedKde::Init(mlpack::DistributedKdeArguments -void mlpack::DistributedKde::set_bandwidth(double bandwidth_in) { +template +void mlpack::distributed_kde::DistributedKde::set_bandwidth( + double bandwidth_in) { global_.set_bandwidth(bandwidth_in); } -template -bool mlpack::DistributedKde::ConstructBoostVariableMap_( +template +bool mlpack::distributed_kde::DistributedKde::ConstructBoostVariableMap_( const std::vector &args, boost::program_options::variables_map *vm) { @@ -175,10 +178,10 @@ bool mlpack::DistributedKde::ConstructBoostVariableMap_( return false; } -template -void mlpack::DistributedKde::ParseArguments( +template +void mlpack::distributed_kde::DistributedKde::ParseArguments( const std::vector &args, - mlpack::DistributedKdeArguments *arguments_out) { + mlpack::distributed_kde::DistributedKdeArguments *arguments_out) { // A L2 metric to index the table to use. arguments_out->metric_ = new core::metric_kernels::LMetric<2>(); @@ -238,11 +241,11 @@ void mlpack::DistributedKde::ParseArguments( std::cout << "Using the kernel: " << arguments_out->kernel_ << "\n"; } -template -void mlpack::DistributedKde::ParseArguments( +template +void mlpack::distributed_kde::DistributedKde::ParseArguments( int argc, char *argv[], - mlpack::DistributedKdeArguments *arguments_out) { + mlpack::distributed_kde::DistributedKdeArguments *arguments_out) { // Convert C input to C++; skip executable name for Boost. std::vector args(argv + 1, argv + argc);