1 // Copyright (C) 2006-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __EXECUTOR_HXX__
21 #define __EXECUTOR_HXX__
23 #include "YACSlibEngineExport.hxx"
26 #include "Semaphore.hxx"
27 #include "Exception.hxx"
32 #pragma comment(lib,"winmm.lib")
43 namespace WorkloadManager
56 /*! \brief Threaded Executor
62 class YACSLIBENGINE_EXPORT Executor
65 Scheduler *_mainSched;
67 int _nbOfConcurrentThreads;
68 YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
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;
78 bool _stopOnErrorRequested;
79 bool _dumpOnErrorRequested;
81 bool _isRunningunderExternalControl;
82 bool _isWaitingEventsFromRunningTasks;
83 int _numberOfRunningTasks;
84 std::set<Task *> _runningTasks;
85 int _numberOfEndedTasks;
87 YACS::ExecutorState _executorState;
88 YACS::ExecutionMode _execMode;
89 std::list<std::string> _listOfBreakPoints;
90 std::list<std::string> _listOfTasksToLoad;
91 std::vector<Task *> _tasks;
92 std::vector<Task *> _tasksSave;
94 std::string _dumpErrorFile;
95 bool _keepGoingOnFail;
96 //! specifies if scope DynParaLoop is active or not. False by default.
97 bool _DPLScopeSensitive;
98 std::chrono::steady_clock::time_point _start;
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);
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();
130 void resume(bool suspended);
131 static int _maxThreads;
132 static size_t _threadStackSize;
133 YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
134 ///// new executor !!!!!
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);
143 bool checkBreakPoints();
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);
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);
157 static void *functionForTaskLoad(void *);
158 static void *functionForTaskExecution(void *);