Skip to content

Commit

Permalink
refactor dataflow init code
Browse files Browse the repository at this point in the history
  • Loading branch information
gentryx committed Jun 29, 2016
1 parent e4e89a6 commit 5449fef
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/parallelization/hpxdataflowsimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,24 @@ class CellComponent

void setupDataflow()
{
std::vector<hpx::shared_future<hpx::id_type> > remoteIDFutures;
std::vector<hpx::future<void> > remoteIDFutures;
remoteIDFutures.reserve(neighbors.size());

for (auto i = neighbors.begin(); i != neighbors.end(); ++i) {
std::string linkName = HPXDataFlowSimulatorHelpers::CellComponent<MessageType, MessageType>::endpointName(
basename, id, *i);

remoteIDFutures << HPXReceiver<MessageType>::find(linkName);
int neighbor = *i;
remoteIDFutures << HPXReceiver<MessageType>::find(linkName).then(
[neighbor, this](hpx::shared_future<hpx::id_type> remoteIDFuture)
{
remoteIDs[neighbor] = remoteIDFuture.get();
});
}

hpx::future<void> res = hpx::when_all(remoteIDFutures).then(
[this](hpx::future<std::vector<hpx::shared_future<hpx::id_type> > > remoteIDReadyFuturesFuture) -> void
{
std::vector<hpx::shared_future<hpx::id_type> > remoteIDReadyFutures = remoteIDReadyFuturesFuture.get();
if (neighbors.size() != remoteIDReadyFutures.size()) {
throw std::logic_error("should have as many neighbors as IDs!");
}

for (std::size_t i = 0; i < neighbors.size(); ++i) {
remoteIDs[neighbors[i]] = remoteIDReadyFutures[i].get();
}
});
// res.get();

res.get();
hpx::when_all(remoteIDFutures).get();
}

// fixme: use move semantics here
Expand Down

0 comments on commit 5449fef

Please sign in to comment.