summaryrefslogtreecommitdiff
path: root/Simulator
diff options
context:
space:
mode:
Diffstat (limited to 'Simulator')
-rw-r--r--Simulator/include/Simulator.h2
-rw-r--r--Simulator/include/database/Queries.h4
-rw-r--r--Simulator/include/simulation/Experiment.h2
-rw-r--r--Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h19
-rw-r--r--Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h22
-rw-r--r--Simulator/include/simulation/workloads/Workload.h10
-rw-r--r--Simulator/src/database/Database.cpp12
-rw-r--r--Simulator/src/simulation/workloads/Workload.cpp7
8 files changed, 62 insertions, 16 deletions
diff --git a/Simulator/include/Simulator.h b/Simulator/include/Simulator.h
index c41a4c2b..d0828dcd 100644
--- a/Simulator/include/Simulator.h
+++ b/Simulator/include/Simulator.h
@@ -64,7 +64,7 @@ namespace Simulation
auto it = experiments.begin();
while(it != experiments.end())
{
- auto history = (*it).second.getHistory();
+ auto& history = (*it).second.getHistory();
if (history.historySize() > 3000 || (*it).second.isFinished())
write((*it).first);
diff --git a/Simulator/include/database/Queries.h b/Simulator/include/database/Queries.h
index 59133058..6f7f90ec 100644
--- a/Simulator/include/database/Queries.h
+++ b/Simulator/include/database/Queries.h
@@ -84,10 +84,10 @@ namespace Database
/*
Returns all columns of each task belonging to the given trace.
- Returns: <int : id, int : start_tick, inn : total_flop_count, int : trace_id, int : task_dependency_id>
+ Returns: <int : id, int : start_tick, inn : total_flop_count, int : trace_id, int : task_dependency_id, std::string : parallelizability>
Binds: <int : trace_id>
*/
- Query<int, int, int, int, int> GET_TASKS_OF_TRACE(std::string(R"query(
+ Query<int, int, int, int, int, std::string> GET_TASKS_OF_TRACE(std::string(R"query(
SELECT * FROM tasks WHERE trace_id = $id;
)query"));
diff --git a/Simulator/include/simulation/Experiment.h b/Simulator/include/simulation/Experiment.h
index 400f418a..54a861e6 100644
--- a/Simulator/include/simulation/Experiment.h
+++ b/Simulator/include/simulation/Experiment.h
@@ -110,7 +110,7 @@ namespace Simulation
/**
* \return The history of this experiment that has no yet been written to the database.
*/
- SimulationHistory getHistory() const
+ SimulationHistory& getHistory()
{
return history;
}
diff --git a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h
index 797eb489..5d277c8d 100644
--- a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h
+++ b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h
@@ -22,8 +22,10 @@ namespace Simulation
// Find the first workload with dependencies finished
int index = 0;
- while(!workloads.at(index)->dependencyFinished)
- index = (++index) % workloads.size();
+
+ std::remove_if(workloads.begin(), workloads.end(), [](Workload* workload) {
+ return !workload->dependencyFinished;
+ });
// Reset the number of cores used for each workload
for (auto workload : workloads)
@@ -38,6 +40,19 @@ namespace Simulation
workloads.at(index)->setCoresUsed(
workloads.at(index)->getCoresUsed() + machine.get().getNumberOfCores()
);
+
+ if (!workloads.at(index)->isParallelizable())
+ {
+ workloads.erase(workloads.begin() + index);
+ if (workloads.size() == 0)
+ break;
+
+ index %= workloads.size();
+ }
+ else
+ {
+ index = (++index) % workloads.size();
+ }
}
}
};
diff --git a/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h
index 51673fb5..a152c39b 100644
--- a/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h
+++ b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h
@@ -20,6 +20,10 @@ namespace Simulation
if (workloads.size() == 0)
return;
+ std::remove_if(workloads.begin(), workloads.end(), [](Workload* workload) {
+ return !workload->dependencyFinished;
+ });
+
for (auto workload : workloads)
{
workload->setCoresUsed(0);
@@ -34,18 +38,26 @@ namespace Simulation
);
int taskIndex = 0;
-
for (auto machine : machines)
{
- while (!workloads.at(taskIndex)->dependencyFinished)
- taskIndex = (++taskIndex) % workloads.size();
-
machine.get().giveTask(workloads.at(taskIndex));
+
workloads.at(taskIndex)->setCoresUsed(
workloads.at(taskIndex)->getCoresUsed() + machine.get().getNumberOfCores()
);
- taskIndex = (++taskIndex) % workloads.size();
+ if (!workloads.at(taskIndex)->isParallelizable())
+ {
+ workloads.erase(workloads.begin() + taskIndex);
+ if (workloads.size() == 0)
+ break;
+
+ taskIndex %= workloads.size();
+ }
+ else
+ {
+ taskIndex = (++taskIndex) % workloads.size();
+ }
}
}
};
diff --git a/Simulator/include/simulation/workloads/Workload.h b/Simulator/include/simulation/workloads/Workload.h
index 0371deac..7e391d8d 100644
--- a/Simulator/include/simulation/workloads/Workload.h
+++ b/Simulator/include/simulation/workloads/Workload.h
@@ -12,7 +12,7 @@ namespace Simulation
/*
Initializes the TOTAL_FLOPS and the remainingFlops to the size.
*/
- Workload(int size, int startTick, int dbId, int traceId, int dependency);
+ Workload(int size, int startTick, int dbId, int traceId, int dependency, bool parallel);
/*
Decreases the remainingFlops by the given amount.
@@ -62,6 +62,11 @@ namespace Simulation
*/
uint32_t getCoresUsed();
+ /**
+ * \return Whether this workload can be spread across machines.
+ */
+ bool isParallelizable();
+
// True if the dependency of this workload has finished.
bool dependencyFinished = false;
@@ -89,5 +94,8 @@ namespace Simulation
// The number of cores that this workload is occupying
uint32_t coresUsed = 0;
+
+ // Whether this task can be parallelized across multiple machines.
+ bool isParallel = false;
};
}
diff --git a/Simulator/src/database/Database.cpp b/Simulator/src/database/Database.cpp
index 5abee41e..d1bb2af5 100644
--- a/Simulator/src/database/Database.cpp
+++ b/Simulator/src/database/Database.cpp
@@ -260,7 +260,7 @@ namespace Database
{
Simulation::WorkloadPool pool;
- std::vector<QueryResult<int, int, int, int, int>> tasks;
+ std::vector<QueryResult<int, int, int, int, int, std::string>> tasks;
// Fetch tasks from database
{
// Retrieves the traceId corresponding to the simulation section
@@ -272,7 +272,7 @@ namespace Database
.get<int, 0>();
// Retrieves the tasks that belong to the traceId
- QueryExecuter<int, int, int, int, int> q2(db);
+ QueryExecuter<int, int, int, int, int, std::string> q2(db);
tasks = q2
.setQuery(Queries::GET_TASKS_OF_TRACE)
.bindParams<int>(traceId)
@@ -287,9 +287,15 @@ namespace Database
int totalFlopCount = row.get<int, 2>();
int traceId = row.get<int, 3>();
int dependency = row.get<int, 4>();
+ std::string parallelizability = row.get<std::string, 5>();
+ bool parallel = false;
+ if (parallelizability == "PARALLEL")
+ {
+ parallel = true;
+ }
// TODO possibly wait and batch?
- Simulation::Workload workload(totalFlopCount, startTick, id, traceId, dependency);
+ Simulation::Workload workload(totalFlopCount, startTick, id, traceId, dependency, parallel);
if(dependency == 0)
workload.dependencyFinished = true;
diff --git a/Simulator/src/simulation/workloads/Workload.cpp b/Simulator/src/simulation/workloads/Workload.cpp
index ba8ca950..f8fe1444 100644
--- a/Simulator/src/simulation/workloads/Workload.cpp
+++ b/Simulator/src/simulation/workloads/Workload.cpp
@@ -2,7 +2,7 @@
namespace Simulation
{
- Workload::Workload(int size, int startTick, int dbId, int traceId, int dependency) : dependencyId(dependency), remainingFlops(size), TOTAL_FLOPS(size), START_TICK(startTick), ID(dbId), TRACE_ID(traceId) {}
+ Workload::Workload(int size, int startTick, int dbId, int traceId, int dependency, bool parallel) : dependencyId(dependency), remainingFlops(size), TOTAL_FLOPS(size), START_TICK(startTick), ID(dbId), TRACE_ID(traceId), isParallel(parallel) {}
void Workload::doOperations(uint32_t opCount)
{
@@ -52,4 +52,9 @@ namespace Simulation
{
return coresUsed;
}
+
+ bool Workload::isParallelizable()
+ {
+ return isParallel;
+ }
}