HW2: RC3a - Remove stats optimization
This commit is contained in:
@@ -231,42 +231,6 @@ void elbowSort(ShadowedDataT& data, bool ascending) noexcept {
|
||||
elbowSortCore(data, ascending, std::greater<>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* Predicate for exchange optimization. Returns true only if an exchange between partners is needed.
|
||||
* In order to do that we exchange min and max statistics of the partner's data.
|
||||
*
|
||||
* @tparam StatT Statistics data type (for min-max)
|
||||
*
|
||||
* @param lstat [const StatT] Reference to the local statistic data
|
||||
* @param rstat [StatT] Reference to the remote statistic data to fill
|
||||
* @param part [mpi_id_t] The partner for the exchange
|
||||
* @param tag [int] The tag to use for the exchange of stats
|
||||
* @param keepSmall [bool] Flag to indicate if the local thread keeps the small ro the large values
|
||||
* @return True if we need data exchange, false otherwise
|
||||
*/
|
||||
template<typename StatT>
|
||||
bool needsExchange(const StatT& lstat, StatT& rstat, mpi_id_t part, int tag, bool keepSmall) {
|
||||
timeCall(Texchange, mpi.exchange_it, lstat, rstat, part, tag);
|
||||
return (keepSmall) ?
|
||||
rstat.min < lstat.max // Lmin: rstat.min - Smax: lstat.max
|
||||
: lstat.min < rstat.max; // Lmin: lstat.min - Smax: rstat.max
|
||||
}
|
||||
|
||||
/*!
|
||||
* Update stats utility
|
||||
*
|
||||
* @tparam RangeT A range type with random access iterator
|
||||
* @tparam StatT Statistics data type (for min-max)
|
||||
*
|
||||
* @param stat [StatT] Reference to the statistic data to update
|
||||
* @param data [const RangeT] Reference to the sequence to extract stats from
|
||||
*/
|
||||
template<typename RangeT, typename StatT>
|
||||
void updateMinMax(StatT& stat, const RangeT& data) noexcept {
|
||||
auto [min, max] = std::minmax_element(data.begin(), data.end());
|
||||
stat.min = *min;
|
||||
stat.max = *max;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Takes two sorted sequences where one is in increasing and the other is in decreasing order
|
||||
@@ -311,7 +275,6 @@ template<typename ShadowedDataT>
|
||||
void distBubbletonic(ShadowedDataT& data, mpi_id_t Processes, mpi_id_t rank) {
|
||||
// Initially sort to create a half part of a bitonic sequence
|
||||
timeCall(TfullSort, fullSort, data, ascending<SortMode::Bubbletonic>(rank, 0));
|
||||
updateMinMax(localStat, data);
|
||||
|
||||
// Sort network (O(N) iterations)
|
||||
for (size_t step = 0; step < static_cast<size_t>(Processes); ++step) {
|
||||
@@ -321,20 +284,17 @@ void distBubbletonic(ShadowedDataT& data, mpi_id_t Processes, mpi_id_t rank) {
|
||||
if ( isActive(rank, Processes) &&
|
||||
isActive(part, Processes) ) {
|
||||
// Exchange with partner, keep nim-or-max and sort - O(N)
|
||||
int tag = static_cast<int>(2 * step);
|
||||
if (needsExchange(localStat, remoteStat, part, tag, ks)) {
|
||||
timeCall(Texchange, mpi.exchange_data, data.getActive(), data.getShadow(), part, ++tag);
|
||||
timeCall(Tminmax, keepMinOrMax, data.getActive(), data.getShadow(), ks);
|
||||
updateMinMax(localStat, data);
|
||||
}
|
||||
int tag = static_cast<int>(step);
|
||||
timeCall(Texchange, mpi.exchange_data, data.getActive(), data.getShadow(), part, tag);
|
||||
timeCall(Tminmax, keepMinOrMax, data.getActive(), data.getShadow(), ks);
|
||||
timeCall(TelbowSort, elbowSort, data, ascending<SortMode::Bubbletonic>(rank, Processes));
|
||||
}
|
||||
}
|
||||
|
||||
// Invert if the node was descending.
|
||||
if (!ascending<SortMode::Bubbletonic>(rank, 0))
|
||||
if (!ascending<SortMode::Bubbletonic>(rank, 0)) {
|
||||
elbowSort(data, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +314,6 @@ template<typename ShadowedDataT>
|
||||
void distBitonic(ShadowedDataT& data, mpi_id_t Processes, mpi_id_t rank) {
|
||||
// Initially sort to create a half part of a bitonic sequence
|
||||
timeCall(TfullSort, fullSort, data, ascending<SortMode::Bitonic>(rank, 0));
|
||||
updateMinMax(localStat, data);
|
||||
|
||||
// Run through sort network using elbow-sort ( O(LogN * LogN) iterations )
|
||||
auto p = static_cast<uint32_t>(std::log2(Processes));
|
||||
@@ -365,12 +324,9 @@ void distBitonic(ShadowedDataT& data, mpi_id_t Processes, mpi_id_t rank) {
|
||||
auto part = partner<SortMode::Bitonic>(rank, step);
|
||||
auto ks = keepSmall<SortMode::Bitonic>(rank, part, depth);
|
||||
// Exchange with partner, keep nim-or-max
|
||||
int tag = static_cast<int>( (2*p*depth) + (2*step) );
|
||||
if (needsExchange(localStat, remoteStat, part, tag, ks)) {
|
||||
timeCall(Texchange, mpi.exchange_data, data.getActive(), data.getShadow(), part, tag);
|
||||
timeCall(Tminmax, keepMinOrMax, data.getActive(), data.getShadow(), ks);
|
||||
updateMinMax(localStat, data);
|
||||
}
|
||||
int tag = static_cast<int>( (2*p*depth) + step );
|
||||
timeCall(Texchange, mpi.exchange_data, data.getActive(), data.getShadow(), part, tag);
|
||||
timeCall(Tminmax, keepMinOrMax, data.getActive(), data.getShadow(), ks);
|
||||
}
|
||||
// sort - O(N)
|
||||
timeCall(TelbowSort, elbowSort, data, ascending<SortMode::Bitonic>(rank, depth));
|
||||
|
||||
@@ -17,22 +17,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/*!
|
||||
* Min-Max statistics data for exchange optimization
|
||||
* @tparam Value_t The underlying data type of the sequence data
|
||||
*/
|
||||
template <typename Value_t>
|
||||
struct Stat_t {
|
||||
using value_type = Value_t; //!< meta-export the type
|
||||
|
||||
Value_t min{}; //!< The minimum value of the sequence
|
||||
Value_t max{}; //!< The maximum value of the sequence
|
||||
};
|
||||
|
||||
//! Application data selection alias
|
||||
using distStat_t = Stat_t<distValue_t>;
|
||||
extern distStat_t localStat, remoteStat; // Make stats public
|
||||
|
||||
/*
|
||||
* MPI_<type> dispatcher mechanism
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user