Skip to content

Commit

Permalink
Merge pull request #1971 from DARMA-tasking/1969-try-to-reduce-more-m…
Browse files Browse the repository at this point in the history
…pi_wtime-calls-when-schedulerprogress-features-are-disabled

#1969: scheduler: reduce calls to get the current time
  • Loading branch information
lifflander authored Sep 28, 2022
2 parents ad1c783 + 090d9cb commit 741065e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/vt/runtime/component/component_pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ int ComponentPack::progress(TimeType current_time) {
return total;
}

bool ComponentPack::needsCurrentTime() {
bool needs_time = false;
for (auto&& pollable : pollable_components_) {
needs_time = needs_time || pollable->needsCurrentTime();
}
return needs_time;
}

std::list<int> ComponentPack::topoSort() {
std::list<int> order;

Expand Down
7 changes: 7 additions & 0 deletions src/vt/runtime/component/component_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ struct ComponentPack {
*/
int progress(TimeType current_time);

/**
* \internal \brief Needs current time
*
* \return whether any component needs the current time on the progress call
*/
bool needsCurrentTime();

/**
* \internal \brief Extract the first component from a running pack that
* matches \c name.
Expand Down
7 changes: 7 additions & 0 deletions src/vt/runtime/component/progressable.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ struct Progressable {
* \return the number of units executed---zero if no progress was made
*/
virtual int progress(TimeType current_time) = 0;

/**
* \brief Whether the component needs the current time
*
* \return whether it needs time
*/
virtual bool needsCurrentTime() { return false; }
};

}}} /* end namespace vt::runtime::component */
Expand Down
7 changes: 7 additions & 0 deletions src/vt/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ struct Runtime {
*/
int progress(TimeType current_time) { if (p_) return p_->progress(current_time); else return 0; }

/**
* \brief Check if any pollable components needs the current time
*
* \return whether it needs the current time
*/
bool needsCurrentTime() { if (p_) return p_->needsCurrentTime(); else return false; }

/**
* \brief Check if runtime has terminated
*
Expand Down
34 changes: 22 additions & 12 deletions src/vt/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ Scheduler::Scheduler()
# endif
}

void Scheduler::startup() {
special_progress_ =
theConfig()->vt_sched_progress_han != 0 or progress_time_enabled_;
}

void Scheduler::preDiagnostic() {
vtLiveTime.stop();
}
Expand Down Expand Up @@ -236,23 +241,28 @@ void Scheduler::runProgress(bool msg_only, TimeType current_time) {
printMemoryUsage();
}

// Reset count of processed handlers since the last time progress was invoked
processed_after_last_progress_ = 0;
last_progress_time_ = timing::getCurrentTime();

if (special_progress_) {
// Reset count of processed handlers since the last time progress was invoked
processed_after_last_progress_ = 0;
last_progress_time_ = timing::getCurrentTime();
}
}

void Scheduler::runSchedulerOnceImpl(bool msg_only) {
auto current_time = timing::getCurrentTime();
auto time_since_last_progress = current_time - last_progress_time_;
if (
work_queue_.empty() or
shouldCallProgress(processed_after_last_progress_, time_since_last_progress)
) {
runProgress(msg_only, current_time);
if (special_progress_) {
auto current_time = timing::getCurrentTime();
auto time_since_last_progress = current_time - last_progress_time_;
if (shouldCallProgress(processed_after_last_progress_, time_since_last_progress)) {
runProgress(msg_only, current_time);
}
} else if (work_queue_.empty()) {
if (curRT->needsCurrentTime()) {
runProgress(msg_only, timing::getCurrentTime());
} else {
runProgress(msg_only, TimeType{0});
}
}


if (not work_queue_.empty()) {
queueSizeGauge.update(work_queue_.size());

Expand Down
3 changes: 3 additions & 0 deletions src/vt/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct Scheduler : runtime::component::Component<Scheduler> {
std::string name() override { return "Scheduler"; }

void preDiagnostic() override;
void startup() override;

/**
* \internal \brief Check for termination when running on a single node
Expand Down Expand Up @@ -423,6 +424,8 @@ struct Scheduler : runtime::component::Component<Scheduler> {
std::size_t threshold_memory_usage_ = 0;
std::size_t last_memory_usage_poll_ = 0;

bool special_progress_ = false; /**< time-based/k-handler progress enabled */

// Access to triggerEvent.
template <typename Callable>
friend void vt::runInEpochRooted(Callable&& fn);
Expand Down
4 changes: 4 additions & 0 deletions src/vt/timetrigger/time_trigger_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ int TimeTriggerManager::progress(TimeType current_time) {
return 0;
}

bool TimeTriggerManager::needsCurrentTime() {
return queue_.size() != 0;
}

}} /* end namespace vt::timetrigger */
2 changes: 2 additions & 0 deletions src/vt/timetrigger/time_trigger_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ struct TimeTriggerManager

int progress(TimeType current_time) override;

bool needsCurrentTime() override;

/**
* \brief Register a time-based trigger with a specific period
*
Expand Down

0 comments on commit 741065e

Please sign in to comment.