Skip to content

Commit

Permalink
#1941: remove Epoch Stack from ActiveMessenger
Browse files Browse the repository at this point in the history
  • Loading branch information
stmcgovern committed Sep 20, 2022
1 parent 53f206d commit acf44fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 112 deletions.
48 changes: 12 additions & 36 deletions src/vt/context/runnable_context/td.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,77 +62,53 @@ TD::TD(EpochType in_ep)
}

void TD::begin() {
theMsg()->pushEpoch(ep_);
theTerm()->pushEpoch(ep_);

auto& epoch_stack = theMsg()->getEpochStack();
auto& epoch_stack = theTerm()->getEpochStack();

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

base_epoch_stack_size_ = epoch_stack.size();
}

void TD::end() {
auto& epoch_stack = theMsg()->getEpochStack();
auto& epoch_stack = theTerm()->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(
base_epoch_stack_size_ <= epoch_stack.size(),
"Epoch stack popped below preceding push size in handler"
);

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

theMsg()->popEpoch(ep_);
theTerm()->popEpoch(ep_);
}

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

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();
suspended_epochs_.push_back(theTerm()->getEpoch());
theTerm()->popEpoch();
}

theMsg()->popEpoch(ep_);
theTerm()->popEpoch(ep_);
}

void TD::resume() {
theMsg()->pushEpoch(ep_);
theTerm()->pushEpoch(ep_);

auto& epoch_stack = theMsg()->getEpochStack();
auto& epoch_stack = theTerm()->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);
theTerm()->pushEpoch(*it);
}

suspended_epochs_.clear();
Expand Down
17 changes: 3 additions & 14 deletions src/vt/messaging/active.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void ActiveMessenger::initialize() {
}

void ActiveMessenger::startup() {
pushEpoch(term::any_epoch_sentinel);

auto const this_node = theContext()->getNode();
bare_handler_dummy_elm_id_for_lb_data_ =
elm::ElmIDBits::createBareHandler(this_node);
Expand All @@ -171,20 +173,7 @@ void ActiveMessenger::startup() {
#endif
}

/*virtual*/ ActiveMessenger::~ActiveMessenger() {
// Pop all extraneous epochs off the stack greater than 1
auto stack_size = epoch_stack_.size();
while (stack_size > 1) {
stack_size = (epoch_stack_.pop(), epoch_stack_.size());
}
// Pop off the last epoch: term::any_epoch_sentinel
auto const ret_epoch = popEpoch(term::any_epoch_sentinel);
vtAssertInfo(
ret_epoch == term::any_epoch_sentinel, "Last pop must be any epoch",
ret_epoch, term::any_epoch_sentinel, epoch_stack_.size()
);
vtAssertExpr(epoch_stack_.size() == 0);
}
/*virtual*/ ActiveMessenger::~ActiveMessenger() {};

trace::TraceEventIDType ActiveMessenger::makeTraceCreationSend(
HandlerType const handler, ByteType serialized_msg_size, bool is_bcast
Expand Down
20 changes: 0 additions & 20 deletions src/vt/messaging/active.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ struct ActiveMessenger : runtime::component::PollableComponent<ActiveMessenger>
using ReadyHanTagType = std::tuple<HandlerType, TagType>;
using MaybeReadyType = std::vector<ReadyHanTagType>;
using HandlerManagerType = HandlerManager;
using EpochStackType = std::stack<EpochType>;
using PendingSendType = PendingSend;

/**
Expand Down Expand Up @@ -1516,17 +1515,6 @@ struct ActiveMessenger : runtime::component::PollableComponent<ActiveMessenger>
MsgSizeType const& msg_size, TagType const& send_tag
);

/**
* \internal
* \brief Get the current global epoch
*
* \c Returns the top epoch on the stack iff \c epoch_stack.size() > 0, else it
* returns \c vt::no_epoch
*
* \return the current global epoch
*/
inline EpochType getGlobalEpoch() const;

/**
* \internal
* \brief Push an epoch on the stack
Expand Down Expand Up @@ -1563,12 +1551,6 @@ struct ActiveMessenger : runtime::component::PollableComponent<ActiveMessenger>
*/
inline EpochType getEpoch() const;

/**
* \internal
* \brief Access the epoch stack
*/
inline EpochStackType& getEpochStack() { return epoch_stack_; }

/**
* \internal
* \brief Get the epoch for a message based on the current context so an
Expand Down Expand Up @@ -1644,7 +1626,6 @@ struct ActiveMessenger : runtime::component::PollableComponent<ActiveMessenger>
| pending_handler_msgs_
| pending_recvs_
| cur_direct_buffer_tag_
| epoch_stack_
| in_progress_active_msg_irecv
| in_progress_data_irecv
| in_progress_ops
Expand Down Expand Up @@ -1755,7 +1736,6 @@ struct ActiveMessenger : runtime::component::PollableComponent<ActiveMessenger>
ContWaitType pending_handler_msgs_ = {};
ContainerPendingType pending_recvs_ = {};
TagType cur_direct_buffer_tag_ = starting_direct_buffer_tag;
EpochStackType epoch_stack_;
RequestHolder<InProgressIRecv> in_progress_active_msg_irecv;
RequestHolder<InProgressDataIRecv> in_progress_data_irecv;
RequestHolder<AsyncOpWrapper> in_progress_ops;
Expand Down
44 changes: 3 additions & 41 deletions src/vt/messaging/active.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,54 +445,16 @@ ActiveMessenger::PendingSendType ActiveMessenger::broadcastMsgAuto(
);
}

inline EpochType ActiveMessenger::getGlobalEpoch() const {
vtAssertInfo(
epoch_stack_.size() > 0, "Epoch stack size must be greater than zero",
epoch_stack_.size()
);
return epoch_stack_.size() ? epoch_stack_.top() : term::any_epoch_sentinel;
}

inline void ActiveMessenger::pushEpoch(EpochType const& epoch) {
/*
* pushEpoch(epoch) pushes any epoch onto the local stack iff epoch !=
* no_epoch; the epoch stack includes all locally pushed epochs and the
* current contexts pushed, transitively causally related active message
* handlers.
*/
vtAssertInfo(
epoch != no_epoch, "Do not push no_epoch onto the epoch stack",
epoch, no_epoch, epoch_stack_.size(),
epoch_stack_.size() > 0 ? epoch_stack_.top() : no_epoch
);
if (epoch != no_epoch) {
epoch_stack_.push(epoch);
}
return theTerm()->pushEpoch(epoch);
}

inline EpochType ActiveMessenger::popEpoch(EpochType const& epoch) {
/*
* popEpoch(epoch) shall remove the top entry from epoch_size_, iif the size
* is non-zero and the `epoch' passed, if `epoch != no_epoch', is equal to the
* top of the `epoch_stack_.top()'; else, it shall remove any entry from the
* top of the stack.
*/
auto const& non_zero = epoch_stack_.size() > 0;
vtAssertExprInfo(
non_zero and (epoch_stack_.top() == epoch or epoch == no_epoch),
epoch, non_zero, epoch_stack_.top()
);
if (epoch == no_epoch) {
return non_zero ? epoch_stack_.pop(),epoch_stack_.top() : no_epoch;
} else {
return non_zero && epoch == epoch_stack_.top() ?
epoch_stack_.pop(),epoch :
no_epoch;
}
return theTerm()->popEpoch(epoch);
}

inline EpochType ActiveMessenger::getEpoch() const {
return getGlobalEpoch();
return theTerm()->getEpoch();
}

template <typename MsgT>
Expand Down
2 changes: 1 addition & 1 deletion src/vt/termination/termination.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct EpochStack {
void push(DataType in) { stack_[cur_++] = in; }
DataType top() const { return stack_[cur_-1]; }
void pop() { cur_--; }
int size() const { return cur_; }
unsigned int size() const { return cur_; }

int cur_ = 0;
std::array<DataType, 64> stack_;
Expand Down

0 comments on commit acf44fc

Please sign in to comment.