Version: 9.16.0
Executor.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef __EXECUTOR_HXX__
21#define __EXECUTOR_HXX__
22
24#include "Mutex.hxx"
25#include "Thread.hxx"
26#include "Semaphore.hxx"
27#include "Exception.hxx"
28#include "define.hxx"
29
30#ifdef WIN32
31#include <windows.h>
32#pragma comment(lib,"winmm.lib")
33#endif
34#include <list>
35#include <vector>
36#include <set>
37#include <string>
38#include <fstream>
39#include <ctime>
40#include <chrono>
41#include <cstdint>
42
44{
45 struct RunInfo;
46}
47
48namespace YACS
49{
50 namespace ENGINE
51 {
52 class Scheduler;
53 class ComposedNode;
54 class Task;
55
63 {
64 protected:
69 YACS::BASES::Condition _condForNewTasksToPerform;
70 YACS::BASES::Semaphore _semForMaxThreads;
71 YACS::BASES::Condition _condForStepByStep;
72 YACS::BASES::Condition _condForPilot;
73 YACS::BASES::Mutex _mutexForSchedulerUpdate;
74 YACS::BASES::Mutex _mutexForTrace;
75 std::uint32_t _maxNbThreads = 10000;
84 std::set<Task *> _runningTasks;
89 std::list<std::string> _listOfBreakPoints;
90 std::list<std::string> _listOfTasksToLoad;
91 std::vector<Task *> _tasks;
92 std::vector<Task *> _tasksSave;
93 std::ofstream _trace;
94 std::string _dumpErrorFile;
98 std::chrono::steady_clock::time_point _start;
99 public:
100 Executor();
101 virtual ~Executor();
102 void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
103 void RunW(Scheduler *graph,int debug=0, bool fromScratch=true);
104 void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
105 void runWlm(Scheduler *graph,int debug=0, bool fromScratch=true);
106 void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
107 bool getKeepGoingProperty() const { return _keepGoingOnFail; }
108 void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; }
109 bool getDPLScopeSensitive() const { return _DPLScopeSensitive; }
110 YACS::ExecutionMode getCurrentExecMode();
111 YACS::ExecutorState getExecutorState();
112 void setExecMode(YACS::ExecutionMode mode);
113 void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
114 std::list<std::string> getTasksToLoad();
115 bool setStepsToExecute(std::list<std::string> listToExecute);
116 bool resumeCurrentBreakPoint();
117 bool isNotFinished();
118 void stopExecution();
119 bool saveState(const std::string& xmlFile);
120 bool loadState();
121 int getMaxNbOfThreads() const;
122 void setMaxNbOfThreads(int maxNbThreads);
123 int getNbOfThreads();
124 int getNumberOfRunningTasks();
125 void displayDot(Scheduler *graph);
126 void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
127 void unsetStopOnError();
128 void waitPause();
129 bool suspendASAP();
130 void resume(bool suspended);
131 static int _maxThreads;
132 static size_t _threadStackSize;
133 YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
135 void loadTask(Task *task, const WorkloadManager::RunInfo& runInfo);
136 YACS::Event runTask(Task *task);
137 void makeDatastreamConnections(Task *task);
138 void beginTask(Task *task);
139 void endTask(Task *task, YACS::Event ev);
140 void failTask(Task *task, const std::string& message);
142 protected:
143 bool checkBreakPoints();
144 void waitResume();
145 void loadTask(Task *task, const Executor *execInst);
146 void loadParallelTasks(const std::vector<Task *>& tasks, const Executor *execInst);
147 void launchTasks(const std::vector<Task*>& tasks);
148 void launchTask(Task *task);
149 void wakeUp();
150 void sleepWhileNoEventsFromAnyRunningTask();
151 void traceExec(Task *task, const std::string& message, const std::string& placement);
152 void _displayDot(Scheduler *graph);
153 virtual void sendEvent(const std::string& event);
154 void filterTasksConsideringContainers(std::vector<Task *>& tsks);
155 static std::string ComputePlacement(Task *zeTask);
156 protected:
157 static void *functionForTaskLoad(void *);
158 static void *functionForTaskExecution(void *);
159 };
160 }
161}
162
163#endif
#define YACSLIBENGINE_EXPORT
Base class for all composed nodes.
Threaded Executor.
Definition: Executor.hxx:63
std::list< std::string > _listOfTasksToLoad
Definition: Executor.hxx:90
YACS::BASES::Mutex & getTheMutexForSchedulerUpdate()
Definition: Executor.hxx:133
YACS::BASES::Mutex _mutexForTrace
Definition: Executor.hxx:74
std::vector< Task * > _tasks
Definition: Executor.hxx:91
bool _isWaitingEventsFromRunningTasks
Definition: Executor.hxx:82
bool _isRunningunderExternalControl
Definition: Executor.hxx:81
bool _DPLScopeSensitive
specifies if scope DynParaLoop is active or not. False by default.
Definition: Executor.hxx:97
YACS::ExecutionMode _execMode
Definition: Executor.hxx:88
std::set< Task * > _runningTasks
Definition: Executor.hxx:84
static size_t _threadStackSize
Definition: Executor.hxx:132
YACS::BASES::Mutex _mutexForSchedulerUpdate
Definition: Executor.hxx:73
std::string _dumpErrorFile
Definition: Executor.hxx:94
std::vector< Task * > _tasksSave
Definition: Executor.hxx:92
YACS::BASES::Condition _condForNewTasksToPerform
Definition: Executor.hxx:69
static int _maxThreads
Definition: Executor.hxx:131
std::list< std::string > _listOfBreakPoints
Definition: Executor.hxx:89
YACS::BASES::Semaphore _semForMaxThreads
Definition: Executor.hxx:70
bool getDPLScopeSensitive() const
Definition: Executor.hxx:109
YACS::ExecutorState _executorState
Definition: Executor.hxx:87
ComposedNode * _root
Definition: Executor.hxx:66
std::ofstream _trace
Definition: Executor.hxx:93
void setDPLScopeSensitive(bool newVal)
Definition: Executor.hxx:108
Scheduler * _mainSched
Definition: Executor.hxx:65
bool getKeepGoingProperty() const
Definition: Executor.hxx:107
YACS::BASES::Mutex _mutexForNbOfConcurrentThreads
Definition: Executor.hxx:68
YACS::BASES::Condition _condForPilot
Definition: Executor.hxx:72
std::chrono::steady_clock::time_point _start
Definition: Executor.hxx:98
YACS::BASES::Condition _condForStepByStep
Definition: Executor.hxx:71
void setKeepGoingProperty(bool newVal)
Definition: Executor.hxx:106
YACSLOADER_EXPORT void loadState(YACS::ENGINE::Proc *p, const std::string &xmlStateFile)
Load state from a file into a Proc.
Definition: LoadState.cxx:950
Event
Definition: define.hxx:56
ExecutionMode
Definition: define.hxx:75
ExecutorState
Definition: define.hxx:64