Skip to content

Commit

Permalink
#1258: improve footprinting of CallbackUnion
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Feb 25, 2021
1 parent bab5809 commit 42dd0e1
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/vt/pipe/callback/cb_union/cb_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,43 @@ struct GeneralCallback {

template <typename SerializerT>
void serialize(SerializerT& s) {
using EnumDataType = typename std::underlying_type<CallbackEnum>::type;
EnumDataType val = static_cast<EnumDataType>(active_);
s | val;
s.skip(active_);
s | active_;

active_ = static_cast<CallbackEnum>(val);
s.skip(u_); // only serialize actual content of the union
// serialize actual content of the union and account for leftovers and
// padding bytes when footprinting
auto ser = [&](auto& cb){
s | cb;
s.addBytes(sizeof(this->u_) - sizeof(cb));
};
s.skip(u_);
switch (active_) {
case CallbackEnum::AnonCB:
s | u_.anon_cb_;
ser(u_.anon_cb_);
break;
case CallbackEnum::SendMsgCB:
s | u_.send_msg_cb_;
ser(u_.send_msg_cb_);
break;
case CallbackEnum::SendColMsgCB:
s | u_.send_col_msg_cb_;
ser(u_.send_col_msg_cb_);
break;
case CallbackEnum::BcastMsgCB:
s | u_.bcast_msg_cb_;
ser(u_.bcast_msg_cb_);
break;
case CallbackEnum::BcastColMsgCB:
s | u_.bcast_col_msg_cb_;
ser(u_.bcast_col_msg_cb_);
break;
case CallbackEnum::BcastColDirCB:
s | u_.bcast_col_dir_cb_;
ser(u_.bcast_col_dir_cb_);
break;
case CallbackEnum::BcastObjGrpCB:
s | u_.bcast_obj_cb_;
ser(u_.bcast_obj_cb_);
break;
case CallbackEnum::SendObjGrpCB:
s | u_.send_obj_cb_;
ser(u_.send_obj_cb_);
break;
case CallbackEnum::NoCB:
// Serializing empty callback!
s.addBytes(sizeof(u_) - sizeof(active_));
break;
default:
vtAssert(0, "Should be unreachable");
Expand Down

0 comments on commit 42dd0e1

Please sign in to comment.