From 070ce923574dcc57435cb3fb2dfe86b6a38cd249 Mon Sep 17 00:00:00 2001 From: MDBijman Date: Tue, 24 Jan 2017 12:15:26 +0100 Subject: Initial code commit with organized dependencies --- Simulator/include/simulation/workloads/Workload.h | 80 ++++++++++++++++++++++ .../include/simulation/workloads/WorkloadPool.h | 43 ++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 Simulator/include/simulation/workloads/Workload.h create mode 100644 Simulator/include/simulation/workloads/WorkloadPool.h (limited to 'Simulator/include/simulation/workloads') diff --git a/Simulator/include/simulation/workloads/Workload.h b/Simulator/include/simulation/workloads/Workload.h new file mode 100644 index 00000000..9de57990 --- /dev/null +++ b/Simulator/include/simulation/workloads/Workload.h @@ -0,0 +1,80 @@ +#pragma once +#include + +namespace Simulation +{ + /* + The Workload class models a workload. + */ + class Workload + { + public: + /* + Initializes the TOTAL_FLOPS and the remainingFlops to the size. + */ + Workload(int size, int startTick, int dbId, int traceId, int dependency); + + /* + Decreases the remainingFlops by the given amount. + */ + void doOperations(uint32_t opCount); + + /* + Returns the amount of operations left to do. + */ + uint32_t getRemainingOperations() const; + + /* + Returns the total amount of operations, including finished ones. + */ + uint32_t getTotalOperations() const; + + /* + Returns true if the workload has been finished. + */ + bool isFinished() const; + + /* + Returns the id of this workload. + */ + uint32_t getId() const; + + /* + Returns the dependency id of this workload. + */ + int getDependencyId() const; + + /** + * \return The start tick of this workload. + */ + uint32_t getStartTick() const + { + return START_TICK; + } + + // True if the dependency of this workload has finished. + bool dependencyFinished = false; + + private: + // The id of the workload this workload depends on. + int dependencyId; + + // Finished is true if the remainingFlops is 0. + bool finished = false; + + // The amount of operations done. + uint32_t remainingFlops; + + // The total amount of operations required to finish this task. + uint32_t TOTAL_FLOPS; + + // The tick during which this workload was started. + uint32_t START_TICK; + + // The id of this workload in the database + uint32_t ID; + + // The id of the trace this workload belongs to in the database. + uint32_t TRACE_ID; + }; +} diff --git a/Simulator/include/simulation/workloads/WorkloadPool.h b/Simulator/include/simulation/workloads/WorkloadPool.h new file mode 100644 index 00000000..28a2ad04 --- /dev/null +++ b/Simulator/include/simulation/workloads/WorkloadPool.h @@ -0,0 +1,43 @@ +#pragma once +#include "simulation/workloads/Workload.h" +#include + +namespace Simulation +{ + class WorkloadPool + { + public: + /* + Adds the given workload to this pool of workloads. + */ + void addWorkload(Workload w); + + /* + Returns a reference to the vector of workloads. + */ + std::vector getWorkloads(uint32_t currentTick); + + /* + Returns a reference to the workload with the given id. + */ + Workload& getWorkload(int id); + + /* + Removes all workloads that are finished. + */ + void clearFinishedWorkloads(); + + /* + Returns true if the workloads vector of this pool is empty. + */ + bool isEmpty(); + + private: + /* + Sets all dependencyFinished to true of workloads with the given id as dependency. + */ + void setDependenciesFinished(int id); + + std::vector workloads; + }; +} -- cgit v1.2.3