Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2099: Make NodeType a strong type and use it across the codebase #2139

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 6 additions & 6 deletions docs/md/active-messenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,35 @@ struct MyMsg : vt::Message {

// Active function pointer
void myHandler(MyMsg* m) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeT this_node = vt::theContext()->getNode();
fmt::print("{}: val={}, vec size={}\n", this_node, m->val, m->my_vec.size());
}

// Active functor
struct MyFunctor {
void operator()(MyMsg* m) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeT this_node = vt::theContext()->getNode();
fmt::print("{}: val={}, vec size={}\n", this_node, m->val, m->my_vec.size());
}
};

int main(int argc, char** argv) {
vt::initialize(argc, argv);

vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeT this_node = vt::theContext()->getNode();

if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
// spins in scheduler until termination of the enclosed work
vt::runInEpochRooted([=]{
std::vector<double> vec_to_send;
vec_to_send.push_back(29.);
vec_to_send.push_back(54.);

auto msg = vt::makeMessage<MyMsg>(10, vec_to_send);
vt::theMsg()->sendMsg<MyMsg, myHandler>(1, msg); // send to node 1
vt::theMsg()->sendMsg<MyMsg, myHandler>(vt::NodeT{1}, msg); // send to node 1

auto msg2 = vt::makeMessage<MyMsg>(11, vec_to_send);
vt::theMsg()->sendMsg<MyFunctor>(1, msg2); // send to node 1
vt::theMsg()->sendMsg<MyFunctor>(vt::NodeT{1}, msg2); // send to node 1
});
}

Expand Down
10 changes: 5 additions & 5 deletions docs/md/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template argument to `.mapperFunc<my_map>()`, where `my_map` has the following
definition (shown for a 1-dimensional collection):

\code{.cpp}
vt::NodeType my_map(vt::Index1D* idx, vt::Index1D* bounds, vt::NodeType num_nodes) {
vt::NodeT my_map(vt::Index1D* idx, vt::Index1D* bounds, vt::NodeT num_nodes) {
return idx->x() % num_nodes;
}
\endcode
Expand All @@ -85,7 +85,7 @@ group instance that already exists by passing the proxy to it. Otherwise, one
may just give the type and constructor arguments to create a new instance:
`.mapperObjGroupConstruct<MyObjectGroup>(args...)`. An object group mapper must
inherit from `vt::mapping::BaseMapper` and implement the pure virtual method
`NodeType map(IdxT* idx, int ndim, NodeType num_nodes)` to define the mapping
`NodeT map(IdxT* idx, int ndim, NodeT num_nodes)` to define the mapping
for the runtime. As an example, the object group mapper used by default for
unbounded collections is implemented as follows:

Expand All @@ -97,7 +97,7 @@ struct UnboundedDefaultMap : vt::mapping::BaseMapper<IdxT> {
return proxy.getProxy();
}

NodeType map(IdxT* idx, int ndim, NodeType num_nodes) override {
NodeT map(IdxT* idx, int ndim, NodeT num_nodes) override {
typename IdxT::DenseIndexType val = 0;
for (int i = 0; i < ndim; i++) {
val ^= idx->get(i);
Expand Down Expand Up @@ -157,8 +157,8 @@ collective interface):
auto range = vt::Index1D(num_elms);
auto token = proxy.beginModification();
for (int i = 0; i < range.x() / 2; i++) {
if (i % num_nodes == this_node) {
proxy[i].insertAt(token, i % 2);
if (vt::NodeT{i} % num_nodes == this_node) {
proxy[i].insertAt(token, vt::NodeT{i % 2});
}
}
proxy.finishModification(std::move(token));
Expand Down
2 changes: 1 addition & 1 deletion docs/md/collective.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char** argv) {

auto reduce_msg = vt::makeMessage<ReduceDataMsg>(50);

NodeType const root_reduce_node = 0;
NodeT const root_reduce_node = 0;
vt::theCollective()->global()->reduce<vt::collective::PlusOp<int>,ReduceResult>(
root_reduce_node, reduce_msg.get()
);
Expand Down
4 changes: 2 additions & 2 deletions docs/md/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provides the MPI communicator that an instance of \vt is currently using.
To get the current node, one may query this method:

\code{.cpp}
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeT this_node = vt::theContext()->getNode();
\endcode

\subsection get-num-nodes Number of nodes/ranks
Expand All @@ -29,7 +29,7 @@ To get the number of nodes or ranks that an instance of \vt is using, one may
query this method:

\code{.cpp}
vt::NodeType num_nodes = vt::theContext()->getNumNodes();
vt::NodeT num_nodes = vt::theContext()->getNumNodes();
\endcode

\note The result from \c getNode or \c getNumNodes will depend on the
Expand Down
12 changes: 6 additions & 6 deletions docs/md/vt.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ management.
bool done = false;

struct HelloMsg : vt::Message {
HelloMsg(vt::NodeType in_from) : from(in_from) { }
vt::NodeType from = 0;
HelloMsg(vt::NodeT in_from) : from(in_from) { }
vt::NodeT from = 0;
};

void hello_world(HelloMsg* msg) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeT this_node = vt::theContext()->getNode();
fmt::print("{}: Hello from node {}\n", this_node, msg->from);
done = true;
}

int main(int argc, char** argv) {
vt::initialize(argc, arv);

vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeType num_nodes = vt::theContext()->getNumNodes();
vt::NodeT this_node = vt::theContext()->getNode();
vt::NodeT num_nodes = vt::theContext()->getNumNodes();

if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
auto msg = vt::makeMessage<HelloMsg>(this_node);
vt::theMsg()->broadcastMsg<HelloMsg, hello_world>(msg);
done = true;
Expand Down
14 changes: 7 additions & 7 deletions examples/callback/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void hello_world(HelloMsg* msg) {
}

void printOutput(TestMsg* msg, std::string type) {
vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();
fmt::print("{}: cb {}: val={}, str={}\n", this_node, type, msg->val_, msg->s_);
}

Expand Down Expand Up @@ -116,16 +116,16 @@ void colHan(MyCol* col, TestMsg* msg) {

void bounceCallback(vt::Callback<TestMsg> cb) {
auto msg = vt::makeMessage<HelloMsg>(cb);
vt::theMsg()->sendMsg<hello_world>(1, msg);
vt::theMsg()->sendMsg<hello_world>(vt::NodeT{1}, msg);
}

int main(int argc, char** argv) {
vt::initialize(argc, argv);

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

if (num_nodes == 1) {
if (num_nodes == vt::NodeT{1}) {
return vt::rerror("requires at least 2 nodes");
}

Expand All @@ -135,8 +135,8 @@ int main(int argc, char** argv) {
.bulkInsert()
.wait();

if (this_node == 0) {
vt::NodeType dest = num_nodes > 2 ? 2 : 0;
if (this_node == vt::NodeT{0}) {
vt::NodeT dest = num_nodes > vt::NodeT{2} ? vt::NodeT{2} : vt::NodeT{0};

auto cb_functor = vt::theCB()->makeSend<CallbackFunctor>(dest);
bounceCallback(cb_functor);
Expand Down
2 changes: 1 addition & 1 deletion examples/callback/callback_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main(int argc, char** argv) {
return 0;
}

vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();

if (this_node == 0) {
my_global_ctx.x = 1283;
Expand Down
14 changes: 7 additions & 7 deletions examples/collection/insertable_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static constexpr int32_t const default_num_elms = 64;

struct InsertCol : vt::Collection<InsertCol, vt::Index1D> {
InsertCol() {
vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();
::fmt::print("{}: constructing: idx={}\n", this_node, getIndex().x());
}
};
Expand All @@ -60,8 +60,8 @@ int main(int argc, char** argv) {
return 0;
}

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

int32_t num_elms = default_num_elms;
if (argc > 1) {
Expand All @@ -77,8 +77,8 @@ int main(int argc, char** argv) {
auto token = proxy.beginModification();

for (int i = 0; i < range.x() / 2; i++) {
if (i % num_nodes == this_node) {
proxy[i].insertAt(token, i % 2);
if (vt::NodeT{i} % num_nodes == this_node) {
proxy[i].insertAt(token, vt::NodeT{i % 2});
}
}

Expand All @@ -90,8 +90,8 @@ int main(int argc, char** argv) {
auto token = proxy.beginModification();

for (int i = range.x()/2; i < range.x(); i++) {
if (i % num_nodes == this_node) {
proxy[i].insertAt(token, i % 2);
if (vt::NodeT{i} % num_nodes == this_node) {
proxy[i].insertAt(token, vt::NodeT{i % 2});
}
}
proxy.finishModification(std::move(token));
Expand Down
6 changes: 3 additions & 3 deletions examples/collection/jacobi1d_vt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ int main(int argc, char** argv) {

vt::initialize(argc, argv);

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

if (argc == 1) {
if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print(
stderr, "{}: using default arguments since none provided\n", name
);
Expand Down
6 changes: 3 additions & 3 deletions examples/collection/jacobi2d_vt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ int main(int argc, char** argv) {

vt::initialize(argc, argv);

vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();

if (argc == 1) {
if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print(
stderr, "{}: using default arguments since none provided\n", name
);
Expand All @@ -458,7 +458,7 @@ int main(int argc, char** argv) {

/* --- Print information about the simulation */

if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print(
stdout, "\n - Solve the linear system for the Laplacian with homogeneous Dirichlet"
" on [0, 1] x [0, 1]\n"
Expand Down
6 changes: 3 additions & 3 deletions examples/collection/lb_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ int main(int argc, char** argv) {
num_iter = atoi(argv[3]);
}

vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();

if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print(
"lb_iter: elms={}, weight={}, num_iter={}\n",
num_elms, weight, num_iter
Expand All @@ -126,7 +126,7 @@ int main(int argc, char** argv) {
});

auto total_time = vt::timing::getCurrentTime() - cur_time;
if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print("iteration: iter={},time={}\n", i, total_time);
}

Expand Down
18 changes: 9 additions & 9 deletions examples/collection/migrate_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static constexpr int32_t const default_num_elms = 16;
struct Hello : vt::Collection<Hello, vt::Index1D> {

Hello() {
vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();
fmt::print("{}: Hello: index={}\n", this_node, getIndex());
test_val = getIndex().x() * 29.3;
}
Expand All @@ -66,14 +66,14 @@ struct Hello : vt::Collection<Hello, vt::Index1D> {
};

static void doWork(Hello* col) {
vt::NodeType this_node = vt::theContext()->getNode();
auto this_node = vt::theContext()->getNode();
fmt::print("{}: idx={}: val={}\n", this_node, col->getIndex(), col->test_val);
}

static void migrateToNext(Hello* col) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeType num_nodes = vt::theContext()->getNumNodes();
vt::NodeType next_node = (this_node + 1) % num_nodes;
auto this_node = vt::theContext()->getNode();
auto num_nodes = vt::theContext()->getNumNodes();
auto next_node = (this_node + 1) % num_nodes;

fmt::print("{}: migrateToNext: idx={}\n", this_node, col->getIndex());
col->migrate(next_node);
Expand All @@ -82,10 +82,10 @@ static void migrateToNext(Hello* col) {
int main(int argc, char** argv) {
vt::initialize(argc, argv);

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

if (num_nodes == 1) {
if (num_nodes == vt::NodeT{1}) {
return vt::rerror("requires at least 2 nodes");
}

Expand All @@ -100,7 +100,7 @@ int main(int argc, char** argv) {
.bulkInsert()
.wait();

if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
vt::runInEpochRooted([=] { proxy.broadcast<doWork>(); });
vt::runInEpochRooted([=] { proxy.broadcast<migrateToNext>(); });
vt::runInEpochRooted([=] { proxy.broadcast<doWork>(); });
Expand Down
10 changes: 5 additions & 5 deletions examples/collection/polymorphic_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ void Hello::doWork() {


static void migrateToNext(Hello* col) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeType num_nodes = vt::theContext()->getNumNodes();
vt::NodeType next_node = (this_node + 1) % num_nodes;
auto this_node = vt::theContext()->getNode();
auto num_nodes = vt::theContext()->getNumNodes();
auto const next_node = (this_node + 1) % num_nodes;

fmt::print("{}: migrateToNext: idx={}\n", this_node, col->getIndex());
col->migrate(next_node);
Expand All @@ -150,8 +150,8 @@ static void migrateToNext(Hello* col) {
int main(int argc, char** argv) {
vt::initialize(argc, argv);

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

auto num_elms = std::max(static_cast<int32_t>(num_nodes), default_num_elms);

Expand Down
8 changes: 4 additions & 4 deletions examples/collection/reduce_integral.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
static constexpr std::size_t const default_nparts_object = 8;
static constexpr std::size_t const default_num_objs = 4;
static constexpr std::size_t const verbose = 1;
static constexpr vt::NodeType const reduce_root_node = 0;
static constexpr vt::NodeT const reduce_root_node = vt::NodeT{0};

static bool root_reduce_finished = false;
static double exactIntegral = 0.0;
Expand Down Expand Up @@ -190,11 +190,11 @@ int main(int argc, char** argv) {

vt::initialize(argc, argv);

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

if (argc == 1) {
if (this_node == 0) {
if (this_node == vt::NodeT{0}) {
fmt::print(
stderr, "{}: using default arguments since none provided\n", name
);
Expand Down
Loading
Loading