Skip to content

Commit

Permalink
Lift color space size restriction. (#115)
Browse files Browse the repository at this point in the history
Now we allow for more colors than number of pieces for a split.
qvi_scope_ksplit() is getting closer to the semantics we need.

Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Apr 24, 2024
1 parent a25e8db commit ae5333f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/qvi-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <chrono>
#include <map>
#include <new>
#include <numeric>
#include <set>
#include <stack>
#include <stdexcept>
Expand Down
26 changes: 5 additions & 21 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -963,30 +963,14 @@ agg_split_affinity_preserving(
}

/**
* Takes a vector of colors and clamps their values to [0, max) in place. If
* this function finds more colors than slots available from [0, max), then it
* returns an error code.
* Takes a vector of colors and clamps their values to [0, values.size()) in
* place.
*/
// TODO(skg) Lift size restriction.
static int
clamp_colors(
std::vector<int> &values,
uint_t max
std::vector<int> &values
) {
// Recall: sets are ordered.
std::set<int> valset(values.begin(), values.end());
// Too many colors for the given space.
if (valset.size() > max) return QV_ERR_INVLD_ARG;
// Maps the input vector colors to their clamped values.
std::map<int, int> colors2clamped;
// color': the clamped color.
int colorp = 0;
for (auto val : valset) {
colors2clamped.insert({val, colorp++});
}
for (uint_t i = 0; i < values.size(); ++i) {
values[i] = colors2clamped[values[i]];
}
std::iota(values.begin(), values.end(), 0);
return QV_SUCCESS;
}

Expand Down Expand Up @@ -1019,7 +1003,7 @@ agg_split(

// All colors are positive.
if (tcolors.front() >= 0) {
rc = clamp_colors(splitagg.colors, splitagg.split_size);
rc = clamp_colors(splitagg.colors);
if (rc != QV_SUCCESS) return rc;
}
// Some values are negative.
Expand Down
2 changes: 1 addition & 1 deletion tests/test-mpi-scope-ksplit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ main(void)

// Test internal APIs
const int npieces = ncores / 2;
std::vector<int> colors(npieces);
std::vector<int> colors(npieces * 2);
std::iota(colors.begin(), colors.end(), 0);

qv_scope_t **subscopes = nullptr;
Expand Down

0 comments on commit ae5333f

Please sign in to comment.