9 #include <dpsim/OpenMPLevelScheduler.h>
15 using namespace DPsim;
17 OpenMPLevelScheduler::OpenMPLevelScheduler(Int threads,
18 String outMeasurementFile)
19 : mOutMeasurementFile(outMeasurementFile) {
21 mNumThreads = threads;
23 mNumThreads = omp_get_num_threads();
26 void OpenMPLevelScheduler::createSchedule(
const Task::List &tasks,
28 const Edges &outEdges) {
34 if (!mOutMeasurementFile.empty())
35 Scheduler::initMeasurements(tasks);
40 std::chrono::steady_clock::time_point start, end;
42 if (!mOutMeasurementFile.empty()) {
43 #pragma omp parallel shared(time, timeStepCount) private(level, i, start, end) \
44 num_threads(mNumThreads)
45 for (level = 0; level < static_cast<long>(mLevels.size()); level++) {
47 #pragma omp for schedule(static)
48 for (i = 0; i < static_cast<long>(mLevels[level].size()); i++) {
49 start = std::chrono::steady_clock::now();
50 mLevels[level][i]->execute(time, timeStepCount);
51 end = std::chrono::steady_clock::now();
57 #pragma omp parallel shared(time, timeStepCount) private(level, i) \
58 num_threads(mNumThreads)
59 for (level = 0; level < static_cast<long>(mLevels.size()); level++) {
61 #pragma omp for schedule(static)
62 for (i = 0; i < static_cast<long>(mLevels[level].size()); i++) {
63 mLevels[level][i]->execute(time, timeStepCount);
71 if (!mOutMeasurementFile.empty()) {
void step(Real time, Int timeStepCount)
Performs a single simulation step.
void stop()
Called on simulation stop to reliably clean up e.g. running helper threads.
void writeMeasurements(CPS::String filename)
Write measurement data to file.
void topologicalSort(const CPS::Task::List &tasks, const Edges &inEdges, const Edges &outEdges, CPS::Task::List &sortedTasks)
Simple topological sort, filtering out tasks that do not need to be executed.
static void levelSchedule(const CPS::Task::List &tasks, const Edges &inEdges, const Edges &outEdges, std::vector< CPS::Task::List > &levels)
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
void updateMeasurement(CPS::Task *task, TaskTime time)