diff options
author | Arnur Nigmetov <a.nigmetov@gmail.com> | 2018-01-20 19:11:29 +0100 |
---|---|---|
committer | Arnur Nigmetov <a.nigmetov@gmail.com> | 2018-01-20 19:11:29 +0100 |
commit | 0cc35ad04f9c2997014d7cf62a12f697e79fb534 (patch) | |
tree | 744c07bc2c12fba193934ac98417c5063bead189 /geom_matching/wasserstein/include/dnn/parallel | |
parent | 3552ce68bc7654df35da471bd937b09a9fde101f (diff) |
Major rewrite, templatized version
Diffstat (limited to 'geom_matching/wasserstein/include/dnn/parallel')
-rw-r--r-- | geom_matching/wasserstein/include/dnn/parallel/tbb.h | 29 | ||||
-rw-r--r-- | geom_matching/wasserstein/include/dnn/parallel/utils.h | 20 |
2 files changed, 36 insertions, 13 deletions
diff --git a/geom_matching/wasserstein/include/dnn/parallel/tbb.h b/geom_matching/wasserstein/include/dnn/parallel/tbb.h index 64c59e0..3f811d6 100644 --- a/geom_matching/wasserstein/include/dnn/parallel/tbb.h +++ b/geom_matching/wasserstein/include/dnn/parallel/tbb.h @@ -1,7 +1,6 @@ -#ifndef PARALLEL_H -#define PARALLEL_H +#ifndef HERA_WS_PARALLEL_H +#define HERA_WS_PARALLEL_H -//#include <iostream> #include <vector> #include <boost/range.hpp> @@ -18,6 +17,10 @@ #include <boost/serialization/collections_load_imp.hpp> #include <boost/serialization/collections_save_imp.hpp> +namespace hera +{ +namespace ws +{ namespace dnn { using tbb::mutex; @@ -87,7 +90,9 @@ namespace dnn tbb::tick_count start; }; -} +} // dnn +} // ws +} // hera // Serialization for tbb::concurrent_vector<...> namespace boost @@ -132,6 +137,10 @@ namespace boost #include <map> #include <boost/progress.hpp> +namespace hera +{ +namespace ws +{ namespace dnn { template<class T> @@ -207,14 +216,22 @@ namespace dnn }; using boost::progress_timer; -} +} // dnn +} // ws +} // hera #endif // TBB +namespace hera +{ +namespace ws +{ namespace dnn { template<class Range, class F> void do_foreach(const Range& range, const F& f) { do_foreach(boost::begin(range), boost::end(range), f); } -} +} // dnn +} // ws +} // hera #endif diff --git a/geom_matching/wasserstein/include/dnn/parallel/utils.h b/geom_matching/wasserstein/include/dnn/parallel/utils.h index ba73814..7104ec3 100644 --- a/geom_matching/wasserstein/include/dnn/parallel/utils.h +++ b/geom_matching/wasserstein/include/dnn/parallel/utils.h @@ -1,8 +1,12 @@ -#ifndef PARALLEL_UTILS_H -#define PARALLEL_UTILS_H +#ifndef HERA_WS_PARALLEL_UTILS_H +#define HERA_WS_PARALLEL_UTILS_H #include "../utils.h" +namespace hera +{ +namespace ws +{ namespace dnn { // Assumes rng is synchronized across ranks @@ -15,11 +19,13 @@ namespace dnn typedef decltype(data[0]) T; shuffle(world, data, rng, [](T& x, T& y) { std::swap(x,y); }); } -} +} // dnn +} // ws +} // hera template<class DataVector, class RNGType, class SwapFunctor> void -dnn::shuffle(mpi::communicator& world, DataVector& data, RNGType& rng, const SwapFunctor& swap, DataVector empty) +hera::ws::dnn::shuffle(mpi::communicator& world, DataVector& data, RNGType& rng, const SwapFunctor& swap, DataVector empty) { // This is not a perfect shuffle: it dishes out data in chunks of 1/size. // (It can be interpreted as generating a bistochastic matrix by taking the @@ -42,7 +48,7 @@ dnn::shuffle(mpi::communicator& world, DataVector& data, RNGType& rng, const Swa RNGType local_rng(seed); // Shuffle local data - dnn::random_shuffle(data.begin(), data.end(), local_rng, swap); + hera::ws::dnn::random_shuffle(data.begin(), data.end(), local_rng, swap); // Decide how much of our data goes to i-th processor std::vector<size_t> out_counts(size); @@ -50,7 +56,7 @@ dnn::shuffle(mpi::communicator& world, DataVector& data, RNGType& rng, const Swa boost::counting_iterator<int>(size)); for (size_t i = 0; i < size; ++i) { - dnn::random_shuffle(ranks.begin(), ranks.end(), rng); + hera::ws::dnn::random_shuffle(ranks.begin(), ranks.end(), rng); ++out_counts[ranks[rank]]; } @@ -87,7 +93,7 @@ dnn::shuffle(mpi::communicator& world, DataVector& data, RNGType& rng, const Swa for(const DataVector& vec : incoming) for (size_t i = 0; i < vec.size(); ++i) data.push_back(vec[i]); - dnn::random_shuffle(data.begin(), data.end(), local_rng, swap); + hera::ws::dnn::random_shuffle(data.begin(), data.end(), local_rng, swap); // XXX: the final shuffle is irrelevant for our purposes. But it's also cheap. } |