blob: 797eb489a419bef038a00d1bee3df99d628b37a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#pragma once
#include "Scheduler.h"
#include <algorithm>
namespace Simulation
{
class FirstInFirstOutScheduler : public Scheduler
{
protected:
~FirstInFirstOutScheduler()
{
}
public:
/**
* \brief Distribute workloads according to the FIFO principle.
*/
void schedule(std::vector<std::reference_wrapper<Modeling::Machine>>& machines, std::vector<Workload*> workloads) override
{
if (workloads.size() == 0)
return;
// Find the first workload with dependencies finished
int index = 0;
while(!workloads.at(index)->dependencyFinished)
index = (++index) % workloads.size();
// Reset the number of cores used for each workload
for (auto workload : workloads)
{
workload->setCoresUsed(0);
}
// Distribute tasks across machines and set cores used of workloads
for (auto machine : machines)
{
machine.get().giveTask(workloads.at(index));
workloads.at(index)->setCoresUsed(
workloads.at(index)->getCoresUsed() + machine.get().getNumberOfCores()
);
}
}
};
}
|