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

1507 context td #1508

Merged
merged 7 commits into from
Jul 22, 2021
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions src/vt/context/runnable_context/td.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,52 @@ TD::TD(EpochType in_ep)

void TD::begin() {
theMsg()->pushEpoch(ep_);
epoch_stack_size_ = theMsg()->getEpochStack().size();
}

void TD::end() {
auto& epoch_stack = theMsg()->getEpochStack();

vt_debug_print(
verbose, context,
"TD::end: top={:x}, size={}\n",
"TD::begin: top={:x}, size={}\n",
epoch_stack.size() > 0 ? epoch_stack.top(): no_epoch,
epoch_stack.size()
);

vtAssertNot(
epoch_stack_size_ < epoch_stack.size(),
"Epoch stack popped below preceding push size in handler"
base_epoch_stack_size_ = epoch_stack.size();
}

void TD::end() {
auto& epoch_stack = theMsg()->getEpochStack();

vt_debug_print(
verbose, context,
"TD::end: top={:x}, size={}, base_size={}\n",
epoch_stack.size() > 0 ? epoch_stack.top(): no_epoch,
epoch_stack.size(), base_epoch_stack_size_
);

vtAssert(
epoch_stack_size_ == epoch_stack.size(), "Stack must be same size"
base_epoch_stack_size_ <= epoch_stack.size(),
"Epoch stack popped below preceding push size in handler"
);

vtAssertNotExpr(epoch_stack.size() == 0);

while (epoch_stack.size() > epoch_stack_size_) {
while (epoch_stack.size() > base_epoch_stack_size_) {
theMsg()->popEpoch();
}

vtAssertExpr(epoch_stack.size() == epoch_stack_size_);

theMsg()->popEpoch(ep_);
}

void TD::suspend() {
auto& epoch_stack = theMsg()->getEpochStack();

while (epoch_stack.size() > epoch_stack_size_) {
vt_debug_print(
verbose, context,
"TD::suspend: top={:x}, size={}, base_size={}\n",
epoch_stack.size() > 0 ? epoch_stack.top(): no_epoch,
epoch_stack.size(), base_epoch_stack_size_
);

while (epoch_stack.size() > base_epoch_stack_size_) {
suspended_epochs_.push_back(theMsg()->getEpoch());
theMsg()->popEpoch();
}
Expand All @@ -108,13 +117,25 @@ void TD::suspend() {
}

void TD::resume() {
auto const sz = suspended_epochs_.size();
for (std::size_t i = 0; i < sz; i++) {
theMsg()->pushEpoch(suspended_epochs_[sz - i - 1]);
theMsg()->pushEpoch(ep_);

auto& epoch_stack = theMsg()->getEpochStack();
base_epoch_stack_size_ = epoch_stack.size();

vt_debug_print(
verbose, context,
"TD::resume: top={:x}, size={}, base_size={}\n",
epoch_stack.size() > 0 ? epoch_stack.top(): no_epoch,
epoch_stack.size(), base_epoch_stack_size_
);

for (auto it = suspended_epochs_.rbegin();
it != suspended_epochs_.rend();
++it) {
theMsg()->pushEpoch(*it);
}
suspended_epochs_.clear();

theMsg()->pushEpoch(ep_);
suspended_epochs_.clear();
}

}} /* end namespace vt::ctx */
2 changes: 1 addition & 1 deletion src/vt/context/runnable_context/td.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct TD final : Base {

private:
EpochType ep_ = no_epoch; /**< The epoch for the task */
std::size_t epoch_stack_size_ = 0; /**< Epoch stack size at start */
std::size_t base_epoch_stack_size_ = 0; /**< Epoch stack size at start */
std::vector<EpochType> suspended_epochs_; /**< Suspended epoch stack */
};

Expand Down
1 change: 1 addition & 0 deletions tests/unit/active/test_async_op_threads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <vt/messaging/async_op_mpi.h>
#include <vt/messaging/active.h>
#include <vt/objgroup/headers.h>

#include <gtest/gtest.h>

Expand Down