Skip to content

Commit

Permalink
Reduce resource compare computation
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessOIer committed Dec 19, 2024
1 parent 30b3e9f commit a1c7c10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/CraneCtld/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2128,13 +2128,12 @@ bool MinLoadFirst::CalculateRunningNodesAndStartTime_(
while (!pq.empty() && pq.top()->it->first == time) {
auto tracker = pq.top();
pq.pop();
if (tracker->satisfied()) {
if (tracker->satisfied_flag) {
satisfied_trackers.try_push_back(tracker, time);
if (tracker->genNextUnsatisfied()) pq.emplace(tracker);
} else {
satisfied_trackers.try_erase(tracker);
if (tracker->genNextSatisfied()) pq.emplace(tracker);
}
if (tracker->genNext()) pq.emplace(tracker);
}
if (pq.empty() || satisfied_trackers.kth_time() + task->time_limit <=
pq.top()->it->first) {
Expand Down
10 changes: 9 additions & 1 deletion src/CraneCtld/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class MinLoadFirst : public INodeSelectionAlgo {
const TimeAvailResMap::const_iterator end;
const ResourceInNode* task_res;
void* tracker_list_elem;
bool satisfied_flag;

TimeAvailResTracker(const CranedId& craned_id,
const TimeAvailResMap::const_iterator& begin,
Expand All @@ -171,10 +172,17 @@ class MinLoadFirst : public INodeSelectionAlgo {
it(begin),
end(end),
task_res(task_res),
tracker_list_elem(nullptr) {}
tracker_list_elem(nullptr) {
satisfied_flag = satisfied();
}

bool satisfied() const { return *task_res <= it->second; }

bool genNext() {
satisfied_flag = !satisfied_flag; // target state
return satisfied_flag ? genNextSatisfied() : genNextUnsatisfied();
}

bool genNextUnsatisfied() {
while (++it != end && satisfied());
return it != end;
Expand Down

0 comments on commit a1c7c10

Please sign in to comment.