Skip to content

Commit

Permalink
#2099: Types: Add basic arithmetic operations and use them across cod…
Browse files Browse the repository at this point in the history
…ebase
  • Loading branch information
JacobDomagala committed Dec 29, 2023
1 parent d286a84 commit 2c337ea
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/vt/collective/scatter/scatter.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void Scatter::scatter(
std::size_t const& total_size, std::size_t const& max_proc_size,
FuncSizeType size_fn, FuncDataType data_fn
) {
auto const& num_nodes = theContext()->getNumNodes();
auto const& elm_size = max_proc_size;
auto const& combined_size = num_nodes * elm_size;
auto const num_nodes = theContext()->getNumNodes();
auto const elm_size = max_proc_size;
auto const combined_size = static_cast<size_t>(num_nodes * elm_size);
auto scatter_msg =
makeMessageSz<ScatterMsg>(combined_size, combined_size, elm_size);
vtAssert(total_size == combined_size, "Sizes must be consistent");
Expand Down
2 changes: 1 addition & 1 deletion src/vt/group/region/group_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Range::Range(Range const& in_other, BoundType in_remove_extent)
for (auto split = 0; split < num_splits; split++) {
auto const& child_size = size / num_splits;
auto hi_bound = split == num_splits - 1 ?
hi_ : std::min(static_cast<int>(hi_), cur_lo + child_size*stride_);
hi_ : std::min(hi_, cur_lo + child_size*stride_);
auto r1 = std::make_unique<Range>(cur_lo, BoundType{hi_bound}, stride_);
apply(std::move(r1));
cur_lo += BoundType{child_size*stride_};
Expand Down
83 changes: 83 additions & 0 deletions src/vt/utils/strong/strong_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,89 @@ struct Strong {
return ThisType{v_ / in.v_};
}

/**
* \brief Addition assignment operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType& operator+=(const OtherType& in) {
v_ += static_cast<Type>(in);
return *this;
}

/**
* \brief Division assignment operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType& operator/=(const OtherType& in) {
v_ /= static_cast<Type>(in);
return *this;
}

/**
* \brief Multiplication assignment operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType& operator*=(const OtherType& in) {
v_ *= static_cast<Type>(in);
return *this;
}

/**
* \brief Addition operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType operator+(const OtherType& in) const {
return ThisType{v_ + static_cast<Type>(in)};
}

/**
* \brief Subtraction operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType operator-(const OtherType& in) const {
return ThisType{v_ - static_cast<Type>(in)};
}

/**
* \brief Modulo operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType operator%(const OtherType& in) const {
return ThisType{v_ % static_cast<Type>(in)};
}

/**
* \brief Multiplication operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType operator*(const OtherType& in) const {
return ThisType{v_ * static_cast<Type>(in)};
}

/**
* \brief Division operator
*
* \param[in] in the other value
*/
template <typename OtherType>
ThisType operator/(const OtherType& in) const {
return ThisType{v_ / static_cast<Type>(in)};
}

/**
* \brief Pre-increment operator
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/collection/test_destroy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static constexpr int32_t const num_elms_per_node = 8;

TEST_F(TestDestroy, test_destroy_1) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();
auto const& num_nodes = theContext()->getNumNodes().get();

vt::runInEpochCollective([&]{
if (this_node == vt::NodeT{0}) {
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/collection/test_insert.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static constexpr int32_t const num_elms_per_node = 8;

TEST_F(TestInsert, test_insert_dense_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
auto proxy = vt::makeCollection<InsertTest>("test_insert_dense_1")
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST_F(TestInsert, test_insert_dense_1) {

TEST_F(TestInsert, test_insert_sparse_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node * 16);
auto proxy = vt::makeCollection<InsertTest>("test_insert_sparse_1")
Expand All @@ -158,7 +158,7 @@ TEST_F(TestInsert, test_insert_sparse_1) {

TEST_F(TestInsert, test_insert_dense_node_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
auto proxy = vt::makeCollection<InsertTest>("test_insert_dense_node_1")
Expand All @@ -185,7 +185,7 @@ TEST_F(TestInsert, test_insert_dense_node_1) {

TEST_F(TestInsert, test_insert_sparse_node_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node * 16);
auto proxy = vt::makeCollection<InsertTest>("test_insert_sparse_node_1")
Expand All @@ -212,7 +212,7 @@ TEST_F(TestInsert, test_insert_sparse_node_1) {

TEST_F(TestInsert, test_insert_send_dense_node_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
auto proxy = vt::makeCollection<InsertTest>("test_insert_send_dense_node_1")
Expand Down Expand Up @@ -250,7 +250,7 @@ TEST_F(TestInsert, test_insert_send_dense_node_1) {

TEST_F(TestInsert, test_insert_send_sparse_node_1) {
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node * 16);
auto proxy = vt::makeCollection<InsertTest>("test_insert_send_sparse_node_1")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/collection/test_lb.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct MyCol2 : vt::Collection<MyCol2,vt::Index1D> {};
using TestLoadBalancerNoWork = TestParallelHarness;

TEST_F(TestLoadBalancerNoWork, test_load_balancer_no_work) {
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const range = Index1D(num_nodes * 8);
theCollection()->constructCollective<MyCol2>(
range, [](vt::Index1D) { return std::make_unique<MyCol2>(); },
Expand Down Expand Up @@ -719,8 +719,8 @@ getJsonStringForPhase(
TEST_P(TestDumpUserdefinedData, test_dump_userdefined_json) {
bool should_dump = GetParam();

auto this_node = vt::theContext()->getNode();
auto num_nodes = vt::theContext()->getNumNodes();
auto this_node = vt::theContext()->getNode().get();
auto num_nodes = vt::theContext()->getNumNodes().get();

vt::vrt::collection::CollectionProxy<MyCol> proxy;
auto const range = vt::Index1D(num_nodes * 1);
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/collection/test_list_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TEST_F(TestListInsert, test_bounded_list_insert_1) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
std::vector<Index1D> list_insert;
Expand All @@ -151,7 +151,7 @@ TEST_F(TestListInsert, test_bounded_list_insert_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
std::vector<Index1D> list_insert;
Expand Down Expand Up @@ -192,7 +192,7 @@ TEST_F(TestListInsert, test_unbounded_list_insert_2) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
std::vector<Index1D> list_insert;
Expand All @@ -219,7 +219,7 @@ TEST_F(TestListInsert, test_unbounded_list_insert_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();

auto const range = Index1D(num_nodes * num_elms_per_node);
std::vector<Index1D> list_insert;
Expand Down Expand Up @@ -247,7 +247,7 @@ TEST_F(TestListInsert, test_bounded_list_insert_here_3) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const this_node = theContext()->getNode();
auto const range = Index1D(num_nodes * num_elms_per_node);

Expand Down Expand Up @@ -281,7 +281,7 @@ TEST_F(TestListInsert, test_bounded_list_insert_here_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const this_node = theContext()->getNode();
auto const range = Index1D(num_nodes * num_elms_per_node);

Expand Down Expand Up @@ -314,7 +314,7 @@ TEST_F(TestListInsert, test_unbounded_list_insert_here_4) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const this_node = theContext()->getNode();
auto const range = Index1D(num_nodes * num_elms_per_node);

Expand Down Expand Up @@ -348,7 +348,7 @@ TEST_F(TestListInsert, test_unbounded_list_insert_here_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const this_node = theContext()->getNode();
auto const range = Index1D(num_nodes * num_elms_per_node);

Expand Down Expand Up @@ -426,7 +426,7 @@ TEST_F(TestListInsert, test_bounded_bulk_insert_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const range = Index1D(num_nodes * num_elms_per_node);

auto proxy = vt::makeCollection<NonDefaultConstructibleStruct>("test_bounded_bulk_insert_no_default_constructor")
Expand All @@ -450,7 +450,7 @@ TEST_F(TestListInsert, test_bounded_mix_list_insert_no_default_constructor) {
num_inserted = 0;
num_work = 0;

auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const this_node = theContext()->getNode();
auto const range = Index1D(num_nodes * num_elms_per_node);

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/collection/test_mapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ std::vector<T> kFactors(T n, int8_t k) {
T const orig_n = n;
std::vector<T> factors;
while (n % 2 == 0) {
factors.push_back(2);
factors.push_back(T{2});
n /= 2;
}
for (T i = 3; i*i <= n; i += 2) {
for (T i = T{3}; i*i <= n; i += 2) {
while (n % i == 0) {
factors.push_back(i);
factors.push_back(T{i});
n /= i;
}
}
if (n > 2) {
factors.push_back(n);
factors.push_back(T{n});
}
while (factors.size() < static_cast<std::size_t>(k)) {
factors.push_back(1);
factors.push_back(T{1});
}

std::vector<T> output = factors;
Expand All @@ -133,7 +133,7 @@ std::vector<T> kFactors(T n, int8_t k) {
output = compressed;
}

T total = 1;
T total = T{1};
std::string buf = "";
for (auto&& elm : output) {
buf += fmt::format("{}, ", elm);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/collection/test_query_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TEST_F(TestQueryContext, test_query_context_broadcast_1) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();
if (this_node == vt::NodeT{0}) {
auto const& range = Index1D(num_nodes * num_elms_per_node);
auto const& range = Index1D(num_nodes.get() * num_elms_per_node);
auto proxy = theCollection()->construct<QueryTest>(
range, "test_query_context_broadcast_1"
);
Expand All @@ -88,7 +88,7 @@ TEST_F(TestQueryContext, test_query_context_broadcast_1) {

TEST_F(TestQueryContext, test_query_context_send_1) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();
auto const& num_nodes = theContext()->getNumNodes().get();
if (this_node == vt::NodeT{0}) {
auto const& range = Index1D(num_nodes * num_elms_per_node);
auto proxy = theCollection()->construct<QueryTest>(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/collection/test_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct TestCollectionStorage : TestParallelHarness {
};

TEST_F(TestCollectionStorage, test_collection_storage_1) {
auto const num_nodes = theContext()->getNumNodes();
auto const num_nodes = theContext()->getNumNodes().get();
auto const num_elms = Index1D{num_nodes*16};

using MsgType = typename TestCol::TestMsg;
Expand Down

0 comments on commit 2c337ea

Please sign in to comment.