Skip to content

Commit

Permalink
#1899: Split array into separate variables for each context type
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Aug 23, 2022
1 parent c2af5bd commit 05579f9
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 31 deletions.
113 changes: 98 additions & 15 deletions src/vt/runnable/runnable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,38 +200,121 @@ void RunnableNew::run() {
}

void RunnableNew::begin() {
for (int i = 0; i < ci_; i++) {
contexts_[i]->begin();
}
#if vt_check_enabled(trace_enabled)
if(ctx_trace_) ctx_trace_->begin();
#endif
if(ctx_continuation_) ctx_continuation_->begin();
if(ctx_lbdata_) ctx_lbdata_->begin();
if(ctx_setcontext_) ctx_setcontext_->begin();
if(ctx_td_) ctx_td_->begin();
if(ctx_collection_) ctx_collection_->begin();
}

void RunnableNew::end() {
for (int i = 0; i < ci_; i++) {
contexts_[i]->end();
}
#if vt_check_enabled(trace_enabled)
if(ctx_trace_) ctx_trace_->end();
#endif
if(ctx_continuation_) ctx_continuation_->end();
if(ctx_lbdata_) ctx_lbdata_->end();
if(ctx_setcontext_) ctx_setcontext_->end();
if(ctx_td_) ctx_td_->end();
if(ctx_collection_) ctx_collection_->end();
}

void RunnableNew::suspend() {
for (int i = 0; i < ci_; i++) {
contexts_[i]->suspend();
}
#if vt_check_enabled(trace_enabled)
if(ctx_trace_) ctx_trace_->suspend();
#endif
if(ctx_continuation_) ctx_continuation_->suspend();
if(ctx_lbdata_) ctx_lbdata_->suspend();
if(ctx_setcontext_) ctx_setcontext_->suspend();
if(ctx_td_) ctx_td_->suspend();
if(ctx_collection_) ctx_collection_->suspend();
}

void RunnableNew::resume() {
for (int i = 0; i < ci_; i++) {
contexts_[i]->resume();
}
#if vt_check_enabled(trace_enabled)
if(ctx_trace_) ctx_trace_->resume();
#endif
if(ctx_continuation_) ctx_continuation_->resume();
if(ctx_lbdata_) ctx_lbdata_->resume();
if(ctx_setcontext_) ctx_setcontext_->resume();
if(ctx_td_) ctx_td_->resume();
if(ctx_collection_) ctx_collection_->resume();
}

void RunnableNew::send(elm::ElementIDStruct elm, MsgSizeType bytes) {
for (int i = 0; i < ci_; i++) {
contexts_[i]->send(elm, bytes);
}
#if vt_check_enabled(trace_enabled)
if(ctx_trace_) ctx_trace_->send(elm, bytes);
#endif
if(ctx_continuation_) ctx_continuation_->send(elm, bytes);
if(ctx_lbdata_) ctx_lbdata_->send(elm, bytes);
if(ctx_setcontext_) ctx_setcontext_->send(elm, bytes);
if(ctx_td_) ctx_td_->send(elm, bytes);
if(ctx_collection_) ctx_collection_->send(elm, bytes);
}

/*static*/ std::unique_ptr<
pool::MemoryPoolEqual<detail::runnable_context_max_size>
> RunnableNew::up_pool =
std::make_unique<pool::MemoryPoolEqual<detail::runnable_context_max_size>>();

#if vt_check_enabled(trace_enabled)
void RunnableNew::addContext(CtxTracePtr&& ptr) {
ctx_trace_ = std::move(ptr);
}
#endif

void RunnableNew::addContext(CtxContinuationPtr&& ptr) {
ctx_continuation_ = std::move(ptr);
}

void RunnableNew::addContext(CtxLBDataPtr&& ptr) {
ctx_lbdata_ = std::move(ptr);
}

void RunnableNew::addContext(CtxSetContextPtr&& ptr) {
ctx_setcontext_ = std::move(ptr);
}

void RunnableNew::addContext(CtxTDPtr&& ptr) {
ctx_td_ = std::move(ptr);
}

void RunnableNew::addContext(CtxCollectionPtr&& ptr) {
ctx_collection_ = std::move(ptr);
}

#if vt_check_enabled(trace_enabled)
template<>
ctx::Trace* RunnableNew::get<ctx::Trace>() {
return ctx_trace_.get();
}
#endif

template<>
ctx::Continuation* RunnableNew::get<ctx::Continuation>() {
return ctx_continuation_.get();
}

template<>
ctx::LBData* RunnableNew::get<ctx::LBData>() {
return ctx_lbdata_.get();
}

template<>
ctx::SetContext* RunnableNew::get<ctx::SetContext>() {
return ctx_setcontext_.get();
}

template<>
ctx::TD* RunnableNew::get<ctx::TD>() {
return ctx_td_.get();
}

template<>
ctx::Collection* RunnableNew::get<ctx::Collection>() {
return ctx_collection_.get();
}

}} /* end namespace vt::runnable */
34 changes: 31 additions & 3 deletions src/vt/runnable/runnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ constexpr std::size_t runnable_context_max_size = arrayMax(runnable_context_arra
* with it to run it independently of the where in the stack it was created.
*/
struct RunnableNew {
using CtxBasePtr = vt::util::ptr::unique_ptr_fixed<ctx::Base>;
#if vt_check_enabled(trace_enabled)
using CtxTracePtr = vt::util::ptr::unique_ptr_fixed<ctx::Trace>;
#endif
using CtxContinuationPtr = vt::util::ptr::unique_ptr_fixed<ctx::Continuation>;
using CtxLBDataPtr = vt::util::ptr::unique_ptr_fixed<ctx::LBData>;
using CtxSetContextPtr = vt::util::ptr::unique_ptr_fixed<ctx::SetContext>;
using CtxTDPtr = vt::util::ptr::unique_ptr_fixed<ctx::TD>;
using CtxCollectionPtr = vt::util::ptr::unique_ptr_fixed<ctx::Collection>;

template <typename... Args>
using FnParamType = void(*)(Args...);
Expand Down Expand Up @@ -285,15 +292,36 @@ struct RunnableNew {
pool::MemoryPoolEqual<detail::runnable_context_max_size>
> up_pool;

private:

/**
* \internal \brief Store context passed in as parameter in a private member
*/
#if vt_check_enabled(trace_enabled)
void addContext(CtxTracePtr&& ptr);
#endif
void addContext(CtxContinuationPtr&& ptr);
void addContext(CtxLBDataPtr&& ptr);
void addContext(CtxSetContextPtr&& ptr);
void addContext(CtxTDPtr&& ptr);
void addContext(CtxCollectionPtr&& ptr);

private:
MsgSharedPtr<BaseMsgType> msg_ = nullptr; /**< The associated message */
bool is_threaded_ = false; /**< Whether ULTs are supported */
std::array<CtxBasePtr, 8> contexts_; /**< Array of contexts */
int ci_ = 0; /**< Current index of contexts */
ActionType task_ = nullptr; /**< The runnable's task */
bool done_ = false; /**< Whether task is complete */
bool suspended_ = false; /**< Whether task is suspended */
ThreadIDType tid_ = no_thread_id; /**< The thread ID for the task */

#if vt_check_enabled(trace_enabled)
CtxTracePtr ctx_trace_ = nullptr; /**< The Trace context */
#endif
CtxContinuationPtr ctx_continuation_ = nullptr; /**< The Continuation context */
CtxLBDataPtr ctx_lbdata_ = nullptr; /**< The LB Data context */
CtxSetContextPtr ctx_setcontext_ = nullptr; /**< The SetContext context */
CtxTDPtr ctx_td_ = nullptr; /**< The TD context */
CtxCollectionPtr ctx_collection_ = nullptr; /**< The Collection context */
};

}} /* end namespace vt::runnable */
Expand Down
16 changes: 3 additions & 13 deletions src/vt/runnable/runnable.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,15 @@

namespace vt { namespace runnable {

template <typename T>
T* RunnableNew::get() {
for (int i = 0; i < ci_; i++) {
auto t = dynamic_cast<T*>(contexts_[i].get());
if (t) {
return t;
}
}
return nullptr;
}

template <typename T, typename... Args>
void RunnableNew::addContext(Args&&... args) {
auto c = vt::util::ptr::make_unique_fixed<
T, detail::runnable_context_max_size
>(*up_pool.get(), std::forward<Args>(args)...);
contexts_[ci_++] = vt::util::ptr::unique_fixed_to_base<ctx::Base, detail::runnable_context_max_size>(

addContext(vt::util::ptr::unique_fixed_to_base<T, detail::runnable_context_max_size>(
*up_pool.get(), std::move(c)
);
));
}

}} /* end namespace vt::runnable */
Expand Down

0 comments on commit 05579f9

Please sign in to comment.