Skip to content

Commit

Permalink
#1554: examples: enhance for collection NOMERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Oct 14, 2021
1 parent e5d03df commit 38454f4
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion examples/hello_world/hello_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ struct HelloMsg : vt::Message {
vt::DataRepIDType handle_id_ = vt::no_datarep;
};

struct MyCol : vt::Collection<MyCol, vt::Index2D> {
MyCol() {
auto proxy = getCollectionProxy();
auto idx = getIndex();
vt_print(gen, "MyCol: {}\n", idx);
test_dr = vt::theDR()->makeIndexedHandle<std::vector<double>>(proxy[idx]);
test_dr.publish(0, std::vector<double>{10.2, 32.4, 22.3 + idx.x() * idx.y()});
}

using TestMsg = vt::CollectionMessage<MyCol>;

void doWork(TestMsg* msg) {
auto proxy = getCollectionProxy();
auto idx = getIndex();
vt_print(gen, "Hello from {}\n", idx);
vt::datarep::Reader<std::vector<double>, vt::Index2D> reader;
auto idx_x = (idx.x() + 1) % 8;
reader = vt::theDR()->makeIndexedReader<std::vector<double>>(proxy(idx_x, idx.y()));
reader.fetch(0);
vt::theSched()->runSchedulerWhile([&]{ return not reader.isReady(); });
auto const& vec = reader.get(0);
for (auto&& elm : *vec) {
vt_print(gen, "idx={}, elm={}\n", idx, elm);
}
}

vt::datarep::DR<std::vector<double>, vt::Index2D> test_dr;
};

static void hello_world(HelloMsg* msg) {
vt::NodeType this_node = vt::theContext()->getNode();
fmt::print("{}: Hello from node {} (start)\n", this_node, msg->from);
Expand All @@ -78,12 +107,22 @@ int main(int argc, char** argv) {
return vt::rerror("requires at least 2 nodes");
}

auto range = vt::Index2D(8, 1);
auto proxy = vt::makeCollection<MyCol>()
.bounds(range)
.bulkInsert()
.wait();

proxy.broadcastCollective<MyCol::TestMsg,&MyCol::doWork>();

if (this_node == 0) {
std::vector<double> my_vec;
for (int i = 0; i < 10; i++) {
my_vec.push_back(i*10);
}
auto my_dr = vt::theDR()->makeHandle(0, std::move(my_vec));
auto my_dr = vt::theDR()->makeHandle<std::vector<double>>();
my_dr.publish(0, std::move(my_vec));

auto msg = vt::makeMessage<HelloMsg>(this_node, my_dr.getHandleID());
vt::theMsg()->broadcastMsg<HelloMsg, hello_world>(msg);
}
Expand Down

0 comments on commit 38454f4

Please sign in to comment.